Example usage for org.eclipse.jdt.core.dom Name getNodeType

List of usage examples for org.eclipse.jdt.core.dom Name getNodeType

Introduction

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

Prototype

public final int getNodeType() 

Source Link

Document

Returns an integer value identifying the type of this concrete AST node.

Usage

From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java

License:Apache License

/** Visitor method for {@link QualifiedName}s. */
private void visitQualifiedName(QualifiedName node0, BreakOrNot breaks) {
    QualifiedName node = node0;//from  ww  w. j a  v  a  2s .c  o  m
    sync(node);

    // defer to visitDot for builder-style wrapping if breaks are enabled
    if (breaks.isYes()) {
        visitDot(node0);
        return;
    }

    // Collapse chains of "." operators.
    ArrayDeque<SimpleName> stack = new ArrayDeque<>();
    Name qualifier;
    while (true) {
        stack.addFirst(node.getName());
        qualifier = node.getQualifier();
        if (qualifier == null || qualifier.getNodeType() != ASTNode.QUALIFIED_NAME) {
            break;
        }
        node = (QualifiedName) qualifier;
    }
    if (qualifier != null) {
        visitName(qualifier, breaks);
        token(".");
    }
    boolean needDot = false;
    for (SimpleName name : stack) {
        if (needDot) {
            token(".");
        }
        visit(name);
        needDot = true;
    }
}

From source file:org.eclipse.recommenders.rcp.utils.ASTNodeUtils.java

License:Open Source License

/**
 * Returns the names top-level identifier, i.e., for "java.lang.String" --&gt; "String" and "String" --&gt; "String"
 *
 * @param name//from ww  w  .j  av a 2 s .c  om
 * @return
 */
public static SimpleName stripQualifier(Name name) {
    switch (name.getNodeType()) {
    case ASTNode.SIMPLE_NAME:
        return (SimpleName) name;
    case ASTNode.QUALIFIED_NAME:
        return ((QualifiedName) name).getName();
    default:
        throw throwUnreachable("Unknown subtype of name: '%s'", name.getClass()); //$NON-NLS-1$
    }
}

From source file:org.eclipse.recommenders.utils.rcp.ast.ASTNodeUtils.java

License:Open Source License

/**
 * Returns the names top-level identifier, i.e., for "java.lang.String" --&gt; "String" and "String" --&gt; "String"
 * /*from w w w .  jav  a2 s .c  o  m*/
 * @param name
 * @return
 */
public static SimpleName stripQualifier(Name name) {
    switch (name.getNodeType()) {
    case ASTNode.SIMPLE_NAME:
        return (SimpleName) name;
    case ASTNode.QUALIFIED_NAME:
        return ((QualifiedName) name).getName();
    default:
        throw throwUnreachable("unknow subtype of name: '%s'", name.getClass());
    }
}

From source file:refactorer.Refactorer.java

License:Apache License

protected void processName(Name name) {
    switch (name.getNodeType()) {
    case ASTNode.SIMPLE_NAME:
        break;//www  .j  av  a 2  s.  com
    case ASTNode.QUALIFIED_NAME:
        QualifiedName qualifiedName = (QualifiedName) name;
        ITypeBinding typeBinding = qualifiedName.getQualifier().resolveTypeBinding();
        if (typeBinding != null) {
            AST ast = qualifiedName.getAST();
            String typeName = typeBinding.getQualifiedName();
            if ("javax.media.opengl.GL".equals(typeName)) {
                qualifiedName.setQualifier(ast.newSimpleName("GL2"));
                addImportIfRequired("javax.media.opengl.GL2");

                String constantName = qualifiedName.getName().getFullyQualifiedName();
                if (constantName.endsWith("_EXT") || constantName.endsWith("_ARB")) {
                    //GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT no longer exists, replace with int literal
                    if ("GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT".equals(constantName)) {
                        if (name.getParent().getNodeType() == ASTNode.SWITCH_CASE) {
                            SwitchCase switchCase = (SwitchCase) name.getParent();
                            switchCase.setExpression(ast.newNumberLiteral("0x8CD8"));
                        }
                    } else if (!"GL_TEXTURE_MAX_ANISOTROPY_EXT".equals(constantName)
                            && !"GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT".equals(constantName)
                            && !"GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_EXT".equals(constantName)
                            && !"GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT".equals(constantName)) {
                        qualifiedName.setName(
                                ast.newSimpleName(constantName.substring(0, constantName.length() - 4)));
                    }
                }
            } else if ("com.sun.opengl.util.BufferUtil".equals(typeName)) {
                qualifiedName.setQualifier(ast.newSimpleName("Buffers"));
            }
        }
        break;
    }
}