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 public boolean visit(EnumConstantDeclaration node) { if (found(node, node.getName()) && this.resolveBinding) this.foundBinding = node.resolveVariable(); return true; }
void accept0(ASTVisitor visitor) { boolean visitChildren = visitor.visit(this); if (visitChildren) { // visit children in normal left to right reading order acceptChild(visitor, getJavadoc()); acceptChildren(visitor, this.modifiers); acceptChild(visitor, getName()); acceptChildren(visitor, this.arguments); acceptChild(visitor, getAnonymousClassDeclaration()); } visitor.endVisit(this); }
public boolean visit(EnumConstantDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); } printModifiers(node.modifiers()); node.getName().accept(this); if (!node.arguments().isEmpty()) { this.fBuffer.append("(");//$NON-NLS-1$ for (Iterator it= node.arguments().iterator(); it.hasNext();) { Expression e= (Expression) it.next(); e.accept(this); if (it.hasNext()) { this.fBuffer.append(",");//$NON-NLS-1$ } } this.fBuffer.append(")");//$NON-NLS-1$ } if (node.getAnonymousClassDeclaration() != null) { node.getAnonymousClassDeclaration().accept(this); } return false; }
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); }
public EnumConstantDeclaration convert(org.eclipse.jdt.internal.compiler.ast.FieldDeclaration enumConstant) { checkCanceled(); EnumConstantDeclaration enumConstantDeclaration = new EnumConstantDeclaration(this.ast); final SimpleName typeName = new SimpleName(this.ast); typeName.internalSetIdentifier(new String(enumConstant.name)); typeName.setSourceRange(enumConstant.sourceStart, enumConstant.sourceEnd - enumConstant.sourceStart + 1); enumConstantDeclaration.setName(typeName); int declarationSourceStart = enumConstant.declarationSourceStart; int declarationSourceEnd = enumConstant.declarationSourceEnd; if (end == -1) end = anonymousType.bodyEnd; anonymousClassDeclaration.setSourceRange(start, end - start + 1); enumConstantDeclaration.setAnonymousClassDeclaration(anonymousClassDeclaration); buildBodyDeclarations(anonymousType, anonymousClassDeclaration); if (this.resolveBindings) { anonymousClassDeclaration.resolveBinding(); enumConstantDeclaration.setSourceRange(declarationSourceStart, end - declarationSourceStart + 1); enumConstantDeclaration.setSourceRange(declarationSourceStart, declarationSourceEnd - declarationSourceStart + 1); enumConstantDeclaration.arguments().add(convert(arguments[i])); enumConstantDeclaration.setSourceRange(declarationSourceStart, declarationSourceEnd - declarationSourceStart + 1); recordNodes(enumConstantDeclaration, enumConstant); recordNodes(typeName, enumConstant); enumConstantDeclaration.resolveVariable();
int treeSize() { return memSize() + (this.optionalDocComment == null ? 0 : getJavadoc().treeSize()) + this.modifiers.listSize() + (this.constantName == null ? 0 : getName().treeSize()) + this.arguments.listSize() + (this.optionalAnonymousClassDeclaration == null ? 0 : getAnonymousClassDeclaration().treeSize()); } }
@Override public boolean visit(EnumConstantDeclaration node) { handleArguments(node.arguments(), this.options.alignment_for_arguments_in_enum_constant); AnonymousClassDeclaration anonymousClass = node.getAnonymousClassDeclaration(); if (anonymousClass != null) { forceContinuousWrapping(anonymousClass, this.tm.firstIndexIn(node.getName(), -1)); } return true; }
EnumConstantDeclaration constantDeclaration= (EnumConstantDeclaration) bodyDeclaration; EnumConstantDeclaration newConstDeclaration= targetAst.newEnumConstantDeclaration(); newConstDeclaration.setName((SimpleName) ASTNode.copySubtree(targetAst, constantDeclaration.getName())); AnonymousClassDeclaration anonymousDeclaration= constantDeclaration.getAnonymousClassDeclaration(); if (anonymousDeclaration != null) { String content= ASTNodes.getNodeSource(anonymousDeclaration, false, true); if (content != null) { newConstDeclaration.setAnonymousClassDeclaration((AnonymousClassDeclaration) rewrite.createStringPlaceholder(content, ASTNode.ANONYMOUS_CLASS_DECLARATION));
/** * Called only from visitFieldInitNode(node,context) */ private CAstNode createEnumConstantDeclarationInit(EnumConstantDeclaration node, WalkContext context) { String hiddenVariableName = (String) node.getProperty("com.ibm.wala.cast.java.translator.jdt.fakeValuesDeclName"); if (hiddenVariableName == null) { FieldReference fieldRef = fIdentityMapper.getFieldRef(node.resolveVariable()); // We use null to indicate an OBJECT_REF to a static field CAstNode lhsNode = makeNode(context, fFactory, node, CAstNode.OBJECT_REF, makeNode(context, fFactory, null, CAstNode.VOID), fFactory.makeConstant(fieldRef)); // CONSTRUCT ARGUMENTS & "new MyEnum(...)" statement ArrayList<Object> arguments = new ArrayList<>(); arguments.add(fFactory.makeConstant(node.getName().getIdentifier())); // name of constant arguments.add(fFactory.makeConstant(node.resolveVariable().getVariableId())); // id arguments.addAll(node.arguments()); CAstNode rhsNode = createClassInstanceCreation(node, arguments, node.resolveConstructorBinding(), null, node .getAnonymousClassDeclaration(), context); CAstNode assNode = makeNode(context, fFactory, node, CAstNode.ASSIGN, lhsNode, rhsNode); return assNode; // their naming, not mine } else { // String[] x = (new Direction[] { // NORTH, EAST, SOUTH, WEST, $VALUES, $VALUES$ // }); return null; } }
final List internalGetChildListProperty(ChildListPropertyDescriptor property) { if (property == MODIFIERS2_PROPERTY) { return modifiers(); } if (property == ARGUMENTS_PROPERTY) { return arguments(); } // allow default implementation to flag the error return super.internalGetChildListProperty(property); }
@Override public void endVisit(EnumConstantDeclaration node) { if (skipNode(node)) { return; } GenericSequentialFlowInfo info = processSequential(node, node.arguments()); process(info, node.getAnonymousClassDeclaration()); }
@Override public boolean visit(EnumConstantDeclaration node) { push(JavaNode.FIELD, node.getName().toString(), node.getStartPosition(), node.getLength()); return false; }
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; }
/** * Only called from createClassDeclaration. */ private CAstEntity visit(EnumConstantDeclaration decl) { return new FieldEntity(decl.getName().getIdentifier(), decl.resolveVariable().getType(), enumQuals, makePosition(decl .getStartPosition(), decl.getStartPosition() + decl.getLength()), null, makePosition(decl.getName())); }
private IMethodBinding[] getUnimplementedMethods(ASTNode typeNode) { ITypeBinding binding = null; boolean implementAbstractsOfInput = false; if (typeNode instanceof AnonymousClassDeclaration) { AnonymousClassDeclaration decl = (AnonymousClassDeclaration) typeNode; binding = decl.resolveBinding(); } else if (typeNode instanceof AbstractTypeDeclaration) { AbstractTypeDeclaration decl = (AbstractTypeDeclaration) typeNode; binding = decl.resolveBinding(); } else if (typeNode instanceof EnumConstantDeclaration) { EnumConstantDeclaration enumConstantDeclaration = (EnumConstantDeclaration) typeNode; if (enumConstantDeclaration.getAnonymousClassDeclaration() != null) { binding = enumConstantDeclaration.getAnonymousClassDeclaration().resolveBinding(); } else { IVariableBinding varBinding = enumConstantDeclaration.resolveVariable(); if (varBinding != null) { binding = varBinding.getDeclaringClass(); implementAbstractsOfInput = true; } } } if (binding == null) { return new IMethodBinding[0]; } IMethodBinding[] unimplementedMethods = StubUtility2Core.getUnimplementedMethods(binding, implementAbstractsOfInput); Arrays.sort(unimplementedMethods, new MethodsSourcePositionComparator(binding)); return unimplementedMethods; } }
pos= node.getStartPosition() + node.getLength(); // insert pos
AnonymousClassDeclaration getBody() { final EnumConstantDeclaration enumConstantDeclaration = (EnumConstantDeclaration) enumConstant.getInternal(); synchronized (enumConstantDeclaration) { AnonymousClassDeclaration result = enumConstantDeclaration.getAnonymousClassDeclaration(); if (result == null) { final String stub = "enum StubEnum { FOO() {}; }"; final JavaEnumSource temp = Roaster.parse(JavaEnumSource.class, stub); final AnonymousClassDeclaration body = ((EnumConstantBodyImpl) temp.getEnumConstants().get(0).getBody()) .getBody(); final AST ast = ((ASTNode) javaEnum.getInternal()).getAST(); result = (AnonymousClassDeclaration) ASTNode.copySubtree(ast, body); enumConstantDeclaration.setAnonymousClassDeclaration(result); } return result; } }
/** * 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"); } }
@Override public List<String> getConstructorArguments() { final List<String> result = new ArrayList<String>(); for (Object o : enumConstant.arguments()) { result.add(o.toString()); } return Collections.unmodifiableList(result); }