Only create lazy annotations for descriptors from code
This commit is contained in:
+9
-5
@@ -42,7 +42,9 @@ import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import javax.inject.Inject;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.jet.descriptors.serialization.descriptors.Deserializers.AnnotatedCallableKind;
|
||||
import static org.jetbrains.jet.lang.resolve.kotlin.DescriptorDeserializersStorage.MemberSignature;
|
||||
@@ -119,10 +121,10 @@ public class AnnotationDescriptorDeserializer extends BaseDescriptorDeserializer
|
||||
if (JvmAnnotationNames.isSpecialAnnotation(className)) return null;
|
||||
|
||||
final ClassDescriptor annotationClass = resolveClass(className, classResolver);
|
||||
final AnnotationDescriptorImpl annotation = new AnnotationDescriptorImpl();
|
||||
annotation.setAnnotationType(annotationClass.getDefaultType());
|
||||
|
||||
return new KotlinJvmBinaryClass.AnnotationArgumentVisitor() {
|
||||
private final Map<ValueParameterDescriptor, CompileTimeConstant<?>> arguments = new HashMap<ValueParameterDescriptor, CompileTimeConstant<?>>();
|
||||
|
||||
@Override
|
||||
public void visit(@Nullable Name name, @Nullable Object value) {
|
||||
if (name != null) {
|
||||
@@ -157,14 +159,16 @@ public class AnnotationDescriptorDeserializer extends BaseDescriptorDeserializer
|
||||
|
||||
@Override
|
||||
public void visitEnd() {
|
||||
annotation.markValueArgumentsResolved();
|
||||
result.add(annotation);
|
||||
result.add(new AnnotationDescriptorImpl(
|
||||
annotationClass.getDefaultType(),
|
||||
arguments
|
||||
));
|
||||
}
|
||||
|
||||
private void setArgumentValueByName(@NotNull Name name, @NotNull CompileTimeConstant<?> argumentValue) {
|
||||
ValueParameterDescriptor parameter = DescriptorResolverUtils.getAnnotationParameterByName(name, annotationClass);
|
||||
if (parameter != null) {
|
||||
annotation.setValueArgument(parameter, argumentValue);
|
||||
arguments.put(parameter, argumentValue);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+11
-24
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.annotations;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
@@ -28,9 +27,16 @@ import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public class AnnotationDescriptorImpl implements AnnotationDescriptor {
|
||||
private JetType annotationType;
|
||||
private final Map<ValueParameterDescriptor, CompileTimeConstant<?>> valueArguments = Maps.newHashMap();
|
||||
private boolean valueArgumentsResolved = false;
|
||||
private final JetType annotationType;
|
||||
private final Map<ValueParameterDescriptor, CompileTimeConstant<?>> valueArguments;
|
||||
|
||||
public AnnotationDescriptorImpl(
|
||||
@NotNull JetType annotationType,
|
||||
@NotNull Map<ValueParameterDescriptor, CompileTimeConstant<?>> valueArguments
|
||||
) {
|
||||
this.annotationType = annotationType;
|
||||
this.valueArguments = Collections.unmodifiableMap(valueArguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
@@ -47,26 +53,7 @@ public class AnnotationDescriptorImpl implements AnnotationDescriptor {
|
||||
@Override
|
||||
@NotNull
|
||||
public Map<ValueParameterDescriptor, CompileTimeConstant<?>> getAllValueArguments() {
|
||||
// TODO: this assertion does not hold now, but this whole class will be gone before long, so I'm not fixing it
|
||||
//assert valueArgumentsResolved : "Value arguments are not resolved yet for [" + getType() + "]";
|
||||
return Collections.unmodifiableMap(valueArguments);
|
||||
}
|
||||
|
||||
public void setAnnotationType(@NotNull JetType annotationType) {
|
||||
this.annotationType = annotationType;
|
||||
}
|
||||
|
||||
public void setValueArgument(@NotNull ValueParameterDescriptor name, @NotNull CompileTimeConstant<?> value) {
|
||||
assert !valueArgumentsResolved : "Value arguments are already resolved for " + this;
|
||||
valueArguments.put(name, value);
|
||||
}
|
||||
|
||||
public void markValueArgumentsResolved() {
|
||||
this.valueArgumentsResolved = true;
|
||||
}
|
||||
|
||||
public boolean areValueArgumentsResolved() {
|
||||
return valueArgumentsResolved;
|
||||
return valueArguments;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user