Extract interface out of JavaAnnotation

This commit is contained in:
Alexander Udalov
2013-08-19 16:44:45 +04:00
parent 912d3426a4
commit dc048f0edd
7 changed files with 71 additions and 27 deletions
@@ -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
@@ -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<JavaAnnotationArgument> getArguments() {
return namedAnnotationArguments(getPsi().getParameterList().getAttributes());
}
Collection<JavaAnnotationArgument> getArguments();
@Nullable
public FqName getFqName() {
String qualifiedName = getPsi().getQualifiedName();
return qualifiedName == null ? null : new FqName(qualifiedName);
}
FqName getFqName();
}
@@ -34,6 +34,6 @@ public class JavaAnnotationAsAnnotationArgument extends JavaAnnotationArgument {
@NotNull
public JavaAnnotation getAnnotation() {
return new JavaAnnotation(getPsi());
return new JavaAnnotationImpl(getPsi());
}
}
@@ -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<JavaAnnotationArgument> getArguments() {
return namedAnnotationArguments(getPsi().getParameterList().getAttributes());
}
@Override
@Nullable
public FqName getFqName() {
String qualifiedName = getPsi().getQualifiedName();
return qualifiedName == null ? null : new FqName(qualifiedName);
}
}
@@ -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;
@@ -114,7 +114,7 @@ public class JavaElementCollectionFromPsiArrayUtil {
if (annotations.length == 0) return Collections.emptyList();
List<JavaAnnotation> result = new ArrayList<JavaAnnotation>(annotations.length);
for (PsiAnnotation psiAnnotation : annotations) {
result.add(new JavaAnnotation(psiAnnotation));
result.add(new JavaAnnotationImpl(psiAnnotation));
}
return result;
}
@@ -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;
}