types AST converted to Kotlin
This commit is contained in:
committed by
Pavel V. Talanov
parent
4a07263908
commit
112d64b228
@@ -24,6 +24,9 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jetbrains.jet.j2k.ast.*;
|
import org.jetbrains.jet.j2k.ast.*;
|
||||||
import org.jetbrains.jet.j2k.ast.Class;
|
import org.jetbrains.jet.j2k.ast.Class;
|
||||||
import org.jetbrains.jet.j2k.ast.Enum;
|
import org.jetbrains.jet.j2k.ast.Enum;
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.ClassType;
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.EmptyType;
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type;
|
||||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||||
import org.jetbrains.jet.j2k.visitors.*;
|
import org.jetbrains.jet.j2k.visitors.*;
|
||||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
||||||
@@ -295,7 +298,7 @@ public class Converter {
|
|||||||
new Constructor(
|
new Constructor(
|
||||||
Identifier.EMPTY_IDENTIFIER,
|
Identifier.EMPTY_IDENTIFIER,
|
||||||
Collections.<String>emptySet(),
|
Collections.<String>emptySet(),
|
||||||
new ClassType(name),
|
new ClassType(name, Collections.<Element>emptyList(), false),
|
||||||
Collections.<Element>emptyList(),
|
Collections.<Element>emptyList(),
|
||||||
new ParameterList(createParametersFromFields(finalOrWithEmptyInitializer)),
|
new ParameterList(createParametersFromFields(finalOrWithEmptyInitializer)),
|
||||||
new Block(createInitStatementsFromFields(finalOrWithEmptyInitializer)),
|
new Block(createInitStatementsFromFields(finalOrWithEmptyInitializer)),
|
||||||
@@ -323,7 +326,7 @@ public class Converter {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static String getDefaultInitializer(@NotNull Field f) {
|
public static String getDefaultInitializer(@NotNull Field f) {
|
||||||
if (f.getType().isNullable()) {
|
if (f.getType().getNullable()) {
|
||||||
return "null";
|
return "null";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -602,7 +605,7 @@ public class Converter {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Type typeToType(@Nullable PsiType type) {
|
public Type typeToType(@Nullable PsiType type) {
|
||||||
if (type == null) return Type.EMPTY_TYPE;
|
if (type == null) return new EmptyType();
|
||||||
TypeVisitor typeVisitor = new TypeVisitor(this);
|
TypeVisitor typeVisitor = new TypeVisitor(this);
|
||||||
type.accept(typeVisitor);
|
type.accept(typeVisitor);
|
||||||
return typeVisitor.getResult();
|
return typeVisitor.getResult();
|
||||||
@@ -619,15 +622,17 @@ public class Converter {
|
|||||||
public Type typeToType(PsiType type, boolean notNull) {
|
public Type typeToType(PsiType type, boolean notNull) {
|
||||||
Type result = typeToType(type);
|
Type result = typeToType(type);
|
||||||
if (notNull) {
|
if (notNull) {
|
||||||
result.convertedToNotNull();
|
return result.convertedToNotNull();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private List<Type> typesToNotNullableTypeList(@NotNull PsiType[] types) {
|
private List<Type> typesToNotNullableTypeList(@NotNull PsiType[] types) {
|
||||||
List<Type> result = new LinkedList<Type>(typesToTypeList(types));
|
List<Type> result = new ArrayList<Type>();
|
||||||
for (Type p : result) p.convertedToNotNull();
|
for (PsiType type : types) {
|
||||||
|
result.add(typeToType(type).convertedToNotNull());
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package org.jetbrains.jet.j2k.ast;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.j2k.Converter;
|
import org.jetbrains.jet.j2k.Converter;
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.jetbrains.jet.j2k.ast
|
package org.jetbrains.jet.j2k.ast
|
||||||
|
|
||||||
import org.jetbrains.jet.j2k.util.AstUtil
|
import org.jetbrains.jet.j2k.util.AstUtil
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type
|
||||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions
|
import org.jetbrains.jet.lang.types.expressions.OperatorConventions
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2012 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.jet.j2k.ast;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author ignatov
|
|
||||||
*/
|
|
||||||
public class ArrayType extends Type {
|
|
||||||
private final Type myType;
|
|
||||||
|
|
||||||
public ArrayType(Type type) {
|
|
||||||
myType = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Type getInnerType() {
|
|
||||||
return myType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Kind getKind() {
|
|
||||||
return Kind.ARRAY_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String toKotlin() {
|
|
||||||
if (PRIMITIVE_TYPES.contains(myType.toKotlin().toLowerCase())) {
|
|
||||||
return myType.toKotlin() + "Array" + isNullableStr(); // returns IntArray, BooleanArray, etc.
|
|
||||||
}
|
|
||||||
return "Array" + "<" + myType.toKotlin() + ">" + isNullableStr();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
package org.jetbrains.jet.j2k.ast
|
package org.jetbrains.jet.j2k.ast
|
||||||
|
|
||||||
import org.jetbrains.jet.j2k.util.AstUtil
|
import org.jetbrains.jet.j2k.util.AstUtil
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.ArrayType
|
||||||
import java.util.List
|
import java.util.List
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type
|
||||||
|
|
||||||
public open class ArrayWithoutInitializationExpression(val `type` : Type, val expressions : List<Expression>) : Expression() {
|
public open class ArrayWithoutInitializationExpression(val `type` : Type, val expressions : List<Expression>) : Expression() {
|
||||||
public override fun toKotlin() : String {
|
public override fun toKotlin() : String {
|
||||||
@@ -19,7 +21,7 @@ public open class ArrayWithoutInitializationExpression(val `type` : Type, val ex
|
|||||||
return oneDim(hostType, expressions[0])
|
return oneDim(hostType, expressions[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
var innerType : Type? = hostType.getInnerType()
|
var innerType : Type? = hostType.elementType
|
||||||
if (expressions.size() > 1 && innerType?.getKind() == INode.Kind.ARRAY_TYPE)
|
if (expressions.size() > 1 && innerType?.getKind() == INode.Kind.ARRAY_TYPE)
|
||||||
{
|
{
|
||||||
return oneDim(hostType, expressions[0], "{" + constructInnerType(innerType as ArrayType, expressions.subList(1, expressions.size())) + "}")
|
return oneDim(hostType, expressions[0], "{" + constructInnerType(innerType as ArrayType, expressions.subList(1, expressions.size())) + "}")
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.j2k.Converter;
|
import org.jetbrains.jet.j2k.Converter;
|
||||||
import org.jetbrains.jet.j2k.J2KConverterFlags;
|
import org.jetbrains.jet.j2k.J2KConverterFlags;
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.ClassType;
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type;
|
||||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -45,6 +47,9 @@ public class Class extends Member {
|
|||||||
public Class(Converter converter, Identifier name, Set<String> modifiers, List<Element> typeParameters, List<Type> extendsTypes,
|
public Class(Converter converter, Identifier name, Set<String> modifiers, List<Element> typeParameters, List<Type> extendsTypes,
|
||||||
List<Expression> baseClassParams, List<Type> implementsTypes, List<Member> members) {
|
List<Expression> baseClassParams, List<Type> implementsTypes, List<Member> members) {
|
||||||
super(modifiers);
|
super(modifiers);
|
||||||
|
if (extendsTypes.size() > 0) {
|
||||||
|
System.out.println("here");
|
||||||
|
}
|
||||||
myName = name;
|
myName = name;
|
||||||
myBaseClassParams = baseClassParams;
|
myBaseClassParams = baseClassParams;
|
||||||
myTypeParameters = typeParameters;
|
myTypeParameters = typeParameters;
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2012 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.jet.j2k.ast;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author ignatov
|
|
||||||
*/
|
|
||||||
public class ClassType extends Type {
|
|
||||||
private final Identifier myType;
|
|
||||||
private final List<? extends Element> myParameters;
|
|
||||||
|
|
||||||
public ClassType(Identifier type, List<? extends Element> parameters, boolean nullable) {
|
|
||||||
myType = type;
|
|
||||||
myParameters = parameters;
|
|
||||||
myNullable = nullable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ClassType(Identifier type, List<? extends Element> parameters) {
|
|
||||||
myType = type;
|
|
||||||
myParameters = parameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ClassType(Identifier type) {
|
|
||||||
myType = type;
|
|
||||||
myNullable = false;
|
|
||||||
myParameters = Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String toKotlin() {
|
|
||||||
String params = myParameters.size() == 0
|
|
||||||
? EMPTY
|
|
||||||
: "<" + AstUtil.joinNodes(myParameters, COMMA_WITH_SPACE) + ">";
|
|
||||||
return myType.toKotlin() + params + isNullableStr();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,7 @@ package org.jetbrains.jet.j2k.ast
|
|||||||
import java.util.List
|
import java.util.List
|
||||||
import java.util.Set
|
import java.util.Set
|
||||||
import org.jetbrains.jet.j2k.ast.INode.Kind
|
import org.jetbrains.jet.j2k.ast.INode.Kind
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type
|
||||||
|
|
||||||
public open class Constructor(identifier : Identifier,
|
public open class Constructor(identifier : Identifier,
|
||||||
modifiers : Set<String?>,
|
modifiers : Set<String?>,
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package org.jetbrains.jet.j2k.ast;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.j2k.Converter;
|
import org.jetbrains.jet.j2k.Converter;
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type;
|
||||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.j2k.ast;
|
package org.jetbrains.jet.j2k.ast;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.j2k.ast;
|
package org.jetbrains.jet.j2k.ast;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type;
|
||||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.j2k.ast;
|
package org.jetbrains.jet.j2k.ast;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type;
|
||||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import org.jetbrains.jet.j2k.util.AstUtil
|
|||||||
import java.util.LinkedList
|
import java.util.LinkedList
|
||||||
import java.util.List
|
import java.util.List
|
||||||
import java.util.Set
|
import java.util.Set
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type
|
||||||
|
|
||||||
public open class Function(val name : Identifier,
|
public open class Function(val name : Identifier,
|
||||||
modifiers : Set<String?>,
|
modifiers : Set<String?>,
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2012 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.jet.j2k.ast;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author ignatov
|
|
||||||
*/
|
|
||||||
public class InProjectionType extends Type {
|
|
||||||
private final Type myBound;
|
|
||||||
|
|
||||||
public InProjectionType(Type bound) {
|
|
||||||
myBound = bound;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String toKotlin() {
|
|
||||||
return "in" + SPACE + myBound.toKotlin();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.j2k.ast;
|
package org.jetbrains.jet.j2k.ast;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.j2k.ast;
|
package org.jetbrains.jet.j2k.ast;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type;
|
||||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2012 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.jet.j2k.ast;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author ignatov
|
|
||||||
*/
|
|
||||||
public class OutProjectionType extends Type {
|
|
||||||
private final Type myBound;
|
|
||||||
|
|
||||||
public OutProjectionType(Type bound) {
|
|
||||||
myBound = bound;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String toKotlin() {
|
|
||||||
return "out" + SPACE + myBound.toKotlin();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.j2k.ast;
|
package org.jetbrains.jet.j2k.ast;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ignatov
|
* @author ignatov
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2012 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.jet.j2k.ast;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author ignatov
|
|
||||||
*/
|
|
||||||
public class PrimitiveType extends Type {
|
|
||||||
private final Identifier myType;
|
|
||||||
|
|
||||||
public PrimitiveType(Identifier type) {
|
|
||||||
myType = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isNullable() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String toKotlin() {
|
|
||||||
return myType.toKotlin();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.j2k.ast;
|
package org.jetbrains.jet.j2k.ast;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type;
|
||||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2012 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.jet.j2k.ast;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author ignatov
|
|
||||||
*/
|
|
||||||
public class StarProjectionType extends Type {
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String toKotlin() {
|
|
||||||
return STAR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.j2k.ast;
|
package org.jetbrains.jet.j2k.ast;
|
||||||
|
|
||||||
import org.jetbrains.jet.j2k.Converter;
|
import org.jetbrains.jet.j2k.Converter;
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2012 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.jet.j2k.ast;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author ignatov
|
|
||||||
*/
|
|
||||||
public abstract class Type extends Element {
|
|
||||||
@NotNull
|
|
||||||
public static final Type EMPTY_TYPE = new EmptyType();
|
|
||||||
boolean myNullable = true;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Kind getKind() {
|
|
||||||
return Kind.TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public Type convertedToNotNull() {
|
|
||||||
myNullable = false;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isNullable() {
|
|
||||||
return myNullable;
|
|
||||||
}
|
|
||||||
|
|
||||||
String isNullableStr() {
|
|
||||||
return isNullable() ? QUEST : EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author ignatov
|
|
||||||
*/
|
|
||||||
private static class EmptyType extends Type {
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String toKotlin() {
|
|
||||||
return "UNRESOLVED_TYPE";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isNullable() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.j2k.ast;
|
package org.jetbrains.jet.j2k.ast;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ignatov
|
* @author ignatov
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.j2k.ast;
|
package org.jetbrains.jet.j2k.ast;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ignatov
|
* @author ignatov
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.j2k.ast;
|
package org.jetbrains.jet.j2k.ast;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2012 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.jet.j2k.ast;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author ignatov
|
|
||||||
*/
|
|
||||||
public class VarArg extends Type {
|
|
||||||
private final Type myType;
|
|
||||||
|
|
||||||
public VarArg(Type type) {
|
|
||||||
myType = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Kind getKind() {
|
|
||||||
return Kind.VARARG;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String toKotlin() {
|
|
||||||
return myType.toKotlin();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package org.jetbrains.jet.j2k.ast.types
|
||||||
|
|
||||||
|
import org.jetbrains.jet.j2k.ast.INode
|
||||||
|
|
||||||
|
public open class ArrayType(val elementType : Type, nullable: Boolean) : Type(nullable) {
|
||||||
|
public override fun getKind() : INode.Kind = INode.Kind.ARRAY_TYPE
|
||||||
|
|
||||||
|
public override fun toKotlin() : String {
|
||||||
|
if (elementType is PrimitiveType) {
|
||||||
|
return elementType.toKotlin() + "Array" + isNullableStr()
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Array<" + elementType.toKotlin() + ">" + isNullableStr()
|
||||||
|
}
|
||||||
|
|
||||||
|
public override fun convertedToNotNull() : Type = ArrayType(elementType, false)
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package org.jetbrains.jet.j2k.ast.types
|
||||||
|
|
||||||
|
import org.jetbrains.jet.j2k.ast.Element
|
||||||
|
import org.jetbrains.jet.j2k.ast.Identifier
|
||||||
|
import org.jetbrains.jet.j2k.util.AstUtil
|
||||||
|
import java.util.Collections
|
||||||
|
import java.util.List
|
||||||
|
|
||||||
|
public open class ClassType(val `type` : Identifier, val parameters : List<out Element>, nullable : Boolean) : Type(nullable) {
|
||||||
|
public override fun toKotlin() : String {
|
||||||
|
// TODO change to map() when KT-2051 is fixed
|
||||||
|
val parametersToKotlin: List<String> = arrayList()
|
||||||
|
for(val param in parameters) {
|
||||||
|
parametersToKotlin.add(param.toKotlin())
|
||||||
|
}
|
||||||
|
var params : String = if (parametersToKotlin.size() == 0)
|
||||||
|
""
|
||||||
|
else
|
||||||
|
"<" + parametersToKotlin.makeString(", ") + ">"
|
||||||
|
return `type`.toKotlin() + params + isNullableStr()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override fun convertedToNotNull() : Type = ClassType(`type`, parameters, false)
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package org.jetbrains.jet.j2k.ast.types
|
||||||
|
|
||||||
|
public open class EmptyType() : Type(false) {
|
||||||
|
public override fun toKotlin() : String = "UNRESOLVED_TYPE"
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package org.jetbrains.jet.j2k.ast.types
|
||||||
|
|
||||||
|
public open class InProjectionType(val bound : Type) : Type(false) {
|
||||||
|
public override fun toKotlin() : String = "in " + bound.toKotlin()
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package org.jetbrains.jet.j2k.ast.types
|
||||||
|
|
||||||
|
public open class OutProjectionType(val bound : Type) : Type(false) {
|
||||||
|
public override fun toKotlin() : String = "out " + bound.toKotlin()
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package org.jetbrains.jet.j2k.ast.types
|
||||||
|
|
||||||
|
import org.jetbrains.jet.j2k.ast.Identifier
|
||||||
|
|
||||||
|
public open class PrimitiveType(val `type` : Identifier) : Type(false) {
|
||||||
|
public override fun toKotlin() : String = `type`.toKotlin()
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package org.jetbrains.jet.j2k.ast.types
|
||||||
|
|
||||||
|
public open class StarProjectionType() : Type(false) {
|
||||||
|
public override fun toKotlin() : String = "*"
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.jetbrains.jet.j2k.ast.types
|
||||||
|
|
||||||
|
import org.jetbrains.jet.j2k.ast.Element
|
||||||
|
import org.jetbrains.jet.j2k.ast.INode
|
||||||
|
|
||||||
|
public abstract class Type(val nullable: Boolean) : Element() {
|
||||||
|
public override fun getKind() : INode.Kind = INode.Kind.TYPE
|
||||||
|
|
||||||
|
public open fun convertedToNotNull() : Type {
|
||||||
|
if (nullable) throw UnsupportedOperationException("convertedToNotNull must be defined")
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
public open fun isNullableStr() : String? {
|
||||||
|
return (if (nullable)
|
||||||
|
"?"
|
||||||
|
else
|
||||||
|
"")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package org.jetbrains.jet.j2k.ast.types
|
||||||
|
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type
|
||||||
|
import org.jetbrains.jet.j2k.ast.INode
|
||||||
|
|
||||||
|
public open class VarArg(val `type` : Type) : Type(false) {
|
||||||
|
public override fun getKind() : INode.Kind = INode.Kind.VARARG
|
||||||
|
public override fun toKotlin() : String = `type`.toKotlin()
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ import com.intellij.psi.*;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.j2k.Converter;
|
import org.jetbrains.jet.j2k.Converter;
|
||||||
import org.jetbrains.jet.j2k.ast.*;
|
import org.jetbrains.jet.j2k.ast.*;
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.j2k.Converter;
|
import org.jetbrains.jet.j2k.Converter;
|
||||||
import org.jetbrains.jet.j2k.ast.*;
|
import org.jetbrains.jet.j2k.ast.*;
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type;
|
||||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -238,7 +239,7 @@ public class ExpressionVisitor extends StatementVisitor {
|
|||||||
getConverter().expressionToExpression(expression.getMethodExpression()),
|
getConverter().expressionToExpression(expression.getMethodExpression()),
|
||||||
getConverter().expressionsToExpressionList(expression.getArgumentList().getExpressions()),
|
getConverter().expressionsToExpressionList(expression.getArgumentList().getExpressions()),
|
||||||
getConverter().createConversions(expression),
|
getConverter().createConversions(expression),
|
||||||
getConverter().typeToType(expression.getType()).isNullable(),
|
getConverter().typeToType(expression.getType()).getNullable(),
|
||||||
getConverter().typesToTypeList(expression.getTypeArguments())
|
getConverter().typesToTypeList(expression.getTypeArguments())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -348,7 +349,7 @@ public class ExpressionVisitor extends StatementVisitor {
|
|||||||
final boolean insideSecondaryConstructor = isInsideSecondaryConstructor(expression);
|
final boolean insideSecondaryConstructor = isInsideSecondaryConstructor(expression);
|
||||||
final boolean hasReceiver = isFieldReference && insideSecondaryConstructor;
|
final boolean hasReceiver = isFieldReference && insideSecondaryConstructor;
|
||||||
final boolean isThis = isThisExpression(expression);
|
final boolean isThis = isThisExpression(expression);
|
||||||
final boolean isNullable = getConverter().typeToType(expression.getType()).isNullable();
|
final boolean isNullable = getConverter().typeToType(expression.getType()).getNullable();
|
||||||
final String className = getClassNameWithConstructor(expression);
|
final String className = getClassNameWithConstructor(expression);
|
||||||
|
|
||||||
Expression identifier = new IdentifierImpl(expression.getReferenceName(), isNullable);
|
Expression identifier = new IdentifierImpl(expression.getReferenceName(), isNullable);
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.jet.j2k.Converter;
|
import org.jetbrains.jet.j2k.Converter;
|
||||||
import org.jetbrains.jet.j2k.J2KConverterFlags;
|
import org.jetbrains.jet.j2k.J2KConverterFlags;
|
||||||
import org.jetbrains.jet.j2k.ast.*;
|
import org.jetbrains.jet.j2k.ast.*;
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.*;
|
||||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -45,7 +45,7 @@ public class TypeVisitor extends PsiTypeVisitor<Type> implements J2KVisitor {
|
|||||||
private static final String JAVA_LANG_ITERABLE = "java.lang.Iterable";
|
private static final String JAVA_LANG_ITERABLE = "java.lang.Iterable";
|
||||||
private static final String JAVA_UTIL_ITERATOR = "java.util.Iterator";
|
private static final String JAVA_UTIL_ITERATOR = "java.util.Iterator";
|
||||||
private final Converter myConverter;
|
private final Converter myConverter;
|
||||||
private Type myResult = Type.EMPTY_TYPE;
|
private Type myResult = new EmptyType();
|
||||||
|
|
||||||
public TypeVisitor(@NotNull Converter myConverter) {
|
public TypeVisitor(@NotNull Converter myConverter) {
|
||||||
this.myConverter = myConverter;
|
this.myConverter = myConverter;
|
||||||
@@ -75,8 +75,8 @@ public class TypeVisitor extends PsiTypeVisitor<Type> implements J2KVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type visitArrayType(@NotNull PsiArrayType arrayType) {
|
public Type visitArrayType(@NotNull PsiArrayType arrayType) {
|
||||||
if (myResult == Type.EMPTY_TYPE) {
|
if (myResult instanceof EmptyType) {
|
||||||
myResult = new ArrayType(getConverter().typeToType(arrayType.getComponentType()));
|
myResult = new ArrayType(getConverter().typeToType(arrayType.getComponentType()), true);
|
||||||
}
|
}
|
||||||
return super.visitArrayType(arrayType);
|
return super.visitArrayType(arrayType);
|
||||||
}
|
}
|
||||||
@@ -87,10 +87,10 @@ public class TypeVisitor extends PsiTypeVisitor<Type> implements J2KVisitor {
|
|||||||
final List<Type> resolvedClassTypeParams = createRawTypesForResolvedReference(classType);
|
final List<Type> resolvedClassTypeParams = createRawTypesForResolvedReference(classType);
|
||||||
|
|
||||||
if (classType.getParameterCount() == 0 && resolvedClassTypeParams.size() > 0) {
|
if (classType.getParameterCount() == 0 && resolvedClassTypeParams.size() > 0) {
|
||||||
myResult = new ClassType(identifier, resolvedClassTypeParams);
|
myResult = new ClassType(identifier, resolvedClassTypeParams, true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
myResult = new ClassType(identifier, getConverter().typesToTypeList(classType.getParameters()));
|
myResult = new ClassType(identifier, getConverter().typesToTypeList(classType.getParameters()), true);
|
||||||
}
|
}
|
||||||
return super.visitClassType(classType);
|
return super.visitClassType(classType);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user