KT-656 Convert java.lang.Iterable with full qualified name

This commit is contained in:
Sergey Ignatov
2011-11-29 13:41:07 +04:00
parent 876ba8736b
commit acc9d70dab
4 changed files with 85 additions and 8 deletions
+3 -3
View File
@@ -286,7 +286,7 @@ public class Converter {
@NotNull @NotNull
private static Function methodToFunction(@NotNull PsiMethod method, boolean notEmpty) { private static Function methodToFunction(@NotNull PsiMethod method, boolean notEmpty) {
final IdentifierImpl identifier = new IdentifierImpl(method.getName()); 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 Block body = blockToBlock(method.getBody(), notEmpty);
final Element params = elementToElement(method.getParameterList()); final Element params = elementToElement(method.getParameterList());
final List<Element> typeParameters = elementsToElementList(method.getTypeParameters()); final List<Element> typeParameters = elementsToElementList(method.getTypeParameters());
@@ -307,7 +307,7 @@ public class Converter {
return new Constructor( return new Constructor(
identifier, identifier,
modifiers, modifiers,
type, returnType,
typeParameters, typeParameters,
params, params,
new Block(removeEmpty(body.getStatements()), false), new Block(removeEmpty(body.getStatements()), false),
@@ -317,7 +317,7 @@ public class Converter {
return new Function( return new Function(
identifier, identifier,
modifiers, modifiers,
type, returnType,
typeParameters, typeParameters,
params, params,
body body
@@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.j2k.ast.*; import org.jetbrains.jet.j2k.ast.*;
import org.jetbrains.jet.j2k.util.AstUtil; import org.jetbrains.jet.j2k.util.AstUtil;
import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@@ -46,12 +47,9 @@ public class TypeVisitor extends PsiTypeVisitor<Type> {
@Override @Override
public Type visitClassType(PsiClassType classType) { public Type visitClassType(PsiClassType classType) {
String classTypeName = createQualifiedName(classType); final IdentifierImpl identifier = constructClassTypeIdentifier(classType);
if (classTypeName.isEmpty()) final List<Type> resolvedClassTypeParams = createRawTypesForResolvedReference(classType);
classTypeName = getClassTypeName(classType);
List<Type> resolvedClassTypeParams = createRawTypesForResolvedReference(classType);
final IdentifierImpl identifier = new IdentifierImpl(classTypeName);
if (classType.getParameterCount() == 0 && resolvedClassTypeParams.size() > 0) if (classType.getParameterCount() == 0 && resolvedClassTypeParams.size() > 0)
myResult = new ClassType(identifier, resolvedClassTypeParams); myResult = new ClassType(identifier, resolvedClassTypeParams);
else else
@@ -59,6 +57,26 @@ public class TypeVisitor extends PsiTypeVisitor<Type> {
return super.visitClassType(classType); 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 @NotNull
private static String createQualifiedName(@NotNull PsiClassType classType) { private static String createQualifiedName(@NotNull PsiClassType classType) {
String classTypeName = ""; String classTypeName = "";
@@ -136,3 +154,15 @@ public class TypeVisitor extends PsiTypeVisitor<Type> {
return super.visitDisjunctionType(disjunctionType); 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
}
}