Made AlternativeSignatureMismatchException unchecked to make code simpler. Got rid of catching and rethrowings.
This commit is contained in:
+52
-73
@@ -109,24 +109,16 @@ class AlternativeSignatureData {
|
|||||||
return altTypeParameters;
|
return altTypeParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JetType computeType(JetTypeElement alternativeTypeElement, final JetType autoType)
|
static JetType computeType(JetTypeElement alternativeTypeElement, final JetType autoType) {
|
||||||
throws AlternativeSignatureMismatchException {
|
return alternativeTypeElement.accept(new JetVisitor<JetType, Void>() {
|
||||||
final Ref<AlternativeSignatureMismatchException> exception = new Ref<AlternativeSignatureMismatchException>();
|
|
||||||
JetType result = alternativeTypeElement.accept(new JetVisitor<JetType, Void>() {
|
|
||||||
@Override
|
@Override
|
||||||
public JetType visitNullableType(JetNullableType nullableType, Void data) {
|
public JetType visitNullableType(JetNullableType nullableType, Void data) {
|
||||||
try {
|
if (!autoType.isNullable()) {
|
||||||
if (!autoType.isNullable()) {
|
throw new AlternativeSignatureMismatchException(String.format(
|
||||||
throw new AlternativeSignatureMismatchException(String.format(
|
"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));
|
|
||||||
}
|
|
||||||
catch (AlternativeSignatureMismatchException e) {
|
|
||||||
exception.set(e);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return TypeUtils.makeNullable(computeType(nullableType.getInnerType(), autoType));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -157,58 +149,52 @@ class AlternativeSignatureData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JetType visitCommonType(@NotNull String expectedFqNamePostfix, @NotNull JetTypeElement type) {
|
private JetType visitCommonType(@NotNull String expectedFqNamePostfix, @NotNull JetTypeElement type) {
|
||||||
try {
|
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(
|
||||||
throw new AlternativeSignatureMismatchException(String.format(
|
"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(
|
throw new AlternativeSignatureMismatchException(String.format(
|
||||||
"'%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(),
|
DescriptorRenderer.TEXT.renderType(autoType), arguments.size(),
|
||||||
type.getText(), type.getTypeArgumentsAsTypes().size()));
|
type.getText(), type.getTypeArgumentsAsTypes().size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<TypeProjection> altArguments = new ArrayList<TypeProjection>();
|
List<TypeProjection> altArguments = new ArrayList<TypeProjection>();
|
||||||
for (int i = 0, size = arguments.size(); i < size; i++) {
|
for (int i = 0, size = arguments.size(); i < size; i++) {
|
||||||
JetTypeElement argumentAlternativeTypeElement = type.getTypeArgumentsAsTypes().get(i).getTypeElement();
|
JetTypeElement argumentAlternativeTypeElement = type.getTypeArgumentsAsTypes().get(i).getTypeElement();
|
||||||
TypeProjection argument = arguments.get(i);
|
TypeProjection argument = arguments.get(i);
|
||||||
JetType alternativeType =
|
JetType alternativeType =
|
||||||
computeType(argumentAlternativeTypeElement, argument.getType());
|
computeType(argumentAlternativeTypeElement, argument.getType());
|
||||||
Variance variance = argument.getProjectionKind();
|
Variance variance = argument.getProjectionKind();
|
||||||
if (type instanceof JetUserType) {
|
if (type instanceof JetUserType) {
|
||||||
JetTypeProjection typeProjection = ((JetUserType) type).getTypeArguments().get(i);
|
JetTypeProjection typeProjection = ((JetUserType) type).getTypeArguments().get(i);
|
||||||
Variance altVariance = Variance.INVARIANT;
|
Variance altVariance = Variance.INVARIANT;
|
||||||
switch (typeProjection.getProjectionKind()) {
|
switch (typeProjection.getProjectionKind()) {
|
||||||
case IN:
|
case IN:
|
||||||
altVariance = Variance.IN_VARIANCE;
|
altVariance = Variance.IN_VARIANCE;
|
||||||
break;
|
break;
|
||||||
case OUT:
|
case OUT:
|
||||||
altVariance = Variance.OUT_VARIANCE;
|
altVariance = Variance.OUT_VARIANCE;
|
||||||
break;
|
break;
|
||||||
case STAR:
|
case STAR:
|
||||||
throw new AlternativeSignatureMismatchException(
|
throw new AlternativeSignatureMismatchException(
|
||||||
"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(
|
throw new AlternativeSignatureMismatchException(String.format(
|
||||||
"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));
|
|
||||||
}
|
}
|
||||||
return new JetTypeImpl(autoType.getAnnotations(), autoType.getConstructor(), false,
|
altArguments.add(new TypeProjection(variance, alternativeType));
|
||||||
altArguments, autoType.getMemberScope());
|
|
||||||
}
|
|
||||||
catch (AlternativeSignatureMismatchException e) {
|
|
||||||
exception.set(e);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return new JetTypeImpl(autoType.getAnnotations(), autoType.getConstructor(), false,
|
||||||
|
altArguments, autoType.getMemberScope());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -216,15 +202,9 @@ class AlternativeSignatureData {
|
|||||||
throw new UnsupportedOperationException("Self-types are not supported yet");
|
throw new UnsupportedOperationException("Self-types are not supported yet");
|
||||||
}
|
}
|
||||||
}, null);
|
}, null);
|
||||||
//noinspection ThrowableResultOfMethodCallIgnored
|
|
||||||
if (exception.get() != null) {
|
|
||||||
throw exception.get();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static JetType computeReturnType(@NotNull JetType autoType, @Nullable JetTypeReference altReturnTypeRef)
|
static JetType computeReturnType(@NotNull JetType autoType, @Nullable JetTypeReference altReturnTypeRef) {
|
||||||
throws AlternativeSignatureMismatchException {
|
|
||||||
JetType altReturnType;
|
JetType altReturnType;
|
||||||
if (altReturnTypeRef == null) {
|
if (altReturnTypeRef == null) {
|
||||||
if (JetStandardClasses.isUnit(autoType)) {
|
if (JetStandardClasses.isUnit(autoType)) {
|
||||||
@@ -245,7 +225,7 @@ class AlternativeSignatureData {
|
|||||||
|
|
||||||
static JavaDescriptorResolver.ValueParameterDescriptors computeValueParameters(
|
static JavaDescriptorResolver.ValueParameterDescriptors computeValueParameters(
|
||||||
JavaDescriptorResolver.ValueParameterDescriptors valueParameterDescriptors,
|
JavaDescriptorResolver.ValueParameterDescriptors valueParameterDescriptors,
|
||||||
JetNamedFunction altFunDeclaration) throws AlternativeSignatureMismatchException {
|
JetNamedFunction altFunDeclaration) {
|
||||||
List<ValueParameterDescriptor> parameterDescriptors = valueParameterDescriptors.descriptors;
|
List<ValueParameterDescriptor> parameterDescriptors = valueParameterDescriptors.descriptors;
|
||||||
|
|
||||||
if (parameterDescriptors.size() != altFunDeclaration.getValueParameters().size()) {
|
if (parameterDescriptors.size() != altFunDeclaration.getValueParameters().size()) {
|
||||||
@@ -290,7 +270,7 @@ class AlternativeSignatureData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static List<TypeParameterDescriptor> computeTypeParameters(List<TypeParameterDescriptor> typeParameterDescriptors,
|
static List<TypeParameterDescriptor> computeTypeParameters(List<TypeParameterDescriptor> typeParameterDescriptors,
|
||||||
JetNamedFunction altFunDeclaration) throws AlternativeSignatureMismatchException {
|
JetNamedFunction altFunDeclaration) {
|
||||||
if (typeParameterDescriptors.size() != altFunDeclaration.getTypeParameters().size()) {
|
if (typeParameterDescriptors.size() != altFunDeclaration.getTypeParameters().size()) {
|
||||||
throw new AlternativeSignatureMismatchException(
|
throw new AlternativeSignatureMismatchException(
|
||||||
String.format("Method signature has %d type parameters, but alternative signature has %d",
|
String.format("Method signature has %d type parameters, but alternative signature has %d",
|
||||||
@@ -349,8 +329,7 @@ class AlternativeSignatureData {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void checkForSyntaxErrors(PsiMethodWrapper method, JetNamedFunction altFunDeclaration)
|
static void checkForSyntaxErrors(PsiMethodWrapper method, JetNamedFunction altFunDeclaration) {
|
||||||
throws AlternativeSignatureMismatchException {
|
|
||||||
List<PsiErrorElement> syntaxErrors = AnalyzingUtils.getSyntaxErrorRanges(altFunDeclaration);
|
List<PsiErrorElement> syntaxErrors = AnalyzingUtils.getSyntaxErrorRanges(altFunDeclaration);
|
||||||
if (!syntaxErrors.isEmpty()) {
|
if (!syntaxErrors.isEmpty()) {
|
||||||
String textSignature = String.format("%s(%s)", method.getName(),
|
String textSignature = String.format("%s(%s)", method.getName(),
|
||||||
@@ -379,7 +358,7 @@ class AlternativeSignatureData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class AlternativeSignatureMismatchException extends Exception {
|
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