Search in sources :

Example 1 with DelegatedMethod

use of org.jetbrains.plugins.groovy.lang.resolve.ast.DelegatedMethod 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)1 MethodSignatureBackedByPsiMethod (com.intellij.psi.util.MethodSignatureBackedByPsiMethod)1 GroovyScriptClass (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass)1 DelegatedMethod (org.jetbrains.plugins.groovy.lang.resolve.ast.DelegatedMethod)1