List of usage examples for org.eclipse.jdt.internal.compiler.lookup TypeBinding isParameterizedType
public boolean isParameterizedType()
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.FieldLocator.java
License:Open Source License
protected int resolveLevelForType(TypeBinding typeBinding) { FieldPattern fieldPattern = (FieldPattern) this.pattern; TypeBinding fieldTypeBinding = typeBinding; if (fieldTypeBinding != null && fieldTypeBinding.isParameterizedType()) { fieldTypeBinding = typeBinding.erasure(); }/*from w w w . j av a 2 s . c o m*/ return resolveLevelForType(fieldPattern.typeSimpleName, fieldPattern.typeQualification, fieldPattern.getTypeArguments(), 0, fieldTypeBinding); }
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 ww w. j av a 2s. c o 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; }// ww w . j a v a 2 s .c o m // 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 w ww. j a 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: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;//from w ww . ja va2s .com // 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.jdt.internal.compiler.lookup.MethodVerifier15.java
License:Open Source License
boolean areTypesEqual(TypeBinding one, TypeBinding two) { if (one == two) return true; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=329584 switch (one.kind()) { case Binding.TYPE: switch (two.kind()) { case Binding.PARAMETERIZED_TYPE: case Binding.RAW_TYPE: if (one == two.erasure()) return true; }/*from w w w. j a v a 2 s . c om*/ break; case Binding.RAW_TYPE: case Binding.PARAMETERIZED_TYPE: switch (two.kind()) { case Binding.TYPE: if (one.erasure() == two) return true; } } // need to consider X<?> and X<? extends Object> as the same 'type' if (one.isParameterizedType() && two.isParameterizedType()) return one.isEquivalentTo(two) && two.isEquivalentTo(one); // Can skip this since we resolved each method before comparing it, see computeSubstituteMethod() // if (one instanceof UnresolvedReferenceBinding) // return ((UnresolvedReferenceBinding) one).resolvedType == two; // if (two instanceof UnresolvedReferenceBinding) // return ((UnresolvedReferenceBinding) two).resolvedType == one; return false; // all other type bindings are identical }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.LiftingTypeReference.java
License:Open Source License
@Override public TypeBinding resolveType(BlockScope scope, boolean checkBounds) { TypeBinding baseType = this.resolvedType = this.baseReference.resolveType(scope); if (this.roleReference.getTypeName().length > 1) { scope.problemReporter().qualifiedLiftingType(this.roleReference, scope.enclosingSourceType()); return invalidate(baseType); }/* w w w. j a va2s .c o m*/ TypeBinding roleType = this.roleReference.resolveType(scope); if (scope.kind != Scope.BLOCK_SCOPE) { // not a catch block? if (!TeamModel.isAnyTeam(scope.enclosingSourceType())) { scope.problemReporter().liftingTypeNotAllowedHere(scope.methodScope().referenceContext, this); return invalidate(roleType); } } if (baseType == null || baseType instanceof MissingTypeBinding) return invalidate(roleType); if (roleType == null || roleType instanceof MissingTypeBinding) return invalidate(baseType); if (roleType.isArrayType()) { baseType = baseType.leafComponentType(); roleType = roleType.leafComponentType(); } if (roleType.isBaseType()) { scope.problemReporter().primitiveTypeNotAllowedForLifting(scope.referenceType(), this.roleReference, roleType); return invalidate(roleType); } if (baseType.isBaseType()) { scope.problemReporter().primitiveTypeNotAllowedForLifting(scope.referenceType(), this.baseReference, baseType); return invalidate(roleType); } ReferenceBinding roleRefType = (ReferenceBinding) roleType; if (!roleRefType.isValidBinding()) // already reported. return invalidate(roleType); if (!roleRefType.isDirectRole()) { scope.problemReporter().needRoleInLiftingType(scope.referenceType(), this.roleReference, roleType); return invalidate(roleType); } if (roleRefType.isSynthInterface()) roleRefType = roleRefType.getRealClass(); if (roleRefType.roleModel.hasBaseclassProblem()) {// already reported for the role class. scope.referenceContext().tagAsHavingErrors(); // -> mark method as erroneous, too. return invalidate(roleType); } // TODO (SH): maybe look for bound sub-type? // Note (SH): calling baseclass() requires STATE_LENV_DONE_FIELDS_AND_METHODS: Dependencies.ensureBindingState(roleRefType, ITranslationStates.STATE_LENV_DONE_FIELDS_AND_METHODS); if (baseType.isTypeVariable() && ((TypeVariableBinding) baseType).roletype != null) { // resolving "<B base R> as R": roleRefType = ((TypeVariableBinding) baseType).roletype; // ambiguity is handled by _OT$lift_dynamic which may or may not declare LiftingFailedException } else if ((baseType.tagBits & TagBits.HierarchyHasProblems) != 0) { // already reported (?) } else { // static adjustment (OTJLD 2.3.2(a)): roleRefType = (ReferenceBinding) TeamModel.getRoleToLiftTo(scope, baseType, roleRefType, true, this); if (roleRefType == null) roleRefType = (ReferenceBinding) roleType; // revert unsuccessful adjustment if (roleRefType.baseclass() == null || RoleModel.hasTagBit(roleRefType, RoleModel.BaseclassHasProblems)) { scope.problemReporter().roleNotBoundCantLift(scope.referenceType(), this.roleReference, roleType); return invalidate(roleType); } if (baseType.isRole()) // see http://trac.objectteams.org/ot/ticket/73 baseType = RoleTypeCreator.maybeWrapUnqualifiedRoleType(baseType, scope.enclosingReceiverType()); if (baseType == null) return invalidate(roleType); Config oldConfig = Config.createOrResetConfig(this); try { // fetch role's base class and perform substitutions: ReferenceBinding roleBase = roleRefType.baseclass(); if (roleType.isParameterizedType()) { ParameterizedTypeBinding parameterizedRole = (ParameterizedTypeBinding) roleType; TypeBinding[] typeArgs = parameterizedRole.arguments; ITeamAnchor anchor = null; if (roleRefType.baseclass() instanceof RoleTypeBinding) anchor = ((RoleTypeBinding) roleRefType.baseclass())._teamAnchor; roleBase = parameterizedRole.environment.createParameterizedType( (ReferenceBinding) roleBase.original(), typeArgs, anchor, -1, roleBase.enclosingType(), roleBase.getTypeAnnotations()); } // THE compatibility check: if (!baseType.isCompatibleWith(roleBase) || Config.getLoweringRequired()) { scope.problemReporter().incompatibleBaseForRole(scope.referenceType(), this, roleType, baseType); return invalidate(roleType); } } finally { Config.removeOrRestore(oldConfig, this); } } return this.resolvedType; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.PotentialLiftExpression.java
License:Open Source License
public TypeBinding resolveType(BlockScope scope) { this.constant = Constant.NotAConstant; TypeBinding providedType = this.expression.resolveType(scope); if (providedType == null) return null; // no chance if (providedType.isParameterizedType()) providedType = providedType.erasure(); if (this.expectedType == null) this.expectedType = this.expectedTypeReference.resolvedType; this.checked = true; return internalResolveType(scope, providedType, false); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lifting.DeclaredLifting.java
License:Open Source License
private static IfStatement genNewIf(BlockScope scope, AstGenerator gen, ReferenceBinding boundDescendant, LookupEnvironment environment) { TypeBinding boundBase = boundDescendant.baseclass(); if (RoleTypeBinding.isRoleWithExplicitAnchor(boundBase)) { if (boundBase.isParameterizedType()) { // tricky case: need to discard type parameters, but retain/recreate the role type wrapping: RoleTypeBinding baseRole = (RoleTypeBinding) boundBase; boundBase = environment.createParameterizedType(baseRole._declaredRoleType, null, // erase type parameters baseRole._teamAnchor, // but retain anchor -1, // valueParamPosition baseRole.enclosingType(), Binding.NO_ANNOTATIONS); }/*from ww w .j a v a 2 s. c o m*/ // only RTB but not parameterized: leave unchanged. } else { boundBase = boundBase.erasure(); } return gen.ifStatement( gen.instanceOfExpression(gen.singleNameReference(IOTConstants.BASE), gen.typeReference(boundBase)), gen.returnStatement(Lifting.liftCall( scope, gen.thisReference(), gen.castExpression(gen.singleNameReference(IOTConstants.BASE), gen.typeReference(boundBase), CastExpression.DO_WRAP), boundBase, boundDescendant, false/*needLowering*/)), null); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CalloutImplementor.java
License:Open Source License
TypeBinding adjustBaseSideType(TypeBinding givenType) { ReferenceBinding baseBinding = this._role.getBaseTypeBinding(); if (baseBinding == null) return givenType; if (givenType.leafComponentType().isBaseType()) return givenType; ReferenceBinding givenLeaf = (ReferenceBinding) givenType.leafComponentType(); int dimensions = givenType.dimensions(); TypeVariableBinding[] arguments = null; if (givenType.isParameterizedType()) arguments = ((ParameterizedTypeBinding) givenType).typeVariables(); if (baseBinding instanceof DependentTypeBinding) { ITeamAnchor anchor = ((DependentTypeBinding) baseBinding).getAnchor(); if (anchor.isTeamContainingRole(givenLeaf)) { if (TypeBinding.notEquals(anchor.getResolvedType(), givenLeaf.enclosingType())) givenLeaf = (ReferenceBinding) TeamModel .strengthenRoleType((ReferenceBinding) anchor.getResolvedType(), givenLeaf); return anchor.getDependentTypeBinding(givenLeaf, -1, arguments, dimensions); }//from ww w . j a v a 2s. co m } return givenType; }