List of usage examples for org.eclipse.jdt.internal.compiler.lookup TagBits HasTypeVariable
long HasTypeVariable
To view the source code for org.eclipse.jdt.internal.compiler.lookup TagBits HasTypeVariable.
Click Source Link
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
/** * Returns a type where either all variables or specific ones got discarded. * e.g. List<E> (discarding <E extends Enum<E>) will return: List<? extends Enum<?>> *//* www. j a va 2 s . c o m*/ public static TypeBinding convertEliminatingTypeVariables(TypeBinding originalType, ReferenceBinding genericType, int rank, Set eliminatedVariables) { if ((originalType.tagBits & TagBits.HasTypeVariable) != 0) { switch (originalType.kind()) { case Binding.ARRAY_TYPE: ArrayBinding originalArrayType = (ArrayBinding) originalType; TypeBinding originalLeafComponentType = originalArrayType.leafComponentType; TypeBinding substitute = convertEliminatingTypeVariables(originalLeafComponentType, genericType, rank, eliminatedVariables); // substitute could itself be array type if (substitute != originalLeafComponentType) { return originalArrayType.environment.createArrayType(substitute.leafComponentType(), substitute.dimensions() + originalArrayType.dimensions()); } break; case Binding.PARAMETERIZED_TYPE: ParameterizedTypeBinding paramType = (ParameterizedTypeBinding) originalType; ReferenceBinding originalEnclosing = paramType.enclosingType(); ReferenceBinding substitutedEnclosing = originalEnclosing; if (originalEnclosing != null) { substitutedEnclosing = (ReferenceBinding) convertEliminatingTypeVariables(originalEnclosing, genericType, rank, eliminatedVariables); } TypeBinding[] originalArguments = paramType.arguments; TypeBinding[] substitutedArguments = originalArguments; for (int i = 0, length = originalArguments == null ? 0 : originalArguments.length; i < length; i++) { TypeBinding originalArgument = originalArguments[i]; TypeBinding substitutedArgument = convertEliminatingTypeVariables(originalArgument, paramType.genericType(), i, eliminatedVariables); if (substitutedArgument != originalArgument) { if (substitutedArguments == originalArguments) { System.arraycopy(originalArguments, 0, substitutedArguments = new TypeBinding[length], 0, i); } substitutedArguments[i] = substitutedArgument; } else if (substitutedArguments != originalArguments) { substitutedArguments[i] = originalArgument; } } if (originalEnclosing != substitutedEnclosing || originalArguments != substitutedArguments) { return paramType.environment.createParameterizedType(paramType.genericType(), substitutedArguments, substitutedEnclosing); } break; case Binding.TYPE_PARAMETER: if (genericType == null) { break; } TypeVariableBinding originalVariable = (TypeVariableBinding) originalType; if (eliminatedVariables != null && eliminatedVariables.contains(originalType)) { return originalVariable.environment.createWildcard(genericType, rank, null, null, Wildcard.UNBOUND); } TypeBinding originalUpperBound = originalVariable.upperBound(); if (eliminatedVariables == null) { eliminatedVariables = new HashSet(2); } eliminatedVariables.add(originalVariable); TypeBinding substitutedUpperBound = convertEliminatingTypeVariables(originalUpperBound, genericType, rank, eliminatedVariables); eliminatedVariables.remove(originalVariable); return originalVariable.environment.createWildcard(genericType, rank, substitutedUpperBound, null, Wildcard.EXTENDS); case Binding.RAW_TYPE: break; case Binding.GENERIC_TYPE: ReferenceBinding currentType = (ReferenceBinding) originalType; originalEnclosing = currentType.enclosingType(); substitutedEnclosing = originalEnclosing; if (originalEnclosing != null) { substitutedEnclosing = (ReferenceBinding) convertEliminatingTypeVariables(originalEnclosing, genericType, rank, eliminatedVariables); } originalArguments = currentType.typeVariables(); substitutedArguments = originalArguments; for (int i = 0, length = originalArguments == null ? 0 : originalArguments.length; i < length; i++) { TypeBinding originalArgument = originalArguments[i]; TypeBinding substitutedArgument = convertEliminatingTypeVariables(originalArgument, currentType, i, eliminatedVariables); if (substitutedArgument != originalArgument) { if (substitutedArguments == originalArguments) { System.arraycopy(originalArguments, 0, substitutedArguments = new TypeBinding[length], 0, i); } substitutedArguments[i] = substitutedArgument; } else if (substitutedArguments != originalArguments) { substitutedArguments[i] = originalArgument; } } if (originalEnclosing != substitutedEnclosing || originalArguments != substitutedArguments) { return ((TypeVariableBinding) originalArguments[0]).environment .createParameterizedType(genericType, substitutedArguments, substitutedEnclosing); } break; case Binding.WILDCARD_TYPE: WildcardBinding wildcard = (WildcardBinding) originalType; TypeBinding originalBound = wildcard.bound; TypeBinding substitutedBound = originalBound; if (originalBound != null) { substitutedBound = convertEliminatingTypeVariables(originalBound, genericType, rank, eliminatedVariables); if (substitutedBound != originalBound) { return wildcard.environment.createWildcard(wildcard.genericType, wildcard.rank, substitutedBound, null, wildcard.boundKind); } } break; case Binding.INTERSECTION_TYPE: WildcardBinding intersection = (WildcardBinding) originalType; originalBound = intersection.bound; substitutedBound = originalBound; if (originalBound != null) { substitutedBound = convertEliminatingTypeVariables(originalBound, genericType, rank, eliminatedVariables); } TypeBinding[] originalOtherBounds = intersection.otherBounds; TypeBinding[] substitutedOtherBounds = originalOtherBounds; for (int i = 0, length = originalOtherBounds == null ? 0 : originalOtherBounds.length; i < length; i++) { TypeBinding originalOtherBound = originalOtherBounds[i]; TypeBinding substitutedOtherBound = convertEliminatingTypeVariables(originalOtherBound, genericType, rank, eliminatedVariables); if (substitutedOtherBound != originalOtherBound) { if (substitutedOtherBounds == originalOtherBounds) { System.arraycopy(originalOtherBounds, 0, substitutedOtherBounds = new TypeBinding[length], 0, i); } substitutedOtherBounds[i] = substitutedOtherBound; } else if (substitutedOtherBounds != originalOtherBounds) { substitutedOtherBounds[i] = originalOtherBound; } } if (substitutedBound != originalBound || substitutedOtherBounds != originalOtherBounds) { return intersection.environment.createWildcard(intersection.genericType, intersection.rank, substitutedBound, substitutedOtherBounds, intersection.boundKind); } break; } } return originalType; }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
/** * Internal use only/*from w w w . j a va 2 s.c o m*/ * Given a method, returns null if arguments cannot be converted to parameters. * Will answer a substituted method in case the method was generic and type inference got triggered; * in case the method was originally compatible, then simply answer it back. */ protected final MethodBinding computeCompatibleMethod(MethodBinding method, TypeBinding[] arguments, InvocationSite invocationSite) { TypeBinding[] genericTypeArguments = invocationSite.genericTypeArguments(); TypeBinding[] parameters = method.parameters; TypeVariableBinding[] typeVariables = method.typeVariables; if (parameters == arguments && (method.returnType.tagBits & TagBits.HasTypeVariable) == 0 && genericTypeArguments == null && typeVariables == Binding.NO_TYPE_VARIABLES) return method; int argLength = arguments.length; int paramLength = parameters.length; boolean isVarArgs = method.isVarargs(); if (argLength != paramLength) if (!isVarArgs || argLength < paramLength - 1) return null; // incompatible // https://bugs.eclipse.org/bugs/show_bug.cgi?id=330435, inference should kick in only at source 1.5+ if (typeVariables != Binding.NO_TYPE_VARIABLES && compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) { // generic method TypeBinding[] newArgs = null; for (int i = 0; i < argLength; i++) { TypeBinding param = i < paramLength ? parameters[i] : parameters[paramLength - 1]; if (arguments[i].isBaseType() != param.isBaseType()) { if (newArgs == null) { newArgs = new TypeBinding[argLength]; System.arraycopy(arguments, 0, newArgs, 0, argLength); } newArgs[i] = environment().computeBoxingType(arguments[i]); } } if (newArgs != null) arguments = newArgs; method = ParameterizedGenericMethodBinding.computeCompatibleMethod(method, arguments, this, invocationSite); if (method == null) return null; // incompatible if (!method.isValidBinding()) return method; // bound check issue is taking precedence } else if (genericTypeArguments != null && compilerOptions().complianceLevel < ClassFileConstants.JDK1_7) { if (method instanceof ParameterizedGenericMethodBinding) { if (!((ParameterizedGenericMethodBinding) method).wasInferred) // attempt to invoke generic method of raw type with type hints <String>foo() return new ProblemMethodBinding(method, method.selector, genericTypeArguments, ProblemReasons.TypeArgumentsForRawGenericMethod); } else if (!method.isOverriding() || !isOverriddenMethodGeneric(method)) { return new ProblemMethodBinding(method, method.selector, genericTypeArguments, ProblemReasons.TypeParameterArityMismatch); } } if (parameterCompatibilityLevel(method, arguments) > NOT_COMPATIBLE) { if ((method.tagBits & TagBits.AnnotationPolymorphicSignature) != 0) { // generate polymorphic method return this.environment().createPolymorphicMethod(method, arguments); } return method; } // if method is generic and type arguments have been supplied, only then answer a problem // of ParameterizedMethodTypeMismatch, else a non-generic method was invoked using type arguments // in which case this problem category will be bogus if (genericTypeArguments != null && typeVariables != Binding.NO_TYPE_VARIABLES) return new ProblemMethodBinding(method, method.selector, arguments, ProblemReasons.ParameterizedMethodTypeMismatch); return null; // incompatible }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.RoleTypeBinding.java
License:Open Source License
private void initialize(ReferenceBinding roleType, ITeamAnchor teamAnchor) { // FIXME(SH): is it OK to strip ParameterizedFields? if (teamAnchor instanceof ParameterizedFieldBinding) teamAnchor = ((ParameterizedFieldBinding) teamAnchor).original(); initializeDependentType(teamAnchor, -1); // role type bindings have no explicit value parameters // infer argument position. ITeamAnchor firstAnchorSegment = teamAnchor.getBestNamePath()[0]; if (firstAnchorSegment instanceof LocalVariableBinding && (((LocalVariableBinding) firstAnchorSegment).tagBits & TagBits.IsArgument) != 0) { LocalVariableBinding argumentBinding = (LocalVariableBinding) firstAnchorSegment; this._argumentPosition = argumentBinding.resolvedPosition; final MethodScope methodScope = argumentBinding.declaringScope.methodScope(); if (methodScope != null) // if scope is a callout, role method may not yet be resolved, defer: this._declaringMethod = new IMethodProvider() { private MethodBinding binding; public MethodBinding getMethod() { if (this.binding == null) this.binding = methodScope.referenceMethodBinding(); return this.binding; }/*from w ww.j av a2 s . c o m*/ }; } // compute the team: if (CharOperation.equals(roleType.compoundName, IOTConstants.ORG_OBJECTTEAMS_TEAM_OTCONFINED)) // the following is needed in order to break the circularity // of roles extending the predefined Team.__OT__Confined (see class comment) this._staticallyKnownTeam = roleType.enclosingType(); else if (teamAnchor == NoAnchor) this._staticallyKnownTeam = roleType.enclosingType(); else teamAnchor.setStaticallyKnownTeam(this); assert (this._staticallyKnownTeam.isTeam()); // compute role class and role interface (by name manipulation): if (RoleSplitter.isClassPartName(roleType.sourceName)) { this._staticallyKnownRoleClass = roleType.getRealClass(); char[] typeName = RoleSplitter.getInterfacePartName(roleType.sourceName); this._staticallyKnownRoleType = this._staticallyKnownTeam.getMemberType(typeName); } else { this._staticallyKnownRoleType = roleType.getRealType(); char[] className = CharOperation.concat(OT_DELIM_NAME, this._staticallyKnownRoleType.sourceName); this._staticallyKnownRoleClass = this._staticallyKnownTeam.getMemberType(className); this._staticallyKnownRoleClass = transferTypeArguments(this._staticallyKnownRoleClass); } this._staticallyKnownRoleType = transferTypeArguments(this._staticallyKnownRoleType); this._declaredRoleType = this._staticallyKnownRoleType; // keep these consistent with _declaredRoleType: this.roleModel = this._declaredRoleType.roleModel; this._teamModel = this._declaredRoleType.getTeamModel(); assert TypeBinding.equalsEquals(this._staticallyKnownTeam.getRealClass(), roleType.enclosingType()) : "weakening not using WeakenedTypeBinding"; //$NON-NLS-1$ // some adjustments after all fields are known: if (TypeBinding.notEquals(this._staticallyKnownTeam, roleType.enclosingType())) this._staticallyKnownRoleType = this._staticallyKnownTeam.getMemberType(roleType.sourceName); if (this._staticallyKnownRoleClass != null) this.modifiers = this._staticallyKnownRoleClass.modifiers; // after we might have overwritten the modifiers restore some bits in the vein of ParameterizedTypeBinding: if (this.arguments != null) { this.modifiers |= ExtraCompilerModifiers.AccGenericSignature; } else if (this.enclosingType() != null) { this.modifiers |= (this.enclosingType().modifiers & ExtraCompilerModifiers.AccGenericSignature); this.tagBits |= this.enclosingType().tagBits & (TagBits.HasTypeVariable | TagBits.HasMissingType); } // record as known role type at teamAnchor and in our own cache registerAnchor(); }