protected TypeReference cloneParamType(int index, List<TypeReference> typeArgs, EclipseNode builderType) { if (typeArgs != null && typeArgs.size() > index) { TypeReference originalType = typeArgs.get(index); if (originalType instanceof Wildcard) { Wildcard wOriginalType = (Wildcard) originalType; if (wOriginalType.kind == Wildcard.EXTENDS) { try { return copyType(wOriginalType.bound); } catch (Exception e) { // fallthrough } } } else { return copyType(originalType); } } return new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, NULL_POSS); }
public boolean visit(Wildcard wildcard, BlockScope scope) { if (wildcard.annotations != null) { if (formatInlineAnnotations(wildcard.annotations[0], false)) this.scribe.space(); } this.scribe.printNextToken(TerminalTokens.TokenNameQUESTION, this.preferences.insert_space_before_question_in_wilcard); switch(wildcard.kind) { case Wildcard.SUPER : this.scribe.printNextToken(TerminalTokens.TokenNamesuper, true); this.scribe.space(); wildcard.bound.traverse(this, scope); break; case Wildcard.EXTENDS : this.scribe.printNextToken(TerminalTokens.TokenNameextends, true); this.scribe.space(); wildcard.bound.traverse(this, scope); break; case Wildcard.UNBOUND : if (this.preferences.insert_space_after_question_in_wilcard) { this.scribe.space(); } } return false; }
public boolean visit(Wildcard wildcard, ClassScope scope) { if (wildcard.annotations != null) { if (formatInlineAnnotations(wildcard.annotations[0], false)) this.scribe.space(); } this.scribe.printNextToken(TerminalTokens.TokenNameQUESTION, this.preferences.insert_space_before_question_in_wilcard); switch(wildcard.kind) { case Wildcard.SUPER : this.scribe.printNextToken(TerminalTokens.TokenNamesuper, true); this.scribe.space(); wildcard.bound.traverse(this, scope); break; case Wildcard.EXTENDS : this.scribe.printNextToken(TerminalTokens.TokenNameextends, true); this.scribe.space(); wildcard.bound.traverse(this, scope); break; case Wildcard.UNBOUND : if (this.preferences.insert_space_after_question_in_wilcard) { this.scribe.space(); } } return false; }
public void consumeWildCard(int wildCardKind) { // don't put generic type in signature this.signature = new StringBuffer(); switch (wildCardKind) { case Wildcard.UNBOUND: this.signature.append('*'); break; case Wildcard.EXTENDS: this.signature.append('+'); this.signature.append(((KeyToSignature) this.arguments.get(0)).signature); break; case Wildcard.SUPER: this.signature.append('-'); this.signature.append(((KeyToSignature) this.arguments.get(0)).signature); break; default: // malformed return; } }
public void consumeWildCard(int kind) { switch (kind) { case Wildcard.EXTENDS: case Wildcard.SUPER: BindingKeyResolver boundResolver = (BindingKeyResolver) this.types.get(0); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=157847, do not allow creation of // internally inconsistent wildcards of the form '? super <null>' or '? extends <null>' final Binding boundBinding = boundResolver.compilerBinding; if (boundBinding instanceof TypeBinding) { this.typeBinding = this.environment.createWildcard((ReferenceBinding) this.typeBinding, this.wildcardRank, (TypeBinding) boundBinding, null /*no extra bound*/, kind); } else { this.typeBinding = null; } break; case Wildcard.UNBOUND: this.typeBinding = this.environment.createWildcard((ReferenceBinding) this.typeBinding, this.wildcardRank, null/*no bound*/, null /*no extra bound*/, kind); break; } }
protected void annotateTypeReference(Wildcard ref) { int length; if ((length = this.typeAnnotationLengthStack[this.typeAnnotationLengthPtr--]) != 0) { if (ref.annotations == null) ref.annotations = new Annotation[ref.getAnnotatableLevels()][]; System.arraycopy( this.typeAnnotationStack, (this.typeAnnotationPtr -= length) + 1, ref.annotations[0] = new Annotation[length], 0, length); if (ref.sourceStart > ref.annotations[0][0].sourceStart) { ref.sourceStart = ref.annotations[0][0].sourceStart; } ref.bits |= ASTNode.HasTypeAnnotations; } if (ref.bound != null) { ref.bits |= (ref.bound.bits & ASTNode.HasTypeAnnotations); } }
/** * The type of x.getClass() is substituted from 'Class<? extends Object>' into: 'Class<? extends raw(X)> */ public static ParameterizedMethodBinding instantiateGetClass(TypeBinding receiverType, MethodBinding originalMethod, Scope scope) { ParameterizedMethodBinding method = new ParameterizedMethodBinding(); method.modifiers = originalMethod.modifiers; method.selector = originalMethod.selector; method.declaringClass = originalMethod.declaringClass; method.typeVariables = Binding.NO_TYPE_VARIABLES; method.originalMethod = originalMethod; method.parameters = originalMethod.parameters; method.thrownExceptions = originalMethod.thrownExceptions; method.tagBits = originalMethod.tagBits; ReferenceBinding genericClassType = scope.getJavaLangClass(); LookupEnvironment environment = scope.environment(); TypeBinding rawType = environment.convertToRawType(receiverType.erasure(), false /*do not force conversion of enclosing types*/); method.returnType = environment.createParameterizedType( genericClassType, new TypeBinding[] { environment.createWildcard(genericClassType, 0, rawType, null /*no extra bound*/, Wildcard.EXTENDS) }, null); if ((method.returnType.tagBits & TagBits.HasMissingType) != 0) { method.tagBits |= TagBits.HasMissingType; } return method; }
/** * Returns true if the argument type satisfies the wildcard bound(s) */ public boolean boundCheck(TypeBinding argumentType) { switch (this.boundKind) { case Wildcard.UNBOUND : return true; case Wildcard.EXTENDS : if (!argumentType.isCompatibleWith(this.bound)) return false; // check other bounds (lub scenario) for (int i = 0, length = this.otherBounds == null ? 0 : this.otherBounds.length; i < length; i++) { if (!argumentType.isCompatibleWith(this.otherBounds[i])) return false; } return true; default: // SUPER // ? super Exception ok for: IOException, since it would be ok for (Exception)ioException return argumentType.isCompatibleWith(this.bound); } }
public char[] computeUniqueKey(boolean isLeaf) { char[] genericTypeKey = this.genericType.computeUniqueKey(false/*not a leaf*/); char[] wildCardKey; // We now encode the rank also in the binding key - https://bugs.eclipse.org/bugs/show_bug.cgi?id=234609 char[] rankComponent = ('{' + String.valueOf(this.rank) + '}').toCharArray(); switch (this.boundKind) { case Wildcard.UNBOUND : wildCardKey = TypeConstants.WILDCARD_STAR; break; case Wildcard.EXTENDS : wildCardKey = CharOperation.concat(TypeConstants.WILDCARD_PLUS, this.bound.computeUniqueKey(false/*not a leaf*/)); break; default: // SUPER wildCardKey = CharOperation.concat(TypeConstants.WILDCARD_MINUS, this.bound.computeUniqueKey(false/*not a leaf*/)); break; } return CharOperation.concat(genericTypeKey, rankComponent, wildCardKey); }
public String annotatedDebugName() { StringBuffer buffer = new StringBuffer(16); AnnotationBinding [] annotations = getTypeAnnotations(); for (int i = 0, length = annotations == null ? 0 : annotations.length; i < length; i++) { buffer.append(annotations[i]); buffer.append(' '); } switch (this.boundKind) { case Wildcard.UNBOUND : return buffer.append(TypeConstants.WILDCARD_NAME).toString(); case Wildcard.EXTENDS : if (this.otherBounds == null) return buffer.append(CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_EXTENDS, this.bound.annotatedDebugName().toCharArray())).toString(); buffer.append(this.bound.annotatedDebugName()); for (int i = 0, length = this.otherBounds.length; i < length; i++) { buffer.append(" & ").append(this.otherBounds[i].annotatedDebugName()); //$NON-NLS-1$ } return buffer.toString(); default: // SUPER return buffer.append(CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_SUPER, this.bound.annotatedDebugName().toCharArray())).toString(); } }
public ReferenceBinding superclass() { if (this.superclass == null) { TypeBinding superType = null; if (this.boundKind == Wildcard.EXTENDS && !this.bound.isInterface()) { superType = this.bound; } else { TypeVariableBinding variable = typeVariable(); if (variable != null) superType = variable.firstBound; } this.superclass = superType instanceof ReferenceBinding && !superType.isInterface() ? (ReferenceBinding) superType : this.environment.getResolvedType(TypeConstants.JAVA_LANG_OBJECT, null); } return this.superclass; }
/** * @see java.lang.Object#toString() */ public String toString() { if (this.hasTypeAnnotations()) return annotatedDebugName(); switch (this.boundKind) { case Wildcard.UNBOUND : return new String(TypeConstants.WILDCARD_NAME); case Wildcard.EXTENDS : if (this.otherBounds == null) return new String(CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_EXTENDS, this.bound.debugName().toCharArray())); StringBuffer buffer = new StringBuffer(this.bound.debugName()); for (int i = 0, length = this.otherBounds.length; i < length; i++) { buffer.append('&').append(this.otherBounds[i].debugName()); } return buffer.toString(); default: // SUPER return new String(CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_SUPER, this.bound.debugName().toCharArray())); } }
public boolean visit(Wildcard wildcard, BlockScope scope) { this.scribe.printNextToken(TerminalTokens.TokenNameQUESTION, this.preferences.insert_space_before_question_in_wilcard); switch(wildcard.kind) { case Wildcard.SUPER : this.scribe.printNextToken(TerminalTokens.TokenNamesuper, true); this.scribe.space(); wildcard.bound.traverse(this, scope); break; case Wildcard.EXTENDS : this.scribe.printNextToken(TerminalTokens.TokenNameextends, true); this.scribe.space(); wildcard.bound.traverse(this, scope); break; case Wildcard.UNBOUND : if (this.preferences.insert_space_after_question_in_wilcard) { this.scribe.space(); } } return false; }
public boolean visit(Wildcard wildcard, ClassScope scope) { this.scribe.printNextToken(TerminalTokens.TokenNameQUESTION, this.preferences.insert_space_before_question_in_wilcard); switch(wildcard.kind) { case Wildcard.SUPER : this.scribe.printNextToken(TerminalTokens.TokenNamesuper, true); this.scribe.space(); wildcard.bound.traverse(this, scope); break; case Wildcard.EXTENDS : this.scribe.printNextToken(TerminalTokens.TokenNameextends, true); this.scribe.space(); wildcard.bound.traverse(this, scope); break; case Wildcard.UNBOUND : if (this.preferences.insert_space_after_question_in_wilcard) { this.scribe.space(); } } return false; }
/** * @see java.lang.Object#toString() */ public String toString() { switch (this.boundKind) { case Wildcard.UNBOUND : return new String(TypeConstants.WILDCARD_NAME); case Wildcard.EXTENDS : if (this.otherBounds == null) return new String(CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_EXTENDS, this.bound.debugName().toCharArray())); StringBuffer buffer = new StringBuffer(this.bound.debugName()); for (int i = 0, length = this.otherBounds.length; i < length; i++) { buffer.append('&').append(this.otherBounds[i].debugName()); } return buffer.toString(); default: // SUPER return new String(CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_SUPER, this.bound.debugName().toCharArray())); } }
@Override public TypeMirror getExtendsBound() { WildcardBinding wildcardBinding = (WildcardBinding) this._binding; if (wildcardBinding.boundKind != Wildcard.EXTENDS) return null; TypeBinding bound = wildcardBinding.bound; if (bound == null) return null; return _env.getFactory().newTypeMirror(bound); }
@Override public TypeMirror getSuperBound() { WildcardBinding wildcardBinding = (WildcardBinding) this._binding; if (wildcardBinding.boundKind != Wildcard.SUPER) return null; TypeBinding bound = wildcardBinding.bound; if (bound == null) return null; return _env.getFactory().newTypeMirror(bound); }
@Override public TypeBinding resolveType(BlockScope scope) { final CompilerOptions compilerOptions = scope.compilerOptions(); TypeBinding lhsType; boolean typeArgumentsHaveErrors; this.constant = Constant.NotAConstant; lhsType = this.lhs.resolveType(scope); if (this.typeArguments != null) { int length = this.typeArguments.length; typeArgumentsHaveErrors = compilerOptions.sourceLevel < ClassFileConstants.JDK1_5; this.resolvedTypeArguments = new TypeBinding[length]; for (int i = 0; i < length; i++) { TypeReference typeReference = this.typeArguments[i]; if ((this.resolvedTypeArguments[i] = typeReference.resolveType(scope, true /* check bounds*/)) == null) { typeArgumentsHaveErrors = true; } if (typeArgumentsHaveErrors && typeReference instanceof Wildcard) { // resolveType on wildcard always return null above, resolveTypeArgument is the real workhorse. scope.problemReporter().illegalUsageOfWildcard(typeReference); } } if (typeArgumentsHaveErrors || lhsType == null) throw new CompletionNodeFound(); } if (lhsType != null && lhsType.isValidBinding()) throw new CompletionNodeFound(this, lhsType, scope); throw new CompletionNodeFound(); }
private void parseWildcard() { parseWildcardRank(); if (this.scanner.nextToken() != Scanner.WILDCARD) return; char[] source = this.scanner.getTokenSource(); if (source.length == 0) { malformedKey(); return; } int kind = -1; switch (source[0]) { case '*': kind = Wildcard.UNBOUND; break; case '+': kind = Wildcard.EXTENDS; break; case '-': kind = Wildcard.SUPER; break; } if (kind == -1) { malformedKey(); return; } if (kind != Wildcard.UNBOUND) parseWildcardBound(); consumeWildCard(kind); }
public boolean isUpperbound() { switch (this.binding.kind()) { case Binding.WILDCARD_TYPE : return ((WildcardBinding) this.binding).boundKind == Wildcard.EXTENDS; case Binding.INTERSECTION_TYPE : return true; } return false; }
protected void consumeWildcard() { final Wildcard wildcard = new Wildcard(Wildcard.UNBOUND); wildcard.sourceEnd = this.intStack[this.intPtr--]; wildcard.sourceStart = this.intStack[this.intPtr--]; annotateTypeReference(wildcard); pushOnGenericsStack(wildcard); }
protected void consumeWildcard1() { final Wildcard wildcard = new Wildcard(Wildcard.UNBOUND); wildcard.sourceEnd = this.intStack[this.intPtr--]; wildcard.sourceStart = this.intStack[this.intPtr--]; annotateTypeReference(wildcard); pushOnGenericsStack(wildcard); }
protected void consumeWildcard2() { final Wildcard wildcard = new Wildcard(Wildcard.UNBOUND); wildcard.sourceEnd = this.intStack[this.intPtr--]; wildcard.sourceStart = this.intStack[this.intPtr--]; annotateTypeReference(wildcard); pushOnGenericsStack(wildcard); }
protected void consumeWildcard3() { final Wildcard wildcard = new Wildcard(Wildcard.UNBOUND); wildcard.sourceEnd = this.intStack[this.intPtr--]; wildcard.sourceStart = this.intStack[this.intPtr--]; annotateTypeReference(wildcard); pushOnGenericsStack(wildcard); }
protected void consumeWildcardBounds1Extends() { Wildcard wildcard = new Wildcard(Wildcard.EXTENDS); wildcard.bound = (TypeReference) this.genericsStack[this.genericsPtr]; wildcard.sourceEnd = wildcard.bound.sourceEnd; this.intPtr--; // remove end position of the '?' wildcard.sourceStart = this.intStack[this.intPtr--]; annotateTypeReference(wildcard); this.genericsStack[this.genericsPtr] = wildcard; }
protected void consumeWildcardBounds1Super() { Wildcard wildcard = new Wildcard(Wildcard.SUPER); wildcard.bound = (TypeReference) this.genericsStack[this.genericsPtr]; this.intPtr--; // remove the starting position of the super keyword wildcard.sourceEnd = wildcard.bound.sourceEnd; this.intPtr--; // remove end position of the '?' wildcard.sourceStart = this.intStack[this.intPtr--]; annotateTypeReference(wildcard); this.genericsStack[this.genericsPtr] = wildcard; }
protected void consumeWildcardBounds2Extends() { Wildcard wildcard = new Wildcard(Wildcard.EXTENDS); wildcard.bound = (TypeReference) this.genericsStack[this.genericsPtr]; wildcard.sourceEnd = wildcard.bound.sourceEnd; this.intPtr--; // remove end position of the '?' wildcard.sourceStart = this.intStack[this.intPtr--]; annotateTypeReference(wildcard); this.genericsStack[this.genericsPtr] = wildcard; }
protected void consumeWildcardBounds2Super() { Wildcard wildcard = new Wildcard(Wildcard.SUPER); wildcard.bound = (TypeReference) this.genericsStack[this.genericsPtr]; this.intPtr--; // remove the starting position of the super keyword wildcard.sourceEnd = wildcard.bound.sourceEnd; this.intPtr--; // remove end position of the '?' wildcard.sourceStart = this.intStack[this.intPtr--]; annotateTypeReference(wildcard); this.genericsStack[this.genericsPtr] = wildcard; }
protected void consumeWildcardBounds3Extends() { Wildcard wildcard = new Wildcard(Wildcard.EXTENDS); wildcard.bound = (TypeReference) this.genericsStack[this.genericsPtr]; wildcard.sourceEnd = wildcard.bound.sourceEnd; this.intPtr--; // remove end position of the '?' wildcard.sourceStart = this.intStack[this.intPtr--]; annotateTypeReference(wildcard); this.genericsStack[this.genericsPtr] = wildcard; }
protected void consumeWildcardBounds3Super() { Wildcard wildcard = new Wildcard(Wildcard.SUPER); wildcard.bound = (TypeReference) this.genericsStack[this.genericsPtr]; this.intPtr--; // remove the starting position of the super keyword wildcard.sourceEnd = wildcard.bound.sourceEnd; this.intPtr--; // remove end position of the '?' wildcard.sourceStart = this.intStack[this.intPtr--]; annotateTypeReference(wildcard); this.genericsStack[this.genericsPtr] = wildcard; }
protected void consumeWildcardBoundsExtends() { Wildcard wildcard = new Wildcard(Wildcard.EXTENDS); wildcard.bound = getTypeReference(this.intStack[this.intPtr--]); wildcard.sourceEnd = wildcard.bound.sourceEnd; this.intPtr--; // remove end position of the '?' wildcard.sourceStart = this.intStack[this.intPtr--]; annotateTypeReference(wildcard); pushOnGenericsStack(wildcard); }
protected void consumeWildcardBoundsSuper() { Wildcard wildcard = new Wildcard(Wildcard.SUPER); wildcard.bound = getTypeReference(this.intStack[this.intPtr--]); this.intPtr--; // remove the starting position of the super keyword wildcard.sourceEnd = wildcard.bound.sourceEnd; this.intPtr--; // remove end position of the '?' wildcard.sourceStart = this.intStack[this.intPtr--]; annotateTypeReference(wildcard); pushOnGenericsStack(wildcard); }
void addTypeBoundsFromWildcardBound(InferenceContext18 context, InferenceSubstitution theta, int boundKind, TypeBinding t, TypeBinding r, TypeBinding bi) throws InferenceFailureException { ConstraintFormula formula = null; if (boundKind == Wildcard.EXTENDS) { if (bi.id == TypeIds.T_JavaLangObject) formula = ConstraintTypeFormula.create(t, r, ReductionResult.SUBTYPE); if (t.id == TypeIds.T_JavaLangObject) formula = ConstraintTypeFormula.create(theta.substitute(theta, bi), r, ReductionResult.SUBTYPE); } else { formula = ConstraintTypeFormula.create(theta.substitute(theta, bi), r, ReductionResult.SUBTYPE); } if (formula != null) reduceOneConstraint(context, formula); }