use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumTypeDefinition in project intellij-community by JetBrains.
the class MoveGroovyMemberHandler method addEnumConstant.
private static PsiElement addEnumConstant(PsiClass targetClass, GrEnumConstant constant, @Nullable PsiElement anchor) {
if (targetClass instanceof GrEnumTypeDefinition) {
final GrEnumTypeDefinition enumeration = (GrEnumTypeDefinition) targetClass;
final GrEnumConstantList constantList = enumeration.getEnumConstantList();
if (constantList != null) {
ASTNode node = constantList.getNode();
node.addLeaf(GroovyTokenTypes.mCOMMA, ",", node.getFirstChildNode());
return constantList.addBefore(constant, constantList.getFirstChild());
} else {
final PsiElement parent = constant.getParent();
assert parent instanceof GrEnumConstantList;
final GrEnumConstantList constListCopy = ((GrEnumConstantList) targetClass.add(parent));
return constListCopy.getEnumConstants()[0];
}
}
return (anchor != null ? targetClass.addAfter(constant, anchor) : targetClass.add(constant));
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumTypeDefinition in project intellij-community by JetBrains.
the class GrIntroduceFieldProcessor method insertField.
@NotNull
protected GrVariableDeclaration insertField(@NotNull PsiClass targetClass) {
GrVariableDeclaration declaration = createField(targetClass);
if (targetClass instanceof GrEnumTypeDefinition) {
final GrEnumConstantList enumConstants = ((GrEnumTypeDefinition) targetClass).getEnumConstantList();
return (GrVariableDeclaration) targetClass.addAfter(declaration, enumConstants);
}
if (targetClass instanceof GrTypeDefinition) {
PsiElement anchor = getAnchorForDeclaration((GrTypeDefinition) targetClass);
return (GrVariableDeclaration) targetClass.addAfter(declaration, anchor);
} else {
assert targetClass instanceof GroovyScriptClass;
final GroovyFile file = ((GroovyScriptClass) targetClass).getContainingFile();
PsiElement[] elements = file.getMethods();
if (elements.length == 0)
elements = file.getStatements();
final PsiElement anchor = ArrayUtil.getFirstElement(elements);
return (GrVariableDeclaration) file.addBefore(declaration, anchor);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumTypeDefinition in project intellij-community by JetBrains.
the class GrIntroduceConstantProcessor method addDeclaration.
protected GrVariableDeclaration addDeclaration(PsiClass targetClass) {
GrVariableDeclaration declaration = createField(targetClass);
final GrVariableDeclaration added;
if (targetClass instanceof GrEnumTypeDefinition) {
final GrEnumConstantList enumConstants = ((GrEnumTypeDefinition) targetClass).getEnumConstantList();
added = (GrVariableDeclaration) targetClass.addAfter(declaration, enumConstants);
} else {
added = ((GrVariableDeclaration) targetClass.add(declaration));
}
JavaCodeStyleManager.getInstance(added.getProject()).shortenClassReferences(added);
return added;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumTypeDefinition 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);
}
Aggregations