Ask for external annotation only while looking for nullability or kotlin signature annotation

This commit is contained in:
Nikolay Krasko
2012-11-28 18:13:46 +04:00
parent c9bdfd2f07
commit 2dafbdc45a
12 changed files with 28 additions and 15 deletions
@@ -82,7 +82,7 @@ public class PsiClassFinderImpl implements PsiClassFinder {
if ("jet".equals(qualifiedName.parent().getFqName())) { if ("jet".equals(qualifiedName.parent().getFqName())) {
PsiAnnotation assertInvisibleAnnotation = PsiAnnotation assertInvisibleAnnotation =
JavaAnnotationResolver.findAnnotation(original, JvmStdlibNames.ASSERT_INVISIBLE_IN_RESOLVER.getFqName().getFqName()); JavaAnnotationResolver.findOwnAnnotation(original, JvmStdlibNames.ASSERT_INVISIBLE_IN_RESOLVER.getFqName().getFqName());
if (assertInvisibleAnnotation != null) { if (assertInvisibleAnnotation != null) {
if (runtimeClassesHandleMode == RuntimeClassesHandleMode.IGNORE) { if (runtimeClassesHandleMode == RuntimeClassesHandleMode.IGNORE) {
return null; return null;
@@ -56,7 +56,8 @@ public class JetClassAnnotation extends PsiAnnotationWithFlags {
@NotNull @NotNull
public static JetClassAnnotation get(PsiClass psiClass) { public static JetClassAnnotation get(PsiClass psiClass) {
final PsiAnnotation annotation = JavaAnnotationResolver.findAnnotation(psiClass, JvmStdlibNames.JET_CLASS.getFqName().getFqName()); final PsiAnnotation annotation = JavaAnnotationResolver.findOwnAnnotation(psiClass,
JvmStdlibNames.JET_CLASS.getFqName().getFqName());
return annotation != null ? new JetClassAnnotation(annotation) : NULL_ANNOTATION; return annotation != null ? new JetClassAnnotation(annotation) : NULL_ANNOTATION;
} }
} }
@@ -51,7 +51,7 @@ public class JetConstructorAnnotation extends PsiAnnotationWithFlags {
public static JetConstructorAnnotation get(PsiMethod constructor) { public static JetConstructorAnnotation get(PsiMethod constructor) {
final PsiAnnotation annotation = final PsiAnnotation annotation =
JavaAnnotationResolver.findAnnotation(constructor, JvmStdlibNames.JET_CONSTRUCTOR.getFqName().getFqName()); JavaAnnotationResolver.findOwnAnnotation(constructor, JvmStdlibNames.JET_CONSTRUCTOR.getFqName().getFqName());
return annotation != null ? new JetConstructorAnnotation(annotation) : NULL_ANNOTATION; return annotation != null ? new JetConstructorAnnotation(annotation) : NULL_ANNOTATION;
} }
} }
@@ -73,7 +73,7 @@ public class JetMethodAnnotation extends PsiAnnotationWithFlags {
public static JetMethodAnnotation get(PsiMethod psiMethod) { public static JetMethodAnnotation get(PsiMethod psiMethod) {
final PsiAnnotation annotation = final PsiAnnotation annotation =
JavaAnnotationResolver.findAnnotation(psiMethod, JvmStdlibNames.JET_METHOD.getFqName().getFqName()); JavaAnnotationResolver.findOwnAnnotation(psiMethod, JvmStdlibNames.JET_METHOD.getFqName().getFqName());
return annotation != null ? new JetMethodAnnotation(annotation) : NULL_ANNOTATION; return annotation != null ? new JetMethodAnnotation(annotation) : NULL_ANNOTATION;
} }
} }
@@ -43,7 +43,7 @@ public class JetTypeParameterAnnotation extends PsiAnnotationWrapper {
@NotNull @NotNull
public static JetTypeParameterAnnotation get(@NotNull PsiParameter psiParameter) { public static JetTypeParameterAnnotation get(@NotNull PsiParameter psiParameter) {
final PsiAnnotation annotation = final PsiAnnotation annotation =
JavaAnnotationResolver.findAnnotation(psiParameter, JvmStdlibNames.JET_TYPE_PARAMETER.getFqName().getFqName()); JavaAnnotationResolver.findOwnAnnotation(psiParameter, JvmStdlibNames.JET_TYPE_PARAMETER.getFqName().getFqName());
return annotation != null ? new JetTypeParameterAnnotation(annotation) : NULL_ANNOTATION; return annotation != null ? new JetTypeParameterAnnotation(annotation) : NULL_ANNOTATION;
} }
} }
@@ -74,7 +74,7 @@ public class JetValueParameterAnnotation extends PsiAnnotationWrapper {
public static JetValueParameterAnnotation get(PsiParameter psiParameter) { public static JetValueParameterAnnotation get(PsiParameter psiParameter) {
final PsiAnnotation annotation = final PsiAnnotation annotation =
JavaAnnotationResolver.findAnnotation(psiParameter, JvmStdlibNames.JET_VALUE_PARAMETER.getFqName().getFqName()); JavaAnnotationResolver.findOwnAnnotation(psiParameter, JvmStdlibNames.JET_VALUE_PARAMETER.getFqName().getFqName());
return annotation != null ? new JetValueParameterAnnotation(annotation) : NULL_ANNOTATION; return annotation != null ? new JetValueParameterAnnotation(annotation) : NULL_ANNOTATION;
} }
} }
@@ -54,7 +54,7 @@ public class KotlinSignatureAnnotation extends PsiAnnotationWrapper {
@NotNull @NotNull
public static KotlinSignatureAnnotation get(PsiModifierListOwner psiModifierListOwner) { public static KotlinSignatureAnnotation get(PsiModifierListOwner psiModifierListOwner) {
final PsiAnnotation annotation = final PsiAnnotation annotation =
JavaAnnotationResolver.findAnnotation(psiModifierListOwner, JvmStdlibNames.KOTLIN_SIGNATURE.getFqName().getFqName()); JavaAnnotationResolver.findAnnotationWithExternal(psiModifierListOwner, JvmStdlibNames.KOTLIN_SIGNATURE.getFqName().getFqName());
return annotation != null ? new KotlinSignatureAnnotation(annotation) : NULL_ANNOTATION; return annotation != null ? new KotlinSignatureAnnotation(annotation) : NULL_ANNOTATION;
} }
} }
@@ -24,8 +24,11 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.constants.*; import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.resolve.java.*; import org.jetbrains.jet.lang.resolve.java.DescriptorResolverUtils;
import org.jetbrains.jet.lang.resolve.java.DescriptorSearchRule;
import org.jetbrains.jet.lang.resolve.java.JavaToKotlinClassMap;
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.name.Name;
@@ -146,7 +149,7 @@ public final class JavaAnnotationResolver {
} }
@Nullable @Nullable
public static PsiAnnotation findAnnotation(@NotNull PsiModifierListOwner owner, @NotNull String fqName) { public static PsiAnnotation findOwnAnnotation(@NotNull PsiModifierListOwner owner, @NotNull String fqName) {
PsiModifierList list = owner.getModifierList(); PsiModifierList list = owner.getModifierList();
if (list != null) { if (list != null) {
PsiAnnotation found = list.findAnnotation(fqName); PsiAnnotation found = list.findAnnotation(fqName);
@@ -155,6 +158,16 @@ public final class JavaAnnotationResolver {
} }
} }
return null;
}
@Nullable
public static PsiAnnotation findAnnotationWithExternal(@NotNull PsiModifierListOwner owner, @NotNull String fqName) {
PsiAnnotation annotation = findOwnAnnotation(owner, fqName);
if (annotation != null) {
return annotation;
}
return ExternalAnnotationsManager.getInstance(owner.getProject()).findExternalAnnotation(owner, fqName); return ExternalAnnotationsManager.getInstance(owner.getProject()).findExternalAnnotation(owner, fqName);
} }
} }
@@ -309,7 +309,7 @@ public final class JavaFunctionResolver {
returnType, JavaTypeTransformer.TypeUsage.MEMBER_SIGNATURE_COVARIANT, typeVariableResolver); returnType, JavaTypeTransformer.TypeUsage.MEMBER_SIGNATURE_COVARIANT, typeVariableResolver);
} }
if (JavaAnnotationResolver.findAnnotation(method.getPsiMethod(), JvmAbi.JETBRAINS_NOT_NULL_ANNOTATION.getFqName().getFqName()) != if (JavaAnnotationResolver.findAnnotationWithExternal(method.getPsiMethod(), JvmAbi.JETBRAINS_NOT_NULL_ANNOTATION.getFqName().getFqName()) !=
null) { null) {
return TypeUtils.makeNullableAsSpecified(transformedType, false); return TypeUtils.makeNullableAsSpecified(transformedType, false);
} }
@@ -379,7 +379,7 @@ public final class JavaPropertyResolver {
JetType propertyType = semanticServices.getTypeTransformer().transformToType( JetType propertyType = semanticServices.getTypeTransformer().transformToType(
characteristicMember.getType().getPsiType(), typeVariableResolverForPropertyInternals); characteristicMember.getType().getPsiType(), typeVariableResolverForPropertyInternals);
boolean hasNotNullAnnotation = JavaAnnotationResolver.findAnnotation( boolean hasNotNullAnnotation = JavaAnnotationResolver.findAnnotationWithExternal(
characteristicMember.getType().getPsiNotNullOwner(), characteristicMember.getType().getPsiNotNullOwner(),
JvmAbi.JETBRAINS_NOT_NULL_ANNOTATION.getFqName().getFqName()) != null; JvmAbi.JETBRAINS_NOT_NULL_ANNOTATION.getFqName().getFqName()) != null;
@@ -93,8 +93,7 @@ public final class JavaValueParameterResolver {
else { else {
JetType transformedType; JetType transformedType;
if (JavaAnnotationResolver if (JavaAnnotationResolver.findAnnotationWithExternal(parameter.getPsiParameter(), JvmAbi.JETBRAINS_NOT_NULL_ANNOTATION.getFqName().getFqName()) !=
.findAnnotation(parameter.getPsiParameter(), JvmAbi.JETBRAINS_NOT_NULL_ANNOTATION.getFqName().getFqName()) !=
null) { null) {
transformedType = TypeUtils.makeNullableAsSpecified(outType, false); transformedType = TypeUtils.makeNullableAsSpecified(outType, false);
} }
@@ -84,7 +84,7 @@ class KotlinSignatureUtil {
static PsiAnnotation findKotlinSignatureAnnotation(@NotNull PsiElement element) { static PsiAnnotation findKotlinSignatureAnnotation(@NotNull PsiElement element) {
if (!(element instanceof PsiModifierListOwner)) return null; if (!(element instanceof PsiModifierListOwner)) return null;
PsiModifierListOwner annotationOwner = getAnnotationOwner(element); PsiModifierListOwner annotationOwner = getAnnotationOwner(element);
PsiAnnotation annotation = JavaAnnotationResolver.findAnnotation(annotationOwner, KOTLIN_SIGNATURE_ANNOTATION); PsiAnnotation annotation = JavaAnnotationResolver.findAnnotationWithExternal(annotationOwner, KOTLIN_SIGNATURE_ANNOTATION);
if (annotation == null) return null; if (annotation == null) return null;
if (annotation.getParameterList().getAttributes().length == 0) return null; if (annotation.getParameterList().getAttributes().length == 0) return null;
return annotation; return annotation;