Introduce PostponedTasks helper class to replace List<Runnable> passed everywhere in jdr
This commit is contained in:
+2
-2
@@ -135,8 +135,8 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public ClassDescriptor resolveClass(FqName name, DescriptorSearchRule searchRule, List<Runnable> list) {
|
public ClassDescriptor resolveClass(@NotNull FqName name, @NotNull DescriptorSearchRule searchRule, @NotNull PostponedTasks tasks) {
|
||||||
return classResolver.resolveClass(name, searchRule, list);
|
return classResolver.resolveClass(name, searchRule, tasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ValueParameterDescriptors {
|
public static class ValueParameterDescriptors {
|
||||||
|
|||||||
+15
-15
@@ -53,7 +53,8 @@ public final class JavaAnnotationResolver {
|
|||||||
this.compileTimeConstResolver = compileTimeConstResolver;
|
this.compileTimeConstResolver = compileTimeConstResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<AnnotationDescriptor> resolveAnnotations(PsiModifierListOwner owner, @NotNull List<Runnable> tasks) {
|
@NotNull
|
||||||
|
public List<AnnotationDescriptor> resolveAnnotations(@NotNull PsiModifierListOwner owner, @NotNull PostponedTasks tasks) {
|
||||||
PsiAnnotation[] psiAnnotations = getAllAnnotations(owner);
|
PsiAnnotation[] psiAnnotations = getAllAnnotations(owner);
|
||||||
List<AnnotationDescriptor> r = Lists.newArrayListWithCapacity(psiAnnotations.length);
|
List<AnnotationDescriptor> r = Lists.newArrayListWithCapacity(psiAnnotations.length);
|
||||||
for (PsiAnnotation psiAnnotation : psiAnnotations) {
|
for (PsiAnnotation psiAnnotation : psiAnnotations) {
|
||||||
@@ -65,17 +66,16 @@ public final class JavaAnnotationResolver {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<AnnotationDescriptor> resolveAnnotations(PsiModifierListOwner owner) {
|
@NotNull
|
||||||
List<Runnable> tasks = Lists.newArrayList();
|
public List<AnnotationDescriptor> resolveAnnotations(@NotNull PsiModifierListOwner owner) {
|
||||||
List<AnnotationDescriptor> annotations = resolveAnnotations(owner, tasks);
|
PostponedTasks postponedTasks = new PostponedTasks();
|
||||||
for (Runnable task : tasks) {
|
List<AnnotationDescriptor> annotations = resolveAnnotations(owner, postponedTasks);
|
||||||
task.run();
|
postponedTasks.performTasks();
|
||||||
}
|
|
||||||
return annotations;
|
return annotations;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public AnnotationDescriptor resolveAnnotation(PsiAnnotation psiAnnotation, @NotNull List<Runnable> taskList) {
|
public AnnotationDescriptor resolveAnnotation(PsiAnnotation psiAnnotation, @NotNull PostponedTasks postponedTasks) {
|
||||||
final AnnotationDescriptor annotation = new AnnotationDescriptor();
|
final AnnotationDescriptor annotation = new AnnotationDescriptor();
|
||||||
String qname = psiAnnotation.getQualifiedName();
|
String qname = psiAnnotation.getQualifiedName();
|
||||||
if (qname == null) {
|
if (qname == null) {
|
||||||
@@ -88,16 +88,16 @@ public final class JavaAnnotationResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FqName annotationFqName = new FqName(qname);
|
FqName annotationFqName = new FqName(qname);
|
||||||
final ClassDescriptor clazz =
|
final ClassDescriptor annotationClass =
|
||||||
classResolver.resolveClass(annotationFqName, DescriptorSearchRule.INCLUDE_KOTLIN, taskList);
|
classResolver.resolveClass(annotationFqName, DescriptorSearchRule.INCLUDE_KOTLIN, postponedTasks);
|
||||||
if (clazz == null) {
|
if (annotationClass == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
taskList.add(new Runnable() {
|
postponedTasks.addTask(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
annotation.setAnnotationType(clazz.getDefaultType());
|
annotation.setAnnotationType(annotationClass.getDefaultType());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -111,10 +111,10 @@ public final class JavaAnnotationResolver {
|
|||||||
|
|
||||||
assert value != null;
|
assert value != null;
|
||||||
CompileTimeConstant compileTimeConst =
|
CompileTimeConstant compileTimeConst =
|
||||||
compileTimeConstResolver.getCompileTimeConstFromExpression(annotationFqName, identifier, value, taskList);
|
compileTimeConstResolver.getCompileTimeConstFromExpression(annotationFqName, identifier, value, postponedTasks);
|
||||||
if (compileTimeConst != null) {
|
if (compileTimeConst != null) {
|
||||||
ValueParameterDescriptor valueParameterDescriptor =
|
ValueParameterDescriptor valueParameterDescriptor =
|
||||||
DescriptorResolverUtils.getValueParameterDescriptorForAnnotationParameter(identifier, clazz);
|
DescriptorResolverUtils.getValueParameterDescriptorForAnnotationParameter(identifier, annotationClass);
|
||||||
if (valueParameterDescriptor != null) {
|
if (valueParameterDescriptor != null) {
|
||||||
annotation.setValueArgument(valueParameterDescriptor, compileTimeConst);
|
annotation.setValueArgument(valueParameterDescriptor, compileTimeConst);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-9
@@ -123,11 +123,9 @@ public final class JavaClassResolver {
|
|||||||
|
|
||||||
@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();
|
PostponedTasks postponedTasks = new PostponedTasks();
|
||||||
ClassDescriptor clazz = resolveClass(qualifiedName, searchRule, tasks);
|
ClassDescriptor clazz = resolveClass(qualifiedName, searchRule, postponedTasks);
|
||||||
for (Runnable task : tasks) {
|
postponedTasks.performTasks();
|
||||||
task.run();
|
|
||||||
}
|
|
||||||
return clazz;
|
return clazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +133,7 @@ public final class JavaClassResolver {
|
|||||||
public ClassDescriptor resolveClass(
|
public ClassDescriptor resolveClass(
|
||||||
@NotNull FqName qualifiedName,
|
@NotNull FqName qualifiedName,
|
||||||
@NotNull DescriptorSearchRule searchRule,
|
@NotNull DescriptorSearchRule searchRule,
|
||||||
@NotNull List<Runnable> tasks
|
@NotNull PostponedTasks tasks
|
||||||
) {
|
) {
|
||||||
if (isTraitImplementation(qualifiedName)) {
|
if (isTraitImplementation(qualifiedName)) {
|
||||||
return null;
|
return null;
|
||||||
@@ -162,7 +160,7 @@ public final class JavaClassResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private ClassDescriptor doResolveClass(@NotNull FqName qualifiedName, List<Runnable> tasks) {
|
private ClassDescriptor doResolveClass(@NotNull FqName qualifiedName, @NotNull PostponedTasks tasks) {
|
||||||
PsiClass psiClass = psiClassFinder.findPsiClass(qualifiedName, PsiClassFinder.RuntimeClassesHandleMode.THROW);
|
PsiClass psiClass = psiClassFinder.findPsiClass(qualifiedName, PsiClassFinder.RuntimeClassesHandleMode.THROW);
|
||||||
if (psiClass == null) {
|
if (psiClass == null) {
|
||||||
cacheValue(qualifiedName);
|
cacheValue(qualifiedName);
|
||||||
@@ -187,7 +185,7 @@ public final class JavaClassResolver {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private ResolverClassData createJavaClassDescriptor(
|
private ResolverClassData createJavaClassDescriptor(
|
||||||
@NotNull FqName fqName, @NotNull final PsiClass psiClass,
|
@NotNull FqName fqName, @NotNull final PsiClass psiClass,
|
||||||
List<Runnable> taskList
|
@NotNull PostponedTasks taskList
|
||||||
) {
|
) {
|
||||||
|
|
||||||
checkFqNamesAreConsistent(psiClass, fqName);
|
checkFqNamesAreConsistent(psiClass, fqName);
|
||||||
@@ -207,7 +205,7 @@ public final class JavaClassResolver {
|
|||||||
private ResolverClassData doCreateClassDescriptor(
|
private ResolverClassData doCreateClassDescriptor(
|
||||||
@NotNull FqName fqName,
|
@NotNull FqName fqName,
|
||||||
@NotNull PsiClass psiClass,
|
@NotNull PsiClass psiClass,
|
||||||
@NotNull List<Runnable> taskList,
|
@NotNull PostponedTasks taskList,
|
||||||
@NotNull ClassOrNamespaceDescriptor containingDeclaration
|
@NotNull ClassOrNamespaceDescriptor containingDeclaration
|
||||||
) {
|
) {
|
||||||
JetClassAnnotation jetClassAnnotation = JetClassAnnotation.get(psiClass);
|
JetClassAnnotation jetClassAnnotation = JetClassAnnotation.get(psiClass);
|
||||||
|
|||||||
+9
-8
@@ -59,29 +59,29 @@ public final class JavaCompileTimeConstResolver {
|
|||||||
@Nullable
|
@Nullable
|
||||||
public CompileTimeConstant<?> getCompileTimeConstFromExpression(
|
public CompileTimeConstant<?> getCompileTimeConstFromExpression(
|
||||||
FqName annotationFqName, Name parameterName,
|
FqName annotationFqName, Name parameterName,
|
||||||
PsiAnnotationMemberValue value, List<Runnable> taskList
|
PsiAnnotationMemberValue value, PostponedTasks postponedTasks
|
||||||
) {
|
) {
|
||||||
if (value instanceof PsiLiteralExpression) {
|
if (value instanceof PsiLiteralExpression) {
|
||||||
return getCompileTimeConstFromLiteralExpression((PsiLiteralExpression) value);
|
return getCompileTimeConstFromLiteralExpression((PsiLiteralExpression) value);
|
||||||
}
|
}
|
||||||
// Enum
|
// Enum
|
||||||
else if (value instanceof PsiReferenceExpression) {
|
else if (value instanceof PsiReferenceExpression) {
|
||||||
return getCompileTimeConstFromReferenceExpression((PsiReferenceExpression) value, taskList);
|
return getCompileTimeConstFromReferenceExpression((PsiReferenceExpression) value, postponedTasks);
|
||||||
}
|
}
|
||||||
// Array
|
// Array
|
||||||
else if (value instanceof PsiArrayInitializerMemberValue) {
|
else if (value instanceof PsiArrayInitializerMemberValue) {
|
||||||
return getCompileTimeConstFromArrayExpression(annotationFqName, parameterName, (PsiArrayInitializerMemberValue) value,
|
return getCompileTimeConstFromArrayExpression(annotationFqName, parameterName, (PsiArrayInitializerMemberValue) value,
|
||||||
taskList);
|
postponedTasks);
|
||||||
}
|
}
|
||||||
// Annotation
|
// Annotation
|
||||||
else if (value instanceof PsiAnnotation) {
|
else if (value instanceof PsiAnnotation) {
|
||||||
return getCompileTimeConstFromAnnotation((PsiAnnotation) value, taskList);
|
return getCompileTimeConstFromAnnotation((PsiAnnotation) value, postponedTasks);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private CompileTimeConstant<?> getCompileTimeConstFromAnnotation(PsiAnnotation value, List<Runnable> taskList) {
|
private CompileTimeConstant<?> getCompileTimeConstFromAnnotation(PsiAnnotation value, PostponedTasks taskList) {
|
||||||
AnnotationDescriptor annotationDescriptor = annotationResolver.resolveAnnotation(value, taskList);
|
AnnotationDescriptor annotationDescriptor = annotationResolver.resolveAnnotation(value, taskList);
|
||||||
if (annotationDescriptor != null) {
|
if (annotationDescriptor != null) {
|
||||||
return new AnnotationValue(annotationDescriptor);
|
return new AnnotationValue(annotationDescriptor);
|
||||||
@@ -93,7 +93,7 @@ public final class JavaCompileTimeConstResolver {
|
|||||||
private CompileTimeConstant<?> getCompileTimeConstFromArrayExpression(
|
private CompileTimeConstant<?> getCompileTimeConstFromArrayExpression(
|
||||||
FqName annotationFqName,
|
FqName annotationFqName,
|
||||||
Name valueName, PsiArrayInitializerMemberValue value,
|
Name valueName, PsiArrayInitializerMemberValue value,
|
||||||
List<Runnable> taskList
|
PostponedTasks taskList
|
||||||
) {
|
) {
|
||||||
PsiAnnotationMemberValue[] initializers = value.getInitializers();
|
PsiAnnotationMemberValue[] initializers = value.getInitializers();
|
||||||
List<CompileTimeConstant<?>> values = getCompileTimeConstantForArrayValues(annotationFqName, valueName, taskList, initializers);
|
List<CompileTimeConstant<?>> values = getCompileTimeConstantForArrayValues(annotationFqName, valueName, taskList, initializers);
|
||||||
@@ -101,6 +101,7 @@ public final class JavaCompileTimeConstResolver {
|
|||||||
ClassDescriptor classDescriptor =
|
ClassDescriptor classDescriptor =
|
||||||
classResolver.resolveClass(annotationFqName, DescriptorSearchRule.INCLUDE_KOTLIN, taskList);
|
classResolver.resolveClass(annotationFqName, DescriptorSearchRule.INCLUDE_KOTLIN, taskList);
|
||||||
|
|
||||||
|
//TODO: nullability issues
|
||||||
ValueParameterDescriptor valueParameterDescriptor =
|
ValueParameterDescriptor valueParameterDescriptor =
|
||||||
DescriptorResolverUtils.getValueParameterDescriptorForAnnotationParameter(valueName, classDescriptor);
|
DescriptorResolverUtils.getValueParameterDescriptorForAnnotationParameter(valueName, classDescriptor);
|
||||||
if (valueParameterDescriptor == null) {
|
if (valueParameterDescriptor == null) {
|
||||||
@@ -113,7 +114,7 @@ public final class JavaCompileTimeConstResolver {
|
|||||||
private List<CompileTimeConstant<?>> getCompileTimeConstantForArrayValues(
|
private List<CompileTimeConstant<?>> getCompileTimeConstantForArrayValues(
|
||||||
FqName annotationQualifiedName,
|
FqName annotationQualifiedName,
|
||||||
Name valueName,
|
Name valueName,
|
||||||
List<Runnable> taskList,
|
PostponedTasks taskList,
|
||||||
PsiAnnotationMemberValue[] initializers
|
PsiAnnotationMemberValue[] initializers
|
||||||
) {
|
) {
|
||||||
List<CompileTimeConstant<?>> values = new ArrayList<CompileTimeConstant<?>>();
|
List<CompileTimeConstant<?>> values = new ArrayList<CompileTimeConstant<?>>();
|
||||||
@@ -129,7 +130,7 @@ public final class JavaCompileTimeConstResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private CompileTimeConstant<?> getCompileTimeConstFromReferenceExpression(PsiReferenceExpression value, List<Runnable> taskList) {
|
private CompileTimeConstant<?> getCompileTimeConstFromReferenceExpression(PsiReferenceExpression value, PostponedTasks taskList) {
|
||||||
PsiElement resolveElement = value.resolve();
|
PsiElement resolveElement = value.resolve();
|
||||||
if (resolveElement instanceof PsiEnumConstant) {
|
if (resolveElement instanceof PsiEnumConstant) {
|
||||||
PsiElement psiElement = resolveElement.getParent();
|
PsiElement psiElement = resolveElement.getParent();
|
||||||
|
|||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 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.lang.resolve.java.resolver;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public final class PostponedTasks {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private final List<Runnable> tasks = Lists.newArrayList();
|
||||||
|
|
||||||
|
public void addTask(@NotNull Runnable runnable) {
|
||||||
|
tasks.add(runnable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void performTasks() {
|
||||||
|
for (Runnable task : tasks) {
|
||||||
|
task.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user