本文整理汇总了Java中org.eclipse.jdt.internal.compiler.impl.CompilerOptions.tolerateIllegalAmbiguousVarargsInvocation方法的典型用法代码示例。如果您正苦于以下问题:Java CompilerOptions.tolerateIllegalAmbiguousVarargsInvocation方法的具体用法?Java CompilerOptions.tolerateIllegalAmbiguousVarargsInvocation怎么用?Java CompilerOptions.tolerateIllegalAmbiguousVarargsInvocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.internal.compiler.impl.CompilerOptions
的用法示例。
在下文中一共展示了CompilerOptions.tolerateIllegalAmbiguousVarargsInvocation方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parameterCompatibilityLevel
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; //导入方法依赖的package包/类
private int parameterCompatibilityLevel(TypeBinding arg, TypeBinding param, LookupEnvironment env, boolean tieBreakingVarargsMethods) {
// only called if env.options.sourceLevel >= ClassFileConstants.JDK1_5
if (arg == null || param == null)
return NOT_COMPATIBLE;
if (arg.isCompatibleWith(param, this))
return COMPATIBLE;
if (tieBreakingVarargsMethods && (this.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_7 || !CompilerOptions.tolerateIllegalAmbiguousVarargsInvocation)) {
/* 15.12.2.5 Choosing the Most Specific Method, ... One variable arity member method named m is more specific than
another variable arity member method of the same name if either ... Only subtypes relationship should be used.
Actually this is true even for fixed arity methods, but in practice is not an issue since we run the algorithm
multiple times for each compatibility level.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=346038, https://bugs.eclipse.org/bugs/show_bug.cgi?id=346039.
*/
return NOT_COMPATIBLE;
}
if (arg.kind() == Binding.POLY_TYPE || (arg.isBaseType() != param.isBaseType())) {
TypeBinding convertedType = env.computeBoxingType(arg);
if (TypeBinding.equalsEquals(convertedType, param) || convertedType.isCompatibleWith(param, this))
return AUTOBOX_COMPATIBLE;
}
return NOT_COMPATIBLE;
}
示例2: parameterCompatibilityLevel
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; //导入方法依赖的package包/类
private int parameterCompatibilityLevel(TypeBinding arg, TypeBinding param, LookupEnvironment env, boolean tieBreakingVarargsMethods) {
// only called if env.options.sourceLevel >= ClassFileConstants.JDK1_5
if (arg.isCompatibleWith(param))
return COMPATIBLE;
if (tieBreakingVarargsMethods && (this.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_7 || !CompilerOptions.tolerateIllegalAmbiguousVarargsInvocation)) {
/* 15.12.2.5 Choosing the Most Specific Method, ... One variable arity member method named m is more specific than
another variable arity member method of the same name if either ... Only subtypes relationship should be used.
Actually this is true even for fixed arity methods, but in practice is not an issue since we run the algorithm
multiple times for each compatibility level.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=346038, https://bugs.eclipse.org/bugs/show_bug.cgi?id=346039.
*/
return NOT_COMPATIBLE;
}
if (arg.isBaseType() != param.isBaseType()) {
TypeBinding convertedType = env.computeBoxingType(arg);
if (convertedType == param || convertedType.isCompatibleWith(param))
return AUTOBOX_COMPATIBLE;
}
return NOT_COMPATIBLE;
}
示例3: computeCompatibleMethod
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; //导入方法依赖的package包/类
/**
* Internal use only
* 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, int inferenceLevel, boolean tiebreakingVarargsMethods)
{
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
CompilerOptions compilerOptions = this.compilerOptions();
// 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;
else // ensure that computeCompatibleMethod() below can update arguments without harming our caller: (TODO: always copy before the loop? only in 1.8?)
System.arraycopy(arguments, 0, arguments=new TypeBinding[argLength], 0, argLength);
method = ParameterizedGenericMethodBinding.computeCompatibleMethod(method, arguments, this, invocationSite, inferenceLevel);
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 (tiebreakingVarargsMethods) {
if (CompilerOptions.tolerateIllegalAmbiguousVarargsInvocation && compilerOptions.complianceLevel < ClassFileConstants.JDK1_7)
tiebreakingVarargsMethods = false;
}
if ((parameterCompatibilityLevel18(method, arguments, tiebreakingVarargsMethods, invocationSite)) > 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
}
示例4: isAcceptableMethod
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; //导入方法依赖的package包/类
protected boolean isAcceptableMethod(MethodBinding one, MethodBinding two) {
TypeBinding[] oneParams = one.parameters;
TypeBinding[] twoParams = two.parameters;
int oneParamsLength = oneParams.length;
int twoParamsLength = twoParams.length;
if (oneParamsLength == twoParamsLength) {
/* Below 1.5, discard any generics we have left in for the method verifier's benefit, (so it
can detect method overriding properly in the presence of generic super types.) This is so
as to allow us to determine whether we have been handed an acceptable method in 1.4 terms
without all the 1.5isms below kicking in and spoiling the party.
See https://bugs.eclipse.org/bugs/show_bug.cgi?id=331446
*/
boolean applyErasure = environment().globalOptions.sourceLevel < ClassFileConstants.JDK1_5;
next : for (int i = 0; i < oneParamsLength; i++) {
TypeBinding oneParam = applyErasure ? oneParams[i].erasure() : oneParams[i];
TypeBinding twoParam = applyErasure ? twoParams[i].erasure() : twoParams[i];
if (TypeBinding.equalsEquals(oneParam, twoParam) || oneParam.isCompatibleWith(twoParam)) {
if (two.declaringClass.isRawType()) continue next;
TypeBinding leafComponentType = two.original().parameters[i].leafComponentType();
TypeBinding originalTwoParam = applyErasure ? leafComponentType.erasure() : leafComponentType;
switch (originalTwoParam.kind()) {
case Binding.TYPE_PARAMETER :
if (((TypeVariableBinding) originalTwoParam).hasOnlyRawBounds())
continue next;
//$FALL-THROUGH$
case Binding.WILDCARD_TYPE :
case Binding.INTERSECTION_TYPE:
case Binding.PARAMETERIZED_TYPE :
TypeBinding originalOneParam = one.original().parameters[i].leafComponentType();
switch (originalOneParam.kind()) {
case Binding.TYPE :
case Binding.GENERIC_TYPE :
TypeBinding inheritedTwoParam = oneParam.findSuperTypeOriginatingFrom(twoParam);
if (inheritedTwoParam == null || !inheritedTwoParam.leafComponentType().isRawType()) break;
return false;
case Binding.TYPE_PARAMETER :
if (!((TypeVariableBinding) originalOneParam).upperBound().isRawType()) break;
return false;
case Binding.RAW_TYPE:
// originalOneParam is RAW so it cannot be more specific than a wildcard or parameterized type
return false;
}
}
} else {
if (i == oneParamsLength - 1 && one.isVarargs() && two.isVarargs()) {
TypeBinding oType = ((ArrayBinding) oneParam).elementsType();
TypeBinding eType = ((ArrayBinding) twoParam).elementsType();
if (CompilerOptions.tolerateIllegalAmbiguousVarargsInvocation && this.compilerOptions().complianceLevel < ClassFileConstants.JDK1_7) {
if (TypeBinding.equalsEquals(oneParam, eType) || oneParam.isCompatibleWith(eType))
return true; // special case to choose between 2 varargs methods when the last arg is Object[]
} else {
if (TypeBinding.equalsEquals(oType, eType) || oType.isCompatibleWith(eType))
return true; // special case to choose between 2 varargs methods when the last arg is Object[]
}
}
return false;
}
}
return true;
}
if (one.isVarargs() && two.isVarargs()) {
if (CompilerOptions.tolerateIllegalAmbiguousVarargsInvocation && this.compilerOptions().complianceLevel < ClassFileConstants.JDK1_7 &&
oneParamsLength > twoParamsLength) {
// special case when autoboxing makes (int, int...) better than (Object...) but not (int...) or (Integer, int...)
if (((ArrayBinding) twoParams[twoParamsLength - 1]).elementsType().id != TypeIds.T_JavaLangObject)
return false;
}
// check that each parameter before the vararg parameters are compatible (no autoboxing allowed here)
for (int i = (oneParamsLength > twoParamsLength ? twoParamsLength : oneParamsLength) - 2; i >= 0; i--)
if (TypeBinding.notEquals(oneParams[i], twoParams[i]) && !oneParams[i].isCompatibleWith(twoParams[i]))
return false;
if (parameterCompatibilityLevel(one, twoParams, true) == NOT_COMPATIBLE
&& parameterCompatibilityLevel(two, oneParams, true) == VARARGS_COMPATIBLE)
return true;
}
return false;
}
示例5: computeCompatibleMethod
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; //导入方法依赖的package包/类
/**
* Internal use only
* 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, boolean tiebreakingVarargsMethods) {
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
CompilerOptions compilerOptions = this.compilerOptions();
// 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);
}
}
int compatibilityLevel;
if (tiebreakingVarargsMethods) {
if (CompilerOptions.tolerateIllegalAmbiguousVarargsInvocation && compilerOptions.complianceLevel < ClassFileConstants.JDK1_7)
tiebreakingVarargsMethods = false;
}
if ((compatibilityLevel = parameterCompatibilityLevel(method, arguments, tiebreakingVarargsMethods)) > NOT_COMPATIBLE) {
if (compatibilityLevel == VARARGS_COMPATIBLE) {
TypeBinding varargsElementType = method.parameters[method.parameters.length - 1].leafComponentType();
if (varargsElementType instanceof ReferenceBinding) {
if (!((ReferenceBinding) varargsElementType).canBeSeenBy(this)) {
return new ProblemMethodBinding(method, method.selector, genericTypeArguments, ProblemReasons.VarargsElementTypeNotVisible);
}
}
}
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
}
示例6: isAcceptableMethod
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; //导入方法依赖的package包/类
protected boolean isAcceptableMethod(MethodBinding one, MethodBinding two) {
TypeBinding[] oneParams = one.parameters;
TypeBinding[] twoParams = two.parameters;
int oneParamsLength = oneParams.length;
int twoParamsLength = twoParams.length;
if (oneParamsLength == twoParamsLength) {
/* Below 1.5, discard any generics we have left in for the method verifier's benefit, (so it
can detect method overriding properly in the presence of generic super types.) This is so
as to allow us to determine whether we have been handed an acceptable method in 1.4 terms
without all the 1.5isms below kicking in and spoiling the party.
See https://bugs.eclipse.org/bugs/show_bug.cgi?id=331446
*/
boolean applyErasure = environment().globalOptions.sourceLevel < ClassFileConstants.JDK1_5;
next : for (int i = 0; i < oneParamsLength; i++) {
TypeBinding oneParam = applyErasure ? oneParams[i].erasure() : oneParams[i];
TypeBinding twoParam = applyErasure ? twoParams[i].erasure() : twoParams[i];
if (oneParam == twoParam || oneParam.isCompatibleWith(twoParam)) {
if (two.declaringClass.isRawType()) continue next;
TypeBinding leafComponentType = two.original().parameters[i].leafComponentType();
TypeBinding originalTwoParam = applyErasure ? leafComponentType.erasure() : leafComponentType;
switch (originalTwoParam.kind()) {
case Binding.TYPE_PARAMETER :
if (((TypeVariableBinding) originalTwoParam).hasOnlyRawBounds())
continue next;
//$FALL-THROUGH$
case Binding.WILDCARD_TYPE :
case Binding.INTERSECTION_TYPE:
case Binding.PARAMETERIZED_TYPE :
TypeBinding originalOneParam = one.original().parameters[i].leafComponentType();
switch (originalOneParam.kind()) {
case Binding.TYPE :
case Binding.GENERIC_TYPE :
TypeBinding inheritedTwoParam = oneParam.findSuperTypeOriginatingFrom(twoParam);
if (inheritedTwoParam == null || !inheritedTwoParam.leafComponentType().isRawType()) break;
return false;
case Binding.TYPE_PARAMETER :
if (!((TypeVariableBinding) originalOneParam).upperBound().isRawType()) break;
return false;
case Binding.RAW_TYPE:
// originalOneParam is RAW so it cannot be more specific than a wildcard or parameterized type
return false;
}
}
} else {
if (i == oneParamsLength - 1 && one.isVarargs() && two.isVarargs()) {
TypeBinding oType = ((ArrayBinding) oneParam).elementsType();
TypeBinding eType = ((ArrayBinding) twoParam).elementsType();
if (CompilerOptions.tolerateIllegalAmbiguousVarargsInvocation && this.compilerOptions().complianceLevel < ClassFileConstants.JDK1_7) {
if (oneParam == eType || oneParam.isCompatibleWith(eType))
return true; // special case to choose between 2 varargs methods when the last arg is Object[]
} else {
if (oType == eType || oType.isCompatibleWith(eType))
return true; // special case to choose between 2 varargs methods when the last arg is Object[]
}
}
return false;
}
}
return true;
}
if (one.isVarargs() && two.isVarargs()) {
if (CompilerOptions.tolerateIllegalAmbiguousVarargsInvocation && this.compilerOptions().complianceLevel < ClassFileConstants.JDK1_7 &&
oneParamsLength > twoParamsLength) {
// special case when autoboxing makes (int, int...) better than (Object...) but not (int...) or (Integer, int...)
if (((ArrayBinding) twoParams[twoParamsLength - 1]).elementsType().id != TypeIds.T_JavaLangObject)
return false;
}
// check that each parameter before the vararg parameters are compatible (no autoboxing allowed here)
for (int i = (oneParamsLength > twoParamsLength ? twoParamsLength : oneParamsLength) - 2; i >= 0; i--)
if (oneParams[i] != twoParams[i] && !oneParams[i].isCompatibleWith(twoParams[i]))
return false;
if (parameterCompatibilityLevel(one, twoParams, true) == NOT_COMPATIBLE
&& parameterCompatibilityLevel(two, oneParams, true) == VARARGS_COMPATIBLE)
return true;
}
return false;
}