Extract interfaces out of Java*AnnotationArgument

This commit is contained in:
Alexander Udalov
2013-08-19 17:05:20 +04:00
parent 90e0d51463
commit d364834168
9 changed files with 189 additions and 65 deletions
@@ -38,16 +38,16 @@ public abstract class JavaAnnotationArgumentImpl extends JavaElementImpl impleme
@NotNull
/* package */ static JavaAnnotationArgument create(@NotNull PsiAnnotationMemberValue argument, @Nullable Name name) {
if (argument instanceof PsiLiteralExpression) {
return new JavaLiteralAnnotationArgument((PsiLiteralExpression) argument, name);
return new JavaLiteralAnnotationArgumentImpl((PsiLiteralExpression) argument, name);
}
else if (argument instanceof PsiReferenceExpression) {
return new JavaReferenceAnnotationArgument((PsiReferenceExpression) argument, name);
return new JavaReferenceAnnotationArgumentImpl((PsiReferenceExpression) argument, name);
}
else if (argument instanceof PsiArrayInitializerMemberValue) {
return new JavaArrayAnnotationArgument((PsiArrayInitializerMemberValue) argument, name);
return new JavaArrayAnnotationArgumentImpl((PsiArrayInitializerMemberValue) argument, name);
}
else if (argument instanceof PsiAnnotation) {
return new JavaAnnotationAsAnnotationArgument((PsiAnnotation) argument, name);
return new JavaAnnotationAsAnnotationArgumentImpl((PsiAnnotation) argument, name);
}
else {
throw new UnsupportedOperationException("Unsupported annotation argument type: " + argument);
@@ -18,22 +18,12 @@ 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 JavaAnnotationAsAnnotationArgument extends JavaAnnotationArgumentImpl {
protected JavaAnnotationAsAnnotationArgument(@NotNull PsiAnnotation psiAnnotation, @Nullable Name name) {
super(psiAnnotation, name);
}
public interface JavaAnnotationAsAnnotationArgument extends JavaAnnotationArgument {
@NotNull
@Override
public PsiAnnotation getPsi() {
return (PsiAnnotation) super.getPsi();
}
PsiAnnotation getPsi();
@NotNull
public JavaAnnotation getAnnotation() {
return new JavaAnnotationImpl(getPsi());
}
JavaAnnotation getAnnotation();
}
@@ -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());
}
}
@@ -18,26 +18,14 @@ 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 JavaArrayAnnotationArgument extends JavaAnnotationArgumentImpl {
protected JavaArrayAnnotationArgument(@NotNull PsiArrayInitializerMemberValue psiArrayInitializerMemberValue, @Nullable Name name) {
super(psiArrayInitializerMemberValue, name);
}
public interface JavaArrayAnnotationArgument extends JavaAnnotationArgument {
@NotNull
@Override
public PsiArrayInitializerMemberValue getPsi() {
return (PsiArrayInitializerMemberValue) super.getPsi();
}
PsiArrayInitializerMemberValue getPsi();
@NotNull
public Collection<JavaAnnotationArgument> getElements() {
return namelessAnnotationArguments(getPsi().getInitializers());
}
Collection<JavaAnnotationArgument> getElements();
}
@@ -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());
}
}
@@ -19,21 +19,12 @@ 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 JavaLiteralAnnotationArgument extends JavaAnnotationArgumentImpl {
protected JavaLiteralAnnotationArgument(@NotNull PsiLiteralExpression psiLiteralExpression, @Nullable Name name) {
super(psiLiteralExpression, name);
}
public interface JavaLiteralAnnotationArgument extends JavaAnnotationArgument {
@NotNull
@Override
public PsiLiteralExpression getPsi() {
return (PsiLiteralExpression) super.getPsi();
}
PsiLiteralExpression getPsi();
@Nullable
public Object getValue() {
return getPsi().getValue();
}
Object getValue();
}
@@ -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();
}
}
@@ -16,33 +16,15 @@
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 JavaReferenceAnnotationArgument extends JavaAnnotationArgumentImpl {
protected JavaReferenceAnnotationArgument(@NotNull PsiReferenceExpression psiReferenceExpression, @Nullable Name name) {
super(psiReferenceExpression, name);
}
public interface JavaReferenceAnnotationArgument extends JavaAnnotationArgument {
@NotNull
@Override
public PsiReferenceExpression getPsi() {
return (PsiReferenceExpression) super.getPsi();
}
PsiReferenceExpression getPsi();
@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;
}
JavaElement resolve();
}
@@ -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;
}
}