Deserialize annotations on value parameters of functions

This commit is contained in:
Alexander Udalov
2013-10-21 20:05:38 +04:00
parent 4105455179
commit 938a906bcd
24 changed files with 395 additions and 43 deletions
@@ -237,7 +237,7 @@ public class DescriptorDeserializer {
local.typeDeserializer.typeOrNull(proto.hasReceiverType() ? proto.getReceiverType() : null),
getExpectedThisObject(),
typeParameters,
local.valueParameters(proto.getValueParameterList()),
local.valueParameters(proto),
local.typeDeserializer.type(proto.getReturnType()),
modality(Flags.MODALITY.get(flags)),
visibility(Flags.VISIBILITY.get(flags)),
@@ -265,7 +265,7 @@ public class DescriptorDeserializer {
DescriptorDeserializer local = createChildDeserializer(descriptor, Collections.<TypeParameter>emptyList(), typeParameters);
descriptor.initialize(
classDescriptor.getTypeConstructor().getParameters(),
local.valueParameters(proto.getValueParameterList()),
local.valueParameters(proto),
visibility(Flags.VISIBILITY.get(proto.getFlags())),
DescriptorUtils.isConstructorOfStaticNestedClass(descriptor)
);
@@ -384,29 +384,37 @@ public class DescriptorDeserializer {
}
@NotNull
private List<ValueParameterDescriptor> valueParameters(@NotNull List<Callable.ValueParameter> protos) {
private List<ValueParameterDescriptor> valueParameters(@NotNull Callable callable) {
DeclarationDescriptor containerOfCallable = containingDeclaration.getContainingDeclaration();
assert containerOfCallable instanceof ClassOrNamespaceDescriptor
: "Only members in classes or namespaces should be serialized: " + containerOfCallable;
ClassOrNamespaceDescriptor classOrNamespace = (ClassOrNamespaceDescriptor) containerOfCallable;
List<Callable.ValueParameter> protos = callable.getValueParameterList();
List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>(protos.size());
for (int i = 0; i < protos.size(); i++) {
Callable.ValueParameter proto = protos.get(i);
result.add(valueParameter(proto, i));
result.add(new ValueParameterDescriptorImpl(
containingDeclaration,
i,
getAnnotations(classOrNamespace, callable, proto),
nameResolver.getName(proto.getName()),
typeDeserializer.type(proto.getType()),
Flags.DECLARES_DEFAULT_VALUE.get(proto.getFlags()),
typeDeserializer.typeOrNull(proto.hasVarargElementType() ? proto.getVarargElementType() : null))
);
}
return result;
}
private ValueParameterDescriptor valueParameter(Callable.ValueParameter proto, int index) {
return new ValueParameterDescriptorImpl(
containingDeclaration,
index,
getAnnotations(proto),
nameResolver.getName(proto.getName()),
typeDeserializer.type(proto.getType()),
Flags.DECLARES_DEFAULT_VALUE.get(proto.getFlags()),
typeDeserializer.typeOrNull(proto.hasVarargElementType() ? proto.getVarargElementType() : null));
}
private List<AnnotationDescriptor> getAnnotations(Callable.ValueParameter proto) {
return Flags.HAS_ANNOTATIONS.get(proto.getFlags())
? annotationDeserializer.loadValueParameterAnnotations(proto)
@NotNull
private List<AnnotationDescriptor> getAnnotations(
@NotNull ClassOrNamespaceDescriptor classOrNamespace,
@NotNull Callable callable,
@NotNull Callable.ValueParameter valueParameter
) {
return Flags.HAS_ANNOTATIONS.get(valueParameter.getFlags())
? annotationDeserializer.loadValueParameterAnnotations(classOrNamespace, callable, nameResolver, valueParameter)
: Collections.<AnnotationDescriptor>emptyList();
}
}
@@ -1,3 +1,19 @@
/*
* 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;
@@ -30,7 +46,12 @@ public interface AnnotationDeserializer {
@NotNull
@Override
public List<AnnotationDescriptor> loadValueParameterAnnotations(@NotNull ProtoBuf.Callable.ValueParameter parameterProto) {
public List<AnnotationDescriptor> loadValueParameterAnnotations(
@NotNull ClassOrNamespaceDescriptor container,
@NotNull ProtoBuf.Callable callable,
@NotNull NameResolver nameResolver,
@NotNull ProtoBuf.Callable.ValueParameter proto
) {
return notSupported();
}
@@ -59,5 +80,10 @@ public interface AnnotationDeserializer {
);
@NotNull
List<AnnotationDescriptor> loadValueParameterAnnotations(@NotNull ProtoBuf.Callable.ValueParameter parameterProto);
List<AnnotationDescriptor> loadValueParameterAnnotations(
@NotNull ClassOrNamespaceDescriptor container,
@NotNull ProtoBuf.Callable callable,
@NotNull NameResolver nameResolver,
@NotNull ProtoBuf.Callable.ValueParameter proto
);
}