Example usage for org.eclipse.jdt.core.dom SimpleName accept

List of usage examples for org.eclipse.jdt.core.dom SimpleName accept

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom SimpleName accept.

Prototype

public final void accept(ASTVisitor visitor) 

Source Link

Document

Accepts the given visitor on a visit of the current node.

Usage

From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java

License:Open Source License

@Override
public boolean visit(MethodDeclaration node) {
    if (node.getJavadoc() != null) {
        node.getJavadoc().accept(this);
    }/*w w w . j  ava 2s  .  c om*/
    if (node.getAST().apiLevel() >= JLS3) {
        printModifiers(node.modifiers());
        if (!node.typeParameters().isEmpty()) {
            this.fBuffer.append("<");//$NON-NLS-1$
            for (Iterator<TypeParameter> it = node.typeParameters().iterator(); it.hasNext();) {
                TypeParameter t = it.next();
                t.accept(this);
                if (it.hasNext()) {
                    this.fBuffer.append(", ");//$NON-NLS-1$
                }
            }
            this.fBuffer.append("> ");//$NON-NLS-1$
        }
    }
    if (!node.isConstructor()) {
        if (node.getReturnType2() != null) {
            node.getReturnType2().accept(this);
        } else {
            // methods really ought to have a return type
            this.fBuffer.append("void");//$NON-NLS-1$
        }
        this.fBuffer.append(" ");//$NON-NLS-1$
    }
    node.getName().accept(this);
    this.fBuffer.append("(");//$NON-NLS-1$
    if (node.getAST().apiLevel() >= AST.JLS8) {
        Type receiverType = node.getReceiverType();
        if (receiverType != null) {
            receiverType.accept(this);
            this.fBuffer.append(' ');
            SimpleName qualifier = node.getReceiverQualifier();
            if (qualifier != null) {
                qualifier.accept(this);
                this.fBuffer.append('.');
            }
            this.fBuffer.append("this"); //$NON-NLS-1$
            if (node.parameters().size() > 0) {
                this.fBuffer.append(',');
            }
        }
    }
    for (Iterator<SingleVariableDeclaration> it = node.parameters().iterator(); it.hasNext();) {
        SingleVariableDeclaration v = it.next();
        v.accept(this);
        if (it.hasNext()) {
            this.fBuffer.append(", ");//$NON-NLS-1$
        }
    }
    this.fBuffer.append(")");//$NON-NLS-1$
    if (node.getAST().apiLevel() >= AST.JLS8) {
        List<Dimension> dimensions = node.extraDimensions();
        for (Iterator<Dimension> it = dimensions.iterator(); it.hasNext();) {
            Dimension e = it.next();
            e.accept(this);
        }
    } else {
        for (int i = 0; i < node.getExtraDimensions(); i++) {
            this.fBuffer.append("[]"); //$NON-NLS-1$
        }
    }
    List<? extends ASTNode> thrownExceptions = node.getAST().apiLevel() >= AST.JLS8
            ? node.thrownExceptionTypes()
            : getThrownExceptions(node);
    if (!thrownExceptions.isEmpty()) {
        this.fBuffer.append(" throws ");//$NON-NLS-1$
        for (Iterator<? extends ASTNode> it = thrownExceptions.iterator(); it.hasNext();) {
            ASTNode n = it.next();
            n.accept(this);
            if (it.hasNext()) {
                this.fBuffer.append(", ");//$NON-NLS-1$
            }
        }
        this.fBuffer.append(" ");//$NON-NLS-1$
    }
    if (node.getBody() == null) {
        this.fBuffer.append(";");//$NON-NLS-1$
    } else {
        node.getBody().accept(this);
    }
    return false;
}

From source file:net.sf.j2s.core.astvisitors.ASTKeywordVisitor.java

License:Open Source License

public boolean visit(BreakStatement node) {
    buffer.append("break");
    /*/*from w  w w . j  a  v a 2  s . co m*/
     * TODO: verify that the label is not supported!
     */
    SimpleName label = node.getLabel();
    if (label != null) {
        buffer.append(' ');
        label.accept(this);
    }
    buffer.append(";\r\n");
    return false;
}

From source file:net.sf.j2s.core.astvisitors.ASTKeywordVisitor.java

License:Open Source License

public boolean visit(ContinueStatement node) {
    buffer.append("continue");
    /*/*  w ww  .  j a v a  2 s  . com*/
     * TODO: verify that label is not supported!
     */
    SimpleName label = node.getLabel();
    if (label != null) {
        buffer.append(' ');
        label.accept(this);
    }
    buffer.append(";\r\n");
    return false;
}

From source file:net.sf.j2s.core.astvisitors.ASTKeywordVisitor.java

License:Open Source License

public boolean visit(VariableDeclarationFragment node) {
    SimpleName name = node.getName();
    IBinding binding = name.resolveBinding();
    if (binding != null) {
        String identifier = name.getIdentifier();
        ASTFinalVariable f = null;//from w  w w .  j a v a 2s . c  o  m
        if (methodDeclareStack.size() == 0) {
            f = new ASTFinalVariable(blockLevel, identifier, null);
        } else {
            String methodSig = (String) methodDeclareStack.peek();
            f = new ASTFinalVariable(blockLevel, identifier, methodSig);
        }
        List finalVars = ((ASTVariableVisitor) getAdaptable(ASTVariableVisitor.class)).finalVars;
        List normalVars = ((ASTVariableVisitor) getAdaptable(ASTVariableVisitor.class)).normalVars;
        f.toVariableName = getIndexedVarName(identifier, normalVars.size());
        normalVars.add(f);
        if ((binding.getModifiers() & Modifier.FINAL) != 0) {
            finalVars.add(f);
        }
    }
    name.accept(this);
    Expression initializer = node.getInitializer();
    if (initializer != null) {
        buffer.append(" = ");
        ITypeBinding typeBinding = initializer.resolveTypeBinding();
        if (typeBinding != null && "char".equals(typeBinding.getName())) {
            ITypeBinding nameTypeBinding = name.resolveTypeBinding();
            String nameType = nameTypeBinding.getName();
            if (initializer instanceof CharacterLiteral) {
                CharacterLiteral cl = (CharacterLiteral) initializer;
                if ("char".equals(nameType)) {
                    String constValue = checkConstantValue(initializer);
                    buffer.append(constValue);
                } else {
                    buffer.append(0 + cl.charValue());
                }
                return false;
            } else {
                if (nameType != null && !"char".equals(nameType) && nameType.indexOf("String") == -1) {
                    int idx1 = buffer.length();
                    buffer.append("(");
                    initializer.accept(this);
                    buffer.append(")");
                    boolean appendingCode = true;
                    int length = buffer.length();
                    if (initializer instanceof MethodInvocation) {
                        MethodInvocation m = (MethodInvocation) initializer;
                        if ("charAt".equals(m.getName().toString())) {
                            int idx2 = buffer.indexOf(".charAt ", idx1);
                            if (idx2 != -1) {
                                StringBuffer newMethodBuffer = new StringBuffer();
                                newMethodBuffer.append(buffer.substring(idx1 + 1, idx2));
                                newMethodBuffer.append(".charCodeAt ");
                                newMethodBuffer.append(buffer.substring(idx2 + 8, length - 1));
                                buffer.delete(idx1, length);
                                buffer.append(newMethodBuffer.toString());
                                appendingCode = false;
                            }
                        }
                    }
                    if (appendingCode) {
                        buffer.append(".charCodeAt (0)");
                    }
                    return false;
                }
            }
        }
        ITypeBinding nameTypeBinding = name.resolveTypeBinding();
        if (nameTypeBinding != null) {
            String nameType = nameTypeBinding.getName();
            if ("char".equals(nameType)) {
                if (typeBinding != null && !"char".equals(typeBinding.getName())) {
                    buffer.append("String.fromCharCode (");
                    initializer.accept(this);
                    buffer.append(")");
                    return false;
                }
            }
        }
        boxingNode(initializer);
    }
    return false;
}

From source file:net.sf.j2s.core.astvisitors.ASTScriptVisitor.java

License:Open Source License

public boolean visit(SingleVariableDeclaration node) {
    SimpleName name = node.getName();
    IBinding binding = name.resolveBinding();
    if (binding != null) {
        String identifier = name.getIdentifier();
        ASTFinalVariable f = null;/*from   ww w .  j  a va  2  s .  c  o  m*/
        if (methodDeclareStack.size() == 0) {
            f = new ASTFinalVariable(blockLevel + 1, identifier, null);
        } else {
            String methodSig = (String) methodDeclareStack.peek();
            f = new ASTFinalVariable(blockLevel + 1, identifier, methodSig);
        }
        List finalVars = ((ASTVariableVisitor) getAdaptable(ASTVariableVisitor.class)).finalVars;
        List normalVars = ((ASTVariableVisitor) getAdaptable(ASTVariableVisitor.class)).normalVars;
        f.toVariableName = getIndexedVarName(identifier, normalVars.size());
        normalVars.add(f);
        if ((binding.getModifiers() & Modifier.FINAL) != 0) {
            finalVars.add(f);
        }
    }
    name.accept(this);
    return false;
}

From source file:org.codemucker.jmutate.ast.JAstFlattener.java

License:Open Source License

public boolean visit(MethodDeclaration node) {
    if (node.getJavadoc() != null) {
        node.getJavadoc().accept(this);
    }/*  w  w  w .  j  a v a  2 s.  c o  m*/
    printIndent();
    if (node.getAST().apiLevel() == JLS2) {
        printModifiers(node.getModifiers());
    }
    if (node.getAST().apiLevel() >= JLS3) {
        printModifiers(node.modifiers());
        if (!node.typeParameters().isEmpty()) {
            this.buffer.append("<");//$NON-NLS-1$
            for (Iterator it = node.typeParameters().iterator(); it.hasNext();) {
                TypeParameter t = (TypeParameter) it.next();
                t.accept(this);
                if (it.hasNext()) {
                    this.buffer.append(",");//$NON-NLS-1$
                }
            }
            this.buffer.append(">");//$NON-NLS-1$
        }
    }
    if (!node.isConstructor()) {
        if (node.getAST().apiLevel() == JLS2) {
            getReturnType(node).accept(this);
        } else {
            if (node.getReturnType2() != null) {
                node.getReturnType2().accept(this);
            } else {
                // methods really ought to have a return type
                this.buffer.append("void");//$NON-NLS-1$
            }
        }
        this.buffer.append(" ");//$NON-NLS-1$
    }
    node.getName().accept(this);
    this.buffer.append("(");//$NON-NLS-1$
    if (node.getAST().apiLevel() >= AST.JLS8) {
        Type receiverType = node.getReceiverType();
        if (receiverType != null) {
            receiverType.accept(this);
            this.buffer.append(' ');
            SimpleName qualifier = node.getReceiverQualifier();
            if (qualifier != null) {
                qualifier.accept(this);
                this.buffer.append('.');
            }
            this.buffer.append("this"); //$NON-NLS-1$
            if (node.parameters().size() > 0) {
                this.buffer.append(',');
            }
        }
    }
    for (Iterator it = node.parameters().iterator(); it.hasNext();) {
        SingleVariableDeclaration v = (SingleVariableDeclaration) it.next();
        v.accept(this);
        if (it.hasNext()) {
            this.buffer.append(",");//$NON-NLS-1$
        }
    }
    this.buffer.append(")");//$NON-NLS-1$
    int size = node.getExtraDimensions();
    if (node.getAST().apiLevel() >= AST.JLS8) {
        List dimensions = node.extraDimensions();
        for (int i = 0; i < size; i++) {
            visit((Dimension) dimensions.get(i));
        }
    } else {
        for (int i = 0; i < size; i++) {
            this.buffer.append("[]"); //$NON-NLS-1$
        }
    }
    if (node.getAST().apiLevel() < AST.JLS8) {
        if (!thrownExceptions(node).isEmpty()) {
            this.buffer.append(" throws ");//$NON-NLS-1$
            for (Iterator it = thrownExceptions(node).iterator(); it.hasNext();) {
                Name n = (Name) it.next();
                n.accept(this);
                if (it.hasNext()) {
                    this.buffer.append(", ");//$NON-NLS-1$
                }
            }
            this.buffer.append(" ");//$NON-NLS-1$
        }
    } else {
        if (!node.thrownExceptionTypes().isEmpty()) {
            this.buffer.append(" throws ");//$NON-NLS-1$
            for (Iterator it = node.thrownExceptionTypes().iterator(); it.hasNext();) {
                Type n = (Type) it.next();
                n.accept(this);
                if (it.hasNext()) {
                    this.buffer.append(", ");//$NON-NLS-1$
                }
            }
            this.buffer.append(" ");//$NON-NLS-1$               
        }
    }
    if (node.getBody() == null) {
        this.buffer.append(";\n");//$NON-NLS-1$
    } else {
        node.getBody().accept(this);
    }
    return false;
}