Search in sources :

Example 1 with GrMembersDeclaration

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

the class GrIntroduceFieldProcessor method getAnchorForDeclaration.

@Nullable
private static PsiElement getAnchorForDeclaration(@NotNull GrTypeDefinition targetClass) {
    final GrTypeDefinitionBody body = targetClass.getBody();
    if (body == null)
        return null;
    PsiElement anchor = body.getLBrace();
    final GrMembersDeclaration[] declarations = targetClass.getMemberDeclarations();
    for (GrMembersDeclaration declaration : declarations) {
        if (declaration instanceof GrVariableDeclaration)
            anchor = declaration;
        if (!(declaration instanceof GrVariableDeclaration))
            return anchor;
    }
    return anchor;
}
Also used : GrTypeDefinitionBody(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody) GrMembersDeclaration(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMembersDeclaration) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with GrMembersDeclaration

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

the class GrDocCommentUtil method findDocOwner.

@Nullable
public static GrDocCommentOwner findDocOwner(GroovyDocPsiElement docElement) {
    PsiElement element = docElement;
    while (element != null && element.getParent() instanceof GroovyDocPsiElement) element = element.getParent();
    if (element == null)
        return null;
    element = skipWhiteSpacesAndStopOnDoc(element, true);
    if (element instanceof GrDocCommentOwner)
        return (GrDocCommentOwner) element;
    if (element instanceof GrMembersDeclaration) {
        GrMember[] members = ((GrMembersDeclaration) element).getMembers();
        if (members.length > 0 && members[0] instanceof GrDocCommentOwner) {
            return (GrDocCommentOwner) members[0];
        }
    }
    return null;
}
Also used : GroovyDocPsiElement(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GroovyDocPsiElement) GrMember(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember) GrMembersDeclaration(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMembersDeclaration) GrDocCommentOwner(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner) PsiElement(com.intellij.psi.PsiElement) GroovyDocPsiElement(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GroovyDocPsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with GrMembersDeclaration

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

the class ClassGenerator method writeMembers.

public void writeMembers(StringBuilder text, PsiClass typeDefinition) {
    if (typeDefinition instanceof GrEnumTypeDefinition) {
        final GrEnumConstant[] enumConstants = ((GrEnumTypeDefinition) typeDefinition).getEnumConstants();
        for (GrEnumConstant constant : enumConstants) {
            classItemGenerator.writeEnumConstant(text, constant);
            text.append(',');
        }
        if (enumConstants.length > 0) {
            //text.removeFromTheEnd(1).append(";\n");
            text.delete(text.length() - 1, text.length());
        }
        text.append(";\n");
    }
    writeAllMethods(text, classItemGenerator.collectMethods(typeDefinition), typeDefinition);
    if (typeDefinition instanceof GrTypeDefinition) {
        for (GrMembersDeclaration declaration : ((GrTypeDefinition) typeDefinition).getMemberDeclarations()) {
            if (declaration instanceof GrVariableDeclaration) {
                classItemGenerator.writeVariableDeclarations(text, (GrVariableDeclaration) declaration);
            }
        }
        for (PsiClass inner : typeDefinition.getInnerClasses()) {
            writeTypeDefinition(text, inner, false, false);
            text.append('\n');
        }
    }
    classItemGenerator.writePostponed(text, typeDefinition);
}
Also used : GrVariableDeclaration(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration) GrEnumTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumTypeDefinition) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) GrMembersDeclaration(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMembersDeclaration) GrEnumConstant(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstant) PsiClass(com.intellij.psi.PsiClass)

Aggregations

GrMembersDeclaration (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMembersDeclaration)3 Nullable (org.jetbrains.annotations.Nullable)2 PsiClass (com.intellij.psi.PsiClass)1 PsiElement (com.intellij.psi.PsiElement)1 GrDocCommentOwner (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner)1 GroovyDocPsiElement (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GroovyDocPsiElement)1 GrVariableDeclaration (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration)1 GrEnumTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumTypeDefinition)1 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)1 GrTypeDefinitionBody (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody)1 GrEnumConstant (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstant)1 GrMember (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember)1