Got rid of constructors/initializers zoo in constructor descriptors
This commit is contained in:
@@ -190,9 +190,9 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public ConstructorContext intoConstructor(@Nullable ConstructorDescriptor descriptor, @Nullable MutableClosure closure) {
|
public ConstructorContext intoConstructor(@Nullable ConstructorDescriptor descriptor, @Nullable MutableClosure closure) {
|
||||||
if (descriptor == null) {
|
if (descriptor == null) {
|
||||||
descriptor = new ConstructorDescriptorImpl(getThisDescriptor(), Annotations.EMPTY, true)
|
descriptor = ConstructorDescriptorImpl.create(getThisDescriptor(), Annotations.EMPTY, true)
|
||||||
.initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList(),
|
.initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList(),
|
||||||
Visibilities.PUBLIC);
|
Visibilities.PUBLIC, false);
|
||||||
}
|
}
|
||||||
return new ConstructorContext(descriptor, getContextKind(), this, closure);
|
return new ConstructorContext(descriptor, getContextKind(), this, closure);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -250,7 +250,7 @@ public class DescriptorDeserializer {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private CallableMemberDescriptor loadConstructor(@NotNull Callable proto) {
|
private CallableMemberDescriptor loadConstructor(@NotNull Callable proto) {
|
||||||
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
||||||
ConstructorDescriptorImpl descriptor = new ConstructorDescriptorImpl(
|
ConstructorDescriptorImpl descriptor = ConstructorDescriptorImpl.create(
|
||||||
classDescriptor,
|
classDescriptor,
|
||||||
getAnnotations(proto, proto.getFlags(), AnnotatedCallableKind.FUNCTION),
|
getAnnotations(proto, proto.getFlags(), AnnotatedCallableKind.FUNCTION),
|
||||||
// TODO: primary
|
// TODO: primary
|
||||||
|
|||||||
@@ -1228,7 +1228,7 @@ public class DescriptorResolver {
|
|||||||
@NotNull JetDeclaration declarationToTrace,
|
@NotNull JetDeclaration declarationToTrace,
|
||||||
List<TypeParameterDescriptor> typeParameters, @NotNull List<JetParameter> valueParameters, BindingTrace trace
|
List<TypeParameterDescriptor> typeParameters, @NotNull List<JetParameter> valueParameters, BindingTrace trace
|
||||||
) {
|
) {
|
||||||
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(
|
ConstructorDescriptorImpl constructorDescriptor = ConstructorDescriptorImpl.create(
|
||||||
classDescriptor,
|
classDescriptor,
|
||||||
annotationResolver.resolveAnnotationsWithoutArguments(scope, modifierList, trace),
|
annotationResolver.resolveAnnotationsWithoutArguments(scope, modifierList, trace),
|
||||||
isPrimary
|
isPrimary
|
||||||
|
|||||||
+12
-10
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.lang.resolve.java.descriptor;
|
package org.jetbrains.jet.lang.resolve.java.descriptor;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||||
@@ -25,21 +26,22 @@ import org.jetbrains.jet.lang.descriptors.impl.ConstructorDescriptorImpl;
|
|||||||
public class JavaConstructorDescriptor extends ConstructorDescriptorImpl {
|
public class JavaConstructorDescriptor extends ConstructorDescriptorImpl {
|
||||||
private Boolean hasStableParameterNames;
|
private Boolean hasStableParameterNames;
|
||||||
|
|
||||||
public JavaConstructorDescriptor(
|
|
||||||
@NotNull ClassDescriptor containingDeclaration,
|
|
||||||
@NotNull Annotations annotations,
|
|
||||||
boolean isPrimary
|
|
||||||
) {
|
|
||||||
super(containingDeclaration, annotations, isPrimary);
|
|
||||||
}
|
|
||||||
|
|
||||||
private JavaConstructorDescriptor(
|
private JavaConstructorDescriptor(
|
||||||
@NotNull ClassDescriptor containingDeclaration,
|
@NotNull ClassDescriptor containingDeclaration,
|
||||||
@NotNull JavaConstructorDescriptor original,
|
@Nullable JavaConstructorDescriptor original,
|
||||||
@NotNull Annotations annotations,
|
@NotNull Annotations annotations,
|
||||||
boolean isPrimary
|
boolean isPrimary
|
||||||
) {
|
) {
|
||||||
super(containingDeclaration, original, annotations, isPrimary);
|
super(containingDeclaration, original, annotations, isPrimary, Kind.DECLARATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static JavaConstructorDescriptor createJavaConstructor(
|
||||||
|
@NotNull ClassDescriptor containingDeclaration,
|
||||||
|
@NotNull Annotations annotations,
|
||||||
|
boolean isPrimary
|
||||||
|
) {
|
||||||
|
return new JavaConstructorDescriptor(containingDeclaration, null, annotations, isPrimary);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+2
-2
@@ -74,7 +74,7 @@ public class LazyJavaClassMemberScope(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun resolveConstructor(constructor: JavaMethod, classDescriptor: ClassDescriptor, isStaticClass: Boolean): ConstructorDescriptor {
|
private fun resolveConstructor(constructor: JavaMethod, classDescriptor: ClassDescriptor, isStaticClass: Boolean): ConstructorDescriptor {
|
||||||
val constructorDescriptor = JavaConstructorDescriptor(classDescriptor, Annotations.EMPTY, /* isPrimary = */ false)
|
val constructorDescriptor = JavaConstructorDescriptor.createJavaConstructor(classDescriptor, Annotations.EMPTY, /* isPrimary = */ false)
|
||||||
|
|
||||||
val valueParameters = resolveValueParameters(c, constructorDescriptor, constructor.getValueParameters())
|
val valueParameters = resolveValueParameters(c, constructorDescriptor, constructor.getValueParameters())
|
||||||
val effectiveSignature = c.externalSignatureResolver.resolveAlternativeMethodSignature(
|
val effectiveSignature = c.externalSignatureResolver.resolveAlternativeMethodSignature(
|
||||||
@@ -106,7 +106,7 @@ public class LazyJavaClassMemberScope(
|
|||||||
return null
|
return null
|
||||||
|
|
||||||
val classDescriptor = getContainingDeclaration()
|
val classDescriptor = getContainingDeclaration()
|
||||||
val constructorDescriptor = JavaConstructorDescriptor(classDescriptor, Annotations.EMPTY, /* isPrimary = */ true)
|
val constructorDescriptor = JavaConstructorDescriptor.createJavaConstructor(classDescriptor, Annotations.EMPTY, /* isPrimary = */ true)
|
||||||
val typeParameters = classDescriptor.getTypeConstructor().getParameters()
|
val typeParameters = classDescriptor.getTypeConstructor().getParameters()
|
||||||
val valueParameters = if (isAnnotation) createAnnotationConstructorParameters(constructorDescriptor)
|
val valueParameters = if (isAnnotation) createAnnotationConstructorParameters(constructorDescriptor)
|
||||||
else Collections.emptyList<ValueParameterDescriptor>()
|
else Collections.emptyList<ValueParameterDescriptor>()
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ import org.jetbrains.jet.lang.resolve.java.descriptor.SamAdapterDescriptor;
|
|||||||
private final ConstructorDescriptor declaration;
|
private final ConstructorDescriptor declaration;
|
||||||
|
|
||||||
public SamAdapterConstructorDescriptor(@NotNull ConstructorDescriptor declaration) {
|
public SamAdapterConstructorDescriptor(@NotNull ConstructorDescriptor declaration) {
|
||||||
super(declaration.getContainingDeclaration(), declaration.getAnnotations(), declaration.isPrimary(), Kind.SYNTHESIZED);
|
super(declaration.getContainingDeclaration(), null, declaration.getAnnotations(), declaration.isPrimary(), Kind.SYNTHESIZED);
|
||||||
this.declaration = declaration;
|
this.declaration = declaration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.jet.lang.descriptors;
|
package org.jetbrains.jet.lang.descriptors;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||||
import org.jetbrains.jet.lang.descriptors.impl.*;
|
import org.jetbrains.jet.lang.descriptors.impl.*;
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
|
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
|
||||||
@@ -157,8 +156,8 @@ public class ScriptDescriptor extends DeclarationDescriptorNonRootImpl {
|
|||||||
public void setValueParameters(@NotNull List<ValueParameterDescriptor> valueParameters) {
|
public void setValueParameters(@NotNull List<ValueParameterDescriptor> valueParameters) {
|
||||||
this.valueParameters = valueParameters;
|
this.valueParameters = valueParameters;
|
||||||
ConstructorDescriptorImpl constructorDescriptor =
|
ConstructorDescriptorImpl constructorDescriptor =
|
||||||
new ConstructorDescriptorImpl(classDescriptor, Annotations.EMPTY, true)
|
ConstructorDescriptorImpl.create(classDescriptor, Annotations.EMPTY, true)
|
||||||
.initialize(Collections.<TypeParameterDescriptor>emptyList(), valueParameters, Visibilities.PUBLIC);
|
.initialize(Collections.<TypeParameterDescriptor>emptyList(), valueParameters, Visibilities.PUBLIC, false);
|
||||||
constructorDescriptor.setReturnType(classDescriptor.getDefaultType());
|
constructorDescriptor.setReturnType(classDescriptor.getDefaultType());
|
||||||
|
|
||||||
classDescriptor.getConstructors().add(constructorDescriptor);
|
classDescriptor.getConstructors().add(constructorDescriptor);
|
||||||
|
|||||||
+26
-16
@@ -35,26 +35,34 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
|||||||
|
|
||||||
private static final Name NAME = Name.special("<init>");
|
private static final Name NAME = Name.special("<init>");
|
||||||
|
|
||||||
public ConstructorDescriptorImpl(@NotNull ClassDescriptor containingDeclaration, @NotNull Annotations annotations, boolean isPrimary) {
|
protected ConstructorDescriptorImpl(
|
||||||
this(containingDeclaration, annotations, isPrimary, Kind.DECLARATION);
|
@NotNull ClassDescriptor containingDeclaration,
|
||||||
}
|
@Nullable ConstructorDescriptor original,
|
||||||
|
@NotNull Annotations annotations,
|
||||||
public ConstructorDescriptorImpl(@NotNull ClassDescriptor containingDeclaration, @NotNull Annotations annotations, boolean isPrimary, Kind kind) {
|
boolean isPrimary,
|
||||||
super(containingDeclaration, null, annotations, NAME, kind);
|
@NotNull Kind kind
|
||||||
|
) {
|
||||||
|
super(containingDeclaration, original, annotations, NAME, kind);
|
||||||
this.isPrimary = isPrimary;
|
this.isPrimary = isPrimary;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConstructorDescriptorImpl(@NotNull ClassDescriptor containingDeclaration, @NotNull ConstructorDescriptor original, @NotNull Annotations annotations, boolean isPrimary) {
|
@NotNull
|
||||||
super(containingDeclaration, original, annotations, NAME, Kind.DECLARATION);
|
public static ConstructorDescriptorImpl create(
|
||||||
this.isPrimary = isPrimary;
|
@NotNull ClassDescriptor containingDeclaration,
|
||||||
|
@NotNull Annotations annotations,
|
||||||
|
boolean isPrimary
|
||||||
|
) {
|
||||||
|
return new ConstructorDescriptorImpl(containingDeclaration, null, annotations, isPrimary, Kind.DECLARATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConstructorDescriptorImpl initialize(@NotNull List<TypeParameterDescriptor> typeParameters, @NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters, Visibility visibility) {
|
public ConstructorDescriptorImpl initialize(
|
||||||
return initialize(typeParameters, unsubstitutedValueParameters, visibility, false);
|
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||||
}
|
@NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
|
||||||
|
@NotNull Visibility visibility,
|
||||||
public ConstructorDescriptorImpl initialize(@NotNull List<TypeParameterDescriptor> typeParameters, @NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters, Visibility visibility, boolean isStatic) {
|
boolean isStatic
|
||||||
super.initialize(null, isStatic ? NO_RECEIVER_PARAMETER : getExpectedThisObject(getContainingDeclaration()), typeParameters, unsubstitutedValueParameters, null, Modality.FINAL, visibility);
|
) {
|
||||||
|
super.initialize(null, isStatic ? NO_RECEIVER_PARAMETER : getExpectedThisObject(getContainingDeclaration()), typeParameters,
|
||||||
|
unsubstitutedValueParameters, null, Modality.FINAL, visibility);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,11 +113,13 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
|||||||
"newOwner: " + newOwner + "\n" +
|
"newOwner: " + newOwner + "\n" +
|
||||||
"kind: " + kind);
|
"kind: " + kind);
|
||||||
}
|
}
|
||||||
|
assert preserveOriginal : "Attempt to create copy of constructor without preserving original: " + this;
|
||||||
return new ConstructorDescriptorImpl(
|
return new ConstructorDescriptorImpl(
|
||||||
(ClassDescriptor) newOwner,
|
(ClassDescriptor) newOwner,
|
||||||
this,
|
this,
|
||||||
Annotations.EMPTY, // TODO
|
Annotations.EMPTY, // TODO
|
||||||
isPrimary);
|
isPrimary,
|
||||||
|
Kind.DECLARATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@ public abstract class DeclarationDescriptorNonRootImpl
|
|||||||
@NotNull
|
@NotNull
|
||||||
private final DeclarationDescriptor containingDeclaration;
|
private final DeclarationDescriptor containingDeclaration;
|
||||||
|
|
||||||
public DeclarationDescriptorNonRootImpl(
|
protected DeclarationDescriptorNonRootImpl(
|
||||||
@NotNull DeclarationDescriptor containingDeclaration,
|
@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
@NotNull Annotations annotations,
|
@NotNull Annotations annotations,
|
||||||
@NotNull Name name) {
|
@NotNull Name name) {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class DescriptorFactory {
|
|||||||
|
|
||||||
private static class DefaultConstructorDescriptor extends ConstructorDescriptorImpl {
|
private static class DefaultConstructorDescriptor extends ConstructorDescriptorImpl {
|
||||||
public DefaultConstructorDescriptor(@NotNull ClassDescriptor containingClass) {
|
public DefaultConstructorDescriptor(@NotNull ClassDescriptor containingClass) {
|
||||||
super(containingClass, Annotations.EMPTY, true);
|
super(containingClass, null, Annotations.EMPTY, true, Kind.DECLARATION);
|
||||||
initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList(),
|
initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList(),
|
||||||
getDefaultConstructorVisibility(containingClass), true);
|
getDefaultConstructorVisibility(containingClass), true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,13 +37,10 @@ public final class ErrorClassDescriptor extends ClassDescriptorImpl {
|
|||||||
super(getErrorModule(), Name.special("<ERROR CLASS: " + debugMessage + ">"), Modality.OPEN, Collections.<JetType>emptyList());
|
super(getErrorModule(), Name.special("<ERROR CLASS: " + debugMessage + ">"), Modality.OPEN, Collections.<JetType>emptyList());
|
||||||
|
|
||||||
ConstructorDescriptorImpl errorConstructor =
|
ConstructorDescriptorImpl errorConstructor =
|
||||||
new ConstructorDescriptorImpl(this, Annotations.EMPTY, true);
|
ConstructorDescriptorImpl.create(this, Annotations.EMPTY, true);
|
||||||
|
|
||||||
errorConstructor.initialize(
|
errorConstructor.initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList(),
|
||||||
Collections.<TypeParameterDescriptor>emptyList(), // TODO
|
Visibilities.INTERNAL, false);
|
||||||
Collections.<ValueParameterDescriptor>emptyList(), // TODO
|
|
||||||
Visibilities.INTERNAL
|
|
||||||
);
|
|
||||||
errorConstructor.setReturnType(createErrorType("<ERROR RETURN TYPE>"));
|
errorConstructor.setReturnType(createErrorType("<ERROR RETURN TYPE>"));
|
||||||
|
|
||||||
initialize(createErrorScope("ERROR_CLASS"), Collections.<ConstructorDescriptor>singleton(errorConstructor), errorConstructor);
|
initialize(createErrorScope("ERROR_CLASS"), Collections.<ConstructorDescriptor>singleton(errorConstructor), errorConstructor);
|
||||||
|
|||||||
+2
-2
@@ -58,8 +58,8 @@ public class MissingDependencyErrorClassDescriptor(override val fullFqName: FqNa
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
val emptyConstructor = ConstructorDescriptorImpl(this, Annotations.EMPTY, true)
|
val emptyConstructor = ConstructorDescriptorImpl.create(this, Annotations.EMPTY, true)
|
||||||
emptyConstructor.initialize(Collections.emptyList<TypeParameterDescriptor>(), Collections.emptyList<ValueParameterDescriptor>(), Visibilities.INTERNAL)
|
emptyConstructor.initialize(Collections.emptyList<TypeParameterDescriptor>(), Collections.emptyList<ValueParameterDescriptor>(), Visibilities.INTERNAL, false)
|
||||||
emptyConstructor.setReturnType(createErrorType("<ERROR RETURN TYPE>"))
|
emptyConstructor.setReturnType(createErrorType("<ERROR RETURN TYPE>"))
|
||||||
initialize(JetScope.EMPTY, Collections.singleton<ConstructorDescriptor>(emptyConstructor), emptyConstructor)
|
initialize(JetScope.EMPTY, Collections.singleton<ConstructorDescriptor>(emptyConstructor), emptyConstructor)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user