public ParameterizedTypeBinding mergeTypeParameters(ParameterizedTypeBinding current, ParameterizedTypeBinding newB) { TypeBinding[] curTypeArgs = current.typeArguments(); TypeBinding[] newTypeArgs = newB.typeArguments(); TypeBinding[] merged = new TypeBinding[curTypeArgs.length]; System.arraycopy(curTypeArgs, 0, merged, 0, curTypeArgs.length);
private boolean isOnlyWildcardMismatch(TypeBinding expected, TypeBinding argument) { boolean onlyWildcardMismatch = false; if (expected.isParameterizedType() && argument.isParameterizedType()) { TypeBinding[] expectedArgs = ((ParameterizedTypeBinding)expected).typeArguments(); TypeBinding[] args = ((ParameterizedTypeBinding)argument).typeArguments(); for (int j = 0; j < args.length; j++) { if (TypeBinding.notEquals(expectedArgs[j], args[j])) { if (expectedArgs[j].isWildcard() && args[j].isUnboundWildcard()) { WildcardBinding wc = (WildcardBinding)expectedArgs[j]; TypeBinding bound = wc.allBounds(); if (bound != null && wc.boundKind == Wildcard.EXTENDS && bound.id == TypeIds.T_JavaLangObject) onlyWildcardMismatch = true; } else { onlyWildcardMismatch = false; break; } } } } return onlyWildcardMismatch; } private ReferenceBinding findGroundTargetType(BlockScope blockScope, TypeBinding targetType, TypeBinding expectedSAMType, boolean argumentTypesElided) {
private boolean isOnlyWildcardMismatch(TypeBinding expected, TypeBinding argument) { boolean onlyWildcardMismatch = false; if (expected.isParameterizedType() && argument.isParameterizedType()) { TypeBinding[] expectedArgs = ((ParameterizedTypeBinding)expected).typeArguments(); TypeBinding[] args = ((ParameterizedTypeBinding)argument).typeArguments(); for (int j = 0; j < args.length; j++) { if (TypeBinding.notEquals(expectedArgs[j], args[j])) { if (expectedArgs[j].isWildcard() && args[j].isUnboundWildcard()) { WildcardBinding wc = (WildcardBinding)expectedArgs[j]; TypeBinding bound = wc.allBounds(); if (bound != null && wc.boundKind == Wildcard.EXTENDS && bound.id == TypeIds.T_JavaLangObject) onlyWildcardMismatch = true; } else { onlyWildcardMismatch = false; break; } } } } return onlyWildcardMismatch; } private ReferenceBinding findGroundTargetType(BlockScope blockScope, TypeBinding targetType, TypeBinding expectedSAMType, boolean argumentTypesElided) {
public ParameterizedTypeBinding mergeTypeParameters(ParameterizedTypeBinding current, ParameterizedTypeBinding newB) { TypeBinding[] curTypeArgs = current.typeArguments(); TypeBinding[] newTypeArgs = newB.typeArguments(); TypeBinding[] merged = new TypeBinding[curTypeArgs.length]; System.arraycopy(curTypeArgs, 0, merged, 0, curTypeArgs.length);
public ParameterizedTypeBinding mergeTypeParameters(ParameterizedTypeBinding current, ParameterizedTypeBinding newB) { TypeBinding[] curTypeArgs = current.typeArguments(); TypeBinding[] newTypeArgs = newB.typeArguments(); TypeBinding[] merged = new TypeBinding[curTypeArgs.length]; System.arraycopy(curTypeArgs, 0, merged, 0, curTypeArgs.length);
@Override public TypeMirror find(ReferenceBinding typeBinding, Binding memberBinding) { if (typeBinding instanceof ParameterizedTypeBinding) { TypeVariableBinding variableBinding = ((TypeVariableBinding) memberBinding); ReferenceBinding binding = ((ParameterizedTypeBinding) typeBinding).genericType(); if (variableBinding.declaringElement == binding) { // check in advance avoid looking into type parameters unnecessarily. TypeVariableBinding[] typeVariables = binding.typeVariables(); TypeBinding[] typeArguments = ((ParameterizedTypeBinding) typeBinding).typeArguments(); if (typeVariables.length == typeArguments.length) { for(int i = 0; i < typeVariables.length; i++) { if (typeVariables[i] == memberBinding) { return TypesImpl.this._env.getFactory().newTypeMirror(typeArguments[i]); } } } } } return null; } });
if (mapType != null && mapType.isParameterizedType()) return new UnlikelyArgumentCheck(suspect, argumentType, ((ParameterizedTypeBinding) mapType).typeArguments()[0], mapType); break; case ContainsValue: if (mapType != null && mapType.isParameterizedType()) return new UnlikelyArgumentCheck(suspect, argumentType, ((ParameterizedTypeBinding) mapType).typeArguments()[1], mapType); break; default: // no other suspects are detected in java.util.Map if (collectionType != null && collectionType.isParameterizedType()) return new UnlikelyArgumentCheck(suspect, argumentType, ((ParameterizedTypeBinding) collectionType).typeArguments()[0], collectionType); break; default: // no other suspects with Object-parameter are detected in java.util.Collection && collectionType.isParameterizedTypeWithActualArguments()) { return new UnlikelyArgumentCheck(suspect, ((ParameterizedTypeBinding) argumentCollectionType).typeArguments()[0], ((ParameterizedTypeBinding) collectionType).typeArguments()[0], collectionType); if (listType != null && listType.isParameterizedType()) return new UnlikelyArgumentCheck(suspect, argumentType, ((ParameterizedTypeBinding) listType).typeArguments()[0], listType); break; default: // no other suspects are detected in java.util.List
if (mapType != null && mapType.isParameterizedType()) return new UnlikelyArgumentCheck(suspect, argumentType, ((ParameterizedTypeBinding) mapType).typeArguments()[0], mapType); break; case ContainsValue: if (mapType != null && mapType.isParameterizedType()) return new UnlikelyArgumentCheck(suspect, argumentType, ((ParameterizedTypeBinding) mapType).typeArguments()[1], mapType); break; default: // no other suspects are detected in java.util.Map if (collectionType != null && collectionType.isParameterizedType()) return new UnlikelyArgumentCheck(suspect, argumentType, ((ParameterizedTypeBinding) collectionType).typeArguments()[0], collectionType); break; default: // no other suspects with Object-parameter are detected in java.util.Collection && collectionType.isParameterizedTypeWithActualArguments()) { return new UnlikelyArgumentCheck(suspect, ((ParameterizedTypeBinding) argumentCollectionType).typeArguments()[0], ((ParameterizedTypeBinding) collectionType).typeArguments()[0], collectionType); if (listType != null && listType.isParameterizedType()) return new UnlikelyArgumentCheck(suspect, argumentType, ((ParameterizedTypeBinding) listType).typeArguments()[0], listType); break; default: // no other suspects are detected in java.util.List
|| !Util.effectivelyEqual(parameterizedType.typeArguments(), typeArgumentsToMatch)) continue; if (Util.effectivelyEqual(annotations, parameterizedType.getTypeAnnotations()))
|| !Util.effectivelyEqual(parameterizedType.typeArguments(), typeArgumentsToMatch)) continue; if (Util.effectivelyEqual(annotations, parameterizedType.getTypeAnnotations()))
|| !Util.effectivelyEqual(parameterizedType.typeArguments(), typeArgumentsToMatch)) continue; if (Util.effectivelyEqual(annotations, parameterizedType.getTypeAnnotations()))
|| !Util.effectivelyEqual(parameterizedType.typeArguments(), typeArgumentsToMatch)) continue; if (Util.effectivelyEqual(annotations, parameterizedType.getTypeAnnotations()))
|| !Util.effectivelyEqual(parameterizedType.typeArguments(), typeArgumentsToMatch)) continue; if (Util.effectivelyEqual(annotations, parameterizedType.getTypeAnnotations()))
@Override public boolean visit(ParameterizedTypeBinding parameterizedTypeBinding) { ExternalAnnotationSuperimposer memento = snapshot(); try { IBinaryAnnotation[] binaryAnnotations = this.currentWalker.getAnnotationsAtCursor(parameterizedTypeBinding.id, false); AnnotationBinding[] annotations = Binding.NO_ANNOTATIONS; if (binaryAnnotations != ITypeAnnotationWalker.NO_ANNOTATIONS) { annotations = BinaryTypeBinding.createAnnotations(binaryAnnotations, this.environment, null); this.isReplacing = true; } TypeBinding[] typeArguments = parameterizedTypeBinding.typeArguments(); TypeBinding[] newArguments = new TypeBinding[typeArguments.length]; for (int i = 0; i < typeArguments.length; i++) { newArguments[i] = goAndSuperimpose(memento.currentWalker.toTypeArgument(i), typeArguments[i]); } if (this.isReplacing) this.typeReplacement = this.environment.createParameterizedType(parameterizedTypeBinding.genericType(), newArguments, parameterizedTypeBinding.enclosingType(), annotations); return false; } finally { restore(memento); } } @Override
@Override public boolean visit(ParameterizedTypeBinding parameterizedTypeBinding) { ExternalAnnotationSuperimposer memento = snapshot(); try { IBinaryAnnotation[] binaryAnnotations = this.currentWalker.getAnnotationsAtCursor(parameterizedTypeBinding.id); AnnotationBinding[] annotations = Binding.NO_ANNOTATIONS; if (binaryAnnotations != ITypeAnnotationWalker.NO_ANNOTATIONS) { annotations = BinaryTypeBinding.createAnnotations(binaryAnnotations, this.environment, null); this.isReplacing = true; } TypeBinding[] typeArguments = parameterizedTypeBinding.typeArguments(); TypeBinding[] newArguments = new TypeBinding[typeArguments.length]; for (int i = 0; i < typeArguments.length; i++) { newArguments[i] = goAndSuperimpose(memento.currentWalker.toTypeArgument(i), typeArguments[i]); } if (this.isReplacing) this.typeReplacement = this.environment.createParameterizedType(parameterizedTypeBinding.genericType(), newArguments, parameterizedTypeBinding.enclosingType(), annotations); return false; } finally { restore(memento); } } @Override
@Override public boolean visit(ParameterizedTypeBinding parameterizedTypeBinding) { ExternalAnnotationSuperimposer memento = snapshot(); try { IBinaryAnnotation[] binaryAnnotations = this.currentWalker.getAnnotationsAtCursor(parameterizedTypeBinding.id); AnnotationBinding[] annotations = Binding.NO_ANNOTATIONS; if (binaryAnnotations != ITypeAnnotationWalker.NO_ANNOTATIONS) { annotations = BinaryTypeBinding.createAnnotations(binaryAnnotations, this.environment, null); this.isReplacing = true; } TypeBinding[] typeArguments = parameterizedTypeBinding.typeArguments(); TypeBinding[] newArguments = new TypeBinding[typeArguments.length]; for (int i = 0; i < typeArguments.length; i++) { newArguments[i] = goAndSuperimpose(memento.currentWalker.toTypeArgument(i), typeArguments[i]); } if (this.isReplacing) this.typeReplacement = this.environment.createParameterizedType(parameterizedTypeBinding.genericType(), newArguments, parameterizedTypeBinding.enclosingType(), annotations); return false; } finally { restore(memento); } } @Override
@Override public boolean visit(ParameterizedTypeBinding parameterizedTypeBinding) { ExternalAnnotationSuperimposer memento = snapshot(); try { IBinaryAnnotation[] binaryAnnotations = this.currentWalker.getAnnotationsAtCursor(parameterizedTypeBinding.id, false); AnnotationBinding[] annotations = Binding.NO_ANNOTATIONS; if (binaryAnnotations != ITypeAnnotationWalker.NO_ANNOTATIONS) { annotations = BinaryTypeBinding.createAnnotations(binaryAnnotations, this.environment, null); this.isReplacing = true; } TypeBinding[] typeArguments = parameterizedTypeBinding.typeArguments(); TypeBinding[] newArguments = new TypeBinding[typeArguments.length]; for (int i = 0; i < typeArguments.length; i++) { newArguments[i] = goAndSuperimpose(memento.currentWalker.toTypeArgument(i), typeArguments[i]); } if (this.isReplacing) this.typeReplacement = this.environment.createParameterizedType(parameterizedTypeBinding.genericType(), newArguments, parameterizedTypeBinding.enclosingType(), annotations); return false; } finally { restore(memento); } } @Override
@Override public boolean visit(ParameterizedTypeBinding parameterizedTypeBinding) { ExternalAnnotationSuperimposer memento = snapshot(); try { IBinaryAnnotation[] binaryAnnotations = this.currentWalker.getAnnotationsAtCursor(parameterizedTypeBinding.id); AnnotationBinding[] annotations = Binding.NO_ANNOTATIONS; if (binaryAnnotations != ITypeAnnotationWalker.NO_ANNOTATIONS) { annotations = BinaryTypeBinding.createAnnotations(binaryAnnotations, this.environment, null); this.isReplacing = true; } TypeBinding[] typeArguments = parameterizedTypeBinding.typeArguments(); TypeBinding[] newArguments = new TypeBinding[typeArguments.length]; for (int i = 0; i < typeArguments.length; i++) { newArguments[i] = goAndSuperimpose(memento.currentWalker.toTypeArgument(i), typeArguments[i]); } if (this.isReplacing) this.typeReplacement = this.environment.createParameterizedType(parameterizedTypeBinding.genericType(), newArguments, parameterizedTypeBinding.enclosingType(), annotations); return false; } finally { restore(memento); } } @Override