ClassDescriptor is now a super-interface for ClassConstructorDescriptor and TypeAliasConstructorDescriptor.
This commit is contained in:
committed by
Dmitry Petrov
parent
7d214c6e58
commit
796d11c860
+2
-5
@@ -20,10 +20,7 @@ import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.load.java.structure.*;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
@@ -106,7 +103,7 @@ public final class DescriptorResolverUtils {
|
||||
|
||||
@Nullable
|
||||
public static ValueParameterDescriptor getAnnotationParameterByName(@NotNull Name name, @NotNull ClassDescriptor annotationClass) {
|
||||
Collection<ConstructorDescriptor> constructors = annotationClass.getConstructors();
|
||||
Collection<ClassConstructorDescriptor> constructors = annotationClass.getConstructors();
|
||||
if (constructors.size() != 1) return null;
|
||||
|
||||
for (ValueParameterDescriptor parameter : constructors.iterator().next().getValueParameters()) {
|
||||
|
||||
+14
-14
@@ -20,19 +20,19 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ConstructorDescriptorImpl;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class JavaConstructorDescriptor extends ConstructorDescriptorImpl implements JavaCallableMemberDescriptor {
|
||||
public class JavaClassConstructorDescriptor extends ClassConstructorDescriptorImpl implements JavaCallableMemberDescriptor {
|
||||
private Boolean hasStableParameterNames = null;
|
||||
private Boolean hasSynthesizedParameterNames = null;
|
||||
|
||||
protected JavaConstructorDescriptor(
|
||||
protected JavaClassConstructorDescriptor(
|
||||
@NotNull ClassDescriptor containingDeclaration,
|
||||
@Nullable JavaConstructorDescriptor original,
|
||||
@Nullable JavaClassConstructorDescriptor original,
|
||||
@NotNull Annotations annotations,
|
||||
boolean isPrimary,
|
||||
@NotNull Kind kind,
|
||||
@@ -42,13 +42,13 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JavaConstructorDescriptor createJavaConstructor(
|
||||
public static JavaClassConstructorDescriptor createJavaConstructor(
|
||||
@NotNull ClassDescriptor containingDeclaration,
|
||||
@NotNull Annotations annotations,
|
||||
boolean isPrimary,
|
||||
@NotNull SourceElement source
|
||||
) {
|
||||
return new JavaConstructorDescriptor(containingDeclaration, null, annotations, isPrimary, Kind.DECLARATION, source);
|
||||
return new JavaClassConstructorDescriptor(containingDeclaration, null, annotations, isPrimary, Kind.DECLARATION, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,7 +73,7 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected JavaConstructorDescriptor createSubstitutedCopy(
|
||||
protected JavaClassConstructorDescriptor createSubstitutedCopy(
|
||||
@NotNull DeclarationDescriptor newOwner,
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@@ -92,22 +92,22 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme
|
||||
|
||||
assert newName == null : "Attempt to rename constructor: " + this;
|
||||
|
||||
JavaConstructorDescriptor result =
|
||||
createDescriptor((ClassDescriptor) newOwner, (JavaConstructorDescriptor) original, kind, source, annotations);
|
||||
JavaClassConstructorDescriptor result =
|
||||
createDescriptor((ClassDescriptor) newOwner, (JavaClassConstructorDescriptor) original, kind, source, annotations);
|
||||
result.setHasStableParameterNames(hasStableParameterNames());
|
||||
result.setHasSynthesizedParameterNames(hasSynthesizedParameterNames());
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected JavaConstructorDescriptor createDescriptor(
|
||||
protected JavaClassConstructorDescriptor createDescriptor(
|
||||
@NotNull ClassDescriptor newOwner,
|
||||
@Nullable JavaConstructorDescriptor original,
|
||||
@Nullable JavaClassConstructorDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@NotNull SourceElement sourceElement,
|
||||
@NotNull Annotations annotations
|
||||
) {
|
||||
return new JavaConstructorDescriptor(
|
||||
return new JavaClassConstructorDescriptor(
|
||||
newOwner, original, annotations, isPrimary, kind,
|
||||
sourceElement
|
||||
);
|
||||
@@ -115,12 +115,12 @@ public class JavaConstructorDescriptor extends ConstructorDescriptorImpl impleme
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JavaConstructorDescriptor enhance(
|
||||
public JavaClassConstructorDescriptor enhance(
|
||||
@Nullable KotlinType enhancedReceiverType,
|
||||
@NotNull List<KotlinType> enhancedValueParametersTypes,
|
||||
@NotNull KotlinType enhancedReturnType
|
||||
) {
|
||||
JavaConstructorDescriptor enhanced = createSubstitutedCopy(
|
||||
JavaClassConstructorDescriptor enhanced = createSubstitutedCopy(
|
||||
getContainingDeclaration(), /* original = */ null, getKind(), null, getAnnotations(), getSource());
|
||||
// We do not use doSubstitute here as in JavaMethodDescriptor.enhance because type parameters of constructor belongs to class
|
||||
enhanced.initialize(
|
||||
+1
-1
@@ -108,7 +108,7 @@ class LazyJavaClassDescriptor(
|
||||
private val staticScope = LazyJavaStaticClassScope(c, jClass, this)
|
||||
override fun getStaticScope(): MemberScope = staticScope
|
||||
|
||||
override fun getUnsubstitutedPrimaryConstructor(): ConstructorDescriptor? = null
|
||||
override fun getUnsubstitutedPrimaryConstructor(): ClassConstructorDescriptor? = null
|
||||
|
||||
override fun getCompanionObjectDescriptor(): ClassDescriptor? = null
|
||||
|
||||
|
||||
+8
-8
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.load.java.lazy.descriptors
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.ConstructorDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.EnumEntrySyntheticClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.
|
||||
import org.jetbrains.kotlin.load.java.BuiltinSpecialProperties.getBuiltinSpecialPropertyGetterName
|
||||
import org.jetbrains.kotlin.load.java.components.DescriptorResolverUtils.resolveOverridesForNonStaticMembers
|
||||
import org.jetbrains.kotlin.load.java.components.TypeUsage
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaConstructorDescriptor
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassConstructorDescriptor
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.load.java.descriptors.copyValueParameters
|
||||
@@ -79,7 +79,7 @@ class LazyJavaClassMemberScope(
|
||||
|
||||
internal val constructors = c.storageManager.createLazyValue {
|
||||
val constructors = jClass.constructors
|
||||
val result = ArrayList<JavaConstructorDescriptor>(constructors.size)
|
||||
val result = ArrayList<JavaClassConstructorDescriptor>(constructors.size)
|
||||
for (constructor in constructors) {
|
||||
val descriptor = resolveConstructor(constructor)
|
||||
result.add(descriptor)
|
||||
@@ -505,10 +505,10 @@ class LazyJavaClassMemberScope(
|
||||
&& !doesOverride(builtinWithErasedParameters)
|
||||
}
|
||||
|
||||
private fun resolveConstructor(constructor: JavaConstructor): JavaConstructorDescriptor {
|
||||
private fun resolveConstructor(constructor: JavaConstructor): JavaClassConstructorDescriptor {
|
||||
val classDescriptor = ownerDescriptor
|
||||
|
||||
val constructorDescriptor = JavaConstructorDescriptor.createJavaConstructor(
|
||||
val constructorDescriptor = JavaClassConstructorDescriptor.createJavaConstructor(
|
||||
classDescriptor, c.resolveAnnotations(constructor), /* isPrimary = */ false, c.components.sourceElementFactory.source(constructor)
|
||||
)
|
||||
|
||||
@@ -530,13 +530,13 @@ class LazyJavaClassMemberScope(
|
||||
return constructorDescriptor
|
||||
}
|
||||
|
||||
private fun createDefaultConstructor(): ConstructorDescriptor? {
|
||||
private fun createDefaultConstructor(): ClassConstructorDescriptor? {
|
||||
val isAnnotation: Boolean = jClass.isAnnotationType
|
||||
if (jClass.isInterface && !isAnnotation)
|
||||
return null
|
||||
|
||||
val classDescriptor = ownerDescriptor
|
||||
val constructorDescriptor = JavaConstructorDescriptor.createJavaConstructor(
|
||||
val constructorDescriptor = JavaClassConstructorDescriptor.createJavaConstructor(
|
||||
classDescriptor, Annotations.EMPTY, /* isPrimary = */ true, c.components.sourceElementFactory.source(jClass)
|
||||
)
|
||||
val valueParameters = if (isAnnotation) createAnnotationConstructorParameters(constructorDescriptor)
|
||||
@@ -558,7 +558,7 @@ class LazyJavaClassMemberScope(
|
||||
return visibility
|
||||
}
|
||||
|
||||
private fun createAnnotationConstructorParameters(constructor: ConstructorDescriptorImpl): List<ValueParameterDescriptor> {
|
||||
private fun createAnnotationConstructorParameters(constructor: ClassConstructorDescriptorImpl): List<ValueParameterDescriptor> {
|
||||
val methods = jClass.methods
|
||||
val result = ArrayList<ValueParameterDescriptor>(methods.size)
|
||||
|
||||
|
||||
+2
-2
@@ -231,7 +231,7 @@ open class JvmBuiltInsSettings(
|
||||
return ownerModuleDescriptor.resolveClassByFqName(javaAnalogueFqName, NoLookupLocation.FROM_BUILTINS) as? LazyJavaClassDescriptor
|
||||
}
|
||||
|
||||
override fun getConstructors(classDescriptor: DeserializedClassDescriptor): Collection<ConstructorDescriptor> {
|
||||
override fun getConstructors(classDescriptor: DeserializedClassDescriptor): Collection<ClassConstructorDescriptor> {
|
||||
if (classDescriptor.kind != ClassKind.CLASS) return emptyList()
|
||||
|
||||
val javaAnalogueDescriptor = classDescriptor.getJavaAnalogue() ?: return emptyList()
|
||||
@@ -264,7 +264,7 @@ open class JvmBuiltInsSettings(
|
||||
setAdditionalAnnotations(notConsideredDeprecation)
|
||||
}
|
||||
|
||||
}.build() as ConstructorDescriptor
|
||||
}.build() as ClassConstructorDescriptor
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -93,7 +93,7 @@ class FunctionClassDescriptor(
|
||||
override fun getUnsubstitutedMemberScope() = memberScope
|
||||
|
||||
override fun getCompanionObjectDescriptor() = null
|
||||
override fun getConstructors() = emptyList<ConstructorDescriptor>()
|
||||
override fun getConstructors() = emptyList<ClassConstructorDescriptor>()
|
||||
override fun getKind() = ClassKind.INTERFACE
|
||||
override fun getModality() = Modality.ABSTRACT
|
||||
override fun getUnsubstitutedPrimaryConstructor() = null
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2016 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.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
|
||||
|
||||
interface ClassConstructorDescriptor : ConstructorDescriptor {
|
||||
override fun getContainingDeclaration(): ClassDescriptor
|
||||
|
||||
override fun getOriginal(): ClassConstructorDescriptor
|
||||
|
||||
override fun substitute(substitutor: TypeSubstitutor): ClassConstructorDescriptor
|
||||
|
||||
override fun copy(
|
||||
newOwner: DeclarationDescriptor,
|
||||
modality: Modality,
|
||||
visibility: Visibility,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
copyOverrides: Boolean
|
||||
): ClassConstructorDescriptor
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public interface ClassDescriptor extends ClassifierDescriptorWithTypeParameters,
|
||||
|
||||
@NotNull
|
||||
@ReadOnly
|
||||
Collection<ConstructorDescriptor> getConstructors();
|
||||
Collection<ClassConstructorDescriptor> getConstructors();
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
@@ -88,7 +88,7 @@ public interface ClassDescriptor extends ClassifierDescriptorWithTypeParameters,
|
||||
ReceiverParameterDescriptor getThisAsReceiverParameter();
|
||||
|
||||
@Nullable
|
||||
ConstructorDescriptor getUnsubstitutedPrimaryConstructor();
|
||||
ClassConstructorDescriptor getUnsubstitutedPrimaryConstructor();
|
||||
|
||||
/**
|
||||
* It may differ from 'typeConstructor.parameters' in current class is inner, 'typeConstructor.parameters' contains
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.ReadOnly;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ClassifierDescriptorWithTypeParameters extends ClassifierDescriptor {
|
||||
public interface ClassifierDescriptorWithTypeParameters extends ClassifierDescriptor, DeclarationDescriptorWithVisibility {
|
||||
/**
|
||||
* @return <code>true</code> if this class contains a reference to its outer class (as opposed to static nested class)
|
||||
*/
|
||||
|
||||
@@ -34,7 +34,10 @@ public interface ConstructorDescriptor extends FunctionDescriptor {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
ClassDescriptor getContainingDeclaration();
|
||||
ClassifierDescriptorWithTypeParameters getContainingDeclaration();
|
||||
|
||||
@NotNull
|
||||
ClassDescriptor getConstructedClass();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
@@ -28,7 +28,7 @@ public interface ScriptDescriptor extends ClassDescriptor {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
ConstructorDescriptor getUnsubstitutedPrimaryConstructor();
|
||||
ClassConstructorDescriptor getUnsubstitutedPrimaryConstructor();
|
||||
|
||||
List<Pair<Name, KotlinType>> getScriptParametersToPassToSuperclass();
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class Visibilities {
|
||||
}
|
||||
|
||||
if (what instanceof ConstructorDescriptor) {
|
||||
ClassDescriptor classDescriptor = ((ConstructorDescriptor) what).getContainingDeclaration();
|
||||
ClassifierDescriptorWithTypeParameters classDescriptor = ((ConstructorDescriptor) what).getContainingDeclaration();
|
||||
if (DescriptorUtils.isSealedClass(classDescriptor)
|
||||
&& DescriptorUtils.isTopLevelDeclaration(classDescriptor)
|
||||
&& from instanceof ConstructorDescriptor
|
||||
|
||||
+20
-14
@@ -27,13 +27,13 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements ConstructorDescriptor {
|
||||
public class ClassConstructorDescriptorImpl extends FunctionDescriptorImpl implements ClassConstructorDescriptor {
|
||||
|
||||
protected final boolean isPrimary;
|
||||
|
||||
private static final Name NAME = Name.special("<init>");
|
||||
|
||||
protected ConstructorDescriptorImpl(
|
||||
protected ClassConstructorDescriptorImpl(
|
||||
@NotNull ClassDescriptor containingDeclaration,
|
||||
@Nullable ConstructorDescriptor original,
|
||||
@NotNull Annotations annotations,
|
||||
@@ -46,16 +46,16 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConstructorDescriptorImpl create(
|
||||
public static ClassConstructorDescriptorImpl create(
|
||||
@NotNull ClassDescriptor containingDeclaration,
|
||||
@NotNull Annotations annotations,
|
||||
boolean isPrimary,
|
||||
@NotNull SourceElement source
|
||||
) {
|
||||
return new ConstructorDescriptorImpl(containingDeclaration, null, annotations, isPrimary, Kind.DECLARATION, source);
|
||||
return new ClassConstructorDescriptorImpl(containingDeclaration, null, annotations, isPrimary, Kind.DECLARATION, source);
|
||||
}
|
||||
|
||||
public ConstructorDescriptorImpl initialize(
|
||||
public ClassConstructorDescriptorImpl initialize(
|
||||
@NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
|
||||
@NotNull Visibility visibility,
|
||||
@NotNull List<TypeParameterDescriptor> typeParameterDescriptors
|
||||
@@ -68,7 +68,7 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConstructorDescriptorImpl initialize(
|
||||
public ClassConstructorDescriptorImpl initialize(
|
||||
@NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
|
||||
@NotNull Visibility visibility
|
||||
) {
|
||||
@@ -96,14 +96,20 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ConstructorDescriptor getOriginal() {
|
||||
return (ConstructorDescriptor) super.getOriginal();
|
||||
public ClassDescriptor getConstructedClass() {
|
||||
return getContainingDeclaration();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ConstructorDescriptor substitute(@NotNull TypeSubstitutor originalSubstitutor) {
|
||||
return (ConstructorDescriptor) super.substitute(originalSubstitutor);
|
||||
public ClassConstructorDescriptor getOriginal() {
|
||||
return (ClassConstructorDescriptor) super.getOriginal();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ClassConstructorDescriptor substitute(@NotNull TypeSubstitutor originalSubstitutor) {
|
||||
return (ClassConstructorDescriptor) super.substitute(originalSubstitutor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,7 +135,7 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected ConstructorDescriptorImpl createSubstitutedCopy(
|
||||
protected ClassConstructorDescriptorImpl createSubstitutedCopy(
|
||||
@NotNull DeclarationDescriptor newOwner,
|
||||
@Nullable FunctionDescriptor original,
|
||||
@NotNull Kind kind,
|
||||
@@ -144,7 +150,7 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
"kind: " + kind);
|
||||
}
|
||||
assert newName == null : "Attempt to rename constructor: " + this;
|
||||
return new ConstructorDescriptorImpl(
|
||||
return new ClassConstructorDescriptorImpl(
|
||||
(ClassDescriptor) newOwner,
|
||||
this,
|
||||
annotations,
|
||||
@@ -156,13 +162,13 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ConstructorDescriptor copy(
|
||||
public ClassConstructorDescriptor copy(
|
||||
DeclarationDescriptor newOwner,
|
||||
Modality modality,
|
||||
Visibility visibility,
|
||||
Kind kind,
|
||||
boolean copyOverrides
|
||||
) {
|
||||
return (ConstructorDescriptor) super.copy(newOwner, modality, visibility, kind, copyOverrides);
|
||||
return (ClassConstructorDescriptor) super.copy(newOwner, modality, visibility, kind, copyOverrides);
|
||||
}
|
||||
}
|
||||
@@ -38,8 +38,8 @@ public class ClassDescriptorImpl extends ClassDescriptorBase {
|
||||
private final TypeConstructor typeConstructor;
|
||||
|
||||
private MemberScope unsubstitutedMemberScope;
|
||||
private Set<ConstructorDescriptor> constructors;
|
||||
private ConstructorDescriptor primaryConstructor;
|
||||
private Set<ClassConstructorDescriptor> constructors;
|
||||
private ClassConstructorDescriptor primaryConstructor;
|
||||
|
||||
public ClassDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@@ -60,8 +60,8 @@ public class ClassDescriptorImpl extends ClassDescriptorBase {
|
||||
|
||||
public final void initialize(
|
||||
@NotNull MemberScope unsubstitutedMemberScope,
|
||||
@NotNull Set<ConstructorDescriptor> constructors,
|
||||
@Nullable ConstructorDescriptor primaryConstructor
|
||||
@NotNull Set<ClassConstructorDescriptor> constructors,
|
||||
@Nullable ClassConstructorDescriptor primaryConstructor
|
||||
) {
|
||||
this.unsubstitutedMemberScope = unsubstitutedMemberScope;
|
||||
this.constructors = constructors;
|
||||
@@ -82,7 +82,7 @@ public class ClassDescriptorImpl extends ClassDescriptorBase {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ConstructorDescriptor> getConstructors() {
|
||||
public Collection<ClassConstructorDescriptor> getConstructors() {
|
||||
return constructors;
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public class ClassDescriptorImpl extends ClassDescriptorBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
|
||||
public ClassConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
|
||||
return primaryConstructor;
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -43,7 +43,7 @@ import java.util.*;
|
||||
|
||||
public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
|
||||
private final TypeConstructor typeConstructor;
|
||||
private final ConstructorDescriptor primaryConstructor;
|
||||
private final ClassConstructorDescriptor primaryConstructor;
|
||||
private final MemberScope scope;
|
||||
private final NotNullLazyValue<Set<Name>> enumMemberNames;
|
||||
private final Annotations annotations;
|
||||
@@ -86,7 +86,7 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
|
||||
this.scope = new EnumEntryScope(storageManager);
|
||||
this.enumMemberNames = enumMemberNames;
|
||||
|
||||
ConstructorDescriptorImpl primaryConstructor = DescriptorFactory.createPrimaryConstructorForObject(this, source);
|
||||
ClassConstructorDescriptorImpl primaryConstructor = DescriptorFactory.createPrimaryConstructorForObject(this, source);
|
||||
primaryConstructor.setReturnType(getDefaultType());
|
||||
this.primaryConstructor = primaryConstructor;
|
||||
}
|
||||
@@ -105,7 +105,7 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ConstructorDescriptor> getConstructors() {
|
||||
public Collection<ClassConstructorDescriptor> getConstructors() {
|
||||
return Collections.singleton(primaryConstructor);
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
|
||||
public ClassConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
|
||||
return primaryConstructor;
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -143,11 +143,11 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ConstructorDescriptor> getConstructors() {
|
||||
Collection<ConstructorDescriptor> originalConstructors = original.getConstructors();
|
||||
Collection<ConstructorDescriptor> result = new ArrayList<ConstructorDescriptor>(originalConstructors.size());
|
||||
for (ConstructorDescriptor constructor : originalConstructors) {
|
||||
ConstructorDescriptor copy =
|
||||
public Collection<ClassConstructorDescriptor> getConstructors() {
|
||||
Collection<ClassConstructorDescriptor> originalConstructors = original.getConstructors();
|
||||
Collection<ClassConstructorDescriptor> result = new ArrayList<ClassConstructorDescriptor>(originalConstructors.size());
|
||||
for (ClassConstructorDescriptor constructor : originalConstructors) {
|
||||
ClassConstructorDescriptor copy =
|
||||
constructor.copy(this, constructor.getModality(), constructor.getVisibility(), constructor.getKind(), false);
|
||||
result.add(copy.substitute(getSubstitutor()));
|
||||
}
|
||||
@@ -241,7 +241,7 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
|
||||
public ClassConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
|
||||
return original.getUnsubstitutedPrimaryConstructor();
|
||||
}
|
||||
|
||||
|
||||
+13
-6
@@ -24,8 +24,8 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
interface TypeAliasConstructorDescriptor : FunctionDescriptor {
|
||||
val underlyingConstructorDescriptor: ConstructorDescriptor
|
||||
interface TypeAliasConstructorDescriptor : ConstructorDescriptor {
|
||||
val underlyingConstructorDescriptor: ClassConstructorDescriptor
|
||||
|
||||
override fun getContainingDeclaration(): TypeAliasDescriptor
|
||||
|
||||
@@ -46,7 +46,7 @@ interface TypeAliasConstructorDescriptor : FunctionDescriptor {
|
||||
|
||||
class TypeAliasConstructorDescriptorImpl private constructor(
|
||||
val typeAliasDescriptor: TypeAliasDescriptor,
|
||||
override val underlyingConstructorDescriptor: ConstructorDescriptor,
|
||||
override val underlyingConstructorDescriptor: ClassConstructorDescriptor,
|
||||
original: TypeAliasConstructorDescriptor?,
|
||||
annotations: Annotations,
|
||||
kind: Kind,
|
||||
@@ -54,9 +54,15 @@ class TypeAliasConstructorDescriptorImpl private constructor(
|
||||
) : TypeAliasConstructorDescriptor,
|
||||
FunctionDescriptorImpl(typeAliasDescriptor, original, annotations, Name.special("<init>"), kind, source)
|
||||
{
|
||||
override fun isPrimary(): Boolean =
|
||||
underlyingConstructorDescriptor.isPrimary
|
||||
|
||||
override fun getContainingDeclaration(): TypeAliasDescriptor =
|
||||
typeAliasDescriptor
|
||||
|
||||
override fun getConstructedClass(): ClassDescriptor =
|
||||
underlyingConstructorDescriptor.constructedClass
|
||||
|
||||
override fun getReturnType(): KotlinType =
|
||||
super.getReturnType()!!
|
||||
|
||||
@@ -103,7 +109,7 @@ class TypeAliasConstructorDescriptorImpl private constructor(
|
||||
companion object {
|
||||
fun create(
|
||||
typeAliasDescriptor: TypeAliasDescriptor,
|
||||
constructor: ConstructorDescriptor,
|
||||
constructor: ClassConstructorDescriptor,
|
||||
substitutor: TypeSubstitutor
|
||||
): TypeAliasConstructorDescriptor? {
|
||||
val typeAliasConstructor =
|
||||
@@ -117,9 +123,10 @@ class TypeAliasConstructorDescriptorImpl private constructor(
|
||||
val returnType = substitutor.substitute(constructor.returnType, Variance.INVARIANT)
|
||||
?: return null
|
||||
|
||||
val containingDeclaration = constructor.containingDeclaration as ClassDescriptor
|
||||
val dispatchReceiverParameter =
|
||||
if (constructor.containingDeclaration.isInner)
|
||||
constructor.containingDeclaration.thisAsReceiverParameter
|
||||
if (containingDeclaration.isInner)
|
||||
containingDeclaration.thisAsReceiverParameter
|
||||
else
|
||||
null
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ import static org.jetbrains.kotlin.resolve.DescriptorUtils.getDefaultConstructor
|
||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getBuiltIns;
|
||||
|
||||
public class DescriptorFactory {
|
||||
private static class DefaultConstructorDescriptor extends ConstructorDescriptorImpl {
|
||||
public DefaultConstructorDescriptor(@NotNull ClassDescriptor containingClass, @NotNull SourceElement source) {
|
||||
private static class DefaultClassConstructorDescriptor extends ClassConstructorDescriptorImpl {
|
||||
public DefaultClassConstructorDescriptor(@NotNull ClassDescriptor containingClass, @NotNull SourceElement source) {
|
||||
super(containingClass, null, Annotations.Companion.getEMPTY(), true, Kind.DECLARATION, source);
|
||||
initialize(Collections.<ValueParameterDescriptor>emptyList(),
|
||||
getDefaultConstructorVisibility(containingClass));
|
||||
@@ -116,11 +116,11 @@ public class DescriptorFactory {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConstructorDescriptorImpl createPrimaryConstructorForObject(
|
||||
public static ClassConstructorDescriptorImpl createPrimaryConstructorForObject(
|
||||
@NotNull ClassDescriptor containingClass,
|
||||
@NotNull SourceElement source
|
||||
) {
|
||||
return new DefaultConstructorDescriptor(containingClass, source);
|
||||
return new DefaultClassConstructorDescriptor(containingClass, source);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -41,7 +41,7 @@ fun ClassDescriptor.getClassObjectReferenceTarget(): ClassDescriptor = companion
|
||||
|
||||
fun DeclarationDescriptor.getImportableDescriptor(): DeclarationDescriptor {
|
||||
return when {
|
||||
this is TypeAliasConstructorDescriptor -> typeAliasDescriptor
|
||||
this is TypeAliasConstructorDescriptor -> containingDeclaration
|
||||
this is ConstructorDescriptor -> containingDeclaration
|
||||
this is PropertyAccessorDescriptor -> correspondingProperty
|
||||
else -> this
|
||||
@@ -137,7 +137,7 @@ fun ClassDescriptor.getSuperInterfaces(): List<ClassDescriptor> =
|
||||
else null
|
||||
}
|
||||
|
||||
val ClassDescriptor.secondaryConstructors: List<ConstructorDescriptor>
|
||||
val ClassDescriptor.secondaryConstructors: List<ClassConstructorDescriptor>
|
||||
get() = constructors.filterNot { it.isPrimary }
|
||||
|
||||
val DeclarationDescriptor.builtIns: KotlinBuiltIns
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ConstructorDescriptorImpl;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl;
|
||||
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl;
|
||||
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl;
|
||||
import org.jetbrains.kotlin.incremental.components.LookupLocation;
|
||||
@@ -304,7 +304,8 @@ public class ErrorUtils {
|
||||
super(getErrorModule(), Name.special(name == null ? "<ERROR CLASS>" : "<ERROR CLASS: " + name + ">"),
|
||||
Modality.OPEN, ClassKind.CLASS, Collections.<KotlinType>emptyList(), SourceElement.NO_SOURCE);
|
||||
|
||||
ConstructorDescriptorImpl errorConstructor = ConstructorDescriptorImpl.create(this, Annotations.Companion.getEMPTY(), true, SourceElement.NO_SOURCE);
|
||||
ClassConstructorDescriptorImpl
|
||||
errorConstructor = ClassConstructorDescriptorImpl.create(this, Annotations.Companion.getEMPTY(), true, SourceElement.NO_SOURCE);
|
||||
errorConstructor.initialize(Collections.<ValueParameterDescriptor>emptyList(),
|
||||
Visibilities.INTERNAL);
|
||||
MemberScope memberScope = createErrorScope(getName().asString());
|
||||
@@ -315,7 +316,7 @@ public class ErrorUtils {
|
||||
)
|
||||
);
|
||||
|
||||
initialize(memberScope, Collections.<ConstructorDescriptor>singleton(errorConstructor), errorConstructor);
|
||||
initialize(memberScope, Collections.<ClassConstructorDescriptor>singleton(errorConstructor), errorConstructor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+3
-2
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -25,13 +26,13 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
interface AdditionalClassPartsProvider {
|
||||
fun getSupertypes(classDescriptor: DeserializedClassDescriptor): Collection<KotlinType>
|
||||
fun getFunctions(name: Name, classDescriptor: DeserializedClassDescriptor): Collection<SimpleFunctionDescriptor>
|
||||
fun getConstructors(classDescriptor: DeserializedClassDescriptor): Collection<ConstructorDescriptor>
|
||||
fun getConstructors(classDescriptor: DeserializedClassDescriptor): Collection<ClassConstructorDescriptor>
|
||||
fun getFunctionsNames(classDescriptor: DeserializedClassDescriptor): Collection<Name>
|
||||
|
||||
object None : AdditionalClassPartsProvider {
|
||||
override fun getSupertypes(classDescriptor: DeserializedClassDescriptor): Collection<KotlinType> = emptyList()
|
||||
override fun getFunctions(name: Name, classDescriptor: DeserializedClassDescriptor): Collection<SimpleFunctionDescriptor> = emptyList()
|
||||
override fun getFunctionsNames(classDescriptor: DeserializedClassDescriptor): Collection<Name> = emptyList()
|
||||
override fun getConstructors(classDescriptor: DeserializedClassDescriptor): Collection<ConstructorDescriptor> = emptyList()
|
||||
override fun getConstructors(classDescriptor: DeserializedClassDescriptor): Collection<ClassConstructorDescriptor> = emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -197,9 +197,9 @@ class MemberDeserializer(private val c: DeserializationContext) {
|
||||
return (c.containingDeclaration as? ClassDescriptor)?.thisAsReceiverParameter
|
||||
}
|
||||
|
||||
fun loadConstructor(proto: ProtoBuf.Constructor, isPrimary: Boolean): ConstructorDescriptor {
|
||||
fun loadConstructor(proto: ProtoBuf.Constructor, isPrimary: Boolean): ClassConstructorDescriptor {
|
||||
val classDescriptor = c.containingDeclaration as ClassDescriptor
|
||||
val descriptor = DeserializedConstructorDescriptor(
|
||||
val descriptor = DeserializedClassConstructorDescriptor(
|
||||
classDescriptor, null, getAnnotations(proto, proto.flags, AnnotatedCallableKind.FUNCTION),
|
||||
isPrimary, CallableMemberDescriptor.Kind.DECLARATION, proto, c.nameResolver, c.typeTable, c.containerSource
|
||||
)
|
||||
|
||||
+2
-2
@@ -106,8 +106,8 @@ class NotFoundClasses(private val storageManager: StorageManager, private val mo
|
||||
|
||||
override fun getUnsubstitutedMemberScope() = MemberScope.Empty
|
||||
override fun getStaticScope() = MemberScope.Empty
|
||||
override fun getConstructors(): Collection<ConstructorDescriptor> = emptySet()
|
||||
override fun getUnsubstitutedPrimaryConstructor(): ConstructorDescriptor? = null
|
||||
override fun getConstructors(): Collection<ClassConstructorDescriptor> = emptySet()
|
||||
override fun getUnsubstitutedPrimaryConstructor(): ClassConstructorDescriptor? = null
|
||||
override fun getCompanionObjectDescriptor(): ClassDescriptor? = null
|
||||
|
||||
override fun toString() = "class $name (not found)"
|
||||
|
||||
+4
-4
@@ -101,7 +101,7 @@ class DeserializedClassDescriptor(
|
||||
|
||||
override fun isCompanionObject(): Boolean = Flags.CLASS_KIND.get(classProto.flags) == ProtoBuf.Class.Kind.COMPANION_OBJECT
|
||||
|
||||
private fun computePrimaryConstructor(): ConstructorDescriptor? {
|
||||
private fun computePrimaryConstructor(): ClassConstructorDescriptor? {
|
||||
if (kind.isSingleton) {
|
||||
return DescriptorFactory.createPrimaryConstructorForObject(this, SourceElement.NO_SOURCE).apply {
|
||||
returnType = getDefaultType()
|
||||
@@ -113,13 +113,13 @@ class DeserializedClassDescriptor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getUnsubstitutedPrimaryConstructor(): ConstructorDescriptor? = primaryConstructor()
|
||||
override fun getUnsubstitutedPrimaryConstructor(): ClassConstructorDescriptor? = primaryConstructor()
|
||||
|
||||
private fun computeConstructors(): Collection<ConstructorDescriptor> =
|
||||
private fun computeConstructors(): Collection<ClassConstructorDescriptor> =
|
||||
computeSecondaryConstructors() + unsubstitutedPrimaryConstructor.singletonOrEmptyList() +
|
||||
c.components.additionalClassPartsProvider.getConstructors(this)
|
||||
|
||||
private fun computeSecondaryConstructors(): List<ConstructorDescriptor> =
|
||||
private fun computeSecondaryConstructors(): List<ClassConstructorDescriptor> =
|
||||
classProto.constructorList.filter { Flags.IS_SECONDARY.get(it.flags) }.map {
|
||||
c.memberDeserializer.loadConstructor(it, false)
|
||||
}
|
||||
|
||||
+4
-4
@@ -103,7 +103,7 @@ class DeserializedPropertyDescriptor(
|
||||
}
|
||||
}
|
||||
|
||||
class DeserializedConstructorDescriptor(
|
||||
class DeserializedClassConstructorDescriptor(
|
||||
containingDeclaration: ClassDescriptor,
|
||||
original: ConstructorDescriptor?,
|
||||
annotations: Annotations,
|
||||
@@ -115,7 +115,7 @@ class DeserializedConstructorDescriptor(
|
||||
override val containerSource: SourceElement?,
|
||||
source: SourceElement? = null
|
||||
) : DeserializedCallableMemberDescriptor,
|
||||
ConstructorDescriptorImpl(containingDeclaration, original, annotations, isPrimary, kind, source ?: SourceElement.NO_SOURCE) {
|
||||
ClassConstructorDescriptorImpl(containingDeclaration, original, annotations, isPrimary, kind, source ?: SourceElement.NO_SOURCE) {
|
||||
|
||||
override fun createSubstitutedCopy(
|
||||
newOwner: DeclarationDescriptor,
|
||||
@@ -124,8 +124,8 @@ class DeserializedConstructorDescriptor(
|
||||
newName: Name?,
|
||||
annotations: Annotations,
|
||||
source: SourceElement
|
||||
): DeserializedConstructorDescriptor {
|
||||
return DeserializedConstructorDescriptor(
|
||||
): DeserializedClassConstructorDescriptor {
|
||||
return DeserializedClassConstructorDescriptor(
|
||||
newOwner as ClassDescriptor, original as ConstructorDescriptor?, annotations, isPrimary, kind,
|
||||
proto, nameResolver, typeTable, containerSource, source
|
||||
)
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaConstructorDescriptor
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassConstructorDescriptor
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.load.java.sources.JavaSourceElement
|
||||
@@ -188,7 +188,7 @@ internal object RuntimeTypeMapper {
|
||||
|
||||
return JvmFunctionSignature.JavaMethod(method)
|
||||
}
|
||||
is JavaConstructorDescriptor -> {
|
||||
is JavaClassConstructorDescriptor -> {
|
||||
val constructor = ((function.source as? JavaSourceElement)?.javaElement as? ReflectJavaConstructor)?.member ?:
|
||||
throw KotlinReflectionInternalError("Incorrect resolution sequence for Java constructor $function")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user