Made AlternativeSignatureMismatchException unchecked to make code simpler. Got rid of catching and rethrowings.
This commit is contained in:
+7
-28
@@ -109,13 +109,10 @@ 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'",
|
||||||
@@ -123,11 +120,6 @@ class AlternativeSignatureData {
|
|||||||
}
|
}
|
||||||
return TypeUtils.makeNullable(computeType(nullableType.getInnerType(), autoType));
|
return TypeUtils.makeNullable(computeType(nullableType.getInnerType(), autoType));
|
||||||
}
|
}
|
||||||
catch (AlternativeSignatureMismatchException e) {
|
|
||||||
exception.set(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetType visitFunctionType(JetFunctionType type, Void data) {
|
public JetType visitFunctionType(JetFunctionType type, Void data) {
|
||||||
@@ -157,7 +149,6 @@ 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(
|
||||||
@@ -205,26 +196,15 @@ class AlternativeSignatureData {
|
|||||||
return new JetTypeImpl(autoType.getAnnotations(), autoType.getConstructor(), false,
|
return new JetTypeImpl(autoType.getAnnotations(), autoType.getConstructor(), false,
|
||||||
altArguments, autoType.getMemberScope());
|
altArguments, autoType.getMemberScope());
|
||||||
}
|
}
|
||||||
catch (AlternativeSignatureMismatchException e) {
|
|
||||||
exception.set(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetType visitSelfType(JetSelfType type, Void data) {
|
public JetType visitSelfType(JetSelfType type, Void data) {
|
||||||
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