From fa34ebac4a6f8240088960831ee7a200efacab65 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 13 Nov 2015 22:51:00 +0300 Subject: [PATCH] Delete KotlinSignature and corresponding code --- .../TraceBasedExternalSignatureResolver.java | 75 +---- .../AlternativeFieldSignatureData.java | 89 ----- .../AlternativeMethodSignatureData.java | 317 ------------------ ...AlternativeSignatureMismatchException.java | 27 -- .../ElementAlternativeSignatureData.java | 109 ------ .../jvm/kotlinSignature/SignaturesUtil.java | 55 --- .../TypeTransformingVisitor.java | 235 ------------- .../kotlin/load/java/JvmAnnotationNames.java | 9 +- .../components/ExternalSignatureResolver.java | 109 +----- .../descriptors/LazyJavaClassMemberScope.kt | 23 +- .../java/lazy/descriptors/LazyJavaScope.kt | 8 +- .../lazy/descriptors/LazyJavaStaticScope.kt | 6 +- .../jet/runtime/typeinfo/KotlinSignature.java | 29 -- .../src/kotlin/jvm/KotlinSignature.java | 29 -- 14 files changed, 29 insertions(+), 1091 deletions(-) delete mode 100644 compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/AlternativeFieldSignatureData.java delete mode 100644 compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/AlternativeMethodSignatureData.java delete mode 100644 compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/AlternativeSignatureMismatchException.java delete mode 100644 compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/ElementAlternativeSignatureData.java delete mode 100644 compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/SignaturesUtil.java delete mode 100644 compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/TypeTransformingVisitor.java delete mode 100644 core/runtime.jvm/src/jet/runtime/typeinfo/KotlinSignature.java delete mode 100644 core/runtime.jvm/src/kotlin/jvm/KotlinSignature.java diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/components/TraceBasedExternalSignatureResolver.java b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/components/TraceBasedExternalSignatureResolver.java index 4431f27d76f..1fc5646731b 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/components/TraceBasedExternalSignatureResolver.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/components/TraceBasedExternalSignatureResolver.java @@ -16,7 +16,6 @@ package org.jetbrains.kotlin.load.java.components; -import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor; @@ -24,35 +23,23 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor; import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor; import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor; import org.jetbrains.kotlin.load.java.JavaBindingContext; -import org.jetbrains.kotlin.load.java.structure.JavaConstructor; -import org.jetbrains.kotlin.load.java.structure.JavaField; -import org.jetbrains.kotlin.load.java.structure.JavaMember; import org.jetbrains.kotlin.load.java.structure.JavaMethod; import org.jetbrains.kotlin.resolve.BindingTrace; -import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolverKt; -import org.jetbrains.kotlin.resolve.jvm.kotlinSignature.AlternativeFieldSignatureData; -import org.jetbrains.kotlin.resolve.jvm.kotlinSignature.AlternativeMethodSignatureData; import org.jetbrains.kotlin.resolve.jvm.kotlinSignature.SignaturesPropagationData; import org.jetbrains.kotlin.types.KotlinType; -import java.util.Collections; import java.util.List; public class TraceBasedExternalSignatureResolver implements ExternalSignatureResolver { - @NotNull private final BindingTrace trace; - @NotNull private final Project project; + private final BindingTrace trace; - public TraceBasedExternalSignatureResolver( - @NotNull Project project, - @NotNull BindingTrace trace - ) { - this.project = project; + public TraceBasedExternalSignatureResolver(@NotNull BindingTrace trace) { this.trace = trace; } @Override @NotNull - public PropagatedMethodSignature resolvePropagatedSignature( + public AlternativeMethodSignature resolvePropagatedSignature( @NotNull JavaMethod method, @NotNull ClassDescriptor owner, @NotNull KotlinType returnType, @@ -62,60 +49,10 @@ public class TraceBasedExternalSignatureResolver implements ExternalSignatureRes ) { SignaturesPropagationData data = new SignaturesPropagationData(owner, returnType, receiverType, valueParameters, typeParameters, method); - return new PropagatedMethodSignature(data.getModifiedReturnType(), data.getModifiedReceiverType(), - data.getModifiedValueParameters(), data.getModifiedTypeParameters(), data.getSignatureErrors(), - data.getModifiedHasStableParameterNames(), data.getSuperFunctions()); - } - - @Override - @NotNull - public AlternativeMethodSignature resolveAlternativeMethodSignature( - @NotNull JavaMember methodOrConstructor, - boolean hasSuperMethods, - @Nullable KotlinType returnType, - @Nullable KotlinType receiverType, - @NotNull List valueParameters, - @NotNull List typeParameters, - boolean hasStableParameterNames - ) { - assert methodOrConstructor instanceof JavaMethod || methodOrConstructor instanceof JavaConstructor : - "Not a method or a constructor: " + methodOrConstructor.getName(); - - AlternativeMethodSignatureData data = new AlternativeMethodSignatureData( - methodOrConstructor, receiverType, project, valueParameters, returnType, typeParameters, hasSuperMethods + return new AlternativeMethodSignature( + data.getModifiedReturnType(), data.getModifiedReceiverType(), data.getModifiedValueParameters(), + data.getModifiedTypeParameters(), data.getSignatureErrors(), data.getModifiedHasStableParameterNames() ); - - if (data.isAnnotated() && !data.hasErrors()) { - if (JavaDescriptorResolverKt.getPLATFORM_TYPES()) { - return new AlternativeMethodSignature(returnType, receiverType, valueParameters, - typeParameters, Collections.emptyList(), hasStableParameterNames); - } - return new AlternativeMethodSignature(data.getReturnType(), receiverType, data.getValueParameters(), data.getTypeParameters(), - Collections.emptyList(), true); - } - - List error = data.hasErrors() ? Collections.singletonList(data.getError()) : Collections.emptyList(); - return new AlternativeMethodSignature(returnType, receiverType, valueParameters, typeParameters, error, hasStableParameterNames); - } - - @Override - @NotNull - public AlternativeFieldSignature resolveAlternativeFieldSignature( - @NotNull JavaField field, - @NotNull KotlinType returnType, - boolean isVar - ) { - AlternativeFieldSignatureData data = new AlternativeFieldSignatureData(field, returnType, project, isVar); - - if (data.isAnnotated() && !data.hasErrors()) { - if (JavaDescriptorResolverKt.getPLATFORM_TYPES()) { - return new AlternativeFieldSignature(returnType, null); - } - return new AlternativeFieldSignature(data.getReturnType(), null); - } - - String error = data.hasErrors() ? data.getError() : null; - return new AlternativeFieldSignature(returnType, error); } @Override diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/AlternativeFieldSignatureData.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/AlternativeFieldSignatureData.java deleted file mode 100644 index 2e668f7c078..00000000000 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/AlternativeFieldSignatureData.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.jvm.kotlinSignature; - -import com.intellij.openapi.project.Project; -import com.intellij.util.containers.ComparatorUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor; -import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl; -import org.jetbrains.kotlin.load.java.structure.JavaField; -import org.jetbrains.kotlin.psi.KtProperty; -import org.jetbrains.kotlin.psi.KtPsiFactoryKt; -import org.jetbrains.kotlin.types.KotlinType; - -import java.util.HashMap; - -public class AlternativeFieldSignatureData extends ElementAlternativeSignatureData { - private KotlinType altReturnType; - - public AlternativeFieldSignatureData( - @NotNull JavaField field, - @NotNull KotlinType originalReturnType, - @NotNull Project project, - boolean isVar - ) { - String signature = SignaturesUtil.getKotlinSignature(field); - - if (signature == null) { - setAnnotated(false); - return; - } - - setAnnotated(true); - KtProperty altPropertyDeclaration = KtPsiFactoryKt.KtPsiFactory(project).createProperty(signature); - - try { - checkForSyntaxErrors(altPropertyDeclaration); - checkFieldAnnotation(altPropertyDeclaration, field, isVar); - altReturnType = computeReturnType(originalReturnType, altPropertyDeclaration.getTypeReference(), - new HashMap()); - } - catch (AlternativeSignatureMismatchException e) { - setError(e.getMessage()); - } - } - - @NotNull - public KotlinType getReturnType() { - checkForErrors(); - return altReturnType; - } - - private static void checkFieldAnnotation(@NotNull KtProperty altProperty, @NotNull JavaField field, boolean isVar) { - if (!ComparatorUtil.equalsNullable(field.getName().asString(), altProperty.getName())) { - throw new AlternativeSignatureMismatchException("Field name mismatch, original: %s, alternative: %s", - field.getName().asString(), altProperty.getName()); - } - - if (altProperty.getTypeReference() == null) { - throw new AlternativeSignatureMismatchException("Field annotation for shouldn't have type reference"); - } - - if (altProperty.getGetter() != null || altProperty.getSetter() != null) { - throw new AlternativeSignatureMismatchException("Field annotation for shouldn't have getters and setters"); - } - - if (altProperty.isVar() != isVar) { - throw new AlternativeSignatureMismatchException("Wrong mutability in annotation for field"); - } - - if (altProperty.hasInitializer()) { - throw new AlternativeSignatureMismatchException("Default value is not expected in annotation for field"); - } - } -} diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/AlternativeMethodSignatureData.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/AlternativeMethodSignatureData.java deleted file mode 100644 index acaece7435b..00000000000 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/AlternativeMethodSignatureData.java +++ /dev/null @@ -1,317 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.jvm.kotlinSignature; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiNamedElement; -import com.intellij.util.containers.ComparatorUtil; -import com.intellij.util.containers.ContainerUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.descriptors.SourceElement; -import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor; -import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor; -import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl; -import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl; -import org.jetbrains.kotlin.load.java.structure.JavaMember; -import org.jetbrains.kotlin.name.Name; -import org.jetbrains.kotlin.psi.*; -import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolverKt; -import org.jetbrains.kotlin.resolve.jvm.JavaResolverUtils; -import org.jetbrains.kotlin.types.*; -import org.jetbrains.kotlin.types.checker.KotlinTypeChecker; -import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import static org.jetbrains.kotlin.load.java.components.TypeUsage.MEMBER_SIGNATURE_CONTRAVARIANT; -import static org.jetbrains.kotlin.load.java.components.TypeUsage.UPPER_BOUND; -import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getBuiltIns; - -public class AlternativeMethodSignatureData extends ElementAlternativeSignatureData { - private final KtNamedFunction altFunDeclaration; - - private List altValueParameters; - private KotlinType altReturnType; - private List altTypeParameters; - - private Map originalToAltTypeParameters; - - public AlternativeMethodSignatureData( - @NotNull JavaMember methodOrConstructor, - @Nullable KotlinType receiverType, - @NotNull Project project, - @NotNull List valueParameters, - @Nullable KotlinType originalReturnType, - @NotNull List methodTypeParameters, - boolean hasSuperMethods - ) { - String signature = SignaturesUtil.getKotlinSignature(methodOrConstructor); - - if (signature == null) { - setAnnotated(false); - altFunDeclaration = null; - return; - } - - if (receiverType != null) { - throw new UnsupportedOperationException("Alternative annotations for extension functions are not supported yet"); - } - - setAnnotated(true); - altFunDeclaration = KtPsiFactoryKt.KtPsiFactory(project).createFunction(signature); - - originalToAltTypeParameters = JavaResolverUtils.recreateTypeParametersAndReturnMapping(methodTypeParameters, null); - - try { - checkForSyntaxErrors(altFunDeclaration); - checkEqualFunctionNames(altFunDeclaration, methodOrConstructor); - - computeTypeParameters(methodTypeParameters); - computeValueParameters(valueParameters); - - if (originalReturnType != null) { - altReturnType = computeReturnType(originalReturnType, altFunDeclaration.getTypeReference(), originalToAltTypeParameters); - } - - if (hasSuperMethods) { - checkParameterAndReturnTypesForOverridingMethods(valueParameters, methodTypeParameters, originalReturnType); - } - } - catch (AlternativeSignatureMismatchException e) { - setError(e.getMessage()); - } - } - - public static List updateNames( - List originalValueParameters, - List altValueParameters - ) { - List result = new ArrayList(originalValueParameters.size()); - for (int i = 0; i < originalValueParameters.size(); i++) { - ValueParameterDescriptor originalValueParameter = originalValueParameters.get(i); - ValueParameterDescriptor altValueParameter = altValueParameters.get(i); - result.add(originalValueParameter.copy(originalValueParameter.getContainingDeclaration(), altValueParameter.getName())); - } - return result; - } - - private void checkParameterAndReturnTypesForOverridingMethods( - @NotNull List valueParameters, - @NotNull List methodTypeParameters, - @Nullable KotlinType returnType - ) { - if (JavaDescriptorResolverKt.getPLATFORM_TYPES()) return; - TypeSubstitutor substitutor = JavaResolverUtils.createSubstitutorForTypeParameters(originalToAltTypeParameters); - - for (ValueParameterDescriptor parameter : valueParameters) { - int index = parameter.getIndex(); - ValueParameterDescriptor altParameter = altValueParameters.get(index); - - KotlinType substituted = substitutor.substitute(parameter.getType(), Variance.INVARIANT); - assert substituted != null; - - if (!TypeUtils.equalTypes(substituted, altParameter.getType())) { - throw new AlternativeSignatureMismatchException( - "Parameter type changed for method which overrides another: " + altParameter.getType() - + ", was: " + parameter.getType()); - } - } - - // don't check receiver - - for (TypeParameterDescriptor parameter : methodTypeParameters) { - int index = parameter.getIndex(); - - KotlinType upperBoundsAsType = TypeIntersector.getUpperBoundsAsType(parameter); - KotlinType substituted = substitutor.substitute(upperBoundsAsType, Variance.INVARIANT); - assert substituted != null; - - KotlinType altUpperBoundsAsType = TypeIntersector.getUpperBoundsAsType(altTypeParameters.get(index)); - if (!TypeUtils.equalTypes(substituted, altUpperBoundsAsType)) { - throw new AlternativeSignatureMismatchException( - "Type parameter's upper bound changed for method which overrides another: " - + altUpperBoundsAsType + ", was: " + upperBoundsAsType - ); - } - } - - if (returnType != null) { - KotlinType substitutedReturnType = substitutor.substitute(returnType, Variance.INVARIANT); - assert substitutedReturnType != null; - - if (!KotlinTypeChecker.DEFAULT.isSubtypeOf(altReturnType, substitutedReturnType)) { - throw new AlternativeSignatureMismatchException( - "Return type is changed to not subtype for method which overrides another: " + altReturnType + ", was: " + returnType); - } - } - } - - @NotNull - public List getValueParameters() { - checkForErrors(); - return altValueParameters; - } - - @Nullable - public KotlinType getReturnType() { - checkForErrors(); - return altReturnType; - } - - @NotNull - public List getTypeParameters() { - checkForErrors(); - return altTypeParameters; - } - - private void computeValueParameters(@NotNull List parameterDescriptors) { - if (parameterDescriptors.size() != altFunDeclaration.getValueParameters().size()) { - throw new AlternativeSignatureMismatchException("Method signature has %d value parameters, but alternative signature has %d", - parameterDescriptors.size(), altFunDeclaration.getValueParameters().size()); - } - - List altParamDescriptors = new ArrayList(parameterDescriptors.size()); - for (int i = 0; i < parameterDescriptors.size(); i++) { - ValueParameterDescriptor originalParameterDescriptor = parameterDescriptors.get(i); - KtParameter annotationValueParameter = altFunDeclaration.getValueParameters().get(i); - - //noinspection ConstantConditions - KtTypeElement alternativeTypeElement = annotationValueParameter.getTypeReference().getTypeElement(); - assert alternativeTypeElement != null; - - KotlinType alternativeType; - KotlinType alternativeVarargElementType; - - KotlinType originalParamVarargElementType = originalParameterDescriptor.getVarargElementType(); - if (originalParamVarargElementType == null) { - if (annotationValueParameter.isVarArg()) { - throw new AlternativeSignatureMismatchException("Parameter in method signature is not vararg, but in alternative signature it is vararg"); - } - - alternativeType = TypeTransformingVisitor.computeType(alternativeTypeElement, originalParameterDescriptor.getType(), originalToAltTypeParameters, MEMBER_SIGNATURE_CONTRAVARIANT); - alternativeVarargElementType = null; - } - else { - if (!annotationValueParameter.isVarArg()) { - throw new AlternativeSignatureMismatchException("Parameter in method signature is vararg, but in alternative signature it is not"); - } - - alternativeVarargElementType = TypeTransformingVisitor.computeType(alternativeTypeElement, originalParamVarargElementType, - originalToAltTypeParameters, MEMBER_SIGNATURE_CONTRAVARIANT); - alternativeType = getBuiltIns(originalParameterDescriptor).getArrayType(Variance.OUT_VARIANCE, alternativeVarargElementType); - } - - Name altName = annotationValueParameter.getNameAsName(); - - altParamDescriptors.add(new ValueParameterDescriptorImpl( - originalParameterDescriptor.getContainingDeclaration(), - null, - originalParameterDescriptor.getIndex(), - originalParameterDescriptor.getAnnotations(), - altName != null ? altName : originalParameterDescriptor.getName(), - alternativeType, - originalParameterDescriptor.declaresDefaultValue(), - originalParameterDescriptor.isCrossinline(), - originalParameterDescriptor.isNoinline(), - alternativeVarargElementType, - SourceElement.NO_SOURCE - )); - } - - altValueParameters = altParamDescriptors; - } - - private void computeTypeParameters(List typeParameters) { - if (typeParameters.size() != altFunDeclaration.getTypeParameters().size()) { - throw new AlternativeSignatureMismatchException("Method signature has %d type parameters, but alternative signature has %d", - typeParameters.size(), altFunDeclaration.getTypeParameters().size()); - } - - altTypeParameters = new ArrayList(typeParameters.size()); - - for (int i = 0; i < typeParameters.size(); i++) { - TypeParameterDescriptor originalTypeParamDescriptor = typeParameters.get(i); - - TypeParameterDescriptorImpl altParamDescriptor = originalToAltTypeParameters.get(originalTypeParamDescriptor); - KtTypeParameter altTypeParameter = altFunDeclaration.getTypeParameters().get(i); - - List originalUpperBounds = originalTypeParamDescriptor.getUpperBounds(); - List altUpperBounds = getUpperBounds(altFunDeclaration, altTypeParameter); - if (altUpperBounds.size() != originalUpperBounds.size()) { - if (altUpperBounds.isEmpty() - && originalUpperBounds.size() == 1 - && TypeUtilsKt.isDefaultBound(originalUpperBounds.iterator().next())) { - // Only default bound => no error - } - else { - throw new AlternativeSignatureMismatchException("Upper bound number mismatch for %s. Expected %d, but found %d", - originalTypeParamDescriptor.getName(), - originalUpperBounds.size(), - altUpperBounds.size()); - } - } - - if (altUpperBounds.isEmpty()) { - altParamDescriptor.addDefaultUpperBound(); - } - else { - int upperBoundIndex = 0; - for (KotlinType upperBound : originalUpperBounds) { - - KtTypeElement altTypeElement = altUpperBounds.get(upperBoundIndex).getTypeElement(); - assert altTypeElement != null; - - altParamDescriptor.addUpperBound(TypeTransformingVisitor.computeType(altTypeElement, upperBound, - originalToAltTypeParameters, UPPER_BOUND)); - upperBoundIndex++; - } - } - - altParamDescriptor.setInitialized(); - altTypeParameters.add(altParamDescriptor); - } - } - - @NotNull - private static List getUpperBounds(@NotNull KtFunction function, @NotNull KtTypeParameter jetTypeParameter) { - List result = new ArrayList(); - ContainerUtil.addIfNotNull(result, jetTypeParameter.getExtendsBound()); - - Name name = jetTypeParameter.getNameAsName(); - if (name == null) return result; - - for (KtTypeConstraint constraint : function.getTypeConstraints()) { - KtSimpleNameExpression parameterName = constraint.getSubjectTypeParameterName(); - assert parameterName != null : "No parameter name in constraint " + constraint.getText(); - if (name.equals(parameterName.getReferencedNameAsName())) { - result.add(constraint.getBoundTypeReference()); - } - } - - return result; - } - - private static void checkEqualFunctionNames(@NotNull PsiNamedElement namedElement, @NotNull JavaMember methodOrConstructor) { - if (!ComparatorUtil.equalsNullable(methodOrConstructor.getName().asString(), namedElement.getName())) { - throw new AlternativeSignatureMismatchException("Function names mismatch, original: %s, alternative: %s", - methodOrConstructor.getName().asString(), namedElement.getName()); - } - } -} diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/AlternativeSignatureMismatchException.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/AlternativeSignatureMismatchException.java deleted file mode 100644 index 826dade07f1..00000000000 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/AlternativeSignatureMismatchException.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.jvm.kotlinSignature; - -class AlternativeSignatureMismatchException extends RuntimeException { - AlternativeSignatureMismatchException(String format, Object... params) { - this(String.format(format, params)); - } - - AlternativeSignatureMismatchException(String message) { - super(message); - } -} diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/ElementAlternativeSignatureData.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/ElementAlternativeSignatureData.java deleted file mode 100644 index a3587e75b2d..00000000000 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/ElementAlternativeSignatureData.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.jvm.kotlinSignature; - -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiErrorElement; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.builtins.KotlinBuiltIns; -import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor; -import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl; -import org.jetbrains.kotlin.psi.KtTypeElement; -import org.jetbrains.kotlin.psi.KtTypeReference; -import org.jetbrains.kotlin.renderer.DescriptorRenderer; -import org.jetbrains.kotlin.resolve.AnalyzingUtils; -import org.jetbrains.kotlin.types.KotlinType; - -import java.util.List; -import java.util.Map; - -import static org.jetbrains.kotlin.load.java.components.TypeUsage.MEMBER_SIGNATURE_COVARIANT; - -public abstract class ElementAlternativeSignatureData { - private String error; - private boolean isAnnotated; - - public final boolean hasErrors() { - return error != null; - } - - @NotNull - public final String getError() { - if (error == null) { - throw new IllegalStateException("There are no errors"); - } - return error; - } - - protected final void setError(@Nullable String error) { - this.error = error; - } - - public boolean isAnnotated() { - return this.isAnnotated; - } - - protected final void checkForErrors() { - if (!isAnnotated() || hasErrors()) { - throw new IllegalStateException("Trying to read result while there is none"); - } - } - - protected final void setAnnotated(boolean isAnnotated) { - this.isAnnotated = isAnnotated; - } - - protected static void checkForSyntaxErrors(PsiElement namedElement) { - List syntaxErrors = AnalyzingUtils.getSyntaxErrorRanges(namedElement); - - if (!syntaxErrors.isEmpty()) { - int errorOffset = syntaxErrors.get(0).getTextOffset(); - String syntaxErrorDescription = syntaxErrors.get(0).getErrorDescription(); - - if (syntaxErrors.size() == 1) { - throw new AlternativeSignatureMismatchException("Alternative signature has syntax error at %d: %s", - errorOffset, syntaxErrorDescription); - } - else { - throw new AlternativeSignatureMismatchException("Alternative signature has %d syntax errors, first is at %d: %s", - syntaxErrors.size(), errorOffset, syntaxErrorDescription); - } - } - } - - protected static KotlinType computeReturnType( - @NotNull KotlinType originalType, - @Nullable KtTypeReference altReturnTypeReference, - @NotNull Map originalToAltTypeParameters) { - if (altReturnTypeReference == null) { - if (KotlinBuiltIns.isUnit(originalType)) { - return originalType; - } - else { - throw new AlternativeSignatureMismatchException( - "Return type in alternative signature is missing, while in real signature it is '%s'", - DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(originalType)); - } - } - - KtTypeElement typeElement = altReturnTypeReference.getTypeElement(); - assert (typeElement != null); - - return TypeTransformingVisitor.computeType(typeElement, originalType, originalToAltTypeParameters, MEMBER_SIGNATURE_COVARIANT); - } -} diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/SignaturesUtil.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/SignaturesUtil.java deleted file mode 100644 index c4c7696d6f0..00000000000 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/SignaturesUtil.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.jvm.kotlinSignature; - -import com.intellij.openapi.util.text.StringUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.load.java.structure.JavaAnnotation; -import org.jetbrains.kotlin.load.java.structure.JavaAnnotationArgument; -import org.jetbrains.kotlin.load.java.structure.JavaLiteralAnnotationArgument; -import org.jetbrains.kotlin.load.java.structure.JavaMember; - -import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.*; - -public class SignaturesUtil { - private SignaturesUtil() { - } - - @Nullable - public static String getKotlinSignature(@NotNull JavaMember member) { - JavaAnnotation newAnnotation = member.findAnnotation(KOTLIN_SIGNATURE); - if (newAnnotation != null) return extractKotlinSignatureArgument(newAnnotation); - - JavaAnnotation oldAnnotation = member.findAnnotation(OLD_KOTLIN_SIGNATURE); - if (oldAnnotation != null) return extractKotlinSignatureArgument(oldAnnotation); - - return null; - } - - @Nullable - private static String extractKotlinSignatureArgument(@NotNull JavaAnnotation annotation) { - JavaAnnotationArgument argument = annotation.findArgument(DEFAULT_ANNOTATION_MEMBER_NAME); - if (argument instanceof JavaLiteralAnnotationArgument) { - Object value = ((JavaLiteralAnnotationArgument) argument).getValue(); - if (value instanceof String) { - return StringUtil.unescapeStringCharacters((String) value); - } - } - return null; - } -} diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/TypeTransformingVisitor.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/TypeTransformingVisitor.java deleted file mode 100644 index 82669b3ecd3..00000000000 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/TypeTransformingVisitor.java +++ /dev/null @@ -1,235 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.jvm.kotlinSignature; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.builtins.KotlinBuiltIns; -import org.jetbrains.kotlin.descriptors.ClassDescriptor; -import org.jetbrains.kotlin.descriptors.ClassifierDescriptor; -import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor; -import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl; -import org.jetbrains.kotlin.load.java.components.TypeUsage; -import org.jetbrains.kotlin.name.ClassId; -import org.jetbrains.kotlin.name.FqNameUnsafe; -import org.jetbrains.kotlin.platform.JavaToKotlinClassMap; -import org.jetbrains.kotlin.psi.*; -import org.jetbrains.kotlin.renderer.DescriptorRenderer; -import org.jetbrains.kotlin.resolve.DescriptorUtils; -import org.jetbrains.kotlin.resolve.TypeResolver; -import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolverKt; -import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform; -import org.jetbrains.kotlin.resolve.scopes.MemberScope; -import org.jetbrains.kotlin.types.*; - -import java.util.*; - -import static org.jetbrains.kotlin.load.java.components.TypeUsage.TYPE_ARGUMENT; -import static org.jetbrains.kotlin.types.Variance.INVARIANT; - -public class TypeTransformingVisitor extends KtVisitor { - private final KotlinType originalType; - private final Map originalToAltTypeParameters; - - private final TypeUsage typeUsage; - - private TypeTransformingVisitor( - KotlinType originalType, - Map originalToAltTypeParameters, - TypeUsage typeUsage - ) { - this.originalType = originalType; - this.typeUsage = typeUsage; - this.originalToAltTypeParameters = Collections.unmodifiableMap(originalToAltTypeParameters); - } - - @NotNull - public static KotlinType computeType( - @NotNull KtTypeElement alternativeTypeElement, - @NotNull KotlinType originalType, - @NotNull Map originalToAltTypeParameters, - @NotNull TypeUsage typeUsage - ) { - KotlinType computedType = alternativeTypeElement.accept(new TypeTransformingVisitor(originalType, originalToAltTypeParameters, typeUsage), null); - assert (computedType != null); - return computedType; - } - - @Override - public KotlinType visitNullableType(@NotNull KtNullableType nullableType, Void aVoid) { - if (!TypeUtils.isNullableType(originalType) && typeUsage != TYPE_ARGUMENT) { - throw new AlternativeSignatureMismatchException("Auto type '%s' is not-null, while type in alternative signature is nullable: '%s'", - DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(originalType), nullableType.getText()); - } - KtTypeElement innerType = nullableType.getInnerType(); - assert innerType != null : "Syntax error: " + nullableType.getText(); - return TypeUtils.makeNullable(computeType(innerType, originalType, originalToAltTypeParameters, typeUsage)); - } - - @Override - public KotlinType visitFunctionType(@NotNull KtFunctionType type, Void data) { - KotlinBuiltIns builtIns = JvmPlatform.INSTANCE$.getBuiltIns(); - return visitCommonType(type.getReceiverTypeReference() == null - ? builtIns.getFunction(type.getParameters().size()) - : builtIns.getExtensionFunction(type.getParameters().size()), type); - } - - @Override - public KotlinType visitUserType(@NotNull KtUserType type, Void data) { - KtUserType qualifier = type.getQualifier(); - - //noinspection ConstantConditions - String shortName = type.getReferenceExpression().getReferencedName(); - String longName = (qualifier == null ? "" : qualifier.getText() + ".") + shortName; - - return visitCommonType(longName, type); - } - - private KotlinType visitCommonType(@NotNull ClassDescriptor classDescriptor, @NotNull KtTypeElement type) { - return visitCommonType(DescriptorUtils.getFqNameSafe(classDescriptor).asString(), type); - } - - @NotNull - private KotlinType visitCommonType(@NotNull String qualifiedName, @NotNull KtTypeElement type) { - if (originalType.isError()) { - return originalType; - } - TypeConstructor originalTypeConstructor = originalType.getConstructor(); - ClassifierDescriptor declarationDescriptor = originalTypeConstructor.getDeclarationDescriptor(); - assert declarationDescriptor != null; - FqNameUnsafe originalClassFqName = DescriptorUtils.getFqName(declarationDescriptor); - ClassDescriptor classFromLibrary = getAutoTypeAnalogWithinBuiltins(originalClassFqName, qualifiedName); - if (!isSameName(qualifiedName, originalClassFqName.asString()) && classFromLibrary == null) { - throw new AlternativeSignatureMismatchException("Alternative signature type mismatch, expected: %s, actual: %s", - qualifiedName, originalClassFqName); - } - - TypeConstructor typeConstructor; - if (classFromLibrary != null) { - typeConstructor = classFromLibrary.getTypeConstructor(); - } - else { - typeConstructor = originalTypeConstructor; - } - ClassifierDescriptor typeConstructorClassifier = typeConstructor.getDeclarationDescriptor(); - if (typeConstructorClassifier instanceof TypeParameterDescriptor && originalToAltTypeParameters.containsKey(typeConstructorClassifier)) { - typeConstructor = originalToAltTypeParameters.get(typeConstructorClassifier).getTypeConstructor(); - } - - List arguments = originalType.getArguments(); - - if (arguments.size() != type.getTypeArgumentsAsTypes().size()) { - if (JavaDescriptorResolverKt.getPLATFORM_TYPES()) return originalType; - - throw new AlternativeSignatureMismatchException("'%s' type in method signature has %d type arguments, while '%s' in alternative signature has %d of them", - DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(originalType), arguments.size(), type.getText(), - type.getTypeArgumentsAsTypes().size()); - } - - List altArguments = new ArrayList(); - for (int i = 0, size = arguments.size(); i < size; i++) { - altArguments.add(getAltArgument(type, typeConstructor, i, arguments.get(i))); - } - - MemberScope memberScope; - if (typeConstructorClassifier instanceof TypeParameterDescriptor) { - memberScope = typeConstructorClassifier.getDefaultType().getMemberScope(); - } - else if (typeConstructorClassifier instanceof ClassDescriptor) { - memberScope = ((ClassDescriptor) typeConstructorClassifier).getMemberScope(altArguments); - } - else { - throw new AssertionError("Unexpected class of type constructor classifier " - + (typeConstructorClassifier == null ? "null" : typeConstructorClassifier.getClass().getName())); - } - return KotlinTypeImpl.create(originalType.getAnnotations(), typeConstructor, false, altArguments, memberScope); - } - - @NotNull - private TypeProjection getAltArgument( - @NotNull KtTypeElement type, - @NotNull TypeConstructor typeConstructor, - int i, - @NotNull TypeProjection originalArgument - ) { - KtTypeReference typeReference = type.getTypeArgumentsAsTypes().get(i); // process both function type and user type - - if (typeReference == null) { - // star projection - assert type instanceof KtUserType - && ((KtUserType) type).getTypeArguments().get(i).getProjectionKind() == KtProjectionKind.STAR; - - return originalArgument; - } - - KtTypeElement argumentAlternativeTypeElement = typeReference.getTypeElement(); - assert argumentAlternativeTypeElement != null; - - TypeParameterDescriptor parameter = typeConstructor.getParameters().get(i); - KotlinType alternativeArgumentType = computeType(argumentAlternativeTypeElement, originalArgument.getType(), originalToAltTypeParameters, TYPE_ARGUMENT); - Variance projectionKind = originalArgument.getProjectionKind(); - Variance altProjectionKind; - if (type instanceof KtUserType) { - KtTypeProjection typeProjection = ((KtUserType) type).getTypeArguments().get(i); - altProjectionKind = TypeResolver.resolveProjectionKind(typeProjection.getProjectionKind()); - if (altProjectionKind != projectionKind && projectionKind != Variance.INVARIANT && !JavaDescriptorResolverKt.getPLATFORM_TYPES()) { - throw new AlternativeSignatureMismatchException("Projection kind mismatch, actual: %s, in alternative signature: %s", - projectionKind, altProjectionKind); - } - if (altProjectionKind != INVARIANT && parameter.getVariance() != INVARIANT) { - if (altProjectionKind == parameter.getVariance()) { - altProjectionKind = projectionKind; - } - else { - throw new AlternativeSignatureMismatchException("Projection kind '%s' is conflicting with variance of %s", - altProjectionKind, DescriptorUtils.getFqName(typeConstructor.getDeclarationDescriptor())); - } - } - } - else { - altProjectionKind = projectionKind; - } - return new TypeProjectionImpl(altProjectionKind, alternativeArgumentType); - } - - @Nullable - private static ClassDescriptor getAutoTypeAnalogWithinBuiltins( - @NotNull FqNameUnsafe originalClassFqName, - @NotNull String qualifiedName - ) { - ClassId javaClassId = JavaToKotlinClassMap.INSTANCE.mapKotlinToJava(originalClassFqName); - if (javaClassId == null) return null; - - Collection descriptors = JavaToKotlinClassMap.INSTANCE.mapPlatformClass(javaClassId.asSingleFqName()); - for (ClassDescriptor descriptor : descriptors) { - String fqName = DescriptorUtils.getFqName(descriptor).asString(); - if (isSameName(qualifiedName, fqName)) { - return descriptor; - } - } - return null; - } - - @Override - public KotlinType visitSelfType(@NotNull KtSelfType type, Void data) { - throw new UnsupportedOperationException("Self-types are not supported yet"); - } - - private static boolean isSameName(String qualifiedName, String fullyQualifiedName) { - return fullyQualifiedName.equals(qualifiedName) || fullyQualifiedName.endsWith("." + qualifiedName); - } -} diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.java index 78fe61fb717..88d0f72abb2 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.java @@ -38,14 +38,9 @@ public final class JvmAnnotationNames { public static final FqName KOTLIN_INTERFACE_DEFAULT_IMPLS = new FqName("kotlin.jvm.internal.KotlinInterfaceDefaultImpls"); public static final FqName KOTLIN_LOCAL_CLASS = new FqName("kotlin.jvm.internal.KotlinLocalClass"); - public static final FqName JAVA_LANG_DEPRECATED = new FqName("java.lang.Deprecated"); - public static final FqName KOTLIN_DELEGATED_METHOD = new FqName("kotlin.jvm.internal.KotlinDelegatedMethod"); public static final String IMPLEMENTATION_CLASS_NAME_FIELD_NAME = "implementationClassName"; - public static final FqName KOTLIN_SIGNATURE = new FqName("kotlin.jvm.KotlinSignature"); - public static final FqName OLD_KOTLIN_SIGNATURE = new FqName("jet.runtime.typeinfo.KotlinSignature"); - public static final String VERSION_FIELD_NAME = "version"; public static final String FILE_PART_CLASS_NAMES_FIELD_NAME = "filePartClassNames"; public static final String MULTIFILE_CLASS_NAME_FIELD_NAME = "multifileClassName"; @@ -87,7 +82,7 @@ public final class JvmAnnotationNames { private static final Set SPECIAL_META_ANNOTATIONS = new HashSet(); static { for (FqName fqName : Arrays.asList( - KOTLIN_CLASS, KOTLIN_PACKAGE, KOTLIN_SIGNATURE, KOTLIN_SYNTHETIC_CLASS, KOTLIN_INTERFACE_DEFAULT_IMPLS, KOTLIN_LOCAL_CLASS + KOTLIN_CLASS, KOTLIN_PACKAGE, KOTLIN_SYNTHETIC_CLASS, KOTLIN_INTERFACE_DEFAULT_IMPLS, KOTLIN_LOCAL_CLASS )) { SPECIAL_ANNOTATIONS.add(JvmClassName.byFqNameWithoutInnerClasses(fqName)); } @@ -105,7 +100,7 @@ public final class JvmAnnotationNames { JvmClassName className = JvmClassName.byClassId(classId); return (javaSpecificAnnotationsAreSpecial && (NULLABILITY_ANNOTATIONS.contains(className) || SPECIAL_META_ANNOTATIONS.contains(className)) - ) || SPECIAL_ANNOTATIONS.contains(className) || className.getInternalName().startsWith("jet/runtime/typeinfo/"); + ) || SPECIAL_ANNOTATIONS.contains(className); } private JvmAnnotationNames() { diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/components/ExternalSignatureResolver.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/components/ExternalSignatureResolver.java index fda413f1171..badeddbdb6a 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/components/ExternalSignatureResolver.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/components/ExternalSignatureResolver.java @@ -18,9 +18,10 @@ package org.jetbrains.kotlin.load.java.components; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.descriptors.*; -import org.jetbrains.kotlin.load.java.structure.JavaField; -import org.jetbrains.kotlin.load.java.structure.JavaMember; +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor; +import org.jetbrains.kotlin.descriptors.ClassDescriptor; +import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor; +import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor; import org.jetbrains.kotlin.load.java.structure.JavaMethod; import org.jetbrains.kotlin.types.KotlinType; @@ -31,68 +32,31 @@ public interface ExternalSignatureResolver { ExternalSignatureResolver DO_NOTHING = new ExternalSignatureResolver() { @NotNull @Override - public PropagatedMethodSignature resolvePropagatedSignature( + public AlternativeMethodSignature resolvePropagatedSignature( @NotNull JavaMethod method, @NotNull ClassDescriptor owner, @NotNull KotlinType returnType, @Nullable KotlinType receiverType, @NotNull List valueParameters, @NotNull List typeParameters - ) { - return new PropagatedMethodSignature( - returnType, receiverType, valueParameters, typeParameters, Collections.emptyList(), false, - Collections.emptyList() - ); - } - - @NotNull - @Override - public AlternativeMethodSignature resolveAlternativeMethodSignature( - @NotNull JavaMember methodOrConstructor, - boolean hasSuperMethods, - @Nullable KotlinType returnType, - @Nullable KotlinType receiverType, - @NotNull List valueParameters, - @NotNull List typeParameters, - boolean hasStableParameterNames ) { return new AlternativeMethodSignature( - returnType, receiverType, valueParameters, typeParameters, Collections.emptyList(), hasStableParameterNames + returnType, receiverType, valueParameters, typeParameters, Collections.emptyList(), false ); } - @NotNull - @Override - public AlternativeFieldSignature resolveAlternativeFieldSignature( - @NotNull JavaField field, @NotNull KotlinType returnType, boolean isVar - ) { - return new AlternativeFieldSignature(returnType, null); - } - @Override public void reportSignatureErrors(@NotNull CallableMemberDescriptor descriptor, @NotNull List signatureErrors) { throw new UnsupportedOperationException("Should not be called"); } }; - abstract class MemberSignature { - private final List signatureErrors; - - protected MemberSignature(@NotNull List signatureErrors) { - this.signatureErrors = signatureErrors; - } - - @NotNull - public List getErrors() { - return signatureErrors; - } - } - - class AlternativeMethodSignature extends MemberSignature { + class AlternativeMethodSignature { private final KotlinType returnType; private final KotlinType receiverType; private final List valueParameters; private final List typeParameters; + private final List signatureErrors; private final boolean hasStableParameterNames; public AlternativeMethodSignature( @@ -103,11 +67,11 @@ public interface ExternalSignatureResolver { @NotNull List signatureErrors, boolean hasStableParameterNames ) { - super(signatureErrors); this.returnType = returnType; this.receiverType = receiverType; this.valueParameters = valueParameters; this.typeParameters = typeParameters; + this.signatureErrors = signatureErrors; this.hasStableParameterNames = hasStableParameterNames; } @@ -134,46 +98,15 @@ public interface ExternalSignatureResolver { public boolean hasStableParameterNames() { return hasStableParameterNames; } - } - - class AlternativeFieldSignature extends MemberSignature { - private final KotlinType returnType; - - public AlternativeFieldSignature(@NotNull KotlinType returnType, @Nullable String signatureError) { - super(signatureError == null ? Collections.emptyList() : Collections.singletonList(signatureError)); - this.returnType = returnType; - } @NotNull - public KotlinType getReturnType() { - return returnType; - } - } - - class PropagatedMethodSignature extends AlternativeMethodSignature { - private final List superMethods; - - public PropagatedMethodSignature( - @Nullable KotlinType returnType, - @Nullable KotlinType receiverType, - @NotNull List valueParameters, - @NotNull List typeParameters, - @NotNull List signatureErrors, - boolean hasStableParameterNames, - @NotNull List superMethods - ) { - super(returnType, receiverType, valueParameters, typeParameters, signatureErrors, hasStableParameterNames); - this.superMethods = superMethods; - } - - @NotNull - public List getSuperMethods() { - return superMethods; + public List getErrors() { + return signatureErrors; } } @NotNull - PropagatedMethodSignature resolvePropagatedSignature( + AlternativeMethodSignature resolvePropagatedSignature( @NotNull JavaMethod method, @NotNull ClassDescriptor owner, @NotNull KotlinType returnType, @@ -182,23 +115,5 @@ public interface ExternalSignatureResolver { @NotNull List typeParameters ); - @NotNull - AlternativeMethodSignature resolveAlternativeMethodSignature( - @NotNull JavaMember methodOrConstructor, - boolean hasSuperMethods, - @Nullable KotlinType returnType, - @Nullable KotlinType receiverType, - @NotNull List valueParameters, - @NotNull List typeParameters, - boolean hasStableParameterNames - ); - - @NotNull - AlternativeFieldSignature resolveAlternativeFieldSignature( - @NotNull JavaField field, - @NotNull KotlinType returnType, - boolean isVar - ); - void reportSignatureErrors(@NotNull CallableMemberDescriptor descriptor, @NotNull List signatureErrors); } diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaClassMemberScope.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaClassMemberScope.kt index 6b545fc2755..91df9bef9f6 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaClassMemberScope.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaClassMemberScope.kt @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.load.java.BuiltinMethodsWithDifferentJvmName.sameAsR import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.sameAsBuiltinMethodWithErasedValueParameters import org.jetbrains.kotlin.load.java.BuiltinSpecialProperties.getBuiltinSpecialPropertyGetterName import org.jetbrains.kotlin.load.java.components.DescriptorResolverUtils +import org.jetbrains.kotlin.load.java.components.ExternalSignatureResolver import org.jetbrains.kotlin.load.java.components.TypeUsage import org.jetbrains.kotlin.load.java.descriptors.JavaConstructorDescriptor import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor @@ -425,13 +426,7 @@ public class LazyJavaClassMemberScope( val propagated = c.components.externalSignatureResolver.resolvePropagatedSignature( method, ownerDescriptor, returnType, null, valueParameters.descriptors, methodTypeParameters ) - val effectiveSignature = c.components.externalSignatureResolver.resolveAlternativeMethodSignature( - method, !propagated.getSuperMethods().isEmpty(), propagated.getReturnType(), - propagated.getReceiverType(), propagated.getValueParameters(), propagated.getTypeParameters(), - propagated.hasStableParameterNames() - ) - - return LazyJavaScope.MethodSignatureData(effectiveSignature, propagated.getErrors() + effectiveSignature.getErrors()) + return LazyJavaScope.MethodSignatureData(propagated, propagated.errors) } private fun hasOverriddenBuiltinFunctionWithErasedValueParameters( @@ -476,23 +471,13 @@ public class LazyJavaClassMemberScope( ) val valueParameters = resolveValueParameters(c, constructorDescriptor, constructor.getValueParameters()) - val effectiveSignature = c.components.externalSignatureResolver.resolveAlternativeMethodSignature( - constructor, false, null, null, valueParameters.descriptors, Collections.emptyList(), false) - constructorDescriptor.initialize( - effectiveSignature.getValueParameters(), - constructor.getVisibility() - ) - constructorDescriptor.setHasStableParameterNames(effectiveSignature.hasStableParameterNames()) + constructorDescriptor.initialize(valueParameters.descriptors, constructor.visibility) + constructorDescriptor.setHasStableParameterNames(false) constructorDescriptor.setHasSynthesizedParameterNames(valueParameters.hasSynthesizedNames) constructorDescriptor.setReturnType(classDescriptor.getDefaultType()) - val signatureErrors = effectiveSignature.getErrors() - if (!signatureErrors.isEmpty()) { - c.components.externalSignatureResolver.reportSignatureErrors(constructorDescriptor, signatureErrors) - } - c.components.javaResolverCache.recordConstructor(constructor, constructorDescriptor) return constructorDescriptor diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaScope.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaScope.kt index 7b0387a7163..6bdd550edec 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaScope.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaScope.kt @@ -241,18 +241,12 @@ public abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : } private fun resolveProperty(field: JavaField): PropertyDescriptor { - val isVar = !field.isFinal() val propertyDescriptor = createPropertyDescriptor(field) propertyDescriptor.initialize(null, null) val propertyType = getPropertyType(field, propertyDescriptor.getAnnotations()) - val effectiveSignature = c.components.externalSignatureResolver.resolveAlternativeFieldSignature(field, propertyType, isVar) - val signatureErrors = effectiveSignature.getErrors() - if (!signatureErrors.isEmpty()) { - c.components.externalSignatureResolver.reportSignatureErrors(propertyDescriptor, signatureErrors) - } - propertyDescriptor.setType(effectiveSignature.getReturnType(), listOf(), getDispatchReceiverParameter(), null as KotlinType?) + propertyDescriptor.setType(propertyType, listOf(), getDispatchReceiverParameter(), null as KotlinType?) if (DescriptorUtils.shouldRecordInitializerForProperty(propertyDescriptor, propertyDescriptor.getType())) { propertyDescriptor.setCompileTimeInitializer( diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaStaticScope.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaStaticScope.kt index 621e35a1a39..f3df3860007 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaStaticScope.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaStaticScope.kt @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.load.java.lazy.descriptors import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor +import org.jetbrains.kotlin.load.java.components.ExternalSignatureResolver import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext import org.jetbrains.kotlin.load.java.structure.JavaMethod import org.jetbrains.kotlin.name.FqName @@ -36,8 +37,9 @@ public abstract class LazyJavaStaticScope(c: LazyJavaResolverContext) : LazyJava method: JavaMethod, methodTypeParameters: List, returnType: KotlinType, valueParameters: LazyJavaScope.ResolvedValueParameters ): LazyJavaScope.MethodSignatureData { - val effectiveSignature = c.components.externalSignatureResolver.resolveAlternativeMethodSignature( - method, false, returnType, null, valueParameters.descriptors, methodTypeParameters, false) + val effectiveSignature = ExternalSignatureResolver.AlternativeMethodSignature( + returnType, null, valueParameters.descriptors, methodTypeParameters, emptyList(), false + ) return LazyJavaScope.MethodSignatureData(effectiveSignature, effectiveSignature.getErrors()) } diff --git a/core/runtime.jvm/src/jet/runtime/typeinfo/KotlinSignature.java b/core/runtime.jvm/src/jet/runtime/typeinfo/KotlinSignature.java deleted file mode 100644 index f1e70bf81bd..00000000000 --- a/core/runtime.jvm/src/jet/runtime/typeinfo/KotlinSignature.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet.runtime.typeinfo; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; - -/** - * @deprecated This annotation is no longer supported by the Kotlin compiler and will be removed in 1.0 - */ -@Deprecated -@Target({ElementType.METHOD, ElementType.TYPE, ElementType.CONSTRUCTOR, ElementType.FIELD}) -public @interface KotlinSignature { - String value(); -} diff --git a/core/runtime.jvm/src/kotlin/jvm/KotlinSignature.java b/core/runtime.jvm/src/kotlin/jvm/KotlinSignature.java deleted file mode 100644 index 569f46f6b1c..00000000000 --- a/core/runtime.jvm/src/kotlin/jvm/KotlinSignature.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package kotlin.jvm; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; - -/** - * @deprecated This annotation is no longer supported by the Kotlin compiler and will be removed in 1.0 - */ -@Deprecated -@Target({ElementType.METHOD, ElementType.TYPE, ElementType.CONSTRUCTOR, ElementType.FIELD}) -public @interface KotlinSignature { - String value(); -}