List of usage examples for org.eclipse.jdt.core.dom BodyDeclaration accept
public final void accept(ASTVisitor visitor)
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); }//ww w . j av a 2 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:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(AnonymousClassDeclaration node) { this.fBuffer.append("{");//$NON-NLS-1$ List<BodyDeclaration> bodyDeclarations = node.bodyDeclarations(); for (Iterator<BodyDeclaration> it = bodyDeclarations.iterator(); it.hasNext();) { BodyDeclaration b = it.next(); b.accept(this); }/* w w w .j a va 2 s. c om*/ this.fBuffer.append("}");//$NON-NLS-1$ return false; }
From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(TypeDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); }/*from www . ja va 2s . co m*/ if (node.getAST().apiLevel() >= JLS3) { printModifiers(node.modifiers()); } this.fBuffer.append(node.isInterface() ? "interface " : "class ");//$NON-NLS-2$//$NON-NLS-1$ node.getName().accept(this); if (node.getAST().apiLevel() >= JLS3) { if (!node.typeParameters().isEmpty()) { this.fBuffer.append("<");//$NON-NLS-1$ for (Iterator<TypeParameter> it = node.typeParameters().iterator(); it.hasNext();) { TypeParameter 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$ if (node.getAST().apiLevel() >= JLS3) { if (node.getSuperclassType() != null) { this.fBuffer.append("extends ");//$NON-NLS-1$ node.getSuperclassType().accept(this); this.fBuffer.append(" ");//$NON-NLS-1$ } if (!node.superInterfaceTypes().isEmpty()) { this.fBuffer.append(node.isInterface() ? "extends " : "implements ");//$NON-NLS-2$//$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$ BodyDeclaration prev = null; for (Iterator<BodyDeclaration> it = node.bodyDeclarations().iterator(); it.hasNext();) { BodyDeclaration d = it.next(); if (prev instanceof EnumConstantDeclaration) { // enum constant declarations do not include punctuation if (d instanceof EnumConstantDeclaration) { // enum constant declarations are separated by commas this.fBuffer.append(", ");//$NON-NLS-1$ } else { // semicolon separates last enum constant declaration from // first class body declarations this.fBuffer.append("; ");//$NON-NLS-1$ } } d.accept(this); prev = d; } 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); }/* w ww . j ava 2s . c o m*/ 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:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(AnonymousClassDeclaration node) { this.buffer.append("{\n");//$NON-NLS-1$ this.indent++; for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext();) { BodyDeclaration b = (BodyDeclaration) it.next(); b.accept(this); }//w w w . jav a 2s . c o m this.indent--; printIndent(); this.buffer.append("}\n");//$NON-NLS-1$ return false; }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(TypeDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); }/*from ww w . j av a 2 s .c o m*/ if (node.getAST().apiLevel() >= AST.JLS3) { printModifiers(node.modifiers()); } this.buffer.append(node.isInterface() ? "interface " : "class ");//$NON-NLS-2$//$NON-NLS-1$ node.getName().accept(this); if (node.getAST().apiLevel() >= AST.JLS3) { if (!node.typeParameters().isEmpty()) { this.buffer.append("<");//$NON-NLS-1$ for (Iterator it = node.typeParameters().iterator(); it.hasNext();) { TypeParameter t = (TypeParameter) 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$ if (node.getAST().apiLevel() >= AST.JLS3) { if (node.getSuperclassType() != null) { this.buffer.append("extends ");//$NON-NLS-1$ node.getSuperclassType().accept(this); this.buffer.append(" ");//$NON-NLS-1$ } if (!node.superInterfaceTypes().isEmpty()) { this.buffer.append(node.isInterface() ? "extends " : "implements ");//$NON-NLS-2$//$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("{\n");//$NON-NLS-1$ this.indent++; BodyDeclaration prev = null; for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext();) { BodyDeclaration d = (BodyDeclaration) it.next(); if (prev instanceof EnumConstantDeclaration) { // enum constant declarations do not include punctuation if (d instanceof EnumConstantDeclaration) { // enum constant declarations are separated by commas this.buffer.append(", ");//$NON-NLS-1$ } else { // semicolon separates last enum constant declaration from // first class body declarations this.buffer.append("; ");//$NON-NLS-1$ } } d.accept(this); } this.indent--; printIndent(); this.buffer.append("}\n");//$NON-NLS-1$ return false; }
From source file:com.google.devtools.j2cpp.translate.AnonymousClassConverter.java
License:Open Source License
/** * Returns a list of nodes that reference any of the method's read-only * parameters and local variables./*from w w w. ja v a2s . c om*/ */ private List<ReferenceDescription> findReferences(AnonymousClassDeclaration node, final Set<IVariableBinding> methodVars) { final List<ReferenceDescription> refs = Lists.newArrayList(); MethodDeclaration decl = getEnclosingMethod(node); if (decl != null) { final IMethodBinding enclosingMethod = Types.getMethodBinding(decl); @SuppressWarnings("unchecked") List<BodyDeclaration> classMembers = node.bodyDeclarations(); // safe by definition for (BodyDeclaration member : classMembers) { member.accept(new ASTVisitor() { @Override public void endVisit(SimpleName node) { IVariableBinding varType = Types.getVariableBinding(node); if (varType != null) { if (methodVars.contains(varType.getVariableDeclaration())) { refs.add(new ReferenceDescription(node, varType, enclosingMethod)); } } } @Override public boolean visit(AnonymousClassDeclaration node) { return false; } }); } } return refs; }
From source file:com.google.devtools.j2objc.ast.DebugASTPrinter.java
License:Apache License
@Override public boolean visit(AnnotationTypeDeclaration node) { sb.printIndent();/*from ww w. j a va 2s.c om*/ printAnnotations(node.getAnnotations()); printModifiers(node.getModifiers()); sb.print("@interface "); node.getName().accept(this); sb.println(" {"); sb.indent(); for (BodyDeclaration decl : node.getBodyDeclarations()) { decl.accept(this); } sb.unindent(); sb.println("}"); return false; }
From source file:com.google.devtools.j2objc.ast.DebugASTPrinter.java
License:Apache License
@Override public boolean visit(AnonymousClassDeclaration node) { sb.print(" {"); sb.indent();//w w w . j a va 2 s. co m for (BodyDeclaration decl : node.getBodyDeclarations()) { decl.accept(this); } sb.unindent(); sb.println("}"); return false; }
From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java
License:Apache License
/** * Add a list of {@link BodyDeclaration}s * @param bodyDeclarations the {@link BodyDeclaration}s * @param braces whether to include braces in the output * @param first0 is the first {@link BodyDeclaration} the first to be output? *//*from w ww. j a va 2 s. c o m*/ void addBodyDeclarations(List<BodyDeclaration> bodyDeclarations, BracesOrNot braces, FirstDeclarationsOrNot first0) { if (bodyDeclarations.isEmpty()) { if (braces.isYes()) { builder.space(); tokenBreakTrailingComment("{", plusTwo); builder.blankLineWanted(BlankLineWanted.NO); builder.open(ZERO); token("}", plusTwo); builder.close(); } } else { if (braces.isYes()) { builder.space(); tokenBreakTrailingComment("{", plusTwo); builder.open(ZERO); } builder.open(plusTwo); boolean first = first0.isYes(); boolean lastOneGotBlankLineBefore = false; for (BodyDeclaration bodyDeclaration : bodyDeclarations) { dropEmptyDeclarations(); builder.forcedBreak(); boolean thisOneGetsBlankLineBefore = bodyDeclaration.getNodeType() != ASTNode.FIELD_DECLARATION || hasJavaDoc(bodyDeclaration); if (first) { builder.blankLineWanted(BlankLineWanted.PRESERVE); } else if (!first && (thisOneGetsBlankLineBefore || lastOneGotBlankLineBefore)) { builder.blankLineWanted(BlankLineWanted.YES); } markForPartialFormat(); bodyDeclaration.accept(this); first = false; lastOneGotBlankLineBefore = thisOneGetsBlankLineBefore; } builder.close(); builder.forcedBreak(); markForPartialFormat(); if (braces.isYes()) { dropEmptyDeclarations(); builder.blankLineWanted(BlankLineWanted.NO); token("}", plusTwo); builder.close(); } } }