Got rid of constructors/initializers zoo in constructor descriptors

This commit is contained in:
Evgeny Gerashchenko
2014-03-25 17:29:19 +04:00
parent 23e6ae02bd
commit 8d38e74bd9
12 changed files with 54 additions and 46 deletions
@@ -190,9 +190,9 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
@NotNull
public ConstructorContext intoConstructor(@Nullable ConstructorDescriptor descriptor, @Nullable MutableClosure closure) {
if (descriptor == null) {
descriptor = new ConstructorDescriptorImpl(getThisDescriptor(), Annotations.EMPTY, true)
descriptor = ConstructorDescriptorImpl.create(getThisDescriptor(), Annotations.EMPTY, true)
.initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList(),
Visibilities.PUBLIC);
Visibilities.PUBLIC, false);
}
return new ConstructorContext(descriptor, getContextKind(), this, closure);
}
@@ -250,7 +250,7 @@ public class DescriptorDeserializer {
@NotNull
private CallableMemberDescriptor loadConstructor(@NotNull Callable proto) {
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
ConstructorDescriptorImpl descriptor = new ConstructorDescriptorImpl(
ConstructorDescriptorImpl descriptor = ConstructorDescriptorImpl.create(
classDescriptor,
getAnnotations(proto, proto.getFlags(), AnnotatedCallableKind.FUNCTION),
// TODO: primary
@@ -1228,7 +1228,7 @@ public class DescriptorResolver {
@NotNull JetDeclaration declarationToTrace,
List<TypeParameterDescriptor> typeParameters, @NotNull List<JetParameter> valueParameters, BindingTrace trace
) {
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(
ConstructorDescriptorImpl constructorDescriptor = ConstructorDescriptorImpl.create(
classDescriptor,
annotationResolver.resolveAnnotationsWithoutArguments(scope, modifierList, trace),
isPrimary
@@ -17,6 +17,7 @@
package org.jetbrains.jet.lang.resolve.java.descriptor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
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 {
private Boolean hasStableParameterNames;
public JavaConstructorDescriptor(
@NotNull ClassDescriptor containingDeclaration,
@NotNull Annotations annotations,
boolean isPrimary
) {
super(containingDeclaration, annotations, isPrimary);
}
private JavaConstructorDescriptor(
@NotNull ClassDescriptor containingDeclaration,
@NotNull JavaConstructorDescriptor original,
@Nullable JavaConstructorDescriptor original,
@NotNull Annotations annotations,
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
@@ -74,7 +74,7 @@ public class LazyJavaClassMemberScope(
}
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 effectiveSignature = c.externalSignatureResolver.resolveAlternativeMethodSignature(
@@ -106,7 +106,7 @@ public class LazyJavaClassMemberScope(
return null
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 valueParameters = if (isAnnotation) createAnnotationConstructorParameters(constructorDescriptor)
else Collections.emptyList<ValueParameterDescriptor>()
@@ -26,7 +26,7 @@ import org.jetbrains.jet.lang.resolve.java.descriptor.SamAdapterDescriptor;
private final 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;
}
@@ -17,7 +17,6 @@
package org.jetbrains.jet.lang.descriptors;
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.impl.*;
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
@@ -157,8 +156,8 @@ public class ScriptDescriptor extends DeclarationDescriptorNonRootImpl {
public void setValueParameters(@NotNull List<ValueParameterDescriptor> valueParameters) {
this.valueParameters = valueParameters;
ConstructorDescriptorImpl constructorDescriptor =
new ConstructorDescriptorImpl(classDescriptor, Annotations.EMPTY, true)
.initialize(Collections.<TypeParameterDescriptor>emptyList(), valueParameters, Visibilities.PUBLIC);
ConstructorDescriptorImpl.create(classDescriptor, Annotations.EMPTY, true)
.initialize(Collections.<TypeParameterDescriptor>emptyList(), valueParameters, Visibilities.PUBLIC, false);
constructorDescriptor.setReturnType(classDescriptor.getDefaultType());
classDescriptor.getConstructors().add(constructorDescriptor);
@@ -35,26 +35,34 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
private static final Name NAME = Name.special("<init>");
public ConstructorDescriptorImpl(@NotNull ClassDescriptor containingDeclaration, @NotNull Annotations annotations, boolean isPrimary) {
this(containingDeclaration, annotations, isPrimary, Kind.DECLARATION);
}
public ConstructorDescriptorImpl(@NotNull ClassDescriptor containingDeclaration, @NotNull Annotations annotations, boolean isPrimary, Kind kind) {
super(containingDeclaration, null, annotations, NAME, kind);
protected ConstructorDescriptorImpl(
@NotNull ClassDescriptor containingDeclaration,
@Nullable ConstructorDescriptor original,
@NotNull Annotations annotations,
boolean isPrimary,
@NotNull Kind kind
) {
super(containingDeclaration, original, annotations, NAME, kind);
this.isPrimary = isPrimary;
}
public ConstructorDescriptorImpl(@NotNull ClassDescriptor containingDeclaration, @NotNull ConstructorDescriptor original, @NotNull Annotations annotations, boolean isPrimary) {
super(containingDeclaration, original, annotations, NAME, Kind.DECLARATION);
this.isPrimary = isPrimary;
@NotNull
public static ConstructorDescriptorImpl create(
@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) {
return initialize(typeParameters, unsubstitutedValueParameters, visibility, false);
}
public ConstructorDescriptorImpl initialize(@NotNull List<TypeParameterDescriptor> typeParameters, @NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters, Visibility visibility, boolean isStatic) {
super.initialize(null, isStatic ? NO_RECEIVER_PARAMETER : getExpectedThisObject(getContainingDeclaration()), typeParameters, unsubstitutedValueParameters, null, Modality.FINAL, visibility);
public ConstructorDescriptorImpl initialize(
@NotNull List<TypeParameterDescriptor> typeParameters,
@NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
@NotNull Visibility visibility,
boolean isStatic
) {
super.initialize(null, isStatic ? NO_RECEIVER_PARAMETER : getExpectedThisObject(getContainingDeclaration()), typeParameters,
unsubstitutedValueParameters, null, Modality.FINAL, visibility);
return this;
}
@@ -105,11 +113,13 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
"newOwner: " + newOwner + "\n" +
"kind: " + kind);
}
assert preserveOriginal : "Attempt to create copy of constructor without preserving original: " + this;
return new ConstructorDescriptorImpl(
(ClassDescriptor) newOwner,
this,
Annotations.EMPTY, // TODO
isPrimary);
isPrimary,
Kind.DECLARATION);
}
@NotNull
@@ -29,7 +29,7 @@ public abstract class DeclarationDescriptorNonRootImpl
@NotNull
private final DeclarationDescriptor containingDeclaration;
public DeclarationDescriptorNonRootImpl(
protected DeclarationDescriptorNonRootImpl(
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull Annotations annotations,
@NotNull Name name) {
@@ -37,7 +37,7 @@ public class DescriptorFactory {
private static class DefaultConstructorDescriptor extends ConstructorDescriptorImpl {
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(),
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());
ConstructorDescriptorImpl errorConstructor =
new ConstructorDescriptorImpl(this, Annotations.EMPTY, true);
ConstructorDescriptorImpl.create(this, Annotations.EMPTY, true);
errorConstructor.initialize(
Collections.<TypeParameterDescriptor>emptyList(), // TODO
Collections.<ValueParameterDescriptor>emptyList(), // TODO
Visibilities.INTERNAL
);
errorConstructor.initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList(),
Visibilities.INTERNAL, false);
errorConstructor.setReturnType(createErrorType("<ERROR RETURN TYPE>"));
initialize(createErrorScope("ERROR_CLASS"), Collections.<ConstructorDescriptor>singleton(errorConstructor), errorConstructor);
@@ -58,8 +58,8 @@ public class MissingDependencyErrorClassDescriptor(override val fullFqName: FqNa
}
{
val emptyConstructor = ConstructorDescriptorImpl(this, Annotations.EMPTY, true)
emptyConstructor.initialize(Collections.emptyList<TypeParameterDescriptor>(), Collections.emptyList<ValueParameterDescriptor>(), Visibilities.INTERNAL)
val emptyConstructor = ConstructorDescriptorImpl.create(this, Annotations.EMPTY, true)
emptyConstructor.initialize(Collections.emptyList<TypeParameterDescriptor>(), Collections.emptyList<ValueParameterDescriptor>(), Visibilities.INTERNAL, false)
emptyConstructor.setReturnType(createErrorType("<ERROR RETURN TYPE>"))
initialize(JetScope.EMPTY, Collections.singleton<ConstructorDescriptor>(emptyConstructor), emptyConstructor)
}