From b70cc84764f1c7db3bb95bd8957222659c2ea702 Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Sun, 23 Sep 2012 13:04:48 +0200 Subject: [PATCH] introduce constants for cases when annotations not present --- .../jet/lang/resolve/java/kt/JetClassAnnotation.java | 4 +++- .../lang/resolve/java/kt/JetConstructorAnnotation.java | 6 +++++- .../jet/lang/resolve/java/kt/JetMethodAnnotation.java | 5 ++++- .../lang/resolve/java/kt/JetTypeParameterAnnotation.java | 9 ++++++--- .../resolve/java/kt/JetValueParameterAnnotation.java | 9 ++++++--- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetClassAnnotation.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetClassAnnotation.java index faa982387eb..5f0c988d954 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetClassAnnotation.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetClassAnnotation.java @@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; */ public class JetClassAnnotation extends PsiAnnotationWithFlags { + public static final JetClassAnnotation NULL_ANNOTATION = new JetClassAnnotation(null); private String signature; public JetClassAnnotation(@Nullable PsiAnnotation psiAnnotation) { @@ -47,6 +48,7 @@ public class JetClassAnnotation extends PsiAnnotationWithFlags { @NotNull public static JetClassAnnotation get(PsiClass psiClass) { - return new JetClassAnnotation(JavaDescriptorResolver.findAnnotation(psiClass, JvmStdlibNames.JET_CLASS.getFqName().getFqName())); + final PsiAnnotation annotation = JavaDescriptorResolver.findAnnotation(psiClass, JvmStdlibNames.JET_CLASS.getFqName().getFqName()); + return annotation != null ? new JetClassAnnotation(annotation) : NULL_ANNOTATION; } } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetConstructorAnnotation.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetConstructorAnnotation.java index 6d767c0c035..e356e8d2c6f 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetConstructorAnnotation.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetConstructorAnnotation.java @@ -27,6 +27,8 @@ import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; */ public class JetConstructorAnnotation extends PsiAnnotationWithFlags { + public static final JetConstructorAnnotation NULL_ANNOTATION = new JetConstructorAnnotation(null); + public JetConstructorAnnotation(@Nullable PsiAnnotation psiAnnotation) { super(psiAnnotation); } @@ -46,6 +48,8 @@ public class JetConstructorAnnotation extends PsiAnnotationWithFlags { } public static JetConstructorAnnotation get(PsiMethod constructor) { - return new JetConstructorAnnotation(JavaDescriptorResolver.findAnnotation(constructor, JvmStdlibNames.JET_CONSTRUCTOR.getFqName().getFqName())); + final PsiAnnotation annotation = + JavaDescriptorResolver.findAnnotation(constructor, JvmStdlibNames.JET_CONSTRUCTOR.getFqName().getFqName()); + return annotation != null ? new JetConstructorAnnotation(annotation) : NULL_ANNOTATION; } } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetMethodAnnotation.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetMethodAnnotation.java index 7873af880c1..6a2b8176ddd 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetMethodAnnotation.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetMethodAnnotation.java @@ -29,6 +29,7 @@ import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; */ public class JetMethodAnnotation extends PsiAnnotationWithFlags { + public static final JetMethodAnnotation NULL_ANNOTATION = new JetMethodAnnotation(null); private String typeParameters; private String returnType; private String propertyType; @@ -68,6 +69,8 @@ public class JetMethodAnnotation extends PsiAnnotationWithFlags { } public static JetMethodAnnotation get(PsiMethod psiMethod) { - return new JetMethodAnnotation(JavaDescriptorResolver.findAnnotation(psiMethod, JvmStdlibNames.JET_METHOD.getFqName().getFqName())); + final PsiAnnotation annotation = + JavaDescriptorResolver.findAnnotation(psiMethod, JvmStdlibNames.JET_METHOD.getFqName().getFqName()); + return annotation != null ? new JetMethodAnnotation(annotation) : NULL_ANNOTATION; } } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetTypeParameterAnnotation.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetTypeParameterAnnotation.java index df4239079e5..69931123bc3 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetTypeParameterAnnotation.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetTypeParameterAnnotation.java @@ -27,7 +27,9 @@ import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; * @author Stepan Koltsov */ public class JetTypeParameterAnnotation extends PsiAnnotationWrapper { - + + public static final JetTypeParameterAnnotation NULL_ANNOTATION = new JetTypeParameterAnnotation(null); + protected JetTypeParameterAnnotation(@Nullable PsiAnnotation psiAnnotation) { super(psiAnnotation); } @@ -38,7 +40,8 @@ public class JetTypeParameterAnnotation extends PsiAnnotationWrapper { @NotNull public static JetTypeParameterAnnotation get(@NotNull PsiParameter psiParameter) { - return new JetTypeParameterAnnotation( - JavaDescriptorResolver.findAnnotation(psiParameter, JvmStdlibNames.JET_TYPE_PARAMETER.getFqName().getFqName())); + final PsiAnnotation annotation = + JavaDescriptorResolver.findAnnotation(psiParameter, JvmStdlibNames.JET_TYPE_PARAMETER.getFqName().getFqName()); + return annotation != null ? new JetTypeParameterAnnotation(annotation) : NULL_ANNOTATION; } } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetValueParameterAnnotation.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetValueParameterAnnotation.java index 7d9b8d424b7..1294df38ad6 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetValueParameterAnnotation.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetValueParameterAnnotation.java @@ -28,7 +28,9 @@ import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; * @author alex.tkachman */ public class JetValueParameterAnnotation extends PsiAnnotationWrapper { - + + public static final JetValueParameterAnnotation NULL_ANNOTATION = new JetValueParameterAnnotation(null); + public JetValueParameterAnnotation(@Nullable PsiAnnotation psiAnnotation) { super(psiAnnotation); } @@ -76,7 +78,8 @@ public class JetValueParameterAnnotation extends PsiAnnotationWrapper { } public static JetValueParameterAnnotation get(PsiParameter psiParameter) { - return new JetValueParameterAnnotation( - JavaDescriptorResolver.findAnnotation(psiParameter, JvmStdlibNames.JET_VALUE_PARAMETER.getFqName().getFqName())); + final PsiAnnotation annotation = + JavaDescriptorResolver.findAnnotation(psiParameter, JvmStdlibNames.JET_VALUE_PARAMETER.getFqName().getFqName()); + return annotation != null ? new JetValueParameterAnnotation(annotation) : NULL_ANNOTATION; } }