blob: 1af192b5f1d6aaa840cbe71ce242ebda9fb6797f [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2002 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Corporation - initial API and implementation
******************************************************************************/
package org.eclipse.jdt.core.dom;
import java.util.Iterator;
/**
* Internal AST visitor for serializing an AST in a qucik and dirty fashion.
* For various reasons the resulting string is not necessarily legal
* Java code; and even if it is legal Java code, it is not necessarily the string
* that corresponds to the given AST. Although useless for most purposes, it's
* fine for generating debug print strings.
* <p>
* Example usage:
* <code>
* <pre>
* NaiveASTFlattener p = new NaiveASTFlattener();
* node.accept(p);
* String result = p.getResult();
* </pre>
* </code>
* Call the <code>reset</code> method to clear the previous result before reusing an
* existing instance.
* </p>
*
* @since 2.0
*/
class NaiveASTFlattener extends ASTVisitor {
/**
* The string buffer into which the serialized representation of the AST is
* written.
*/
private StringBuffer buffer = new StringBuffer(6000);
/**
* Creates a new AST printer.
*/
NaiveASTFlattener() {
}
/**
* Returns the string accumulated in the visit.
*
* @return the serialized
*/
public String getResult() {
// convert to a string, but lose any extra space in the string buffer by copying
return new String(buffer.toString());
}
/**
* Resets this printer so that it can be used again.
*/
public void reset() {
buffer.setLength(0);
}
/**
* Appends the text representation of the given modifier flags, followed by a single space.
*
* @param modifiers the modifiers
*/
void printModifiers(int modifiers) {
if (Modifier.isPublic(modifiers)) {
buffer.append("public ");//$NON-NLS-1$
}
if (Modifier.isProtected(modifiers)) {
buffer.append("protected ");//$NON-NLS-1$
}
if (Modifier.isPrivate(modifiers)) {
buffer.append("private ");//$NON-NLS-1$
}
if (Modifier.isStatic(modifiers)) {
buffer.append("static ");//$NON-NLS-1$
}
if (Modifier.isAbstract(modifiers)) {
buffer.append("abstract ");//$NON-NLS-1$
}
if (Modifier.isFinal(modifiers)) {
buffer.append("final ");//$NON-NLS-1$
}
if (Modifier.isSynchronized(modifiers)) {
buffer.append("synchronized ");//$NON-NLS-1$
}
if (Modifier.isVolatile(modifiers)) {
buffer.append("volatile ");//$NON-NLS-1$
}
if (Modifier.isNative(modifiers)) {
buffer.append("native ");//$NON-NLS-1$
}
if (Modifier.isStrictfp(modifiers)) {
buffer.append("strictfp ");//$NON-NLS-1$
}
if (Modifier.isTransient(modifiers)) {
buffer.append("transient ");//$NON-NLS-1$
}
}
/*
* @see ASTVisitor#visit(AnonymousClassDeclaration)
*/
public boolean visit(AnonymousClassDeclaration node) {
buffer.append("{");//$NON-NLS-1$
for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext(); ) {
BodyDeclaration b = (BodyDeclaration) it.next();
b.accept(this);
}
buffer.append("}");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(ArrayAccess)
*/
public boolean visit(ArrayAccess node) {
node.getArray().accept(this);
buffer.append("[");//$NON-NLS-1$
node.getIndex().accept(this);
buffer.append("]");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(ArrayCreation)
*/
public boolean visit(ArrayCreation node) {
buffer.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(); ) {
buffer.append("[");//$NON-NLS-1$
Expression e = (Expression) it.next();
e.accept(this);
buffer.append("]");//$NON-NLS-1$
dims--;
}
// add empty "[]" for each extra array dimension
for (int i= 0; i < dims; i++) {
buffer.append("[]");//$NON-NLS-1$
}
if (node.getInitializer() != null) {
buffer.append("=");//$NON-NLS-1$
node.getInitializer().accept(this);
}
return false;
}
/*
* @see ASTVisitor#visit(ArrayInitializer)
*/
public boolean visit(ArrayInitializer node) {
buffer.append("{");//$NON-NLS-1$
for (Iterator it = node.expressions().iterator(); it.hasNext(); ) {
Expression e = (Expression) it.next();
e.accept(this);
buffer.append(",");//$NON-NLS-1$
}
buffer.append("}");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(ArrayType)
*/
public boolean visit(ArrayType node) {
node.getComponentType().accept(this);
buffer.append("[]");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(AssertStatement)
*/
public boolean visit(AssertStatement node) {
buffer.append("assert ");//$NON-NLS-1$
node.getExpression().accept(this);
if (node.getMessage() != null) {
buffer.append(" : ");//$NON-NLS-1$
node.getMessage().accept(this);
}
buffer.append(";");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(Assignment)
*/
public boolean visit(Assignment node) {
node.getLeftHandSide().accept(this);
buffer.append(node.getOperator().toString());
node.getRightHandSide().accept(this);
return false;
}
/*
* @see ASTVisitor#visit(Block)
*/
public boolean visit(Block node) {
buffer.append("{");//$NON-NLS-1$
for (Iterator it = node.statements().iterator(); it.hasNext(); ) {
Statement s = (Statement) it.next();
s.accept(this);
}
buffer.append("}");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(BooleanLiteral)
*/
public boolean visit(BooleanLiteral node) {
if (node.booleanValue() == true) {
buffer.append("true");//$NON-NLS-1$
} else {
buffer.append("false");//$NON-NLS-1$
}
return false;
}
/*
* @see ASTVisitor#visit(BreakStatement)
*/
public boolean visit(BreakStatement node) {
buffer.append("break");//$NON-NLS-1$
if (node.getLabel() != null) {
buffer.append(" ");//$NON-NLS-1$
node.getLabel().accept(this);
}
buffer.append(";");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(CastExpression)
*/
public boolean visit(CastExpression node) {
buffer.append("(");//$NON-NLS-1$
node.getType().accept(this);
buffer.append(")");//$NON-NLS-1$
node.getExpression().accept(this);
return false;
}
/*
* @see ASTVisitor#visit(CatchClause)
*/
public boolean visit(CatchClause node) {
buffer.append("catch (");//$NON-NLS-1$
node.getException().accept(this);
buffer.append(") ");//$NON-NLS-1$
node.getBody().accept(this);
return false;
}
/*
* @see ASTVisitor#visit(CharacterLiteral)
*/
public boolean visit(CharacterLiteral node) {
buffer.append(node.getEscapedValue());
return false;
}
/*
* @see ASTVisitor#visit(ClassInstanceCreation)
*/
public boolean visit(ClassInstanceCreation node) {
if (node.getExpression() != null) {
node.getExpression().accept(this);
buffer.append(".");//$NON-NLS-1$
}
buffer.append("new ");//$NON-NLS-1$
node.getName().accept(this);
buffer.append("(");//$NON-NLS-1$
for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
Expression e = (Expression) it.next();
e.accept(this);
if (it.hasNext()) {
buffer.append(",");//$NON-NLS-1$
}
}
buffer.append(")");//$NON-NLS-1$
if (node.getAnonymousClassDeclaration() != null) {
node.getAnonymousClassDeclaration().accept(this);
}
return false;
}
/*
* @see ASTVisitor#visit(CompilationUnit)
*/
public boolean visit(CompilationUnit node) {
if (node.getPackage() != null) {
node.getPackage().accept(this);
}
for (Iterator it = node.imports().iterator(); it.hasNext(); ) {
ImportDeclaration d = (ImportDeclaration) it.next();
d.accept(this);
}
for (Iterator it = node.types().iterator(); it.hasNext(); ) {
TypeDeclaration d = (TypeDeclaration) it.next();
d.accept(this);
}
return false;
}
/*
* @see ASTVisitor#visit(ConditionalExpression)
*/
public boolean visit(ConditionalExpression node) {
node.getExpression().accept(this);
buffer.append("?");//$NON-NLS-1$
node.getThenExpression().accept(this);
buffer.append(":");//$NON-NLS-1$
node.getElseExpression().accept(this);
return false;
}
/*
* @see ASTVisitor#visit(ConstructorInvocation)
*/
public boolean visit(ConstructorInvocation node) {
buffer.append("this(");//$NON-NLS-1$
for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
Expression e = (Expression) it.next();
e.accept(this);
if (it.hasNext()) {
buffer.append(",");//$NON-NLS-1$
}
}
buffer.append(");");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(ContinueStatement)
*/
public boolean visit(ContinueStatement node) {
buffer.append("continue");//$NON-NLS-1$
if (node.getLabel() != null) {
buffer.append(" ");//$NON-NLS-1$
node.getLabel().accept(this);
}
buffer.append(";");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(DoStatement)
*/
public boolean visit(DoStatement node) {
buffer.append("do ");//$NON-NLS-1$
node.getBody().accept(this);
buffer.append(" while (");//$NON-NLS-1$
node.getExpression().accept(this);
buffer.append(");");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(EmptyStatement)
*/
public boolean visit(EmptyStatement node) {
buffer.append(";");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(ExpressionStatement)
*/
public boolean visit(ExpressionStatement node) {
node.getExpression().accept(this);
buffer.append(";");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(FieldAccess)
*/
public boolean visit(FieldAccess node) {
node.getExpression().accept(this);
buffer.append(".");//$NON-NLS-1$
node.getName().accept(this);
return false;
}
/*
* @see ASTVisitor#visit(FieldDeclaration)
*/
public boolean visit(FieldDeclaration node) {
if (node.getJavadoc() != null) {
node.getJavadoc().accept(this);
}
printModifiers(node.getModifiers());
node.getType().accept(this);
buffer.append(" ");//$NON-NLS-1$
for (Iterator it = node.fragments().iterator(); it.hasNext(); ) {
VariableDeclarationFragment f = (VariableDeclarationFragment) it.next();
f.accept(this);
if (it.hasNext()) {
buffer.append(", ");//$NON-NLS-1$
}
}
buffer.append(";");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(ForStatement)
*/
public boolean visit(ForStatement node) {
buffer.append("for (");//$NON-NLS-1$
for (Iterator it = node.initializers().iterator(); it.hasNext(); ) {
Expression e = (Expression) it.next();
e.accept(this);
}
buffer.append("; ");//$NON-NLS-1$
for (Iterator it = node.updaters().iterator(); it.hasNext(); ) {
Expression e = (Expression) it.next();
e.accept(this);
}
buffer.append("; ");//$NON-NLS-1$
if (node.getExpression() != null) {
node.getExpression().accept(this);
}
buffer.append(") ");//$NON-NLS-1$
node.getBody().accept(this);
return false;
}
/*
* @see ASTVisitor#visit(IfStatement)
*/
public boolean visit(IfStatement node) {
buffer.append("if (");//$NON-NLS-1$
node.getExpression().accept(this);
buffer.append(") ");//$NON-NLS-1$
node.getThenStatement().accept(this);
if (node.getElseStatement() != null) {
buffer.append(" else ");//$NON-NLS-1$
node.getElseStatement().accept(this);
}
return false;
}
/*
* @see ASTVisitor#visit(ImportDeclaration)
*/
public boolean visit(ImportDeclaration node) {
buffer.append("import ");//$NON-NLS-1$
node.getName().accept(this);
if (node.isOnDemand()) {
buffer.append(".*");//$NON-NLS-1$
}
buffer.append(";");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(InfixExpression)
*/
public boolean visit(InfixExpression node) {
node.getLeftOperand().accept(this);
buffer.append(node.getOperator().toString());
node.getRightOperand().accept(this);
for (Iterator it = node.extendedOperands().iterator(); it.hasNext(); ) {
buffer.append(node.getOperator().toString());
Expression e = (Expression) it.next();
e.accept(this);
}
return false;
}
/*
* @see ASTVisitor#visit(InstanceofExpression)
*/
public boolean visit(InstanceofExpression node) {
node.getLeftOperand().accept(this);
buffer.append(" instanceof ");//$NON-NLS-1$
node.getRightOperand().accept(this);
return false;
}
/*
* @see ASTVisitor#visit(Initializer)
*/
public boolean visit(Initializer node) {
if (node.getJavadoc() != null) {
node.getJavadoc().accept(this);
}
printModifiers(node.getModifiers());
node.getBody().accept(this);
return false;
}
/*
* @see ASTVisitor#visit(Javadoc)
*/
public boolean visit(Javadoc node) {
buffer.append(node.getComment());
return false;
}
/*
* @see ASTVisitor#visit(LabeledStatement)
*/
public boolean visit(LabeledStatement node) {
node.getLabel().accept(this);
buffer.append(": ");//$NON-NLS-1$
node.getBody().accept(this);
return false;
}
/*
* @see ASTVisitor#visit(MethodDeclaration)
*/
public boolean visit(MethodDeclaration node) {
if (node.getJavadoc() != null) {
node.getJavadoc().accept(this);
}
printModifiers(node.getModifiers());
if (!node.isConstructor()) {
node.getReturnType().accept(this);
buffer.append(" ");//$NON-NLS-1$
}
node.getName().accept(this);
buffer.append("(");//$NON-NLS-1$
for (Iterator it = node.parameters().iterator(); it.hasNext(); ) {
SingleVariableDeclaration v = (SingleVariableDeclaration) it.next();
v.accept(this);
if (it.hasNext()) {
buffer.append(",");//$NON-NLS-1$
}
}
buffer.append(")");//$NON-NLS-1$
if (!node.thrownExceptions().isEmpty()) {
buffer.append(" throws ");//$NON-NLS-1$
for (Iterator it = node.thrownExceptions().iterator(); it.hasNext(); ) {
Name n = (Name) it.next();
n.accept(this);
if (it.hasNext()) {
buffer.append(", ");//$NON-NLS-1$
}
}
buffer.append(" ");//$NON-NLS-1$
}
if (node.getBody() == null) {
buffer.append(";");//$NON-NLS-1$
} else {
node.getBody().accept(this);
}
return false;
}
/*
* @see ASTVisitor#visit(MethodInvocation)
*/
public boolean visit(MethodInvocation node) {
if (node.getExpression() != null) {
node.getExpression().accept(this);
buffer.append(".");//$NON-NLS-1$
}
node.getName().accept(this);
buffer.append("(");//$NON-NLS-1$
for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
Expression e = (Expression) it.next();
e.accept(this);
if (it.hasNext()) {
buffer.append(",");//$NON-NLS-1$
}
}
buffer.append(")");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(NullLiteral)
*/
public boolean visit(NullLiteral node) {
buffer.append("null");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(NumberLiteral)
*/
public boolean visit(NumberLiteral node) {
buffer.append(node.getToken());
return false;
}
/*
* @see ASTVisitor#visit(PackageDeclaration)
*/
public boolean visit(PackageDeclaration node) {
buffer.append("package ");//$NON-NLS-1$
node.getName().accept(this);
buffer.append(";");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(ParenthesizedExpression)
*/
public boolean visit(ParenthesizedExpression node) {
buffer.append("(");//$NON-NLS-1$
node.getExpression().accept(this);
buffer.append(")");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(PostfixExpression)
*/
public boolean visit(PostfixExpression node) {
node.getOperand().accept(this);
buffer.append(node.getOperator().toString());
return false;
}
/*
* @see ASTVisitor#visit(PrefixExpression)
*/
public boolean visit(PrefixExpression node) {
buffer.append(node.getOperator().toString());
node.getOperand().accept(this);
return false;
}
/*
* @see ASTVisitor#visit(PrimitiveType)
*/
public boolean visit(PrimitiveType node) {
buffer.append(node.getPrimitiveTypeCode().toString());
return false;
}
/*
* @see ASTVisitor#visit(QualifiedName)
*/
public boolean visit(QualifiedName node) {
node.getQualifier().accept(this);
buffer.append(".");//$NON-NLS-1$
node.getName().accept(this);
return false;
}
/*
* @see ASTVisitor#visit(ReturnStatement)
*/
public boolean visit(ReturnStatement node) {
buffer.append("return");//$NON-NLS-1$
if (node.getExpression() != null) {
buffer.append(" ");//$NON-NLS-1$
node.getExpression().accept(this);
}
buffer.append(";");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(SimpleName)
*/
public boolean visit(SimpleName node) {
buffer.append(node.getIdentifier());
return false;
}
/*
* @see ASTVisitor#visit(SimpleType)
*/
public boolean visit(SimpleType node) {
return true;
}
/*
* @see ASTVisitor#visit(SingleVariableDeclaration)
*/
public boolean visit(SingleVariableDeclaration node) {
printModifiers(node.getModifiers());
node.getType().accept(this);
buffer.append(" ");//$NON-NLS-1$
node.getName().accept(this);
if (node.getInitializer() != null) {
buffer.append("=");//$NON-NLS-1$
node.getInitializer().accept(this);
}
return false;
}
/*
* @see ASTVisitor#visit(StringLiteral)
*/
public boolean visit(StringLiteral node) {
buffer.append(node.getEscapedValue());
return false;
}
/*
* @see ASTVisitor#visit(SuperConstructorInvocation)
*/
public boolean visit(SuperConstructorInvocation node) {
if (node.getExpression() != null) {
node.getExpression().accept(this);
buffer.append(".");//$NON-NLS-1$
}
buffer.append("super(");//$NON-NLS-1$
for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
Expression e = (Expression) it.next();
e.accept(this);
if (it.hasNext()) {
buffer.append(",");//$NON-NLS-1$
}
}
buffer.append(");");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(SuperFieldAccess)
*/
public boolean visit(SuperFieldAccess node) {
if (node.getQualifier() != null) {
node.getQualifier().accept(this);
buffer.append(".");//$NON-NLS-1$
}
buffer.append("super.");//$NON-NLS-1$
node.getName().accept(this);
return false;
}
/*
* @see ASTVisitor#visit(SuperMethodInvocation)
*/
public boolean visit(SuperMethodInvocation node) {
if (node.getQualifier() != null) {
node.getQualifier().accept(this);
buffer.append(".");//$NON-NLS-1$
}
buffer.append("super.");//$NON-NLS-1$
node.getName().accept(this);
buffer.append("(");//$NON-NLS-1$
for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
Expression e = (Expression) it.next();
e.accept(this);
if (it.hasNext()) {
buffer.append(",");//$NON-NLS-1$
}
}
buffer.append(")");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(SwitchCase)
*/
public boolean visit(SwitchCase node) {
buffer.append("case ");//$NON-NLS-1$
node.getExpression().accept(this);
buffer.append(": ");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(SwitchStatement)
*/
public boolean visit(SwitchStatement node) {
buffer.append("switch (");//$NON-NLS-1$
node.getExpression().accept(this);
buffer.append(") ");//$NON-NLS-1$
buffer.append("{");//$NON-NLS-1$
for (Iterator it = node.statements().iterator(); it.hasNext(); ) {
Statement s = (Statement) it.next();
s.accept(this);
}
buffer.append("}");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(SynchronizedStatement)
*/
public boolean visit(SynchronizedStatement node) {
buffer.append("synchronized (");//$NON-NLS-1$
node.getExpression().accept(this);
buffer.append(") ");//$NON-NLS-1$
node.getBody().accept(this);
return false;
}
/*
* @see ASTVisitor#visit(ThisExpression)
*/
public boolean visit(ThisExpression node) {
if (node.getQualifier() != null) {
node.getQualifier().accept(this);
buffer.append(".");//$NON-NLS-1$
}
buffer.append("this");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(ThrowStatement)
*/
public boolean visit(ThrowStatement node) {
buffer.append("throw ");//$NON-NLS-1$
node.getExpression().accept(this);
buffer.append(";");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(TryStatement)
*/
public boolean visit(TryStatement node) {
buffer.append("try ");//$NON-NLS-1$
node.getBody().accept(this);
buffer.append(" ");//$NON-NLS-1$
for (Iterator it = node.catchClauses().iterator(); it.hasNext(); ) {
CatchClause cc = (CatchClause) it.next();
cc.accept(this);
}
if (node.getFinally() != null) {
node.getFinally().accept(this);
}
return false;
}
/*
* @see ASTVisitor#visit(TypeDeclaration)
*/
public boolean visit(TypeDeclaration node) {
if (node.getJavadoc() != null) {
node.getJavadoc().accept(this);
}
printModifiers(node.getModifiers());
buffer.append(node.isInterface() ? "interface " : "class ");//$NON-NLS-2$//$NON-NLS-1$
node.getName().accept(this);
buffer.append(" ");//$NON-NLS-1$
if (node.getSuperclass() != null) {
buffer.append("extends ");//$NON-NLS-1$
node.getSuperclass().accept(this);
buffer.append(" ");//$NON-NLS-1$
}
if (!node.superInterfaces().isEmpty()) {
buffer.append(node.isInterface() ? "extends " : "implements ");//$NON-NLS-2$//$NON-NLS-1$
for (Iterator it = node.superInterfaces().iterator(); it.hasNext(); ) {
Name n = (Name) it.next();
n.accept(this);
if (it.hasNext()) {
buffer.append(", ");//$NON-NLS-1$
}
}
buffer.append(" ");//$NON-NLS-1$
}
buffer.append("{");//$NON-NLS-1$
for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext(); ) {
BodyDeclaration d = (BodyDeclaration) it.next();
d.accept(this);
}
buffer.append("}");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(TypeDeclarationStatement)
*/
public boolean visit(TypeDeclarationStatement node) {
node.getTypeDeclaration().accept(this);
buffer.append(";");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(TypeLiteral)
*/
public boolean visit(TypeLiteral node) {
node.getType().accept(this);
buffer.append(".class");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(VariableDeclarationExpression)
*/
public boolean visit(VariableDeclarationExpression node) {
printModifiers(node.getModifiers());
node.getType().accept(this);
buffer.append(" ");//$NON-NLS-1$
for (Iterator it = node.fragments().iterator(); it.hasNext(); ) {
VariableDeclarationFragment f = (VariableDeclarationFragment) it.next();
f.accept(this);
if (it.hasNext()) {
buffer.append(", ");//$NON-NLS-1$
}
}
buffer.append(";");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(VariableDeclarationFragment)
*/
public boolean visit(VariableDeclarationFragment node) {
node.getName().accept(this);
for (int i = 0; i < node.getExtraDimensions(); i++) {
buffer.append("[]");//$NON-NLS-1$
}
if (node.getInitializer() != null) {
buffer.append("=");//$NON-NLS-1$
node.getInitializer().accept(this);
}
return false;
}
/*
* @see ASTVisitor#visit(VariableDeclarationStatement)
*/
public boolean visit(VariableDeclarationStatement node) {
printModifiers(node.getModifiers());
node.getType().accept(this);
buffer.append(" ");//$NON-NLS-1$
for (Iterator it = node.fragments().iterator(); it.hasNext(); ) {
VariableDeclarationFragment f = (VariableDeclarationFragment) it.next();
f.accept(this);
if (it.hasNext()) {
buffer.append(", ");//$NON-NLS-1$
}
}
buffer.append(";");//$NON-NLS-1$
return false;
}
/*
* @see ASTVisitor#visit(WhileStatement)
*/
public boolean visit(WhileStatement node) {
buffer.append("while (");//$NON-NLS-1$
node.getExpression().accept(this);
buffer.append(") ");//$NON-NLS-1$
node.getBody().accept(this);
return false;
}
}