Remove interface JavaTypeSubstitutor, use implementation
After 151e55b JavaTypeSubstitutor is only used from inside PSI-based
implementation of Java structure
This commit is contained in:
+2
-3
@@ -176,14 +176,13 @@ public class JavaClassImpl extends JavaClassifierImpl<PsiClass> implements JavaC
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JavaType createImmediateType(@NotNull JavaTypeSubstitutor substitutor) {
|
||||
public JavaType createImmediateType(@NotNull JavaTypeSubstitutorImpl substitutor) {
|
||||
return new JavaClassifierTypeImpl(
|
||||
JavaPsiFacade.getElementFactory(getPsi().getProject()).createType(getPsi(), createPsiSubstitutor(substitutor)));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static PsiSubstitutor createPsiSubstitutor(@NotNull JavaTypeSubstitutor substitutor) {
|
||||
private static PsiSubstitutor createPsiSubstitutor(@NotNull JavaTypeSubstitutorImpl substitutor) {
|
||||
Map<PsiTypeParameter, PsiType> substMap = new HashMap<PsiTypeParameter, PsiType>();
|
||||
for (Map.Entry<JavaTypeParameter, JavaType> entry : substitutor.getSubstitutionMap().entrySet()) {
|
||||
PsiTypeParameter key = ((JavaTypeParameterImpl) entry.getKey()).getPsi();
|
||||
|
||||
+8
-6
@@ -19,17 +19,20 @@ package org.jetbrains.kotlin.load.java.structure.impl;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.load.java.structure.*;
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClassifier;
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClassifierType;
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaType;
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaTypeParameter;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class JavaClassifierTypeImpl extends JavaTypeImpl<PsiClassType> implements JavaClassifierType {
|
||||
private static class ResolutionResult {
|
||||
private final JavaClassifier classifier;
|
||||
private final JavaTypeSubstitutor substitutor;
|
||||
private final JavaTypeSubstitutorImpl substitutor;
|
||||
private final boolean isRaw;
|
||||
|
||||
private ResolutionResult(@Nullable JavaClassifier classifier, @NotNull JavaTypeSubstitutor substitutor, boolean isRaw) {
|
||||
private ResolutionResult(@Nullable JavaClassifier classifier, @NotNull JavaTypeSubstitutorImpl substitutor, boolean isRaw) {
|
||||
this.classifier = classifier;
|
||||
this.substitutor = substitutor;
|
||||
this.isRaw = isRaw;
|
||||
@@ -49,9 +52,8 @@ public class JavaClassifierTypeImpl extends JavaTypeImpl<PsiClassType> implement
|
||||
return resolutionResult.classifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JavaTypeSubstitutor getSubstitutor() {
|
||||
public JavaTypeSubstitutorImpl getSubstitutor() {
|
||||
resolve();
|
||||
return resolutionResult.substitutor;
|
||||
}
|
||||
@@ -118,7 +120,7 @@ public class JavaClassifierTypeImpl extends JavaTypeImpl<PsiClassType> implement
|
||||
? getTypeParameters(((JavaClassImpl) classifier).getPsi())
|
||||
: Collections.<PsiTypeParameter>emptyList();
|
||||
|
||||
JavaTypeSubstitutor substitutor = getSubstitutor();
|
||||
JavaTypeSubstitutorImpl substitutor = getSubstitutor();
|
||||
|
||||
List<JavaType> result = new ArrayList<JavaType>();
|
||||
for (PsiTypeParameter typeParameter : parameters) {
|
||||
|
||||
+7
-8
@@ -25,7 +25,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class JavaTypeSubstitutorImpl implements JavaTypeSubstitutor {
|
||||
public class JavaTypeSubstitutorImpl {
|
||||
private final Map<JavaTypeParameter, JavaType> substitutionMap;
|
||||
|
||||
public JavaTypeSubstitutorImpl(@NotNull Map<JavaTypeParameter, JavaType> substitutionMap) {
|
||||
@@ -33,7 +33,6 @@ public class JavaTypeSubstitutorImpl implements JavaTypeSubstitutor {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JavaType substitute(@NotNull JavaType type) {
|
||||
JavaType substitutedType = substituteInternal(type);
|
||||
return substitutedType != null ? substitutedType : correctSubstitutionForRawType(type);
|
||||
@@ -63,10 +62,10 @@ public class JavaTypeSubstitutorImpl implements JavaTypeSubstitutor {
|
||||
if (classifier instanceof JavaTypeParameter) {
|
||||
return substitute((JavaTypeParameter) classifier);
|
||||
}
|
||||
else if (classifier instanceof JavaClass) {
|
||||
JavaClass javaClass = (JavaClass) classifier;
|
||||
else if (classifier instanceof JavaClassImpl) {
|
||||
JavaClassImpl javaClass = (JavaClassImpl) classifier;
|
||||
Map<JavaTypeParameter, JavaType> substMap = new HashMap<JavaTypeParameter, JavaType>();
|
||||
processClass(javaClass, classifierType.getSubstitutor(), substMap);
|
||||
processClass(javaClass, ((JavaClassifierTypeImpl) classifierType).getSubstitutor(), substMap);
|
||||
|
||||
return javaClass.createImmediateType(new JavaTypeSubstitutorImpl(substMap));
|
||||
}
|
||||
@@ -90,7 +89,9 @@ public class JavaTypeSubstitutorImpl implements JavaTypeSubstitutor {
|
||||
return type;
|
||||
}
|
||||
|
||||
private void processClass(@NotNull JavaClass javaClass, @NotNull JavaTypeSubstitutor substitutor, @NotNull Map<JavaTypeParameter, JavaType> substMap) {
|
||||
private void processClass(
|
||||
@NotNull JavaClass javaClass, @NotNull JavaTypeSubstitutorImpl substitutor, @NotNull Map<JavaTypeParameter, JavaType> substMap
|
||||
) {
|
||||
List<JavaTypeParameter> typeParameters = javaClass.getTypeParameters();
|
||||
for (JavaTypeParameter typeParameter : typeParameters) {
|
||||
JavaType substitutedParam = substitutor.substitute(typeParameter);
|
||||
@@ -152,7 +153,6 @@ public class JavaTypeSubstitutorImpl implements JavaTypeSubstitutor {
|
||||
return typeParameter.getTypeProvider().createJavaLangObjectType();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public JavaType substitute(@NotNull JavaTypeParameter typeParameter) {
|
||||
if (substitutionMap.containsKey(typeParameter)) {
|
||||
@@ -162,7 +162,6 @@ public class JavaTypeSubstitutorImpl implements JavaTypeSubstitutor {
|
||||
return typeParameter.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Map<JavaTypeParameter, JavaType> getSubstitutionMap() {
|
||||
return substitutionMap;
|
||||
|
||||
Reference in New Issue
Block a user