Example usage for org.eclipse.jdt.core.dom IBinding isRecovered

List of usage examples for org.eclipse.jdt.core.dom IBinding isRecovered

Introduction

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

Prototype

public boolean isRecovered();

Source Link

Document

Return whether this binding is created because the bindings recovery is enabled.

Usage

From source file:com.intel.ide.eclipse.mpt.ast.UnresolvedElementsSubProcessor.java

License:Open Source License

public static void addNewTypeProposals(ICompilationUnit cu, Name refNode, int kind, int relevance,
        Map<String, LinkedCorrectionProposal> proposals) throws CoreException {
    Name node = refNode;/* ww w .j ava2s.co  m*/
    //      do {
    String typeName = ASTNodes.getSimpleNameIdentifier(node);
    Name qualifier = null;
    // only propose to create types for qualifiers when the name starts with upper case
    boolean isPossibleName = isLikelyTypeName(typeName) || node == refNode;
    if (isPossibleName) {
        IPackageFragment enclosingPackage = null;
        IType enclosingType = null;
        if (node.isSimpleName()) {
            enclosingPackage = (IPackageFragment) cu.getParent();
            return;
            // don't suggest member type, user can select it in wizard
        } else {
            Name qualifierName = ((QualifiedName) node).getQualifier();
            IBinding binding = qualifierName.resolveBinding();
            if (binding != null && binding.isRecovered()) {
                binding = null;
            }
            if (binding instanceof ITypeBinding) {
                enclosingType = (IType) binding.getJavaElement();
            } else if (binding instanceof IPackageBinding) {
                qualifier = qualifierName;
                enclosingPackage = (IPackageFragment) binding.getJavaElement();
            } else {
                IJavaElement[] res = cu.codeSelect(qualifierName.getStartPosition(), qualifierName.getLength());
                if (res != null && res.length > 0 && res[0] instanceof IType) {
                    enclosingType = (IType) res[0];
                } else {
                    qualifier = qualifierName;
                    enclosingPackage = JavaModelUtil.getPackageFragmentRoot(cu)
                            .getPackageFragment(ASTResolving.getFullName(qualifierName));
                }
            }
        }
        int rel = relevance;
        if (enclosingPackage != null && isLikelyPackageName(enclosingPackage.getElementName())) {
            rel += 3;
        }

        if (enclosingPackage != null
                && !enclosingPackage.getCompilationUnit(typeName + JavaModelUtil.DEFAULT_CU_SUFFIX).exists()
                || enclosingType != null && !enclosingType.isReadOnly()
                        && !enclosingType.getType(typeName).exists()) { // new member type
            IJavaElement enclosing = enclosingPackage != null ? (IJavaElement) enclosingPackage : enclosingType;

            String name = node.getFullyQualifiedName();

            if ((kind & SimilarElementsRequestor.CLASSES) != 0) {
                proposals.put(name, new NewCUProposal(cu, node, NewCUProposal.K_CLASS, enclosing, rel + 3));
            } else if ((kind & SimilarElementsRequestor.INTERFACES) != 0) {
                proposals.put(name, new NewCUProposal(cu, node, NewCUProposal.K_INTERFACE, enclosing, rel + 2));
            } else if ((kind & SimilarElementsRequestor.ENUMS) != 0) {
                proposals.put(name, new NewCUProposal(cu, node, NewCUProposal.K_ENUM, enclosing, rel));
            }
        }
    }
    node = qualifier;
    //      } while (node != null);
}

From source file:edu.uci.ics.sourcerer.extractor.ast.ReferenceExtractorVisitor.java

License:Open Source License

/**
 * This method writes://from   ww  w .j  a  v  a 2s.c  o m
 *<ul>
 *  <li>For any field:
 *  <ul>
 *    <li>Reads relation to <code>IRelationWriter</code>.</li>
 *    <li>Writes relation to <code>IRelationWriter</code>.</li>
 *  </ul></li>
 *  <li>For any type reference:
 *  <ul>
 *    <li>Uses relation to <code>IRelationWriter</code>.</li>
 *  </ul></li>
 *</ul>
 */
@Override
public boolean visit(SimpleName node) {
    IBinding binding = node.resolveBinding();

    if (binding instanceof IVariableBinding) {
        IVariableBinding varBinding = (IVariableBinding) binding;
        if (varBinding.isField()) {
            ITypeBinding declaringClass = varBinding.getDeclaringClass();
            if (declaringClass != null) {
                declaringClass = declaringClass.getErasure();
            }
            String fqn = null;
            if (declaringClass == null) {
                if (binding.isRecovered()) {
                    fqn = getUnknownFqn(binding.getName());
                } else if (binding.getName().equals("length")) {
                    return true;
                } else {
                    logger.log(Level.SEVERE,
                            "Non-recovered field binding without a declaring class that's not an array.length!",
                            node);
                    return true;
                }
            } else {
                fqn = getTypeFqn(declaringClass) + "." + binding.getName();
            }
            // Write the relation
            if (inLhsAssignment) {
                relationWriter.writeWrites(fqnStack.getFqn(), fqn, getLocation(node));
            } else {
                relationWriter.writeReads(fqnStack.getFqn(), fqn, getLocation(node));
            }
            //        if (!inFieldDeclaration) {
            //          relationWriter.writeUses(fqnStack.getFqn(), fqn, getLocation(node));
            //        }
        } else {
            // Write the uses relation
            //        relationWriter.writeUses(fqnStack.getFqn(), getTypeFqn(getBaseType(varBinding.getType())), getLocation(node));
        }
    } else if (binding instanceof ITypeBinding) {
        ITypeBinding typeBinding = (ITypeBinding) binding;
        // Write the uses relation
        relationWriter.writeUses(fqnStack.getFqn(), getTypeFqn(getBaseType(typeBinding)), getLocation(node));
    }
    return true;
}

From source file:edu.uci.ics.sourcerer.tools.java.extractor.eclipse.ReferenceExtractorVisitor.java

License:Open Source License

/**
 * This method writes://from   ww  w. j a  v a2s .  c  o m
 *<ul>
 *  <li>For any field:
 *  <ul>
 *    <li>Reads relation to <code>IRelationWriter</code>.</li>
 *    <li>Writes relation to <code>IRelationWriter</code>.</li>
 *  </ul></li>
 *  <li>For any type reference:
 *  <ul>
 *    <li>Uses relation to <code>IRelationWriter</code>.</li>
 *  </ul></li>
 *</ul>
 */
@Override
public boolean visit(SimpleName node) {
    IBinding binding = node.resolveBinding();

    if (binding instanceof IVariableBinding) {
        IVariableBinding varBinding = (IVariableBinding) binding;
        if (varBinding.isField()) {
            ITypeBinding declaringClass = varBinding.getDeclaringClass();
            if (declaringClass != null) {
                declaringClass = declaringClass.getErasure();
            }
            String fqn = null;
            if (declaringClass == null) {
                if (binding.isRecovered()) {
                    fqn = createUnknownFqn(binding.getName());
                } else if (binding.getName().equals("length")) {
                    return true;
                } else {
                    logger.log(Level.SEVERE,
                            "Non-recovered field binding without a declaring class that's not an array.length!",
                            node);
                    return true;
                }
            } else {
                fqn = getTypeFqn(declaringClass) + "." + binding.getName();
            }
            // Write the relation
            if (inLhsAssignment) {
                relationWriter.writeRelation(Relation.WRITES, fqnStack.getFqn(), fqn, createLocation(node));
            } else {
                relationWriter.writeRelation(Relation.READS, fqnStack.getFqn(), fqn, createLocation(node));
            }
        }
    } else if (binding instanceof ITypeBinding) {
        ITypeBinding typeBinding = (ITypeBinding) binding;
        // Write the uses relation
        relationWriter.writeRelation(Relation.USES, fqnStack.getFqn(), getTypeFqn(getBaseType(typeBinding)),
                createLocation(node));
    }
    return true;
}

From source file:org.eclipse.virgo.ide.bundlor.jdt.core.ArtifactAnalyserTypeVisitor.java

License:Open Source License

/**
 * It is important to record the type binding only if it is not recovered. Recovered bindings occur for invalid
 * source code and incomplete class paths.
 *
 * @param binding the binding which may be recorded
 * @return <code>true</code> if and only if the binding should be recorded
 *//*  w  w  w . ja  va  2 s .c o  m*/
private boolean isValid(IBinding binding) {
    return binding != null && !binding.isRecovered();
}