public static MethodBinding inferDiamondConstructor(Scope scope, InvocationSite site, TypeBinding type, TypeBinding[] argumentTypes, boolean[] inferredReturnTypeOut) { ReferenceBinding genericType = ((ParameterizedTypeBinding) type).genericType(); ReferenceBinding enclosingType = type.enclosingType(); ParameterizedTypeBinding allocationType = scope.environment().createParameterizedType(genericType, genericType.typeVariables(), enclosingType); // Given the allocation type and the arguments to the constructor, see if we can infer the constructor of the elided parameterized type. MethodBinding factory = scope.getStaticFactory(allocationType, enclosingType, argumentTypes, site); if (factory instanceof ParameterizedGenericMethodBinding && factory.isValidBinding()) { ParameterizedGenericMethodBinding genericFactory = (ParameterizedGenericMethodBinding) factory; inferredReturnTypeOut[0] = genericFactory.inferredReturnType; SyntheticFactoryMethodBinding sfmb = (SyntheticFactoryMethodBinding) factory.original(); TypeVariableBinding[] constructorTypeVariables = sfmb.getConstructor().typeVariables(); TypeBinding [] constructorTypeArguments = constructorTypeVariables != null ? new TypeBinding[constructorTypeVariables.length] : Binding.NO_TYPES; if (constructorTypeArguments.length > 0) System.arraycopy(((ParameterizedGenericMethodBinding)factory).typeArguments, sfmb.typeVariables().length - constructorTypeArguments.length , constructorTypeArguments, 0, constructorTypeArguments.length); if (allocationType.isInterface()) { ParameterizedTypeBinding parameterizedType = (ParameterizedTypeBinding) factory.returnType; return new ParameterizedMethodBinding(parameterizedType, sfmb.getConstructor()); } return sfmb.applyTypeArgumentsOnConstructor(((ParameterizedTypeBinding)factory.returnType).arguments, constructorTypeArguments, genericFactory.inferredWithUncheckedConversion, site.invocationTargetType()); } return null; } public TypeBinding[] inferElidedTypes(final Scope scope) {
public static MethodBinding inferDiamondConstructor(Scope scope, InvocationSite site, TypeBinding type, TypeBinding[] argumentTypes, boolean[] inferredReturnTypeOut) { ReferenceBinding genericType = ((ParameterizedTypeBinding) type).genericType(); ReferenceBinding enclosingType = type.enclosingType(); ParameterizedTypeBinding allocationType = scope.environment().createParameterizedType(genericType, genericType.typeVariables(), enclosingType); // Given the allocation type and the arguments to the constructor, see if we can infer the constructor of the elided parameterized type. MethodBinding factory = scope.getStaticFactory(allocationType, enclosingType, argumentTypes, site); if (factory instanceof ParameterizedGenericMethodBinding && factory.isValidBinding()) { ParameterizedGenericMethodBinding genericFactory = (ParameterizedGenericMethodBinding) factory; inferredReturnTypeOut[0] = genericFactory.inferredReturnType; SyntheticFactoryMethodBinding sfmb = (SyntheticFactoryMethodBinding) factory.original(); TypeVariableBinding[] constructorTypeVariables = sfmb.getConstructor().typeVariables(); TypeBinding [] constructorTypeArguments = constructorTypeVariables != null ? new TypeBinding[constructorTypeVariables.length] : Binding.NO_TYPES; if (constructorTypeArguments.length > 0) System.arraycopy(((ParameterizedGenericMethodBinding)factory).typeArguments, sfmb.typeVariables().length - constructorTypeArguments.length , constructorTypeArguments, 0, constructorTypeArguments.length); if (allocationType.isInterface()) { ParameterizedTypeBinding parameterizedType = (ParameterizedTypeBinding) factory.returnType; return new ParameterizedMethodBinding(parameterizedType, sfmb.getConstructor()); } return sfmb.applyTypeArgumentsOnConstructor(((ParameterizedTypeBinding)factory.returnType).arguments, constructorTypeArguments, genericFactory.inferredWithUncheckedConversion, site.invocationTargetType()); } return null; } public TypeBinding[] inferElidedTypes(final Scope scope) {
if (isInterface()) { if (superInterfaces().length == 1) { if (refScope != null)
if (isInterface()) { if (superInterfaces().length == 1) { if (refScope != null)
if (isInterface()) { if (superInterfaces().length == 1) { if (refScope != null)
if (isInterface()) { if (superInterfaces().length == 1) { if (refScope != null)
if (isInterface()) { if (superInterfaces().length == 1) { if (refScope != null)
if (isInterface()) { if (superInterfaces().length == 1) { if (refScope != null)
if (isInterface()) { if (superInterfaces().length == 1) { if (refScope != null)
if (isInterface()) { if (superInterfaces().length == 1) { if (refScope != null)
if (isInterface()) { if (superInterfaces().length == 1) { if (refScope != null)
if (isInterface()) { if (superInterfaces().length == 1) { if (refScope != null)
if (isInterface()) { if (superInterfaces().length == 1) { if (refScope != null)
currentType = currentType.enclosingType(); boolean isInterface = allocationType.isInterface(); ReferenceBinding typeToSearch = isInterface ? getJavaLangObject() : allocationType;
currentType = currentType.enclosingType(); boolean isInterface = allocationType.isInterface(); ReferenceBinding typeToSearch = isInterface ? getJavaLangObject() : allocationType;