Deserialization of function descriptors via DesirializedSimpleFunctionDescriptor
This commit is contained in:
+17
-6
@@ -19,6 +19,7 @@ package org.jetbrains.jet.descriptors.serialization;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.descriptors.serialization.descriptors.AnnotationDeserializer;
|
import org.jetbrains.jet.descriptors.serialization.descriptors.AnnotationDeserializer;
|
||||||
|
import org.jetbrains.jet.descriptors.serialization.descriptors.DeserializedSimpleFunctionDescriptor;
|
||||||
import org.jetbrains.jet.descriptors.serialization.descriptors.DeserializedTypeParameterDescriptor;
|
import org.jetbrains.jet.descriptors.serialization.descriptors.DeserializedTypeParameterDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
@@ -226,11 +227,10 @@ 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();
|
||||||
SimpleFunctionDescriptorImpl function = new SimpleFunctionDescriptorImpl(
|
DeserializedSimpleFunctionDescriptor function = new DeserializedSimpleFunctionDescriptor(
|
||||||
containingDeclaration,
|
containingDeclaration, proto,
|
||||||
getAnnotations(proto, proto.getFlags(), AnnotatedCallableKind.FUNCTION),
|
annotationDeserializer,
|
||||||
nameResolver.getName(proto.getName()),
|
nameResolver
|
||||||
memberKind(Flags.MEMBER_KIND.get(flags))
|
|
||||||
);
|
);
|
||||||
List<TypeParameterDescriptor> typeParameters = new ArrayList<TypeParameterDescriptor>(proto.getTypeParameterCount());
|
List<TypeParameterDescriptor> typeParameters = new ArrayList<TypeParameterDescriptor>(proto.getTypeParameterCount());
|
||||||
DescriptorDeserializer local = createChildDeserializer(function, proto.getTypeParameterList(), typeParameters);
|
DescriptorDeserializer local = createChildDeserializer(function, proto.getTypeParameterList(), typeParameters);
|
||||||
@@ -274,6 +274,17 @@ public class DescriptorDeserializer {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private List<AnnotationDescriptor> getAnnotations(@NotNull Callable proto, int flags, @NotNull AnnotatedCallableKind kind) {
|
private List<AnnotationDescriptor> getAnnotations(@NotNull Callable proto, int flags, @NotNull AnnotatedCallableKind kind) {
|
||||||
|
return getAnnotations(containingDeclaration, proto, flags, kind, annotationDeserializer, nameResolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<AnnotationDescriptor> getAnnotations(
|
||||||
|
@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
|
@NotNull Callable proto,
|
||||||
|
int flags,
|
||||||
|
@NotNull AnnotatedCallableKind kind,
|
||||||
|
@NotNull AnnotationDeserializer annotationDeserializer,
|
||||||
|
@NotNull NameResolver nameResolver
|
||||||
|
) {
|
||||||
assert containingDeclaration instanceof ClassOrNamespaceDescriptor
|
assert containingDeclaration instanceof ClassOrNamespaceDescriptor
|
||||||
: "Only members in classes or namespaces should be serialized: " + containingDeclaration;
|
: "Only members in classes or namespaces should be serialized: " + containingDeclaration;
|
||||||
return Flags.HAS_ANNOTATIONS.get(flags)
|
return Flags.HAS_ANNOTATIONS.get(flags)
|
||||||
@@ -282,7 +293,7 @@ public class DescriptorDeserializer {
|
|||||||
: Collections.<AnnotationDescriptor>emptyList();
|
: Collections.<AnnotationDescriptor>emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CallableMemberDescriptor.Kind memberKind(Callable.MemberKind memberKind) {
|
public static CallableMemberDescriptor.Kind memberKind(Callable.MemberKind memberKind) {
|
||||||
switch (memberKind) {
|
switch (memberKind) {
|
||||||
case DECLARATION:
|
case DECLARATION:
|
||||||
return CallableMemberDescriptor.Kind.DECLARATION;
|
return CallableMemberDescriptor.Kind.DECLARATION;
|
||||||
|
|||||||
+118
@@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.descriptors.serialization.descriptors;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.descriptors.serialization.DescriptorDeserializer;
|
||||||
|
import org.jetbrains.jet.descriptors.serialization.Flags;
|
||||||
|
import org.jetbrains.jet.descriptors.serialization.NameResolver;
|
||||||
|
import org.jetbrains.jet.descriptors.serialization.ProtoBuf;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.impl.FunctionDescriptorImpl;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.impl.SimpleFunctionDescriptorImpl;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DeserializedSimpleFunctionDescriptor extends SimpleFunctionDescriptorImpl {
|
||||||
|
|
||||||
|
private final ProtoBuf.Callable functionProto;
|
||||||
|
private final NameResolver nameResolver;
|
||||||
|
|
||||||
|
private DeserializedSimpleFunctionDescriptor(
|
||||||
|
@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
|
@NotNull List<AnnotationDescriptor> annotations,
|
||||||
|
@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 List<AnnotationDescriptor> annotations,
|
||||||
|
@NotNull Name name,
|
||||||
|
@NotNull Kind kind,
|
||||||
|
@NotNull ProtoBuf.Callable functionProto,
|
||||||
|
@NotNull NameResolver nameResolver) {
|
||||||
|
super(containingDeclaration, original, annotations, name, kind);
|
||||||
|
this.functionProto = functionProto;
|
||||||
|
this.nameResolver = nameResolver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeserializedSimpleFunctionDescriptor(
|
||||||
|
@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
|
@NotNull ProtoBuf.Callable functionProto,
|
||||||
|
@NotNull AnnotationDeserializer annotationDeserializer,
|
||||||
|
@NotNull NameResolver nameResolver
|
||||||
|
) {
|
||||||
|
this(containingDeclaration,
|
||||||
|
DescriptorDeserializer.getAnnotations(containingDeclaration, functionProto, functionProto.getFlags(),
|
||||||
|
AnnotationDeserializer.AnnotatedCallableKind.FUNCTION, annotationDeserializer,
|
||||||
|
nameResolver),
|
||||||
|
nameResolver.getName(functionProto.getName()),
|
||||||
|
DescriptorDeserializer.memberKind(Flags.MEMBER_KIND.get(functionProto.getFlags())),
|
||||||
|
functionProto,
|
||||||
|
nameResolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
||||||
|
if (preserveOriginal) {
|
||||||
|
return new DeserializedSimpleFunctionDescriptor(
|
||||||
|
newOwner,
|
||||||
|
getOriginal(),
|
||||||
|
getAnnotations(),
|
||||||
|
getName(),
|
||||||
|
kind,
|
||||||
|
functionProto,
|
||||||
|
nameResolver
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return new DeserializedSimpleFunctionDescriptor(
|
||||||
|
newOwner,
|
||||||
|
getAnnotations(),
|
||||||
|
getName(),
|
||||||
|
kind,
|
||||||
|
functionProto,
|
||||||
|
nameResolver
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public DeserializedSimpleFunctionDescriptor getOriginal() {
|
||||||
|
return (DeserializedSimpleFunctionDescriptor) super.getOriginal();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProtoBuf.Callable getFunctionProto() {
|
||||||
|
return functionProto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NameResolver getNameResolver() {
|
||||||
|
return nameResolver;
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -41,7 +41,7 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme
|
|||||||
super(containingDeclaration, annotations, name, kind);
|
super(containingDeclaration, annotations, name, kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SimpleFunctionDescriptorImpl(
|
protected SimpleFunctionDescriptorImpl(
|
||||||
@NotNull DeclarationDescriptor containingDeclaration,
|
@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
@NotNull SimpleFunctionDescriptor original,
|
@NotNull SimpleFunctionDescriptor original,
|
||||||
@NotNull List<AnnotationDescriptor> annotations,
|
@NotNull List<AnnotationDescriptor> annotations,
|
||||||
|
|||||||
Reference in New Issue
Block a user