use of com.intellij.psi.util.MethodSignatureBackedByPsiMethod in project intellij-community by JetBrains.
the class JavaLineMarkerProvider method getLineMarkerInfo.
@Override
@Nullable
public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) {
PsiElement parent;
if (element instanceof PsiIdentifier && (parent = element.getParent()) instanceof PsiMethod) {
if (!myOverridingOption.isEnabled() && !myImplementingOption.isEnabled())
return null;
PsiMethod method = (PsiMethod) parent;
MethodSignatureBackedByPsiMethod superSignature = SuperMethodsSearch.search(method, null, true, false).findFirst();
if (superSignature != null) {
boolean overrides = method.hasModifierProperty(PsiModifier.ABSTRACT) == superSignature.getMethod().hasModifierProperty(PsiModifier.ABSTRACT);
final Icon icon;
if (overrides) {
if (!myOverridingOption.isEnabled())
return null;
icon = AllIcons.Gutter.OverridingMethod;
} else {
if (!myImplementingOption.isEnabled())
return null;
icon = AllIcons.Gutter.ImplementingMethod;
}
return createSuperMethodLineMarkerInfo(element, icon, Pass.LINE_MARKERS);
}
}
final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(element);
final PsiElement firstChild = element.getFirstChild();
if (interfaceMethod != null && firstChild != null && myLambdaOption.isEnabled()) {
return createSuperMethodLineMarkerInfo(firstChild, AllIcons.Gutter.ImplementingFunctionalInterface, Pass.LINE_MARKERS);
}
if (myDaemonSettings.SHOW_METHOD_SEPARATORS && firstChild == null) {
PsiElement element1 = element;
boolean isMember = false;
while (element1 != null && !(element1 instanceof PsiFile) && element1.getPrevSibling() == null) {
element1 = element1.getParent();
if (element1 instanceof PsiMember) {
isMember = true;
break;
}
}
if (isMember && !(element1 instanceof PsiAnonymousClass || element1.getParent() instanceof PsiAnonymousClass)) {
PsiFile file = element1.getContainingFile();
Document document = file == null ? null : PsiDocumentManager.getInstance(file.getProject()).getLastCommittedDocument(file);
boolean drawSeparator = false;
if (document != null) {
CharSequence documentChars = document.getCharsSequence();
int category = getCategory(element1, documentChars);
for (PsiElement child = element1.getPrevSibling(); child != null; child = child.getPrevSibling()) {
int category1 = getCategory(child, documentChars);
if (category1 == 0)
continue;
drawSeparator = category != 1 || category1 != 1;
break;
}
}
if (drawSeparator) {
LineMarkerInfo info = new LineMarkerInfo<>(element, element.getTextRange(), null, Pass.LINE_MARKERS, FunctionUtil.<Object, String>nullConstant(), null, GutterIconRenderer.Alignment.RIGHT);
EditorColorsScheme scheme = myColorsManager.getGlobalScheme();
info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR);
info.separatorPlacement = SeparatorPlacement.TOP;
return info;
}
}
}
return null;
}
use of com.intellij.psi.util.MethodSignatureBackedByPsiMethod in project intellij-community by JetBrains.
the class MethodSuperSearcher method addSuperMethods.
private static boolean addSuperMethods(final HierarchicalMethodSignature signature, final PsiMethod method, final PsiClass parentClass, final boolean allowStaticMethod, final boolean checkBases, final Processor<MethodSignatureBackedByPsiMethod> consumer) {
PsiMethod signatureMethod = signature.getMethod();
PsiClass hisClass = signatureMethod.getContainingClass();
if (parentClass == null || InheritanceUtil.isInheritorOrSelf(parentClass, hisClass, true)) {
if (isAcceptable(signatureMethod, method, allowStaticMethod)) {
if (parentClass != null && !parentClass.equals(hisClass) && !checkBases) {
return true;
}
// method != method.getsuper()
LOG.assertTrue(signatureMethod != method, method);
//no need to check super classes
return consumer.process(signature);
}
}
for (HierarchicalMethodSignature superSignature : signature.getSuperSignatures()) {
if (MethodSignatureUtil.isSubsignature(superSignature, signature)) {
addSuperMethods(superSignature, method, parentClass, allowStaticMethod, checkBases, consumer);
}
}
return true;
}
use of com.intellij.psi.util.MethodSignatureBackedByPsiMethod in project intellij-community by JetBrains.
the class MethodSuperSearcher method execute.
@Override
public boolean execute(@NotNull final SuperMethodsSearch.SearchParameters queryParameters, @NotNull final Processor<MethodSignatureBackedByPsiMethod> consumer) {
final PsiClass parentClass = queryParameters.getPsiClass();
final PsiMethod method = queryParameters.getMethod();
return ApplicationManager.getApplication().runReadAction((Computable<Boolean>) () -> {
HierarchicalMethodSignature signature = method.getHierarchicalMethodSignature();
final boolean checkBases = queryParameters.isCheckBases();
final boolean allowStaticMethod = queryParameters.isAllowStaticMethod();
final List<HierarchicalMethodSignature> supers = signature.getSuperSignatures();
for (HierarchicalMethodSignature superSignature : supers) {
if (MethodSignatureUtil.isSubsignature(superSignature, signature)) {
if (!addSuperMethods(superSignature, method, parentClass, allowStaticMethod, checkBases, consumer))
return false;
}
}
return true;
});
}
use of com.intellij.psi.util.MethodSignatureBackedByPsiMethod in project intellij-community by JetBrains.
the class AnnotateMethodFix method applyFix.
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement psiElement = descriptor.getPsiElement();
PsiMethod method = PsiTreeUtil.getParentOfType(psiElement, PsiMethod.class);
if (method == null)
return;
final List<PsiMethod> toAnnotate = new ArrayList<>();
toAnnotate.add(method);
List<MethodSignatureBackedByPsiMethod> superMethodSignatures = method.findSuperMethodSignaturesIncludingStatic(true);
for (MethodSignatureBackedByPsiMethod superMethodSignature : superMethodSignatures) {
PsiMethod superMethod = superMethodSignature.getMethod();
if (!AnnotationUtil.isAnnotated(superMethod, myAnnotation, false, false) && superMethod.getManager().isInProject(superMethod)) {
int ret = shouldAnnotateBaseMethod(method, superMethod, project);
if (ret != 0 && ret != 1)
return;
if (ret == 0) {
toAnnotate.add(superMethod);
}
}
}
if (annotateOverriddenMethods()) {
PsiMethod[] methods = OverridingMethodsSearch.search(method).toArray(PsiMethod.EMPTY_ARRAY);
for (PsiMethod psiMethod : methods) {
if (AnnotationUtil.isAnnotatingApplicable(psiMethod, myAnnotation) && !AnnotationUtil.isAnnotated(psiMethod, myAnnotation, false, false) && psiMethod.getManager().isInProject(psiMethod)) {
toAnnotate.add(psiMethod);
}
}
}
FileModificationService.getInstance().preparePsiElementsForWrite(toAnnotate);
for (PsiMethod psiMethod : toAnnotate) {
annotateMethod(psiMethod);
}
UndoUtil.markPsiFileForUndo(method.getContainingFile());
}
use of com.intellij.psi.util.MethodSignatureBackedByPsiMethod in project intellij-community by JetBrains.
the class JavaArrangementVisitor method visitMethod.
@Override
public void visitMethod(PsiMethod method) {
boolean isSectionCommentsDetected = registerSectionComments(method);
final TextRange range = isSectionCommentsDetected ? getElementRangeWithoutComments(method) : method.getTextRange();
ArrangementSettingsToken type = method.isConstructor() ? CONSTRUCTOR : METHOD;
JavaElementArrangementEntry entry = createNewEntry(method, range, type, method.getName(), true);
if (entry == null) {
return;
}
processEntry(entry, method, method.getBody());
parseProperties(method, entry);
myInfo.onMethodEntryCreated(method, entry);
MethodSignatureBackedByPsiMethod overridden = SuperMethodsSearch.search(method, null, true, false).findFirst();
if (overridden != null) {
entry.addModifier(OVERRIDDEN);
myInfo.onOverriddenMethod(overridden.getMethod(), method);
}
boolean reset = myMethodBodyProcessor.setBaseMethod(method);
try {
method.accept(myMethodBodyProcessor);
} finally {
if (reset) {
myMethodBodyProcessor.setBaseMethod(null);
}
}
}
Aggregations