List of usage examples for org.eclipse.jdt.core.dom AnnotationTypeDeclaration bodyDeclarations
public List bodyDeclarations()
From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(AnnotationTypeDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); }/*from ww w. j av a2 s. c om*/ printModifiers(node.modifiers()); this.fBuffer.append("@interface ");//$NON-NLS-1$ node.getName().accept(this); this.fBuffer.append(" {");//$NON-NLS-1$ for (Iterator<BodyDeclaration> it = node.bodyDeclarations().iterator(); it.hasNext();) { BodyDeclaration d = it.next(); d.accept(this); } this.fBuffer.append("}");//$NON-NLS-1$ return false; }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(AnnotationTypeDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); }//from w w w . j av a 2s . com printIndent(); printModifiers(node.modifiers()); this.buffer.append("@interface ");//$NON-NLS-1$ node.getName().accept(this); this.buffer.append(" {");//$NON-NLS-1$ for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext();) { BodyDeclaration d = (BodyDeclaration) it.next(); d.accept(this); } 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(AnnotationTypeDeclaration node) { handleBracedCode(node, node.getName(), this.options.brace_position_for_annotation_type_declaration, this.options.indent_body_declarations_compare_to_annotation_declaration_header, this.options.insert_new_line_in_empty_annotation_declaration); handleBodyDeclarations(node.bodyDeclarations()); if (node.getModifiers() == 0) this.tm.firstTokenBefore(node.getName(), TokenNameAT).breakBefore(); this.declarationModifierVisited = false; return true;/*from w w w . jav a2 s . co m*/ }
From source file:com.bsiag.eclipse.jdt.java.formatter.linewrap.WrapPreparator.java
License:Open Source License
@Override public boolean visit(AnnotationTypeDeclaration node) { if (this.options.align_type_members_on_columns) this.fieldAligner.prepareAlign(node.bodyDeclarations()); return true;// w w w . j a va 2 s . c o m }
From source file:com.github.parzonka.ccms.engine.SortElementsOperation.java
License:Open Source License
private ASTRewrite sortCompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit ast, final TextEditGroup group) { ast.accept(new ASTVisitor() { @Override// w ww. ja va 2 s .c o m public boolean visit(org.eclipse.jdt.core.dom.CompilationUnit compilationUnit) { final List<AbstractTypeDeclaration> types = compilationUnit.types(); for (final Iterator<AbstractTypeDeclaration> iter = types.iterator(); iter.hasNext();) { final AbstractTypeDeclaration typeDeclaration = iter.next(); typeDeclaration.setProperty(CompilationUnitSorter.RELATIVE_ORDER, new Integer(typeDeclaration.getStartPosition())); compilationUnit.setProperty(CONTAINS_MALFORMED_NODES, Boolean.valueOf(isMalformed(typeDeclaration))); } return true; } @Override public boolean visit(AnnotationTypeDeclaration annotationTypeDeclaration) { final List bodyDeclarations = annotationTypeDeclaration.bodyDeclarations(); for (final Iterator iter = bodyDeclarations.iterator(); iter.hasNext();) { final BodyDeclaration bodyDeclaration = (BodyDeclaration) iter.next(); bodyDeclaration.setProperty(CompilationUnitSorter.RELATIVE_ORDER, new Integer(bodyDeclaration.getStartPosition())); annotationTypeDeclaration.setProperty(CONTAINS_MALFORMED_NODES, Boolean.valueOf(isMalformed(bodyDeclaration))); } return true; } @Override public boolean visit(AnonymousClassDeclaration anonymousClassDeclaration) { final List bodyDeclarations = anonymousClassDeclaration.bodyDeclarations(); for (final Iterator iter = bodyDeclarations.iterator(); iter.hasNext();) { final BodyDeclaration bodyDeclaration = (BodyDeclaration) iter.next(); bodyDeclaration.setProperty(CompilationUnitSorter.RELATIVE_ORDER, new Integer(bodyDeclaration.getStartPosition())); anonymousClassDeclaration.setProperty(CONTAINS_MALFORMED_NODES, Boolean.valueOf(isMalformed(bodyDeclaration))); } return true; } @Override public boolean visit(TypeDeclaration typeDeclaration) { final List bodyDeclarations = typeDeclaration.bodyDeclarations(); for (final Iterator iter = bodyDeclarations.iterator(); iter.hasNext();) { final BodyDeclaration bodyDeclaration = (BodyDeclaration) iter.next(); bodyDeclaration.setProperty(CompilationUnitSorter.RELATIVE_ORDER, new Integer(bodyDeclaration.getStartPosition())); typeDeclaration.setProperty(CONTAINS_MALFORMED_NODES, Boolean.valueOf(isMalformed(bodyDeclaration))); } return true; } @Override public boolean visit(EnumDeclaration enumDeclaration) { final List bodyDeclarations = enumDeclaration.bodyDeclarations(); for (final Iterator iter = bodyDeclarations.iterator(); iter.hasNext();) { final BodyDeclaration bodyDeclaration = (BodyDeclaration) iter.next(); bodyDeclaration.setProperty(CompilationUnitSorter.RELATIVE_ORDER, new Integer(bodyDeclaration.getStartPosition())); enumDeclaration.setProperty(CONTAINS_MALFORMED_NODES, Boolean.valueOf(isMalformed(bodyDeclaration))); } final List enumConstants = enumDeclaration.enumConstants(); for (final Iterator iter = enumConstants.iterator(); iter.hasNext();) { final EnumConstantDeclaration enumConstantDeclaration = (EnumConstantDeclaration) iter.next(); enumConstantDeclaration.setProperty(CompilationUnitSorter.RELATIVE_ORDER, new Integer(enumConstantDeclaration.getStartPosition())); enumDeclaration.setProperty(CONTAINS_MALFORMED_NODES, Boolean.valueOf(isMalformed(enumConstantDeclaration))); } return true; } }); final ASTRewrite rewriter = ASTRewrite.create(ast.getAST()); final boolean[] hasChanges = new boolean[] { false }; ast.accept(new ASTVisitor() { /** * This * * @param elements * @param listRewrite */ private void sortElements(List<BodyDeclaration> elements, ListRewrite listRewrite) { if (elements.size() == 0) return; final List<BodyDeclaration> myCopy = new ArrayList<BodyDeclaration>(); myCopy.addAll(elements); // orderexperiment final List<Signature> methods = new ArrayList<Signature>(); for (final BodyDeclaration bd : myCopy) { if (bd.getNodeType() == ASTNode.METHOD_DECLARATION) { methods.add(new Signature((MethodDeclaration) bd)); } } Collections.sort(methods, ((BodyDeclarationComparator) SortElementsOperation.this.comparator) .getMethodDeclarationComparator()); logger.info("Sorting of methods based on appearance:"); int j = 0; for (final Signature sig : methods) { logger.info("Method [{}] : {}", ++j, sig); } Collections.sort(myCopy, SortElementsOperation.this.comparator); logger.info("Final sorting order just before the AST-Rewrite:"); for (final BodyDeclaration bd : myCopy) { if (bd.getNodeType() == ASTNode.METHOD_DECLARATION) { logger.info("{}", new Signature((MethodDeclaration) bd)); } else { logger.info("{}", bd.toString()); } } for (int i = 0; i < elements.size(); i++) { final BodyDeclaration oldNode = elements.get(i); final BodyDeclaration newNode = myCopy.get(i); if (oldNode != newNode) { if (oldNode.getNodeType() == ASTNode.METHOD_DECLARATION && newNode.getNodeType() == ASTNode.METHOD_DECLARATION) { final Signature oldMethodSignature = new Signature((MethodDeclaration) oldNode); final Signature newMethodSignature = new Signature((MethodDeclaration) newNode); logger.trace("Swapping [{}]for [{}]", oldMethodSignature, newMethodSignature); } else { logger.trace("Swapping [{}]for [{}]", oldNode.getNodeType(), newNode.getNodeType()); } listRewrite.replace(oldNode, rewriter.createMoveTarget(newNode), group); hasChanges[0] = true; } } } @Override public boolean visit(org.eclipse.jdt.core.dom.CompilationUnit compilationUnit) { if (checkMalformedNodes(compilationUnit)) { logger.warn("Malformed nodes. Aborting sorting of current element."); return true; } sortElements(compilationUnit.types(), rewriter.getListRewrite(compilationUnit, org.eclipse.jdt.core.dom.CompilationUnit.TYPES_PROPERTY)); return true; } @Override public boolean visit(AnnotationTypeDeclaration annotationTypeDeclaration) { if (checkMalformedNodes(annotationTypeDeclaration)) { logger.warn("Malformed nodes. Aborting sorting of current element."); return true; } sortElements(annotationTypeDeclaration.bodyDeclarations(), rewriter.getListRewrite( annotationTypeDeclaration, AnnotationTypeDeclaration.BODY_DECLARATIONS_PROPERTY)); return true; } @Override public boolean visit(AnonymousClassDeclaration anonymousClassDeclaration) { if (checkMalformedNodes(anonymousClassDeclaration)) { logger.warn("Malformed nodes. Aborting sorting of current element."); return true; } sortElements(anonymousClassDeclaration.bodyDeclarations(), rewriter.getListRewrite( anonymousClassDeclaration, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY)); return true; } @Override public boolean visit(TypeDeclaration typeDeclaration) { if (checkMalformedNodes(typeDeclaration)) { logger.warn("Malformed nodes. Aborting sorting of current element."); return true; } sortElements(typeDeclaration.bodyDeclarations(), rewriter.getListRewrite(typeDeclaration, TypeDeclaration.BODY_DECLARATIONS_PROPERTY)); return true; } @Override public boolean visit(EnumDeclaration enumDeclaration) { if (checkMalformedNodes(enumDeclaration)) { return true; // abort sorting of current element } sortElements(enumDeclaration.bodyDeclarations(), rewriter.getListRewrite(enumDeclaration, EnumDeclaration.BODY_DECLARATIONS_PROPERTY)); sortElements(enumDeclaration.enumConstants(), rewriter.getListRewrite(enumDeclaration, EnumDeclaration.ENUM_CONSTANTS_PROPERTY)); return true; } }); if (!hasChanges[0]) return null; return rewriter; }
From source file:com.google.devtools.j2cpp.translate.DeadCodeEliminator.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//w w w . j a v a 2 s. co m public void endVisit(AnnotationTypeDeclaration node) { eliminateDeadCode(node.resolveBinding(), node.bodyDeclarations()); // All annotations are stripped, so we can remove all annotation members. removeAnnotationMembers(node.bodyDeclarations()); finishElimination(); }
From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java
License:Apache License
/** Visitor method for {@link AnnotationTypeDeclaration}s. */ @Override//from www .java 2 s .co m public boolean visit(AnnotationTypeDeclaration node) { sync(node); builder.open(ZERO); visitAndBreakModifiers(node.modifiers(), Direction.VERTICAL, Optional.<BreakTag>absent()); builder.open(ZERO); token("@"); token("interface"); builder.breakOp(" "); visit(node.getName()); builder.close(); builder.close(); if (node.bodyDeclarations() == null) { builder.open(plusFour); token(";"); builder.close(); } else { addBodyDeclarations(node.bodyDeclarations(), BracesOrNot.YES, FirstDeclarationsOrNot.YES); } builder.guessToken(";"); return false; }
From source file:edu.uci.ics.sourcerer.extractor.ast.ReferenceExtractorVisitor.java
License:Open Source License
/** * This method writes://from w ww .ja va 2 s. com *<ul> * <li>For any annotation declaration: * <ul> * <li>Annotation entity to <code>IEntityWriter</code>.</li> * <li>Inside relation to <code>IRelationWriter</code>.</li> * </ul></li> *</ul> */ @SuppressWarnings("unchecked") @Override public boolean visit(AnnotationTypeDeclaration node) { // Get the fqn String fqn = null; if (node.isPackageMemberTypeDeclaration()) { fqn = fqnStack.getTypeFqn(node.getName().getIdentifier()); } else if (node.isMemberTypeDeclaration()) { if (node.getName().getIdentifier().length() > 0) { fqn = fqnStack.getMemberFqn(node.getName().getIdentifier()); } else { logger.severe("A annotation declaration should not declare an annonymous type!"); fqn = fqnStack.getAnonymousClassFqn(); } } else if (node.isLocalTypeDeclaration()) { ITypeBinding binding = node.resolveBinding(); fqn = fqnStack.getLocalFqn(node.getName().getIdentifier(), binding); } else { logger.severe("Unsure what type the declaration is!"); fqn = "(ERROR)" + node.getName().getIdentifier(); } // Write the entity entityWriter.writeAnnotation(fqn, node.getModifiers(), MetricsCalculator.computeLinesOfCode(getSource(node)), getLocation(node)); // Write the inside relation relationWriter.writeInside(fqn, fqnStack.getFqn(), getUnknownLocation()); fqnStack.push(fqn, Entity.ANNOTATION); accept(node.getJavadoc()); 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 ww w . jav a 2s . c o m*/ *<ul> * <li>For any annotation declaration: * <ul> * <li>Annotation entity to <code>IEntityWriter</code>.</li> * <li>Inside relation to <code>IRelationWriter</code>.</li> * </ul></li> *</ul> */ @Override public boolean visit(AnnotationTypeDeclaration node) { // Get the fqn String fqn = null; if (node.isPackageMemberTypeDeclaration()) { fqn = fqnStack.peek(EnclosingPackage.class).getTypeFqn(node.getName().getIdentifier()); } else if (node.isMemberTypeDeclaration()) { if (node.getName().getIdentifier().length() > 0) { fqn = fqnStack.peek(EnclosingDeclaredType.class).getMemberFqn(node.getName().getIdentifier()); } else { throw new IllegalStateException("A annotation declaration should not declare an annonymous type!"); } } else if (node.isLocalTypeDeclaration()) { ITypeBinding binding = node.resolveBinding(); if (binding == null) { fqn = createUnknownFqn(node.getName().getIdentifier()); } else { fqn = fqnStack.peek(EnclosingBlock.class).getLocalFqn(node.getName().getIdentifier(), binding); } } else { throw new IllegalArgumentException("Unknown annotation type declaration type: " + node); } // Push the stack String parentFqn = fqnStack.getFqn(); fqnStack.push(fqn, Entity.ANNOTATION); // Visit the children accept(node.getJavadoc()); accept(node.modifiers()); accept(node.bodyDeclarations()); // Write the entity entityWriter.writeEntity(Entity.ANNOTATION, fqn, node.getModifiers(), createMetrics(node), createLocation(node)); // Write the contains relation relationWriter.writeRelation(Relation.CONTAINS, parentFqn, fqn, createUnknownLocation()); // Write the extends relation relationWriter.writeRelation(Relation.EXTENDS, fqn, "java.lang.Object", createUnknownLocation()); // Write the implements relation relationWriter.writeRelation(Relation.IMPLEMENTS, fqn, "java.lang.annotation.Annotation", createUnknownLocation()); fqnStack.pop(); return false; }
From source file:lang.java.jdt.internal.JdtAstToRascalAstConverter.java
License:Open Source License
public boolean visit(AnnotationTypeDeclaration node) { java.util.Map.Entry<IValueList, IValueList> extendedModifiers = parseExtendedModifiers(node.modifiers()); IValue name = values.string(node.getName().getFullyQualifiedName()); IValueList bodyDeclarations = new IValueList(values); for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext();) { BodyDeclaration d = (BodyDeclaration) it.next(); bodyDeclarations.add(visitChild(d)); }/*from ww w .j a va 2 s. c om*/ ownValue = constructRascalNode(node, extendedModifiers.getKey().asList(), extendedModifiers.getValue().asList(), name, bodyDeclarations.asList()); return false; }