Example usage for org.eclipse.jdt.internal.compiler.lookup TypeBinding isValidBinding

List of usage examples for org.eclipse.jdt.internal.compiler.lookup TypeBinding isValidBinding

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.lookup TypeBinding isValidBinding.

Prototype

public final boolean isValidBinding() 

Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java

License:Open Source License

protected TypeBinding getType(Object typeKey, char[] typeName) {
    if (this.unitScope == null || typeName == null || typeName.length == 0)
        return null;
    // Try to get binding from cache
    Binding binding = (Binding) this.bindings.get(typeKey);
    if (binding != null) {
        if (binding instanceof TypeBinding && binding.isValidBinding())
            return (TypeBinding) binding;
        return null;
    }/* w w w . j  a  va2s.c  o m*/
    // Get binding from unit scope
    char[][] compoundName = CharOperation.splitOn('.', typeName);
    TypeBinding typeBinding = this.unitScope.getType(compoundName, compoundName.length);
    if (typeBinding == null || !typeBinding.isValidBinding()) {
        typeBinding = this.lookupEnvironment.getType(compoundName);
    }
    this.bindings.put(typeKey, typeBinding);
    return typeBinding != null && typeBinding.isValidBinding() ? typeBinding : null;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.PatternLocator.java

License:Open Source License

/**
 * Returns whether the given type binding matches the given simple name pattern
 * and qualification pattern./*from  w  w  w .ja  va  2s. c o m*/
 * Note that from since 3.1, this method resolve to accurate member or local types
 * even if they are not fully qualified (i.e. X.Member instead of p.X.Member).
 * Returns ACCURATE_MATCH if it does.
 * Returns INACCURATE_MATCH if resolve failed.
 * Returns IMPOSSIBLE_MATCH if it doesn't.
 */
protected int resolveLevelForType(char[] simpleNamePattern, char[] qualificationPattern, TypeBinding binding) {
    //   return resolveLevelForType(qualifiedPattern(simpleNamePattern, qualificationPattern), type);
    char[] qualifiedPattern = getQualifiedPattern(simpleNamePattern, qualificationPattern);
    int level = resolveLevelForType(qualifiedPattern, binding);
    if (level == ACCURATE_MATCH || binding == null || !binding.isValidBinding())
        return level;
    TypeBinding type = binding instanceof ArrayBinding ? ((ArrayBinding) binding).leafComponentType : binding;
    char[] sourceName = null;
    if (type.isMemberType() || type.isLocalType()) {
        if (qualificationPattern != null) {
            sourceName = getQualifiedSourceName(binding);
        } else {
            sourceName = binding.sourceName();
        }
    } else if (qualificationPattern == null) {
        sourceName = getQualifiedSourceName(binding);
    }
    if (sourceName == null)
        return IMPOSSIBLE_MATCH;
    switch (this.matchMode) {
    case SearchPattern.R_PREFIX_MATCH:
        if (CharOperation.prefixEquals(qualifiedPattern, sourceName, this.isCaseSensitive)) {
            return ACCURATE_MATCH;
        }
        break;
    case SearchPattern.R_CAMELCASE_MATCH:
        if ((qualifiedPattern.length > 0 && sourceName.length > 0 && qualifiedPattern[0] == sourceName[0])) {
            if (CharOperation.camelCaseMatch(qualifiedPattern, sourceName, false)) {
                return ACCURATE_MATCH;
            }
            if (!this.isCaseSensitive && CharOperation.prefixEquals(qualifiedPattern, sourceName, false)) {
                return ACCURATE_MATCH;
            }
        }
        break;
    case SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH:
        if ((qualifiedPattern.length > 0 && sourceName.length > 0 && qualifiedPattern[0] == sourceName[0])) {
            if (CharOperation.camelCaseMatch(qualifiedPattern, sourceName, true)) {
                return ACCURATE_MATCH;
            }
        }
        break;
    default:
        if (CharOperation.match(qualifiedPattern, sourceName, this.isCaseSensitive)) {
            return ACCURATE_MATCH;
        }
    }
    return IMPOSSIBLE_MATCH;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.PatternLocator.java

License:Open Source License

/**
 * Returns whether the given type binding matches the given qualified pattern.
 * Returns ACCURATE_MATCH if it does.//from   w  w w.  j a  v a2 s  .c o m
 * Returns INACCURATE_MATCH if resolve failed.
 * Returns IMPOSSIBLE_MATCH if it doesn't.
 */
protected int resolveLevelForType(char[] qualifiedPattern, TypeBinding type) {
    if (qualifiedPattern == null)
        return ACCURATE_MATCH;
    if (type == null || !type.isValidBinding())
        return INACCURATE_MATCH;

    // Type variable cannot be specified through pattern => this kind of binding cannot match it (see bug 79803)
    if (type.isTypeVariable())
        return IMPOSSIBLE_MATCH;

    // NOTE: if case insensitive search then qualifiedPattern is assumed to be lowercase

    char[] qualifiedPackageName = type.qualifiedPackageName();
    char[] qualifiedSourceName = qualifiedSourceName(type);
    char[] fullyQualifiedTypeName = qualifiedPackageName.length == 0 ? qualifiedSourceName
            : CharOperation.concat(qualifiedPackageName, qualifiedSourceName, '.');
    return CharOperation.match(qualifiedPattern, fullyQualifiedTypeName, this.isCaseSensitive) ? ACCURATE_MATCH
            : IMPOSSIBLE_MATCH;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.SuperTypeReferenceLocator.java

License:Open Source License

public int resolveLevel(ASTNode node) {
    if (!(node instanceof TypeReference))
        return IMPOSSIBLE_MATCH;

    TypeReference typeRef = (TypeReference) node;
    TypeBinding typeBinding = typeRef.resolvedType;
    if (typeBinding instanceof ArrayBinding)
        typeBinding = ((ArrayBinding) typeBinding).leafComponentType;
    if (typeBinding instanceof ProblemReferenceBinding)
        typeBinding = ((ProblemReferenceBinding) typeBinding).closestMatch();

    if (typeBinding == null || !typeBinding.isValidBinding())
        return INACCURATE_MATCH;
    return resolveLevelForType(this.pattern.superSimpleName, this.pattern.superQualification, typeBinding);
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.TypeReferenceLocator.java

License:Open Source License

protected int resolveLevelForType(TypeBinding typeBinding) {
    if (typeBinding == null || !typeBinding.isValidBinding()) {
        if (this.pattern.typeSuffix != TYPE_SUFFIX)
            return INACCURATE_MATCH;
    } else {/*ww  w  .java 2  s  .  c om*/
        switch (this.pattern.typeSuffix) {
        case CLASS_SUFFIX:
            if (!typeBinding.isClass())
                return IMPOSSIBLE_MATCH;
            break;
        case CLASS_AND_INTERFACE_SUFFIX:
            if (!(typeBinding.isClass() || (typeBinding.isInterface() && !typeBinding.isAnnotationType())))
                return IMPOSSIBLE_MATCH;
            break;
        case CLASS_AND_ENUM_SUFFIX:
            if (!(typeBinding.isClass() || typeBinding.isEnum()))
                return IMPOSSIBLE_MATCH;
            break;
        case INTERFACE_SUFFIX:
            if (!typeBinding.isInterface() || typeBinding.isAnnotationType())
                return IMPOSSIBLE_MATCH;
            break;
        case INTERFACE_AND_ANNOTATION_SUFFIX:
            if (!(typeBinding.isInterface() || typeBinding.isAnnotationType()))
                return IMPOSSIBLE_MATCH;
            break;
        case ENUM_SUFFIX:
            if (!typeBinding.isEnum())
                return IMPOSSIBLE_MATCH;
            break;
        case ANNOTATION_TYPE_SUFFIX:
            if (!typeBinding.isAnnotationType())
                return IMPOSSIBLE_MATCH;
            break;
        case TYPE_SUFFIX: // nothing
        }
    }
    return resolveLevelForType(this.pattern.simpleName, this.pattern.qualification,
            this.pattern.getTypeArguments(), 0, typeBinding);
}

From source file:org.eclipse.che.jdt.internal.core.search.matching.SuperTypeReferenceLocator.java

License:Open Source License

public int resolveLevel(ASTNode node) {
    TypeBinding typeBinding = null;
    if (node instanceof LambdaExpression) {
        LambdaExpression lambda = (LambdaExpression) node;
        typeBinding = lambda.resolvedType;
    } else {/*from w w w.  j a v a 2 s .c  o m*/
        if (!(node instanceof TypeReference))
            return IMPOSSIBLE_MATCH;
        TypeReference typeRef = (TypeReference) node;
        typeBinding = typeRef.resolvedType;
    }

    if (typeBinding instanceof ArrayBinding)
        typeBinding = ((ArrayBinding) typeBinding).leafComponentType;
    if (typeBinding instanceof ProblemReferenceBinding)
        typeBinding = ((ProblemReferenceBinding) typeBinding).closestMatch();

    if (typeBinding == null || !typeBinding.isValidBinding())
        return INACCURATE_MATCH;
    return resolveLevelForType(this.pattern.superSimpleName, this.pattern.superQualification, typeBinding);
}

From source file:org.eclipse.che.jdt.internal.core.search.matching.TypeReferenceLocator.java

License:Open Source License

int resolveLevelForTypeOrQualifyingTypes(TypeReference typeRef, TypeBinding typeBinding) {
    if (typeBinding == null || !typeBinding.isValidBinding())
        return INACCURATE_MATCH;
    List resolutionsList = (List) this.recordedResolutions.get(typeRef);
    if (resolutionsList != null) {
        for (Iterator i = resolutionsList.iterator(); i.hasNext();) {
            TypeBinding resolution = (TypeBinding) i.next();
            int level = resolveLevelForType(resolution);
            if (level != IMPOSSIBLE_MATCH)
                return level;
        }/*from   w  ww  .j  a v  a 2 s  .  co m*/
    }
    return IMPOSSIBLE_MATCH;
}

From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java

License:Open Source License

public ArrayBinding createArrayType(TypeBinding type, int dimension) {
    if (type.isValidBinding())
        return environment().createArrayType(type, dimension);
    // do not cache obvious invalid types
    return new ArrayBinding(type, dimension, environment());
}

From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java

License:Open Source License

public final TypeBinding getType(char[][] compoundName, int typeNameLength) {
    if (typeNameLength == 1) {
        // Would like to remove this test and require senders to specially handle base types
        TypeBinding binding = getBaseType(compoundName[0]);
        if (binding != null)
            return binding;
    }//  w  w  w . j a va2  s .com

    CompilationUnitScope unitScope = compilationUnitScope();
    unitScope.recordQualifiedReference(compoundName);
    Binding binding = getTypeOrPackage(compoundName[0],
            typeNameLength == 1 ? Binding.TYPE : Binding.TYPE | Binding.PACKAGE, true);
    if (binding == null) {
        char[][] qName = new char[][] { compoundName[0] };
        return new ProblemReferenceBinding(qName,
                environment().createMissingType(compilationUnitScope().getCurrentPackage(), qName),
                ProblemReasons.NotFound);
    }
    if (!binding.isValidBinding()) {
        if (binding instanceof PackageBinding) {
            char[][] qName = new char[][] { compoundName[0] };
            return new ProblemReferenceBinding(qName, environment().createMissingType(null, qName),
                    ProblemReasons.NotFound);
        }
        return (ReferenceBinding) binding;
    }
    int currentIndex = 1;
    boolean checkVisibility = false;
    if (binding instanceof PackageBinding) {
        PackageBinding packageBinding = (PackageBinding) binding;
        while (currentIndex < typeNameLength) {
            binding = packageBinding.getTypeOrPackage(compoundName[currentIndex++]); // does not check visibility
            if (binding == null) {
                char[][] qName = CharOperation.subarray(compoundName, 0, currentIndex);
                return new ProblemReferenceBinding(qName,
                        environment().createMissingType(packageBinding, qName), ProblemReasons.NotFound);
            }
            if (!binding.isValidBinding())
                return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex),
                        binding instanceof ReferenceBinding
                                ? (ReferenceBinding) ((ReferenceBinding) binding).closestMatch()
                                : null,
                        binding.problemId());
            if (!(binding instanceof PackageBinding))
                break;
            packageBinding = (PackageBinding) binding;
        }
        if (binding instanceof PackageBinding) {
            char[][] qName = CharOperation.subarray(compoundName, 0, currentIndex);
            return new ProblemReferenceBinding(qName, environment().createMissingType(null, qName),
                    ProblemReasons.NotFound);
        }
        checkVisibility = true;
    }

    // binding is now a ReferenceBinding
    ReferenceBinding typeBinding = (ReferenceBinding) binding;
    unitScope.recordTypeReference(typeBinding);
    if (checkVisibility) // handles the fall through case
        if (!typeBinding.canBeSeenBy(this))
            return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex),
                    typeBinding, ProblemReasons.NotVisible);

    while (currentIndex < typeNameLength) {
        typeBinding = getMemberType(compoundName[currentIndex++], typeBinding);
        if (!typeBinding.isValidBinding()) {
            if (typeBinding instanceof ProblemReferenceBinding) {
                ProblemReferenceBinding problemBinding = (ProblemReferenceBinding) typeBinding;
                return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex),
                        problemBinding.closestReferenceMatch(), typeBinding.problemId());
            }
            return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex),
                    (ReferenceBinding) ((ReferenceBinding) binding).closestMatch(), typeBinding.problemId());
        }
    }
    return typeBinding;
}

From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java

License:Open Source License

public final Binding getTypeOrPackage(char[][] compoundName) {
    int nameLength = compoundName.length;
    if (nameLength == 1) {
        TypeBinding binding = getBaseType(compoundName[0]);
        if (binding != null)
            return binding;
    }/* w  ww.j a v  a2s .c  om*/
    Binding binding = getTypeOrPackage(compoundName[0], Binding.TYPE | Binding.PACKAGE, true);
    if (!binding.isValidBinding())
        return binding;

    int currentIndex = 1;
    boolean checkVisibility = false;
    if (binding instanceof PackageBinding) {
        PackageBinding packageBinding = (PackageBinding) binding;

        while (currentIndex < nameLength) {
            binding = packageBinding.getTypeOrPackage(compoundName[currentIndex++]);
            if (binding == null)
                return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex), null,
                        ProblemReasons.NotFound);
            if (!binding.isValidBinding())
                return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex),
                        binding instanceof ReferenceBinding
                                ? (ReferenceBinding) ((ReferenceBinding) binding).closestMatch()
                                : null,
                        binding.problemId());
            if (!(binding instanceof PackageBinding))
                break;
            packageBinding = (PackageBinding) binding;
        }
        if (binding instanceof PackageBinding)
            return binding;
        checkVisibility = true;
    }
    // binding is now a ReferenceBinding
    ReferenceBinding typeBinding = (ReferenceBinding) binding;
    ReferenceBinding qualifiedType = (ReferenceBinding) environment().convertToRawType(typeBinding,
            false /*do not force conversion of enclosing types*/);

    if (checkVisibility) // handles the fall through case
        if (!typeBinding.canBeSeenBy(this))
            return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex),
                    typeBinding, ProblemReasons.NotVisible);

    while (currentIndex < nameLength) {
        typeBinding = getMemberType(compoundName[currentIndex++], typeBinding);
        // checks visibility
        if (!typeBinding.isValidBinding())
            return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex),
                    (ReferenceBinding) typeBinding.closestMatch(), typeBinding.problemId());

        if (typeBinding.isGenericType()) {
            qualifiedType = environment().createRawType(typeBinding, qualifiedType);
        } else {
            qualifiedType = (qualifiedType != null
                    && (qualifiedType.isRawType() || qualifiedType.isParameterizedType()))
                            ? environment().createParameterizedType(typeBinding, null, qualifiedType)
                            : typeBinding;
        }
    }
    return qualifiedType;
}