/** * @see org.eclipse.jdt.internal.compiler.lookup.Binding#shortReadableName() */ public char[] shortReadableName() { StringBuffer nameBuffer = new StringBuffer(10); if (isMemberType()) { nameBuffer.append(CharOperation.concat(enclosingType().shortReadableName(), this.sourceName, '.')); } else { nameBuffer.append(this.type.sourceName); } if (this.arguments != null && this.arguments.length > 0) { // empty arguments array happens when PTB has been created just to capture type annotations nameBuffer.append('<'); for (int i = 0, length = this.arguments.length; i < length; i++) { if (i > 0) nameBuffer.append(','); nameBuffer.append(this.arguments[i].shortReadableName()); } nameBuffer.append('>'); } int nameLength = nameBuffer.length(); char[] shortReadableName = new char[nameLength]; nameBuffer.getChars(0, nameLength, shortReadableName, 0); return shortReadableName; }
public ReferenceBinding findGroundTargetTypeForElidedLambda(BlockScope blockScope, ParameterizedTypeBinding withWildCards) { // non-wildcard parameterization (9.8) of the target type TypeBinding[] types = withWildCards.getNonWildcardParameterization(blockScope); if (types == null) return null; ReferenceBinding genericType = withWildCards.genericType(); return blockScope.environment().createParameterizedType(genericType, types, withWildCards.enclosingType()); }
public ReferenceBinding findGroundTargetTypeForElidedLambda(BlockScope blockScope, ParameterizedTypeBinding withWildCards) { // non-wildcard parameterization (9.8) of the target type TypeBinding[] types = withWildCards.getNonWildcardParameterization(blockScope); if (types == null) return null; ReferenceBinding genericType = withWildCards.genericType(); return blockScope.environment().createParameterizedType(genericType, types, withWildCards.enclosingType()); }
public ReferenceBinding findGroundTargetTypeForElidedLambda(BlockScope blockScope, ParameterizedTypeBinding withWildCards) { // non-wildcard parameterization (9.8) of the target type TypeBinding[] types = withWildCards.getNonWildcardParameterization(blockScope); if (types == null) return null; ReferenceBinding genericType = withWildCards.genericType(); return blockScope.environment().createParameterizedType(genericType, types, withWildCards.enclosingType()); }
public ReferenceBinding findGroundTargetTypeForElidedLambda(BlockScope blockScope, ParameterizedTypeBinding withWildCards) { // non-wildcard parameterization (9.8) of the target type TypeBinding[] types = withWildCards.getNonWildcardParameterization(blockScope); if (types == null) return null; ReferenceBinding genericType = withWildCards.genericType(); return blockScope.environment().createParameterizedType(genericType, types, withWildCards.enclosingType()); }
public ReferenceBinding findGroundTargetTypeForElidedLambda(BlockScope blockScope, ParameterizedTypeBinding withWildCards) { // non-wildcard parameterization (9.8) of the target type TypeBinding[] types = withWildCards.getNonWildcardParameterization(blockScope); if (types == null) return null; ReferenceBinding genericType = withWildCards.genericType(); return blockScope.environment().createParameterizedType(genericType, types, withWildCards.enclosingType()); }
public TypeBinding[] inferElidedTypes(ParameterizedTypeBinding parameterizedType, final Scope scope) { ReferenceBinding genericType = parameterizedType.genericType(); ReferenceBinding enclosingType = parameterizedType.enclosingType(); ParameterizedTypeBinding allocationType = scope.environment().createParameterizedType(genericType, genericType.typeVariables(), enclosingType); /* Given the allocation type and the arguments to the constructor, see if we can synthesize a generic static factory method that would, given the argument types and the invocation site, manufacture a parameterized object of type allocationType. If we are successful then by design and construction, the parameterization of the return type of the factory method is identical to the types elided in the <>. */ MethodBinding factory = scope.getStaticFactory(allocationType, enclosingType, this.argumentTypes, this); if (factory instanceof ParameterizedGenericMethodBinding && factory.isValidBinding()) { ParameterizedGenericMethodBinding genericFactory = (ParameterizedGenericMethodBinding) factory; this.inferredReturnType = genericFactory.inferredReturnType; return ((ParameterizedTypeBinding)factory.returnType).arguments; } return null; }
public TypeBinding[] inferElidedTypes(ParameterizedTypeBinding parameterizedType, final Scope scope) { ReferenceBinding genericType = parameterizedType.genericType(); ReferenceBinding enclosingType = parameterizedType.enclosingType(); ParameterizedTypeBinding allocationType = scope.environment().createParameterizedType(genericType, genericType.typeVariables(), enclosingType); /* Given the allocation type and the arguments to the constructor, see if we can synthesize a generic static factory method that would, given the argument types and the invocation site, manufacture a parameterized object of type allocationType. If we are successful then by design and construction, the parameterization of the return type of the factory method is identical to the types elided in the <>. */ MethodBinding factory = scope.getStaticFactory(allocationType, enclosingType, this.argumentTypes, this); if (factory instanceof ParameterizedGenericMethodBinding && factory.isValidBinding()) { ParameterizedGenericMethodBinding genericFactory = (ParameterizedGenericMethodBinding) factory; this.inferredReturnType = genericFactory.inferredReturnType; return ((ParameterizedTypeBinding)factory.returnType).arguments; } return null; }
/** * Returns true if the type is parameterized using its own type variables as arguments */ public boolean isParameterizedWithOwnVariables() { if (kind() != Binding.PARAMETERIZED_TYPE) return false; ParameterizedTypeBinding paramType = (ParameterizedTypeBinding) this; if (paramType.arguments == null) return false; TypeVariableBinding[] variables = erasure().typeVariables(); for (int i = 0, length = variables.length; i < length; i++) { if (variables[i] != paramType.arguments[i]) return false; } ReferenceBinding enclosing = paramType.enclosingType(); if (enclosing != null && enclosing.erasure().isGenericType() && !enclosing.isParameterizedWithOwnVariables()) { return false; } return true; }
private static TypeBinding mergeTypeAnnotations(TypeBinding type, TypeBinding otherType, boolean top, LookupEnvironment environment) { TypeBinding mainType = type; if (!top) { // for all but the top level type superimpose other's type annotation onto type AnnotationBinding[] otherAnnotations = otherType.getTypeAnnotations(); if (otherAnnotations != Binding.NO_ANNOTATIONS) mainType = environment.createAnnotatedType(type, otherAnnotations); } if (mainType.isParameterizedType() && otherType.isParameterizedType()) { ParameterizedTypeBinding ptb = (ParameterizedTypeBinding) type, otherPTB = (ParameterizedTypeBinding) otherType; TypeBinding[] typeArguments = ptb.arguments; TypeBinding[] otherTypeArguments = otherPTB.arguments; TypeBinding[] newTypeArguments = new TypeBinding[typeArguments.length]; for (int i = 0; i < typeArguments.length; i++) { newTypeArguments[i] = mergeTypeAnnotations(typeArguments[i], otherTypeArguments[i], false, environment); } return environment.createParameterizedType(ptb.genericType(), newTypeArguments, ptb.enclosingType()); } return mainType; }
private static TypeBinding mergeTypeAnnotations(TypeBinding type, TypeBinding otherType, boolean top, LookupEnvironment environment) { TypeBinding mainType = type; if (!top) { // for all but the top level type superimpose other's type annotation onto type AnnotationBinding[] otherAnnotations = otherType.getTypeAnnotations(); if (otherAnnotations != Binding.NO_ANNOTATIONS) mainType = environment.createAnnotatedType(type, otherAnnotations); } if (mainType.isParameterizedType() && otherType.isParameterizedType()) { ParameterizedTypeBinding ptb = (ParameterizedTypeBinding) type, otherPTB = (ParameterizedTypeBinding) otherType; TypeBinding[] typeArguments = ptb.arguments; TypeBinding[] otherTypeArguments = otherPTB.arguments; TypeBinding[] newTypeArguments = new TypeBinding[typeArguments.length]; for (int i = 0; i < typeArguments.length; i++) { newTypeArguments[i] = mergeTypeAnnotations(typeArguments[i], otherTypeArguments[i], false, environment); } return environment.createParameterizedType(ptb.genericType(), newTypeArguments, ptb.enclosingType()); } return mainType; }
/** * Returns true if the type is parameterized using its own type variables as arguments */ public boolean isParameterizedWithOwnVariables() { if (kind() != Binding.PARAMETERIZED_TYPE) return false; ParameterizedTypeBinding paramType = (ParameterizedTypeBinding) this; if (paramType.arguments == null) return false; TypeVariableBinding[] variables = erasure().typeVariables(); for (int i = 0, length = variables.length; i < length; i++) { if (TypeBinding.notEquals(variables[i], paramType.arguments[i])) return false; } ReferenceBinding enclosing = paramType.enclosingType(); if (enclosing != null && enclosing.erasure().isGenericType() && !enclosing.isParameterizedWithOwnVariables()) { return false; } return true; }
private static TypeBinding mergeTypeAnnotations(TypeBinding type, TypeBinding otherType, boolean top, LookupEnvironment environment) { TypeBinding mainType = type; if (!top) { // for all but the top level type superimpose other's type annotation onto type AnnotationBinding[] otherAnnotations = otherType.getTypeAnnotations(); if (otherAnnotations != Binding.NO_ANNOTATIONS) mainType = environment.createAnnotatedType(type, otherAnnotations); } if (mainType.isParameterizedType() && otherType.isParameterizedType()) { ParameterizedTypeBinding ptb = (ParameterizedTypeBinding) type, otherPTB = (ParameterizedTypeBinding) otherType; TypeBinding[] typeArguments = ptb.arguments; TypeBinding[] otherTypeArguments = otherPTB.arguments; TypeBinding[] newTypeArguments = new TypeBinding[typeArguments.length]; for (int i = 0; i < typeArguments.length; i++) { newTypeArguments[i] = mergeTypeAnnotations(typeArguments[i], otherTypeArguments[i], false, environment); } return environment.createParameterizedType(ptb.genericType(), newTypeArguments, ptb.enclosingType()); } return mainType; }
/** * Returns true if the type is parameterized using its own type variables as arguments */ public boolean isParameterizedWithOwnVariables() { if (kind() != Binding.PARAMETERIZED_TYPE) return false; ParameterizedTypeBinding paramType = (ParameterizedTypeBinding) this; if (paramType.arguments == null) return false; TypeVariableBinding[] variables = erasure().typeVariables(); for (int i = 0, length = variables.length; i < length; i++) { if (TypeBinding.notEquals(variables[i], paramType.arguments[i])) return false; } ReferenceBinding enclosing = paramType.enclosingType(); if (enclosing != null && enclosing.erasure().isGenericType() && !enclosing.isParameterizedWithOwnVariables()) { return false; } return true; }
/** * Returns true if the type is parameterized using its own type variables as arguments */ public boolean isParameterizedWithOwnVariables() { if (kind() != Binding.PARAMETERIZED_TYPE) return false; ParameterizedTypeBinding paramType = (ParameterizedTypeBinding) this; if (paramType.arguments == null) return false; TypeVariableBinding[] variables = erasure().typeVariables(); for (int i = 0, length = variables.length; i < length; i++) { if (TypeBinding.notEquals(variables[i], paramType.arguments[i])) return false; } ReferenceBinding enclosing = paramType.enclosingType(); if (enclosing != null && enclosing.erasure().isGenericType() && !enclosing.isParameterizedWithOwnVariables()) { return false; } return true; }
private static TypeBinding mergeTypeAnnotations(TypeBinding type, TypeBinding otherType, boolean top, LookupEnvironment environment) { TypeBinding mainType = type; if (!top) { // for all but the top level type superimpose other's type annotation onto type AnnotationBinding[] otherAnnotations = otherType.getTypeAnnotations(); if (otherAnnotations != Binding.NO_ANNOTATIONS) mainType = environment.createAnnotatedType(type, otherAnnotations); } if (mainType.isParameterizedType() && otherType.isParameterizedType()) { ParameterizedTypeBinding ptb = (ParameterizedTypeBinding) type, otherPTB = (ParameterizedTypeBinding) otherType; TypeBinding[] typeArguments = ptb.arguments; TypeBinding[] otherTypeArguments = otherPTB.arguments; TypeBinding[] newTypeArguments = new TypeBinding[typeArguments.length]; for (int i = 0; i < typeArguments.length; i++) { newTypeArguments[i] = mergeTypeAnnotations(typeArguments[i], otherTypeArguments[i], false, environment); } return environment.createParameterizedType(ptb.genericType(), newTypeArguments, ptb.enclosingType()); } return mainType; }
private static TypeBinding mergeTypeAnnotations(TypeBinding type, TypeBinding otherType, boolean top, LookupEnvironment environment) { TypeBinding mainType = type; if (!top) { // for all but the top level type superimpose other's type annotation onto type AnnotationBinding[] otherAnnotations = otherType.getTypeAnnotations(); if (otherAnnotations != Binding.NO_ANNOTATIONS) mainType = environment.createAnnotatedType(type, otherAnnotations); } if (mainType.isParameterizedType() && otherType.isParameterizedType()) { ParameterizedTypeBinding ptb = (ParameterizedTypeBinding) type, otherPTB = (ParameterizedTypeBinding) otherType; TypeBinding[] typeArguments = ptb.arguments; TypeBinding[] otherTypeArguments = otherPTB.arguments; TypeBinding[] newTypeArguments = new TypeBinding[typeArguments.length]; for (int i = 0; i < typeArguments.length; i++) { newTypeArguments[i] = mergeTypeAnnotations(typeArguments[i], otherTypeArguments[i], false, environment); } return environment.createParameterizedType(ptb.genericType(), newTypeArguments, ptb.enclosingType()); } return mainType; }
/** * 18.5.3 Functional Interface Parameterization Inference */ public ReferenceBinding inferFunctionalInterfaceParameterization(LambdaExpression lambda, BlockScope blockScope, ParameterizedTypeBinding targetTypeWithWildCards) { TypeBinding[] q = createBoundsForFunctionalInterfaceParameterizationInference(targetTypeWithWildCards); if (q == null || q.length != lambda.arguments().length) { // fail TODO: can this still happen here? } else { if (reduceWithEqualityConstraints(lambda.argumentTypes(), q)) { ReferenceBinding genericType = targetTypeWithWildCards.genericType(); TypeBinding[] a = targetTypeWithWildCards.arguments; // a is not-null by construction of parameterizedWithWildcard() TypeBinding[] aprime = getFunctionInterfaceArgumentSolutions(a); // TODO If F<A'1, ..., A'm> is a well-formed type, ... return blockScope.environment().createParameterizedType(genericType, aprime, targetTypeWithWildCards.enclosingType()); } } return targetTypeWithWildCards; }
/** * 18.5.3 Functional Interface Parameterization Inference */ public ReferenceBinding inferFunctionalInterfaceParameterization(LambdaExpression lambda, BlockScope blockScope, ParameterizedTypeBinding targetTypeWithWildCards) { TypeBinding[] q = createBoundsForFunctionalInterfaceParameterizationInference(targetTypeWithWildCards); if (q == null || q.length != lambda.arguments().length) { // fail TODO: can this still happen here? } else { if (reduceWithEqualityConstraints(lambda.argumentTypes(), q)) { ReferenceBinding genericType = targetTypeWithWildCards.genericType(); TypeBinding[] a = targetTypeWithWildCards.arguments; // a is not-null by construction of parameterizedWithWildcard() TypeBinding[] aprime = getFunctionInterfaceArgumentSolutions(a); // TODO If F<A'1, ..., A'm> is a well-formed type, ... return blockScope.environment().createParameterizedType(genericType, aprime, targetTypeWithWildCards.enclosingType()); } } return targetTypeWithWildCards; }
/** * 18.5.3 Functional Interface Parameterization Inference */ public ReferenceBinding inferFunctionalInterfaceParameterization(LambdaExpression lambda, BlockScope blockScope, ParameterizedTypeBinding targetTypeWithWildCards) { TypeBinding[] q = createBoundsForFunctionalInterfaceParameterizationInference(targetTypeWithWildCards); if (q == null || q.length != lambda.arguments().length) { // fail TODO: can this still happen here? } else { if (reduceWithEqualityConstraints(lambda.argumentTypes(), q)) { ReferenceBinding genericType = targetTypeWithWildCards.genericType(); TypeBinding[] a = targetTypeWithWildCards.arguments; // a is not-null by construction of parameterizedWithWildcard() TypeBinding[] aprime = getFunctionInterfaceArgumentSolutions(a); // TODO If F<A'1, ..., A'm> is a well-formed type, ... return blockScope.environment().createParameterizedType(genericType, aprime, targetTypeWithWildCards.enclosingType()); } } return targetTypeWithWildCards; }