ClassDescriptor is now a super-interface for ClassConstructorDescriptor and TypeAliasConstructorDescriptor.
This commit is contained in:
committed by
Dmitry Petrov
parent
7d214c6e58
commit
796d11c860
+11
-5
@@ -23,28 +23,34 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
|
||||
class AccessorForConstructorDescriptor(
|
||||
private val calleeDescriptor: ConstructorDescriptor,
|
||||
private val calleeDescriptor: ClassConstructorDescriptor,
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
private val superCallTarget: ClassDescriptor?
|
||||
) : AbstractAccessorForFunctionDescriptor(containingDeclaration, Name.special("<init>")),
|
||||
ConstructorDescriptor,
|
||||
ClassConstructorDescriptor,
|
||||
AccessorForCallableDescriptor<ConstructorDescriptor> {
|
||||
override fun getCalleeDescriptor(): ConstructorDescriptor = calleeDescriptor
|
||||
|
||||
override fun getContainingDeclaration(): ClassDescriptor = calleeDescriptor.containingDeclaration
|
||||
|
||||
override fun getConstructedClass(): ClassDescriptor = calleeDescriptor.constructedClass
|
||||
|
||||
override fun isPrimary(): Boolean = false
|
||||
|
||||
override fun getReturnType(): KotlinType = super.getReturnType()!!
|
||||
|
||||
override fun getSuperCallTarget(): ClassDescriptor? = superCallTarget
|
||||
|
||||
override fun substitute(substitutor: TypeSubstitutor) = super.substitute(substitutor) as ConstructorDescriptor
|
||||
override fun substitute(substitutor: TypeSubstitutor) = super.substitute(substitutor) as ClassConstructorDescriptor
|
||||
|
||||
override fun copy(
|
||||
newOwner: DeclarationDescriptor?, modality: Modality?, visibility: Visibility?, kind: CallableMemberDescriptor.Kind?, copyOverrides: Boolean
|
||||
newOwner: DeclarationDescriptor,
|
||||
modality: Modality,
|
||||
visibility: Visibility,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
copyOverrides: Boolean
|
||||
): AccessorForConstructorDescriptor {
|
||||
throw UnsupportedOperationException("Trying to copy synthetic accessor $this")
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun getOriginal(): AccessorForConstructorDescriptor = this
|
||||
|
||||
+1
-1
@@ -227,7 +227,7 @@ class DefaultParameterValueSubstitutor(val state: GenerationState) {
|
||||
}
|
||||
|
||||
private fun isEmptyConstructorNeeded(constructorDescriptor: ConstructorDescriptor, classOrObject: KtClassOrObject): Boolean {
|
||||
val classDescriptor = constructorDescriptor.containingDeclaration
|
||||
val classDescriptor = constructorDescriptor.constructedClass
|
||||
if (classDescriptor.kind != ClassKind.CLASS) return false
|
||||
|
||||
if (classOrObject.isLocal()) return false
|
||||
|
||||
@@ -1643,7 +1643,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
|
||||
ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
|
||||
assert primaryConstructor != null : "There should be primary constructor for object literal";
|
||||
ResolvedCall<ConstructorDescriptor> superCall = getDelegationConstructorCall(bindingContext, primaryConstructor);
|
||||
ResolvedCall<ClassConstructorDescriptor> superCall = getDelegationConstructorCall(bindingContext, primaryConstructor);
|
||||
if (superCall != null) {
|
||||
// For an anonymous object, we should also generate all non-default arguments that it captures for its super call
|
||||
ConstructorDescriptor superConstructor = superCall.getResultingDescriptor();
|
||||
@@ -1672,7 +1672,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
argumentGenerator.generate(valueArguments, valueArguments);
|
||||
}
|
||||
|
||||
Collection<ConstructorDescriptor> constructors = classDescriptor.getConstructors();
|
||||
Collection<ClassConstructorDescriptor> constructors = classDescriptor.getConstructors();
|
||||
assert constructors.size() == 1 : "Unexpected number of constructors for class: " + classDescriptor + " " + constructors;
|
||||
ConstructorDescriptor constructorDescriptor = CollectionsKt.single(constructors);
|
||||
|
||||
@@ -3984,11 +3984,11 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConstructorDescriptor getConstructorDescriptor(@NotNull ResolvedCall<?> resolvedCall) {
|
||||
public ClassConstructorDescriptor getConstructorDescriptor(@NotNull ResolvedCall<?> resolvedCall) {
|
||||
FunctionDescriptor accessibleDescriptor = accessibleFunctionDescriptor(resolvedCall);
|
||||
assert accessibleDescriptor instanceof ConstructorDescriptor :
|
||||
"getConstructorDescriptor must be called only for constructors: " + accessibleDescriptor;
|
||||
return (ConstructorDescriptor) accessibleDescriptor;
|
||||
return (ClassConstructorDescriptor) accessibleDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -3999,7 +3999,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
v.anew(objectType);
|
||||
v.dup();
|
||||
|
||||
ConstructorDescriptor constructor = getConstructorDescriptor(resolvedCall);
|
||||
ClassConstructorDescriptor constructor = getConstructorDescriptor(resolvedCall);
|
||||
|
||||
ReceiverParameterDescriptor dispatchReceiver = constructor.getDispatchReceiverParameter();
|
||||
ClassDescriptor containingDeclaration = constructor.getContainingDeclaration();
|
||||
|
||||
@@ -383,7 +383,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
try {
|
||||
lookupConstructorExpressionsInClosureIfPresent();
|
||||
generatePrimaryConstructor(delegationFieldsInfo);
|
||||
for (ConstructorDescriptor secondaryConstructor : DescriptorUtilsKt.getSecondaryConstructors(descriptor)) {
|
||||
for (ClassConstructorDescriptor secondaryConstructor : DescriptorUtilsKt.getSecondaryConstructors(descriptor)) {
|
||||
generateSecondaryConstructor(secondaryConstructor);
|
||||
}
|
||||
}
|
||||
@@ -919,7 +919,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
private void generatePrimaryConstructor(final DelegationFieldsInfo delegationFieldsInfo) {
|
||||
if (isInterface(descriptor) || isAnnotationClass(descriptor)) return;
|
||||
|
||||
final ConstructorDescriptor constructorDescriptor = descriptor.getUnsubstitutedPrimaryConstructor();
|
||||
final ClassConstructorDescriptor constructorDescriptor = descriptor.getUnsubstitutedPrimaryConstructor();
|
||||
if (constructorDescriptor == null) return;
|
||||
|
||||
ConstructorContext constructorContext = context.intoConstructor(constructorDescriptor);
|
||||
@@ -942,7 +942,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
new DefaultParameterValueSubstitutor(state).generatePrimaryConstructorOverloadsIfNeeded(constructorDescriptor, v, this, kind, myClass);
|
||||
}
|
||||
|
||||
private void generateSecondaryConstructor(@NotNull final ConstructorDescriptor constructorDescriptor) {
|
||||
private void generateSecondaryConstructor(@NotNull final ClassConstructorDescriptor constructorDescriptor) {
|
||||
if (!canHaveDeclaredConstructors(descriptor)) return;
|
||||
|
||||
ConstructorContext constructorContext = context.intoConstructor(constructorDescriptor);
|
||||
@@ -969,7 +969,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
|
||||
private void generatePrimaryConstructorImpl(
|
||||
@NotNull ConstructorDescriptor constructorDescriptor,
|
||||
@NotNull ClassConstructorDescriptor constructorDescriptor,
|
||||
@NotNull ExpressionCodegen codegen,
|
||||
@NotNull DelegationFieldsInfo fieldsInfo,
|
||||
@Nullable KtPrimaryConstructor primaryConstructor
|
||||
@@ -1030,7 +1030,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
|
||||
private void generateSecondaryConstructorImpl(
|
||||
@NotNull ConstructorDescriptor constructorDescriptor,
|
||||
@NotNull ClassConstructorDescriptor constructorDescriptor,
|
||||
@NotNull ExpressionCodegen codegen
|
||||
) {
|
||||
InstructionAdapter iv = codegen.v;
|
||||
@@ -1040,7 +1040,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
markLineNumberForConstructor(constructorDescriptor, constructor, codegen);
|
||||
|
||||
ResolvedCall<ConstructorDescriptor> constructorDelegationCall =
|
||||
ResolvedCall<ClassConstructorDescriptor> constructorDelegationCall =
|
||||
getDelegationConstructorCall(bindingContext, constructorDescriptor);
|
||||
ConstructorDescriptor delegateConstructor = constructorDelegationCall == null ? null :
|
||||
constructorDelegationCall.getResultingDescriptor();
|
||||
@@ -1061,7 +1061,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
|
||||
private static void markLineNumberForConstructor(
|
||||
@NotNull ConstructorDescriptor descriptor,
|
||||
@NotNull ClassConstructorDescriptor descriptor,
|
||||
@Nullable KtConstructor constructor,
|
||||
@NotNull ExpressionCodegen codegen
|
||||
) {
|
||||
@@ -1365,8 +1365,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
private void generateDelegatorToConstructorCall(
|
||||
@NotNull InstructionAdapter iv,
|
||||
@NotNull ExpressionCodegen codegen,
|
||||
@NotNull ConstructorDescriptor constructorDescriptor,
|
||||
@Nullable ResolvedCall<ConstructorDescriptor> delegationConstructorCall
|
||||
@NotNull ClassConstructorDescriptor constructorDescriptor,
|
||||
@Nullable ResolvedCall<ClassConstructorDescriptor> delegationConstructorCall
|
||||
) {
|
||||
if (delegationConstructorCall == null) {
|
||||
genSimpleSuperCall(iv);
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorBase;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ConstructorDescriptorImpl;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl;
|
||||
import org.jetbrains.kotlin.descriptors.impl.DeclarationDescriptorImpl;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
||||
@@ -126,13 +126,13 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<ConstructorDescriptor> getConstructors() {
|
||||
public Set<ClassConstructorDescriptor> getConstructors() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
|
||||
public ClassConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
this, Annotations.Companion.getEMPTY(), ModalityKt.isFinalClass(this), typeParameters, supertypes
|
||||
);
|
||||
for (FunctionDescriptor functionDescriptor : getConstructors()) {
|
||||
((ConstructorDescriptorImpl) functionDescriptor).setReturnType(getDefaultType());
|
||||
((ClassConstructorDescriptorImpl) functionDescriptor).setReturnType(getDefaultType());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -449,8 +449,8 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
(FunctionDescriptor) descriptor, contextDescriptor, superCallTarget, nameSuffix
|
||||
);
|
||||
}
|
||||
else if (descriptor instanceof ConstructorDescriptor) {
|
||||
accessor = new AccessorForConstructorDescriptor((ConstructorDescriptor) descriptor, contextDescriptor, superCallTarget);
|
||||
else if (descriptor instanceof ClassConstructorDescriptor) {
|
||||
accessor = new AccessorForConstructorDescriptor((ClassConstructorDescriptor) descriptor, contextDescriptor, superCallTarget);
|
||||
}
|
||||
else if (descriptor instanceof PropertyDescriptor) {
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
|
||||
@@ -584,8 +584,8 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
descriptorContext = ExpressionCodegen.getParentContextSubclassOf((ClassDescriptor) enclosed, this);
|
||||
}
|
||||
|
||||
if (descriptorContext == null && descriptor instanceof ConstructorDescriptor) {
|
||||
ClassDescriptor classDescriptor = ((ConstructorDescriptor) descriptor).getContainingDeclaration();
|
||||
if (descriptorContext == null && descriptor instanceof ClassConstructorDescriptor) {
|
||||
ClassDescriptor classDescriptor = ((ClassConstructorDescriptor) descriptor).getContainingDeclaration();
|
||||
if (DescriptorUtils.isSealedClass(classDescriptor)) {
|
||||
CodegenContext parentContextForClass = findParentContextWithDescriptor(classDescriptor.getContainingDeclaration());
|
||||
if (parentContextForClass != null) {
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ internal class FictitiousArrayConstructor(arrayClass: ClassDescriptor) : SimpleF
|
||||
companion object Factory {
|
||||
@JvmStatic
|
||||
fun create(arrayConstructor: ConstructorDescriptor): FictitiousArrayConstructor {
|
||||
val arrayClass = arrayConstructor.containingDeclaration
|
||||
val arrayClass = arrayConstructor.constructedClass
|
||||
return FictitiousArrayConstructor(arrayClass).apply {
|
||||
this.initialize(null, null, arrayConstructor.typeParameters, arrayConstructor.valueParameters, arrayClass.defaultType,
|
||||
Modality.FINAL, Visibilities.PUBLIC)
|
||||
|
||||
@@ -929,9 +929,9 @@ public class KotlinTypeMapper {
|
||||
? new JvmSignatureWriter()
|
||||
: new BothSignatureWriter(BothSignatureWriter.Mode.METHOD);
|
||||
|
||||
if (f instanceof ConstructorDescriptor) {
|
||||
if (f instanceof ClassConstructorDescriptor) {
|
||||
sw.writeParametersStart();
|
||||
writeAdditionalConstructorParameters((ConstructorDescriptor) f, sw);
|
||||
writeAdditionalConstructorParameters((ClassConstructorDescriptor) f, sw);
|
||||
|
||||
for (ValueParameterDescriptor parameter : valueParameters) {
|
||||
writeParameter(sw, parameter.getType(), f);
|
||||
@@ -1211,7 +1211,7 @@ public class KotlinTypeMapper {
|
||||
sw.writeParameterTypeEnd();
|
||||
}
|
||||
|
||||
private void writeAdditionalConstructorParameters(@NotNull ConstructorDescriptor descriptor, @NotNull JvmSignatureWriter sw) {
|
||||
private void writeAdditionalConstructorParameters(@NotNull ClassConstructorDescriptor descriptor, @NotNull JvmSignatureWriter sw) {
|
||||
MutableClosure closure = bindingContext.get(CodegenBinding.CLOSURE, descriptor.getContainingDeclaration());
|
||||
|
||||
ClassDescriptor captureThis = getDispatchReceiverParameterForConstructorCall(descriptor, closure);
|
||||
@@ -1260,7 +1260,7 @@ public class KotlinTypeMapper {
|
||||
// We may generate a slightly wrong signature for a local class / anonymous object in light classes mode but we don't care,
|
||||
// because such classes are not accessible from the outside world
|
||||
if (classBuilderMode.generateBodies) {
|
||||
ResolvedCall<ConstructorDescriptor> superCall = findFirstDelegatingSuperCall(descriptor);
|
||||
ResolvedCall<ClassConstructorDescriptor> superCall = findFirstDelegatingSuperCall(descriptor);
|
||||
if (superCall == null) return;
|
||||
writeSuperConstructorCallParameters(sw, descriptor, superCall, captureThis != null);
|
||||
}
|
||||
@@ -1268,8 +1268,8 @@ public class KotlinTypeMapper {
|
||||
|
||||
private void writeSuperConstructorCallParameters(
|
||||
@NotNull JvmSignatureWriter sw,
|
||||
@NotNull ConstructorDescriptor descriptor,
|
||||
@NotNull ResolvedCall<ConstructorDescriptor> superCall,
|
||||
@NotNull ClassConstructorDescriptor descriptor,
|
||||
@NotNull ResolvedCall<ClassConstructorDescriptor> superCall,
|
||||
boolean hasOuter
|
||||
) {
|
||||
ConstructorDescriptor superDescriptor = SamCodegenUtil.resolveSamAdapter(superCall.getResultingDescriptor());
|
||||
@@ -1308,10 +1308,10 @@ public class KotlinTypeMapper {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ResolvedCall<ConstructorDescriptor> findFirstDelegatingSuperCall(@NotNull ConstructorDescriptor descriptor) {
|
||||
private ResolvedCall<ClassConstructorDescriptor> findFirstDelegatingSuperCall(@NotNull ClassConstructorDescriptor descriptor) {
|
||||
ClassDescriptor classDescriptor = descriptor.getContainingDeclaration();
|
||||
while (true) {
|
||||
ResolvedCall<ConstructorDescriptor> next = getDelegationConstructorCall(bindingContext, descriptor);
|
||||
ResolvedCall<ClassConstructorDescriptor> next = getDelegationConstructorCall(bindingContext, descriptor);
|
||||
if (next == null) return null;
|
||||
descriptor = next.getResultingDescriptor();
|
||||
if (descriptor.getContainingDeclaration() != classDescriptor) return next;
|
||||
|
||||
+12
-12
@@ -21,14 +21,14 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaConstructorDescriptor;
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassConstructorDescriptor;
|
||||
import org.jetbrains.kotlin.load.java.descriptors.SamAdapterDescriptor;
|
||||
|
||||
/* package */ class SamAdapterConstructorDescriptor extends JavaConstructorDescriptor
|
||||
implements SamAdapterDescriptor<JavaConstructorDescriptor> {
|
||||
private final JavaConstructorDescriptor declaration;
|
||||
/* package */ class SamAdapterClassConstructorDescriptor extends JavaClassConstructorDescriptor
|
||||
implements SamAdapterDescriptor<JavaClassConstructorDescriptor> {
|
||||
private final JavaClassConstructorDescriptor declaration;
|
||||
|
||||
public SamAdapterConstructorDescriptor(@NotNull JavaConstructorDescriptor declaration) {
|
||||
public SamAdapterClassConstructorDescriptor(@NotNull JavaClassConstructorDescriptor declaration) {
|
||||
super(declaration.getContainingDeclaration(), null, declaration.getAnnotations(),
|
||||
declaration.isPrimary(), Kind.SYNTHESIZED, declaration.getSource());
|
||||
this.declaration = declaration;
|
||||
@@ -36,14 +36,14 @@ import org.jetbrains.kotlin.load.java.descriptors.SamAdapterDescriptor;
|
||||
setHasSynthesizedParameterNames(declaration.hasSynthesizedParameterNames());
|
||||
}
|
||||
|
||||
private SamAdapterConstructorDescriptor(
|
||||
private SamAdapterClassConstructorDescriptor(
|
||||
@NotNull ClassDescriptor containingDeclaration,
|
||||
@Nullable JavaConstructorDescriptor original,
|
||||
@Nullable JavaClassConstructorDescriptor original,
|
||||
@NotNull Annotations annotations,
|
||||
boolean isPrimary,
|
||||
@NotNull Kind kind,
|
||||
@NotNull SourceElement source,
|
||||
@NotNull JavaConstructorDescriptor declaration
|
||||
@NotNull JavaClassConstructorDescriptor declaration
|
||||
) {
|
||||
super(containingDeclaration, original, annotations, isPrimary, kind, source);
|
||||
this.declaration = declaration;
|
||||
@@ -51,19 +51,19 @@ import org.jetbrains.kotlin.load.java.descriptors.SamAdapterDescriptor;
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
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 SamAdapterConstructorDescriptor(newOwner, original, annotations, isPrimary, kind, sourceElement, declaration);
|
||||
return new SamAdapterClassConstructorDescriptor(newOwner, original, annotations, isPrimary, kind, sourceElement, declaration);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JavaConstructorDescriptor getBaseDescriptorForSynthetic() {
|
||||
public JavaClassConstructorDescriptor getBaseDescriptorForSynthetic() {
|
||||
return declaration;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.load.java.components.SamConversionResolver
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
|
||||
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.SamConstructorDescriptor
|
||||
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaClassDescriptor
|
||||
@@ -38,7 +38,7 @@ object SamConversionResolverImpl : SamConversionResolver {
|
||||
override fun <D : FunctionDescriptor> resolveSamAdapter(original: D): D? {
|
||||
return when {
|
||||
!SingleAbstractMethodUtils.isSamAdapterNecessary(original) -> null
|
||||
original is JavaConstructorDescriptor -> SingleAbstractMethodUtils.createSamAdapterConstructor(original) as D
|
||||
original is JavaClassConstructorDescriptor -> SingleAbstractMethodUtils.createSamAdapterConstructor(original) as D
|
||||
original is JavaMethodDescriptor -> SingleAbstractMethodUtils.createSamAdapterFunction(original) as D
|
||||
else -> null
|
||||
}
|
||||
|
||||
+3
-3
@@ -205,8 +205,8 @@ public class SingleAbstractMethodUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static SamAdapterDescriptor<JavaConstructorDescriptor> createSamAdapterConstructor(@NotNull final JavaConstructorDescriptor original) {
|
||||
final SamAdapterConstructorDescriptor result = new SamAdapterConstructorDescriptor(original);
|
||||
public static SamAdapterDescriptor<JavaClassConstructorDescriptor> createSamAdapterConstructor(@NotNull final JavaClassConstructorDescriptor original) {
|
||||
final SamAdapterClassConstructorDescriptor result = new SamAdapterClassConstructorDescriptor(original);
|
||||
return initSamAdapter(original, result, new FunctionInitializer() {
|
||||
@Override
|
||||
public void initialize(
|
||||
@@ -277,7 +277,7 @@ public class SingleAbstractMethodUtils {
|
||||
@NotNull List<TypeParameterDescriptor> originalParameters,
|
||||
@Nullable DeclarationDescriptor newOwner
|
||||
) {
|
||||
if (newOwner instanceof SamAdapterConstructorDescriptor) {
|
||||
if (newOwner instanceof SamAdapterClassConstructorDescriptor) {
|
||||
return new TypeParameters(originalParameters, TypeSubstitutor.EMPTY);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory0
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.load.java.components.JavaAnnotationMapper
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaConstructorDescriptor
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassConstructorDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
class JavaAnnotationCallChecker : CallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
val resultingDescriptor = resolvedCall.resultingDescriptor.original
|
||||
if (resultingDescriptor !is JavaConstructorDescriptor ||
|
||||
if (resultingDescriptor !is JavaClassConstructorDescriptor ||
|
||||
resultingDescriptor.containingDeclaration.kind != ClassKind.ANNOTATION_CLASS) return
|
||||
|
||||
reportErrorsOnPositionedArguments(resolvedCall, context)
|
||||
|
||||
@@ -169,7 +169,7 @@ public class AnnotationResolver {
|
||||
if (!ErrorUtils.isError(descriptor)) {
|
||||
if (descriptor instanceof ConstructorDescriptor) {
|
||||
ConstructorDescriptor constructor = (ConstructorDescriptor)descriptor;
|
||||
ClassDescriptor classDescriptor = constructor.getContainingDeclaration();
|
||||
ClassDescriptor classDescriptor = constructor.getConstructedClass();
|
||||
if (classDescriptor.getKind() != ClassKind.ANNOTATION_CLASS) {
|
||||
trace.report(NOT_AN_ANNOTATION_CLASS.on(entryElement, classDescriptor));
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ public interface BindingContext {
|
||||
*/
|
||||
WritableSlice<PsiElement, SimpleFunctionDescriptor> FUNCTION = Slices.createSimpleSlice();
|
||||
WritableSlice<PsiElement, ConstructorDescriptor> CONSTRUCTOR = Slices.createSimpleSlice();
|
||||
WritableSlice<ConstructorDescriptor, ResolvedCall<ConstructorDescriptor>> CONSTRUCTOR_RESOLVED_DELEGATION_CALL =
|
||||
WritableSlice<ConstructorDescriptor, ResolvedCall<ClassConstructorDescriptor>> CONSTRUCTOR_RESOLVED_DELEGATION_CALL =
|
||||
Slices.createSimpleSlice();
|
||||
WritableSlice<PsiElement, VariableDescriptor> VARIABLE = Slices.createSimpleSlice();
|
||||
WritableSlice<KtParameter, VariableDescriptor> VALUE_PARAMETER = Slices.createSimpleSlice();
|
||||
|
||||
@@ -222,7 +222,7 @@ public class BindingContextUtils {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ResolvedCall<ConstructorDescriptor> getDelegationConstructorCall(
|
||||
public static ResolvedCall<ClassConstructorDescriptor> getDelegationConstructorCall(
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull ConstructorDescriptor constructorDescriptor
|
||||
) {
|
||||
|
||||
@@ -38,7 +38,7 @@ public interface BodiesResolveContext {
|
||||
@Mutable
|
||||
Map<KtAnonymousInitializer, ClassDescriptorWithResolutionScopes> getAnonymousInitializers();
|
||||
@Mutable
|
||||
Map<KtSecondaryConstructor, ConstructorDescriptor> getSecondaryConstructors();
|
||||
Map<KtSecondaryConstructor, ClassConstructorDescriptor> getSecondaryConstructors();
|
||||
@Mutable
|
||||
Map<KtScript, LazyScriptDescriptor> getScripts();
|
||||
|
||||
|
||||
@@ -122,14 +122,14 @@ public class BodyResolver {
|
||||
}
|
||||
|
||||
private void resolveSecondaryConstructors(@NotNull BodiesResolveContext c) {
|
||||
for (Map.Entry<KtSecondaryConstructor, ConstructorDescriptor> entry : c.getSecondaryConstructors().entrySet()) {
|
||||
for (Map.Entry<KtSecondaryConstructor, ClassConstructorDescriptor> entry : c.getSecondaryConstructors().entrySet()) {
|
||||
LexicalScope declaringScope = c.getDeclaringScope(entry.getKey());
|
||||
assert declaringScope != null : "Declaring scope should be registered before body resolve";
|
||||
resolveSecondaryConstructorBody(c.getOuterDataFlowInfo(), trace, entry.getKey(), entry.getValue(), declaringScope);
|
||||
}
|
||||
if (c.getSecondaryConstructors().isEmpty()) return;
|
||||
Set<ConstructorDescriptor> visitedConstructors = Sets.newHashSet();
|
||||
for (Map.Entry<KtSecondaryConstructor, ConstructorDescriptor> entry : c.getSecondaryConstructors().entrySet()) {
|
||||
for (Map.Entry<KtSecondaryConstructor, ClassConstructorDescriptor> entry : c.getSecondaryConstructors().entrySet()) {
|
||||
checkCyclicConstructorDelegationCall(entry.getValue(), visitedConstructors);
|
||||
}
|
||||
}
|
||||
@@ -138,7 +138,7 @@ public class BodyResolver {
|
||||
@NotNull final DataFlowInfo outerDataFlowInfo,
|
||||
@NotNull final BindingTrace trace,
|
||||
@NotNull final KtSecondaryConstructor constructor,
|
||||
@NotNull final ConstructorDescriptor descriptor,
|
||||
@NotNull final ClassConstructorDescriptor descriptor,
|
||||
@NotNull LexicalScope declaringScope
|
||||
) {
|
||||
ForceResolveUtil.forceResolveAllContents(descriptor.getAnnotations());
|
||||
@@ -167,7 +167,7 @@ public class BodyResolver {
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull LexicalScope scope,
|
||||
@NotNull KtSecondaryConstructor constructor,
|
||||
@NotNull ConstructorDescriptor descriptor
|
||||
@NotNull ClassConstructorDescriptor descriptor
|
||||
) {
|
||||
OverloadResolutionResults<?> results = callResolver.resolveConstructorDelegationCall(
|
||||
trace, scope, outerDataFlowInfo,
|
||||
@@ -231,7 +231,7 @@ public class BodyResolver {
|
||||
|
||||
@Nullable
|
||||
private ConstructorDescriptor getDelegatedConstructor(@NotNull ConstructorDescriptor constructor) {
|
||||
ResolvedCall<ConstructorDescriptor> call = trace.get(CONSTRUCTOR_RESOLVED_DELEGATION_CALL, constructor);
|
||||
ResolvedCall<ClassConstructorDescriptor> call = trace.get(CONSTRUCTOR_RESOLVED_DELEGATION_CALL, constructor);
|
||||
return call == null || !call.getStatus().isSuccess() ? null : call.getResultingDescriptor().getOriginal();
|
||||
}
|
||||
|
||||
@@ -430,7 +430,7 @@ public class BodyResolver {
|
||||
@NotNull ResolvedCall<?> call
|
||||
) {
|
||||
//noinspection unchecked
|
||||
trace.record(CONSTRUCTOR_RESOLVED_DELEGATION_CALL, constructor, (ResolvedCall<ConstructorDescriptor>) call);
|
||||
trace.record(CONSTRUCTOR_RESOLVED_DELEGATION_CALL, constructor, (ResolvedCall<ClassConstructorDescriptor>) call);
|
||||
}
|
||||
|
||||
private void checkSupertypeList(
|
||||
|
||||
@@ -217,7 +217,7 @@ class DeclarationsChecker(
|
||||
TypeAliasExpander(reportStrategy).expandWithoutAbbreviation(typeAliasExpansion, Annotations.EMPTY)
|
||||
}
|
||||
|
||||
private fun checkConstructorDeclaration(constructorDescriptor: ConstructorDescriptor, declaration: KtDeclaration) {
|
||||
private fun checkConstructorDeclaration(constructorDescriptor: ClassConstructorDescriptor, declaration: KtDeclaration) {
|
||||
declaration.checkTypeReferences()
|
||||
modifiersChecker.checkModifiersForDeclaration(declaration, constructorDescriptor)
|
||||
identifierChecker.checkDeclaration(declaration, trace)
|
||||
@@ -225,7 +225,7 @@ class DeclarationsChecker(
|
||||
checkConstructorVisibility(constructorDescriptor, declaration)
|
||||
}
|
||||
|
||||
private fun checkConstructorVisibility(constructorDescriptor: ConstructorDescriptor, declaration: KtDeclaration) {
|
||||
private fun checkConstructorVisibility(constructorDescriptor: ClassConstructorDescriptor, declaration: KtDeclaration) {
|
||||
val visibilityModifier = declaration.visibilityModifier()
|
||||
if (visibilityModifier != null && visibilityModifier.node?.elementType != KtTokens.PRIVATE_KEYWORD) {
|
||||
val classDescriptor = constructorDescriptor.containingDeclaration
|
||||
|
||||
@@ -396,12 +396,12 @@ public class DescriptorResolver {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConstructorDescriptorImpl createAndRecordPrimaryConstructorForObject(
|
||||
public static ClassConstructorDescriptorImpl createAndRecordPrimaryConstructorForObject(
|
||||
@Nullable KtClassOrObject object,
|
||||
@NotNull ClassDescriptor classDescriptor,
|
||||
@NotNull BindingTrace trace
|
||||
) {
|
||||
ConstructorDescriptorImpl constructorDescriptor =
|
||||
ClassConstructorDescriptorImpl constructorDescriptor =
|
||||
DescriptorFactory.createPrimaryConstructorForObject(classDescriptor, KotlinSourceElementKt.toSourceElement(object));
|
||||
if (object != null) {
|
||||
KtPrimaryConstructor primaryConstructor = object.getPrimaryConstructor();
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.resolve
|
||||
import org.jetbrains.kotlin.builtins.*
|
||||
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.FunctionExpressionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||
@@ -239,7 +239,7 @@ class FunctionDescriptorResolver(
|
||||
classDescriptor: ClassDescriptor,
|
||||
classElement: KtClassOrObject,
|
||||
trace: BindingTrace
|
||||
): ConstructorDescriptorImpl? {
|
||||
): ClassConstructorDescriptorImpl? {
|
||||
if (classDescriptor.getKind() == ClassKind.ENUM_ENTRY || !classElement.hasPrimaryConstructor()) return null
|
||||
return createConstructorDescriptor(
|
||||
scope,
|
||||
@@ -257,7 +257,7 @@ class FunctionDescriptorResolver(
|
||||
classDescriptor: ClassDescriptor,
|
||||
constructor: KtSecondaryConstructor,
|
||||
trace: BindingTrace
|
||||
): ConstructorDescriptorImpl {
|
||||
): ClassConstructorDescriptorImpl {
|
||||
return createConstructorDescriptor(
|
||||
scope,
|
||||
classDescriptor,
|
||||
@@ -277,8 +277,8 @@ class FunctionDescriptorResolver(
|
||||
declarationToTrace: KtDeclaration,
|
||||
valueParameters: List<KtParameter>,
|
||||
trace: BindingTrace
|
||||
): ConstructorDescriptorImpl {
|
||||
val constructorDescriptor = ConstructorDescriptorImpl.create(
|
||||
): ClassConstructorDescriptorImpl {
|
||||
val constructorDescriptor = ClassConstructorDescriptorImpl.create(
|
||||
classDescriptor,
|
||||
annotationResolver.resolveAnnotationsWithoutArguments(scope, modifierList, trace),
|
||||
isPrimary,
|
||||
|
||||
@@ -147,7 +147,7 @@ class LazyTopDownAnalyzer(
|
||||
}
|
||||
|
||||
override fun visitSecondaryConstructor(constructor: KtSecondaryConstructor) {
|
||||
c.secondaryConstructors.put(constructor, lazyDeclarationResolver.resolveToDescriptor(constructor) as ConstructorDescriptor)
|
||||
c.secondaryConstructors.put(constructor, lazyDeclarationResolver.resolveToDescriptor(constructor) as ClassConstructorDescriptor)
|
||||
}
|
||||
|
||||
override fun visitEnumEntry(enumEntry: KtEnumEntry) {
|
||||
|
||||
@@ -40,7 +40,7 @@ public class TopDownAnalysisContext implements BodiesResolveContext {
|
||||
private final Map<KtClassOrObject, ClassDescriptorWithResolutionScopes> classes = Maps.newLinkedHashMap();
|
||||
private final Map<KtAnonymousInitializer, ClassDescriptorWithResolutionScopes> anonymousInitializers = Maps.newLinkedHashMap();
|
||||
private final Set<KtFile> files = new LinkedHashSet<KtFile>();
|
||||
private final Map<KtSecondaryConstructor, ConstructorDescriptor> secondaryConstructors = Maps.newLinkedHashMap();
|
||||
private final Map<KtSecondaryConstructor, ClassConstructorDescriptor> secondaryConstructors = Maps.newLinkedHashMap();
|
||||
|
||||
private final Map<KtNamedFunction, SimpleFunctionDescriptor> functions = Maps.newLinkedHashMap();
|
||||
private final Map<KtProperty, PropertyDescriptor> properties = Maps.newLinkedHashMap();
|
||||
@@ -101,7 +101,7 @@ public class TopDownAnalysisContext implements BodiesResolveContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<KtSecondaryConstructor, ConstructorDescriptor> getSecondaryConstructors() {
|
||||
public Map<KtSecondaryConstructor, ClassConstructorDescriptor> getSecondaryConstructors() {
|
||||
return secondaryConstructors;
|
||||
}
|
||||
|
||||
|
||||
@@ -280,7 +280,7 @@ public class CallResolver {
|
||||
DeclarationDescriptor container = context.scope.getOwnerDescriptor();
|
||||
assert container instanceof ConstructorDescriptor : "Trying to resolve JetConstructorDelegationCall not in constructor. scope.ownerDescriptor = " + container;
|
||||
return (OverloadResolutionResults) resolveConstructorDelegationCall(context, delegationCall, (KtConstructorDelegationReferenceExpression) calleeExpression,
|
||||
(ConstructorDescriptor) container);
|
||||
(ClassConstructorDescriptor) container);
|
||||
}
|
||||
else if (calleeExpression == null) {
|
||||
return checkArgumentTypesAndFail(context);
|
||||
@@ -308,7 +308,7 @@ public class CallResolver {
|
||||
return resolveCallForInvoke(context.replaceCall(call), tracingForInvoke);
|
||||
}
|
||||
|
||||
private OverloadResolutionResults<ConstructorDescriptor> resolveCallForConstructor(
|
||||
private OverloadResolutionResults<ClassConstructorDescriptor> resolveCallForConstructor(
|
||||
@NotNull BasicCallResolutionContext context,
|
||||
@NotNull KtConstructorCalleeExpression expression
|
||||
) {
|
||||
@@ -335,25 +335,25 @@ public class CallResolver {
|
||||
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) declarationDescriptor;
|
||||
|
||||
Collection<ConstructorDescriptor> constructors = classDescriptor.getConstructors();
|
||||
Collection<ClassConstructorDescriptor> constructors = classDescriptor.getConstructors();
|
||||
if (constructors.isEmpty()) {
|
||||
context.trace.report(NO_CONSTRUCTOR.on(CallUtilKt.getValueArgumentListOrElement(context.call)));
|
||||
return checkArgumentTypesAndFail(context);
|
||||
}
|
||||
|
||||
Pair<Collection<ResolutionCandidate<ConstructorDescriptor>>, BasicCallResolutionContext> candidatesAndContext =
|
||||
Pair<Collection<ResolutionCandidate<ClassConstructorDescriptor>>, BasicCallResolutionContext> candidatesAndContext =
|
||||
prepareCandidatesAndContextForConstructorCall(constructedType, context);
|
||||
|
||||
Collection<ResolutionCandidate<ConstructorDescriptor>> candidates = candidatesAndContext.getFirst();
|
||||
Collection<ResolutionCandidate<ClassConstructorDescriptor>> candidates = candidatesAndContext.getFirst();
|
||||
context = candidatesAndContext.getSecond();
|
||||
|
||||
return computeTasksFromCandidatesAndResolvedCall(context, functionReference, candidates);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public OverloadResolutionResults<ConstructorDescriptor> resolveConstructorDelegationCall(
|
||||
public OverloadResolutionResults<ClassConstructorDescriptor> resolveConstructorDelegationCall(
|
||||
@NotNull BindingTrace trace, @NotNull LexicalScope scope, @NotNull DataFlowInfo dataFlowInfo,
|
||||
@NotNull ConstructorDescriptor constructorDescriptor,
|
||||
@NotNull ClassConstructorDescriptor constructorDescriptor,
|
||||
@NotNull KtConstructorDelegationCall call
|
||||
) {
|
||||
// Method returns `null` when there is nothing to resolve in trivial cases like `null` call expression or
|
||||
@@ -368,7 +368,7 @@ public class CallResolver {
|
||||
|
||||
if (call.getCalleeExpression() == null) return checkArgumentTypesAndFail(context);
|
||||
|
||||
if (constructorDescriptor.getContainingDeclaration().getKind() == ClassKind.ENUM_CLASS && call.isImplicit()) {
|
||||
if (constructorDescriptor.getConstructedClass().getKind() == ClassKind.ENUM_CLASS && call.isImplicit()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -381,11 +381,11 @@ public class CallResolver {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private OverloadResolutionResults<ConstructorDescriptor> resolveConstructorDelegationCall(
|
||||
private OverloadResolutionResults<ClassConstructorDescriptor> resolveConstructorDelegationCall(
|
||||
@NotNull BasicCallResolutionContext context,
|
||||
@NotNull KtConstructorDelegationCall call,
|
||||
@NotNull KtConstructorDelegationReferenceExpression calleeExpression,
|
||||
@NotNull ConstructorDescriptor calleeConstructor
|
||||
@NotNull ClassConstructorDescriptor calleeConstructor
|
||||
) {
|
||||
context.trace.record(BindingContext.LEXICAL_SCOPE, call, context.scope);
|
||||
|
||||
@@ -399,7 +399,7 @@ public class CallResolver {
|
||||
|
||||
ClassDescriptor delegateClassDescriptor = isThisCall ? currentClassDescriptor :
|
||||
DescriptorUtilsKt.getSuperClassOrAny(currentClassDescriptor);
|
||||
Collection<ConstructorDescriptor> constructors = delegateClassDescriptor.getConstructors();
|
||||
Collection<ClassConstructorDescriptor> constructors = delegateClassDescriptor.getConstructors();
|
||||
|
||||
if (!isThisCall && currentClassDescriptor.getUnsubstitutedPrimaryConstructor() != null) {
|
||||
if (DescriptorUtils.canHaveDeclaredConstructors(currentClassDescriptor)) {
|
||||
@@ -421,9 +421,9 @@ public class CallResolver {
|
||||
calleeConstructor.getContainingDeclaration().getDefaultType() :
|
||||
DescriptorUtils.getSuperClassType(currentClassDescriptor);
|
||||
|
||||
Pair<Collection<ResolutionCandidate<ConstructorDescriptor>>, BasicCallResolutionContext> candidatesAndContext =
|
||||
Pair<Collection<ResolutionCandidate<ClassConstructorDescriptor>>, BasicCallResolutionContext> candidatesAndContext =
|
||||
prepareCandidatesAndContextForConstructorCall(superType, context);
|
||||
Collection<ResolutionCandidate<ConstructorDescriptor>> candidates = candidatesAndContext.getFirst();
|
||||
Collection<ResolutionCandidate<ClassConstructorDescriptor>> candidates = candidatesAndContext.getFirst();
|
||||
context = candidatesAndContext.getSecond();
|
||||
|
||||
TracingStrategy tracing = call.isImplicit() ?
|
||||
@@ -442,13 +442,13 @@ public class CallResolver {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Pair<Collection<ResolutionCandidate<ConstructorDescriptor>>, BasicCallResolutionContext> prepareCandidatesAndContextForConstructorCall(
|
||||
private static Pair<Collection<ResolutionCandidate<ClassConstructorDescriptor>>, BasicCallResolutionContext> prepareCandidatesAndContextForConstructorCall(
|
||||
@NotNull KotlinType superType,
|
||||
@NotNull BasicCallResolutionContext context
|
||||
) {
|
||||
if (!(superType.getConstructor().getDeclarationDescriptor() instanceof ClassDescriptor)) {
|
||||
return new Pair<Collection<ResolutionCandidate<ConstructorDescriptor>>, BasicCallResolutionContext>(
|
||||
Collections.<ResolutionCandidate<ConstructorDescriptor>>emptyList(), context);
|
||||
return new Pair<Collection<ResolutionCandidate<ClassConstructorDescriptor>>, BasicCallResolutionContext>(
|
||||
Collections.<ResolutionCandidate<ClassConstructorDescriptor>>emptyList(), context);
|
||||
}
|
||||
|
||||
ClassDescriptor superClass = (ClassDescriptor) superType.getConstructor().getDeclarationDescriptor();
|
||||
@@ -463,10 +463,10 @@ public class CallResolver {
|
||||
context = context.replaceExpectedType(superType);
|
||||
}
|
||||
|
||||
Collection<ResolutionCandidate<ConstructorDescriptor>> candidates =
|
||||
Collection<ResolutionCandidate<ClassConstructorDescriptor>> candidates =
|
||||
CallResolverUtilKt.createResolutionCandidatesForConstructors(context.scope, context.call, superClass, knownTypeParametersSubstitutor);
|
||||
|
||||
return new Pair<Collection<ResolutionCandidate<ConstructorDescriptor>>, BasicCallResolutionContext>(candidates, context);
|
||||
return new Pair<Collection<ResolutionCandidate<ClassConstructorDescriptor>>, BasicCallResolutionContext>(candidates, context);
|
||||
}
|
||||
|
||||
private static boolean anyConstructorHasDeclaredTypeParameters(@Nullable ClassifierDescriptor classDescriptor) {
|
||||
|
||||
@@ -202,7 +202,7 @@ fun createResolutionCandidatesForConstructors(
|
||||
call: Call,
|
||||
classWithConstructors: ClassDescriptor,
|
||||
knownSubstitutor: TypeSubstitutor? = null
|
||||
): Collection<ResolutionCandidate<ConstructorDescriptor>> {
|
||||
): Collection<ResolutionCandidate<ClassConstructorDescriptor>> {
|
||||
val constructors = classWithConstructors.constructors
|
||||
|
||||
if (constructors.isEmpty()) return emptyList()
|
||||
|
||||
@@ -240,7 +240,7 @@ class CandidateResolver(
|
||||
val dispatchReceiver = candidateCall.dispatchReceiver
|
||||
if (dispatchReceiver != null) {
|
||||
var nestedClass: ClassDescriptor? = null
|
||||
if (candidateDescriptor is ConstructorDescriptor
|
||||
if (candidateDescriptor is ClassConstructorDescriptor
|
||||
&& DescriptorUtils.isStaticNestedClass(candidateDescriptor.containingDeclaration)
|
||||
) {
|
||||
nestedClass = candidateDescriptor.containingDeclaration
|
||||
@@ -285,7 +285,7 @@ class CandidateResolver(
|
||||
if (expression is KtSimpleNameExpression) {
|
||||
// 'B' in 'class A: B()' is JetConstructorCalleeExpression
|
||||
if (descriptor is ConstructorDescriptor) {
|
||||
val modality = descriptor.containingDeclaration.modality
|
||||
val modality = descriptor.constructedClass.modality
|
||||
if (modality == Modality.ABSTRACT) {
|
||||
tracing.instantiationOfAbstractClass(trace)
|
||||
}
|
||||
|
||||
+2
-1
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.resolve.calls.checkers
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
@@ -47,7 +48,7 @@ object ConstructorHeaderCallChecker : CallChecker {
|
||||
|
||||
if (context.scope.parentsWithSelf.any { scope ->
|
||||
scope is LexicalScope && scope.kind == LexicalScopeKind.CONSTRUCTOR_HEADER &&
|
||||
(scope.ownerDescriptor as ConstructorDescriptor).containingDeclaration in classes
|
||||
(scope.ownerDescriptor as ClassConstructorDescriptor).containingDeclaration in classes
|
||||
}) {
|
||||
context.trace.report(Errors.INSTANCE_ACCESS_BEFORE_SUPER_CALL.on(reportOn, resolvedCall.resultingDescriptor))
|
||||
}
|
||||
|
||||
+1
-1
@@ -625,7 +625,7 @@ private class ConstantExpressionEvaluatorVisitor(
|
||||
|
||||
// Ann()
|
||||
if (resultingDescriptor is ConstructorDescriptor) {
|
||||
val classDescriptor: ClassDescriptor = resultingDescriptor.containingDeclaration
|
||||
val classDescriptor: ClassDescriptor = resultingDescriptor.constructedClass
|
||||
if (DescriptorUtils.isAnnotationClass(classDescriptor)) {
|
||||
val descriptor = AnnotationDescriptorImpl(
|
||||
classDescriptor.defaultType,
|
||||
|
||||
@@ -160,7 +160,7 @@ public class InlineUtil {
|
||||
public static boolean isArrayConstructorWithLambda(@NotNull CallableDescriptor descriptor) {
|
||||
return descriptor.getValueParameters().size() == 2 &&
|
||||
descriptor instanceof ConstructorDescriptor &&
|
||||
KotlinBuiltIns.isArrayOrPrimitiveArray(((ConstructorDescriptor) descriptor).getContainingDeclaration());
|
||||
KotlinBuiltIns.isArrayOrPrimitiveArray(((ConstructorDescriptor) descriptor).getConstructedClass());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+2
-2
@@ -376,12 +376,12 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ConstructorDescriptor> getConstructors() {
|
||||
public Collection<ClassConstructorDescriptor> getConstructors() {
|
||||
return unsubstitutedMemberScope.getConstructors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
|
||||
public ClassConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
|
||||
return unsubstitutedMemberScope.getPrimaryConstructor();
|
||||
}
|
||||
|
||||
|
||||
+8
-8
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.DELEGATION
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.FAKE_OVERRIDE
|
||||
import org.jetbrains.kotlin.descriptors.impl.ConstructorDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
@@ -88,7 +88,7 @@ open class LazyClassMemberScope(
|
||||
fun extract(extractFrom: KotlinType, name: Name): Collection<T>
|
||||
}
|
||||
|
||||
private val primaryConstructor: NullableLazyValue<ConstructorDescriptor>
|
||||
private val primaryConstructor: NullableLazyValue<ClassConstructorDescriptor>
|
||||
= c.storageManager.createNullableLazyValue { resolvePrimaryConstructor() }
|
||||
|
||||
override fun getScopeForMemberDeclarationResolution(declaration: KtDeclaration): LexicalScope {
|
||||
@@ -292,18 +292,18 @@ open class LazyClassMemberScope(
|
||||
result.addAll(getContributedFunctions(Name.identifier("copy"), location))
|
||||
}
|
||||
|
||||
private val secondaryConstructors: NotNullLazyValue<Collection<ConstructorDescriptor>>
|
||||
private val secondaryConstructors: NotNullLazyValue<Collection<ClassConstructorDescriptor>>
|
||||
= c.storageManager.createLazyValue { resolveSecondaryConstructors() }
|
||||
|
||||
fun getConstructors(): Collection<ConstructorDescriptor> {
|
||||
fun getConstructors(): Collection<ClassConstructorDescriptor> {
|
||||
val result = secondaryConstructors()
|
||||
val primaryConstructor = getPrimaryConstructor()
|
||||
return if (primaryConstructor == null) result else result + primaryConstructor
|
||||
}
|
||||
|
||||
fun getPrimaryConstructor(): ConstructorDescriptor? = primaryConstructor()
|
||||
fun getPrimaryConstructor(): ClassConstructorDescriptor? = primaryConstructor()
|
||||
|
||||
protected open fun resolvePrimaryConstructor(): ConstructorDescriptor? {
|
||||
protected open fun resolvePrimaryConstructor(): ClassConstructorDescriptor? {
|
||||
val ownerInfo = declarationProvider.getOwnerInfo()
|
||||
val classOrObject = ownerInfo.correspondingClassOrObject ?: return null
|
||||
|
||||
@@ -324,7 +324,7 @@ open class LazyClassMemberScope(
|
||||
}
|
||||
}
|
||||
|
||||
private fun resolveSecondaryConstructors(): Collection<ConstructorDescriptor> {
|
||||
private fun resolveSecondaryConstructors(): Collection<ClassConstructorDescriptor> {
|
||||
val classOrObject = declarationProvider.getOwnerInfo().correspondingClassOrObject ?: return emptyList()
|
||||
|
||||
return classOrObject.getSecondaryConstructors().map { constructor ->
|
||||
@@ -336,7 +336,7 @@ open class LazyClassMemberScope(
|
||||
}
|
||||
}
|
||||
|
||||
protected fun setDeferredReturnType(descriptor: ConstructorDescriptorImpl) {
|
||||
protected fun setDeferredReturnType(descriptor: ClassConstructorDescriptorImpl) {
|
||||
descriptor.returnType = DeferredType.create(c.storageManager, trace, { thisDescriptor.getDefaultType() })
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.resolve.lazy.descriptors
|
||||
|
||||
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.PropertyDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
@@ -37,8 +37,8 @@ class LazyScriptClassMemberScope(
|
||||
trace: BindingTrace)
|
||||
: LazyClassMemberScope(resolveSession, declarationProvider, scriptDescriptor, trace) {
|
||||
|
||||
override fun resolvePrimaryConstructor(): ConstructorDescriptor? {
|
||||
val constructor = ConstructorDescriptorImpl.create(
|
||||
override fun resolvePrimaryConstructor(): ClassConstructorDescriptor? {
|
||||
val constructor = ClassConstructorDescriptorImpl.create(
|
||||
scriptDescriptor,
|
||||
Annotations.EMPTY,
|
||||
true,
|
||||
@@ -52,7 +52,7 @@ class LazyScriptClassMemberScope(
|
||||
return constructor
|
||||
}
|
||||
|
||||
private fun createScriptParameters(constructor: ConstructorDescriptorImpl): List<ValueParameterDescriptor> {
|
||||
private fun createScriptParameters(constructor: ClassConstructorDescriptorImpl): List<ValueParameterDescriptor> {
|
||||
return scriptDescriptor.scriptDefinition.getScriptParameters(scriptDescriptor).mapIndexed { index, scriptParameter ->
|
||||
ValueParameterDescriptorImpl(
|
||||
constructor, null, index, Annotations.EMPTY, scriptParameter.name, scriptParameter.type,
|
||||
|
||||
@@ -6,11 +6,11 @@ typealias <!REDECLARATION!>SomeClass<!> = Any
|
||||
typealias <!REDECLARATION!>SomeClass<!> = Any
|
||||
|
||||
class Outer {
|
||||
class <!REDECLARATION, CONFLICTING_OVERLOADS!>Nested<!>
|
||||
class <!REDECLARATION!>Nested<!>
|
||||
|
||||
<!CONFLICTING_OVERLOADS!>typealias <!REDECLARATION!>Nested<!> = Any<!>
|
||||
<!CONFLICTING_OVERLOADS!>typealias <!REDECLARATION!>Nested<!> = Any<!>
|
||||
<!CONFLICTING_OVERLOADS!>typealias <!REDECLARATION!>Nested<!> = Any<!>
|
||||
typealias <!REDECLARATION!>Nested<!> = Any
|
||||
typealias <!REDECLARATION!>Nested<!> = Any
|
||||
typealias <!REDECLARATION!>Nested<!> = Any
|
||||
}
|
||||
|
||||
// FILE: file2.kt
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
typealias Exn = java.lang.Exception
|
||||
|
||||
fun test() {
|
||||
throw <!FUNCTION_CALL_EXPECTED!>Exn<!>
|
||||
throw <!NO_COMPANION_OBJECT!>Exn<!>
|
||||
}
|
||||
+6
-6
@@ -1,13 +1,13 @@
|
||||
<set-?>:ValueParameterDescriptor
|
||||
Class.<get-classProp>:PropertyGetterDescriptor
|
||||
Class.<init>():ConstructorDescriptor
|
||||
Class.<init>():ClassConstructorDescriptor
|
||||
Class.classFunc:SimpleFunctionDescriptor
|
||||
Class.classProp:PropertyDescriptor
|
||||
Class.this:ReceiverParameterDescriptor
|
||||
Class:ClassDescriptorWithResolutionScopes
|
||||
Companion.<get-classObjProp>:PropertyGetterDescriptor
|
||||
Companion.<init>():ConstructorDescriptor
|
||||
Companion.<init>():ConstructorDescriptor
|
||||
Companion.<init>():ClassConstructorDescriptor
|
||||
Companion.<init>():ClassConstructorDescriptor
|
||||
Companion.classObjFunc:SimpleFunctionDescriptor
|
||||
Companion.classObjProp:PropertyDescriptor
|
||||
Companion.nestedClassObjFunc:SimpleFunctionDescriptor
|
||||
@@ -15,10 +15,10 @@ Companion.this:ReceiverParameterDescriptor
|
||||
Companion.this:ReceiverParameterDescriptor
|
||||
Companion:ClassDescriptorWithResolutionScopes
|
||||
Companion:ClassDescriptorWithResolutionScopes
|
||||
NestedClass.<init>():ConstructorDescriptor
|
||||
NestedClass.<init>():ClassConstructorDescriptor
|
||||
NestedClass.this:ReceiverParameterDescriptor
|
||||
NestedClass:ClassDescriptorWithResolutionScopes
|
||||
NestedObject.<init>():ConstructorDescriptor
|
||||
NestedObject.<init>():ClassConstructorDescriptor
|
||||
NestedObject.nestedFunc:SimpleFunctionDescriptor
|
||||
NestedObject.this:ReceiverParameterDescriptor
|
||||
NestedObject:ClassDescriptorWithResolutionScopes
|
||||
@@ -26,7 +26,7 @@ NestedTrait.nestedTraitFun:SimpleFunctionDescriptor
|
||||
NestedTrait.this:ReceiverParameterDescriptor
|
||||
NestedTrait:ClassDescriptorWithResolutionScopes
|
||||
Object.<get-objProp>:PropertyGetterDescriptor
|
||||
Object.<init>():ConstructorDescriptor
|
||||
Object.<init>():ClassConstructorDescriptor
|
||||
Object.objFunc:SimpleFunctionDescriptor
|
||||
Object.objProp:PropertyDescriptor
|
||||
Object.this:ReceiverParameterDescriptor
|
||||
|
||||
+1
-1
@@ -115,7 +115,7 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
|
||||
}
|
||||
|
||||
private fun DeclarationDescriptor.isJavaAnnotationConstructor() =
|
||||
this is ConstructorDescriptor &&
|
||||
this is ClassConstructorDescriptor &&
|
||||
containingDeclaration is JavaClassDescriptor &&
|
||||
containingDeclaration.kind == ClassKind.ANNOTATION_CLASS
|
||||
|
||||
|
||||
+1
-1
@@ -317,7 +317,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends KotlinTest
|
||||
|
||||
@NotNull
|
||||
private static ConstructorDescriptor getConstructorDescriptor(@NotNull ClassDescriptor classDescriptor) {
|
||||
Collection<ConstructorDescriptor> constructors = classDescriptor.getConstructors();
|
||||
Collection<ClassConstructorDescriptor> constructors = classDescriptor.getConstructors();
|
||||
assert constructors.size() == 1;
|
||||
return constructors.iterator().next();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user