List of usage examples for org.eclipse.jdt.core.dom EnhancedForStatement getBody
public Statement getBody()
From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(EnhancedForStatement node) { this.fBuffer.append("for (");//$NON-NLS-1$ node.getParameter().accept(this); this.fBuffer.append(" : ");//$NON-NLS-1$ node.getExpression().accept(this); this.fBuffer.append(") ");//$NON-NLS-1$ node.getBody().accept(this); return false; }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(EnhancedForStatement node) { boa.types.Ast.Statement.Builder b = boa.types.Ast.Statement.newBuilder(); // b.setPosition(pos.build()); List<boa.types.Ast.Statement> list = statements.peek(); b.setKind(boa.types.Ast.Statement.StatementKind.FOR); SingleVariableDeclaration ex = node.getParameter(); Variable.Builder vb = Variable.newBuilder(); // vb.setPosition(pos.build());//FIXME vb.setName(ex.getName().getFullyQualifiedName()); for (Object m : ex.modifiers()) { if (((IExtendedModifier) m).isAnnotation()) ((Annotation) m).accept(this); else/*from ww w . ja v a 2s.co m*/ ((org.eclipse.jdt.core.dom.Modifier) m).accept(this); vb.addModifiers(modifiers.pop()); } boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder(); String name = typeName(ex.getType()); for (int i = 0; i < ex.getExtraDimensions(); i++) name += "[]"; tb.setName(getIndex(name)); tb.setKind(boa.types.Ast.TypeKind.OTHER); vb.setVariableType(tb.build()); if (ex.getInitializer() != null) { ex.getInitializer().accept(this); vb.setInitializer(expressions.pop()); } b.setVariableDeclaration(vb.build()); node.getExpression().accept(this); b.setExpression(expressions.pop()); statements.push(new ArrayList<boa.types.Ast.Statement>()); node.getBody().accept(this); for (boa.types.Ast.Statement s : statements.pop()) b.addStatements(s); list.add(b.build()); return false; }
From source file:br.uff.ic.gems.resources.ast.Visitor.java
@Override public boolean visit(EnhancedForStatement node) { int beginLine = cu.getLineNumber(node.getStartPosition()); int endLine = cu.getLineNumber(node.getStartPosition() + node.getLength()); int beginColumn = cu.getColumnNumber(node.getStartPosition()); int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength()); Statement body = node.getBody(); if (body != null) { int beginLineBody = cu.getLineNumber(body.getStartPosition()); int endLineBody = cu.getLineNumber(body.getStartPosition() + body.getLength()); int beginColumnBody = cu.getColumnNumber(body.getStartPosition()); int endColumnBody = cu.getColumnNumber(body.getStartPosition() + body.getLength()); languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine, beginColumn, endColumn, beginLineBody, endLineBody, beginColumnBody, endColumnBody, null)); } else {/* w ww . j a va 2 s . com*/ languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine, beginColumn, endColumn)); } return true; }
From source file:cc.kave.eclipse.commons.analysis.transformer.BodyVisitor.java
License:Apache License
@Override public boolean visit(EnhancedForStatement stmt) { if (isTargetMatch(stmt, CompletionCase.EmptyCompletionBefore)) { body.add(getEmptyCompletionExpression()); }//from ww w .java 2s.c o m ForEachLoop loop = new ForEachLoop(); // TODO: stmt.Collection analogie suchen // LoopedReference = _exprVisitor.ToVariableRef(stmt.Collection, body) // loop.setLoopedReference(exprVisitor.toVariableRef(stmt.get)); body.add(loop); // TODO : ??? // if (stmt.IteratorDeclaration != null && // stmt.IteratorDeclaration.DeclaredElement != null) // { // var localVar = // stmt.IteratorDeclaration.DeclaredElement.GetName<LocalVariableName>(); // loop.Declaration = new VariableDeclaration // { // Reference = new VariableReference {Identifier = localVar.Name}, // Type = localVar.ValueType // }; // } if (isTargetMatch(stmt, CompletionCase.InBody)) { loop.getBody().add(getEmptyCompletionExpression()); } if (stmt.getBody() != null) { stmt.getBody().accept(new BodyVisitor(nameGen, marker, loop.getBody())); } if (isTargetMatch(stmt, CompletionCase.EmptyCompletionAfter)) { body.add(getEmptyCompletionExpression()); } return super.visit(stmt); }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(EnhancedForStatement node) { printIndent();/*from ww w . ja v a 2s . c o m*/ this.buffer.append("for (");//$NON-NLS-1$ node.getParameter().accept(this); this.buffer.append(" : ");//$NON-NLS-1$ node.getExpression().accept(this); this.buffer.append(") ");//$NON-NLS-1$ node.getBody().accept(this); return false; }
From source file:com.bsiag.eclipse.jdt.java.formatter.LineBreaksPreparator.java
License:Open Source License
@Override public boolean visit(EnhancedForStatement node) { handleLoopBody(node.getBody()); return true; }
From source file:com.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java
License:Open Source License
@Override public boolean visit(EnhancedForStatement node) { handleToken(node, TokenNameLPAREN, this.options.insert_space_before_opening_paren_in_for, this.options.insert_space_after_opening_paren_in_for); handleTokenBefore(node.getBody(), TokenNameRPAREN, this.options.insert_space_before_closing_paren_in_for, false);/* www .j a v a2 s. c om*/ handleTokenAfter(node.getParameter(), TokenNameCOLON, this.options.insert_space_before_colon_in_for, this.options.insert_space_after_colon_in_for); return true; }
From source file:com.google.dart.java2dart.SyntaxTranslator.java
License:Open Source License
@Override public boolean visit(org.eclipse.jdt.core.dom.EnhancedForStatement node) { SimpleFormalParameter sfp = (SimpleFormalParameter) translate(node.getParameter()); return done(forEachStatement(declaredIdentifier(sfp.getType(), sfp.getIdentifier()), translateExpression(node.getExpression()), (Statement) translate(node.getBody()))); }
From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java
License:Open Source License
@Override public boolean visit(EnhancedForStatement node) { SingleVariableDeclaration var = node.getParameter(); boolean emitAutoreleasePool = Types.hasAutoreleasePoolAnnotation(Types.getBinding(var)); String varName = NameTable.getName(var.getName()); if (NameTable.isReservedName(varName)) { varName += "__"; NameTable.rename(Types.getBinding(var.getName()), varName); }//from w ww .ja v a2s . c o m String arrayExpr = generate(node.getExpression(), fieldHiders, asFunction, buffer.getCurrentLine()); ITypeBinding arrayType = Types.getTypeBinding(node.getExpression()); if (arrayType.isArray()) { buffer.append("{\nint n__ = ["); buffer.append(arrayExpr); buffer.append(" count];\n"); buffer.append("for (int i__ = 0; i__ < n__; i__++) {\n"); if (emitAutoreleasePool) { buffer.append("NSAutoreleasePool *pool__ = [[NSAutoreleasePool alloc] init];\n"); } buffer.append(NameTable.javaRefToCpp(var.getType())); buffer.append(' '); buffer.append(varName); buffer.append(" = ["); buffer.append(arrayExpr); buffer.append(' '); if (arrayType.getComponentType().isPrimitive()) { buffer.append(var.getType().toString()); } else { buffer.append("object"); } buffer.append("AtIndex:i__];\n"); Statement body = node.getBody(); if (body instanceof Block) { // strip surrounding braces printStatements(((Block) body).statements()); } else { body.accept(this); } if (emitAutoreleasePool) { buffer.append("[pool__ release];\n"); } buffer.append("}\n}\n"); } else { // var must be an instance of an Iterable class. String objcType = NameTable.javaRefToCpp(var.getType()); buffer.append("{\nid<JavaLangIterable> array__ = (id<JavaLangIterable>) "); buffer.append(arrayExpr); buffer.append(";\n"); buffer.append("if (!array__) {\n"); if (useReferenceCounting) { buffer.append("@throw [[[JavaLangNullPointerException alloc] init] autorelease];\n}\n"); } else { buffer.append("@throw [[JavaLangNullPointerException alloc] init];\n}\n"); } buffer.append("id<JavaUtilIterator> iter__ = [array__ iterator];\n"); buffer.append("while ([iter__ hasNext]) {\n"); if (emitAutoreleasePool) { buffer.append("NSAutoreleasePool *pool__ = [[NSAutoreleasePool alloc] init];\n"); } buffer.append(objcType); buffer.append(' '); buffer.append(varName); buffer.append(" = ("); buffer.append(objcType); buffer.append(") [iter__ next];\n"); Statement body = node.getBody(); if (body instanceof Block) { // strip surrounding braces printStatements(((Block) body).statements()); } else { body.accept(this); } if (emitAutoreleasePool) { buffer.append("[pool__ release];\n"); } buffer.append("}\n}\n"); } return false; }
From source file:com.google.devtools.j2objc.ast.DebugASTPrinter.java
License:Apache License
@Override public boolean visit(EnhancedForStatement node) { sb.printIndent();//ww w .java 2s. c om sb.print("for ("); node.getParameter().accept(this); sb.print(" : "); node.getExpression().accept(this); sb.print(") "); node.getBody().accept(this); return false; }