replace lazy type with explicit deferred task list

This commit is contained in:
Stepan Koltsov
2012-04-19 14:05:39 +04:00
parent cd8e275cf4
commit 9cc11adf7b
@@ -333,7 +333,15 @@ public class JavaDescriptorResolver {
@Nullable @Nullable
public ClassDescriptor resolveClass(@NotNull FqName qualifiedName, @NotNull DescriptorSearchRule searchRule) { public ClassDescriptor resolveClass(@NotNull FqName qualifiedName, @NotNull DescriptorSearchRule searchRule) {
List<Runnable> tasks = Lists.newArrayList();
ClassDescriptor clazz = resolveClass(qualifiedName, searchRule, tasks);
for (Runnable task : tasks) {
task.run();
}
return clazz;
}
private ClassDescriptor resolveClass(@NotNull FqName qualifiedName, @NotNull DescriptorSearchRule searchRule, @NotNull List<Runnable> tasks) {
if (qualifiedName.getFqName().endsWith(JvmAbi.TRAIT_IMPL_SUFFIX)) { if (qualifiedName.getFqName().endsWith(JvmAbi.TRAIT_IMPL_SUFFIX)) {
// TODO: only if -$$TImpl class is created by Kotlin // TODO: only if -$$TImpl class is created by Kotlin
return null; return null;
@@ -368,12 +376,12 @@ public class JavaDescriptorResolver {
if (psiClass == null) { if (psiClass == null) {
return null; return null;
} }
classData = createJavaClassDescriptor(psiClass); classData = createJavaClassDescriptor(psiClass, tasks);
} }
return classData.getClassDescriptor(); return classData.getClassDescriptor();
} }
private ResolverBinaryClassData createJavaClassDescriptor(@NotNull final PsiClass psiClass) { private ResolverBinaryClassData createJavaClassDescriptor(@NotNull final PsiClass psiClass, List<Runnable> taskList) {
FqName fqName = new FqName(psiClass.getQualifiedName()); FqName fqName = new FqName(psiClass.getQualifiedName());
if (classDescriptorCache.containsKey(fqName)) { if (classDescriptorCache.containsKey(fqName)) {
throw new IllegalStateException(psiClass.getQualifiedName()); throw new IllegalStateException(psiClass.getQualifiedName());
@@ -387,7 +395,7 @@ public class JavaDescriptorResolver {
ResolverBinaryClassData classData = new ResolverBinaryClassData(psiClass, fqName, new MutableClassDescriptorLite(containingDeclaration, kind)); ResolverBinaryClassData classData = new ResolverBinaryClassData(psiClass, fqName, new MutableClassDescriptorLite(containingDeclaration, kind));
classDescriptorCache.put(fqName, classData); classDescriptorCache.put(fqName, classData);
classData.classDescriptor.setName(name); classData.classDescriptor.setName(name);
classData.classDescriptor.setAnnotations(resolveAnnotations(psiClass)); classData.classDescriptor.setAnnotations(resolveAnnotations(psiClass, taskList));
List<JetType> supertypes = new ArrayList<JetType>(); List<JetType> supertypes = new ArrayList<JetType>();
@@ -1599,11 +1607,11 @@ public class JavaDescriptorResolver {
return (FunctionDescriptorImpl) substitutedFunctionDescriptor; return (FunctionDescriptorImpl) substitutedFunctionDescriptor;
} }
private List<AnnotationDescriptor> resolveAnnotations(PsiModifierListOwner owner) { private List<AnnotationDescriptor> resolveAnnotations(PsiModifierListOwner owner, @NotNull List<Runnable> tasks) {
PsiAnnotation[] psiAnnotations = owner.getModifierList().getAnnotations(); PsiAnnotation[] psiAnnotations = owner.getModifierList().getAnnotations();
List<AnnotationDescriptor> r = Lists.newArrayListWithCapacity(psiAnnotations.length); List<AnnotationDescriptor> r = Lists.newArrayListWithCapacity(psiAnnotations.length);
for (PsiAnnotation psiAnnotation : psiAnnotations) { for (PsiAnnotation psiAnnotation : psiAnnotations) {
AnnotationDescriptor annotation = resolveAnnotation(psiAnnotation); AnnotationDescriptor annotation = resolveAnnotation(psiAnnotation, tasks);
if (annotation != null) { if (annotation != null) {
r.add(annotation); r.add(annotation);
} }
@@ -1611,9 +1619,18 @@ public class JavaDescriptorResolver {
return r; return r;
} }
private List<AnnotationDescriptor> resolveAnnotations(PsiModifierListOwner owner) {
List<Runnable> tasks = Lists.newArrayList();
List<AnnotationDescriptor> annotations = resolveAnnotations(owner, tasks);
for (Runnable task : tasks) {
task.run();
}
return annotations;
}
@Nullable @Nullable
private AnnotationDescriptor resolveAnnotation(PsiAnnotation psiAnnotation) { private AnnotationDescriptor resolveAnnotation(PsiAnnotation psiAnnotation, @NotNull List<Runnable> taskList) {
AnnotationDescriptor annotation = new AnnotationDescriptor(); final AnnotationDescriptor annotation = new AnnotationDescriptor();
String qname = psiAnnotation.getQualifiedName(); String qname = psiAnnotation.getQualifiedName();
if (qname.startsWith("java.lang.annotation.") || qname.startsWith("jet.runtime.typeinfo.") || qname.equals(JvmAbi.JETBRAINS_NOT_NULL_ANNOTATION.getFqName().getFqName())) { if (qname.startsWith("java.lang.annotation.") || qname.startsWith("jet.runtime.typeinfo.") || qname.equals(JvmAbi.JETBRAINS_NOT_NULL_ANNOTATION.getFqName().getFqName())) {
@@ -1621,18 +1638,16 @@ public class JavaDescriptorResolver {
return null; return null;
} }
final ClassDescriptor clazz = resolveClass(new FqName(psiAnnotation.getQualifiedName()), DescriptorSearchRule.INCLUDE_KOTLIN); final ClassDescriptor clazz = resolveClass(new FqName(psiAnnotation.getQualifiedName()), DescriptorSearchRule.INCLUDE_KOTLIN, taskList);
if (clazz == null) { if (clazz == null) {
return null; return null;
} }
// TODO: no lazy types taskList.add(new Runnable() {
//annotation.setAnnotationType(clazz.getDefaultType());
annotation.setAnnotationType(DeferredType.create(new BindingTraceContext(), new LazyValue<JetType>() {
@Override @Override
protected JetType compute() { public void run() {
return clazz.getDefaultType(); annotation.setAnnotationType(clazz.getDefaultType());
} }
})); });
ArrayList<CompileTimeConstant<?>> valueArguments = new ArrayList<CompileTimeConstant<?>>(); ArrayList<CompileTimeConstant<?>> valueArguments = new ArrayList<CompileTimeConstant<?>>();
PsiAnnotationParameterList parameterList = psiAnnotation.getParameterList(); PsiAnnotationParameterList parameterList = psiAnnotation.getParameterList();