From dc048f0eddc42b3b56e0d048f1db7a98d9367a30 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 19 Aug 2013 16:44:45 +0400 Subject: [PATCH] Extract interface out of JavaAnnotation --- .../PsiBasedExternalAnnotationResolver.java | 3 +- .../java/structure/JavaAnnotation.java | 27 ++------- .../JavaAnnotationAsAnnotationArgument.java | 2 +- .../java/structure/JavaAnnotationImpl.java | 60 +++++++++++++++++++ .../resolve/java/structure/JavaClass.java | 2 +- ...JavaElementCollectionFromPsiArrayUtil.java | 2 +- .../java/structure/JavaElementUtil.java | 2 +- 7 files changed, 71 insertions(+), 27 deletions(-) create mode 100644 compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaAnnotationImpl.java diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/PsiBasedExternalAnnotationResolver.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/PsiBasedExternalAnnotationResolver.java index af362c876d4..983831fb85b 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/PsiBasedExternalAnnotationResolver.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/PsiBasedExternalAnnotationResolver.java @@ -24,6 +24,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.resolve.java.JvmClassName; import org.jetbrains.jet.lang.resolve.java.structure.JavaAnnotation; +import org.jetbrains.jet.lang.resolve.java.structure.JavaAnnotationImpl; import org.jetbrains.jet.lang.resolve.java.structure.JavaAnnotationOwner; import org.jetbrains.jet.lang.resolve.java.structure.JavaElementCollectionFromPsiArrayUtil; import org.jetbrains.jet.lang.resolve.name.FqName; @@ -36,7 +37,7 @@ public class PsiBasedExternalAnnotationResolver implements ExternalAnnotationRes @Override public JavaAnnotation findExternalAnnotation(@NotNull JavaAnnotationOwner owner, @NotNull FqName fqName) { PsiAnnotation psiAnnotation = findExternalAnnotation(owner.getPsi(), fqName); - return psiAnnotation == null ? null : new JavaAnnotation(psiAnnotation); + return psiAnnotation == null ? null : new JavaAnnotationImpl(psiAnnotation); } @NotNull diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaAnnotation.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaAnnotation.java index 2ea38c3d09a..f9d8693d8e8 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaAnnotation.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaAnnotation.java @@ -17,7 +17,6 @@ package org.jetbrains.jet.lang.resolve.java.structure; import com.intellij.psi.PsiAnnotation; -import com.intellij.psi.PsiAnnotationMemberValue; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.resolve.name.FqName; @@ -25,33 +24,17 @@ import org.jetbrains.jet.lang.resolve.name.Name; import java.util.Collection; -import static org.jetbrains.jet.lang.resolve.java.structure.JavaElementCollectionFromPsiArrayUtil.namedAnnotationArguments; - -public class JavaAnnotation extends JavaElementImpl { - public JavaAnnotation(@NotNull PsiAnnotation psiAnnotation) { - super(psiAnnotation); - } - +public interface JavaAnnotation extends JavaElement { @NotNull @Override - public PsiAnnotation getPsi() { - return (PsiAnnotation) super.getPsi(); - } + PsiAnnotation getPsi(); @Nullable - public JavaAnnotationArgument findArgument(@NotNull Name name) { - PsiAnnotationMemberValue attribute = getPsi().findAttributeValue(name.asString()); - return attribute == null ? null : JavaAnnotationArgument.create(attribute, name); - } + JavaAnnotationArgument findArgument(@NotNull Name name); @NotNull - public Collection getArguments() { - return namedAnnotationArguments(getPsi().getParameterList().getAttributes()); - } + Collection getArguments(); @Nullable - public FqName getFqName() { - String qualifiedName = getPsi().getQualifiedName(); - return qualifiedName == null ? null : new FqName(qualifiedName); - } + FqName getFqName(); } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaAnnotationAsAnnotationArgument.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaAnnotationAsAnnotationArgument.java index eb2ab467fa8..afa367ebeaf 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaAnnotationAsAnnotationArgument.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaAnnotationAsAnnotationArgument.java @@ -34,6 +34,6 @@ public class JavaAnnotationAsAnnotationArgument extends JavaAnnotationArgument { @NotNull public JavaAnnotation getAnnotation() { - return new JavaAnnotation(getPsi()); + return new JavaAnnotationImpl(getPsi()); } } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaAnnotationImpl.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaAnnotationImpl.java new file mode 100644 index 00000000000..0d341525943 --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaAnnotationImpl.java @@ -0,0 +1,60 @@ +/* + * Copyright 2010-2013 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.structure; + +import com.intellij.psi.PsiAnnotation; +import com.intellij.psi.PsiAnnotationMemberValue; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.lang.resolve.name.FqName; +import org.jetbrains.jet.lang.resolve.name.Name; + +import java.util.Collection; + +import static org.jetbrains.jet.lang.resolve.java.structure.JavaElementCollectionFromPsiArrayUtil.namedAnnotationArguments; + +public class JavaAnnotationImpl extends JavaElementImpl implements JavaAnnotation { + public JavaAnnotationImpl(@NotNull PsiAnnotation psiAnnotation) { + super(psiAnnotation); + } + + @NotNull + @Override + public PsiAnnotation getPsi() { + return (PsiAnnotation) super.getPsi(); + } + + @Override + @Nullable + public JavaAnnotationArgument findArgument(@NotNull Name name) { + PsiAnnotationMemberValue attribute = getPsi().findAttributeValue(name.asString()); + return attribute == null ? null : JavaAnnotationArgument.create(attribute, name); + } + + @Override + @NotNull + public Collection getArguments() { + return namedAnnotationArguments(getPsi().getParameterList().getAttributes()); + } + + @Override + @Nullable + public FqName getFqName() { + String qualifiedName = getPsi().getQualifiedName(); + return qualifiedName == null ? null : new FqName(qualifiedName); + } +} diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaClass.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaClass.java index d57bc1585f0..b56aac53879 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaClass.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaClass.java @@ -62,7 +62,7 @@ public class JavaClass extends JavaClassifierImpl if (modifierList != null) { PsiAnnotation annotation = modifierList.findAnnotation(fqName); if (annotation != null) { - return new JavaAnnotation(annotation); + return new JavaAnnotationImpl(annotation); } } return null; diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaElementCollectionFromPsiArrayUtil.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaElementCollectionFromPsiArrayUtil.java index 807403f2c2e..2812c05f1ca 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaElementCollectionFromPsiArrayUtil.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaElementCollectionFromPsiArrayUtil.java @@ -114,7 +114,7 @@ public class JavaElementCollectionFromPsiArrayUtil { if (annotations.length == 0) return Collections.emptyList(); List result = new ArrayList(annotations.length); for (PsiAnnotation psiAnnotation : annotations) { - result.add(new JavaAnnotation(psiAnnotation)); + result.add(new JavaAnnotationImpl(psiAnnotation)); } return result; } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaElementUtil.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaElementUtil.java index a5e0ee7b3bb..27986f2cb7f 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaElementUtil.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaElementUtil.java @@ -75,7 +75,7 @@ import static org.jetbrains.jet.lang.resolve.java.structure.JavaElementCollectio PsiModifierList modifierList = owner.getPsi().getModifierList(); if (modifierList != null) { PsiAnnotation psiAnnotation = modifierList.findAnnotation(fqName.asString()); - return psiAnnotation == null ? null : new JavaAnnotation(psiAnnotation); + return psiAnnotation == null ? null : new JavaAnnotationImpl(psiAnnotation); } return null; }