Extract interface out of JavaField

This commit is contained in:
Alexander Udalov
2013-08-19 14:34:52 +04:00
parent ed146e51f9
commit 37beb9e50f
4 changed files with 50 additions and 17 deletions
@@ -64,7 +64,7 @@ public class JavaElementCollectionFromPsiArrayUtil {
if (fields.length == 0) return Collections.emptyList(); if (fields.length == 0) return Collections.emptyList();
List<JavaField> result = new ArrayList<JavaField>(fields.length); List<JavaField> result = new ArrayList<JavaField>(fields.length);
for (PsiField psiField : fields) { for (PsiField psiField : fields) {
result.add(new JavaField(psiField)); result.add(new JavaFieldImpl(psiField));
} }
return result; return result;
} }
@@ -16,27 +16,16 @@
package org.jetbrains.jet.lang.resolve.java.structure; package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiEnumConstant;
import com.intellij.psi.PsiField; import com.intellij.psi.PsiField;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class JavaField extends JavaMemberImpl { public interface JavaField extends JavaMember {
public JavaField(@NotNull PsiField psiField) {
super(psiField);
}
@NotNull @NotNull
@Override @Override
public PsiField getPsi() { PsiField getPsi();
return (PsiField) super.getPsi();
}
public boolean isEnumEntry() { boolean isEnumEntry();
return getPsi() instanceof PsiEnumConstant;
}
@NotNull @NotNull
public JavaType getType() { JavaType getType();
return JavaType.create(getPsi().getType());
}
} }
@@ -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.PsiEnumConstant;
import com.intellij.psi.PsiField;
import org.jetbrains.annotations.NotNull;
public class JavaFieldImpl extends JavaMemberImpl implements JavaField {
public JavaFieldImpl(@NotNull PsiField psiField) {
super(psiField);
}
@NotNull
@Override
public PsiField getPsi() {
return (PsiField) super.getPsi();
}
@Override
public boolean isEnumEntry() {
return getPsi() instanceof PsiEnumConstant;
}
@Override
@NotNull
public JavaType getType() {
return JavaType.create(getPsi().getType());
}
}
@@ -40,7 +40,7 @@ public class JavaReferenceAnnotationArgument extends JavaAnnotationArgument {
PsiReferenceExpression expression = getPsi(); PsiReferenceExpression expression = getPsi();
PsiElement element = expression.resolve(); PsiElement element = expression.resolve();
if (element instanceof PsiEnumConstant) { if (element instanceof PsiEnumConstant) {
return new JavaField((PsiField) element); return new JavaFieldImpl((PsiField) element);
} }
// TODO: other types of references // TODO: other types of references
return null; return null;