Java Code Examples for com.intellij.psi.PsiMethod#delete()
The following examples show how to use
com.intellij.psi.PsiMethod#delete() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CodeGenerator.java From ParcelablePlease with Apache License 2.0 | 6 votes |
/** * Finds and removes a given method * @param methodName * @param arguments */ private void findAndRemoveMethod(String methodName, String... arguments) { // Maybe there's an easier way to do this with mClass.findMethodBySignature(), but I'm not an expert on Psi* PsiMethod[] methods = psiClass.findMethodsByName(methodName, false); for (PsiMethod method : methods) { PsiParameterList parameterList = method.getParameterList(); if (parameterList.getParametersCount() == arguments.length) { boolean shouldDelete = true; PsiParameter[] parameters = parameterList.getParameters(); for (int i = 0; i < arguments.length; i++) { if (!parameters[i].getType().getCanonicalText().equals(arguments[i])) { shouldDelete = false; } } if (shouldDelete) { method.delete(); } } } }
Example 2
Source File: RefactorSetterHandler.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected void process(List<ClassMember> classMembers) { for (ClassMember classMember : classMembers) { final PsiElementClassMember elementClassMember = (PsiElementClassMember) classMember; PsiField psiField = (PsiField) elementClassMember.getPsiElement(); PsiMethod psiMethod = PropertyUtil.findPropertySetter(psiField.getContainingClass(), psiField.getName(), false, false); if (null != psiMethod) { PsiModifierList modifierList = psiField.getModifierList(); if (null != modifierList) { PsiAnnotation psiAnnotation = modifierList.addAnnotation(Setter.class.getName()); psiMethod.delete(); } } } }
Example 3
Source File: RefactorGetterHandler.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected void process(List<ClassMember> classMembers) { for (ClassMember classMember : classMembers) { final PsiElementClassMember elementClassMember = (PsiElementClassMember) classMember; PsiField psiField = (PsiField) elementClassMember.getPsiElement(); PsiMethod psiMethod = PropertyUtil.findPropertyGetter(psiField.getContainingClass(), psiField.getName(), false, false); if (null != psiMethod) { PsiModifierList modifierList = psiField.getModifierList(); if (null != modifierList) { PsiAnnotation psiAnnotation = modifierList.addAnnotation(Getter.class.getName()); // psiAnnotation.setDeclaredAttributeValue("value", ) psiMethod.delete(); } } } }
Example 4
Source File: LombokToStringHandler.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected void processClass(@NotNull PsiClass psiClass) { final PsiElementFactory factory = JavaPsiFacade.getElementFactory(psiClass.getProject()); final PsiClassType stringClassType = factory.createTypeByFQClassName(CommonClassNames.JAVA_LANG_STRING, psiClass.getResolveScope()); final PsiMethod toStringMethod = findPublicNonStaticMethod(psiClass, "toString", stringClassType); if (null != toStringMethod) { toStringMethod.delete(); } addAnnotation(psiClass, ToString.class); }
Example 5
Source File: LombokEqualsAndHashcodeHandler.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected void processClass(@NotNull PsiClass psiClass) { final PsiMethod equalsMethod = findPublicNonStaticMethod(psiClass, "equals", PsiType.BOOLEAN, PsiType.getJavaLangObject(psiClass.getManager(), psiClass.getResolveScope())); if (null != equalsMethod) { equalsMethod.delete(); } final PsiMethod hashCodeMethod = findPublicNonStaticMethod(psiClass, "hashCode", PsiType.INT); if (null != hashCodeMethod) { hashCodeMethod.delete(); } addAnnotation(psiClass, EqualsAndHashCode.class); }