List of usage examples for org.eclipse.jdt.internal.compiler.lookup TypeBinding isRawType
public final boolean isRawType()
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.PatternLocator.java
License:Open Source License
protected void updateMatch(ParameterizedTypeBinding parameterizedBinding, char[][][] patternTypeArguments, boolean patternHasTypeParameters, int depth, MatchLocator locator) { // Only possible if locator has an unit scope. if (locator.unitScope == null) return;/*from w w w . jav a 2 s .co m*/ // Set match raw flag boolean endPattern = patternTypeArguments == null ? true : depth >= patternTypeArguments.length; TypeBinding[] argumentsBindings = parameterizedBinding.arguments; boolean isRaw = parameterizedBinding.isRawType() || (argumentsBindings == null && parameterizedBinding.genericType().isGenericType()); if (isRaw && !this.match.isRaw()) { this.match.setRaw(isRaw); } // Update match if (!endPattern && patternTypeArguments != null) { // verify if this is a reference to the generic type itself if (!isRaw && patternHasTypeParameters && argumentsBindings != null) { boolean needUpdate = false; TypeVariableBinding[] typeVariables = parameterizedBinding.genericType().typeVariables(); int length = argumentsBindings.length; if (length == typeVariables.length) { for (int i = 0; i < length; i++) { if (argumentsBindings[i] != typeVariables[i]) { needUpdate = true; break; } } } if (needUpdate) { char[][] patternArguments = patternTypeArguments[depth]; updateMatch(argumentsBindings, locator, patternArguments, patternHasTypeParameters); } } else { char[][] patternArguments = patternTypeArguments[depth]; updateMatch(argumentsBindings, locator, patternArguments, patternHasTypeParameters); } } // Recurse TypeBinding enclosingType = parameterizedBinding.enclosingType(); if (enclosingType != null && (enclosingType.isParameterizedType() || enclosingType.isRawType())) { updateMatch((ParameterizedTypeBinding) enclosingType, patternTypeArguments, patternHasTypeParameters, depth + 1, locator); } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.PatternLocator.java
License:Open Source License
protected int resolveLevelForType(char[] simpleNamePattern, char[] qualificationPattern, char[][][] patternTypeArguments, int depth, TypeBinding type) { // standard search with no generic additional information must succeed int level = resolveLevelForType(simpleNamePattern, qualificationPattern, type); if (level == IMPOSSIBLE_MATCH) return IMPOSSIBLE_MATCH; if (type == null || patternTypeArguments == null || patternTypeArguments.length == 0 || depth >= patternTypeArguments.length) { return level; }// w w w .j ava2 s .c om // if pattern is erasure match (see bug 79790), commute impossible to erasure int impossible = this.isErasureMatch ? ERASURE_MATCH : IMPOSSIBLE_MATCH; // pattern has type parameter(s) or type argument(s) if (type.isGenericType()) { // Binding is generic, get its type variable(s) TypeVariableBinding[] typeVariables = null; if (type instanceof SourceTypeBinding) { SourceTypeBinding sourceTypeBinding = (SourceTypeBinding) type; typeVariables = sourceTypeBinding.typeVariables; } else if (type instanceof BinaryTypeBinding) { BinaryTypeBinding binaryTypeBinding = (BinaryTypeBinding) type; if (this.mustResolve) typeVariables = binaryTypeBinding.typeVariables(); // TODO (frederic) verify performance } if (patternTypeArguments[depth] != null && patternTypeArguments[depth].length > 0 && typeVariables != null && typeVariables.length > 0) { if (typeVariables.length != patternTypeArguments[depth].length) return IMPOSSIBLE_MATCH; } // TODO (frederic) do we need to verify each parameter? return level; // we can't do better } // raw type always match if (type.isRawType()) { return level; } // Standard types (i.e. neither generic nor parameterized nor raw types) // cannot match pattern with type parameters or arguments TypeBinding leafType = type.leafComponentType(); if (!leafType.isParameterizedType()) { return (patternTypeArguments[depth] == null || patternTypeArguments[depth].length == 0) ? level : IMPOSSIBLE_MATCH; } // Parameterized type ParameterizedTypeBinding paramTypeBinding = (ParameterizedTypeBinding) leafType; // Compare arguments only if there ones on both sides if (patternTypeArguments[depth] != null && patternTypeArguments[depth].length > 0 && paramTypeBinding.arguments != null && paramTypeBinding.arguments.length > 0) { // type parameters length must match at least specified type names length int length = patternTypeArguments[depth].length; if (paramTypeBinding.arguments.length != length) return IMPOSSIBLE_MATCH; // verify each pattern type parameter nextTypeArgument: for (int i = 0; i < length; i++) { char[] patternTypeArgument = patternTypeArguments[depth][i]; TypeBinding argTypeBinding = paramTypeBinding.arguments[i]; // get corresponding pattern wildcard switch (patternTypeArgument[0]) { case Signature.C_STAR: // unbound parameter always match case Signature.C_SUPER: // needs pattern type parameter binding // skip to next type argument as it will be resolved later continue nextTypeArgument; case Signature.C_EXTENDS: // remove wildcard from patter type argument patternTypeArgument = CharOperation.subarray(patternTypeArgument, 1, patternTypeArgument.length); break; default: // no wildcard break; } // get pattern type argument from its signature patternTypeArgument = Signature.toCharArray(patternTypeArgument); if (!this.isCaseSensitive) patternTypeArgument = CharOperation.toLowerCase(patternTypeArgument); boolean patternTypeArgHasAnyChars = CharOperation.contains(new char[] { '*', '?' }, patternTypeArgument); // Verify that names match... // ...special case for wildcard if (argTypeBinding instanceof CaptureBinding) { WildcardBinding capturedWildcard = ((CaptureBinding) argTypeBinding).wildcard; if (capturedWildcard != null) argTypeBinding = capturedWildcard; } if (argTypeBinding.isWildcard()) { WildcardBinding wildcardBinding = (WildcardBinding) argTypeBinding; switch (wildcardBinding.boundKind) { case Wildcard.EXTENDS: // Invalid if type argument is not exact if (patternTypeArgHasAnyChars) return impossible; continue nextTypeArgument; case Wildcard.UNBOUND: // there's no bound name to match => valid continue nextTypeArgument; } // Look if bound name match pattern type argument ReferenceBinding boundBinding = (ReferenceBinding) wildcardBinding.bound; if (CharOperation.match(patternTypeArgument, boundBinding.shortReadableName(), this.isCaseSensitive) || CharOperation.match(patternTypeArgument, boundBinding.readableName(), this.isCaseSensitive)) { // found name in hierarchy => match continue nextTypeArgument; } // If pattern is not exact then match fails if (patternTypeArgHasAnyChars) return impossible; // Look for bound name in type argument superclasses boundBinding = boundBinding.superclass(); while (boundBinding != null) { if (CharOperation.equals(patternTypeArgument, boundBinding.shortReadableName(), this.isCaseSensitive) || CharOperation.equals(patternTypeArgument, boundBinding.readableName(), this.isCaseSensitive)) { // found name in hierarchy => match continue nextTypeArgument; } else if (boundBinding.isLocalType() || boundBinding.isMemberType()) { // for local or member type, verify also source name (bug 81084) if (CharOperation.match(patternTypeArgument, boundBinding.sourceName(), this.isCaseSensitive)) continue nextTypeArgument; } boundBinding = boundBinding.superclass(); } return impossible; } // See if names match if (CharOperation.match(patternTypeArgument, argTypeBinding.shortReadableName(), this.isCaseSensitive) || CharOperation.match(patternTypeArgument, argTypeBinding.readableName(), this.isCaseSensitive)) { continue nextTypeArgument; } else if (argTypeBinding.isLocalType() || argTypeBinding.isMemberType()) { // for local or member type, verify also source name (bug 81084) if (CharOperation.match(patternTypeArgument, argTypeBinding.sourceName(), this.isCaseSensitive)) continue nextTypeArgument; } // If pattern is not exact then match fails if (patternTypeArgHasAnyChars) return impossible; // Scan hierarchy TypeBinding leafTypeBinding = argTypeBinding.leafComponentType(); if (leafTypeBinding.isBaseType()) return impossible; ReferenceBinding refBinding = ((ReferenceBinding) leafTypeBinding).superclass(); while (refBinding != null) { if (CharOperation.equals(patternTypeArgument, refBinding.shortReadableName(), this.isCaseSensitive) || CharOperation.equals(patternTypeArgument, refBinding.readableName(), this.isCaseSensitive)) { // found name in hierarchy => match continue nextTypeArgument; } else if (refBinding.isLocalType() || refBinding.isMemberType()) { // for local or member type, verify also source name (bug 81084) if (CharOperation.match(patternTypeArgument, refBinding.sourceName(), this.isCaseSensitive)) continue nextTypeArgument; } refBinding = refBinding.superclass(); } return impossible; } } // Recurse on enclosing type TypeBinding enclosingType = paramTypeBinding.enclosingType(); if (enclosingType != null && enclosingType.isParameterizedType() && depth < patternTypeArguments.length && qualificationPattern != null) { int lastDot = CharOperation.lastIndexOf('.', qualificationPattern); char[] enclosingQualificationPattern = lastDot == -1 ? null : CharOperation.subarray(qualificationPattern, 0, lastDot); char[] enclosingSimpleNamePattern = lastDot == -1 ? qualificationPattern : CharOperation.subarray(qualificationPattern, lastDot + 1, qualificationPattern.length); int enclosingLevel = resolveLevelForType(enclosingSimpleNamePattern, enclosingQualificationPattern, patternTypeArguments, depth + 1, enclosingType); if (enclosingLevel == impossible) return impossible; if (enclosingLevel == IMPOSSIBLE_MATCH) return IMPOSSIBLE_MATCH; } return level; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.TypeReferenceLocator.java
License:Open Source License
void matchReportReference(Expression expr, int lastIndex, TypeBinding refBinding, MatchLocator locator) throws CoreException { // Look if there's a need to special report for parameterized type if (refBinding.isParameterizedType() || refBinding.isRawType()) { // Try to refine accuracy ParameterizedTypeBinding parameterizedBinding = (ParameterizedTypeBinding) refBinding; updateMatch(parameterizedBinding, this.pattern.getTypeArguments(), this.pattern.hasTypeParameters(), 0, locator);/*from ww w. ja v a2 s . c o m*/ // See whether it is necessary to report or not if (this.match.getRule() == 0) return; // impossible match boolean report = (this.isErasureMatch && this.match.isErasure()) || (this.isEquivalentMatch && this.match.isEquivalent()) || this.match.isExact(); if (!report) return; // Make a special report for parameterized types if necessary if (refBinding.isParameterizedType() && this.pattern.hasTypeArguments()) { TypeReference typeRef = null; TypeReference[] typeArguments = null; if (expr instanceof ParameterizedQualifiedTypeReference) { typeRef = (ParameterizedQualifiedTypeReference) expr; typeArguments = ((ParameterizedQualifiedTypeReference) expr).typeArguments[lastIndex]; } else if (expr instanceof ParameterizedSingleTypeReference) { typeRef = (ParameterizedSingleTypeReference) expr; typeArguments = ((ParameterizedSingleTypeReference) expr).typeArguments; } if (typeRef != null) { locator.reportAccurateParameterizedTypeReference(this.match, typeRef, lastIndex, typeArguments); return; } } } else if (this.pattern.hasTypeArguments()) { // binding has no type params, compatible erasure if pattern does this.match.setRule(SearchPattern.R_ERASURE_MATCH); } // Report match if (expr instanceof ArrayTypeReference) { locator.reportAccurateTypeReference(this.match, expr, this.pattern.simpleName); return; } if (refBinding.isLocalType()) { // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=82673 LocalTypeBinding local = (LocalTypeBinding) refBinding.erasure(); IJavaElement focus = this.pattern.focus; if (focus != null && local.enclosingMethod != null && focus.getParent().getElementType() == IJavaElement.METHOD) { IMethod method = (IMethod) focus.getParent(); if (!CharOperation.equals(local.enclosingMethod.selector, method.getElementName().toCharArray())) { return; } } } if (this.pattern.simpleName == null) { this.match.setOffset(expr.sourceStart); this.match.setLength(expr.sourceEnd - expr.sourceStart + 1); } locator.report(this.match); }
From source file:com.redhat.ceylon.eclipse.core.model.mirror.UnknownTypeMirror.java
License:Open Source License
public JDTType(TypeBinding type, IdentityHashMap<TypeBinding, JDTType> originatingTypes) { originatingTypes.put(type, this); // type params are not qualified if (type instanceof TypeVariableBinding) qualifiedName = new String(type.qualifiedSourceName()); else// w ww . j a va 2 s . co m qualifiedName = JDTUtils.getFullyQualifiedName(type); typeKind = findKind(type); isPrimitive = type.isBaseType() && type.id != TypeIds.T_void && type.id != TypeIds.T_null; isRaw = type.isRawType(); if (type instanceof ParameterizedTypeBinding && !(type instanceof RawTypeBinding)) { TypeBinding[] javaTypeArguments = ((ParameterizedTypeBinding) type).arguments; if (javaTypeArguments == null) { javaTypeArguments = new TypeBinding[0]; } typeArguments = new ArrayList<TypeMirror>(javaTypeArguments.length); for (TypeBinding typeArgument : javaTypeArguments) typeArguments.add(toTypeMirror(typeArgument, type, this, originatingTypes)); } else { typeArguments = Collections.emptyList(); } if (type instanceof ArrayBinding) { TypeBinding jdtComponentType = ((ArrayBinding) type).elementsType(); componentType = toTypeMirror(jdtComponentType, type, this, originatingTypes); } else { componentType = null; } if (type.isWildcard()) { WildcardBinding wildcardBinding = (WildcardBinding) type; if (wildcardBinding.boundKind == Wildcard.EXTENDS) { TypeBinding upperBoundBinding = wildcardBinding.bound; if (upperBoundBinding != null) { upperBound = toTypeMirror(upperBoundBinding, type, this, originatingTypes); } } } else if (type.isTypeVariable()) { TypeVariableBinding typeVariableBinding = (TypeVariableBinding) type; TypeBinding boundBinding = typeVariableBinding.firstBound; // TODO : we should confirm this if (boundBinding != null) { upperBound = toTypeMirror(boundBinding, type, this, originatingTypes); } } else { upperBound = null; } if (type.isWildcard()) { WildcardBinding wildcardBinding = (WildcardBinding) type; if (wildcardBinding.boundKind == Wildcard.SUPER) { TypeBinding lowerBoundBinding = wildcardBinding.bound; if (lowerBoundBinding != null) { lowerBound = toTypeMirror(lowerBoundBinding, type, this, originatingTypes); } } } if (type instanceof ParameterizedTypeBinding || type instanceof SourceTypeBinding || type instanceof BinaryTypeBinding) { ReferenceBinding refBinding = (ReferenceBinding) type; declaredClass = new JDTClass(refBinding, JDTModelLoader.toType(refBinding)); } if (type instanceof TypeVariableBinding) { typeParameter = new JDTTypeParameter((TypeVariableBinding) type, this, originatingTypes); } }
From source file:org.eclipse.che.jdt.internal.core.search.matching.PatternLocator.java
License:Open Source License
protected void updateMatch(ParameterizedTypeBinding parameterizedBinding, char[][][] patternTypeArguments, boolean patternHasTypeParameters, int depth, MatchLocator locator) { // Only possible if locator has an unit scope. if (locator.unitScope == null) return;/* www. j a v a 2 s . co m*/ // Set match raw flag boolean endPattern = patternTypeArguments == null ? true : depth >= patternTypeArguments.length; TypeBinding[] argumentsBindings = parameterizedBinding.arguments; boolean isRaw = parameterizedBinding.isRawType() || (argumentsBindings == null && parameterizedBinding.genericType().isGenericType()); if (isRaw && !this.match.isRaw()) { this.match.setRaw(isRaw); } // Update match if (!endPattern && patternTypeArguments != null) { // verify if this is a reference to the generic type itself if (!isRaw && patternHasTypeParameters && argumentsBindings != null) { boolean needUpdate = false; TypeVariableBinding[] typeVariables = parameterizedBinding.genericType().typeVariables(); int length = argumentsBindings.length; if (length == typeVariables.length) { for (int i = 0; i < length; i++) { if (TypeBinding.notEquals(argumentsBindings[i], typeVariables[i])) { needUpdate = true; break; } } } if (needUpdate) { char[][] patternArguments = patternTypeArguments[depth]; updateMatch(argumentsBindings, locator, patternArguments, patternHasTypeParameters); } } else { char[][] patternArguments = patternTypeArguments[depth]; updateMatch(argumentsBindings, locator, patternArguments, patternHasTypeParameters); } } // Recurse TypeBinding enclosingType = parameterizedBinding.enclosingType(); if (enclosingType != null && (enclosingType.isParameterizedType() || enclosingType.isRawType())) { updateMatch((ParameterizedTypeBinding) enclosingType, patternTypeArguments, patternHasTypeParameters, depth + 1, locator); } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.RoleTypeBinding.java
License:Open Source License
/** * MAIN ENTRY FOR TYPE CHECKING./*from w w w .j a v a2 s. com*/ * * Answer true if the receiver type can be assigned to the argument type (right). * Compare team-anchor and role-type. * Note, that the type of _teamAnchor and _staticallyKnownTeam may differ. * The former is relevant for type-checking. the latter serves mainly for code generation * and for determining overriding. */ public boolean isCompatibleWith(TypeBinding right, /*@Nullable*/ Scope captureScope) { if (TypeBinding.equalsEquals(right, this)) return true; if (!(right instanceof ReferenceBinding)) return false; if (right.isRawType() && this.erasure().isCompatibleWith(right, captureScope)) return true; ReferenceBinding referenceBinding = (ReferenceBinding) right; if (referenceBinding.isRoleType()) { RoleTypeBinding rightRole = getRoleTypeBinding(referenceBinding); ReferenceBinding rightTeam = referenceBinding.enclosingType(); // compare teams: if (!this._teamAnchor.hasSameBestNameAs(rightRole._teamAnchor)) { // different anchors, not both tthis: not compatible! return isCompatibleViaLowering(rightRole); } // compensate weakened signature: if (TypeBinding.notEquals(rightRole._staticallyKnownTeam, this._staticallyKnownTeam)) { try { if (TeamModel.areTypesCompatible(rightTeam, this._staticallyKnownTeam)) { ReferenceBinding leftStrengthened = this._teamAnchor.getMemberTypeOfType(internalName()); if (TypeBinding.notEquals(leftStrengthened, this)) return leftStrengthened.isCompatibleWith(right, captureScope); } else if (TeamModel.areTypesCompatible(this._staticallyKnownTeam, rightTeam)) { rightRole = (RoleTypeBinding) this._teamAnchor .getMemberTypeOfType(rightRole.internalName()); } else { return false; } } finally { Config.setCastRequired(null); // reset } } // check the role types: if (this._staticallyKnownRoleType.isCompatibleWith(rightRole._staticallyKnownRoleType, captureScope)) return true; } if (referenceBinding.isInterface() && implementsInterface(referenceBinding, true)) return true; if (this._staticallyKnownRoleClass == null && this._staticallyKnownRoleType.isCompatibleWith(referenceBinding, false, captureScope)) { checkAmbiguousObjectLower(referenceBinding); return true; // this case is wittnessed by: "this=RoleIfc", right="Object"; other examples? } // do we need the class part instead of the interface part? if ((this._staticallyKnownRoleClass != null) && this._staticallyKnownRoleClass.isStrictlyCompatibleWith(referenceBinding, captureScope) && !TeamModel.isTeamContainingRole(this._staticallyKnownTeam, referenceBinding)) { // Cast from a role to its non-role superclass // (Interfaces do not reflect this compatibility, thus we need to help here). Config.setCastRequired(referenceBinding); checkAmbiguousObjectLower(referenceBinding); return true; } // after everything else has failed try lowering: return isCompatibleViaLowering(referenceBinding); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.TypeAnalyzer.java
License:Open Source License
/** * Are type compatible possibly performing role type adjustment? * @param currentType// www . j a va 2s . com * @param subTeam * @param tsuperType * @param superTeam * @param matchKind * @return the answer */ public static boolean areTypesMatchable(TypeBinding currentType, ReferenceBinding subTeam, TypeBinding tsuperType, ReferenceBinding superTeam, int matchKind) { // be very defensive: if (currentType instanceof ProblemReferenceBinding) { TypeBinding closestMatch = ((ProblemReferenceBinding) currentType).closestMatch(); if (closestMatch == null) return CharOperation.equals(currentType.sourceName(), tsuperType.sourceName()); currentType = closestMatch; } if (tsuperType instanceof ProblemReferenceBinding) { TypeBinding closestMatch = ((ProblemReferenceBinding) tsuperType).closestMatch(); if (closestMatch == null) return CharOperation.equals(currentType.sourceName(), tsuperType.sourceName()); tsuperType = closestMatch; } // if it's array-types, compare dimension and extract leafComponentType if ((currentType instanceof ArrayBinding) || (tsuperType instanceof ArrayBinding)) { if (!(tsuperType instanceof ArrayBinding) || !(currentType instanceof ArrayBinding)) return false; ArrayBinding currentArray = (ArrayBinding) currentType; ArrayBinding superArray = (ArrayBinding) tsuperType; if (currentArray.dimensions() != superArray.dimensions()) return false; currentType = currentArray.leafComponentType(); tsuperType = superArray.leafComponentType(); } // guaranteed to be scalar now if (currentType instanceof ReferenceBinding) { if (currentType instanceof DependentTypeBinding) currentType = ((DependentTypeBinding) currentType).getRealType(); if (!(tsuperType instanceof ReferenceBinding)) return false; if (tsuperType instanceof DependentTypeBinding) tsuperType = ((DependentTypeBinding) tsuperType).getRealType(); if (currentType.isParameterizedType() || tsuperType.isParameterizedType()) { // at least one type parameterized: get erasure(s) if (currentType.isParameterizedType()) { if (tsuperType.isParameterizedType()) { // both parameterized: check parameters: ParameterizedTypeBinding currentParameterized = ((ParameterizedTypeBinding) currentType); ParameterizedTypeBinding tsuperParameterized = ((ParameterizedTypeBinding) tsuperType); if (!CharOperation.equals(currentParameterized.genericTypeSignature, tsuperParameterized.genericTypeSignature)) return false; } else if (!tsuperType.isRawType()) { return false; // mismatch generic vs. non-generic } } else if (!currentType.isRawType()) { return false; // mismatch non-generic vs. generic } currentType = currentType.erasure(); tsuperType = tsuperType.erasure(); } if (currentType.isTypeVariable() && tsuperType.isTypeVariable()) return TypeBinding.equalsEquals(currentType, tsuperType); char[][] tname1 = compoundNameOfReferenceType((ReferenceBinding) tsuperType, true, true); char[][] tname2 = compoundNameOfReferenceType((ReferenceBinding) currentType, true, true); if (CharOperation.equals(tname1, tname2)) { if (TypeBinding.notEquals(tsuperType, currentType) && tsuperType.isValidBinding()) // don't complain about different missing types throw new InternalCompilerError( "different bindings for the same type??" + currentType + ':' + tsuperType); //$NON-NLS-1$ return true; } if (matchKind == EXACT_MATCH_ONLY) { return false; } else { tname1 = splitTypeNameRelativeToTeam((ReferenceBinding) tsuperType, superTeam); tname2 = splitTypeNameRelativeToTeam((ReferenceBinding) currentType, subTeam); if (!CharOperation.equals(tname1, tname2)) return false; } } else if (currentType instanceof BaseTypeBinding) { if (TypeBinding.notEquals(currentType, tsuperType)) return false; } else { throw new InternalCompilerError("matching of unexpected type kind: " + currentType); //$NON-NLS-1$ } return true; }