Simplified code in functions hierarchy.
Minimized constructors variety and reduced code duplication.
This commit is contained in:
+1
-1
@@ -219,7 +219,7 @@ public class DescriptorDeserializer {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private CallableMemberDescriptor loadFunction(@NotNull Callable proto) {
|
private CallableMemberDescriptor loadFunction(@NotNull Callable proto) {
|
||||||
int flags = proto.getFlags();
|
int flags = proto.getFlags();
|
||||||
DeserializedSimpleFunctionDescriptor function = new DeserializedSimpleFunctionDescriptor(
|
DeserializedSimpleFunctionDescriptor function = DeserializedSimpleFunctionDescriptor.create(
|
||||||
containingDeclaration, proto,
|
containingDeclaration, proto,
|
||||||
deserializers,
|
deserializers,
|
||||||
nameResolver
|
nameResolver
|
||||||
|
|||||||
+31
-51
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.descriptors.serialization.descriptors;
|
package org.jetbrains.jet.descriptors.serialization.descriptors;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.descriptors.serialization.DescriptorDeserializer;
|
import org.jetbrains.jet.descriptors.serialization.DescriptorDeserializer;
|
||||||
import org.jetbrains.jet.descriptors.serialization.Flags;
|
import org.jetbrains.jet.descriptors.serialization.Flags;
|
||||||
import org.jetbrains.jet.descriptors.serialization.NameResolver;
|
import org.jetbrains.jet.descriptors.serialization.NameResolver;
|
||||||
@@ -35,20 +36,7 @@ public class DeserializedSimpleFunctionDescriptor extends SimpleFunctionDescript
|
|||||||
|
|
||||||
private DeserializedSimpleFunctionDescriptor(
|
private DeserializedSimpleFunctionDescriptor(
|
||||||
@NotNull DeclarationDescriptor containingDeclaration,
|
@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
@NotNull Annotations annotations,
|
@Nullable SimpleFunctionDescriptor original,
|
||||||
@NotNull Name name,
|
|
||||||
@NotNull Kind kind,
|
|
||||||
@NotNull ProtoBuf.Callable functionProto,
|
|
||||||
@NotNull NameResolver nameResolver
|
|
||||||
) {
|
|
||||||
super(containingDeclaration, annotations, name, kind);
|
|
||||||
this.functionProto = functionProto;
|
|
||||||
this.nameResolver = nameResolver;
|
|
||||||
}
|
|
||||||
|
|
||||||
private DeserializedSimpleFunctionDescriptor(
|
|
||||||
@NotNull DeclarationDescriptor containingDeclaration,
|
|
||||||
@NotNull SimpleFunctionDescriptor original,
|
|
||||||
@NotNull Annotations annotations,
|
@NotNull Annotations annotations,
|
||||||
@NotNull Name name,
|
@NotNull Name name,
|
||||||
@NotNull Kind kind,
|
@NotNull Kind kind,
|
||||||
@@ -59,45 +47,17 @@ public class DeserializedSimpleFunctionDescriptor extends SimpleFunctionDescript
|
|||||||
this.nameResolver = nameResolver;
|
this.nameResolver = nameResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeserializedSimpleFunctionDescriptor(
|
|
||||||
@NotNull DeclarationDescriptor containingDeclaration,
|
|
||||||
@NotNull ProtoBuf.Callable functionProto,
|
|
||||||
@NotNull Deserializers deserializers,
|
|
||||||
@NotNull NameResolver nameResolver
|
|
||||||
) {
|
|
||||||
this(containingDeclaration,
|
|
||||||
DescriptorDeserializer.getAnnotations(containingDeclaration, functionProto, functionProto.getFlags(),
|
|
||||||
Deserializers.AnnotatedCallableKind.FUNCTION, deserializers.getAnnotationDeserializer(),
|
|
||||||
nameResolver),
|
|
||||||
nameResolver.getName(functionProto.getName()),
|
|
||||||
DescriptorDeserializer.memberKind(Flags.MEMBER_KIND.get(functionProto.getFlags())),
|
|
||||||
functionProto,
|
|
||||||
nameResolver);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
||||||
if (preserveOriginal) {
|
return new DeserializedSimpleFunctionDescriptor(
|
||||||
return new DeserializedSimpleFunctionDescriptor(
|
newOwner,
|
||||||
newOwner,
|
preserveOriginal ? getOriginal() : null,
|
||||||
getOriginal(),
|
getAnnotations(),
|
||||||
getAnnotations(),
|
getName(),
|
||||||
getName(),
|
kind,
|
||||||
kind,
|
functionProto,
|
||||||
functionProto,
|
nameResolver
|
||||||
nameResolver
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return new DeserializedSimpleFunctionDescriptor(
|
|
||||||
newOwner,
|
|
||||||
getAnnotations(),
|
|
||||||
getName(),
|
|
||||||
kind,
|
|
||||||
functionProto,
|
|
||||||
nameResolver
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -113,4 +73,24 @@ public class DeserializedSimpleFunctionDescriptor extends SimpleFunctionDescript
|
|||||||
public NameResolver getNameResolver() {
|
public NameResolver getNameResolver() {
|
||||||
return nameResolver;
|
return nameResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static DeserializedSimpleFunctionDescriptor create(
|
||||||
|
@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
|
@NotNull ProtoBuf.Callable functionProto,
|
||||||
|
@NotNull Deserializers deserializers,
|
||||||
|
@NotNull NameResolver nameResolver
|
||||||
|
) {
|
||||||
|
Annotations annotations = DescriptorDeserializer.getAnnotations(containingDeclaration, functionProto, functionProto.getFlags(),
|
||||||
|
Deserializers.AnnotatedCallableKind.FUNCTION,
|
||||||
|
deserializers.getAnnotationDeserializer(),
|
||||||
|
nameResolver);
|
||||||
|
return new DeserializedSimpleFunctionDescriptor(
|
||||||
|
containingDeclaration,
|
||||||
|
null,
|
||||||
|
annotations,
|
||||||
|
nameResolver.getName(functionProto.getName()),
|
||||||
|
DescriptorDeserializer.memberKind(Flags.MEMBER_KIND.get(functionProto.getFlags())),
|
||||||
|
functionProto,
|
||||||
|
nameResolver);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ConstructorDescriptorImpl(@NotNull ClassDescriptor containingDeclaration, @NotNull Annotations annotations, boolean isPrimary, Kind kind) {
|
public ConstructorDescriptorImpl(@NotNull ClassDescriptor containingDeclaration, @NotNull Annotations annotations, boolean isPrimary, Kind kind) {
|
||||||
super(containingDeclaration, annotations, NAME, kind);
|
super(containingDeclaration, null, annotations, NAME, kind);
|
||||||
this.isPrimary = isPrimary;
|
this.isPrimary = isPrimary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-12
@@ -50,22 +50,12 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
|||||||
|
|
||||||
protected FunctionDescriptorImpl(
|
protected FunctionDescriptorImpl(
|
||||||
@NotNull DeclarationDescriptor containingDeclaration,
|
@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
|
@Nullable FunctionDescriptor original,
|
||||||
@NotNull Annotations annotations,
|
@NotNull Annotations annotations,
|
||||||
@NotNull Name name,
|
@NotNull Name name,
|
||||||
@NotNull Kind kind) {
|
@NotNull Kind kind) {
|
||||||
super(containingDeclaration, annotations, name);
|
super(containingDeclaration, annotations, name);
|
||||||
this.original = this;
|
this.original = original == null ? this : original;
|
||||||
this.kind = kind;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected FunctionDescriptorImpl(
|
|
||||||
@NotNull DeclarationDescriptor containingDeclaration,
|
|
||||||
@NotNull FunctionDescriptor original,
|
|
||||||
@NotNull Annotations annotations,
|
|
||||||
@NotNull Name name,
|
|
||||||
@NotNull Kind kind) {
|
|
||||||
super(containingDeclaration, annotations, name);
|
|
||||||
this.original = original;
|
|
||||||
this.kind = kind;
|
this.kind = kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ import java.util.List;
|
|||||||
public class ScriptCodeDescriptor extends FunctionDescriptorImpl {
|
public class ScriptCodeDescriptor extends FunctionDescriptorImpl {
|
||||||
|
|
||||||
public ScriptCodeDescriptor(@NotNull ScriptDescriptor containingDeclaration) {
|
public ScriptCodeDescriptor(@NotNull ScriptDescriptor containingDeclaration) {
|
||||||
super(containingDeclaration, Annotations.EMPTY, Name.special("<script-code>"), Kind.DECLARATION);
|
super(containingDeclaration, null, Annotations.EMPTY, Name.special("<script-code>"), Kind.DECLARATION);
|
||||||
setVisibility(Visibilities.LOCAL);
|
setVisibility(Visibilities.LOCAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-21
@@ -38,12 +38,12 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme
|
|||||||
@NotNull Name name,
|
@NotNull Name name,
|
||||||
@NotNull Kind kind
|
@NotNull Kind kind
|
||||||
) {
|
) {
|
||||||
super(containingDeclaration, annotations, name, kind);
|
this(containingDeclaration, null, annotations, name, kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SimpleFunctionDescriptorImpl(
|
protected SimpleFunctionDescriptorImpl(
|
||||||
@NotNull DeclarationDescriptor containingDeclaration,
|
@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
@NotNull SimpleFunctionDescriptor original,
|
@Nullable SimpleFunctionDescriptor original,
|
||||||
@NotNull Annotations annotations,
|
@NotNull Annotations annotations,
|
||||||
@NotNull Name name,
|
@NotNull Name name,
|
||||||
@NotNull Kind kind) {
|
@NotNull Kind kind) {
|
||||||
@@ -76,30 +76,19 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
||||||
if (preserveOriginal) {
|
return new SimpleFunctionDescriptorImpl(
|
||||||
return new SimpleFunctionDescriptorImpl(
|
newOwner,
|
||||||
newOwner,
|
preserveOriginal ? getOriginal() : null,
|
||||||
getOriginal(),
|
// TODO : safeSubstitute
|
||||||
// TODO : safeSubstitute
|
getAnnotations(),
|
||||||
getAnnotations(),
|
getName(),
|
||||||
getName(),
|
kind);
|
||||||
kind);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return new SimpleFunctionDescriptorImpl(
|
|
||||||
newOwner,
|
|
||||||
// TODO : safeSubstitute
|
|
||||||
getAnnotations(),
|
|
||||||
getName(),
|
|
||||||
kind);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public SimpleFunctionDescriptor copy(DeclarationDescriptor newOwner, Modality modality, Visibility visibility, Kind kind, boolean copyOverrides) {
|
public SimpleFunctionDescriptor copy(DeclarationDescriptor newOwner, Modality modality, Visibility visibility, Kind kind, boolean copyOverrides) {
|
||||||
SimpleFunctionDescriptorImpl copy = (SimpleFunctionDescriptorImpl)doSubstitute(TypeSubstitutor.EMPTY, newOwner, modality, visibility, false, copyOverrides, kind);
|
return (SimpleFunctionDescriptorImpl)doSubstitute(TypeSubstitutor.EMPTY, newOwner, modality, visibility, false, copyOverrides, kind);
|
||||||
return copy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
Reference in New Issue
Block a user