Extract interface out of JavaAnnotationArgument
This commit is contained in:
+4
-34
@@ -16,46 +16,16 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.java.structure;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.PsiAnnotationMemberValue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
public abstract class JavaAnnotationArgument extends JavaElementImpl {
|
||||
private final Name name;
|
||||
|
||||
protected JavaAnnotationArgument(@NotNull PsiAnnotationMemberValue psiAnnotationMemberValue, @Nullable Name name) {
|
||||
super(psiAnnotationMemberValue);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public interface JavaAnnotationArgument extends JavaElement {
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiAnnotationMemberValue getPsi() {
|
||||
return (PsiAnnotationMemberValue) super.getPsi();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JavaAnnotationArgument create(@NotNull PsiAnnotationMemberValue argument, @Nullable Name name) {
|
||||
if (argument instanceof PsiLiteralExpression) {
|
||||
return new JavaLiteralAnnotationArgument((PsiLiteralExpression) argument, name);
|
||||
}
|
||||
else if (argument instanceof PsiReferenceExpression) {
|
||||
return new JavaReferenceAnnotationArgument((PsiReferenceExpression) argument, name);
|
||||
}
|
||||
else if (argument instanceof PsiArrayInitializerMemberValue) {
|
||||
return new JavaArrayAnnotationArgument((PsiArrayInitializerMemberValue) argument, name);
|
||||
}
|
||||
else if (argument instanceof PsiAnnotation) {
|
||||
return new JavaAnnotationAsAnnotationArgument((PsiAnnotation) argument, name);
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException("Unsupported annotation argument type: " + argument);
|
||||
}
|
||||
}
|
||||
PsiAnnotationMemberValue getPsi();
|
||||
|
||||
@Nullable
|
||||
public Name getName() {
|
||||
return name;
|
||||
}
|
||||
Name getName();
|
||||
}
|
||||
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
public abstract class JavaAnnotationArgumentImpl extends JavaElementImpl implements JavaAnnotationArgument {
|
||||
private final Name name;
|
||||
|
||||
protected JavaAnnotationArgumentImpl(@NotNull PsiAnnotationMemberValue psiAnnotationMemberValue, @Nullable Name name) {
|
||||
super(psiAnnotationMemberValue);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiAnnotationMemberValue getPsi() {
|
||||
return (PsiAnnotationMemberValue) super.getPsi();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
/* package */ static JavaAnnotationArgument create(@NotNull PsiAnnotationMemberValue argument, @Nullable Name name) {
|
||||
if (argument instanceof PsiLiteralExpression) {
|
||||
return new JavaLiteralAnnotationArgument((PsiLiteralExpression) argument, name);
|
||||
}
|
||||
else if (argument instanceof PsiReferenceExpression) {
|
||||
return new JavaReferenceAnnotationArgument((PsiReferenceExpression) argument, name);
|
||||
}
|
||||
else if (argument instanceof PsiArrayInitializerMemberValue) {
|
||||
return new JavaArrayAnnotationArgument((PsiArrayInitializerMemberValue) argument, name);
|
||||
}
|
||||
else if (argument instanceof PsiAnnotation) {
|
||||
return new JavaAnnotationAsAnnotationArgument((PsiAnnotation) argument, name);
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException("Unsupported annotation argument type: " + argument);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Name getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
public class JavaAnnotationAsAnnotationArgument extends JavaAnnotationArgument {
|
||||
public class JavaAnnotationAsAnnotationArgument extends JavaAnnotationArgumentImpl {
|
||||
protected JavaAnnotationAsAnnotationArgument(@NotNull PsiAnnotation psiAnnotation, @Nullable Name name) {
|
||||
super(psiAnnotation, name);
|
||||
}
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ public class JavaAnnotationImpl extends JavaElementImpl implements JavaAnnotatio
|
||||
@Nullable
|
||||
public JavaAnnotationArgument findArgument(@NotNull Name name) {
|
||||
PsiAnnotationMemberValue attribute = getPsi().findAttributeValue(name.asString());
|
||||
return attribute == null ? null : JavaAnnotationArgument.create(attribute, name);
|
||||
return attribute == null ? null : JavaAnnotationArgumentImpl.create(attribute, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ import java.util.Collection;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.java.structure.JavaElementCollectionFromPsiArrayUtil.namelessAnnotationArguments;
|
||||
|
||||
public class JavaArrayAnnotationArgument extends JavaAnnotationArgument {
|
||||
public class JavaArrayAnnotationArgument extends JavaAnnotationArgumentImpl {
|
||||
protected JavaArrayAnnotationArgument(@NotNull PsiArrayInitializerMemberValue psiArrayInitializerMemberValue, @Nullable Name name) {
|
||||
super(psiArrayInitializerMemberValue, name);
|
||||
}
|
||||
|
||||
+2
-2
@@ -124,7 +124,7 @@ public class JavaElementCollectionFromPsiArrayUtil {
|
||||
if (memberValues.length == 0) return Collections.emptyList();
|
||||
List<JavaAnnotationArgument> result = new ArrayList<JavaAnnotationArgument>(memberValues.length);
|
||||
for (PsiAnnotationMemberValue psiAnnotationMemberValue : memberValues) {
|
||||
result.add(JavaAnnotationArgument.create(psiAnnotationMemberValue, null));
|
||||
result.add(JavaAnnotationArgumentImpl.create(psiAnnotationMemberValue, null));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -137,7 +137,7 @@ public class JavaElementCollectionFromPsiArrayUtil {
|
||||
String name = pair.getName();
|
||||
PsiAnnotationMemberValue value = pair.getValue();
|
||||
assert value != null : "Annotation argument value cannot be null: " + name;
|
||||
result.add(JavaAnnotationArgument.create(value, name == null ? null : Name.identifier(name)));
|
||||
result.add(JavaAnnotationArgumentImpl.create(value, name == null ? null : Name.identifier(name)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
public class JavaLiteralAnnotationArgument extends JavaAnnotationArgument {
|
||||
public class JavaLiteralAnnotationArgument extends JavaAnnotationArgumentImpl {
|
||||
protected JavaLiteralAnnotationArgument(@NotNull PsiLiteralExpression psiLiteralExpression, @Nullable Name name) {
|
||||
super(psiLiteralExpression, name);
|
||||
}
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
public class JavaReferenceAnnotationArgument extends JavaAnnotationArgument {
|
||||
public class JavaReferenceAnnotationArgument extends JavaAnnotationArgumentImpl {
|
||||
protected JavaReferenceAnnotationArgument(@NotNull PsiReferenceExpression psiReferenceExpression, @Nullable Name name) {
|
||||
super(psiReferenceExpression, name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user