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

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

Introduction

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

Prototype

public final AST getAST() 

Source Link

Document

Returns this node's AST.

Usage

From source file:lang.java.jdt.internal.FullyQualifyTypeNames.java

License:Open Source License

@Override
public boolean visit(FieldAccess node) {
    Expression exp = node.getExpression();
    if (exp instanceof SimpleName) {
        SimpleName sn = (SimpleName) exp;
        ITypeBinding tb = sn.resolveTypeBinding();
        if (tb != null && (tb.isClass() || tb.isInterface())) {
            IPackageBinding pb = tb.getPackage();
            if (pb != null && !pb.isUnnamed()) {
                String qualifiedTypeName = "";
                if (tb.isNested()) {
                    ITypeBinding parent = tb.getDeclaringClass();
                    String parentString = parent.getName();
                    while (parent != null && parent.isNested()) {
                        parent = parent.getDeclaringClass();
                        parentString = parent.getName() + "." + parentString;
                    }/*from  w  w  w .  j a  v a2  s.co m*/
                    qualifiedTypeName = pb.getName() + "." + parentString + ".";
                } else {
                    qualifiedTypeName = pb.getName() + ".";
                }
                qualifiedTypeName = qualifiedTypeName + sn.toString();
                Name n = node.getAST().newName(qualifiedTypeName);
                rewriter.replace(exp, n, null);
            }
        }
    }
    return true;
}

From source file:lang.java.jdt.internal.UnqualifyTypeNames.java

License:Open Source License

@Override
public boolean visit(FieldAccess node) {
    Expression exp = node.getExpression();
    if (exp instanceof SimpleName) {
        SimpleName sn = (SimpleName) exp;
        ITypeBinding tb = sn.resolveTypeBinding();
        if (tb != null && (tb.isClass() || tb.isInterface() || tb.isEnum())) {
            String typeName = "";
            if (tb.getErasure() != null)
                typeName = tb.getErasure().getName();
            else/*from   w w  w.  ja v  a2 s.  c o m*/
                typeName = tb.getName();

            ITypeBinding declaringClass = tb.getDeclaringClass();
            while (declaringClass != null) {
                typeName = declaringClass.getErasure().getName() + "." + typeName;
                declaringClass = declaringClass.getDeclaringClass();
            }

            IPackageBinding pb = tb.getPackage();
            if (pb != null && !pb.isUnnamed()) {
                typeName = pb.getName() + "." + typeName;
            }

            if (unqualifiedTypes.containsKey(typeName)) {
                Name n = node.getAST().newName(unqualifiedTypes.get(typeName));
                rewriter.replace(exp, n, null);
            }
        }
    }
    return true;
}