ICompilationUnit iCUnit = type.getCompilationUnit() // convert iCUnit to CompilationUnit EnumConstantDeclaration constant = compilationUnit.getAST().newEnumConstantDeclaration(); constant.setName(parse.getAST().newSimpleName("constant name"));
@Override public EnumConstantSource setName(String name) { this.enumConstant.setName(ast.newSimpleName(name)); return this; }
@Override public EnumConstantSource setName(String name) { this.enumConstant.setName(ast.newSimpleName(name)); return this; }
/** * Add a constant to a Java 5 enum definition. This method is used for enums which use the name as the value. * * @param value constant * @param doc documentation text, or <code>null</code> if none */ public void addEnumConstant(String value, String doc) { if (m_class instanceof EnumDeclaration) { EnumConstantDeclaration enumdecl = getAST().newEnumConstantDeclaration(); enumdecl.setName(getAST().newSimpleName(value)); addJavaDoc(doc, enumdecl); ((EnumDeclaration)m_class).enumConstants().add(enumdecl); } else { // should not be possible, but just in case of added types in future throw new IllegalStateException("Internal error - cannot add constant to class type"); } }
/** * Add a constant to a Java 5 enum definition. This method is used for enums which have a value separate from the * name. * * @param name constant * @param doc documentation text, or <code>null</code> if none * @param value Value */ public void addEnumConstant(String name, String doc, String value) { if (m_class instanceof EnumDeclaration) { EnumConstantDeclaration enumdecl = getAST().newEnumConstantDeclaration(); enumdecl.setName(getAST().newSimpleName(name)); StringLiteral strlit = getAST().newStringLiteral(); strlit.setLiteralValue(value); enumdecl.arguments().add(strlit); addJavaDoc(doc, enumdecl); ((EnumDeclaration)m_class).enumConstants().add(enumdecl); } else { // should not be possible, but just in case of added types in future throw new IllegalStateException("Internal error - cannot add constant to class type"); } }
final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { if (property == JAVADOC_PROPERTY) { if (get) { return getJavadoc(); } else { setJavadoc((Javadoc) child); return null; } } if (property == NAME_PROPERTY) { if (get) { return getName(); } else { setName((SimpleName) child); return null; } } if (property == ANONYMOUS_CLASS_DECLARATION_PROPERTY) { if (get) { return getAnonymousClassDeclaration(); } else { setAnonymousClassDeclaration((AnonymousClassDeclaration) child); return null; } } // allow default implementation to flag the error return super.internalGetSetChildProperty(property, get, child); }
final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { if (property == JAVADOC_PROPERTY) { if (get) { return getJavadoc(); } else { setJavadoc((Javadoc) child); return null; } } if (property == NAME_PROPERTY) { if (get) { return getName(); } else { setName((SimpleName) child); return null; } } if (property == ANONYMOUS_CLASS_DECLARATION_PROPERTY) { if (get) { return getAnonymousClassDeclaration(); } else { setAnonymousClassDeclaration((AnonymousClassDeclaration) child); return null; } } // allow default implementation to flag the error return super.internalGetSetChildProperty(property, get, child); }
@Override final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { if (property == JAVADOC_PROPERTY) { if (get) { return getJavadoc(); } else { setJavadoc((Javadoc) child); return null; } } if (property == NAME_PROPERTY) { if (get) { return getName(); } else { setName((SimpleName) child); return null; } } if (property == ANONYMOUS_CLASS_DECLARATION_PROPERTY) { if (get) { return getAnonymousClassDeclaration(); } else { setAnonymousClassDeclaration((AnonymousClassDeclaration) child); return null; } } // allow default implementation to flag the error return super.internalGetSetChildProperty(property, get, child); }
final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { if (property == JAVADOC_PROPERTY) { if (get) { return getJavadoc(); } else { setJavadoc((Javadoc) child); return null; } } if (property == NAME_PROPERTY) { if (get) { return getName(); } else { setName((SimpleName) child); return null; } } if (property == ANONYMOUS_CLASS_DECLARATION_PROPERTY) { if (get) { return getAnonymousClassDeclaration(); } else { setAnonymousClassDeclaration((AnonymousClassDeclaration) child); return null; } } // allow default implementation to flag the error return super.internalGetSetChildProperty(property, get, child); }
ASTNode clone0(AST target) { EnumConstantDeclaration result = new EnumConstantDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setJavadoc( (Javadoc) ASTNode.copySubtree(target, getJavadoc())); result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); result.setName((SimpleName) getName().clone(target)); result.arguments().addAll(ASTNode.copySubtrees(target, arguments())); result.setAnonymousClassDeclaration( (AnonymousClassDeclaration) ASTNode.copySubtree(target, getAnonymousClassDeclaration())); return result; }
ASTNode clone0(AST target) { EnumConstantDeclaration result = new EnumConstantDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setJavadoc( (Javadoc) ASTNode.copySubtree(target, getJavadoc())); result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); result.setName((SimpleName) getName().clone(target)); result.arguments().addAll(ASTNode.copySubtrees(target, arguments())); result.setAnonymousClassDeclaration( (AnonymousClassDeclaration) ASTNode.copySubtree(target, getAnonymousClassDeclaration())); return result; }
ASTNode clone0(AST target) { EnumConstantDeclaration result = new EnumConstantDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setJavadoc( (Javadoc) ASTNode.copySubtree(target, getJavadoc())); result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); result.setName((SimpleName) getName().clone(target)); result.arguments().addAll(ASTNode.copySubtrees(target, arguments())); result.setAnonymousClassDeclaration( (AnonymousClassDeclaration) ASTNode.copySubtree(target, getAnonymousClassDeclaration())); return result; }
final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { if (property == JAVADOC_PROPERTY) { if (get) { return getJavadoc(); } else { setJavadoc((Javadoc) child); return null; } } if (property == NAME_PROPERTY) { if (get) { return getName(); } else { setName((SimpleName) child); return null; } } if (property == ANONYMOUS_CLASS_DECLARATION_PROPERTY) { if (get) { return getAnonymousClassDeclaration(); } else { setAnonymousClassDeclaration((AnonymousClassDeclaration) child); return null; } } // allow default implementation to flag the error return super.internalGetSetChildProperty(property, get, child); }
ASTNode clone0(AST target) { EnumConstantDeclaration result = new EnumConstantDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setJavadoc( (Javadoc) ASTNode.copySubtree(target, getJavadoc())); result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); result.setName((SimpleName) getName().clone(target)); result.arguments().addAll(ASTNode.copySubtrees(target, arguments())); result.setAnonymousClassDeclaration( (AnonymousClassDeclaration) ASTNode.copySubtree(target, getAnonymousClassDeclaration())); return result; }
ASTNode clone0(AST target) { EnumConstantDeclaration result = new EnumConstantDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setJavadoc( (Javadoc) ASTNode.copySubtree(target, getJavadoc())); result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); result.setName((SimpleName) getName().clone(target)); result.arguments().addAll(ASTNode.copySubtrees(target, arguments())); result.setAnonymousClassDeclaration( (AnonymousClassDeclaration) ASTNode.copySubtree(target, getAnonymousClassDeclaration())); return result; }
@Override ASTNode clone0(AST target) { EnumConstantDeclaration result = new EnumConstantDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setJavadoc( (Javadoc) ASTNode.copySubtree(target, getJavadoc())); result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers())); result.setName((SimpleName) getName().clone(target)); result.arguments().addAll(ASTNode.copySubtrees(target, arguments())); result.setAnonymousClassDeclaration( (AnonymousClassDeclaration) ASTNode.copySubtree(target, getAnonymousClassDeclaration())); return result; }
private ASTRewrite doAddEnumConst(CompilationUnit astRoot) { SimpleName node= fOriginalNode; ASTNode newTypeDecl= astRoot.findDeclaringNode(fSenderBinding); if (newTypeDecl == null) { astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey()); } if (newTypeDecl != null) { AST ast= newTypeDecl.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); EnumConstantDeclaration constDecl= ast.newEnumConstantDeclaration(); constDecl.setName(ast.newSimpleName(node.getIdentifier())); ListRewrite listRewriter= rewrite.getListRewrite(newTypeDecl, EnumDeclaration.ENUM_CONSTANTS_PROPERTY); listRewriter.insertLast(constDecl, null); return rewrite; } return null; }
private ASTRewrite doAddEnumConst(CompilationUnit astRoot) throws CoreException { SimpleName node= fOriginalNode; ASTNode newTypeDecl= astRoot.findDeclaringNode(fSenderBinding); if (newTypeDecl == null) { astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey()); } if (newTypeDecl != null) { AST ast= newTypeDecl.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); EnumConstantDeclaration constDecl= ast.newEnumConstantDeclaration(); constDecl.setName(ast.newSimpleName(node.getIdentifier())); ListRewrite listRewriter= rewrite.getListRewrite(newTypeDecl, EnumDeclaration.ENUM_CONSTANTS_PROPERTY); listRewriter.insertLast(constDecl, null); addLinkedPosition(rewrite.track(constDecl.getName()), false, KEY_NAME); return rewrite; } return null; }
private ASTRewrite doAddEnumConst(CompilationUnit astRoot) { SimpleName node= fOriginalNode; ASTNode newTypeDecl= astRoot.findDeclaringNode(fSenderBinding); if (newTypeDecl == null) { astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey()); } if (newTypeDecl != null) { AST ast= newTypeDecl.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); EnumConstantDeclaration constDecl= ast.newEnumConstantDeclaration(); constDecl.setName(ast.newSimpleName(node.getIdentifier())); ListRewrite listRewriter= rewrite.getListRewrite(newTypeDecl, EnumDeclaration.ENUM_CONSTANTS_PROPERTY); listRewriter.insertLast(constDecl, null); addLinkedPosition(rewrite.track(constDecl.getName()), false, KEY_NAME); return rewrite; } return null; }
private ASTRewrite doAddEnumConst(CompilationUnit astRoot) { SimpleName node= fOriginalNode; ASTNode newTypeDecl= astRoot.findDeclaringNode(fSenderBinding); if (newTypeDecl == null) { astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey()); } if (newTypeDecl != null) { AST ast= newTypeDecl.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); EnumConstantDeclaration constDecl= ast.newEnumConstantDeclaration(); constDecl.setName(ast.newSimpleName(node.getIdentifier())); ListRewrite listRewriter= rewrite.getListRewrite(newTypeDecl, EnumDeclaration.ENUM_CONSTANTS_PROPERTY); listRewriter.insertLast(constDecl, null); addLinkedPosition(rewrite.track(constDecl.getName()), false, KEY_NAME); return rewrite; } return null; }