List of usage examples for org.eclipse.jdt.core.dom EnumDeclaration getName
public SimpleName getName()
From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(EnumDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); }// w w w . j a va 2 s .c o m printModifiers(node.modifiers()); this.fBuffer.append("enum ");//$NON-NLS-1$ node.getName().accept(this); this.fBuffer.append(" ");//$NON-NLS-1$ if (!node.superInterfaceTypes().isEmpty()) { this.fBuffer.append("implements ");//$NON-NLS-1$ for (Iterator<Type> it = node.superInterfaceTypes().iterator(); it.hasNext();) { Type t = it.next(); t.accept(this); if (it.hasNext()) { this.fBuffer.append(", ");//$NON-NLS-1$ } } this.fBuffer.append(" ");//$NON-NLS-1$ } this.fBuffer.append("{");//$NON-NLS-1$ for (Iterator<EnumConstantDeclaration> it = node.enumConstants().iterator(); it.hasNext();) { EnumConstantDeclaration d = it.next(); d.accept(this); // enum constant declarations do not include punctuation if (it.hasNext()) { // enum constant declarations are separated by commas this.fBuffer.append(", ");//$NON-NLS-1$ } } if (!node.bodyDeclarations().isEmpty()) { this.fBuffer.append("; ");//$NON-NLS-1$ for (Iterator<BodyDeclaration> it = node.bodyDeclarations().iterator(); it.hasNext();) { BodyDeclaration d = it.next(); d.accept(this); // other body declarations include trailing punctuation } } this.fBuffer.append("}");//$NON-NLS-1$ return false; }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(EnumDeclaration node) { boa.types.Ast.Declaration.Builder b = boa.types.Ast.Declaration.newBuilder(); // b.setPosition(pos.build()); b.setName(node.getName().getFullyQualifiedName()); b.setKind(boa.types.Ast.TypeKind.ENUM); // TODO//from ww w.java 2 s . c om declarations.peek().add(b.build()); return false; }
From source file:br.uff.ic.mergeguider.javaparser.DepVisitor.java
@Override public boolean visit(EnumDeclaration node) { String className;//from w w w. j ava 2s . com PackageDeclaration aPackage = cu.getPackage(); if (aPackage != null) { String packageName = aPackage.getName().getFullyQualifiedName(); className = packageName + "." + node.getName().getIdentifier(); } else { className = null; } classLanguageContructs = new ClassLanguageContructs(className, path); classLanguageConstructsList.add(classLanguageContructs); simpleNames = new ArrayList<>(); simpleNamesList.add(simpleNames); return true; }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(EnumDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); }/*from w ww. j ava 2 s .c om*/ printIndent(); printModifiers(node.modifiers()); this.buffer.append("enum ");//$NON-NLS-1$ node.getName().accept(this); this.buffer.append(" ");//$NON-NLS-1$ if (!node.superInterfaceTypes().isEmpty()) { this.buffer.append("implements ");//$NON-NLS-1$ for (Iterator it = node.superInterfaceTypes().iterator(); it.hasNext();) { Type t = (Type) it.next(); t.accept(this); if (it.hasNext()) { this.buffer.append(", ");//$NON-NLS-1$ } } this.buffer.append(" ");//$NON-NLS-1$ } this.buffer.append("{");//$NON-NLS-1$ for (Iterator it = node.enumConstants().iterator(); it.hasNext();) { EnumConstantDeclaration d = (EnumConstantDeclaration) it.next(); d.accept(this); // enum constant declarations do not include punctuation if (it.hasNext()) { // enum constant declarations are separated by commas this.buffer.append(", ");//$NON-NLS-1$ } } if (!node.bodyDeclarations().isEmpty()) { this.buffer.append("; ");//$NON-NLS-1$ for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext();) { BodyDeclaration d = (BodyDeclaration) it.next(); d.accept(this); // other body declarations include trailing punctuation } } this.buffer.append("}\n");//$NON-NLS-1$ return false; }
From source file:com.bsiag.eclipse.jdt.java.formatter.LineBreaksPreparator.java
License:Open Source License
@Override public boolean visit(EnumDeclaration node) { handleBracedCode(node, node.getName(), this.options.brace_position_for_enum_declaration, this.options.indent_body_declarations_compare_to_enum_declaration_header, this.options.insert_new_line_in_empty_enum_declaration); handleBodyDeclarations(node.bodyDeclarations()); List<EnumConstantDeclaration> enumConstants = node.enumConstants(); for (int i = 0; i < enumConstants.size(); i++) { EnumConstantDeclaration declaration = enumConstants.get(i); if (declaration.getJavadoc() != null) this.tm.firstTokenIn(declaration, TokenNameCOMMENT_JAVADOC).breakBefore(); if (declaration.getAnonymousClassDeclaration() != null && i < enumConstants.size() - 1) this.tm.firstTokenAfter(declaration, TokenNameCOMMA).breakAfter(); }// ww w . jav a2s . c om // put breaks after semicolons int index = enumConstants.isEmpty() ? this.tm.firstIndexAfter(node.getName(), TokenNameLBRACE) + 1 : this.tm.firstIndexAfter(enumConstants.get(enumConstants.size() - 1), -1); for (;; index++) { Token token = this.tm.get(index); if (token.isComment()) continue; if (token.tokenType == TokenNameSEMICOLON) token.breakAfter(); else break; } this.declarationModifierVisited = false; return true; }
From source file:com.bsiag.eclipse.jdt.java.formatter.linewrap.WrapPreparator.java
License:Open Source License
@Override public boolean visit(EnumDeclaration node) { List<EnumConstantDeclaration> enumConstants = node.enumConstants(); if (!enumConstants.isEmpty()) { for (EnumConstantDeclaration constant : enumConstants) this.wrapIndexes.add(this.tm.firstIndexIn(constant, -1)); this.wrapParentIndex = this.tm.firstIndexBefore(enumConstants.get(0), TokenNameLBRACE); this.wrapGroupEnd = this.tm.lastIndexIn(enumConstants.get(enumConstants.size() - 1), -1); handleWrap(this.options.alignment_for_enum_constants, node); }/* w ww. j a v a 2 s.c o m*/ List<Type> superInterfaceTypes = node.superInterfaceTypes(); if (!superInterfaceTypes.isEmpty()) { this.wrapIndexes.add(this.tm.firstIndexBefore(superInterfaceTypes.get(0), TokenNameimplements)); for (Type type : superInterfaceTypes) this.wrapIndexes.add(this.tm.firstIndexIn(type, -1)); this.wrapParentIndex = this.tm.lastIndexIn(node.getName(), -1); this.wrapGroupEnd = this.tm.lastIndexIn(superInterfaceTypes.get(superInterfaceTypes.size() - 1), -1); this.wrapPenalties.add(PREFERRED); handleWrap(this.options.alignment_for_superinterfaces_in_enum_declaration, node); } if (this.options.align_type_members_on_columns) this.fieldAligner.prepareAlign(node.bodyDeclarations()); return true; }
From source file:com.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java
License:Open Source License
@Override public boolean visit(EnumDeclaration node) { handleToken(node.getName(), TokenNameLBRACE, this.options.insert_space_before_opening_brace_in_enum_declaration, false); handleCommas(node.enumConstants(), this.options.insert_space_before_comma_in_enum_declarations, this.options.insert_space_after_comma_in_enum_declarations); return true;//from w w w . j a v a 2 s. co m }
From source file:com.codenvy.ide.ext.java.server.internal.core.util.DOMFinder.java
License:Open Source License
public boolean visit(EnumDeclaration node) { if (found(node, node.getName()) && this.resolveBinding) this.foundBinding = node.resolveBinding(); return true;// w w w. j av a 2 s .com }
From source file:com.google.dart.java2dart.SyntaxTranslator.java
License:Open Source License
@Override public boolean visit(org.eclipse.jdt.core.dom.EnumConstantDeclaration node) { String fieldName = node.getName().getIdentifier(); IMethodBinding constructorBinding = node.resolveConstructorBinding(); // prepare enum name org.eclipse.jdt.core.dom.EnumDeclaration parentEnum = (org.eclipse.jdt.core.dom.EnumDeclaration) node .getParent();/*w w w .j a v a 2 s .c om*/ String enumTypeName = parentEnum.getName().getIdentifier(); // may be create Dart top-level class for Java inner class String innerClassName = null; { AnonymousClassDeclaration anoClassDeclaration = node.getAnonymousClassDeclaration(); if (anoClassDeclaration != null) { innerClassName = enumTypeName + "_" + fieldName; declareInnerClass(constructorBinding, anoClassDeclaration, innerClassName, new String[] { "String", ENUM_NAME_FIELD_NAME, "int", ENUM_ORDINAL_FIELD_NAME }); } } // prepare field type TypeName type = typeName(enumTypeName); // prepare field variables List<VariableDeclaration> variables = Lists.newArrayList(); { List<Expression> argList = translateArguments(null, node.arguments()); { int ordinal = parentEnum.enumConstants().indexOf(node); argList.add(0, integer(ordinal)); argList.add(0, string(fieldName)); } InstanceCreationExpression init; if (innerClassName == null) { init = instanceCreationExpression(Keyword.NEW, typeName(enumTypeName), argList); context.getConstructorDescription(constructorBinding).instanceCreations.add(init); } else { init = instanceCreationExpression(Keyword.NEW, typeName(innerClassName), argList); } variables.add(variableDeclaration(fieldName, init)); } return done(fieldDeclaration(translateJavadoc(node), true, Keyword.FINAL, type, variables)); }
From source file:com.google.dart.java2dart.SyntaxTranslator.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public boolean visit(org.eclipse.jdt.core.dom.EnumDeclaration node) { SimpleIdentifier name = translateSimpleName(node.getName()); // implements ImplementsClause implementsClause;// w ww .j av a 2 s . c om { List<TypeName> interfaces = Lists.newArrayList(); // add Comparable interfaces.add(typeName("Comparable", typeName(name))); // add declared interfaces if (!node.superInterfaceTypes().isEmpty()) { for (Object javaInterface : node.superInterfaceTypes()) { interfaces.add((TypeName) translate((org.eclipse.jdt.core.dom.ASTNode) javaInterface)); } } // create ImplementsClause implementsClause = new ImplementsClause(null, interfaces); } // members List<ClassMember> members = Lists.newArrayList(); { // constants List<Expression> valuesList = Lists.newArrayList(); for (Object javaConst : node.enumConstants()) { org.eclipse.jdt.core.dom.EnumConstantDeclaration javaEnumConst = (org.eclipse.jdt.core.dom.EnumConstantDeclaration) javaConst; members.add((FieldDeclaration) translate(javaEnumConst)); valuesList.add(identifier(javaEnumConst.getName().getIdentifier())); } // values members.add(fieldDeclaration(true, Keyword.FINAL, listType(typeName(name), 1), variableDeclaration("values", listLiteral(valuesList)))); // body declarations members.add(fieldDeclaration(eolDocComment(ENUM_NAME_FIELD_COMMENT), false, Keyword.FINAL, typeName("String"), variableDeclaration(ENUM_NAME_FIELD_NAME))); members.add(fieldDeclaration(eolDocComment(ENUM_ORDINAL_FIELD_COMMENT), false, Keyword.FINAL, typeName("int"), variableDeclaration(ENUM_ORDINAL_FIELD_NAME))); boolean hasConstructor = false; for (Iterator<?> I = node.bodyDeclarations().iterator(); I.hasNext();) { org.eclipse.jdt.core.dom.BodyDeclaration javaBodyDecl = (org.eclipse.jdt.core.dom.BodyDeclaration) I .next(); constructorImpl = null; ClassMember member = translate(javaBodyDecl); members.add(member); if (constructorImpl != null) { members.add(constructorImpl); } if (javaBodyDecl instanceof org.eclipse.jdt.core.dom.MethodDeclaration) { if (((org.eclipse.jdt.core.dom.MethodDeclaration) javaBodyDecl).isConstructor()) { hasConstructor = true; } } } // add default constructor, use artificial constructor if (!hasConstructor) { org.eclipse.jdt.core.dom.MethodDeclaration ac = node.getAST().newMethodDeclaration(); try { ac.setConstructor(true); ac.setName(node.getAST().newSimpleName(name.getName())); ac.setBody(node.getAST().newBlock()); node.bodyDeclarations().add(ac); ConstructorDeclaration innerConstructor = translate(ac); members.add(innerConstructor); if (constructorImpl != null) { members.add(constructorImpl); } } finally { node.bodyDeclarations().remove(ac); } } // compareTo() members.add(methodDeclaration(typeName("int"), identifier("compareTo"), formalParameterList(simpleFormalParameter(typeName(name), "other")), expressionFunctionBody(binaryExpression(identifier(ENUM_ORDINAL_FIELD_NAME), TokenType.MINUS, propertyAccess(identifier("other"), identifier(ENUM_ORDINAL_FIELD_NAME)))))); // toString() members.add(methodDeclaration(typeName("String"), identifier("toString"), formalParameterList(), expressionFunctionBody(identifier(ENUM_NAME_FIELD_NAME)))); } return done(classDeclaration(translateJavadoc(node), name, null, null, implementsClause, members)); }