Search in sources :

Example 1 with GrEnumConstantInitializer

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

the class StubGenerator method writeEnumConstant.

@Override
public void writeEnumConstant(StringBuilder text, GrEnumConstant enumConstant) {
    text.append(enumConstant.getName());
    PsiMethod constructor = enumConstant.resolveMethod();
    if (constructor != null) {
        text.append('(');
        writeStubConstructorInvocation(text, constructor, PsiSubstitutor.EMPTY, enumConstant);
        text.append(')');
    }
    GrEnumConstantInitializer initializer = enumConstant.getInitializingClass();
    if (initializer != null) {
        text.append("{\n");
        for (PsiMethod method : initializer.getMethods()) {
            writeMethod(text, method);
        }
        text.append('}');
    }
}
Also used : GrEnumConstantInitializer(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumConstantInitializer) MethodSignatureBackedByPsiMethod(com.intellij.psi.util.MethodSignatureBackedByPsiMethod)

Example 2 with GrEnumConstantInitializer

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

the class ClassItemGeneratorImpl method writeEnumConstant.

@Override
public void writeEnumConstant(StringBuilder builder, GrEnumConstant constant) {
    GenerationUtil.writeDocComment(builder, constant, false);
    builder.append(constant.getName());
    final GrArgumentList argumentList = constant.getArgumentList();
    if (argumentList != null) {
        final GroovyResolveResult resolveResult = constant.advancedResolve();
        GrClosureSignature signature = GrClosureSignatureUtil.createSignature(resolveResult);
        new ArgumentListGenerator(builder, context.extend()).generate(signature, argumentList.getExpressionArguments(), argumentList.getNamedArguments(), GrClosableBlock.EMPTY_ARRAY, constant);
    }
    final GrEnumConstantInitializer anonymousBlock = constant.getInitializingClass();
    if (anonymousBlock != null) {
        builder.append("{\n");
        new ClassGenerator(classNameProvider, this).writeMembers(builder, anonymousBlock);
        builder.append("\n}");
    }
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrEnumConstantInitializer(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumConstantInitializer) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GrClosureSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature)

Example 3 with GrEnumConstantInitializer

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

the class GrEnumConstantImpl method getOrCreateInitializingClass.

@NotNull
@Override
public PsiEnumConstantInitializer getOrCreateInitializingClass() {
    final GrEnumConstantInitializer initializingClass = getInitializingClass();
    if (initializingClass != null)
        return initializingClass;
    final GrEnumConstantInitializer initializer = GroovyPsiElementFactory.getInstance(getProject()).createEnumConstantFromText("foo{}").getInitializingClass();
    LOG.assertTrue(initializer != null);
    final GrArgumentList argumentList = getArgumentList();
    if (argumentList != null) {
        return (PsiEnumConstantInitializer) addAfter(initializer, argumentList);
    } else {
        return (PsiEnumConstantInitializer) addAfter(initializer, getNameIdentifierGroovy());
    }
}
Also used : GrEnumConstantInitializer(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumConstantInitializer) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GrEnumConstantInitializer (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumConstantInitializer)3 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)2 MethodSignatureBackedByPsiMethod (com.intellij.psi.util.MethodSignatureBackedByPsiMethod)1 NotNull (org.jetbrains.annotations.NotNull)1 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)1 GrClosureSignature (org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature)1