Search in sources :

Example 26 with GroovyScriptClass

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass in project intellij-community by JetBrains.

the class ClassGenerator method writeTypeDefinition.

public void writeTypeDefinition(StringBuilder text, @NotNull final PsiClass typeDefinition, boolean toplevel, boolean insertPackageSmst) {
    final boolean isScript = typeDefinition instanceof GroovyScriptClass;
    final GroovyFile containingFile = (GroovyFile) typeDefinition.getContainingFile();
    if (insertPackageSmst) {
        writePackageStatement(text, containingFile.getPackageDefinition());
    }
    GenerationUtil.writeDocComment(text, typeDefinition, true);
    boolean isEnum = typeDefinition.isEnum();
    boolean isAnnotationType = typeDefinition.isAnnotationType();
    boolean isInterface = typeDefinition.isInterface();
    ModifierListGenerator.writeClassModifiers(text, typeDefinition.getModifierList(), typeDefinition.isInterface(), typeDefinition.isEnum(), toplevel, classItemGenerator.generateAnnotations());
    if (isAnnotationType) {
        text.append('@');
    }
    if (isInterface) {
        text.append("interface");
    } else if (isEnum) {
        text.append("enum");
    } else {
        text.append("class");
    }
    text.append(' ').append(typeDefinition.getName());
    GenerationUtil.writeTypeParameters(text, typeDefinition, classNameProvider);
    text.append(' ');
    if (isScript) {
        text.append("extends ").append(GroovyCommonClassNames.GROOVY_LANG_SCRIPT).append(' ');
    } else if (!isEnum && !isAnnotationType) {
        classItemGenerator.writeExtendsList(text, typeDefinition);
        classItemGenerator.writeImplementsList(text, typeDefinition);
    }
    text.append("{\n");
    writeMembers(text, typeDefinition);
    text.append('}');
}
Also used : GroovyScriptClass(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile)

Aggregations

GroovyScriptClass (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass)26 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)8 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)6 PsiElement (com.intellij.psi.PsiElement)4 NotNull (org.jetbrains.annotations.NotNull)4 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)3 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)3 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)3 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)3 GrMember (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember)3 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)3 GrImportStatement (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement)3 PsiClass (com.intellij.psi.PsiClass)2 LightMethodBuilder (com.intellij.psi.impl.light.LightMethodBuilder)2 GrDocComment (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment)2 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)2 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)2 GrPackageDefinition (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition)2 Template (com.intellij.codeInsight.template.Template)1 TemplateManager (com.intellij.codeInsight.template.TemplateManager)1