Make room for laziness in the Annotations interface
This commit is contained in:
+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;
|
||||
|
||||
Reference in New Issue
Block a user