Cleanup JavaElement model from methods used only in substitutor
Downcast everything used in JavaTypeSubstitutorImpl to *Impl, remove methods from interfaces, inline/move some of them
This commit is contained in:
+1
-2
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.load.java.structure.impl;
|
||||
import com.intellij.psi.PsiArrayType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaArrayType;
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaType;
|
||||
|
||||
public class JavaArrayTypeImpl extends JavaTypeImpl<PsiArrayType> implements JavaArrayType {
|
||||
public JavaArrayTypeImpl(@NotNull PsiArrayType psiArrayType) {
|
||||
@@ -28,7 +27,7 @@ public class JavaArrayTypeImpl extends JavaTypeImpl<PsiArrayType> implements Jav
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JavaType getComponentType() {
|
||||
public JavaTypeImpl<?> getComponentType() {
|
||||
return JavaTypeImpl.create(getPsi().getComponentType());
|
||||
}
|
||||
}
|
||||
|
||||
+13
-20
@@ -78,7 +78,7 @@ public class JavaClassImpl extends JavaClassifierImpl<PsiClass> implements JavaC
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public JavaClass getOuterClass() {
|
||||
public JavaClassImpl getOuterClass() {
|
||||
PsiClass outer = getPsi().getContainingClass();
|
||||
return outer == null ? null : new JavaClassImpl(outer);
|
||||
}
|
||||
@@ -154,12 +154,6 @@ public class JavaClassImpl extends JavaClassifierImpl<PsiClass> implements JavaC
|
||||
return JavaElementUtil.getVisibility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JavaClassifierType getDefaultType() {
|
||||
return new JavaClassifierTypeImpl(JavaPsiFacade.getElementFactory(getPsi().getProject()).createType(getPsi()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public OriginKind getOriginKind() {
|
||||
@@ -176,25 +170,24 @@ public class JavaClassImpl extends JavaClassifierImpl<PsiClass> implements JavaC
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JavaType createImmediateType(@NotNull JavaTypeSubstitutorImpl substitutor) {
|
||||
/* package */ JavaTypeImpl<?> createImmediateType(@NotNull Map<JavaTypeParameterImpl, JavaTypeImpl<?>> substitutionMap) {
|
||||
return new JavaClassifierTypeImpl(
|
||||
JavaPsiFacade.getElementFactory(getPsi().getProject()).createType(getPsi(), createPsiSubstitutor(substitutor)));
|
||||
JavaPsiFacade.getElementFactory(getPsi().getProject()).createType(getPsi(), createPsiSubstitutor(substitutionMap))
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
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();
|
||||
if (entry.getValue() == null) {
|
||||
substMap.put(key, null);
|
||||
}
|
||||
else {
|
||||
substMap.put(key, ((JavaTypeImpl) entry.getValue()).getPsi());
|
||||
}
|
||||
private static PsiSubstitutor createPsiSubstitutor(@NotNull Map<JavaTypeParameterImpl, JavaTypeImpl<?>> substitutionMap) {
|
||||
if (substitutionMap.isEmpty()) return PsiSubstitutor.EMPTY;
|
||||
|
||||
Map<PsiTypeParameter, PsiType> result = new HashMap<PsiTypeParameter, PsiType>();
|
||||
for (Map.Entry<JavaTypeParameterImpl, JavaTypeImpl<?>> entry : substitutionMap.entrySet()) {
|
||||
PsiTypeParameter key = entry.getKey().getPsi();
|
||||
JavaTypeImpl<?> value = entry.getValue();
|
||||
result.put(key, value == null ? null : value.getPsi());
|
||||
}
|
||||
|
||||
return PsiSubstitutorImpl.createSubstitutor(substMap);
|
||||
return PsiSubstitutorImpl.createSubstitutor(result);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ public abstract class JavaClassifierImpl<Psi extends PsiClass> extends JavaEleme
|
||||
}
|
||||
|
||||
@NotNull
|
||||
/* package */ static JavaClassifier create(@NotNull PsiClass psiClass) {
|
||||
/* package */ static JavaClassifierImpl<?> create(@NotNull PsiClass psiClass) {
|
||||
if (psiClass instanceof PsiTypeParameter) {
|
||||
return new JavaTypeParameterImpl((PsiTypeParameter) psiClass);
|
||||
}
|
||||
|
||||
+10
-26
@@ -19,20 +19,18 @@ 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.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 JavaClassifierImpl<?> classifier;
|
||||
private final JavaTypeSubstitutorImpl substitutor;
|
||||
private final boolean isRaw;
|
||||
|
||||
private ResolutionResult(@Nullable JavaClassifier classifier, @NotNull JavaTypeSubstitutorImpl substitutor, boolean isRaw) {
|
||||
private ResolutionResult(@Nullable JavaClassifierImpl<?> classifier, @NotNull JavaTypeSubstitutorImpl substitutor, boolean isRaw) {
|
||||
this.classifier = classifier;
|
||||
this.substitutor = substitutor;
|
||||
this.isRaw = isRaw;
|
||||
@@ -47,7 +45,7 @@ public class JavaClassifierTypeImpl extends JavaTypeImpl<PsiClassType> implement
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public JavaClassifier getClassifier() {
|
||||
public JavaClassifierImpl<?> getClassifier() {
|
||||
resolve();
|
||||
return resolutionResult.classifier;
|
||||
}
|
||||
@@ -66,35 +64,21 @@ public class JavaClassifierTypeImpl extends JavaTypeImpl<PsiClassType> implement
|
||||
resolutionResult = new ResolutionResult(
|
||||
psiClass == null ? null : JavaClassifierImpl.create(psiClass),
|
||||
new JavaTypeSubstitutorImpl(convertSubstitutionMap(substitutor.getSubstitutionMap())),
|
||||
PsiClassType.isRaw(result));
|
||||
PsiClassType.isRaw(result)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Map<JavaTypeParameter, JavaType> convertSubstitutionMap(@NotNull Map<PsiTypeParameter, PsiType> psiMap) {
|
||||
private static Map<JavaTypeParameterImpl, JavaTypeImpl<?>> convertSubstitutionMap(@NotNull Map<PsiTypeParameter, PsiType> psiMap) {
|
||||
if (psiMap.isEmpty()) return Collections.emptyMap();
|
||||
|
||||
Map<JavaTypeParameter, JavaType> substitutionMap = new HashMap<JavaTypeParameter, JavaType>();
|
||||
Map<JavaTypeParameterImpl, JavaTypeImpl<?>> result = new HashMap<JavaTypeParameterImpl, JavaTypeImpl<?>>();
|
||||
for (Map.Entry<PsiTypeParameter, PsiType> entry : psiMap.entrySet()) {
|
||||
PsiType value = entry.getValue();
|
||||
substitutionMap.put(new JavaTypeParameterImpl(entry.getKey()), value == null ? null : JavaTypeImpl.create(value));
|
||||
result.put(new JavaTypeParameterImpl(entry.getKey()), value == null ? null : JavaTypeImpl.create(value));
|
||||
}
|
||||
|
||||
return substitutionMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<JavaClassifierType> getSupertypes() {
|
||||
PsiType[] psiTypes = getPsi().getSuperTypes();
|
||||
if (psiTypes.length == 0) return Collections.emptyList();
|
||||
List<JavaClassifierType> result = new ArrayList<JavaClassifierType>(psiTypes.length);
|
||||
for (PsiType psiType : psiTypes) {
|
||||
if (!(psiType instanceof PsiClassType)) {
|
||||
throw new IllegalStateException("Supertype should be a class: " + psiType + ", type: " + getPsi());
|
||||
}
|
||||
result.add(new JavaClassifierTypeImpl((PsiClassType) psiType));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -113,11 +97,11 @@ public class JavaClassifierTypeImpl extends JavaTypeImpl<PsiClassType> implement
|
||||
@Override
|
||||
@NotNull
|
||||
public List<JavaType> getTypeArguments() {
|
||||
JavaClassifier classifier = getClassifier();
|
||||
JavaClassifierImpl<?> classifier = getClassifier();
|
||||
|
||||
// parameters including ones from outer class
|
||||
Iterable<PsiTypeParameter> parameters = classifier instanceof JavaClassImpl
|
||||
? getTypeParameters(((JavaClassImpl) classifier).getPsi())
|
||||
? getTypeParameters(classifier.getPsi())
|
||||
: Collections.<PsiTypeParameter>emptyList();
|
||||
|
||||
JavaTypeSubstitutorImpl substitutor = getSubstitutor();
|
||||
|
||||
-7
@@ -20,7 +20,6 @@ import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaAnnotation;
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaArrayType;
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaType;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
|
||||
@@ -79,12 +78,6 @@ public abstract class JavaTypeImpl<Psi extends PsiType> implements JavaType, Jav
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JavaArrayType createArrayType() {
|
||||
return new JavaArrayTypeImpl(getPsi().createArrayType());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JavaAnnotation> getAnnotations() {
|
||||
|
||||
+4
-33
@@ -16,10 +16,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.java.structure.impl;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.PsiAnnotationOwner;
|
||||
import com.intellij.psi.PsiTypeParameter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.load.java.structure.*;
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClassifierType;
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaTypeParameter;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -43,37 +45,6 @@ public class JavaTypeParameterImpl extends JavaClassifierImpl<PsiTypeParameter>
|
||||
return classifierTypes(getPsi().getExtendsList().getReferencedTypes());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public JavaTypeParameterListOwner getOwner() {
|
||||
PsiTypeParameterListOwner owner = getPsi().getOwner();
|
||||
// TODO: a separate factory for such things
|
||||
if (owner instanceof PsiMethod) {
|
||||
PsiMethod psiMethod = (PsiMethod) owner;
|
||||
return psiMethod.isConstructor() ? new JavaConstructorImpl(psiMethod) : new JavaMethodImpl(psiMethod);
|
||||
}
|
||||
else if (owner instanceof PsiClass) {
|
||||
return new JavaClassImpl((PsiClass) owner);
|
||||
}
|
||||
else if (owner != null) {
|
||||
throw new UnsupportedOperationException("Unsupported type parameter list owner: " + owner);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JavaType getType() {
|
||||
return JavaTypeImpl.create(JavaPsiFacade.getInstance(getPsi().getProject()).getElementFactory().createType(getPsi()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JavaTypeProvider getTypeProvider() {
|
||||
return new JavaTypeProviderImpl(getPsi().getManager());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiAnnotationOwner getAnnotationOwnerPsi() {
|
||||
|
||||
-58
@@ -1,58 +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.impl;
|
||||
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.PsiWildcardType;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaType;
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaTypeProvider;
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaWildcardType;
|
||||
|
||||
public class JavaTypeProviderImpl implements JavaTypeProvider {
|
||||
private final PsiManager manager;
|
||||
|
||||
public JavaTypeProviderImpl(@NotNull PsiManager manager) {
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JavaType createJavaLangObjectType() {
|
||||
return JavaTypeImpl.create(PsiType.getJavaLangObject(manager, GlobalSearchScope.allScope(manager.getProject())));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JavaWildcardType createUpperBoundWildcard(@NotNull JavaType bound) {
|
||||
return new JavaWildcardTypeImpl(PsiWildcardType.createExtends(manager, ((JavaTypeImpl) bound).getPsi()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JavaWildcardType createLowerBoundWildcard(@NotNull JavaType bound) {
|
||||
return new JavaWildcardTypeImpl(PsiWildcardType.createSuper(manager, ((JavaTypeImpl) bound).getPsi()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JavaWildcardType createUnboundedWildcard() {
|
||||
return new JavaWildcardTypeImpl(PsiWildcardType.createUnbounded(manager));
|
||||
}
|
||||
}
|
||||
+73
-52
@@ -16,9 +16,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.java.structure.impl;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
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.JavaPrimitiveType;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -26,15 +30,15 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class JavaTypeSubstitutorImpl {
|
||||
private final Map<JavaTypeParameter, JavaType> substitutionMap;
|
||||
private final Map<JavaTypeParameterImpl, JavaTypeImpl<?>> substitutionMap;
|
||||
|
||||
public JavaTypeSubstitutorImpl(@NotNull Map<JavaTypeParameter, JavaType> substitutionMap) {
|
||||
public JavaTypeSubstitutorImpl(@NotNull Map<JavaTypeParameterImpl, JavaTypeImpl<?>> substitutionMap) {
|
||||
this.substitutionMap = substitutionMap;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JavaType substitute(@NotNull JavaType type) {
|
||||
JavaType substitutedType = substituteInternal(type);
|
||||
public JavaTypeImpl<?> substitute(@NotNull JavaTypeImpl<?> type) {
|
||||
JavaTypeImpl<?> substitutedType = substituteInternal(type);
|
||||
return substitutedType != null ? substitutedType : correctSubstitutionForRawType(type);
|
||||
}
|
||||
|
||||
@@ -42,11 +46,11 @@ public class JavaTypeSubstitutorImpl {
|
||||
// In case of raw type we get substitution map like T -> null,
|
||||
// in this case we should substitute upper bound of T or,
|
||||
// if it does not exist, return java.lang.Object
|
||||
private JavaType correctSubstitutionForRawType(@NotNull JavaType original) {
|
||||
private JavaTypeImpl<?> correctSubstitutionForRawType(@NotNull JavaTypeImpl<?> original) {
|
||||
if (original instanceof JavaClassifierType) {
|
||||
JavaClassifier classifier = ((JavaClassifierType) original).getClassifier();
|
||||
if (classifier instanceof JavaTypeParameter) {
|
||||
return rawTypeForTypeParameter((JavaTypeParameter) classifier);
|
||||
if (classifier instanceof JavaTypeParameterImpl) {
|
||||
return rawTypeForTypeParameter((JavaTypeParameterImpl) classifier);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,20 +58,20 @@ public class JavaTypeSubstitutorImpl {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JavaType substituteInternal(@NotNull JavaType type) {
|
||||
if (type instanceof JavaClassifierType) {
|
||||
JavaClassifierType classifierType = (JavaClassifierType) type;
|
||||
JavaClassifier classifier = classifierType.getClassifier();
|
||||
private JavaTypeImpl<?> substituteInternal(@NotNull JavaTypeImpl<?> type) {
|
||||
if (type instanceof JavaClassifierTypeImpl) {
|
||||
JavaClassifierTypeImpl classifierType = (JavaClassifierTypeImpl) type;
|
||||
JavaClassifierImpl<?> classifier = classifierType.getClassifier();
|
||||
|
||||
if (classifier instanceof JavaTypeParameter) {
|
||||
return substitute((JavaTypeParameter) classifier);
|
||||
if (classifier instanceof JavaTypeParameterImpl) {
|
||||
return substitute((JavaTypeParameterImpl) classifier);
|
||||
}
|
||||
else if (classifier instanceof JavaClassImpl) {
|
||||
JavaClassImpl javaClass = (JavaClassImpl) classifier;
|
||||
Map<JavaTypeParameter, JavaType> substMap = new HashMap<JavaTypeParameter, JavaType>();
|
||||
processClass(javaClass, ((JavaClassifierTypeImpl) classifierType).getSubstitutor(), substMap);
|
||||
Map<JavaTypeParameterImpl, JavaTypeImpl<?>> substMap = new HashMap<JavaTypeParameterImpl, JavaTypeImpl<?>>();
|
||||
processClass(javaClass, classifierType.getSubstitutor(), substMap);
|
||||
|
||||
return javaClass.createImmediateType(new JavaTypeSubstitutorImpl(substMap));
|
||||
return javaClass.createImmediateType(substMap);
|
||||
}
|
||||
|
||||
return type;
|
||||
@@ -75,52 +79,50 @@ public class JavaTypeSubstitutorImpl {
|
||||
else if (type instanceof JavaPrimitiveType) {
|
||||
return type;
|
||||
}
|
||||
else if (type instanceof JavaArrayType) {
|
||||
JavaType componentType = ((JavaArrayType) type).getComponentType();
|
||||
JavaType substitutedComponentType = substitute(componentType);
|
||||
else if (type instanceof JavaArrayTypeImpl) {
|
||||
JavaTypeImpl<?> componentType = ((JavaArrayTypeImpl) type).getComponentType();
|
||||
JavaTypeImpl<?> substitutedComponentType = substitute(componentType);
|
||||
if (substitutedComponentType == componentType) return type;
|
||||
|
||||
return substitutedComponentType.createArrayType();
|
||||
return new JavaArrayTypeImpl(substitutedComponentType.getPsi().createArrayType());
|
||||
}
|
||||
else if (type instanceof JavaWildcardType) {
|
||||
return substituteWildcardType((JavaWildcardType) type);
|
||||
else if (type instanceof JavaWildcardTypeImpl) {
|
||||
return substituteWildcardType((JavaWildcardTypeImpl) type);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
private void processClass(
|
||||
@NotNull JavaClass javaClass, @NotNull JavaTypeSubstitutorImpl substitutor, @NotNull Map<JavaTypeParameter, JavaType> substMap
|
||||
@NotNull JavaClassImpl javaClass,
|
||||
@NotNull JavaTypeSubstitutorImpl substitutor,
|
||||
@NotNull Map<JavaTypeParameterImpl, JavaTypeImpl<?>> substMap
|
||||
) {
|
||||
List<JavaTypeParameter> typeParameters = javaClass.getTypeParameters();
|
||||
for (JavaTypeParameter typeParameter : typeParameters) {
|
||||
JavaType substitutedParam = substitutor.substitute(typeParameter);
|
||||
if (substitutedParam == null) {
|
||||
substMap.put(typeParameter, null);
|
||||
}
|
||||
else {
|
||||
substMap.put(typeParameter, substituteInternal(substitutedParam));
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
List<JavaTypeParameterImpl> typeParameters = (List) javaClass.getTypeParameters();
|
||||
for (JavaTypeParameterImpl typeParameter : typeParameters) {
|
||||
JavaTypeImpl<?> substitutedParam = substitutor.substitute(typeParameter);
|
||||
substMap.put(typeParameter, substitutedParam == null ? null : substituteInternal(substitutedParam));
|
||||
}
|
||||
|
||||
if (javaClass.isStatic()) {
|
||||
return;
|
||||
}
|
||||
|
||||
JavaClass outerClass = javaClass.getOuterClass();
|
||||
JavaClassImpl outerClass = javaClass.getOuterClass();
|
||||
if (outerClass != null) {
|
||||
processClass(outerClass, substitutor, substMap);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JavaType substituteWildcardType(@NotNull JavaWildcardType wildcardType) {
|
||||
JavaType bound = wildcardType.getBound();
|
||||
private JavaTypeImpl<?> substituteWildcardType(@NotNull JavaWildcardTypeImpl wildcardType) {
|
||||
JavaTypeImpl<?> bound = wildcardType.getBound();
|
||||
if (bound == null) {
|
||||
return wildcardType;
|
||||
}
|
||||
|
||||
JavaType newBound = substituteInternal(bound);
|
||||
JavaTypeImpl<?> newBound = substituteInternal(bound);
|
||||
if (newBound == null) {
|
||||
// This can be in case of substitution wildcard to raw type
|
||||
return null;
|
||||
@@ -130,41 +132,40 @@ public class JavaTypeSubstitutorImpl {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JavaWildcardType rebound(@NotNull JavaWildcardType type, @NotNull JavaType newBound) {
|
||||
if (type.getTypeProvider().createJavaLangObjectType().equals(newBound)) {
|
||||
return type.getTypeProvider().createUnboundedWildcard();
|
||||
private static JavaWildcardTypeImpl rebound(@NotNull JavaWildcardTypeImpl type, @NotNull JavaTypeImpl<?> newBound) {
|
||||
PsiManager manager = type.getPsi().getManager();
|
||||
if (createJavaLangObjectType(manager).equals(newBound)) {
|
||||
return createUnboundedWildcard(manager);
|
||||
}
|
||||
|
||||
if (type.isExtends()) {
|
||||
return type.getTypeProvider().createUpperBoundWildcard(newBound);
|
||||
return createUpperBoundWildcard(manager, newBound);
|
||||
}
|
||||
else {
|
||||
return type.getTypeProvider().createLowerBoundWildcard(newBound);
|
||||
return createLowerBoundWildcard(manager, newBound);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JavaType rawTypeForTypeParameter(@NotNull JavaTypeParameter typeParameter) {
|
||||
private JavaTypeImpl<?> rawTypeForTypeParameter(@NotNull JavaTypeParameterImpl typeParameter) {
|
||||
Collection<JavaClassifierType> bounds = typeParameter.getUpperBounds();
|
||||
if (!bounds.isEmpty()) {
|
||||
return substitute(bounds.iterator().next());
|
||||
return substitute(((JavaClassifierTypeImpl) bounds.iterator().next()));
|
||||
}
|
||||
|
||||
return typeParameter.getTypeProvider().createJavaLangObjectType();
|
||||
return createJavaLangObjectType(typeParameter.getPsi().getManager());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JavaType substitute(@NotNull JavaTypeParameter typeParameter) {
|
||||
public JavaTypeImpl<?> substitute(@NotNull JavaTypeParameterImpl typeParameter) {
|
||||
if (substitutionMap.containsKey(typeParameter)) {
|
||||
return substitutionMap.get(typeParameter);
|
||||
}
|
||||
|
||||
return typeParameter.getType();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Map<JavaTypeParameter, JavaType> getSubstitutionMap() {
|
||||
return substitutionMap;
|
||||
PsiTypeParameter psiTypeParameter = typeParameter.getPsi();
|
||||
return JavaTypeImpl.create(
|
||||
JavaPsiFacade.getInstance(psiTypeParameter.getProject()).getElementFactory().createType(psiTypeParameter)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -181,4 +182,24 @@ public class JavaTypeSubstitutorImpl {
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + ": " + substitutionMap;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JavaTypeImpl<?> createJavaLangObjectType(@NotNull PsiManager manager) {
|
||||
return JavaTypeImpl.create(PsiType.getJavaLangObject(manager, GlobalSearchScope.allScope(manager.getProject())));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JavaWildcardTypeImpl createUpperBoundWildcard(@NotNull PsiManager manager, @NotNull JavaTypeImpl<?> bound) {
|
||||
return new JavaWildcardTypeImpl(PsiWildcardType.createExtends(manager, bound.getPsi()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JavaWildcardTypeImpl createLowerBoundWildcard(@NotNull PsiManager manager, @NotNull JavaTypeImpl<?> bound) {
|
||||
return new JavaWildcardTypeImpl(PsiWildcardType.createSuper(manager, bound.getPsi()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JavaWildcardTypeImpl createUnboundedWildcard(@NotNull PsiManager manager) {
|
||||
return new JavaWildcardTypeImpl(PsiWildcardType.createUnbounded(manager));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-9
@@ -20,8 +20,6 @@ import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.PsiWildcardType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaType;
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaTypeProvider;
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaWildcardType;
|
||||
|
||||
public class JavaWildcardTypeImpl extends JavaTypeImpl<PsiWildcardType> implements JavaWildcardType {
|
||||
@@ -31,7 +29,7 @@ public class JavaWildcardTypeImpl extends JavaTypeImpl<PsiWildcardType> implemen
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public JavaType getBound() {
|
||||
public JavaTypeImpl<?> getBound() {
|
||||
PsiType bound = getPsi().getBound();
|
||||
return bound == null ? null : create(bound);
|
||||
}
|
||||
@@ -40,10 +38,4 @@ public class JavaWildcardTypeImpl extends JavaTypeImpl<PsiWildcardType> implemen
|
||||
public boolean isExtends() {
|
||||
return getPsi().isExtends();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JavaTypeProvider getTypeProvider() {
|
||||
return new JavaTypeProviderImpl(getPsi().getManager());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user