use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.
the class SuperMethodWarningUtil method checkSuperMethods.
@NotNull
public static PsiMethod[] checkSuperMethods(@NotNull PsiMethod method, @NotNull String actionString, @NotNull Collection<PsiElement> ignore) {
PsiClass aClass = method.getContainingClass();
if (aClass == null)
return new PsiMethod[] { method };
final Collection<PsiMethod> superMethods = getSuperMethods(method, aClass, ignore);
if (superMethods.isEmpty())
return new PsiMethod[] { method };
Set<String> superClasses = new HashSet<>();
boolean superAbstract = false;
boolean parentInterface = false;
for (final PsiMethod superMethod : superMethods) {
final PsiClass containingClass = superMethod.getContainingClass();
superClasses.add(containingClass.getQualifiedName());
final boolean isInterface = containingClass.isInterface();
superAbstract |= isInterface || superMethod.hasModifierProperty(PsiModifier.ABSTRACT);
parentInterface |= isInterface;
}
SuperMethodWarningDialog dialog = new SuperMethodWarningDialog(method.getProject(), DescriptiveNameUtil.getDescriptiveName(method), actionString, superAbstract, parentInterface, aClass.isInterface(), ArrayUtil.toStringArray(superClasses));
dialog.show();
if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
return superMethods.toArray(new PsiMethod[superMethods.size()]);
}
if (dialog.getExitCode() == SuperMethodWarningDialog.NO_EXIT_CODE) {
return new PsiMethod[] { method };
}
return PsiMethod.EMPTY_ARRAY;
}
use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.
the class HierarchicalMethodSignatureImpl method addSuperSignature.
public void addSuperSignature(@NotNull HierarchicalMethodSignature superSignatureHierarchical) {
PsiMethod superMethod = superSignatureHierarchical.getMethod();
PsiMethod method = getMethod();
if (PsiUtil.isAccessible(method.getProject(), superMethod, method, null)) {
if (mySupers == null)
mySupers = new SmartList<>();
mySupers.add(superSignatureHierarchical);
} else {
if (myInaccessibleSupers == null)
myInaccessibleSupers = new SmartList<>();
myInaccessibleSupers.add(superSignatureHierarchical);
}
}
use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.
the class InsertAfterEqualsHashCodeStrategy method insertNewMethod.
public PsiMethod insertNewMethod(PsiClass clazz, @NotNull PsiMethod newMethod, Editor editor) {
PsiMethod methodHashCode = PsiAdapter.findHashCodeMethod(clazz);
PsiMethod methodEquals = PsiAdapter.findEqualsMethod(clazz);
// if both methods exist determine the last method in the javafile
PsiMethod method;
if (methodEquals != null && methodHashCode != null) {
if (methodEquals.getTextOffset() > methodHashCode.getTextOffset()) {
method = methodEquals;
} else {
method = methodHashCode;
}
} else {
method = methodHashCode != null ? methodHashCode : methodEquals;
}
if (method != null) {
// insert after the equals/hashCode method
newMethod = (PsiMethod) clazz.addAfter(newMethod, method);
} else {
// no equals/hashCode so insert at caret
newMethod = InsertAtCaretStrategy.getInstance().insertNewMethod(clazz, newMethod, editor);
}
return newMethod;
}
use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.
the class ClassAccessVisitor method visitMethodCallExpression.
@Override
public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) {
super.visitMethodCallExpression(expression);
final PsiMethod method = expression.resolveMethod();
if (method == null) {
return;
}
final PsiClass calledClass = method.getContainingClass();
if (calledClass == null) {
return;
}
if (currentClass.equals(calledClass)) {
return;
}
final Set<PsiClass> overAccessedClasses = m_overAccessedClasses;
if (overAccessedClasses.contains(calledClass)) {
return;
}
if (LibraryUtil.classIsInLibrary(calledClass)) {
return;
}
if (PsiTreeUtil.isAncestor(currentClass, calledClass, true)) {
return;
}
if (PsiTreeUtil.isAncestor(calledClass, currentClass, true)) {
return;
}
PsiClass lexicallyEnclosingClass = currentClass;
while (lexicallyEnclosingClass != null) {
if (lexicallyEnclosingClass.isInheritor(calledClass, true)) {
return;
}
lexicallyEnclosingClass = ClassUtils.getContainingClass(lexicallyEnclosingClass);
}
final Map<PsiClass, Integer> accessCounts = m_accessCounts;
final Integer count = accessCounts.get(calledClass);
if (count == null) {
accessCounts.put(calledClass, 1);
} else if (count.equals(Integer.valueOf(1))) {
accessCounts.put(calledClass, 2);
} else {
overAccessedClasses.add(calledClass);
}
}
use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.
the class InlineCallFix method doFix.
@Override
public void doFix(final Project project, ProblemDescriptor descriptor) {
final PsiElement nameElement = descriptor.getPsiElement();
final PsiReferenceExpression methodExpression = (PsiReferenceExpression) nameElement.getParent();
if (methodExpression == null)
return;
final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) methodExpression.getParent();
final PsiMethod method = methodCallExpression.resolveMethod();
if (method == null)
return;
inline(project, methodExpression, method);
}
Aggregations