Loading external annotations in JavaDescriptorResolver.

This commit is contained in:
Evgeny Gerashchenko
2012-06-27 00:43:42 +04:00
parent 18b53bb954
commit 9d90f96573
9 changed files with 58 additions and 23 deletions
@@ -27,12 +27,11 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.JetNamedFunction;
import org.jetbrains.jet.lang.psi.JetPsiFactory;
import org.jetbrains.jet.lang.psi.JetPsiUtil;
import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.constants.*;
import org.jetbrains.jet.lang.resolve.constants.StringValue;
import org.jetbrains.jet.lang.resolve.java.extAnnotations.ExternalAnnotationsProvider;
import org.jetbrains.jet.lang.resolve.java.kt.JetClassAnnotation;
import org.jetbrains.jet.lang.resolve.java.kt.PsiAnnotationWithFlags;
import org.jetbrains.jet.lang.resolve.name.FqName;
@@ -873,7 +872,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
if (parameter.getJetValueParameter().nullable()) {
transformedType = TypeUtils.makeNullableAsSpecified(outType, parameter.getJetValueParameter().nullable());
}
else if (parameter.getPsiParameter().getModifierList().findAnnotation(JvmAbi.JETBRAINS_NOT_NULL_ANNOTATION.getFqName().getFqName()) != null) {
else if (findAnnotation(parameter.getPsiParameter(), JvmAbi.JETBRAINS_NOT_NULL_ANNOTATION.getFqName().getFqName()) != null) {
transformedType = TypeUtils.makeNullableAsSpecified(outType, false);
}
else {
@@ -1151,7 +1150,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
}
else {
propertyType = semanticServices.getTypeTransformer().transformToType(anyMember.getType().getPsiType(), typeVariableResolverForPropertyInternals);
if (anyMember.getType().getPsiNotNullOwner().getModifierList().findAnnotation(JvmAbi.JETBRAINS_NOT_NULL_ANNOTATION.getFqName().getFqName()) != null) {
if (findAnnotation(anyMember.getType().getPsiNotNullOwner(), JvmAbi.JETBRAINS_NOT_NULL_ANNOTATION.getFqName().getFqName()) != null) {
propertyType = TypeUtils.makeNullableAsSpecified(propertyType, false);
}
else if (members.getter == null && members.setter == null && members.field.getMember().isFinal() && members.field.getMember().isStatic()) {
@@ -1420,7 +1419,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
}
private List<AnnotationDescriptor> resolveAnnotations(PsiModifierListOwner owner, @NotNull List<Runnable> tasks) {
PsiAnnotation[] psiAnnotations = owner.getModifierList().getAnnotations();
PsiAnnotation[] psiAnnotations = getAllAnnotations(owner);
List<AnnotationDescriptor> r = Lists.newArrayListWithCapacity(psiAnnotations.length);
for (PsiAnnotation psiAnnotation : psiAnnotations) {
AnnotationDescriptor annotation = resolveAnnotation(psiAnnotation, tasks);
@@ -1549,7 +1548,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
if (method.getJetMethod().returnTypeNullable()) {
return TypeUtils.makeNullableAsSpecified(transformedType, true);
}
else if (method.getPsiMethod().getModifierList().findAnnotation(JvmAbi.JETBRAINS_NOT_NULL_ANNOTATION.getFqName().getFqName()) != null) {
else if (findAnnotation(method.getPsiMethod(), JvmAbi.JETBRAINS_NOT_NULL_ANNOTATION.getFqName().getFqName()) != null) {
return TypeUtils.makeNullableAsSpecified(transformedType, false);
}
else {
@@ -1608,4 +1607,34 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
}
return r;
}
@NotNull
public static PsiAnnotation[] getAllAnnotations(@NotNull PsiModifierListOwner owner) {
List<PsiAnnotation> result = new ArrayList<PsiAnnotation>();
PsiModifierList list = owner.getModifierList();
if (list != null) {
result.addAll(Arrays.asList(list.getAnnotations()));
}
PsiAnnotation[] externalAnnotations = ExternalAnnotationsProvider.getInstance().findExternalAnnotations(owner.getProject(), owner);
if (externalAnnotations != null) {
result.addAll(Arrays.asList(externalAnnotations));
}
return result.toArray(new PsiAnnotation[result.size()]);
}
@Nullable
public static PsiAnnotation findAnnotation(@NotNull PsiModifierListOwner owner, @NotNull String fqName) {
PsiModifierList list = owner.getModifierList();
if (list != null) {
PsiAnnotation found = list.findAnnotation(fqName);
if (found != null) {
return found;
}
}
return ExternalAnnotationsProvider.getInstance().findExternalAnnotation(owner.getProject(), owner, fqName);
}
}
@@ -104,8 +104,8 @@ public class PsiClassFinderForJvm implements PsiClassFinder {
return null;
}
PsiAnnotation assertInvisibleAnnotation = result.getModifierList().findAnnotation(
JvmStdlibNames.ASSERT_INVISIBLE_IN_RESOLVER.getFqName().getFqName());
PsiAnnotation assertInvisibleAnnotation = JavaDescriptorResolver
.findAnnotation(result, JvmStdlibNames.ASSERT_INVISIBLE_IN_RESOLVER.getFqName().getFqName());
if (assertInvisibleAnnotation != null) {
if (runtimeClassesHandleMode == RuntimeClassesHandleMode.IGNORE) {
return null;
@@ -20,6 +20,7 @@ import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiClass;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
import org.jetbrains.jet.utils.BitSetUtils;
@@ -54,6 +55,6 @@ public class JetClassAnnotation extends PsiAnnotationWithFlags {
@NotNull
public static JetClassAnnotation get(PsiClass psiClass) {
return new JetClassAnnotation(psiClass.getModifierList().findAnnotation(JvmStdlibNames.JET_CLASS.getFqName().getFqName()));
return new JetClassAnnotation(JavaDescriptorResolver.findAnnotation(psiClass, JvmStdlibNames.JET_CLASS.getFqName().getFqName()));
}
}
@@ -20,6 +20,7 @@ import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiMethod;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
import org.jetbrains.jet.utils.BitSetUtils;
@@ -56,6 +57,6 @@ public class JetConstructorAnnotation extends PsiAnnotationWithFlags {
}
public static JetConstructorAnnotation get(PsiMethod constructor) {
return new JetConstructorAnnotation(constructor.getModifierList().findAnnotation(JvmStdlibNames.JET_CONSTRUCTOR.getFqName().getFqName()));
return new JetConstructorAnnotation(JavaDescriptorResolver.findAnnotation(constructor, JvmStdlibNames.JET_CONSTRUCTOR.getFqName().getFqName()));
}
}
@@ -20,6 +20,7 @@ import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiMethod;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
import org.jetbrains.jet.utils.BitSetUtils;
@@ -88,6 +89,6 @@ public class JetMethodAnnotation extends PsiAnnotationWithFlags {
}
public static JetMethodAnnotation get(PsiMethod psiMethod) {
return new JetMethodAnnotation(psiMethod.getModifierList().findAnnotation(JvmStdlibNames.JET_METHOD.getFqName().getFqName()));
return new JetMethodAnnotation(JavaDescriptorResolver.findAnnotation(psiMethod, JvmStdlibNames.JET_METHOD.getFqName().getFqName()));
}
}
@@ -20,6 +20,7 @@ import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiParameter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
/**
@@ -33,6 +34,7 @@ public class JetTypeParameterAnnotation extends PsiAnnotationWrapper {
@NotNull
public static JetTypeParameterAnnotation get(@NotNull PsiParameter psiParameter) {
return new JetTypeParameterAnnotation(psiParameter.getModifierList().findAnnotation(JvmStdlibNames.JET_TYPE_PARAMETER.getFqName().getFqName()));
return new JetTypeParameterAnnotation(
JavaDescriptorResolver.findAnnotation(psiParameter, JvmStdlibNames.JET_TYPE_PARAMETER.getFqName().getFqName()));
}
}
@@ -20,6 +20,7 @@ import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiParameter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
/**
@@ -80,7 +81,8 @@ public class JetValueParameterAnnotation extends PsiAnnotationWrapper {
}
public static JetValueParameterAnnotation get(PsiParameter psiParameter) {
return new JetValueParameterAnnotation(psiParameter.getModifierList().findAnnotation(JvmStdlibNames.JET_VALUE_PARAMETER.getFqName().getFqName()));
return new JetValueParameterAnnotation(
JavaDescriptorResolver.findAnnotation(psiParameter, JvmStdlibNames.JET_VALUE_PARAMETER.getFqName().getFqName()));
}
}
@@ -20,6 +20,7 @@ import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiMethod;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
/**
@@ -42,6 +43,6 @@ public class KotlinSignatureAnnotation extends PsiAnnotationWrapper {
@NotNull
public static KotlinSignatureAnnotation get(PsiMethod psiClass) {
return new KotlinSignatureAnnotation(psiClass.getModifierList().findAnnotation(JvmStdlibNames.KOTLIN_SIGNATURE.getFqName().getFqName()));
return new KotlinSignatureAnnotation(JavaDescriptorResolver.findAnnotation(psiClass, JvmStdlibNames.KOTLIN_SIGNATURE.getFqName().getFqName()));
}
}