-
-
Save dkandalov/5476562 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.intellij.openapi.actionSystem.AnActionEvent | |
import com.intellij.psi.PsiClass | |
import com.intellij.psi.PsiElement | |
import com.intellij.psi.PsiModifier | |
import com.intellij.psi.util.PsiTreeUtil | |
import static liveplugin.PluginUtil.* | |
def findContextClass = { project -> | |
def editor = currentEditorIn(project); | |
def psiFile = currentPsiFileIn(project); | |
PsiElement context = psiFile.findElementAt(editor.caretModel.offset); | |
if (context == null) { | |
return null; | |
} | |
PsiClass clazz = PsiTreeUtil.getParentOfType(context, PsiClass.class, false); | |
if (clazz == null || clazz.isInterface()) { | |
return null; | |
} | |
return clazz; | |
} | |
def setters = { method-> | |
return (!method.hasModifierProperty(PsiModifier.STATIC) | |
&& method.name.startsWith('set') | |
&& method.parameterList.parametersCount == 1) | |
} | |
def getters = { method-> | |
return (!method.hasModifierProperty(PsiModifier.STATIC) | |
&& method.name.startsWith('get') | |
&& method.parameterList.parametersCount == 0) | |
} | |
def deleteMethods = { methods -> | |
def deleted = []; | |
methods.each { method -> | |
deleted.add( method.name ) | |
method.delete() | |
} | |
show("deleted $deleted") | |
} | |
registerAction("RemoveSetters", "alt shift S") { AnActionEvent event -> | |
runDocumentWriteAction(event.project) { | |
def clazz = findContextClass(event.project) | |
if (clazz == null) return | |
deleteMethods clazz.methods.findAll(setters) | |
} | |
} | |
registerAction("RemoveGetters", "alt shift G") { AnActionEvent event -> | |
runDocumentWriteAction(event.project) { | |
def clazz = findContextClass(event.project) | |
if (clazz == null) return | |
deleteMethods clazz.methods.findAll(getters) | |
} | |
} | |
show("Loaded 'RemoveSetters' action<br/>Use 'Alt+Shift+S' to run it") | |
show("Loaded 'RemoveGetters' action<br/>Use 'Alt+Shift+G' to run it") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment