Got rid of warnings in AlternativeSignatureData.

This commit is contained in:
Evgeny Gerashchenko
2012-06-21 18:32:36 +04:00
parent 9044ec775f
commit e59120f002
@@ -114,6 +114,7 @@ class AlternativeSignatureData {
} }
static JetType computeType(JetTypeElement alternativeTypeElement, final JetType autoType) { static JetType computeType(JetTypeElement alternativeTypeElement, final JetType autoType) {
//noinspection NullableProblems
return alternativeTypeElement.accept(new JetVisitor<JetType, Void>() { return alternativeTypeElement.accept(new JetVisitor<JetType, Void>() {
@Override @Override
public JetType visitNullableType(JetNullableType nullableType, Void data) { public JetType visitNullableType(JetNullableType nullableType, Void data) {
@@ -139,6 +140,7 @@ class AlternativeSignatureData {
@Override @Override
public JetType visitUserType(JetUserType type, Void data) { public JetType visitUserType(JetUserType type, Void data) {
JetUserType qualifier = type.getQualifier(); JetUserType qualifier = type.getQualifier();
//noinspection ConstantConditions
String shortName = type.getReferenceExpression().getReferencedName(); String shortName = type.getReferenceExpression().getReferencedName();
String longName = (qualifier == null ? "" : qualifier.getText() + ".") + shortName; String longName = (qualifier == null ? "" : qualifier.getText() + ".") + shortName;
if (JetStandardClasses.UNIT_ALIAS.getName().equals(longName)) { if (JetStandardClasses.UNIT_ALIAS.getName().equals(longName)) {
@@ -152,7 +154,9 @@ 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(); ClassifierDescriptor declarationDescriptor = autoType.getConstructor().getDeclarationDescriptor();
assert declarationDescriptor != null;
String fqName = DescriptorUtils.getFQName(declarationDescriptor).toSafe().getFqName();
if (!fqName.endsWith(expectedFqNamePostfix)) { if (!fqName.endsWith(expectedFqNamePostfix)) {
fail("Alternative signature type mismatch, expected: %s, actual: %s", expectedFqNamePostfix, fqName); fail("Alternative signature type mismatch, expected: %s, actual: %s", expectedFqNamePostfix, fqName);
} }
@@ -232,6 +236,7 @@ class AlternativeSignatureData {
for (int i = 0, size = parameterDescriptors.size(); i < size; i++) { for (int i = 0, size = parameterDescriptors.size(); i < size; i++) {
ValueParameterDescriptor pd = parameterDescriptors.get(i); ValueParameterDescriptor pd = parameterDescriptors.get(i);
JetParameter valueParameter = altFunDeclaration.getValueParameters().get(i); JetParameter valueParameter = altFunDeclaration.getValueParameters().get(i);
//noinspection ConstantConditions
JetTypeElement alternativeTypeElement = valueParameter.getTypeReference().getTypeElement(); JetTypeElement alternativeTypeElement = valueParameter.getTypeReference().getTypeElement();
JetType alternativeType; JetType alternativeType;
JetType alternativeVarargElementType; JetType alternativeVarargElementType;
@@ -253,12 +258,10 @@ class AlternativeSignatureData {
pd.getName(), pd.isVar(), alternativeType, pd.declaresDefaultValue(), pd.getName(), pd.isVar(), alternativeType, pd.declaresDefaultValue(),
alternativeVarargElementType)); alternativeVarargElementType));
} }
JetType altReceiverType = null;
if (valueParameterDescriptors.receiverType != null) { if (valueParameterDescriptors.receiverType != null) {
altReceiverType = computeType(altFunDeclaration.getReceiverTypeRef().getTypeElement(), throw new UnsupportedOperationException("Alternative annotations for extension functions are not supported yet");
valueParameterDescriptors.receiverType);
} }
altValueParameters = new JavaDescriptorResolver.ValueParameterDescriptors(altReceiverType, altParamDescriptors); altValueParameters = new JavaDescriptorResolver.ValueParameterDescriptors(null, altParamDescriptors);
} }
private void computeTypeParameters(List<TypeParameterDescriptor> typeParameters) { private void computeTypeParameters(List<TypeParameterDescriptor> typeParameters) {
@@ -272,7 +275,6 @@ class AlternativeSignatureData {
for (int i = 0, size = typeParameters.size(); i < size; i++) { for (int i = 0, size = typeParameters.size(); i < size; i++) {
TypeParameterDescriptor pd = typeParameters.get(i); TypeParameterDescriptor pd = typeParameters.get(i);
DeclarationDescriptor containingDeclaration = pd.getContainingDeclaration(); DeclarationDescriptor containingDeclaration = pd.getContainingDeclaration();
assert containingDeclaration != null;
TypeParameterDescriptorImpl altParamDescriptor = TypeParameterDescriptorImpl TypeParameterDescriptorImpl altParamDescriptor = TypeParameterDescriptorImpl
.createForFurtherModification(containingDeclaration, pd.getAnnotations(), .createForFurtherModification(containingDeclaration, pd.getAnnotations(),
pd.isReified(), pd.getVariance(), pd.getName(), pd.getIndex()); pd.isReified(), pd.getVariance(), pd.getName(), pd.getIndex());
@@ -292,8 +294,12 @@ class AlternativeSignatureData {
} }
} }
else { else {
altTypeElement = findTypeParameterConstraint(altFunDeclaration, parameter.getNameAsName(), upperBoundIndex) JetTypeConstraint constraint =
.getBoundTypeReference().getTypeElement(); findTypeParameterConstraint(altFunDeclaration, pd.getName(), upperBoundIndex);
assert constraint != null; // TODO fail more properly
JetTypeReference boundTypeReference = constraint.getBoundTypeReference();
assert boundTypeReference != null;
altTypeElement = boundTypeReference.getTypeElement();
} }
altParamDescriptor.addUpperBound(computeType(altTypeElement, upperBound)); altParamDescriptor.addUpperBound(computeType(altTypeElement, upperBound));
upperBoundIndex++; upperBoundIndex++;
@@ -310,7 +316,9 @@ class AlternativeSignatureData {
if (index != 0) { if (index != 0) {
int currentIndex = 0; int currentIndex = 0;
for (JetTypeConstraint constraint : function.getTypeConstraints()) { for (JetTypeConstraint constraint : function.getTypeConstraints()) {
if (typeParameterName.equals(constraint.getSubjectTypeParameterName().getReferencedNameAsName())) { JetSimpleNameExpression parameterName = constraint.getSubjectTypeParameterName();
assert parameterName != null;
if (typeParameterName.equals(parameterName.getReferencedNameAsName())) {
currentIndex++; currentIndex++;
} }
if (currentIndex == index) { if (currentIndex == index) {