Renamed methods in AlternativeSignatureParsing, simplifying them.

This commit is contained in:
Evgeny Gerashchenko
2012-06-21 17:16:31 +04:00
parent 2840f6d3ba
commit c427a3b7aa
2 changed files with 17 additions and 18 deletions
@@ -43,7 +43,7 @@ import java.util.List;
* @since 6/5/12 * @since 6/5/12
*/ */
class AlternativeSignatureParsing { class AlternativeSignatureParsing {
static JetType computeAlternativeTypeFromAnnotation(JetTypeElement alternativeTypeElement, final JetType autoType) static JetType computeType(JetTypeElement alternativeTypeElement, final JetType autoType)
throws AlternativeSignatureMismatchException { throws AlternativeSignatureMismatchException {
final Ref<AlternativeSignatureMismatchException> exception = new Ref<AlternativeSignatureMismatchException>(); final Ref<AlternativeSignatureMismatchException> exception = new Ref<AlternativeSignatureMismatchException>();
JetType result = alternativeTypeElement.accept(new JetVisitor<JetType, Void>() { JetType result = alternativeTypeElement.accept(new JetVisitor<JetType, Void>() {
@@ -55,7 +55,7 @@ class AlternativeSignatureParsing {
"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(computeAlternativeTypeFromAnnotation(nullableType.getInnerType(), autoType)); return TypeUtils.makeNullable(computeType(nullableType.getInnerType(), autoType));
} }
catch (AlternativeSignatureMismatchException e) { catch (AlternativeSignatureMismatchException e) {
exception.set(e); exception.set(e);
@@ -112,7 +112,7 @@ class AlternativeSignatureParsing {
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 =
computeAlternativeTypeFromAnnotation(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);
@@ -157,7 +157,7 @@ class AlternativeSignatureParsing {
return result; return result;
} }
static JetType computeAlternativeReturnType(@NotNull JetType autoType, @Nullable JetTypeReference altReturnTypeRef) static JetType computeReturnType(@NotNull JetType autoType, @Nullable JetTypeReference altReturnTypeRef)
throws AlternativeSignatureMismatchException { throws AlternativeSignatureMismatchException {
JetType altReturnType; JetType altReturnType;
if (altReturnTypeRef == null) { if (altReturnTypeRef == null) {
@@ -171,13 +171,13 @@ class AlternativeSignatureParsing {
} }
} }
else { else {
altReturnType = computeAlternativeTypeFromAnnotation(altReturnTypeRef.getTypeElement(), altReturnType = computeType(altReturnTypeRef.getTypeElement(),
autoType); autoType);
} }
return altReturnType; return altReturnType;
} }
static JavaDescriptorResolver.ValueParameterDescriptors computeAlternativeValueParameters( static JavaDescriptorResolver.ValueParameterDescriptors computeValueParameters(
JavaDescriptorResolver.ValueParameterDescriptors valueParameterDescriptors, JavaDescriptorResolver.ValueParameterDescriptors valueParameterDescriptors,
JetNamedFunction altFunDeclaration) throws AlternativeSignatureMismatchException { JetNamedFunction altFunDeclaration) throws AlternativeSignatureMismatchException {
List<ValueParameterDescriptor> parameterDescriptors = valueParameterDescriptors.descriptors; List<ValueParameterDescriptor> parameterDescriptors = valueParameterDescriptors.descriptors;
@@ -200,7 +200,7 @@ class AlternativeSignatureParsing {
throw new AlternativeSignatureMismatchException( throw new AlternativeSignatureMismatchException(
"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 = computeAlternativeTypeFromAnnotation(alternativeTypeElement, pd.getType()); alternativeType = computeType(alternativeTypeElement, pd.getType());
alternativeVarargElementType = null; alternativeVarargElementType = null;
} }
else { else {
@@ -208,7 +208,7 @@ class AlternativeSignatureParsing {
throw new AlternativeSignatureMismatchException( throw new AlternativeSignatureMismatchException(
"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 = computeAlternativeTypeFromAnnotation(alternativeTypeElement, pd.getVarargElementType()); alternativeVarargElementType = computeType(alternativeTypeElement, pd.getVarargElementType());
alternativeType = JetStandardLibrary.getInstance().getArrayType(alternativeVarargElementType); alternativeType = JetStandardLibrary.getInstance().getArrayType(alternativeVarargElementType);
} }
altParamDescriptors.add(new ValueParameterDescriptorImpl(pd.getContainingDeclaration(), pd.getIndex(), pd.getAnnotations(), altParamDescriptors.add(new ValueParameterDescriptorImpl(pd.getContainingDeclaration(), pd.getIndex(), pd.getAnnotations(),
@@ -217,13 +217,13 @@ class AlternativeSignatureParsing {
} }
JetType altReceiverType = null; JetType altReceiverType = null;
if (valueParameterDescriptors.receiverType != null) { if (valueParameterDescriptors.receiverType != null) {
altReceiverType = computeAlternativeTypeFromAnnotation(altFunDeclaration.getReceiverTypeRef().getTypeElement(), altReceiverType = computeType(altFunDeclaration.getReceiverTypeRef().getTypeElement(),
valueParameterDescriptors.receiverType); valueParameterDescriptors.receiverType);
} }
return new JavaDescriptorResolver.ValueParameterDescriptors(altReceiverType, altParamDescriptors); return new JavaDescriptorResolver.ValueParameterDescriptors(altReceiverType, altParamDescriptors);
} }
static List<TypeParameterDescriptor> computeAlternativeTypeParameters(List<TypeParameterDescriptor> typeParameterDescriptors, static List<TypeParameterDescriptor> computeTypeParameters(List<TypeParameterDescriptor> typeParameterDescriptors,
JetNamedFunction altFunDeclaration) throws AlternativeSignatureMismatchException { JetNamedFunction altFunDeclaration) throws AlternativeSignatureMismatchException {
if (typeParameterDescriptors.size() != altFunDeclaration.getTypeParameters().size()) { if (typeParameterDescriptors.size() != altFunDeclaration.getTypeParameters().size()) {
throw new AlternativeSignatureMismatchException( throw new AlternativeSignatureMismatchException(
@@ -257,7 +257,7 @@ class AlternativeSignatureParsing {
else { else {
altTypeElement = findTypeParameterConstraint(altFunDeclaration, parameter.getNameAsName(), upperBoundIndex).getBoundTypeReference().getTypeElement(); altTypeElement = findTypeParameterConstraint(altFunDeclaration, parameter.getNameAsName(), upperBoundIndex).getBoundTypeReference().getTypeElement();
} }
altParamDescriptor.addUpperBound(computeAlternativeTypeFromAnnotation(altTypeElement, upperBound)); altParamDescriptor.addUpperBound(computeType(altTypeElement, upperBound));
upperBoundIndex++; upperBoundIndex++;
} }
@@ -30,7 +30,6 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.JetNamedFunction; import org.jetbrains.jet.lang.psi.JetNamedFunction;
import org.jetbrains.jet.lang.psi.JetPsiFactory; import org.jetbrains.jet.lang.psi.JetPsiFactory;
import org.jetbrains.jet.lang.psi.JetPsiUtil; import org.jetbrains.jet.lang.psi.JetPsiUtil;
import org.jetbrains.jet.lang.psi.JetTypeReference;
import org.jetbrains.jet.lang.resolve.*; import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.constants.*; import org.jetbrains.jet.lang.resolve.constants.*;
import org.jetbrains.jet.lang.resolve.constants.StringValue; import org.jetbrains.jet.lang.resolve.constants.StringValue;
@@ -1399,11 +1398,11 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
AlternativeSignatureParsing.checkForSyntaxErrors(method, altFunDeclaration); AlternativeSignatureParsing.checkForSyntaxErrors(method, altFunDeclaration);
ValueParameterDescriptors altValueParameters = AlternativeSignatureParsing ValueParameterDescriptors altValueParameters = AlternativeSignatureParsing
.computeAlternativeValueParameters(valueParameterDescriptors, altFunDeclaration); .computeValueParameters(valueParameterDescriptors, altFunDeclaration);
JetType altReturnType = AlternativeSignatureParsing.computeAlternativeReturnType(returnType, JetType altReturnType = AlternativeSignatureParsing.computeReturnType(returnType,
altFunDeclaration.getReturnTypeRef()); altFunDeclaration.getReturnTypeRef());
List<TypeParameterDescriptor> altTypeParameters = AlternativeSignatureParsing List<TypeParameterDescriptor> altTypeParameters = AlternativeSignatureParsing
.computeAlternativeTypeParameters(methodTypeParameters, altFunDeclaration); .computeTypeParameters(methodTypeParameters, altFunDeclaration);
// if no exceptions were thrown, save alternative data // if no exceptions were thrown, save alternative data
valueParameterDescriptors = altValueParameters; valueParameterDescriptors = altValueParameters;
returnType = altReturnType; returnType = altReturnType;