/* * @see ASTVisitor#visit(ConstructorInvocation) */ @Override public boolean visit(ConstructorInvocation node) { if (node.getAST().apiLevel() >= JLS3) { if (!node.typeArguments().isEmpty()) { this.fBuffer.append("<"); // $NON-NLS-1$ for (Iterator<Type> it = node.typeArguments().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("this("); // $NON-NLS-1$ for (Iterator<Expression> it = node.arguments().iterator(); it.hasNext(); ) { Expression e = it.next(); e.accept(this); if (it.hasNext()) { this.fBuffer.append(","); // $NON-NLS-1$ } } this.fBuffer.append(");"); // $NON-NLS-1$ return false; }
/* * @see ASTVisitor#visit(MethodInvocation) */ public boolean visit(MethodInvocation node) { if (node.getExpression() != null) { node.getExpression().accept(this); this.fBuffer.append("."); // $NON-NLS-1$ } if (node.getAST().apiLevel() >= AST.JLS3) { if (!node.typeArguments().isEmpty()) { this.fBuffer.append("<"); // $NON-NLS-1$ for (Iterator it = node.typeArguments().iterator(); it.hasNext(); ) { Type t = (Type) it.next(); t.accept(this); if (it.hasNext()) { this.fBuffer.append(","); // $NON-NLS-1$ } } this.fBuffer.append(">"); // $NON-NLS-1$ } } node.getName().accept(this); this.fBuffer.append("("); // $NON-NLS-1$ for (Iterator it = node.arguments().iterator(); it.hasNext(); ) { Expression e = (Expression) it.next(); e.accept(this); if (it.hasNext()) { this.fBuffer.append(","); // $NON-NLS-1$ } } this.fBuffer.append(")"); // $NON-NLS-1$ return false; }
/* * @see ASTVisitor#visit(ClassInstanceCreation) */ public boolean visit(ClassInstanceCreation node) { if (node.getExpression() != null) { node.getExpression().accept(this); this.fBuffer.append("."); // $NON-NLS-1$ } this.fBuffer.append("new "); // $NON-NLS-1$ if (node.getAST().apiLevel() >= AST.JLS3) { if (!node.typeArguments().isEmpty()) { this.fBuffer.append("<"); // $NON-NLS-1$ for (Iterator it = node.typeArguments().iterator(); it.hasNext(); ) { Type t = (Type) it.next(); t.accept(this); if (it.hasNext()) { this.fBuffer.append(","); // $NON-NLS-1$ } } this.fBuffer.append(">"); // $NON-NLS-1$ } node.getType().accept(this); } this.fBuffer.append("("); // $NON-NLS-1$ for (Iterator it = node.arguments().iterator(); it.hasNext(); ) { Expression e = (Expression) it.next(); e.accept(this); if (it.hasNext()) { this.fBuffer.append(","); // $NON-NLS-1$ } } this.fBuffer.append(")"); // $NON-NLS-1$ if (node.getAnonymousClassDeclaration() != null) { node.getAnonymousClassDeclaration().accept(this); } return false; }
/* * @see ASTVisitor#visit(SuperMethodInvocation) */ @Override public boolean visit(SuperMethodInvocation node) { if (node.getQualifier() != null) { node.getQualifier().accept(this); this.fBuffer.append("."); // $NON-NLS-1$ } this.fBuffer.append("super."); // $NON-NLS-1$ if (node.getAST().apiLevel() >= JLS3) { if (!node.typeArguments().isEmpty()) { this.fBuffer.append("<"); // $NON-NLS-1$ for (Iterator<Type> it = node.typeArguments().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$ } } node.getName().accept(this); this.fBuffer.append("("); // $NON-NLS-1$ for (Iterator<Expression> it = node.arguments().iterator(); it.hasNext(); ) { Expression e = it.next(); e.accept(this); if (it.hasNext()) { this.fBuffer.append(","); // $NON-NLS-1$ } } this.fBuffer.append(")"); // $NON-NLS-1$ return false; }
/* * @see ASTVisitor#visit(ForStatement) */ public boolean visit(ForStatement node) { this.fBuffer.append("for ("); // $NON-NLS-1$ for (Iterator it = node.initializers().iterator(); it.hasNext(); ) { Expression e = (Expression) it.next(); e.accept(this); } this.fBuffer.append("; "); // $NON-NLS-1$ if (node.getExpression() != null) { node.getExpression().accept(this); } this.fBuffer.append("; "); // $NON-NLS-1$ for (Iterator it = node.updaters().iterator(); it.hasNext(); ) { Expression e = (Expression) it.next(); e.accept(this); } this.fBuffer.append(") "); // $NON-NLS-1$ node.getBody().accept(this); return false; }
/* * @see ASTVisitor#visit(ArrayInitializer) */ public boolean visit(ArrayInitializer node) { this.fBuffer.append("{"); // $NON-NLS-1$ for (Iterator it = node.expressions().iterator(); it.hasNext(); ) { Expression e = (Expression) it.next(); e.accept(this); if (it.hasNext()) { this.fBuffer.append(","); // $NON-NLS-1$ } } this.fBuffer.append("}"); // $NON-NLS-1$ return false; }
private void evalQualifyingExpression(Expression expr, Name selector) { if (expr != null) { if (expr instanceof Name) { Name name = (Name) expr; possibleTypeRefFound(name); possibleStaticImportFound(name); } else { expr.accept(this); } } else if (selector != null) { possibleStaticImportFound(selector); } }
/* * Visit the AST expression and get the ParseTree Expression. * This is used by the individual visits when parsing a tree. * It passes to the top method (createExpression), which can * handle the InvalidExpressionException. * * If any visit doesn't return an expression, then an invalid * expression exception will be thrown to indicate this. If the * incoming expression is <code>null</code>, then return of <code>null</code> is ok because * this would be for an optional expression which didn't exist. * * @return The new ParseTree Expression or <code>null</code> if incoming expression was null. * * @see createExpression(org.eclipse.jdt.core.dom.Expression) * @exception InvalidExpressionException * @since 1.0.0 */ protected final PTExpression perform(Expression astExpression) { if (astExpression != null) { expression = null; astExpression.accept(this); if (expression == null) throw new InvalidExpressionException( MessageFormat.format( WorkbenchUtilityMessages.ParseTreeCreationFromAST_ExpressionTooComplicated_EXC_, new Object[] {astExpression.toString()})); return expression; } else return null; // This is ok. It means an optional expression was being processed and the // expression didn't exist. }
/** {@inheritDoc} */ public boolean visit(VariableDeclarationStatement node) { if (fAddFinalLocals) handleFragments(node.fragments(), node); List fragments = node.fragments(); for (Iterator iterator = fragments.iterator(); iterator.hasNext(); ) { VariableDeclarationFragment fragment = (VariableDeclarationFragment) iterator.next(); Expression initializer = fragment.getInitializer(); if (initializer != null) { initializer.accept(this); } } return false; }
/* * @see ASTVisitor#visit(InfixExpression) */ public boolean visit(InfixExpression node) { node.getLeftOperand().accept(this); this.fBuffer.append(' '); // for cases like x= i - -1; or x= i++ + ++i; this.fBuffer.append(node.getOperator().toString()); this.fBuffer.append(' '); node.getRightOperand().accept(this); final List extendedOperands = node.extendedOperands(); if (extendedOperands.size() != 0) { this.fBuffer.append(' '); for (Iterator it = extendedOperands.iterator(); it.hasNext(); ) { this.fBuffer.append(node.getOperator().toString()).append(' '); Expression e = (Expression) it.next(); e.accept(this); } } return false; }
/* * @see ASTVisitor#visit(EnumConstantDeclaration) * @since 3.0 */ public boolean visit(EnumConstantDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); } printModifiers(node.modifiers()); node.getName().accept(this); if (!node.arguments().isEmpty()) { this.fBuffer.append("("); // $NON-NLS-1$ for (Iterator it = node.arguments().iterator(); it.hasNext(); ) { Expression e = (Expression) it.next(); e.accept(this); if (it.hasNext()) { this.fBuffer.append(","); // $NON-NLS-1$ } } this.fBuffer.append(")"); // $NON-NLS-1$ } if (node.getAnonymousClassDeclaration() != null) { node.getAnonymousClassDeclaration().accept(this); } return false; }
/* * @see ASTVisitor#visit(ArrayCreation) */ public boolean visit(ArrayCreation node) { this.fBuffer.append("new "); // $NON-NLS-1$ ArrayType at = node.getType(); int dims = at.getDimensions(); Type elementType = at.getElementType(); elementType.accept(this); for (Iterator it = node.dimensions().iterator(); it.hasNext(); ) { this.fBuffer.append("["); // $NON-NLS-1$ Expression e = (Expression) it.next(); e.accept(this); this.fBuffer.append("]"); // $NON-NLS-1$ dims--; } // add empty "[]" for each extra array dimension for (int i = 0; i < dims; i++) { this.fBuffer.append("[]"); // $NON-NLS-1$ } if (node.getInitializer() != null) { node.getInitializer().accept(this); } return false; }