use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstantList 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.members.GrEnumConstantList 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.members.GrEnumConstantList 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;
}
Aggregations