Extract interface out of JavaType

This commit is contained in:
Alexander Udalov
2013-08-19 17:16:48 +04:00
parent d364834168
commit 9f44a1eb0d
12 changed files with 102 additions and 76 deletions
@@ -19,7 +19,7 @@ package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiArrayType;
import org.jetbrains.annotations.NotNull;
public class JavaArrayType extends JavaType {
public class JavaArrayType extends JavaTypeImpl {
public JavaArrayType(@NotNull PsiArrayType psiArrayType) {
super(psiArrayType);
}
@@ -37,6 +37,6 @@ public class JavaArrayType extends JavaType {
@NotNull
public JavaType getComponentType() {
return JavaType.create(getPsi().getComponentType());
return JavaTypeImpl.create(getPsi().getComponentType());
}
}
@@ -29,7 +29,7 @@ import java.util.List;
import static org.jetbrains.jet.lang.resolve.java.structure.JavaElementCollectionFromPsiArrayUtil.types;
public class JavaClassifierType extends JavaType {
public class JavaClassifierType extends JavaTypeImpl {
private static class ResolutionResult {
private final JavaClassifier classifier;
private final JavaTypeSubstitutor substitutor;
@@ -94,7 +94,7 @@ public class JavaElementCollectionFromPsiArrayUtil {
if (types.length == 0) return Collections.emptyList();
List<JavaType> result = new ArrayList<JavaType>(types.length);
for (PsiType psiType : types) {
result.add(JavaType.create(psiType));
result.add(JavaTypeImpl.create(psiType));
}
return result;
}
@@ -39,6 +39,6 @@ public class JavaFieldImpl extends JavaMemberImpl implements JavaField {
@Override
@NotNull
public JavaType getType() {
return JavaType.create(getPsi().getType());
return JavaTypeImpl.create(getPsi().getType());
}
}
@@ -67,7 +67,7 @@ public class JavaMethodImpl extends JavaMemberImpl implements JavaMethod {
@Nullable
public JavaType getReturnType() {
PsiType psiType = getPsi().getReturnType();
return psiType == null ? null : JavaType.create(psiType);
return psiType == null ? null : JavaTypeImpl.create(psiType);
}
@Override
@@ -19,7 +19,7 @@ package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiPrimitiveType;
import org.jetbrains.annotations.NotNull;
public class JavaPrimitiveType extends JavaType {
public class JavaPrimitiveType extends JavaTypeImpl {
public JavaPrimitiveType(@NotNull PsiPrimitiveType psiPrimitiveType) {
super(psiPrimitiveType);
}
@@ -16,69 +16,10 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.*;
import com.intellij.psi.PsiType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public abstract class JavaType {
private final PsiType psiType;
public JavaType(@NotNull PsiType psiType) {
this.psiType = psiType;
}
public interface JavaType {
@NotNull
public PsiType getPsi() {
return psiType;
}
@NotNull
public static JavaType create(@NotNull PsiType psiType) {
return psiType.accept(new PsiTypeVisitor<JavaType>() {
@Nullable
@Override
public JavaType visitType(PsiType type) {
throw new UnsupportedOperationException("Unsupported PsiType: " + type);
}
@Nullable
@Override
public JavaType visitPrimitiveType(PsiPrimitiveType primitiveType) {
return new JavaPrimitiveType(primitiveType);
}
@Nullable
@Override
public JavaType visitArrayType(PsiArrayType arrayType) {
return new JavaArrayType(arrayType);
}
@Nullable
@Override
public JavaType visitClassType(PsiClassType classType) {
return new JavaClassifierType(classType);
}
@Nullable
@Override
public JavaType visitWildcardType(PsiWildcardType wildcardType) {
return new JavaWildcardType(wildcardType);
}
});
}
@Override
public int hashCode() {
return getPsi().hashCode();
}
@Override
public boolean equals(Object obj) {
return obj instanceof JavaType && getPsi().equals(((JavaType) obj).getPsi());
}
@Override
public String toString() {
return getClass().getSimpleName() + ": " + getPsi();
}
PsiType getPsi();
}
@@ -0,0 +1,85 @@
/*
* 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;
public abstract class JavaTypeImpl implements JavaType {
private final PsiType psiType;
public JavaTypeImpl(@NotNull PsiType psiType) {
this.psiType = psiType;
}
@Override
@NotNull
public PsiType getPsi() {
return psiType;
}
@NotNull
public static JavaType create(@NotNull PsiType psiType) {
return psiType.accept(new PsiTypeVisitor<JavaType>() {
@Nullable
@Override
public JavaType visitType(PsiType type) {
throw new UnsupportedOperationException("Unsupported PsiType: " + type);
}
@Nullable
@Override
public JavaType visitPrimitiveType(PsiPrimitiveType primitiveType) {
return new JavaPrimitiveType(primitiveType);
}
@Nullable
@Override
public JavaType visitArrayType(PsiArrayType arrayType) {
return new JavaArrayType(arrayType);
}
@Nullable
@Override
public JavaType visitClassType(PsiClassType classType) {
return new JavaClassifierType(classType);
}
@Nullable
@Override
public JavaType visitWildcardType(PsiWildcardType wildcardType) {
return new JavaWildcardType(wildcardType);
}
});
}
@Override
public int hashCode() {
return getPsi().hashCode();
}
@Override
public boolean equals(Object obj) {
return obj instanceof JavaTypeImpl && getPsi().equals(((JavaType) obj).getPsi());
}
@Override
public String toString() {
return getClass().getSimpleName() + ": " + getPsi();
}
}
@@ -30,6 +30,6 @@ public class JavaTypeProvider {
@NotNull
public JavaType createJavaLangObjectType() {
return JavaType.create(PsiType.getJavaLangObject(manager, GlobalSearchScope.allScope(manager.getProject())));
return JavaTypeImpl.create(PsiType.getJavaLangObject(manager, GlobalSearchScope.allScope(manager.getProject())));
}
}
@@ -59,13 +59,13 @@ public class JavaTypeSubstitutor {
@NotNull
public JavaType substitute(@NotNull JavaType type) {
return JavaType.create(getPsi().substitute(type.getPsi()));
return JavaTypeImpl.create(getPsi().substitute(type.getPsi()));
}
@Nullable
public JavaType substitute(@NotNull JavaTypeParameter typeParameter) {
PsiType psiType = getPsi().substitute(typeParameter.getPsi());
return psiType == null ? null : JavaType.create(psiType);
return psiType == null ? null : JavaTypeImpl.create(psiType);
}
@NotNull
@@ -75,7 +75,7 @@ public class JavaTypeSubstitutor {
substitutionMap = new HashMap<JavaTypeParameter, JavaType>();
for (Map.Entry<PsiTypeParameter, PsiType> entry : psiMap.entrySet()) {
PsiType value = entry.getValue();
substitutionMap.put(new JavaTypeParameter(entry.getKey()), value == null ? null : JavaType.create(value));
substitutionMap.put(new JavaTypeParameter(entry.getKey()), value == null ? null : JavaTypeImpl.create(value));
}
}
@@ -55,7 +55,7 @@ public class JavaValueParameter extends JavaElementImpl implements JavaAnnotatio
@NotNull
public JavaType getType() {
return JavaType.create(getPsi().getType());
return JavaTypeImpl.create(getPsi().getType());
}
public boolean isVararg() {
@@ -21,7 +21,7 @@ import com.intellij.psi.PsiWildcardType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JavaWildcardType extends JavaType {
public class JavaWildcardType extends JavaTypeImpl {
public JavaWildcardType(@NotNull PsiWildcardType psiWildcardType) {
super(psiWildcardType);
}
@@ -35,7 +35,7 @@ public class JavaWildcardType extends JavaType {
@Nullable
public JavaType getBound() {
PsiType bound = getPsi().getBound();
return bound == null ? null : JavaType.create(bound);
return bound == null ? null : JavaTypeImpl.create(bound);
}
public boolean isExtends() {