Make room for laziness in the Annotations interface
This commit is contained in:
@@ -149,7 +149,7 @@ public class PropertyCodegen extends GenerationStateAware {
|
||||
// Annotations on properties without backing fields are stored in bytecode on an empty synthetic method. This way they're still
|
||||
// accessible via reflection, and 'deprecated' and 'private' flags prevent this method from being called accidentally
|
||||
private void generateSyntheticMethodIfNeeded(@NotNull PropertyDescriptor descriptor) {
|
||||
if (descriptor.getAnnotations().getAnnotationDescriptors().isEmpty()) return;
|
||||
if (descriptor.getAnnotations().isEmpty()) return;
|
||||
|
||||
ReceiverParameterDescriptor receiver = descriptor.getReceiverParameter();
|
||||
Type receiverAsmType = receiver == null ? null : typeMapper.mapType(receiver.getType());
|
||||
|
||||
+1
-1
@@ -431,7 +431,7 @@ public class DescriptorSerializer {
|
||||
}
|
||||
|
||||
private static boolean hasAnnotations(Annotated descriptor) {
|
||||
return !descriptor.getAnnotations().getAnnotationDescriptors().isEmpty();
|
||||
return !descriptor.getAnnotations().isEmpty();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -155,7 +155,7 @@ public class DeclarationResolver {
|
||||
if (modifierList != null) {
|
||||
MutableClassDescriptor descriptor = entry.getValue();
|
||||
descriptor.addAnnotations(annotationResolver.resolveAnnotationsWithoutArguments(
|
||||
descriptor.getScopeForSupertypeResolution(), modifierList, trace).getAnnotationDescriptors());
|
||||
descriptor.getScopeForSupertypeResolution(), modifierList, trace));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-9
@@ -17,28 +17,23 @@
|
||||
package org.jetbrains.jet.lang.descriptors.annotations;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.ReadOnly;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public interface Annotations extends Iterable<AnnotationDescriptor> {
|
||||
Annotations EMPTY = new Annotations() {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<AnnotationDescriptor> getAnnotationDescriptors() {
|
||||
return Collections.emptyList();
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<AnnotationDescriptor> iterator() {
|
||||
return getAnnotationDescriptors().iterator();
|
||||
return Collections.<AnnotationDescriptor>emptyList().iterator();
|
||||
}
|
||||
};
|
||||
|
||||
@NotNull
|
||||
@ReadOnly
|
||||
List<AnnotationDescriptor> getAnnotationDescriptors();
|
||||
boolean isEmpty();
|
||||
}
|
||||
|
||||
+5
-1
@@ -29,11 +29,15 @@ public class AnnotationsImpl implements Annotations {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<AnnotationDescriptor> getAnnotationDescriptors() {
|
||||
return annotations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return getAnnotationDescriptors().isEmpty();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<AnnotationDescriptor> iterator() {
|
||||
|
||||
+10
-3
@@ -39,7 +39,7 @@ import java.util.List;
|
||||
|
||||
public abstract class MutableClassDescriptorLite extends ClassDescriptorBase {
|
||||
|
||||
private Annotations annotations = new AnnotationsImpl(new ArrayList<AnnotationDescriptor>(0));
|
||||
private Annotations annotations;
|
||||
|
||||
private List<TypeParameterDescriptor> typeParameters;
|
||||
private Collection<JetType> supertypes = Lists.newArrayList();
|
||||
@@ -183,6 +183,9 @@ public abstract class MutableClassDescriptorLite extends ClassDescriptorBase {
|
||||
@NotNull
|
||||
@Override
|
||||
public Annotations getAnnotations() {
|
||||
if (annotations == null) {
|
||||
annotations = new AnnotationsImpl(new ArrayList<AnnotationDescriptor>(0));
|
||||
}
|
||||
return annotations;
|
||||
}
|
||||
|
||||
@@ -190,8 +193,12 @@ public abstract class MutableClassDescriptorLite extends ClassDescriptorBase {
|
||||
this.annotations = annotations;
|
||||
}
|
||||
|
||||
public void addAnnotations(@NotNull List<AnnotationDescriptor> annotationDescriptors) {
|
||||
this.annotations.getAnnotationDescriptors().addAll(annotationDescriptors);
|
||||
public void addAnnotations(@NotNull Iterable<AnnotationDescriptor> annotationDescriptors) {
|
||||
|
||||
AnnotationsImpl annotationsImpl = (AnnotationsImpl) getAnnotations();
|
||||
for (AnnotationDescriptor annotationDescriptor : annotationDescriptors) {
|
||||
annotationsImpl.getAnnotationDescriptors().add(annotationDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
private PackageLikeBuilder builder = null;
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.di.InjectorForBodyResolve;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
@@ -216,7 +217,9 @@ public class ResolveElementCache {
|
||||
Annotated descriptor = analyzer.resolveToDescriptor(declaration);
|
||||
|
||||
// Activate annotation resolving
|
||||
descriptor.getAnnotations().getAnnotationDescriptors();
|
||||
for (AnnotationDescriptor annotationDescriptor : descriptor.getAnnotations()) {
|
||||
// do nothing, all we need is iteration
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user