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
|
@NotNull
|
||||||
@Override
|
public JavaType createImmediateType(@NotNull JavaTypeSubstitutorImpl substitutor) {
|
||||||
public JavaType createImmediateType(@NotNull JavaTypeSubstitutor substitutor) {
|
|
||||||
return new JavaClassifierTypeImpl(
|
return new JavaClassifierTypeImpl(
|
||||||
JavaPsiFacade.getElementFactory(getPsi().getProject()).createType(getPsi(), createPsiSubstitutor(substitutor)));
|
JavaPsiFacade.getElementFactory(getPsi().getProject()).createType(getPsi(), createPsiSubstitutor(substitutor)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static PsiSubstitutor createPsiSubstitutor(@NotNull JavaTypeSubstitutor substitutor) {
|
private static PsiSubstitutor createPsiSubstitutor(@NotNull JavaTypeSubstitutorImpl substitutor) {
|
||||||
Map<PsiTypeParameter, PsiType> substMap = new HashMap<PsiTypeParameter, PsiType>();
|
Map<PsiTypeParameter, PsiType> substMap = new HashMap<PsiTypeParameter, PsiType>();
|
||||||
for (Map.Entry<JavaTypeParameter, JavaType> entry : substitutor.getSubstitutionMap().entrySet()) {
|
for (Map.Entry<JavaTypeParameter, JavaType> entry : substitutor.getSubstitutionMap().entrySet()) {
|
||||||
PsiTypeParameter key = ((JavaTypeParameterImpl) entry.getKey()).getPsi();
|
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 com.intellij.psi.*;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
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.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class JavaClassifierTypeImpl extends JavaTypeImpl<PsiClassType> 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 JavaTypeSubstitutorImpl substitutor;
|
||||||
private final boolean isRaw;
|
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.classifier = classifier;
|
||||||
this.substitutor = substitutor;
|
this.substitutor = substitutor;
|
||||||
this.isRaw = isRaw;
|
this.isRaw = isRaw;
|
||||||
@@ -49,9 +52,8 @@ public class JavaClassifierTypeImpl extends JavaTypeImpl<PsiClassType> implement
|
|||||||
return resolutionResult.classifier;
|
return resolutionResult.classifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JavaTypeSubstitutor getSubstitutor() {
|
public JavaTypeSubstitutorImpl getSubstitutor() {
|
||||||
resolve();
|
resolve();
|
||||||
return resolutionResult.substitutor;
|
return resolutionResult.substitutor;
|
||||||
}
|
}
|
||||||
@@ -118,7 +120,7 @@ public class JavaClassifierTypeImpl extends JavaTypeImpl<PsiClassType> implement
|
|||||||
? getTypeParameters(((JavaClassImpl) classifier).getPsi())
|
? getTypeParameters(((JavaClassImpl) classifier).getPsi())
|
||||||
: Collections.<PsiTypeParameter>emptyList();
|
: Collections.<PsiTypeParameter>emptyList();
|
||||||
|
|
||||||
JavaTypeSubstitutor substitutor = getSubstitutor();
|
JavaTypeSubstitutorImpl substitutor = getSubstitutor();
|
||||||
|
|
||||||
List<JavaType> result = new ArrayList<JavaType>();
|
List<JavaType> result = new ArrayList<JavaType>();
|
||||||
for (PsiTypeParameter typeParameter : parameters) {
|
for (PsiTypeParameter typeParameter : parameters) {
|
||||||
|
|||||||
+7
-8
@@ -25,7 +25,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class JavaTypeSubstitutorImpl implements JavaTypeSubstitutor {
|
public class JavaTypeSubstitutorImpl {
|
||||||
private final Map<JavaTypeParameter, JavaType> substitutionMap;
|
private final Map<JavaTypeParameter, JavaType> substitutionMap;
|
||||||
|
|
||||||
public JavaTypeSubstitutorImpl(@NotNull Map<JavaTypeParameter, JavaType> substitutionMap) {
|
public JavaTypeSubstitutorImpl(@NotNull Map<JavaTypeParameter, JavaType> substitutionMap) {
|
||||||
@@ -33,7 +33,6 @@ public class JavaTypeSubstitutorImpl implements JavaTypeSubstitutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
|
||||||
public JavaType substitute(@NotNull JavaType type) {
|
public JavaType substitute(@NotNull JavaType type) {
|
||||||
JavaType substitutedType = substituteInternal(type);
|
JavaType substitutedType = substituteInternal(type);
|
||||||
return substitutedType != null ? substitutedType : correctSubstitutionForRawType(type);
|
return substitutedType != null ? substitutedType : correctSubstitutionForRawType(type);
|
||||||
@@ -63,10 +62,10 @@ public class JavaTypeSubstitutorImpl implements JavaTypeSubstitutor {
|
|||||||
if (classifier instanceof JavaTypeParameter) {
|
if (classifier instanceof JavaTypeParameter) {
|
||||||
return substitute((JavaTypeParameter) classifier);
|
return substitute((JavaTypeParameter) classifier);
|
||||||
}
|
}
|
||||||
else if (classifier instanceof JavaClass) {
|
else if (classifier instanceof JavaClassImpl) {
|
||||||
JavaClass javaClass = (JavaClass) classifier;
|
JavaClassImpl javaClass = (JavaClassImpl) classifier;
|
||||||
Map<JavaTypeParameter, JavaType> substMap = new HashMap<JavaTypeParameter, JavaType>();
|
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));
|
return javaClass.createImmediateType(new JavaTypeSubstitutorImpl(substMap));
|
||||||
}
|
}
|
||||||
@@ -90,7 +89,9 @@ public class JavaTypeSubstitutorImpl implements JavaTypeSubstitutor {
|
|||||||
return type;
|
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();
|
List<JavaTypeParameter> typeParameters = javaClass.getTypeParameters();
|
||||||
for (JavaTypeParameter typeParameter : typeParameters) {
|
for (JavaTypeParameter typeParameter : typeParameters) {
|
||||||
JavaType substitutedParam = substitutor.substitute(typeParameter);
|
JavaType substitutedParam = substitutor.substitute(typeParameter);
|
||||||
@@ -152,7 +153,6 @@ public class JavaTypeSubstitutorImpl implements JavaTypeSubstitutor {
|
|||||||
return typeParameter.getTypeProvider().createJavaLangObjectType();
|
return typeParameter.getTypeProvider().createJavaLangObjectType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public JavaType substitute(@NotNull JavaTypeParameter typeParameter) {
|
public JavaType substitute(@NotNull JavaTypeParameter typeParameter) {
|
||||||
if (substitutionMap.containsKey(typeParameter)) {
|
if (substitutionMap.containsKey(typeParameter)) {
|
||||||
@@ -162,7 +162,6 @@ public class JavaTypeSubstitutorImpl implements JavaTypeSubstitutor {
|
|||||||
return typeParameter.getType();
|
return typeParameter.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Map<JavaTypeParameter, JavaType> getSubstitutionMap() {
|
public Map<JavaTypeParameter, JavaType> getSubstitutionMap() {
|
||||||
return substitutionMap;
|
return substitutionMap;
|
||||||
|
|||||||
-3
@@ -56,9 +56,6 @@ public interface JavaClass extends JavaClassifier, JavaTypeParameterListOwner, J
|
|||||||
@NotNull
|
@NotNull
|
||||||
OriginKind getOriginKind();
|
OriginKind getOriginKind();
|
||||||
|
|
||||||
@NotNull
|
|
||||||
JavaType createImmediateType(@NotNull JavaTypeSubstitutor substitutor);
|
|
||||||
|
|
||||||
enum OriginKind {
|
enum OriginKind {
|
||||||
COMPILED,
|
COMPILED,
|
||||||
SOURCE,
|
SOURCE,
|
||||||
|
|||||||
-3
@@ -27,9 +27,6 @@ public interface JavaClassifierType extends JavaType, JavaAnnotationOwner {
|
|||||||
@Nullable
|
@Nullable
|
||||||
JavaClassifier getClassifier();
|
JavaClassifier getClassifier();
|
||||||
|
|
||||||
@NotNull
|
|
||||||
JavaTypeSubstitutor getSubstitutor();
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ReadOnly
|
@ReadOnly
|
||||||
Collection<JavaClassifierType> getSupertypes();
|
Collection<JavaClassifierType> getSupertypes();
|
||||||
|
|||||||
-59
@@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2015 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.kotlin.load.java.structure;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public interface JavaTypeSubstitutor {
|
|
||||||
JavaTypeSubstitutor EMPTY = new JavaTypeSubstitutor() {
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public JavaType substitute(@NotNull JavaType type) {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public JavaType substitute(@NotNull JavaTypeParameter typeParameter) {
|
|
||||||
return typeParameter.getType();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Map<JavaTypeParameter, JavaType> getSubstitutionMap() {
|
|
||||||
return Collections.emptyMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Empty JavaTypeSubstitutor";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
JavaType substitute(@NotNull JavaType type);
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
JavaType substitute(@NotNull JavaTypeParameter typeParameter);
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
Map<JavaTypeParameter, JavaType> getSubstitutionMap();
|
|
||||||
}
|
|
||||||
+1
-5
@@ -18,11 +18,9 @@ package org.jetbrains.kotlin.load.java.structure.reflect
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaClassifierType
|
import org.jetbrains.kotlin.load.java.structure.JavaClassifierType
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaType
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaTypeSubstitutor
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import java.lang.reflect.Method
|
import java.lang.reflect.Method
|
||||||
import java.util.Arrays
|
import java.util.*
|
||||||
|
|
||||||
class ReflectJavaClass(
|
class ReflectJavaClass(
|
||||||
private val klass: Class<*>
|
private val klass: Class<*>
|
||||||
@@ -88,8 +86,6 @@ class ReflectJavaClass(
|
|||||||
// TODO: drop OriginKind
|
// TODO: drop OriginKind
|
||||||
override fun getOriginKind() = JavaClass.OriginKind.COMPILED
|
override fun getOriginKind() = JavaClass.OriginKind.COMPILED
|
||||||
|
|
||||||
override fun createImmediateType(substitutor: JavaTypeSubstitutor): JavaType = throw UnsupportedOperationException()
|
|
||||||
|
|
||||||
override fun getName(): Name = Name.identifier(klass.simpleName)
|
override fun getName(): Name = Name.identifier(klass.simpleName)
|
||||||
|
|
||||||
override fun getTypeParameters() = klass.typeParameters.map { ReflectJavaTypeParameter(it) }
|
override fun getTypeParameters() = klass.typeParameters.map { ReflectJavaTypeParameter(it) }
|
||||||
|
|||||||
+4
-3
@@ -16,7 +16,10 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.load.java.structure.reflect
|
package org.jetbrains.kotlin.load.java.structure.reflect
|
||||||
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.*
|
import org.jetbrains.kotlin.load.java.structure.JavaAnnotation
|
||||||
|
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.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import java.lang.reflect.ParameterizedType
|
import java.lang.reflect.ParameterizedType
|
||||||
import java.lang.reflect.Type
|
import java.lang.reflect.Type
|
||||||
@@ -36,8 +39,6 @@ class ReflectJavaClassifierType(public override val type: Type) : ReflectJavaTyp
|
|||||||
|
|
||||||
override fun getClassifier(): JavaClassifier = classifier
|
override fun getClassifier(): JavaClassifier = classifier
|
||||||
|
|
||||||
override fun getSubstitutor(): JavaTypeSubstitutor = throw UnsupportedOperationException()
|
|
||||||
|
|
||||||
override fun getSupertypes(): Collection<JavaClassifierType> = throw UnsupportedOperationException()
|
override fun getSupertypes(): Collection<JavaClassifierType> = throw UnsupportedOperationException()
|
||||||
|
|
||||||
override fun getPresentableText(): String = type.toString()
|
override fun getPresentableText(): String = type.toString()
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ import com.intellij.testFramework.LightProjectDescriptor;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase;
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase;
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor;
|
import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor;
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaClassifierType;
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaType;
|
import org.jetbrains.kotlin.load.java.structure.JavaType;
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaTypeParameter;
|
import org.jetbrains.kotlin.load.java.structure.JavaTypeParameter;
|
||||||
|
import org.jetbrains.kotlin.load.java.structure.impl.JavaClassifierTypeImpl;
|
||||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaTypeImpl;
|
import org.jetbrains.kotlin.load.java.structure.impl.JavaTypeImpl;
|
||||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaTypeParameterImpl;
|
import org.jetbrains.kotlin.load.java.structure.impl.JavaTypeParameterImpl;
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ public abstract class AbstractJavaTypeSubstitutorTest extends KotlinLightCodeIns
|
|||||||
private static void doTest(@NotNull PsiClassType type, @NotNull PsiTypeParameter typeParameter) {
|
private static void doTest(@NotNull PsiClassType type, @NotNull PsiTypeParameter typeParameter) {
|
||||||
PsiType expectedType = type.resolveGenerics().getSubstitutor().substitute(typeParameter);
|
PsiType expectedType = type.resolveGenerics().getSubstitutor().substitute(typeParameter);
|
||||||
|
|
||||||
JavaClassifierType javaClassifierType = (JavaClassifierType) JavaTypeImpl.create(type);
|
JavaClassifierTypeImpl javaClassifierType = (JavaClassifierTypeImpl) JavaTypeImpl.create(type);
|
||||||
JavaTypeParameter javaTypeToSubstitute = new JavaTypeParameterImpl(typeParameter);
|
JavaTypeParameter javaTypeToSubstitute = new JavaTypeParameterImpl(typeParameter);
|
||||||
JavaType actualType = javaClassifierType.getSubstitutor().substitute(javaTypeToSubstitute);
|
JavaType actualType = javaClassifierType.getSubstitutor().substitute(javaTypeToSubstitute);
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ public abstract class AbstractJavaTypeSubstitutorTest extends KotlinLightCodeIns
|
|||||||
private static void doTest(@NotNull PsiClassType type, @NotNull PsiType psiTypeToSubstitute) {
|
private static void doTest(@NotNull PsiClassType type, @NotNull PsiType psiTypeToSubstitute) {
|
||||||
PsiType expectedType = type.resolveGenerics().getSubstitutor().substitute(psiTypeToSubstitute);
|
PsiType expectedType = type.resolveGenerics().getSubstitutor().substitute(psiTypeToSubstitute);
|
||||||
|
|
||||||
JavaClassifierType javaClassifierType = (JavaClassifierType) JavaTypeImpl.create(type);
|
JavaClassifierTypeImpl javaClassifierType = (JavaClassifierTypeImpl) JavaTypeImpl.create(type);
|
||||||
JavaType javaTypeToSubstitute = JavaTypeImpl.create(psiTypeToSubstitute);
|
JavaType javaTypeToSubstitute = JavaTypeImpl.create(psiTypeToSubstitute);
|
||||||
JavaType actualType = javaClassifierType.getSubstitutor().substitute(javaTypeToSubstitute);
|
JavaType actualType = javaClassifierType.getSubstitutor().substitute(javaTypeToSubstitute);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user