KT-656 Convert java.lang.Iterable with full qualified name
This commit is contained in:
@@ -286,7 +286,7 @@ public class Converter {
|
||||
@NotNull
|
||||
private static Function methodToFunction(@NotNull PsiMethod method, boolean notEmpty) {
|
||||
final IdentifierImpl identifier = new IdentifierImpl(method.getName());
|
||||
final Type type = typeToType(method.getReturnType());
|
||||
final Type returnType = typeToType(method.getReturnType());
|
||||
final Block body = blockToBlock(method.getBody(), notEmpty);
|
||||
final Element params = elementToElement(method.getParameterList());
|
||||
final List<Element> typeParameters = elementsToElementList(method.getTypeParameters());
|
||||
@@ -307,7 +307,7 @@ public class Converter {
|
||||
return new Constructor(
|
||||
identifier,
|
||||
modifiers,
|
||||
type,
|
||||
returnType,
|
||||
typeParameters,
|
||||
params,
|
||||
new Block(removeEmpty(body.getStatements()), false),
|
||||
@@ -317,7 +317,7 @@ public class Converter {
|
||||
return new Function(
|
||||
identifier,
|
||||
modifiers,
|
||||
type,
|
||||
returnType,
|
||||
typeParameters,
|
||||
params,
|
||||
body
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.ast.*;
|
||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -46,12 +47,9 @@ public class TypeVisitor extends PsiTypeVisitor<Type> {
|
||||
|
||||
@Override
|
||||
public Type visitClassType(PsiClassType classType) {
|
||||
String classTypeName = createQualifiedName(classType);
|
||||
if (classTypeName.isEmpty())
|
||||
classTypeName = getClassTypeName(classType);
|
||||
List<Type> resolvedClassTypeParams = createRawTypesForResolvedReference(classType);
|
||||
final IdentifierImpl identifier = constructClassTypeIdentifier(classType);
|
||||
final List<Type> resolvedClassTypeParams = createRawTypesForResolvedReference(classType);
|
||||
|
||||
final IdentifierImpl identifier = new IdentifierImpl(classTypeName);
|
||||
if (classType.getParameterCount() == 0 && resolvedClassTypeParams.size() > 0)
|
||||
myResult = new ClassType(identifier, resolvedClassTypeParams);
|
||||
else
|
||||
@@ -59,6 +57,26 @@ public class TypeVisitor extends PsiTypeVisitor<Type> {
|
||||
return super.visitClassType(classType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static IdentifierImpl constructClassTypeIdentifier(@NotNull PsiClassType classType) {
|
||||
final PsiClass psiClass = classType.resolve();
|
||||
if (psiClass != null) {
|
||||
String qualifiedName = psiClass.getQualifiedName();
|
||||
if (qualifiedName != null) {
|
||||
if (qualifiedName.equals("java.lang.Iterable"))
|
||||
return new IdentifierImpl("java.lang.Iterable");
|
||||
if (qualifiedName.equals("java.util.Iterator"))
|
||||
return new IdentifierImpl("java.util.Iterator");
|
||||
}
|
||||
}
|
||||
final String classTypeName = createQualifiedName(classType);
|
||||
|
||||
if (classTypeName.isEmpty())
|
||||
return new IdentifierImpl(getClassTypeName(classType));
|
||||
|
||||
return new IdentifierImpl(classTypeName);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String createQualifiedName(@NotNull PsiClassType classType) {
|
||||
String classTypeName = "";
|
||||
@@ -136,3 +154,15 @@ public class TypeVisitor extends PsiTypeVisitor<Type> {
|
||||
return super.visitDisjunctionType(disjunctionType);
|
||||
}
|
||||
}
|
||||
|
||||
class Test implements Iterable<String> {
|
||||
@Override
|
||||
public Iterator<String> iterator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Iterator<String> push(Iterator<String> i) {
|
||||
Iterator<String> j = i;
|
||||
return j;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package demo;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
class Test implements Iterable<String> {
|
||||
@Override
|
||||
public Iterator<String> iterator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Iterator<String> push(Iterator<String> i) {
|
||||
Iterator<String> j = i;
|
||||
return j;
|
||||
}
|
||||
}
|
||||
|
||||
class FullTest implements java.lang.Iterable<String> {
|
||||
@Override
|
||||
public java.util.Iterator<String> iterator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public java.util.Iterator<String> push(java.util.Iterator<String> i) {
|
||||
java.util.Iterator<String> j = i;
|
||||
return j;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace demo
|
||||
import java.util.Iterator
|
||||
open class Test() : java.lang.Iterable<String?> {
|
||||
override public fun iterator() : java.util.Iterator<String?>? {
|
||||
return null
|
||||
}
|
||||
open public fun push(i : java.util.Iterator<String?>?) : java.util.Iterator<String?>? {
|
||||
var j : java.util.Iterator<String?>? = i
|
||||
return j
|
||||
}
|
||||
}
|
||||
open class FullTest() : java.lang.Iterable<String?> {
|
||||
override public fun iterator() : java.util.Iterator<String?>? {
|
||||
return null
|
||||
}
|
||||
open public fun push(i : java.util.Iterator<String?>?) : java.util.Iterator<String?>? {
|
||||
var j : java.util.Iterator<String?>? = i
|
||||
return j
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user