List of usage examples for org.eclipse.jdt.core.dom EnumDeclaration superInterfaceTypes
ASTNode.NodeList superInterfaceTypes
To view the source code for org.eclipse.jdt.core.dom EnumDeclaration superInterfaceTypes.
Click Source Link
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. jav a 2s .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:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(EnumDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); }/*w w w .ja va 2s . 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.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); }/*www . j a va 2s. co 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.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;/*from w ww. j av a 2 s . c o m*/ { 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)); }
From source file:com.google.devtools.j2cpp.types.HeaderImportCollector.java
License:Open Source License
@Override public boolean visit(EnumDeclaration node) { addSuperType("JavaLangEnum", "java.lang.Enum", false); for (Iterator<?> iterator = node.superInterfaceTypes().iterator(); iterator.hasNext();) { Object o = iterator.next(); if (o instanceof Type) { addSuperType((Type) o); } else {//from ww w . j a v a2 s. c om throw new AssertionError("unknown AST type: " + o.getClass()); } } return true; }
From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java
License:Apache License
/** Visitor method for {@link EnumDeclaration}s. */ @Override/*from ww w . ja v a2 s. c o m*/ public boolean visit(EnumDeclaration node) { sync(node); builder.open(ZERO); visitAndBreakModifiers(node.modifiers(), Direction.VERTICAL, Optional.<BreakTag>absent()); builder.open(plusFour); token("enum"); builder.breakOp(" "); visit(node.getName()); builder.close(); builder.close(); if (!node.superInterfaceTypes().isEmpty()) { builder.open(plusFour); builder.breakOp(" "); builder.open(plusFour); token("implements"); builder.breakOp(" "); builder.open(ZERO); boolean first = true; for (Type superInterfaceType : (List<Type>) node.superInterfaceTypes()) { if (!first) { token(","); builder.breakToFill(" "); } superInterfaceType.accept(this); first = false; } builder.close(); builder.close(); builder.close(); } builder.space(); tokenBreakTrailingComment("{", plusTwo); if (node.enumConstants().isEmpty() && node.bodyDeclarations().isEmpty()) { builder.open(ZERO); builder.blankLineWanted(BlankLineWanted.NO); token("}"); builder.close(); } else { builder.open(plusTwo); builder.blankLineWanted(BlankLineWanted.NO); builder.forcedBreak(); builder.open(ZERO); boolean first = true; for (EnumConstantDeclaration enumConstant : (List<EnumConstantDeclaration>) node.enumConstants()) { if (!first) { token(","); builder.forcedBreak(); } visit(enumConstant); first = false; } if (builder.peekToken().or("").equals(",")) { token(","); builder.forcedBreak(); // The ";" goes on its own line. } builder.close(); builder.close(); builder.open(ZERO); if (node.bodyDeclarations().isEmpty()) { builder.guessToken(";"); } else { token(";"); builder.forcedBreak(); addBodyDeclarations(node.bodyDeclarations(), BracesOrNot.NO, FirstDeclarationsOrNot.NO); } builder.forcedBreak(); builder.blankLineWanted(BlankLineWanted.NO); token("}", plusTwo); builder.close(); } builder.guessToken(";"); return false; }
From source file:com.kodebeagle.javaparser.MethodInvocationResolver.java
License:Apache License
@Override public boolean visit(org.eclipse.jdt.core.dom.EnumDeclaration ed) { String typeFullyQualifiedName = removeSpecialSymbols(ed.getName().getFullyQualifiedName()); if (ed.superInterfaceTypes() != null && ed.superInterfaceTypes().size() > 0) { List<Object> interfaces = ed.superInterfaceTypes(); typeToInterfacesFullyQualifiedName.put(typeFullyQualifiedName, interfaces); }/*from w ww. ja va 2s. c o m*/ typesInFile.push(ed.getName().getFullyQualifiedName()); TypeDecl obj = new TypeDecl(typeFullyQualifiedName, ed.getName().getStartPosition()); typeDeclarations.add(obj); addTypeDoc(ed, typeFullyQualifiedName); return true; }
From source file:de.fkoeberle.autocommit.message.java.helper.delta.TypeDelta.java
License:Open Source License
private static boolean isSuperInterfaceListChange(EnumDeclaration oldTypeDeclaration, EnumDeclaration newTypeDeclaration) { List<?> oldInterfaces = oldTypeDeclaration.superInterfaceTypes(); List<?> newInterfaces = newTypeDeclaration.superInterfaceTypes(); return ASTCompareUtil.listsOfASTNodesDiffer(oldInterfaces, newInterfaces); }
From source file:edu.uci.ics.sourcerer.extractor.ast.ReferenceExtractorVisitor.java
License:Open Source License
/** * This method writes:/* ww w . j a v a 2 s . co m*/ * <ul> * <li>Enum entity to <code>IEntityWriter</code>. * <ul> * <li>Inside relation to <code>IRelationWriter</code>.</li> * <li>Implements relation to <code>IRelationWriter</code>.</li> * <li>Parametrized by relation to <code>IRelationWriter</code>.</li> * <li>Synthesized constructors to <code>IEntityWriter</code>. * <ul> * <li>Inside relation to <code>IRelationWriter</code>.</li> * </ul></li> * </ul></li> * </ul> * * Enum qualified names (FQNs) adhere to the following format: * <ul> * <li>Top-level: package fqn + . + simple name</li> * <li>Member: parent fqn + $ + simple name</li> * </ul> */ @SuppressWarnings("unchecked") @Override public boolean visit(EnumDeclaration node) { // Get the fqn String fqn = null; if (node.isPackageMemberTypeDeclaration()) { fqn = fqnStack.getTypeFqn(node.getName().getIdentifier()); } else if (node.isMemberTypeDeclaration()) { fqn = fqnStack.getFqn() + "$" + node.getName().getIdentifier(); } else if (node.isLocalTypeDeclaration()) { logger.log(Level.WARNING, "Can't have local enums! eclipse error"); fqnStack.push(null, null); return false; } else { logger.log(Level.SEVERE, "Unsure what type the declaration is!"); fqn = "(ERROR)"; } // Write the entity entityWriter.writeEnum(fqn, node.getModifiers(), MetricsCalculator.computeLinesOfCode(getSource(node)), getLocation(node)); // Write the inside relation relationWriter.writeInside(fqn, fqnStack.getFqn(), getUnknownLocation()); // Write the implements relation for (Type superInterfaceType : (List<Type>) node.superInterfaceTypes()) { relationWriter.writeImplements(fqn, getTypeFqn(superInterfaceType), getLocation(superInterfaceType)); } ITypeBinding binding = node.resolveBinding(); if (binding != null) { // Write out the synthesized constructors for (IMethodBinding method : binding.getDeclaredMethods()) { if (method.isDefaultConstructor()) { // Write the entity String constructorFqn = getMethodFqn(method, true); entityWriter.writeConstructor(constructorFqn, method.getModifiers(), MetricsCalculator.computeLinesOfCode(getSource(node)), getUnknownLocation()); // Write the inside relation relationWriter.writeInside(constructorFqn, fqn, getUnknownLocation()); } } } fqnStack.push(fqn, Entity.ENUM); accept(node.getJavadoc()); accept(node.enumConstants()); accept(node.bodyDeclarations()); return false; }
From source file:edu.uci.ics.sourcerer.tools.java.extractor.eclipse.ReferenceExtractorVisitor.java
License:Open Source License
/** * This method writes://from www . j ava 2s .c om * <ul> * <li>Enum entity to <code>IEntityWriter</code>. * <ul> * <li>Inside relation to <code>IRelationWriter</code>.</li> * <li>Implements relation to <code>IRelationWriter</code>.</li> * <li>Parametrized by relation to <code>IRelationWriter</code>.</li> * <li>Synthesized constructors to <code>IEntityWriter</code>. * <ul> * <li>Inside relation to <code>IRelationWriter</code>.</li> * </ul></li> * </ul></li> * </ul> * * Enum qualified names (FQNs) adhere to the following format: * <ul> * <li>Top-level: package fqn + . + simple name</li> * <li>Member: parent fqn + $ + simple name</li> * </ul> */ @SuppressWarnings("unchecked") @Override public boolean visit(EnumDeclaration node) { // Get the fqn String fqn = null; if (node.isPackageMemberTypeDeclaration()) { fqn = fqnStack.peek(EnclosingPackage.class).getTypeFqn(node.getName().getIdentifier()); } else if (node.isMemberTypeDeclaration()) { fqn = fqnStack.peek(EnclosingDeclaredType.class).getMemberFqn(node.getName().getIdentifier()); } else if (node.isLocalTypeDeclaration()) { throw new IllegalStateException("Can't have local enums!"); } else { logger.log(Level.SEVERE, "Unsure what type the declaration is!"); fqn = "(ERROR)"; } String parentFqn = fqnStack.getFqn(); fqnStack.push(fqn, Entity.ENUM); // Visit the children accept(node.getJavadoc()); accept(node.enumConstants()); accept(node.bodyDeclarations()); Location unknown = createUnknownLocation(); // Write the entity entityWriter.writeEntity(Entity.ENUM, fqn, node.getModifiers(), createMetrics(node), createLocation(node)); // Write the contains relation relationWriter.writeRelation(Relation.CONTAINS, parentFqn, fqn, unknown); // Write the implements relation for (Type superInterfaceType : (List<Type>) node.superInterfaceTypes()) { relationWriter.writeRelation(Relation.IMPLEMENTS, fqn, getTypeFqn(superInterfaceType), createLocation(superInterfaceType)); } // Write the extends relation relationWriter.writeRelation(Relation.EXTENDS, fqn, "java.lang.Enum<" + fqn + ">", unknown); ITypeBinding binding = node.resolveBinding(); if (binding != null) { // Write out the synthesized constructors for (IMethodBinding method : binding.getDeclaredMethods()) { if (method.isDefaultConstructor()) { // Write the entity String constructorFqn = getMethodName(method, true); entityWriter.writeEntity(Entity.CONSTRUCTOR, constructorFqn, "()", null, method.getModifiers(), createMetrics(node), unknown); constructorFqn += "()"; // Write the contains relation relationWriter.writeRelation(Relation.CONTAINS, fqn, constructorFqn, unknown); // Write the calls relation relationWriter.writeRelation(Relation.CALLS, constructorFqn, "java.lang.Enum.<init>(java.lang.String,int)", unknown); } } } // Write the values method { String methodFqn = fqn + ".values"; entityWriter.writeEntity(Entity.METHOD, methodFqn, "()", null, 9, null, unknown); methodFqn += "()"; relationWriter.writeRelation(Relation.CONTAINS, fqn, methodFqn, unknown); relationWriter.writeRelation(Relation.RETURNS, methodFqn, fqn + "[]", unknown); } // Write the valueOf method { String methodFqn = fqn + ".valueOf"; entityWriter.writeEntity(Entity.METHOD, methodFqn, "(java.lang.String)", null, 9, null, unknown); methodFqn += "(java.lang.String)"; relationWriter.writeRelation(Relation.CONTAINS, fqn, methodFqn, unknown); relationWriter.writeRelation(Relation.RETURNS, methodFqn, fqn, unknown); localVariableWriter.writeLocalVariable(LocalVariable.PARAM, "name", 0, "java.lang.String", unknown, methodFqn, 0, unknown); } fqnStack.pop(); return false; }