Example usage for org.eclipse.jdt.core.dom QualifiedName getAST

List of usage examples for org.eclipse.jdt.core.dom QualifiedName getAST

Introduction

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

Prototype

public final AST getAST() 

Source Link

Document

Returns this node's AST.

Usage

From source file:com.google.currysrc.processors.ModifyQualifiedNames.java

License:Apache License

@Override
public void process(Context context, CompilationUnit cu) {
    final ASTRewrite rewrite = context.rewrite();
    ASTVisitor visitor = new ASTVisitor(true /* visitDocTags */) {
        @Override//w  w  w.ja  v  a  2 s  .co  m
        public boolean visit(QualifiedName node) {
            Name qualifier = node.getQualifier();
            if (qualifier != null) {
                String fullyQualifiedName = qualifier.getFullyQualifiedName();
                if (fullyQualifiedName.startsWith(oldPrefix)) {
                    String newQualifierString = newPrefix + fullyQualifiedName.substring(oldPrefix.length());
                    Name newQualifier = node.getAST().newName(newQualifierString);
                    rewrite.replace(qualifier, newQualifier, null /* editGroup */);
                }
            }
            return false;
        }
    };
    cu.accept(visitor);
}

From source file:com.google.devtools.j2objc.translate.ASTFactory.java

License:Apache License

/**
 * Replaces (in place) a QualifiedName node with an equivalent FieldAccess
 * node. This is helpful when a mutation needs to replace the qualifier with
 * a node that has Expression type but not Name type.
 *//*from   ww w  .  j  a  v a  2 s.  c o m*/
public static FieldAccess convertToFieldAccess(QualifiedName node) {
    AST ast = node.getAST();
    ASTNode parent = node.getParent();
    if (parent instanceof QualifiedName) {
        FieldAccess newParent = convertToFieldAccess((QualifiedName) parent);
        Expression expr = newParent.getExpression();
        assert expr instanceof QualifiedName;
        node = (QualifiedName) expr;
    }
    FieldAccess newNode = newFieldAccess(ast, Types.getVariableBinding(node),
            NodeCopier.copySubtree(ast, node.getQualifier()));
    ASTUtil.setProperty(node, newNode);
    return newNode;
}

From source file:nl.han.ica.core.issue.solver.EncapsulateFieldSolver.java

@SuppressWarnings("unchecked")
private void refactorQualifiedNames(QualifiedName qualifiedName) {
    SourceFile sourceFile = getSourceFileFromNode(qualifiedName);
    IDocument document = getSourceFileDocument(sourceFile);
    Delta delta = createDelta(sourceFile, document);
    AST ast = qualifiedName.getAST();

    ASTRewrite rewrite = ASTRewrite.create(ast);
    MethodInvocation methodInvocation = ast.newMethodInvocation();
    methodInvocation.setExpression(ast.newSimpleName(qualifiedName.getQualifier().toString()));

    if (qualifiedName.getParent() instanceof Assignment
            && qualifiedName != ((Assignment) qualifiedName.getParent()).getRightHandSide()) {
        Assignment assignment = (Assignment) qualifiedName.getParent();
        methodInvocation.setName(ast.newSimpleName(setter.getName().toString()));
        methodInvocation.arguments().add(ASTNode.copySubtree(ast, assignment.getRightHandSide()));
        rewrite.replace(assignment, methodInvocation, null);
    } else {//from  ww w.  ja v a  2  s.c o  m
        methodInvocation.setName(ast.newSimpleName(getter.getName().toString()));
        rewrite.replace(qualifiedName, methodInvocation, null);
    }

    TextEdit textEdit = rewrite.rewriteAST(document, JavaCore.getOptions());

    try {
        textEdit.apply(document);
    } catch (MalformedTreeException | BadLocationException e) {
        log.fatal(e);
    }
    delta.setAfter(document.get());
}

From source file:refactorer.Refactorer.java

License:Apache License

protected void processName(Name name) {
    switch (name.getNodeType()) {
    case ASTNode.SIMPLE_NAME:
        break;//from w w w .  j  a  v a  2 s .co  m
    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;
    }
}