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

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

Introduction

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

Prototype

public Name getQualifier() 

Source Link

Document

Returns the qualifier part of this qualified name.

Usage

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

License:Open Source License

@Override
public boolean visit(QualifiedName node) {
    node.getQualifier().accept(this);
    this.fBuffer.append(".");//$NON-NLS-1$
    node.getName().accept(this);
    return false;
}

From source file:ca.mcgill.cs.swevo.ppa.inference.QNameInferenceStrategy.java

License:Open Source License

public boolean isSafe(ASTNode node) {
    QualifiedName qName = (QualifiedName) node;
    boolean leftSafe = true;
    boolean rightSafe = true;

    Expression left = qName.getQualifier();
    Expression right = qName.getName();

    if (indexer.isIndexable(left)) {
        leftSafe = indexer.isSafe(left);
    }/*from  ww  w  .j  ava  2s.  co m*/

    if (indexer.isIndexable(right)) {
        rightSafe = indexer.isSafe(right);
    }

    return leftSafe && rightSafe;
}

From source file:ca.mcgill.cs.swevo.ppa.inference.QNameInferenceStrategy.java

License:Open Source License

public void makeSafeSecondary(ASTNode node, TypeFact typeFact) {
    ITypeBinding oldBinding = typeFact.getOldType();
    QualifiedName qName = (QualifiedName) node;
    Expression left = qName.getQualifier();
    Expression right = qName.getName();

    if (indexer.isIndexable(right) && indexer.getMainIndex(right).equals(typeFact.getIndex())) {
        ITypeBinding newBinding = PPABindingsUtil.getTypeBinding(right);

        // ITypeBinding realBinding = qName.resolveTypeBinding();
        TypeFact tFact = new TypeFact(getMainIndex(node), oldBinding, typeFact.getOldDirection(), newBinding,
                typeFact.getNewDirection(), typeFact.getStrategy());
        ppaEngine.reportTypeFact(tFact);
    }/*  ww  w  .  ja v  a 2  s .com*/

    if (indexer.isIndexable(left) && indexer.getMainIndex(left).equals(typeFact.getIndex())) {

    }

}

From source file:ca.mcgill.cs.swevo.ppa.inference.QNameInferenceStrategy.java

License:Open Source License

@Override
public List<PPAIndex> getSecondaryIndexes(ASTNode node) {
    QualifiedName qName = (QualifiedName) node;
    List<PPAIndex> indexes = new ArrayList<PPAIndex>();

    Expression left = qName.getQualifier();
    Expression right = qName.getName();

    if (indexer.isIndexable(left)) {
        PPAIndex tempIndex = indexer.getMainIndex(left);
        indexes.add(tempIndex);//w w w . java  2s  . c om
    }

    if (indexer.isIndexable(right)) {
        PPAIndex tempIndex = indexer.getMainIndex(right);
        indexes.add(tempIndex);
    }

    return indexes;
}

From source file:ca.mcgill.cs.swevo.ppa.PPAASTUtil.java

License:Open Source License

/**
 * <p>//from  ww  w . j  a va 2s .com
 * Convenience method to exclude self and/or name.
 * </p>
 * 
 * @param node
 * @param includeSelf
 * @return
 */
public static ASTNode getFieldContainer(ASTNode node, boolean includeSpecial, boolean includeSelf) {
    ASTNode container = null;

    // XXX Special case: if you want the container of the first qualifier in
    // a qualified name,
    // You want the type declaration (or whatever is the top-level parent),
    // but not the
    // qualified name.
    if (!includeSelf && includeSpecial) {
        ASTNode parent = node.getParent();
        if (parent instanceof QualifiedName) {
            QualifiedName qName = (QualifiedName) parent;
            if (qName.getQualifier().equals(node)) {
                return getFieldContainer(parent, includeSpecial, includeSelf);
            }
        }
    }

    if (node == null) {
        container = null;
    } else if (includeSelf && isFieldContainer(node, includeSpecial)) {
        if (node instanceof QualifiedName) {
            container = ((QualifiedName) node).getQualifier();
        } else if (node instanceof SuperFieldAccess) {
            SuperFieldAccess sFieldAccess = (SuperFieldAccess) node;
            if (sFieldAccess.getQualifier() != null) {
                container = sFieldAccess.getQualifier();
            } else {
                container = getFieldContainer(node.getParent(), includeSpecial, true);
            }
        } else if (node instanceof FieldAccess) {
            container = ((FieldAccess) node).getExpression();
        } else {
            container = node;
        }
    } else {
        container = getFieldContainer(node.getParent(), includeSpecial, true);
    }

    return container;
}

From source file:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(QualifiedName node) {
    node.getQualifier().accept(this);
    this.buffer.append(".");//$NON-NLS-1$
    node.getName().accept(this);
    return false;
}

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/*from w  ww  .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.dart.java2dart.SyntaxTranslator.java

License:Open Source License

@Override
public boolean visit(org.eclipse.jdt.core.dom.QualifiedName node) {
    PropertyAccess result = propertyAccess(translateExpression(node.getQualifier()),
            translateSimpleName(node.getName()));
    context.putNodeBinding(result, node.resolveBinding());
    return done(result);
}

From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java

License:Open Source License

@Override
public boolean visit(Assignment node) {
    Operator op = node.getOperator();//from  w w w  . jav a  2 s.c o m
    Expression lhs = node.getLeftHandSide();
    Expression rhs = node.getRightHandSide();
    if (op == Operator.PLUS_ASSIGN && Types.isJavaStringType(lhs.resolveTypeBinding())) {
        boolean needClosingParen = printAssignmentLhs(lhs);
        // Change "str1 += str2" to "str1 = str1 + str2".
        buffer.append(" = ");
        printStringConcatenation(lhs, rhs, Collections.<Expression>emptyList(), needClosingParen);
        if (needClosingParen) {
            buffer.append(")");
        }
    } else if (op == Operator.REMAINDER_ASSIGN && (isFloatingPoint(lhs) || isFloatingPoint(rhs))) {
        lhs.accept(this);
        buffer.append(" = fmod(");
        lhs.accept(this);
        buffer.append(", ");
        rhs.accept(this);
        buffer.append(")");
    } else if (lhs instanceof ArrayAccess) {
        printArrayElementAssignment(lhs, rhs, op);
    } else if (op == Operator.RIGHT_SHIFT_UNSIGNED_ASSIGN) {
        lhs.accept(this);
        buffer.append(" = ");
        printUnsignedRightShift(lhs, rhs);
    } else {
        IVariableBinding var = Types.getVariableBinding(lhs);
        boolean useWriter = false;
        if (var != null && var.getDeclaringClass() != null) {
            // Test with toString, as var may have been have a renamed type.
            String declaringClassName = var.getDeclaringClass().toString();
            String methodsClassName = Types.getTypeBinding(getOwningType(node)).toString();
            useWriter = Types.isStaticVariable(var) && !declaringClassName.equals(methodsClassName);
        }
        if (useWriter) {
            // convert static var assignment to its writer message
            buffer.append('[');
            if (lhs instanceof QualifiedName) {
                QualifiedName qn = (QualifiedName) lhs;
                qn.getQualifier().accept(this);
            } else {
                buffer.append(NameTable.getFullName(var.getDeclaringClass()));
            }
            buffer.append(" set");
            buffer.append(NameTable.capitalize(var.getName()));
            String typeName = NameTable.javaTypeToCpp(var.getType(), false);
            String param = CppSourceFileGenerator.parameterKeyword(typeName, var.getType());
            buffer.append(NameTable.capitalize(param));
            buffer.append(':');
            rhs.accept(this);
            buffer.append(']');
            return false;
        } else {
            boolean needClosingParen = printAssignmentLhs(lhs);
            buffer.append(' ');
            buffer.append(op.toString());
            buffer.append(' ');
            if (Types.isJavaObjectType(Types.getTypeBinding(lhs)) && Types.getTypeBinding(rhs).isInterface()) {
                // The compiler doesn't know that NSObject is the root of all
                // objects used by transpiled code, so add a cast.
                buffer.append("(NSObject *) ");
            }
            if (useReferenceCounting && !isNewAssignment(node) && var != null && Types.isStaticVariable(var)
                    && !var.getType().isPrimitive() && !Types.isWeakReference(var)
                    && rhs.getNodeType() != ASTNode.NULL_LITERAL) {
                buffer.append('[');
                rhs.accept(this);
                buffer.append(" retain]");
            } else {
                boolean needRetainRhs = needClosingParen && !isNewAssignment(node)
                        && !Types.isWeakReference(var);
                if (rhs instanceof NullLiteral) {
                    needRetainRhs = false;
                }
                if (needRetainRhs) {
                    buffer.append("[");
                }
                rhs.accept(this);
                if (needRetainRhs) {
                    buffer.append(" retain]");
                }
                if (needClosingParen) {
                    buffer.append(")");
                }
            }
            return false;
        }
    }
    return false;
}

From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java

License:Open Source License

@Override
public boolean visit(QualifiedName node) {
    IBinding binding = Types.getBinding(node);
    if (binding instanceof IVariableBinding) {
        IVariableBinding var = (IVariableBinding) binding;
        if (Types.isPrimitiveConstant(var)) {
            buffer.append(NameTable.getPrimitiveConstantName(var));
            return false;
        } else if (Types.isStaticVariable(var)) {
            printStaticVarReference(node);
            return false;
        }/*  ww w  . j  a  va  2 s  .co m*/

        if (maybePrintArrayLength(var.getName(), node.getQualifier())) {
            return false;
        }
    }
    if (binding instanceof ITypeBinding) {
        buffer.append(NameTable.getFullName((ITypeBinding) binding));
        return false;
    }
    printNilCheck(node.getQualifier(), true);
    buffer.append('.');
    node.getName().accept(this);
    return false;
}