Delete JavaTypeSubstitutorImpl, use PsiSubstitutor in JavaClassImpl

Also delete related tests
This commit is contained in:
Alexander Udalov
2016-03-17 18:25:57 +03:00
parent 291c713d8b
commit 0ba0e2b10d
51 changed files with 14 additions and 1102 deletions
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.load.java.structure.impl;
import com.intellij.psi.*;
import com.intellij.psi.impl.PsiSubstitutorImpl;
import kotlin.collections.ArraysKt;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
@@ -29,9 +28,7 @@ import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.Name;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.jetbrains.kotlin.load.java.structure.impl.JavaElementCollectionFromPsiArrayUtil.*;
@@ -169,27 +166,6 @@ public class JavaClassImpl extends JavaClassifierImpl<PsiClass> implements JavaC
}
}
@NotNull
/* package */ JavaTypeImpl<?> createImmediateType(@NotNull Map<JavaTypeParameterImpl, JavaTypeImpl<?>> substitutionMap) {
return new JavaClassifierTypeImpl(
JavaPsiFacade.getElementFactory(getPsi().getProject()).createType(getPsi(), createPsiSubstitutor(substitutionMap))
);
}
@NotNull
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(result);
}
@Nullable
@Override
public PsiAnnotationOwner getAnnotationOwnerPsi() {
@@ -22,15 +22,17 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.load.java.structure.JavaClassifierType;
import org.jetbrains.kotlin.load.java.structure.JavaType;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class JavaClassifierTypeImpl extends JavaTypeImpl<PsiClassType> implements JavaClassifierType {
private static class ResolutionResult {
private final JavaClassifierImpl<?> classifier;
private final JavaTypeSubstitutorImpl substitutor;
private final PsiSubstitutor substitutor;
private final boolean isRaw;
private ResolutionResult(@Nullable JavaClassifierImpl<?> classifier, @NotNull JavaTypeSubstitutorImpl substitutor, boolean isRaw) {
private ResolutionResult(@Nullable JavaClassifierImpl<?> classifier, @NotNull PsiSubstitutor substitutor, boolean isRaw) {
this.classifier = classifier;
this.substitutor = substitutor;
this.isRaw = isRaw;
@@ -51,7 +53,7 @@ public class JavaClassifierTypeImpl extends JavaTypeImpl<PsiClassType> implement
}
@NotNull
public JavaTypeSubstitutorImpl getSubstitutor() {
public PsiSubstitutor getSubstitutor() {
resolve();
return resolutionResult.substitutor;
}
@@ -62,26 +64,11 @@ public class JavaClassifierTypeImpl extends JavaTypeImpl<PsiClassType> implement
PsiClass psiClass = result.getElement();
PsiSubstitutor substitutor = result.getSubstitutor();
resolutionResult = new ResolutionResult(
psiClass == null ? null : JavaClassifierImpl.create(psiClass),
new JavaTypeSubstitutorImpl(convertSubstitutionMap(substitutor.getSubstitutionMap())),
PsiClassType.isRaw(result)
psiClass == null ? null : JavaClassifierImpl.create(psiClass), substitutor, PsiClassType.isRaw(result)
);
}
}
@NotNull
private static Map<JavaTypeParameterImpl, JavaTypeImpl<?>> convertSubstitutionMap(@NotNull Map<PsiTypeParameter, PsiType> psiMap) {
if (psiMap.isEmpty()) return Collections.emptyMap();
Map<JavaTypeParameterImpl, JavaTypeImpl<?>> result = new HashMap<JavaTypeParameterImpl, JavaTypeImpl<?>>();
for (Map.Entry<PsiTypeParameter, PsiType> entry : psiMap.entrySet()) {
PsiType value = entry.getValue();
result.put(new JavaTypeParameterImpl(entry.getKey()), value == null ? null : JavaTypeImpl.create(value));
}
return result;
}
@Override
@NotNull
public String getPresentableText() {
@@ -98,17 +85,17 @@ public class JavaClassifierTypeImpl extends JavaTypeImpl<PsiClassType> implement
@NotNull
public List<JavaType> getTypeArguments() {
JavaClassifierImpl<?> classifier = getClassifier();
if (!(classifier instanceof JavaClassImpl)) return Collections.emptyList();
// parameters including ones from outer class
Iterable<PsiTypeParameter> parameters = classifier instanceof JavaClassImpl
? getTypeParameters(classifier.getPsi())
: Collections.<PsiTypeParameter>emptyList();
List<PsiTypeParameter> parameters = getTypeParameters(classifier.getPsi());
JavaTypeSubstitutorImpl substitutor = getSubstitutor();
PsiSubstitutor substitutor = getSubstitutor();
List<JavaType> result = new ArrayList<JavaType>();
List<JavaType> result = new ArrayList<JavaType>(parameters.size());
for (PsiTypeParameter typeParameter : parameters) {
result.add(substitutor.substitute(new JavaTypeParameterImpl(typeParameter)));
PsiType substitutedType = substitutor.substitute(typeParameter);
result.add(substitutedType == null ? null : JavaTypeImpl.create(substitutedType));
}
return result;
@@ -124,7 +111,7 @@ public class JavaClassifierTypeImpl extends JavaTypeImpl<PsiClassType> implement
// PsiUtil.typeParametersIterable returns H3, H2, H1
// But we would like to have H2, H3, H1 as such order is consistent with our type representation
@NotNull
public static List<PsiTypeParameter> getTypeParameters(@NotNull PsiClass owner) {
private static List<PsiTypeParameter> getTypeParameters(@NotNull PsiClass owner) {
List<PsiTypeParameter> result = null;
PsiTypeParameterListOwner currentOwner = owner;
@@ -88,14 +88,6 @@ public class JavaElementCollectionFromPsiArrayUtil {
}
};
private static final Factory<PsiType, JavaType> TYPES = new Factory<PsiType, JavaType>() {
@NotNull
@Override
public JavaType create(@NotNull PsiType psiType) {
return JavaTypeImpl.create(psiType);
}
};
private static final Factory<PsiClassType, JavaClassifierType> CLASSIFIER_TYPES = new Factory<PsiClassType, JavaClassifierType>() {
@NotNull
@Override
@@ -192,11 +184,6 @@ public class JavaElementCollectionFromPsiArrayUtil {
return convert(typeParameters, Factories.TYPE_PARAMETERS);
}
@NotNull
public static List<JavaType> types(@NotNull PsiType[] types) {
return convert(types, Factories.TYPES);
}
@NotNull
public static Collection<JavaClassifierType> classifierTypes(@NotNull PsiClassType[] classTypes) {
return convert(classTypes, Factories.CLASSIFIER_TYPES);
@@ -1,205 +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.*;
import com.intellij.psi.search.GlobalSearchScope;
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.JavaPrimitiveType;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class JavaTypeSubstitutorImpl {
private final Map<JavaTypeParameterImpl, JavaTypeImpl<?>> substitutionMap;
public JavaTypeSubstitutorImpl(@NotNull Map<JavaTypeParameterImpl, JavaTypeImpl<?>> substitutionMap) {
this.substitutionMap = substitutionMap;
}
@NotNull
public JavaTypeImpl<?> substitute(@NotNull JavaTypeImpl<?> type) {
JavaTypeImpl<?> substitutedType = substituteInternal(type);
return substitutedType != null ? substitutedType : correctSubstitutionForRawType(type);
}
@NotNull
// 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 JavaTypeImpl<?> correctSubstitutionForRawType(@NotNull JavaTypeImpl<?> original) {
if (original instanceof JavaClassifierType) {
JavaClassifier classifier = ((JavaClassifierType) original).getClassifier();
if (classifier instanceof JavaTypeParameterImpl) {
return rawTypeForTypeParameter((JavaTypeParameterImpl) classifier);
}
}
return original;
}
@Nullable
private JavaTypeImpl<?> substituteInternal(@NotNull JavaTypeImpl<?> type) {
if (type instanceof JavaClassifierTypeImpl) {
JavaClassifierTypeImpl classifierType = (JavaClassifierTypeImpl) type;
JavaClassifierImpl<?> classifier = classifierType.getClassifier();
if (classifier instanceof JavaTypeParameterImpl) {
return substitute((JavaTypeParameterImpl) classifier);
}
else if (classifier instanceof JavaClassImpl) {
JavaClassImpl javaClass = (JavaClassImpl) classifier;
Map<JavaTypeParameterImpl, JavaTypeImpl<?>> substMap = new HashMap<JavaTypeParameterImpl, JavaTypeImpl<?>>();
processClass(javaClass, classifierType.getSubstitutor(), substMap);
return javaClass.createImmediateType(substMap);
}
return type;
}
else if (type instanceof JavaPrimitiveType) {
return type;
}
else if (type instanceof JavaArrayTypeImpl) {
JavaTypeImpl<?> componentType = ((JavaArrayTypeImpl) type).getComponentType();
JavaTypeImpl<?> substitutedComponentType = substitute(componentType);
if (substitutedComponentType == componentType) return type;
return new JavaArrayTypeImpl(substitutedComponentType.getPsi().createArrayType());
}
else if (type instanceof JavaWildcardTypeImpl) {
return substituteWildcardType((JavaWildcardTypeImpl) type);
}
return type;
}
private void processClass(
@NotNull JavaClassImpl javaClass,
@NotNull JavaTypeSubstitutorImpl substitutor,
@NotNull Map<JavaTypeParameterImpl, JavaTypeImpl<?>> substMap
) {
@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;
}
JavaClassImpl outerClass = javaClass.getOuterClass();
if (outerClass != null) {
processClass(outerClass, substitutor, substMap);
}
}
@Nullable
private JavaTypeImpl<?> substituteWildcardType(@NotNull JavaWildcardTypeImpl wildcardType) {
JavaTypeImpl<?> bound = wildcardType.getBound();
if (bound == null) {
return wildcardType;
}
JavaTypeImpl<?> newBound = substituteInternal(bound);
if (newBound == null) {
// This can be in case of substitution wildcard to raw type
return null;
}
return rebound(wildcardType, newBound);
}
@NotNull
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 createUpperBoundWildcard(manager, newBound);
}
else {
return createLowerBoundWildcard(manager, newBound);
}
}
@NotNull
private JavaTypeImpl<?> rawTypeForTypeParameter(@NotNull JavaTypeParameterImpl typeParameter) {
Collection<JavaClassifierType> bounds = typeParameter.getUpperBounds();
if (!bounds.isEmpty()) {
return substitute(((JavaClassifierTypeImpl) bounds.iterator().next()));
}
return createJavaLangObjectType(typeParameter.getPsi().getManager());
}
@Nullable
public JavaTypeImpl<?> substitute(@NotNull JavaTypeParameterImpl typeParameter) {
if (substitutionMap.containsKey(typeParameter)) {
return substitutionMap.get(typeParameter);
}
PsiTypeParameter psiTypeParameter = typeParameter.getPsi();
return JavaTypeImpl.create(
JavaPsiFacade.getInstance(psiTypeParameter.getProject()).getElementFactory().createType(psiTypeParameter)
);
}
@Override
public int hashCode() {
return substitutionMap.hashCode();
}
@Override
public boolean equals(Object obj) {
return obj instanceof JavaTypeSubstitutorImpl && substitutionMap.equals(((JavaTypeSubstitutorImpl) obj).substitutionMap);
}
@Override
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));
}
}
@@ -119,7 +119,6 @@ import org.jetbrains.kotlin.jvm.runtime.AbstractJvmRuntimeDescriptorLoaderTest
import org.jetbrains.kotlin.lang.resolve.android.test.AbstractAndroidBoxTest
import org.jetbrains.kotlin.lang.resolve.android.test.AbstractAndroidBytecodeShapeTest
import org.jetbrains.kotlin.lang.resolve.android.test.AbstractAndroidSyntheticPropertyDescriptorTest
import org.jetbrains.kotlin.load.java.AbstractJavaTypeSubstitutorTest
import org.jetbrains.kotlin.modules.xml.AbstractModuleXmlParserTest
import org.jetbrains.kotlin.parsing.AbstractParsingTest
import org.jetbrains.kotlin.psi.patternMatching.AbstractPsiUnifierTest
@@ -359,11 +358,6 @@ fun main(args: Array<String>) {
testGroup("idea/tests", "idea/testData") {
testClass<AbstractJavaTypeSubstitutorTest>() {
model("typeSubstitution", extension = "java")
}
testClass<AbstractAdditionalResolveDescriptorRendererTest>() {
model("resolve/additionalLazyResolve")
}
-8
View File
@@ -1,8 +0,0 @@
interface arrayType {
interface SuperArray<T> {
T[] typeForSubstitute();
}
interface MidArray extends SuperArray<Integer> {
}
}
-8
View File
@@ -1,8 +0,0 @@
interface classType {
interface SuperClass<T> {
List<Integer> typeForSubstitute();
}
interface MidClass extends SuperClass {
}
}
-10
View File
@@ -1,10 +0,0 @@
import java.util.*;
interface classWithWildcard {
interface SuperList<T> {
List<T> typeForSubstitute();
}
interface MidList<U> extends SuperList<List<? extends U>> {
}
}
-8
View File
@@ -1,8 +0,0 @@
interface genericArray {
interface SuperGenericArray<T> {
T typeForSubstitute();
}
interface MidGenericArray<T> extends SuperGenericArray<T[]> {
}
}
-10
View File
@@ -1,10 +0,0 @@
import java.util.*;
interface innerParameter {
interface SuperInnerParam<T> {
<T> T typeForSubstitute();
}
interface MidInnerParam<U> extends SuperInnerParam<U> {
}
}
-10
View File
@@ -1,10 +0,0 @@
import java.util.*;
interface intersectionType {
interface SuperIntersection<T> {
<R extends Enum<R> & List<T>> R typeForSubstitute();
}
interface MidIntersection<U> extends SuperIntersection<U> {
}
}
@@ -1,10 +0,0 @@
import java.util.*;
interface intersectionTypeAsTypeParameter {
interface Super<K> {
<T extends Enum<T> & List<K>> Map<? extends T, K> typeForSubstitute();
}
interface Sub<U> extends Super<U> {
}
}
@@ -1,10 +0,0 @@
import java.util.*;
interface intersectionTypeInEnum {
interface Super<T> {
<R extends Enum<R> & List<T>> Enum<R> typeForSubstitute();
}
interface Sub<U> extends Super<U> {
}
}
@@ -1,8 +0,0 @@
interface intersectionTypeInInterfaceDeclaration {
interface SuperIntersection<T extends Object & Cloneable> {
T typeForSubstitute();
}
interface MidIntersection<U extends Object & Cloneable> extends SuperIntersection<U> {
}
}
@@ -1,10 +0,0 @@
import java.util.*;
interface intersectionTypeInTypeVariableClass {
interface Super<T> {
<R extends Class<R> & List<T>> TypeVariable<R> typeForSubstitute();
}
interface Sub<U> extends Super<U> {
}
}
-10
View File
@@ -1,10 +0,0 @@
import java.util.Map;
interface mapEntry {
interface Super<T, E> {
Map.Entry<T, E> typeForSubstitute();
}
interface Mid<E> extends Super<E, Integer> {
}
}
-8
View File
@@ -1,8 +0,0 @@
interface primitiveType {
interface SuperPrimitive<T> {
int typeForSubstitute();
}
interface MidPrimitive extends SuperPrimitive<Integer> {
}
}
-8
View File
@@ -1,8 +0,0 @@
interface rawArrayType {
interface SuperArray<T> {
T[] typeForSubstitute();
}
interface MidArray extends SuperArray {
}
}
@@ -1,8 +0,0 @@
interface rawArrayTypeParameterWithBound {
interface Super<T extends Cloneable> {
T[] typeForSubstitute();
}
interface Sub extends Super {
}
}
-8
View File
@@ -1,8 +0,0 @@
interface rawEnum {
interface Super<T extends Enum<T>> {
Enum<T> typeForSubstitute();
}
interface Sub extends Super {
}
}
-10
View File
@@ -1,10 +0,0 @@
import java.util.*;
interface rawExtendsWildcard {
interface SuperRawWild<T> {
List<? extends T> typeForSubstitute();
}
interface MidRawWildcard extends SuperRawWild {
}
}
@@ -1,8 +0,0 @@
interface rawIntersectionType {
interface Super<T extends Integer & Cloneable> {
T typeForSubstitute();
}
interface Sub extends Super {
}
}
-10
View File
@@ -1,10 +0,0 @@
import java.util.*;
interface rawSuperWildcard {
interface SuperRawWild<T> {
List<? super T> typeForSubstitute();
}
interface MidRawWildcard extends SuperRawWild {
}
}
-8
View File
@@ -1,8 +0,0 @@
interface rawType {
interface Super<T> {
T typeForSubstitute();
}
interface MidRaw extends Super {
}
}
@@ -1,10 +0,0 @@
import java.util.*;
interface rawTypeInDeclaration {
interface Super<T> {
List typeForSubstitute();
}
interface Sub<U> extends Super<U> {
}
}
-8
View File
@@ -1,8 +0,0 @@
interface rawTypeWithBound {
interface Super<T extends Integer> {
T typeForSubstitute();
}
interface MidRaw extends Super {
}
}
@@ -1,8 +0,0 @@
interface rawTypeWithSelfReferenceBound {
interface Super<T extends Super<T>> {
T typeForSubstitute();
}
interface MidRaw extends Super {
}
}
@@ -1,10 +0,0 @@
import java.lang.reflect.TypeVariable;
interface rawWildcardInTypeVariableClass {
interface Super<T> {
TypeVariable<? super T> typeForSubstitute();
}
interface Sub extends Super {
}
}
@@ -1,10 +0,0 @@
import java.util.*;
interface rawWildcardWithBound {
interface Super<T extends Cloneable> {
List<? extends T> typeForSubstitute();
}
interface Sub extends Super {
}
}
-10
View File
@@ -1,10 +0,0 @@
import java.util.*;
interface selfReference {
interface SuperSelfRef<T extends SuperSelfRef<T>> {
public List<T> typeForSubstitute();
}
interface MidSelfRef extends SuperSelfRef<MidSelfRef> {
}
}
-10
View File
@@ -1,10 +0,0 @@
import java.util.*;
interface twoParameters {
interface SuperTwoParams<T, U> {
Map<T, List<U>> typeForSubstitute();
}
interface MidTwoParams<E> extends SuperTwoParams<Integer, E> {
}
}
@@ -1,10 +0,0 @@
import java.util.*;
interface twoParametersInSubClass {
interface SuperTwoParams<T> {
List<T> typeForSubstitute();
}
interface MidTwoParams<T, S> extends SuperTwoParams<S> {
}
}
-10
View File
@@ -1,10 +0,0 @@
import java.lang.reflect.TypeVariable;
interface typeVariableClass {
interface Super<T> {
TypeVariable<? super T> typeForSubstitute();
}
interface Mid<E> extends Super<E> {
}
}
-10
View File
@@ -1,10 +0,0 @@
import java.lang.reflect.TypeVariable;
interface typeVariableRaw {
interface Super<T extends Class> {
TypeVariable<T> typeForSubstitute();
}
interface Mid extends Super {
}
}
-10
View File
@@ -1,10 +0,0 @@
import java.util.*;
interface unboundedWildcard {
interface Super<T> {
List<?> typeForSubstitute();
}
interface Sub extends Super<Integer> {
}
}
@@ -1,8 +0,0 @@
import java.util.*;
interface unboundedWildcardToTypeParameter {
interface SupList<K> extends List<K> {
@Override
boolean retainAll(Collection<K> c); // error, check that we do not fall
}
}
-10
View File
@@ -1,10 +0,0 @@
import java.util.*;
interface varargArray {
interface Super<T> {
void typeForSubstitute(T... a);
}
interface Sub<Integer> extends Super<Integer[]> {
}
}
@@ -1,10 +0,0 @@
import java.util.*;
interface varargArrayTypeParameter {
interface Super<T> {
void typeForSubstitute(T... a);
}
interface Sub<E> extends Super<E[]> {
}
}
-10
View File
@@ -1,10 +0,0 @@
import java.util.*;
interface varargClass {
interface Super<T> {
void typeForSubstitute(List<T>... a);
}
interface Sub extends Super<Integer> {
}
}
@@ -1,10 +0,0 @@
import java.util.*;
interface varargClassWithWildcard {
interface Super<T> {
void typeForSubstitute(List<? extends T>... a);
}
interface Sub<E> extends Super<List<? extends E>> {
}
}
-10
View File
@@ -1,10 +0,0 @@
import java.util.*;
interface varargRawType {
interface Super<T> {
void typeForSubstitute(T... a);
}
interface Sub extends Super {
}
}
@@ -1,10 +0,0 @@
import java.util.*;
interface varargRawTypeWithBound {
interface Super<T extends Integer> {
void typeForSubstitute(T... a);
}
interface Sub<E> extends Super {
}
}
-10
View File
@@ -1,10 +0,0 @@
import java.util.*;
interface varargToClass {
interface Super<T> {
void typeForSubstitute(T... a);
}
interface Sub extends Super<Integer> {
}
}
@@ -1,10 +0,0 @@
import java.util.*;
interface varargToClassWithWildcard {
interface Super<T> {
void typeForSubstitute(T... a);
}
interface Sub<E> extends Super<List<? extends E>> {
}
}
-10
View File
@@ -1,10 +0,0 @@
import java.util.*;
interface wildcardExtends {
interface SuperWildcardExtends<T> {
List<? extends T> typeForSubstitute();
}
interface MidWildcardExtends extends SuperWildcardExtends<Integer> {
}
}
@@ -1,10 +0,0 @@
import java.util.*;
interface wildcardExtendsObject {
interface SuperWildcardExtendsObject<T> {
List<? extends T> typeForSubstitute();
}
interface MidWildcardExtendsObject extends SuperWildcardExtendsObject<Object> {
}
}
@@ -1,10 +0,0 @@
import java.util.*;
interface wildcardExtendsTypeParameter {
interface SuperWildcard<T, U> {
Map<? extends T, ? extends U> typeForSubstitute();
}
interface MidWildcard<E, K> extends SuperWildcard<E, K> {
}
}
-10
View File
@@ -1,10 +0,0 @@
import java.util.*;
interface wildcardSuper {
interface SuperWildcardSuper<T> {
List<? extends T> typeForSubstitute();
}
interface MidWildcardSuper extends SuperWildcardSuper<Integer> {
}
}
@@ -1,8 +0,0 @@
import java.util.*;
interface wildcardToWildcard {
interface SupList<K> extends List<K> {
@Override
boolean addAll(Collection<? extends K> c);
}
}
@@ -1,114 +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;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.testFramework.LightProjectDescriptor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase;
import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor;
import org.jetbrains.kotlin.load.java.structure.JavaType;
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.JavaTypeParameterImpl;
public abstract class AbstractJavaTypeSubstitutorTest extends KotlinLightCodeInsightFixtureTestCase {
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return KotlinLightProjectDescriptor.INSTANCE;
}
public void doTest(@NotNull String testFile) {
PsiFile psiFile = myFixture.configureByFile(testFile);
Project project = myFixture.getProject();
String javaClassName = psiFile.getName().substring(0, psiFile.getName().length() - ".java".length());
PsiClass psiClass = JavaPsiFacade.getInstance(project).findClass(javaClassName, GlobalSearchScope.allScope(project));
assert psiClass != null : "Wrong path to test file: " + testFile;
assert psiClass.getInnerClasses().length > 0;
for (PsiClass innerInterface : psiClass.getInnerClasses()) {
PsiMethod method = getMethodWithTestData(innerInterface);
PsiClassType[] superTypes = innerInterface.getSuperTypes();
for (PsiClassType superType : superTypes) {
if (method.getReturnType() != null) {
doTest(superType, method.getReturnType());
}
if (method.getTypeParameters().length > 0) {
doTest(superType, method.getTypeParameters()[0]);
}
PsiParameter[] parameters = method.getParameterList().getParameters();
if (parameters.length > 0) {
doTest(superType, parameters[0].getType());
}
}
}
}
private static void doTest(@NotNull PsiClassType type, @NotNull PsiTypeParameter typeParameter) {
PsiType expectedType = type.resolveGenerics().getSubstitutor().substitute(typeParameter);
JavaClassifierTypeImpl javaClassifierType = (JavaClassifierTypeImpl) JavaTypeImpl.create(type);
JavaTypeParameterImpl javaTypeToSubstitute = new JavaTypeParameterImpl(typeParameter);
JavaType actualType = javaClassifierType.getSubstitutor().substitute(javaTypeToSubstitute);
if (actualType == null) {
assertEquals(expectedType, null);
}
else {
assertEquals(expectedType, ((JavaTypeImpl) actualType).getPsi());
}
}
private static void doTest(@NotNull PsiClassType type, @NotNull PsiType psiTypeToSubstitute) {
PsiType expectedType = type.resolveGenerics().getSubstitutor().substitute(psiTypeToSubstitute);
JavaClassifierTypeImpl javaClassifierType = (JavaClassifierTypeImpl) JavaTypeImpl.create(type);
JavaTypeImpl<?> javaTypeToSubstitute = JavaTypeImpl.create(psiTypeToSubstitute);
JavaType actualType = javaClassifierType.getSubstitutor().substitute(javaTypeToSubstitute);
if (expectedType instanceof PsiEllipsisType) {
PsiEllipsisType ellipsisType = (PsiEllipsisType) expectedType;
assertEquals(ellipsisType.toArrayType(), ((JavaTypeImpl) actualType).getPsi());
}
else {
assertEquals(expectedType, ((JavaTypeImpl) actualType).getPsi());
}
}
@NotNull
private static PsiMethod getMethodWithTestData(@NotNull PsiClass psiClass) {
String substituteParameterName = "typeForSubstitute";
PsiMethod[] methods = psiClass.findMethodsByName(substituteParameterName, false);
if (methods.length == 0) {
methods = psiClass.findMethodsByName(substituteParameterName, true);
}
if (methods.length == 0) {
methods = psiClass.getMethods();
}
assert methods.length > 0 : "Wrong parameters for test: method typeForSubstitute not found";
return methods[0];
}
}
@@ -1,301 +0,0 @@
/*
* Copyright 2010-2016 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;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/typeSubstitution")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class JavaTypeSubstitutorTestGenerated extends AbstractJavaTypeSubstitutorTest {
public void testAllFilesPresentInTypeSubstitution() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/typeSubstitution"), Pattern.compile("^(.+)\\.java$"), true);
}
@TestMetadata("arrayType.java")
public void testArrayType() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/arrayType.java");
doTest(fileName);
}
@TestMetadata("classType.java")
public void testClassType() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/classType.java");
doTest(fileName);
}
@TestMetadata("classWithWildcard.java")
public void testClassWithWildcard() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/classWithWildcard.java");
doTest(fileName);
}
@TestMetadata("genericArray.java")
public void testGenericArray() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/genericArray.java");
doTest(fileName);
}
@TestMetadata("innerParameter.java")
public void testInnerParameter() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/innerParameter.java");
doTest(fileName);
}
@TestMetadata("intersectionType.java")
public void testIntersectionType() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/intersectionType.java");
doTest(fileName);
}
@TestMetadata("intersectionTypeAsTypeParameter.java")
public void testIntersectionTypeAsTypeParameter() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/intersectionTypeAsTypeParameter.java");
doTest(fileName);
}
@TestMetadata("intersectionTypeInEnum.java")
public void testIntersectionTypeInEnum() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/intersectionTypeInEnum.java");
doTest(fileName);
}
@TestMetadata("intersectionTypeInInterfaceDeclaration.java")
public void testIntersectionTypeInInterfaceDeclaration() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/intersectionTypeInInterfaceDeclaration.java");
doTest(fileName);
}
@TestMetadata("intersectionTypeInTypeVariableClass.java")
public void testIntersectionTypeInTypeVariableClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/intersectionTypeInTypeVariableClass.java");
doTest(fileName);
}
@TestMetadata("mapEntry.java")
public void testMapEntry() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/mapEntry.java");
doTest(fileName);
}
@TestMetadata("primitiveType.java")
public void testPrimitiveType() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/primitiveType.java");
doTest(fileName);
}
@TestMetadata("rawArrayType.java")
public void testRawArrayType() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/rawArrayType.java");
doTest(fileName);
}
@TestMetadata("rawArrayTypeParameterWithBound.java")
public void testRawArrayTypeParameterWithBound() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/rawArrayTypeParameterWithBound.java");
doTest(fileName);
}
@TestMetadata("rawEnum.java")
public void testRawEnum() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/rawEnum.java");
doTest(fileName);
}
@TestMetadata("rawExtendsWildcard.java")
public void testRawExtendsWildcard() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/rawExtendsWildcard.java");
doTest(fileName);
}
@TestMetadata("rawIntersectionType.java")
public void testRawIntersectionType() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/rawIntersectionType.java");
doTest(fileName);
}
@TestMetadata("rawSuperWildcard.java")
public void testRawSuperWildcard() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/rawSuperWildcard.java");
doTest(fileName);
}
@TestMetadata("rawType.java")
public void testRawType() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/rawType.java");
doTest(fileName);
}
@TestMetadata("rawTypeInDeclaration.java")
public void testRawTypeInDeclaration() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/rawTypeInDeclaration.java");
doTest(fileName);
}
@TestMetadata("rawTypeWithBound.java")
public void testRawTypeWithBound() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/rawTypeWithBound.java");
doTest(fileName);
}
@TestMetadata("rawTypeWithSelfReferenceBound.java")
public void testRawTypeWithSelfReferenceBound() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/rawTypeWithSelfReferenceBound.java");
doTest(fileName);
}
@TestMetadata("rawWildcardInTypeVariableClass.java")
public void testRawWildcardInTypeVariableClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/rawWildcardInTypeVariableClass.java");
doTest(fileName);
}
@TestMetadata("rawWildcardWithBound.java")
public void testRawWildcardWithBound() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/rawWildcardWithBound.java");
doTest(fileName);
}
@TestMetadata("selfReference.java")
public void testSelfReference() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/selfReference.java");
doTest(fileName);
}
@TestMetadata("twoParameters.java")
public void testTwoParameters() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/twoParameters.java");
doTest(fileName);
}
@TestMetadata("twoParametersInSubClass.java")
public void testTwoParametersInSubClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/twoParametersInSubClass.java");
doTest(fileName);
}
@TestMetadata("typeVariableClass.java")
public void testTypeVariableClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/typeVariableClass.java");
doTest(fileName);
}
@TestMetadata("typeVariableRaw.java")
public void testTypeVariableRaw() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/typeVariableRaw.java");
doTest(fileName);
}
@TestMetadata("unboundedWildcard.java")
public void testUnboundedWildcard() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/unboundedWildcard.java");
doTest(fileName);
}
@TestMetadata("unboundedWildcardToTypeParameter.java")
public void testUnboundedWildcardToTypeParameter() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/unboundedWildcardToTypeParameter.java");
doTest(fileName);
}
@TestMetadata("varargArray.java")
public void testVarargArray() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/varargArray.java");
doTest(fileName);
}
@TestMetadata("varargArrayTypeParameter.java")
public void testVarargArrayTypeParameter() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/varargArrayTypeParameter.java");
doTest(fileName);
}
@TestMetadata("varargClass.java")
public void testVarargClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/varargClass.java");
doTest(fileName);
}
@TestMetadata("varargClassWithWildcard.java")
public void testVarargClassWithWildcard() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/varargClassWithWildcard.java");
doTest(fileName);
}
@TestMetadata("varargRawType.java")
public void testVarargRawType() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/varargRawType.java");
doTest(fileName);
}
@TestMetadata("varargRawTypeWithBound.java")
public void testVarargRawTypeWithBound() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/varargRawTypeWithBound.java");
doTest(fileName);
}
@TestMetadata("varargToClass.java")
public void testVarargToClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/varargToClass.java");
doTest(fileName);
}
@TestMetadata("varargToClassWithWildcard.java")
public void testVarargToClassWithWildcard() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/varargToClassWithWildcard.java");
doTest(fileName);
}
@TestMetadata("wildcardExtends.java")
public void testWildcardExtends() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/wildcardExtends.java");
doTest(fileName);
}
@TestMetadata("wildcardExtendsObject.java")
public void testWildcardExtendsObject() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/wildcardExtendsObject.java");
doTest(fileName);
}
@TestMetadata("wildcardExtendsTypeParameter.java")
public void testWildcardExtendsTypeParameter() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/wildcardExtendsTypeParameter.java");
doTest(fileName);
}
@TestMetadata("wildcardSuper.java")
public void testWildcardSuper() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/wildcardSuper.java");
doTest(fileName);
}
@TestMetadata("wildcardToWildcard.java")
public void testWildcardToWildcard() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/typeSubstitution/wildcardToWildcard.java");
doTest(fileName);
}
}