Extract interfaces out of Java*AnnotationArgument
This commit is contained in:
+4
-4
@@ -38,16 +38,16 @@ public abstract class JavaAnnotationArgumentImpl extends JavaElementImpl impleme
|
|||||||
@NotNull
|
@NotNull
|
||||||
/* package */ static JavaAnnotationArgument create(@NotNull PsiAnnotationMemberValue argument, @Nullable Name name) {
|
/* package */ static JavaAnnotationArgument create(@NotNull PsiAnnotationMemberValue argument, @Nullable Name name) {
|
||||||
if (argument instanceof PsiLiteralExpression) {
|
if (argument instanceof PsiLiteralExpression) {
|
||||||
return new JavaLiteralAnnotationArgument((PsiLiteralExpression) argument, name);
|
return new JavaLiteralAnnotationArgumentImpl((PsiLiteralExpression) argument, name);
|
||||||
}
|
}
|
||||||
else if (argument instanceof PsiReferenceExpression) {
|
else if (argument instanceof PsiReferenceExpression) {
|
||||||
return new JavaReferenceAnnotationArgument((PsiReferenceExpression) argument, name);
|
return new JavaReferenceAnnotationArgumentImpl((PsiReferenceExpression) argument, name);
|
||||||
}
|
}
|
||||||
else if (argument instanceof PsiArrayInitializerMemberValue) {
|
else if (argument instanceof PsiArrayInitializerMemberValue) {
|
||||||
return new JavaArrayAnnotationArgument((PsiArrayInitializerMemberValue) argument, name);
|
return new JavaArrayAnnotationArgumentImpl((PsiArrayInitializerMemberValue) argument, name);
|
||||||
}
|
}
|
||||||
else if (argument instanceof PsiAnnotation) {
|
else if (argument instanceof PsiAnnotation) {
|
||||||
return new JavaAnnotationAsAnnotationArgument((PsiAnnotation) argument, name);
|
return new JavaAnnotationAsAnnotationArgumentImpl((PsiAnnotation) argument, name);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new UnsupportedOperationException("Unsupported annotation argument type: " + argument);
|
throw new UnsupportedOperationException("Unsupported annotation argument type: " + argument);
|
||||||
|
|||||||
+3
-13
@@ -18,22 +18,12 @@ package org.jetbrains.jet.lang.resolve.java.structure;
|
|||||||
|
|
||||||
import com.intellij.psi.PsiAnnotation;
|
import com.intellij.psi.PsiAnnotation;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
|
||||||
|
|
||||||
public class JavaAnnotationAsAnnotationArgument extends JavaAnnotationArgumentImpl {
|
|
||||||
protected JavaAnnotationAsAnnotationArgument(@NotNull PsiAnnotation psiAnnotation, @Nullable Name name) {
|
|
||||||
super(psiAnnotation, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public interface JavaAnnotationAsAnnotationArgument extends JavaAnnotationArgument {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public PsiAnnotation getPsi() {
|
PsiAnnotation getPsi();
|
||||||
return (PsiAnnotation) super.getPsi();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JavaAnnotation getAnnotation() {
|
JavaAnnotation getAnnotation();
|
||||||
return new JavaAnnotationImpl(getPsi());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
|
|
||||||
|
public class JavaAnnotationAsAnnotationArgumentImpl extends JavaAnnotationArgumentImpl implements JavaAnnotationAsAnnotationArgument {
|
||||||
|
protected JavaAnnotationAsAnnotationArgumentImpl(@NotNull PsiAnnotation psiAnnotation, @Nullable Name name) {
|
||||||
|
super(psiAnnotation, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public PsiAnnotation getPsi() {
|
||||||
|
return (PsiAnnotation) super.getPsi();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public JavaAnnotation getAnnotation() {
|
||||||
|
return new JavaAnnotationImpl(getPsi());
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-15
@@ -18,26 +18,14 @@ package org.jetbrains.jet.lang.resolve.java.structure;
|
|||||||
|
|
||||||
import com.intellij.psi.PsiArrayInitializerMemberValue;
|
import com.intellij.psi.PsiArrayInitializerMemberValue;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.resolve.java.structure.JavaElementCollectionFromPsiArrayUtil.namelessAnnotationArguments;
|
public interface JavaArrayAnnotationArgument extends JavaAnnotationArgument {
|
||||||
|
|
||||||
public class JavaArrayAnnotationArgument extends JavaAnnotationArgumentImpl {
|
|
||||||
protected JavaArrayAnnotationArgument(@NotNull PsiArrayInitializerMemberValue psiArrayInitializerMemberValue, @Nullable Name name) {
|
|
||||||
super(psiArrayInitializerMemberValue, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public PsiArrayInitializerMemberValue getPsi() {
|
PsiArrayInitializerMemberValue getPsi();
|
||||||
return (PsiArrayInitializerMemberValue) super.getPsi();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Collection<JavaAnnotationArgument> getElements() {
|
Collection<JavaAnnotationArgument> getElements();
|
||||||
return namelessAnnotationArguments(getPsi().getInitializers());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* 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.PsiArrayInitializerMemberValue;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.lang.resolve.java.structure.JavaElementCollectionFromPsiArrayUtil.namelessAnnotationArguments;
|
||||||
|
|
||||||
|
public class JavaArrayAnnotationArgumentImpl extends JavaAnnotationArgumentImpl implements JavaArrayAnnotationArgument {
|
||||||
|
protected JavaArrayAnnotationArgumentImpl(@NotNull PsiArrayInitializerMemberValue psiArrayInitializerMemberValue, @Nullable Name name) {
|
||||||
|
super(psiArrayInitializerMemberValue, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public PsiArrayInitializerMemberValue getPsi() {
|
||||||
|
return (PsiArrayInitializerMemberValue) super.getPsi();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public Collection<JavaAnnotationArgument> getElements() {
|
||||||
|
return namelessAnnotationArguments(getPsi().getInitializers());
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-12
@@ -19,21 +19,12 @@ package org.jetbrains.jet.lang.resolve.java.structure;
|
|||||||
import com.intellij.psi.PsiLiteralExpression;
|
import com.intellij.psi.PsiLiteralExpression;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
|
||||||
|
|
||||||
public class JavaLiteralAnnotationArgument extends JavaAnnotationArgumentImpl {
|
|
||||||
protected JavaLiteralAnnotationArgument(@NotNull PsiLiteralExpression psiLiteralExpression, @Nullable Name name) {
|
|
||||||
super(psiLiteralExpression, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public interface JavaLiteralAnnotationArgument extends JavaAnnotationArgument {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public PsiLiteralExpression getPsi() {
|
PsiLiteralExpression getPsi();
|
||||||
return (PsiLiteralExpression) super.getPsi();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Object getValue() {
|
Object getValue();
|
||||||
return getPsi().getValue();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* 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.PsiLiteralExpression;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
|
|
||||||
|
public class JavaLiteralAnnotationArgumentImpl extends JavaAnnotationArgumentImpl implements JavaLiteralAnnotationArgument {
|
||||||
|
protected JavaLiteralAnnotationArgumentImpl(@NotNull PsiLiteralExpression psiLiteralExpression, @Nullable Name name) {
|
||||||
|
super(psiLiteralExpression, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public PsiLiteralExpression getPsi() {
|
||||||
|
return (PsiLiteralExpression) super.getPsi();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public Object getValue() {
|
||||||
|
return getPsi().getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-21
@@ -16,33 +16,15 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.java.structure;
|
package org.jetbrains.jet.lang.resolve.java.structure;
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement;
|
|
||||||
import com.intellij.psi.PsiEnumConstant;
|
|
||||||
import com.intellij.psi.PsiField;
|
|
||||||
import com.intellij.psi.PsiReferenceExpression;
|
import com.intellij.psi.PsiReferenceExpression;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
|
||||||
|
|
||||||
public class JavaReferenceAnnotationArgument extends JavaAnnotationArgumentImpl {
|
|
||||||
protected JavaReferenceAnnotationArgument(@NotNull PsiReferenceExpression psiReferenceExpression, @Nullable Name name) {
|
|
||||||
super(psiReferenceExpression, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public interface JavaReferenceAnnotationArgument extends JavaAnnotationArgument {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public PsiReferenceExpression getPsi() {
|
PsiReferenceExpression getPsi();
|
||||||
return (PsiReferenceExpression) super.getPsi();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public JavaElement resolve() {
|
JavaElement resolve();
|
||||||
PsiReferenceExpression expression = getPsi();
|
|
||||||
PsiElement element = expression.resolve();
|
|
||||||
if (element instanceof PsiEnumConstant) {
|
|
||||||
return new JavaFieldImpl((PsiField) element);
|
|
||||||
}
|
|
||||||
// TODO: other types of references
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+49
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* 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.PsiElement;
|
||||||
|
import com.intellij.psi.PsiEnumConstant;
|
||||||
|
import com.intellij.psi.PsiField;
|
||||||
|
import com.intellij.psi.PsiReferenceExpression;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
|
|
||||||
|
public class JavaReferenceAnnotationArgumentImpl extends JavaAnnotationArgumentImpl implements JavaReferenceAnnotationArgument {
|
||||||
|
protected JavaReferenceAnnotationArgumentImpl(@NotNull PsiReferenceExpression psiReferenceExpression, @Nullable Name name) {
|
||||||
|
super(psiReferenceExpression, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public PsiReferenceExpression getPsi() {
|
||||||
|
return (PsiReferenceExpression) super.getPsi();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public JavaElement resolve() {
|
||||||
|
PsiReferenceExpression expression = getPsi();
|
||||||
|
PsiElement element = expression.resolve();
|
||||||
|
if (element instanceof PsiEnumConstant) {
|
||||||
|
return new JavaFieldImpl((PsiField) element);
|
||||||
|
}
|
||||||
|
// TODO: other types of references
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user