Make JavaElementImpl generic on underlying PSI type

This commit is contained in:
Alexander Udalov
2013-08-20 15:49:46 +04:00
parent 4cd238ddde
commit 5af28cd953
12 changed files with 19 additions and 78 deletions
@@ -22,7 +22,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.structure.JavaAnnotationArgument; import org.jetbrains.jet.lang.resolve.java.structure.JavaAnnotationArgument;
import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.name.Name;
public abstract class JavaAnnotationArgumentImpl extends JavaElementImpl implements JavaAnnotationArgument { public abstract class JavaAnnotationArgumentImpl extends JavaElementImpl<PsiAnnotationMemberValue> implements JavaAnnotationArgument {
private final Name name; private final Name name;
protected JavaAnnotationArgumentImpl(@NotNull PsiAnnotationMemberValue psiAnnotationMemberValue, @Nullable Name name) { protected JavaAnnotationArgumentImpl(@NotNull PsiAnnotationMemberValue psiAnnotationMemberValue, @Nullable Name name) {
@@ -30,12 +30,6 @@ public abstract class JavaAnnotationArgumentImpl extends JavaElementImpl impleme
this.name = name; this.name = name;
} }
@NotNull
@Override
public PsiAnnotationMemberValue getPsi() {
return (PsiAnnotationMemberValue) super.getPsi();
}
@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) {
@@ -29,17 +29,11 @@ import java.util.Collection;
import static org.jetbrains.jet.lang.resolve.java.structure.impl.JavaElementCollectionFromPsiArrayUtil.namedAnnotationArguments; import static org.jetbrains.jet.lang.resolve.java.structure.impl.JavaElementCollectionFromPsiArrayUtil.namedAnnotationArguments;
public class JavaAnnotationImpl extends JavaElementImpl implements JavaAnnotation { public class JavaAnnotationImpl extends JavaElementImpl<PsiAnnotation> implements JavaAnnotation {
public JavaAnnotationImpl(@NotNull PsiAnnotation psiAnnotation) { public JavaAnnotationImpl(@NotNull PsiAnnotation psiAnnotation) {
super(psiAnnotation); super(psiAnnotation);
} }
@NotNull
@Override
public PsiAnnotation getPsi() {
return (PsiAnnotation) super.getPsi();
}
@Override @Override
@Nullable @Nullable
public JavaAnnotationArgument findArgument(@NotNull Name name) { public JavaAnnotationArgument findArgument(@NotNull Name name) {
@@ -21,17 +21,11 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.java.structure.JavaArrayType; import org.jetbrains.jet.lang.resolve.java.structure.JavaArrayType;
import org.jetbrains.jet.lang.resolve.java.structure.JavaType; import org.jetbrains.jet.lang.resolve.java.structure.JavaType;
public class JavaArrayTypeImpl extends JavaTypeImpl implements JavaArrayType { public class JavaArrayTypeImpl extends JavaTypeImpl<PsiArrayType> implements JavaArrayType {
public JavaArrayTypeImpl(@NotNull PsiArrayType psiArrayType) { public JavaArrayTypeImpl(@NotNull PsiArrayType psiArrayType) {
super(psiArrayType); super(psiArrayType);
} }
@NotNull
@Override
public PsiArrayType getPsi() {
return (PsiArrayType) super.getPsi();
}
@Override @Override
@NotNull @NotNull
public JavaType getComponentType() { public JavaType getComponentType() {
@@ -21,17 +21,11 @@ import com.intellij.psi.PsiTypeParameter;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.java.structure.JavaClassifier; import org.jetbrains.jet.lang.resolve.java.structure.JavaClassifier;
public abstract class JavaClassifierImpl extends JavaElementImpl implements JavaClassifier { public abstract class JavaClassifierImpl extends JavaElementImpl<PsiClass> implements JavaClassifier {
protected JavaClassifierImpl(@NotNull PsiClass psiClass) { protected JavaClassifierImpl(@NotNull PsiClass psiClass) {
super(psiClass); super(psiClass);
} }
@NotNull
@Override
public PsiClass getPsi() {
return (PsiClass) super.getPsi();
}
@NotNull @NotNull
/* package */ static JavaClassifier create(@NotNull PsiClass psiClass) { /* package */ static JavaClassifier create(@NotNull PsiClass psiClass) {
if (psiClass instanceof PsiTypeParameter) { if (psiClass instanceof PsiTypeParameter) {
@@ -33,7 +33,7 @@ import java.util.List;
import static org.jetbrains.jet.lang.resolve.java.structure.impl.JavaElementCollectionFromPsiArrayUtil.types; import static org.jetbrains.jet.lang.resolve.java.structure.impl.JavaElementCollectionFromPsiArrayUtil.types;
public class JavaClassifierTypeImpl extends JavaTypeImpl implements JavaClassifierType { public class JavaClassifierTypeImpl extends JavaTypeImpl<PsiClassType> implements JavaClassifierType {
private static class ResolutionResult { private static class ResolutionResult {
private final JavaClassifier classifier; private final JavaClassifier classifier;
private final JavaTypeSubstitutor substitutor; private final JavaTypeSubstitutor substitutor;
@@ -50,12 +50,6 @@ public class JavaClassifierTypeImpl extends JavaTypeImpl implements JavaClassifi
super(psiClassType); super(psiClassType);
} }
@NotNull
@Override
public PsiClassType getPsi() {
return (PsiClassType) super.getPsi();
}
@Override @Override
@Nullable @Nullable
public JavaClassifier getClassifier() { public JavaClassifier getClassifier() {
@@ -20,15 +20,15 @@ import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.java.structure.JavaElement; import org.jetbrains.jet.lang.resolve.java.structure.JavaElement;
public abstract class JavaElementImpl implements JavaElement { public abstract class JavaElementImpl<Psi extends PsiElement> implements JavaElement {
private final PsiElement psiElement; private final Psi psiElement;
protected JavaElementImpl(@NotNull PsiElement psiElement) { protected JavaElementImpl(@NotNull Psi psiElement) {
this.psiElement = psiElement; this.psiElement = psiElement;
} }
@NotNull @NotNull
public PsiElement getPsi() { public Psi getPsi() {
return psiElement; return psiElement;
} }
@@ -29,17 +29,12 @@ import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.Collection; import java.util.Collection;
public abstract class JavaMemberImpl extends JavaElementImpl implements JavaMember, JavaAnnotationOwnerImpl, JavaModifierListOwnerImpl { public abstract class JavaMemberImpl extends JavaElementImpl<PsiMember>
implements JavaMember, JavaAnnotationOwnerImpl, JavaModifierListOwnerImpl {
protected JavaMemberImpl(@NotNull PsiMember psiMember) { protected JavaMemberImpl(@NotNull PsiMember psiMember) {
super(psiMember); super(psiMember);
} }
@NotNull
@Override
public PsiMember getPsi() {
return (PsiMember) super.getPsi();
}
@NotNull @NotNull
@Override @Override
public Name getName() { public Name getName() {
@@ -27,17 +27,11 @@ import java.util.Collection;
import static org.jetbrains.jet.lang.resolve.java.structure.impl.JavaElementCollectionFromPsiArrayUtil.classes; import static org.jetbrains.jet.lang.resolve.java.structure.impl.JavaElementCollectionFromPsiArrayUtil.classes;
import static org.jetbrains.jet.lang.resolve.java.structure.impl.JavaElementCollectionFromPsiArrayUtil.packages; import static org.jetbrains.jet.lang.resolve.java.structure.impl.JavaElementCollectionFromPsiArrayUtil.packages;
public class JavaPackageImpl extends JavaElementImpl implements JavaPackage { public class JavaPackageImpl extends JavaElementImpl<PsiPackage> implements JavaPackage {
public JavaPackageImpl(@NotNull PsiPackage psiPackage) { public JavaPackageImpl(@NotNull PsiPackage psiPackage) {
super(psiPackage); super(psiPackage);
} }
@NotNull
@Override
public PsiPackage getPsi() {
return (PsiPackage) super.getPsi();
}
@Override @Override
@NotNull @NotNull
public Collection<JavaClass> getClasses() { public Collection<JavaClass> getClasses() {
@@ -20,17 +20,11 @@ import com.intellij.psi.PsiPrimitiveType;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.java.structure.JavaPrimitiveType; import org.jetbrains.jet.lang.resolve.java.structure.JavaPrimitiveType;
public class JavaPrimitiveTypeImpl extends JavaTypeImpl implements JavaPrimitiveType { public class JavaPrimitiveTypeImpl extends JavaTypeImpl<PsiPrimitiveType> implements JavaPrimitiveType {
public JavaPrimitiveTypeImpl(@NotNull PsiPrimitiveType psiPrimitiveType) { public JavaPrimitiveTypeImpl(@NotNull PsiPrimitiveType psiPrimitiveType) {
super(psiPrimitiveType); super(psiPrimitiveType);
} }
@NotNull
@Override
public PsiPrimitiveType getPsi() {
return (PsiPrimitiveType) super.getPsi();
}
@Override @Override
@NotNull @NotNull
public String getCanonicalText() { public String getCanonicalText() {
@@ -21,15 +21,15 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.structure.JavaType; import org.jetbrains.jet.lang.resolve.java.structure.JavaType;
public abstract class JavaTypeImpl implements JavaType { public abstract class JavaTypeImpl<Psi extends PsiType> implements JavaType {
private final PsiType psiType; private final Psi psiType;
public JavaTypeImpl(@NotNull PsiType psiType) { public JavaTypeImpl(@NotNull Psi psiType) {
this.psiType = psiType; this.psiType = psiType;
} }
@NotNull @NotNull
public PsiType getPsi() { public Psi getPsi() {
return psiType; return psiType;
} }
@@ -27,17 +27,11 @@ import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.Collection; import java.util.Collection;
public class JavaValueParameterImpl extends JavaElementImpl implements JavaValueParameter, JavaAnnotationOwnerImpl { public class JavaValueParameterImpl extends JavaElementImpl<PsiParameter> implements JavaValueParameter, JavaAnnotationOwnerImpl {
public JavaValueParameterImpl(@NotNull PsiParameter psiParameter) { public JavaValueParameterImpl(@NotNull PsiParameter psiParameter) {
super(psiParameter); super(psiParameter);
} }
@NotNull
@Override
public PsiParameter getPsi() {
return (PsiParameter) super.getPsi();
}
@NotNull @NotNull
@Override @Override
public Collection<JavaAnnotation> getAnnotations() { public Collection<JavaAnnotation> getAnnotations() {
@@ -24,17 +24,11 @@ import org.jetbrains.jet.lang.resolve.java.structure.JavaType;
import org.jetbrains.jet.lang.resolve.java.structure.JavaTypeProvider; import org.jetbrains.jet.lang.resolve.java.structure.JavaTypeProvider;
import org.jetbrains.jet.lang.resolve.java.structure.JavaWildcardType; import org.jetbrains.jet.lang.resolve.java.structure.JavaWildcardType;
public class JavaWildcardTypeImpl extends JavaTypeImpl implements JavaWildcardType { public class JavaWildcardTypeImpl extends JavaTypeImpl<PsiWildcardType> implements JavaWildcardType {
public JavaWildcardTypeImpl(@NotNull PsiWildcardType psiWildcardType) { public JavaWildcardTypeImpl(@NotNull PsiWildcardType psiWildcardType) {
super(psiWildcardType); super(psiWildcardType);
} }
@NotNull
@Override
public PsiWildcardType getPsi() {
return (PsiWildcardType) super.getPsi();
}
@Override @Override
@Nullable @Nullable
public JavaType getBound() { public JavaType getBound() {