Search in sources :

Example 31 with MethodSignature

use of com.intellij.psi.util.MethodSignature in project intellij-community by JetBrains.

the class StubGenerator method collectMethods.

@Override
public Collection<PsiMethod> collectMethods(PsiClass typeDefinition) {
    List<PsiMethod> methods = new ArrayList<>();
    for (PsiMethod method : typeDefinition.getMethods()) {
        if (method instanceof DelegatedMethod) {
            PsiMethod prototype = ((DelegatedMethod) method).getPrototype();
            PsiClass aClass = prototype.getContainingClass();
            if (prototype.hasModifierProperty(PsiModifier.FINAL) && aClass != null && typeDefinition.isInheritor(aClass, true)) {
                //skip final super methods
                continue;
            }
        }
        methods.add(method);
    }
    boolean isClass = !typeDefinition.isInterface() && !typeDefinition.isAnnotationType() && !typeDefinition.isEnum() && !(typeDefinition instanceof GroovyScriptClass);
    if (isClass) {
        final Collection<MethodSignature> toOverride = OverrideImplementExploreUtil.getMethodSignaturesToOverride(typeDefinition);
        for (MethodSignature signature : toOverride) {
            if (!(signature instanceof MethodSignatureBackedByPsiMethod))
                continue;
            final PsiMethod method = ((MethodSignatureBackedByPsiMethod) signature).getMethod();
            final PsiClass baseClass = method.getContainingClass();
            if (baseClass == null)
                continue;
            final String qname = baseClass.getQualifiedName();
            if (GroovyCommonClassNames.GROOVY_OBJECT.equals(qname) || GroovyCommonClassNames.GROOVY_OBJECT_SUPPORT.equals(qname) || method.hasModifierProperty(PsiModifier.ABSTRACT) && typeDefinition.isInheritor(baseClass, true)) {
                if (method.isConstructor())
                    continue;
                methods.add(mirrorMethod(typeDefinition, method, baseClass, signature.getSubstitutor()));
            }
        }
        final Collection<MethodSignature> toImplement = OverrideImplementExploreUtil.getMethodSignaturesToImplement(typeDefinition);
        for (MethodSignature signature : toImplement) {
            if (!(signature instanceof MethodSignatureBackedByPsiMethod))
                continue;
            final PsiMethod resolved = ((MethodSignatureBackedByPsiMethod) signature).getMethod();
            final PsiClass baseClass = resolved.getContainingClass();
            if (baseClass == null)
                continue;
            if (!GroovyCommonClassNames.GROOVY_OBJECT.equals(baseClass.getQualifiedName()))
                continue;
            methods.add(mirrorMethod(typeDefinition, resolved, baseClass, signature.getSubstitutor()));
        }
    }
    return methods;
}
Also used : DelegatedMethod(org.jetbrains.plugins.groovy.lang.resolve.ast.DelegatedMethod) MethodSignatureBackedByPsiMethod(com.intellij.psi.util.MethodSignatureBackedByPsiMethod) GroovyScriptClass(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass) MethodSignature(com.intellij.psi.util.MethodSignature) MethodSignatureBackedByPsiMethod(com.intellij.psi.util.MethodSignatureBackedByPsiMethod)

Aggregations

MethodSignature (com.intellij.psi.util.MethodSignature)31 Nullable (org.jetbrains.annotations.Nullable)8 NotNull (org.jetbrains.annotations.NotNull)7 ArrayList (java.util.ArrayList)5 Map (java.util.Map)4 com.intellij.psi (com.intellij.psi)3 List (java.util.List)3 GrClosureSignature (org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature)3 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 Logger (com.intellij.openapi.diagnostic.Logger)2 TextRange (com.intellij.openapi.util.TextRange)2 CandidateInfo (com.intellij.psi.infos.CandidateInfo)2 MethodCandidateInfo (com.intellij.psi.infos.MethodCandidateInfo)2 Processor (com.intellij.util.Processor)2 GrSignature (org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature)2 GrClosureType (org.jetbrains.plugins.groovy.lang.psi.impl.GrClosureType)2 OverrideImplementExploreUtil (com.intellij.codeInsight.generation.OverrideImplementExploreUtil)1 RedundantLambdaCodeBlockInspection (com.intellij.codeInspection.RedundantLambdaCodeBlockInspection)1 FindBundle (com.intellij.find.FindBundle)1 InjectedLanguageManager (com.intellij.lang.injection.InjectedLanguageManager)1