Introduced AlternativeSignatureData.fail() method throwing exception.
This commit is contained in:
+28
-35
@@ -118,9 +118,8 @@ class AlternativeSignatureData {
|
|||||||
@Override
|
@Override
|
||||||
public JetType visitNullableType(JetNullableType nullableType, Void data) {
|
public JetType visitNullableType(JetNullableType nullableType, Void data) {
|
||||||
if (!autoType.isNullable()) {
|
if (!autoType.isNullable()) {
|
||||||
throw new AlternativeSignatureMismatchException(String.format(
|
fail("Auto type '%s' is not-null, while type in alternative signature is nullable: '%s'",
|
||||||
"Auto type '%s' is not-null, while type in alternative signature is nullable: '%s'",
|
DescriptorRenderer.TEXT.renderType(autoType), nullableType.getText());
|
||||||
DescriptorRenderer.TEXT.renderType(autoType), nullableType.getText()));
|
|
||||||
}
|
}
|
||||||
return TypeUtils.makeNullable(computeType(nullableType.getInnerType(), autoType));
|
return TypeUtils.makeNullable(computeType(nullableType.getInnerType(), autoType));
|
||||||
}
|
}
|
||||||
@@ -155,17 +154,14 @@ class AlternativeSignatureData {
|
|||||||
private JetType visitCommonType(@NotNull String expectedFqNamePostfix, @NotNull JetTypeElement type) {
|
private JetType visitCommonType(@NotNull String expectedFqNamePostfix, @NotNull JetTypeElement type) {
|
||||||
String fqName = DescriptorUtils.getFQName(autoType.getConstructor().getDeclarationDescriptor()).toSafe().getFqName();
|
String fqName = DescriptorUtils.getFQName(autoType.getConstructor().getDeclarationDescriptor()).toSafe().getFqName();
|
||||||
if (!fqName.endsWith(expectedFqNamePostfix)) {
|
if (!fqName.endsWith(expectedFqNamePostfix)) {
|
||||||
throw new AlternativeSignatureMismatchException(String.format(
|
fail("Alternative signature type mismatch, expected: %s, actual: %s", expectedFqNamePostfix, fqName);
|
||||||
"Alternative signature type mismatch, expected: %s, actual: %s", expectedFqNamePostfix, fqName));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<TypeProjection> arguments = autoType.getArguments();
|
List<TypeProjection> arguments = autoType.getArguments();
|
||||||
|
|
||||||
if (arguments.size() != type.getTypeArgumentsAsTypes().size()) {
|
if (arguments.size() != type.getTypeArgumentsAsTypes().size()) {
|
||||||
throw new AlternativeSignatureMismatchException(String.format(
|
fail("'%s' type in method signature has %d type arguments, while '%s' in alternative signature has %d of them",
|
||||||
"'%s' type in method signature has %d type arguments, while '%s' in alternative signature has %d of them",
|
DescriptorRenderer.TEXT.renderType(autoType), arguments.size(), type.getText(), type.getTypeArgumentsAsTypes().size());
|
||||||
DescriptorRenderer.TEXT.renderType(autoType), arguments.size(),
|
|
||||||
type.getText(), type.getTypeArgumentsAsTypes().size()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<TypeProjection> altArguments = new ArrayList<TypeProjection>();
|
List<TypeProjection> altArguments = new ArrayList<TypeProjection>();
|
||||||
@@ -186,13 +182,11 @@ class AlternativeSignatureData {
|
|||||||
altVariance = Variance.OUT_VARIANCE;
|
altVariance = Variance.OUT_VARIANCE;
|
||||||
break;
|
break;
|
||||||
case STAR:
|
case STAR:
|
||||||
throw new AlternativeSignatureMismatchException(
|
fail("Star projection is not available in alternative signatures");
|
||||||
"Star projection is not available in alternative signatures");
|
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
if (altVariance != variance) {
|
if (altVariance != variance) {
|
||||||
throw new AlternativeSignatureMismatchException(String.format(
|
fail("Variance mismatch, actual: %s, in alternative signature: %s", variance, altVariance);
|
||||||
"Variance mismatch, actual: %s, in alternative signature: %s", variance, altVariance));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
altArguments.add(new TypeProjection(variance, alternativeType));
|
altArguments.add(new TypeProjection(variance, alternativeType));
|
||||||
@@ -215,9 +209,8 @@ class AlternativeSignatureData {
|
|||||||
altReturnType = autoType;
|
altReturnType = autoType;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new AlternativeSignatureMismatchException(String.format(
|
fail("Return type in alternative signature is missing, while in real signature it is '%s'",
|
||||||
"Return type in alternative signature is missing, while in real signature it is '%s'",
|
DescriptorRenderer.TEXT.renderType(autoType));
|
||||||
DescriptorRenderer.TEXT.renderType(autoType)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -230,9 +223,8 @@ class AlternativeSignatureData {
|
|||||||
List<ValueParameterDescriptor> parameterDescriptors = valueParameterDescriptors.descriptors;
|
List<ValueParameterDescriptor> parameterDescriptors = valueParameterDescriptors.descriptors;
|
||||||
|
|
||||||
if (parameterDescriptors.size() != altFunDeclaration.getValueParameters().size()) {
|
if (parameterDescriptors.size() != altFunDeclaration.getValueParameters().size()) {
|
||||||
throw new AlternativeSignatureMismatchException(
|
fail("Method signature has %d value parameters, but alternative signature has %d",
|
||||||
String.format("Method signature has %d value parameters, but alternative signature has %d",
|
parameterDescriptors.size(), altFunDeclaration.getValueParameters().size());
|
||||||
parameterDescriptors.size(), altFunDeclaration.getValueParameters().size()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ValueParameterDescriptor> altParamDescriptors = new ArrayList<ValueParameterDescriptor>();
|
List<ValueParameterDescriptor> altParamDescriptors = new ArrayList<ValueParameterDescriptor>();
|
||||||
@@ -244,16 +236,14 @@ class AlternativeSignatureData {
|
|||||||
JetType alternativeVarargElementType;
|
JetType alternativeVarargElementType;
|
||||||
if (pd.getVarargElementType() == null) {
|
if (pd.getVarargElementType() == null) {
|
||||||
if (valueParameter.isVarArg()) {
|
if (valueParameter.isVarArg()) {
|
||||||
throw new AlternativeSignatureMismatchException(
|
fail("Parameter in method signature is not vararg, but in alternative signature it is vararg");
|
||||||
"Parameter in method signature is not vararg, but in alternative signature it is vararg");
|
|
||||||
}
|
}
|
||||||
alternativeType = computeType(alternativeTypeElement, pd.getType());
|
alternativeType = computeType(alternativeTypeElement, pd.getType());
|
||||||
alternativeVarargElementType = null;
|
alternativeVarargElementType = null;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!valueParameter.isVarArg()) {
|
if (!valueParameter.isVarArg()) {
|
||||||
throw new AlternativeSignatureMismatchException(
|
fail("Parameter in method signature is vararg, but in alternative signature it is not");
|
||||||
"Parameter in method signature is vararg, but in alternative signature it is not");
|
|
||||||
}
|
}
|
||||||
alternativeVarargElementType = computeType(alternativeTypeElement, pd.getVarargElementType());
|
alternativeVarargElementType = computeType(alternativeTypeElement, pd.getVarargElementType());
|
||||||
alternativeType = JetStandardLibrary.getInstance().getArrayType(alternativeVarargElementType);
|
alternativeType = JetStandardLibrary.getInstance().getArrayType(alternativeVarargElementType);
|
||||||
@@ -273,9 +263,8 @@ class AlternativeSignatureData {
|
|||||||
private void computeTypeParameters(List<TypeParameterDescriptor> typeParameters) {
|
private void computeTypeParameters(List<TypeParameterDescriptor> typeParameters) {
|
||||||
|
|
||||||
if (typeParameters.size() != altFunDeclaration.getTypeParameters().size()) {
|
if (typeParameters.size() != altFunDeclaration.getTypeParameters().size()) {
|
||||||
throw new AlternativeSignatureMismatchException(
|
fail("Method signature has %d type parameters, but alternative signature has %d",
|
||||||
String.format("Method signature has %d type parameters, but alternative signature has %d",
|
typeParameters.size(), altFunDeclaration.getTypeParameters().size());
|
||||||
typeParameters.size(), altFunDeclaration.getTypeParameters().size()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
altTypeParameters = new ArrayList<TypeParameterDescriptor>();
|
altTypeParameters = new ArrayList<TypeParameterDescriptor>();
|
||||||
@@ -343,21 +332,25 @@ class AlternativeSignatureData {
|
|||||||
int errorOffset = syntaxErrors.get(0).getTextOffset();
|
int errorOffset = syntaxErrors.get(0).getTextOffset();
|
||||||
String syntaxErrorDescription = syntaxErrors.get(0).getErrorDescription();
|
String syntaxErrorDescription = syntaxErrors.get(0).getErrorDescription();
|
||||||
|
|
||||||
String errorText = syntaxErrors.size() == 1
|
if (syntaxErrors.size() == 1) {
|
||||||
? String.format("Alternative signature for %s has syntax error at %d: %s", textSignature,
|
fail("Alternative signature for %s has syntax error at %d: %s",
|
||||||
errorOffset, syntaxErrorDescription)
|
textSignature, errorOffset, syntaxErrorDescription);
|
||||||
: String.format("Alternative signature for %s has %d syntax errors, first is at %d: %s", textSignature,
|
}
|
||||||
syntaxErrors.size(), errorOffset, syntaxErrorDescription);
|
else {
|
||||||
throw new AlternativeSignatureMismatchException(errorText);
|
fail("Alternative signature for %s has %d syntax errors, first is at %d: %s",
|
||||||
|
textSignature, syntaxErrors.size(), errorOffset, syntaxErrorDescription);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ComparatorUtil.equalsNullable(method.getName(), altFunDeclaration.getName())) {
|
if (!ComparatorUtil.equalsNullable(method.getName(), altFunDeclaration.getName())) {
|
||||||
throw new AlternativeSignatureMismatchException(String.format(
|
fail("Function names mismatch, original: %s, alternative: %s", method.getName(), altFunDeclaration.getName());
|
||||||
"Function names mismatch, original: %s, alternative: %s",
|
|
||||||
method.getName(), altFunDeclaration.getName()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void fail(String format, Object... params) {
|
||||||
|
throw new AlternativeSignatureMismatchException(String.format(format, params));
|
||||||
|
}
|
||||||
|
|
||||||
private static class AlternativeSignatureMismatchException extends RuntimeException {
|
private static class AlternativeSignatureMismatchException extends RuntimeException {
|
||||||
private AlternativeSignatureMismatchException(String message) {
|
private AlternativeSignatureMismatchException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
|
|||||||
Reference in New Issue
Block a user