List of usage examples for org.eclipse.jdt.core.dom EnhancedForStatement getExpression
public Expression getExpression()
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// w ww. j a va 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:ca.uvic.chisel.diver.sequencediagrams.sc.java.editors.JavaMessageGrouper.java
License:Open Source License
/** * Updates labels and colours for the grouping. * @param currentGrouping// w ww . j ava 2 s.co m */ private void updateGrouping(MappedMessageGrouping grouping) { ASTNode node = (ASTNode) grouping.getKey(); String text = ""; int i; Color bg = null; Color fg = null; switch (node.getNodeType()) { case ASTNode.IF_STATEMENT: IfStatement ifStatement = (IfStatement) node; text = "if (" + ifStatement.getExpression().toString() + ")"; //it could be an else-if, make sure if (ifStatement.getParent().getNodeType() == ASTNode.IF_STATEMENT) { if (ifStatement.equals(((IfStatement) ifStatement.getParent()).getElseStatement())) { text = "else " + text; } } fg = ISketchColorConstants.CONDITION_FG; bg = ISketchColorConstants.CONDITION_BG; break; case ASTNode.WHILE_STATEMENT: WhileStatement whileStatement = (WhileStatement) node; text = "while (" + whileStatement.getExpression().toString() + ")"; fg = ISketchColorConstants.LOOP_FG; bg = ISketchColorConstants.LOOP_BG; break; case ASTNode.DO_STATEMENT: DoStatement doStatement = (DoStatement) node; text = "do..while (" + doStatement.getExpression().toString() + ")"; fg = ISketchColorConstants.LOOP_FG; bg = ISketchColorConstants.LOOP_BG; break; case ASTNode.FOR_STATEMENT: ForStatement forStatement = (ForStatement) node; List<?> initializers = forStatement.initializers(); List<?> updaters = forStatement.updaters(); text = "for ("; for (i = 0; i < initializers.size(); i++) { text += initializers.get(i).toString(); if (i < initializers.size() - 1) { text += ","; } } text += ";"; if (forStatement.getExpression() != null) { text += forStatement.getExpression(); } text += ";"; for (i = 0; i < updaters.size(); i++) { text += updaters.get(i).toString(); if (i < updaters.size() - 1) { text += ","; } } text += ")"; fg = ISketchColorConstants.LOOP_FG; bg = ISketchColorConstants.LOOP_BG; break; case ASTNode.ENHANCED_FOR_STATEMENT: EnhancedForStatement enhancedForStatement = (EnhancedForStatement) node; text = "for (" + enhancedForStatement.getExpression().toString() + ")"; fg = ISketchColorConstants.LOOP_FG; bg = ISketchColorConstants.LOOP_BG; break; case ASTNode.TRY_STATEMENT: text = "try"; fg = ISketchColorConstants.ERROR_FG; bg = ISketchColorConstants.ERROR_BG; break; case ASTNode.CATCH_CLAUSE: CatchClause catchClause = (CatchClause) node; text = "catch (" + catchClause.getException().toString() + ")"; fg = ISketchColorConstants.ERROR_FG; bg = ISketchColorConstants.ERROR_BG; break; default: //get the else blocks if (node instanceof Statement) { Statement statement = (Statement) node; if (statement.getParent() instanceof IfStatement) { if (((IfStatement) statement.getParent()).getElseStatement() == statement) { text = "else"; fg = ISketchColorConstants.CONDITION_FG; bg = ISketchColorConstants.CONDITION_BG; } } } break; } grouping.setName(text); grouping.setForeground(fg); grouping.setBackground(bg); }
From source file:ca.uvic.chisel.javasketch.ui.internal.presentation.ASTMessageGrouper.java
License:Open Source License
/** * Updates labels and colours for the grouping. * @param currentGrouping/*from w ww. j a va 2 s.c o m*/ */ private void updateGrouping(ASTMessageGrouping grouping, ASTNode node) { String text = ""; int i; Color bg = null; Color fg = null; switch (node.getNodeType()) { case ASTNode.IF_STATEMENT: IfStatement ifStatement = (IfStatement) node; text = "if (" + ifStatement.getExpression().toString() + ")"; //it could be an else-if, make sure if (ifStatement.getParent().getNodeType() == ASTNode.IF_STATEMENT) { if (ifStatement.equals(((IfStatement) ifStatement.getParent()).getElseStatement())) { text = "else " + text; } } fg = ISketchColorConstants.CONDITION_FG; bg = ISketchColorConstants.CONDITION_BG; break; case ASTNode.WHILE_STATEMENT: WhileStatement whileStatement = (WhileStatement) node; text = "while (" + whileStatement.getExpression().toString() + ")"; fg = ISketchColorConstants.LOOP_FG; bg = ISketchColorConstants.LOOP_BG; break; case ASTNode.DO_STATEMENT: DoStatement doStatement = (DoStatement) node; text = "do..while (" + doStatement.getExpression().toString() + ")"; fg = ISketchColorConstants.LOOP_FG; bg = ISketchColorConstants.LOOP_BG; break; case ASTNode.FOR_STATEMENT: ForStatement forStatement = (ForStatement) node; List<?> initializers = forStatement.initializers(); List<?> updaters = forStatement.updaters(); text = "for ("; for (i = 0; i < initializers.size(); i++) { text += initializers.get(i).toString(); if (i < initializers.size() - 1) { text += ","; } } text += ";"; if (forStatement.getExpression() != null) { text += forStatement.getExpression(); } text += ";"; for (i = 0; i < updaters.size(); i++) { text += updaters.get(i).toString(); if (i < updaters.size() - 1) { text += ","; } } text += ")"; fg = ISketchColorConstants.LOOP_FG; bg = ISketchColorConstants.LOOP_BG; break; case ASTNode.ENHANCED_FOR_STATEMENT: EnhancedForStatement enhancedForStatement = (EnhancedForStatement) node; text = "for (" + enhancedForStatement.getExpression().toString() + ")"; fg = ISketchColorConstants.LOOP_FG; bg = ISketchColorConstants.LOOP_BG; break; case ASTNode.TRY_STATEMENT: text = "try"; fg = ISketchColorConstants.ERROR_FG; bg = ISketchColorConstants.ERROR_BG; break; case ASTNode.CATCH_CLAUSE: CatchClause catchClause = (CatchClause) node; text = "catch (" + catchClause.getException().toString() + ")"; fg = ISketchColorConstants.ERROR_FG; bg = ISketchColorConstants.ERROR_BG; break; default: //get the else blocks if (node instanceof Statement) { Statement statement = (Statement) node; if (statement.getParent() instanceof IfStatement) { if (((IfStatement) statement.getParent()).getElseStatement() == statement) { text = "else"; fg = ISketchColorConstants.CONDITION_FG; bg = ISketchColorConstants.CONDITION_BG; } } } break; } if (grouping.node.isLoop()) { ASTMessageGroupingTree[] siblings = grouping.node.getSiblings(); text = text + "[" + grouping.node.getIteration() + " of " + (siblings.length + 1) + "]"; } grouping.setName(text); grouping.setForeground(fg); grouping.setBackground(bg); }
From source file:ca.uvic.chisel.javasketch.ui.internal.presentation.CopyOfASTMessageGrouper.java
License:Open Source License
/** * Updates labels and colours for the grouping. * @param currentGrouping/* www . j av a 2 s . co m*/ */ private void updateGrouping(ASTMessageGrouping grouping, ASTNode node) { String text = ""; int i; Color bg = null; Color fg = null; switch (node.getNodeType()) { case ASTNode.IF_STATEMENT: IfStatement ifStatement = (IfStatement) node; text = "if (" + ifStatement.getExpression().toString() + ")"; fg = ISketchColorConstants.CONDITION_FG; bg = ISketchColorConstants.CONDITION_BG; break; case ASTNode.WHILE_STATEMENT: WhileStatement whileStatement = (WhileStatement) node; text = "while (" + whileStatement.getExpression().toString() + ")"; fg = ISketchColorConstants.LOOP_FG; bg = ISketchColorConstants.LOOP_BG; break; case ASTNode.DO_STATEMENT: DoStatement doStatement = (DoStatement) node; text = "do..while (" + doStatement.getExpression().toString() + ")"; fg = ISketchColorConstants.LOOP_FG; bg = ISketchColorConstants.LOOP_BG; break; case ASTNode.FOR_STATEMENT: ForStatement forStatement = (ForStatement) node; List<?> initializers = forStatement.initializers(); List<?> updaters = forStatement.updaters(); text = "for ("; for (i = 0; i < initializers.size(); i++) { text += initializers.get(i).toString(); if (i < initializers.size() - 1) { text += ","; } } text += ";"; if (forStatement.getExpression() != null) { text += forStatement.getExpression(); } text += ";"; for (i = 0; i < updaters.size(); i++) { text += updaters.get(i).toString(); if (i < updaters.size() - 1) { text += ","; } } text += ")"; fg = ISketchColorConstants.LOOP_FG; bg = ISketchColorConstants.LOOP_BG; break; case ASTNode.ENHANCED_FOR_STATEMENT: EnhancedForStatement enhancedForStatement = (EnhancedForStatement) node; text = "for (" + enhancedForStatement.getExpression().toString() + ")"; fg = ISketchColorConstants.LOOP_FG; bg = ISketchColorConstants.LOOP_BG; break; case ASTNode.TRY_STATEMENT: text = "try"; fg = ISketchColorConstants.ERROR_FG; bg = ISketchColorConstants.ERROR_BG; break; case ASTNode.CATCH_CLAUSE: CatchClause catchClause = (CatchClause) node; text = "catch (" + catchClause.getException().toString() + ")"; fg = ISketchColorConstants.ERROR_FG; bg = ISketchColorConstants.ERROR_BG; break; default: //get the else blocks if (node instanceof Statement) { Statement statement = (Statement) node; if (statement.getParent() instanceof IfStatement) { if (((IfStatement) statement.getParent()).getElseStatement() == statement) { text = "else"; fg = ISketchColorConstants.CONDITION_FG; bg = ISketchColorConstants.CONDITION_BG; } } } break; } if (grouping.node.isLoop()) { ASTMessageGroupingTree[] siblings = grouping.node.getSiblings(); text = text + "[" + grouping.node.getIteration() + " of " + (siblings.length + 1) + "]"; } grouping.setName(text); grouping.setForeground(fg); grouping.setBackground(bg); }
From source file:chibi.gumtreediff.gen.jdt.cd.CdJdtVisitor.java
License:Open Source License
@Override public boolean visit(EnhancedForStatement node) { pushNode(node, node.getParameter().toString() + COLON + node.getExpression().toString()); return true;//from w ww . ja v a2s . c o m }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(EnhancedForStatement node) { printIndent();/*from w w w . j ava 2 s . 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.chookapp.org.bracketeer.jdt.ClosingBracketHintVisitor.java
License:Open Source License
@Override public boolean visit(EnhancedForStatement node) { /* TODO: specific params: put 2 checkboxes: the var name & the collection */ String hint = GetNodeText(node.getExpression()); int startLoc = node.getStartPosition(); int endLoc = startLoc + node.getLength() - 1; hint = "foreach( " + hint + " )"; //$NON-NLS-1$ //$NON-NLS-2$ _scopeStack.push(new ScopeInfo(hint, startLoc, node)); try {/*ww w . ja v a 2s .c o m*/ _container.add(new Hint("foreach", startLoc, endLoc, hint)); //$NON-NLS-1$ } catch (BadLocationException e) { _cancelProcessing.set(true); } return shouldContinue(); }
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 a 2s .com*/ 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; }