use of com.intellij.psi.util.MethodSignatureBackedByPsiMethod in project intellij-community by JetBrains.
the class GroovyLineMarkerProvider method getLineMarkerInfo.
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) {
final PsiElement parent = element.getParent();
if (parent instanceof PsiNameIdentifierOwner) {
if (parent instanceof GrField && element == ((GrField) parent).getNameIdentifierGroovy()) {
for (GrAccessorMethod method : GroovyPropertyUtils.getFieldAccessors((GrField) parent)) {
MethodSignatureBackedByPsiMethod superSignature = SuperMethodsSearch.search(method, null, true, false).findFirst();
if (superSignature != null) {
PsiMethod superMethod = superSignature.getMethod();
boolean overrides = method.hasModifierProperty(PsiModifier.ABSTRACT) == superMethod.hasModifierProperty(PsiModifier.ABSTRACT) || superMethod.getBody() != null && GrTraitUtil.isTrait(superMethod.getContainingClass());
final Icon icon = overrides ? AllIcons.Gutter.OverridingMethod : AllIcons.Gutter.ImplementingMethod;
final MarkerType type = GroovyMarkerTypes.OVERRIDING_PROPERTY_TYPE;
return new LineMarkerInfo<>(element, element.getTextRange(), icon, Pass.LINE_MARKERS, type.getTooltip(), type.getNavigationHandler(), GutterIconRenderer.Alignment.LEFT);
}
}
} else if (parent instanceof GrMethod && element == ((GrMethod) parent).getNameIdentifierGroovy() && hasSuperMethods((GrMethod) element.getParent())) {
final Icon icon = AllIcons.Gutter.OverridingMethod;
final MarkerType type = GroovyMarkerTypes.GR_OVERRIDING_METHOD;
return new LineMarkerInfo<>(element, element.getTextRange(), icon, Pass.LINE_MARKERS, type.getTooltip(), type.getNavigationHandler(), GutterIconRenderer.Alignment.LEFT);
}
}
//need to draw method separator above docComment
if (myDaemonSettings.SHOW_METHOD_SEPARATORS && element.getFirstChild() == null) {
PsiElement element1 = element;
boolean isMember = false;
while (element1 != null && !(element1 instanceof PsiFile) && element1.getPrevSibling() == null) {
element1 = element1.getParent();
if (element1 instanceof PsiMember || element1 instanceof GrVariableDeclarationImpl) {
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 = getGroovyCategory(element1, documentChars);
for (PsiElement child = element1.getPrevSibling(); child != null; child = child.getPrevSibling()) {
int category1 = getGroovyCategory(child, documentChars);
if (category1 == 0)
continue;
drawSeparator = category != 1 || category1 != 1;
break;
}
}
if (drawSeparator) {
GrDocComment comment = null;
if (element1 instanceof GrDocCommentOwner) {
comment = ((GrDocCommentOwner) element1).getDocComment();
}
LineMarkerInfo info = new LineMarkerInfo<>(element, comment != null ? comment.getTextRange() : 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 StubGenerator method writeMethod.
@Override
public void writeMethod(StringBuilder text, PsiMethod method) {
if (method == null)
return;
String name = method.getName();
if (!PsiNameHelper.getInstance(method.getProject()).isIdentifier(name)) {
//does not have a java image
return;
}
boolean isAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT);
PsiModifierList modifierList = method.getModifierList();
ModifierListGenerator.writeModifiers(text, modifierList, STUB_MODIFIERS, false);
if (method.hasTypeParameters()) {
GenerationUtil.writeTypeParameters(text, method, classNameProvider);
text.append(' ');
}
//append return type
PsiType retType = method.getReturnType();
if (retType == null) {
retType = TypesUtil.getJavaLangObject(method);
}
if (!method.hasModifierProperty(PsiModifier.STATIC)) {
final List<MethodSignatureBackedByPsiMethod> superSignatures = method.findSuperMethodSignaturesIncludingStatic(true);
for (MethodSignatureBackedByPsiMethod superSignature : superSignatures) {
final PsiType superType = superSignature.getSubstitutor().substitute(superSignature.getMethod().getReturnType());
if (superType != null && !superType.isAssignableFrom(retType) && !(PsiUtil.resolveClassInType(superType) instanceof PsiTypeParameter)) {
retType = superType;
}
}
}
TypeWriter.writeType(text, retType, method, classNameProvider);
text.append(' ');
text.append(name);
GenerationUtil.writeParameterList(text, method.getParameterList().getParameters(), classNameProvider, null);
writeThrowsList(text, method);
if (!isAbstract && !method.hasModifierProperty(PsiModifier.NATIVE)) {
/************* body **********/
text.append("{\nreturn ");
text.append(GroovyToJavaGenerator.getDefaultValueText(retType.getCanonicalText()));
text.append(";\n}");
} else {
text.append(';');
}
text.append('\n');
}
use of com.intellij.psi.util.MethodSignatureBackedByPsiMethod in project intellij-community by JetBrains.
the class DeprecationInspection method checkMethodOverridesDeprecated.
private static void checkMethodOverridesDeprecated(MethodSignatureBackedByPsiMethod methodSignature, List<MethodSignatureBackedByPsiMethod> superMethodSignatures, boolean ignoreAbstractDeprecatedOverrides, ProblemsHolder holder) {
PsiMethod method = methodSignature.getMethod();
PsiElement methodName = method.getNameIdentifier();
if (methodName == null)
return;
for (MethodSignatureBackedByPsiMethod superMethodSignature : superMethodSignatures) {
PsiMethod superMethod = superMethodSignature.getMethod();
PsiClass aClass = superMethod.getContainingClass();
if (aClass == null)
continue;
// do not show deprecated warning for class implementing deprecated methods
if (ignoreAbstractDeprecatedOverrides && !aClass.isDeprecated() && superMethod.hasModifierProperty(PsiModifier.ABSTRACT))
continue;
if (superMethod.isDeprecated()) {
String description = JavaErrorMessages.message("overrides.deprecated.method", HighlightMessageUtil.getSymbolName(aClass));
holder.registerProblem(methodName, description, ProblemHighlightType.LIKE_DEPRECATED);
}
}
}
use of com.intellij.psi.util.MethodSignatureBackedByPsiMethod in project intellij-community by JetBrains.
the class PsiMethodTreeElement method getLocationString.
@Override
public String getLocationString() {
if (!Registry.is("show.method.base.class.in.java.file.structure"))
return null;
final PsiMethod method = getElement();
if (myLocation == null && method != null && !DumbService.isDumb(method.getProject())) {
if (isInherited()) {
return super.getLocationString();
} else {
try {
final MethodSignatureBackedByPsiMethod baseMethod = SuperMethodsSearch.search(method, null, true, false).findFirst();
if (baseMethod != null && !method.isEquivalentTo(baseMethod.getMethod())) {
PsiMethod base = baseMethod.getMethod();
PsiClass baseClass = base.getContainingClass();
if (baseClass != null) /*&& !CommonClassNames.JAVA_LANG_OBJECT.equals(baseClass.getQualifiedName())*/
{
if (baseClass.getMethods().length > 1) {
myLocation = baseClass.getName();
}
}
}
} catch (IndexNotReadyException e) {
//some searchers (EJB) require indices. What shall we do?
}
if (StringUtil.isEmpty(myLocation)) {
myLocation = "";
} else {
char upArrow = '↑';
myLocation = UIUtil.getLabelFont().canDisplay(upArrow) ? upArrow + myLocation : myLocation;
}
}
}
return StringUtil.isEmpty(myLocation) ? null : myLocation;
}
use of com.intellij.psi.util.MethodSignatureBackedByPsiMethod in project intellij-community by JetBrains.
the class GDKSuperMethodSearcher method execute.
@Override
public boolean execute(@NotNull SuperMethodsSearch.SearchParameters queryParameters, @NotNull Processor<MethodSignatureBackedByPsiMethod> consumer) {
final PsiMethod method = queryParameters.getMethod();
if (!(method instanceof GrMethod)) {
return true;
}
if (method.hasModifierProperty(PsiModifier.STATIC))
return true;
final PsiClass psiClass = method.getContainingClass();
if (psiClass == null)
return true;
final HierarchicalMethodSignature hierarchicalSignature = method.getHierarchicalMethodSignature();
if (!hierarchicalSignature.getSuperSignatures().isEmpty())
return true;
final Project project = method.getProject();
final String name = method.getName();
final MethodResolverProcessor processor = new MethodResolverProcessor(name, ((GrMethod) method), false, null, null, PsiType.EMPTY_ARRAY);
ResolveUtil.processNonCodeMembers(JavaPsiFacade.getElementFactory(project).createType(psiClass), processor, (GrMethod) method, ResolveState.initial());
final GroovyResolveResult[] candidates = processor.getCandidates();
final PsiManager psiManager = PsiManager.getInstance(project);
final MethodSignature signature = method.getHierarchicalMethodSignature();
List<PsiMethod> goodSupers = new ArrayList<>();
for (GroovyResolveResult candidate : candidates) {
final PsiElement element = candidate.getElement();
if (element instanceof PsiMethod) {
final PsiMethod m = (PsiMethod) element;
if (!isTheSameMethod(method, psiManager, m) && PsiImplUtil.isExtendsSignature(m.getHierarchicalMethodSignature(), signature)) {
goodSupers.add(m);
}
}
}
if (goodSupers.isEmpty())
return true;
List<PsiMethod> result = new ArrayList<>(goodSupers.size());
result.add(goodSupers.get(0));
final Comparator<PsiMethod> comparator = (o1, o2) -> {
//compare by first parameter type
final PsiType type1 = getRealType(o1);
final PsiType type2 = getRealType(o2);
if (TypesUtil.isAssignableByMethodCallConversion(type1, type2, o1)) {
return -1;
} else if (TypesUtil.isAssignableByMethodCallConversion(type2, type1, o1)) {
return 1;
}
return 0;
};
Outer: for (PsiMethod current : goodSupers) {
for (Iterator<PsiMethod> i = result.iterator(); i.hasNext(); ) {
PsiMethod m = i.next();
final int res = comparator.compare(m, current);
if (res > 0) {
continue Outer;
} else if (res < 0) {
i.remove();
}
}
result.add(current);
}
for (PsiMethod psiMethod : result) {
if (!consumer.process(getRealMethod(psiMethod).getHierarchicalMethodSignature())) {
return false;
}
}
return true;
}
Aggregations