Search in sources :

Example 11 with GrReflectedMethod

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrReflectedMethod in project intellij-community by JetBrains.

the class StubGenerator method writeConstructor.

@Override
public void writeConstructor(final StringBuilder text, PsiMethod constructor, boolean isEnum) {
    LOG.assertTrue(constructor.isConstructor());
    if (!isEnum) {
        text.append("public ");
    //writeModifiers(text, constructor.getModifierList(), JAVA_MODIFIERS);
    }
    /************* name **********/
    //append constructor name
    text.append(constructor.getName());
    /************* parameters **********/
    GenerationUtil.writeParameterList(text, constructor.getParameterList().getParameters(), classNameProvider, null);
    final Set<String> throwsTypes = collectThrowsTypes(constructor, new THashSet<>());
    if (!throwsTypes.isEmpty()) {
        text.append("throws ").append(StringUtil.join(throwsTypes, ", ")).append(' ');
    }
    /************* body **********/
    text.append("{\n");
    if (constructor instanceof GrReflectedMethod) {
        constructor = ((GrReflectedMethod) constructor).getBaseMethod();
    }
    if (constructor instanceof GrMethod) {
        final GrConstructorInvocation invocation = PsiImplUtil.getChainingConstructorInvocation((GrMethod) constructor);
        if (invocation != null) {
            final GroovyResolveResult resolveResult = resolveChainingConstructor((GrMethod) constructor);
            if (resolveResult != null) {
                text.append(invocation.isSuperCall() ? "super(" : "this(");
                writeStubConstructorInvocation(text, (PsiMethod) resolveResult.getElement(), resolveResult.getSubstitutor(), invocation);
                text.append(");");
            }
        } else if (constructor instanceof LightElement) {
            writeStubConstructorInvocation(constructor, text);
        }
    }
    text.append("\n}\n");
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrConstructorInvocation(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrConstructorInvocation) GrReflectedMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrReflectedMethod) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) LightElement(com.intellij.psi.impl.light.LightElement)

Aggregations

GrReflectedMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrReflectedMethod)11 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)5 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)4 NotNull (org.jetbrains.annotations.NotNull)2 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)2 GrClosureSignature (org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature)2 GrConstructorInvocation (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrConstructorInvocation)2 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)2 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)2 GrClosureParameter (org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureParameter)2 CodeInsightSettings (com.intellij.codeInsight.CodeInsightSettings)1 PsiMethod (com.intellij.psi.PsiMethod)1 LightElement (com.intellij.psi.impl.light.LightElement)1 ArrayList (java.util.ArrayList)1 Nullable (org.jetbrains.annotations.Nullable)1 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)1 GrStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)1 GrOpenBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock)1 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)1 GrLightMethodBuilder (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder)1