List of usage examples for org.eclipse.jdt.core.dom AnonymousClassDeclaration bodyDeclarations
ASTNode.NodeList bodyDeclarations
To view the source code for org.eclipse.jdt.core.dom AnonymousClassDeclaration bodyDeclarations.
Click Source Link
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();//from ww w . j a v a 2 s . c o m b.accept(this); } this.fBuffer.append("}");//$NON-NLS-1$ return false; }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(AnonymousClassDeclaration node) { boa.types.Ast.Declaration.Builder b = boa.types.Ast.Declaration.newBuilder(); // b.setPosition(pos.build()); b.setName(""); b.setKind(boa.types.Ast.TypeKind.ANONYMOUS); for (Object d : node.bodyDeclarations()) { if (d instanceof FieldDeclaration) { fields.push(new ArrayList<boa.types.Ast.Variable>()); ((FieldDeclaration) d).accept(this); for (boa.types.Ast.Variable v : fields.pop()) b.addFields(v);/*from w ww. j a va 2 s . c o m*/ } else if (d instanceof MethodDeclaration) { methods.push(new ArrayList<boa.types.Ast.Method>()); ((MethodDeclaration) d).accept(this); for (boa.types.Ast.Method m : methods.pop()) b.addMethods(m); } else if (d instanceof Initializer) { methods.push(new ArrayList<boa.types.Ast.Method>()); ((Initializer) d).accept(this); for (boa.types.Ast.Method m : methods.pop()) b.addMethods(m); } else { declarations.push(new ArrayList<boa.types.Ast.Declaration>()); ((BodyDeclaration) d).accept(this); for (boa.types.Ast.Declaration nd : declarations.pop()) b.addNestedDeclarations(nd); } } declarations.peek().add(b.build()); return false; }
From source file:cn.ieclipse.adt.ext.jdt.SourceGenerator.java
License:Apache License
private static void genInnerSQLiteOpenHelper(AnonymousClassDeclaration acd, AST ast, List<String> tableCreators) { MethodDeclaration md = ast.newMethodDeclaration(); md.modifiers().addAll(ast.newModifiers((Modifier.PUBLIC))); md.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID)); md.setName(ast.newSimpleName("onCreate")); SingleVariableDeclaration svd = ast.newSingleVariableDeclaration(); svd.setName(ast.newSimpleName("db")); svd.setType(ast.newSimpleType(ast.newSimpleName("SQLiteDatabase"))); md.parameters().add(svd);//from ww w . j a v a 2 s . c o m Block innerBlock = ast.newBlock(); md.setBody(innerBlock); VariableDeclarationFragment vdf = ast.newVariableDeclarationFragment(); vdf.setName(ast.newSimpleName("sql")); StringLiteral sl = ast.newStringLiteral(); sl.setLiteralValue(""); vdf.setInitializer(sl); VariableDeclarationStatement vds = ast.newVariableDeclarationStatement(vdf); vds.setType(ast.newSimpleType(ast.newSimpleName("String"))); innerBlock.statements().add(vds); for (String creator : tableCreators) { String[] lines = creator.split(SourceAnalysis.LF); for (String line : lines) { Assignment a = ast.newAssignment(); a.setOperator(Assignment.Operator.PLUS_ASSIGN); a.setLeftHandSide(ast.newSimpleName("sql")); StringLiteral temp = ast.newStringLiteral(); temp.setLiteralValue(line); a.setRightHandSide(temp); innerBlock.statements().add(ast.newExpressionStatement(a)); } MethodInvocation mi = ast.newMethodInvocation(); mi.setName(ast.newSimpleName("execSQL")); mi.setExpression(ast.newSimpleName("db")); mi.arguments().add(ast.newSimpleName("sql")); innerBlock.statements().add(ast.newExpressionStatement(mi)); } acd.bodyDeclarations().add(md); // onUpgrade md = ast.newMethodDeclaration(); md.modifiers().addAll(ast.newModifiers((Modifier.PUBLIC))); md.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID)); md.setName(ast.newSimpleName("onUpgrade")); svd = ast.newSingleVariableDeclaration(); svd.setName(ast.newSimpleName("db")); svd.setType(ast.newSimpleType(ast.newSimpleName("SQLiteDatabase"))); md.parameters().add(svd); svd = ast.newSingleVariableDeclaration(); svd.setName(ast.newSimpleName("oldVersion")); svd.setType(ast.newPrimitiveType(PrimitiveType.INT)); md.parameters().add(svd); svd = ast.newSingleVariableDeclaration(); svd.setName(ast.newSimpleName("newVersion")); svd.setType(ast.newPrimitiveType(PrimitiveType.INT)); md.parameters().add(svd); innerBlock = ast.newBlock(); md.setBody(innerBlock); acd.bodyDeclarations().add(md); }
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. j a v a 2s . co m this.indent--; printIndent(); 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(AnonymousClassDeclaration node) { if (node.getParent() instanceof EnumConstantDeclaration) { handleBracedCode(node, null, this.options.brace_position_for_enum_constant, this.options.indent_body_declarations_compare_to_enum_constant_header, this.options.insert_new_line_in_empty_enum_constant); } else {// ww w .ja v a 2 s . c om handleBracedCode(node, null, this.options.brace_position_for_anonymous_type_declaration, this.options.indent_body_declarations_compare_to_type_header, this.options.insert_new_line_in_empty_anonymous_type_declaration); } handleBodyDeclarations(node.bodyDeclarations()); return true; }
From source file:com.bsiag.eclipse.jdt.java.formatter.linewrap.WrapPreparator.java
License:Open Source License
@Override public boolean visit(AnonymousClassDeclaration node) { if (this.options.align_type_members_on_columns) this.fieldAligner.prepareAlign(node.bodyDeclarations()); return true;//w w w. ja v a2 s .com }
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 w w . ja v a2 s . c om*/ 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.dart.java2dart.SyntaxTranslator.java
License:Open Source License
private ClassDeclaration declareInnerClass(IMethodBinding constructorBinding, AnonymousClassDeclaration anoClassDeclaration, String innerClassName, String[] additionalParameters) { ITypeBinding superTypeBinding = anoClassDeclaration.resolveBinding().getSuperclass(); ExtendsClause extendsClause = null;/*from w w w.j ava 2s .co m*/ ImplementsClause implementsClause = null; { ITypeBinding[] superInterfaces = anoClassDeclaration.resolveBinding().getInterfaces(); if (superInterfaces.length != 0) { superTypeBinding = superInterfaces[0]; TypeName superType = typeName(superInterfaces[0].getName()); putReference(superTypeBinding, (SimpleIdentifier) superType.getName()); implementsClause = implementsClause(superType); } else { TypeName superType = translateTypeName(superTypeBinding); putReference(superTypeBinding, (SimpleIdentifier) superType.getName()); extendsClause = extendsClause(superType); } } ClassDeclaration innerClass = classDeclaration(null, identifier(innerClassName), extendsClause, null, implementsClause, null); artificialUnitDeclarations.add(innerClass); if (extendsClause != null) { List<FormalParameter> parameters = Lists.newArrayList(); List<Expression> arguments = Lists.newArrayList(); // find "super" constructor IMethodBinding superConstructor = null; for (IMethodBinding superMethod : superTypeBinding.getDeclaredMethods()) { if (superMethod.isConstructor()) { if (isSuperConstructor(superMethod, constructorBinding)) { superConstructor = superMethod; // additional parameters for (int i = 0; i < additionalParameters.length / 2; i++) { parameters.add(simpleFormalParameter(null, typeName(additionalParameters[2 * i + 0]), additionalParameters[2 * i + 1])); arguments.add(identifier(additionalParameters[2 * i + 1])); } // "declared" parameters ITypeBinding[] parameterTypes = superMethod.getParameterTypes(); for (int i = 0; i < parameterTypes.length; i++) { TypeName dartParameterType = typeName(parameterTypes[i].getName()); String parameterName = "arg" + i; parameters.add(simpleFormalParameter(dartParameterType, parameterName)); arguments.add(identifier(parameterName)); } // done, we found and processed "super" constructor break; } } } // declare "inner" constructor FormalParameterList parameterList = formalParameterList(parameters); ArgumentList argList = new ArgumentList(null, arguments, null); SuperConstructorInvocation superCI = new SuperConstructorInvocation(null, null, null, argList); context.getConstructorDescription(superConstructor).superInvocations.add(superCI); ConstructorDeclaration innerConstructor = constructorDeclaration(null, null, identifier(innerClassName), null, parameterList, ImmutableList.<ConstructorInitializer>of(superCI), emptyFunctionBody()); innerClass.getMembers().add(innerConstructor); } for (Object javaBodyDeclaration : anoClassDeclaration.bodyDeclarations()) { ClassMember classMember = translate((org.eclipse.jdt.core.dom.ASTNode) javaBodyDeclaration); innerClass.getMembers().add(classMember); } return innerClass; }
From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java
License:Open Source License
@Override public boolean visit(AnonymousClassDeclaration node) { // Multi-method anonymous classes should have been converted by the // InnerClassExtractor. assert node.bodyDeclarations().size() == 1; // Generate an iOS block. assert false : "not implemented yet"; return true;/*www .ja v a2 s . c o m*/ }
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. j a v a 2 s .c o m*/ */ 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; }