simplify class hierarchy

This commit is contained in:
Dmitry Jemerov
2012-05-25 21:01:57 +02:00
committed by Pavel V. Talanov
parent 07fcfe3b42
commit 3977db1472
17 changed files with 107 additions and 165 deletions
+11 -11
View File
@@ -108,7 +108,7 @@ public open class Converter() {
val typeParameters: List<Element> = elementsToElementList(psiClass.getTypeParameters()) val typeParameters: List<Element> = elementsToElementList(psiClass.getTypeParameters())
val implementsTypes: List<Type> = typesToNotNullableTypeList(psiClass.getImplementsListTypes()) val implementsTypes: List<Type> = typesToNotNullableTypeList(psiClass.getImplementsListTypes())
val extendsTypes: List<Type> = typesToNotNullableTypeList(psiClass.getExtendsListTypes()) val extendsTypes: List<Type> = typesToNotNullableTypeList(psiClass.getExtendsListTypes())
val name: IdentifierImpl = IdentifierImpl(psiClass.getName()) val name: Identifier = Identifier(psiClass.getName())
val baseClassParams: List<Expression> = arrayList() val baseClassParams: List<Expression> = arrayList()
val members: List<Member> = getMembers(psiClass) val members: List<Member> = getMembers(psiClass)
val visitor: SuperVisitor = SuperVisitor() val visitor: SuperVisitor = SuperVisitor()
@@ -188,10 +188,10 @@ public open class Converter() {
private fun fieldToField(field: PsiField, psiClass: PsiClass?): Field { private fun fieldToField(field: PsiField, psiClass: PsiClass?): Field {
val modifiers: Set<String> = modifiersListToModifiersSet(field.getModifierList()) val modifiers: Set<String> = modifiersListToModifiersSet(field.getModifierList())
if (field is PsiEnumConstant?) { if (field is PsiEnumConstant?) {
return EnumConstant(IdentifierImpl(field.getName()), modifiers, typeToType(field.getType()), elementToElement(field.getArgumentList())) return EnumConstant(Identifier(field.getName()), modifiers, typeToType(field.getType()), elementToElement(field.getArgumentList()))
} }
return Field(IdentifierImpl(field.getName()), return Field(Identifier(field.getName()),
modifiers, modifiers,
typeToType(field.getType()), typeToType(field.getType()),
expressionToExpression(field.getInitializer(), field.getType()), expressionToExpression(field.getInitializer(), field.getType()),
@@ -210,7 +210,7 @@ public open class Converter() {
dispatcher.expressionVisitor = ExpressionVisitor(this) dispatcher.expressionVisitor = ExpressionVisitor(this)
} }
methodReturnType = method.getReturnType() methodReturnType = method.getReturnType()
val identifier: IdentifierImpl = IdentifierImpl(method.getName()) val identifier: Identifier = Identifier(method.getName())
val returnType: Type = typeToType(method.getReturnType(), ConverterUtil.isAnnotatedAsNotNull(method.getModifierList())) val returnType: Type = typeToType(method.getReturnType(), ConverterUtil.isAnnotatedAsNotNull(method.getModifierList()))
val body: Block = (if (hasFlag(J2KConverterFlags.SKIP_BODIES)) val body: Block = (if (hasFlag(J2KConverterFlags.SKIP_BODIES))
Block.EMPTY_BLOCK Block.EMPTY_BLOCK
@@ -245,7 +245,7 @@ public open class Converter() {
val result: List<Parameter> = arrayList() val result: List<Parameter> = arrayList()
for (parameter : PsiParameter? in method.getParameterList().getParameters()) for (parameter : PsiParameter? in method.getParameterList().getParameters())
{ {
result.add(Parameter(IdentifierImpl(parameter?.getName()), result.add(Parameter(Identifier(parameter?.getName()),
typeToType(parameter?.getType(), typeToType(parameter?.getType(),
ConverterUtil.isAnnotatedAsNotNull(parameter?.getModifierList())), ConverterUtil.isAnnotatedAsNotNull(parameter?.getModifierList())),
ConverterUtil.isReadOnly(parameter, method.getBody()))) ConverterUtil.isReadOnly(parameter, method.getBody())))
@@ -377,7 +377,7 @@ public open class Converter() {
} }
public open fun parameterToParameter(parameter: PsiParameter): Parameter { public open fun parameterToParameter(parameter: PsiParameter): Parameter {
return Parameter(IdentifierImpl(parameter.getName()), return Parameter(Identifier(parameter.getName()),
typeToType(parameter.getType(), typeToType(parameter.getType(),
ConverterUtil.isAnnotatedAsNotNull(parameter.getModifierList())), true) ConverterUtil.isAnnotatedAsNotNull(parameter.getModifierList())), true)
} }
@@ -409,7 +409,7 @@ public open class Converter() {
public open fun expressionToExpression(argument: PsiExpression?, expectedType: PsiType?): Expression { public open fun expressionToExpression(argument: PsiExpression?, expectedType: PsiType?): Expression {
if (argument == null) if (argument == null)
return (Identifier.EMPTY_IDENTIFIER as IdentifierImpl) return Identifier.EMPTY_IDENTIFIER
var expression: Expression = expressionToExpression(argument) var expression: Expression = expressionToExpression(argument)
val actualType: PsiType? = argument.getType() val actualType: PsiType? = argument.getType()
@@ -424,7 +424,7 @@ public open class Converter() {
var conversion: String? = PRIMITIVE_TYPE_CONVERSIONS.get(expectedType?.getCanonicalText()) var conversion: String? = PRIMITIVE_TYPE_CONVERSIONS.get(expectedType?.getCanonicalText())
if (conversion != null) if (conversion != null)
{ {
expression = DummyMethodCallExpression(expression, conversion, (Identifier.EMPTY_IDENTIFIER as IdentifierImpl?)) expression = DummyMethodCallExpression(expression, conversion, Identifier.EMPTY_IDENTIFIER)
} }
} }
@@ -454,7 +454,7 @@ public open class Converter() {
?.build()!! ?.build()!!
private fun quoteKeywords(packageName: String): String { private fun quoteKeywords(packageName: String): String {
return packageName.split("\\.").map { IdentifierImpl(it).toKotlin() }.makeString(".") return packageName.split("\\.").map { Identifier(it).toKotlin() }.makeString(".")
} }
private fun getFinalOrWithEmptyInitializer(fields: List<out Field>): List<Field> { private fun getFinalOrWithEmptyInitializer(fields: List<out Field>): List<Field> {
@@ -468,7 +468,7 @@ public open class Converter() {
} }
private fun createParametersFromFields(fields: List<Field>): List<Parameter> { private fun createParametersFromFields(fields: List<Field>): List<Parameter> {
return fields.map { Parameter(IdentifierImpl("_" + it.identifier.getName()), it.`type`, true) } return fields.map { Parameter(Identifier("_" + it.identifier.getName()), it.`type`, true) }
} }
private fun createInitStatementsFromFields(fields: List<out Field>): List<Statement> { private fun createInitStatementsFromFields(fields: List<out Field>): List<Statement> {
@@ -628,7 +628,7 @@ public open class Converter() {
if (identifier == null) if (identifier == null)
return Identifier.EMPTY_IDENTIFIER return Identifier.EMPTY_IDENTIFIER
return IdentifierImpl(identifier?.getText()) return Identifier(identifier?.getText())
} }
public open fun modifiersListToModifiersSet(modifierList: PsiModifierList?): Set<String> { public open fun modifiersListToModifiersSet(modifierList: PsiModifierList?): Set<String> {
@@ -7,7 +7,7 @@ import java.util.List
public open class AnonymousClass(converter : Converter, members : List<Member>) public open class AnonymousClass(converter : Converter, members : List<Member>)
: Class(converter, : Class(converter,
IdentifierImpl("anonClass"), Identifier("anonClass"),
Collections.emptySet<String>()!!, Collections.emptySet<String>()!!,
Collections.emptyList<Element>()!!, Collections.emptyList<Element>()!!,
Collections.emptyList<Type>()!!, Collections.emptyList<Type>()!!,
+2 -2
View File
@@ -66,12 +66,12 @@ public open class Class(converter : Converter,
val modifiers : Set<String> = HashSet<String>(f.getModifiers()) val modifiers : Set<String> = HashSet<String>(f.getModifiers())
modifiers.add(Modifier.STATIC) modifiers.add(Modifier.STATIC)
val statements : List<Statement> = f.block?.statements ?: arrayList() val statements : List<Statement> = f.block?.statements ?: arrayList()
statements.add(ReturnStatement(IdentifierImpl("__"))) statements.add(ReturnStatement(Identifier("__")))
val block : Block = Block(statements) val block : Block = Block(statements)
val constructorTypeParameters : List<Element> = arrayList() val constructorTypeParameters : List<Element> = arrayList()
constructorTypeParameters.addAll(typeParameters) constructorTypeParameters.addAll(typeParameters)
constructorTypeParameters.addAll(f.typeParameters) constructorTypeParameters.addAll(f.typeParameters)
return Function(IdentifierImpl("init"), modifiers, ClassType(name, constructorTypeParameters, false), return Function(Identifier("init"), modifiers, ClassType(name, constructorTypeParameters, false),
constructorTypeParameters, f.params, block) constructorTypeParameters, f.params, block)
} }
@@ -23,11 +23,11 @@ import org.jetbrains.annotations.NotNull;
*/ */
public class ForeachWithRangeStatement extends Statement { public class ForeachWithRangeStatement extends Statement {
private final Expression myStart; private final Expression myStart;
private final IdentifierImpl myIdentifier; private final Identifier myIdentifier;
private final Expression myEnd; private final Expression myEnd;
private final Statement myBody; private final Statement myBody;
public ForeachWithRangeStatement(IdentifierImpl identifier, Expression start, Expression end, Statement body) { public ForeachWithRangeStatement(Identifier identifier, Expression start, Expression end, Statement body) {
myStart = start; myStart = start;
myIdentifier = identifier; myIdentifier = identifier;
myEnd = end; myEnd = end;
-27
View File
@@ -1,27 +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 interface INode {
@NotNull
String toKotlin();
}
+50 -4
View File
@@ -21,11 +21,57 @@ import org.jetbrains.annotations.NotNull;
/** /**
* @author ignatov * @author ignatov
*/ */
public interface Identifier extends INode { public class Identifier extends Expression {
@NotNull @NotNull
Identifier EMPTY_IDENTIFIER = new IdentifierImpl(""); public static Identifier EMPTY_IDENTIFIER = new Identifier("");
boolean isEmpty(); private final String myName;
private boolean myIsNullable = true;
private boolean myQuotingNeeded = true;
String getName(); public Identifier(String name) {
myName = name;
}
public Identifier(String name, boolean isNullable) {
myName = name;
myIsNullable = isNullable;
}
public Identifier(String name, boolean isNullable, boolean quotingNeeded) {
myName = name;
myIsNullable = isNullable;
myQuotingNeeded = quotingNeeded;
}
public boolean isEmpty() {
return myName.length() == 0;
}
public String getName() {
return myName;
}
@NotNull
private static String quote(String str) {
return BACKTICK + str + BACKTICK;
}
@Override
public boolean isNullable() {
return myIsNullable;
}
private String ifNeedQuote() {
if (myQuotingNeeded && (ONLY_KOTLIN_KEYWORDS.contains(myName) || myName.contains("$"))) {
return quote(myName);
}
return myName;
}
@NotNull
@Override
public String toKotlin() {
return ifNeedQuote();
}
} }
@@ -1,76 +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 IdentifierImpl extends Expression implements Identifier {
private final String myName;
private boolean myIsNullable = true;
private boolean myQuotingNeeded = true;
public IdentifierImpl(String name) {
myName = name;
}
public IdentifierImpl(String name, boolean isNullable) {
myName = name;
myIsNullable = isNullable;
}
public IdentifierImpl(String name, boolean isNullable, boolean quotingNeeded) {
myName = name;
myIsNullable = isNullable;
myQuotingNeeded = quotingNeeded;
}
@Override
public boolean isEmpty() {
return myName.length() == 0;
}
@Override
public String getName() {
return myName;
}
@NotNull
private static String quote(String str) {
return BACKTICK + str + BACKTICK;
}
@Override
public boolean isNullable() {
return myIsNullable;
}
private String ifNeedQuote() {
if (myQuotingNeeded && (ONLY_KOTLIN_KEYWORDS.contains(myName) || myName.contains("$"))) {
return quote(myName);
}
return myName;
}
@NotNull
@Override
public String toKotlin() {
return ifNeedQuote();
}
}
+5 -1
View File
@@ -16,6 +16,7 @@
package org.jetbrains.jet.j2k.ast; package org.jetbrains.jet.j2k.ast;
import org.eclipse.jdt.internal.core.search.StringOperation;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Arrays; import java.util.Arrays;
@@ -25,7 +26,7 @@ import java.util.Set;
/** /**
* @author ignatov * @author ignatov
*/ */
public abstract class Node implements INode { public abstract class Node {
@NotNull @NotNull
final static Set<String> ONLY_KOTLIN_KEYWORDS = new HashSet<String>(Arrays.asList( final static Set<String> ONLY_KOTLIN_KEYWORDS = new HashSet<String>(Arrays.asList(
"package", "as", "type", "val", "var", "fun", "is", "in", "object", "when", "trait", "This" "package", "as", "type", "val", "var", "fun", "is", "in", "object", "when", "trait", "This"
@@ -65,4 +66,7 @@ public abstract class Node implements INode {
static final String STAR = "*"; static final String STAR = "*";
@NotNull @NotNull
protected static final String ZERO = "0"; protected static final String ZERO = "0";
@NotNull
public abstract String toKotlin();
} }
@@ -1,7 +1,5 @@
package org.jetbrains.jet.j2k.ast.types 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 open class ArrayType(val elementType : Type, nullable: Boolean) : Type(nullable) {
public override fun toKotlin() : String { public override fun toKotlin() : String {
if (elementType is PrimitiveType) { if (elementType is PrimitiveType) {
@@ -1,7 +1,6 @@
package org.jetbrains.jet.j2k.ast.types package org.jetbrains.jet.j2k.ast.types
import org.jetbrains.jet.j2k.ast.Element import org.jetbrains.jet.j2k.ast.Element
import org.jetbrains.jet.j2k.ast.INode
public abstract class Type(val nullable: Boolean) : Element() { public abstract class Type(val nullable: Boolean) : Element() {
public open fun convertedToNotNull() : Type { public open fun convertedToNotNull() : Type {
@@ -1,7 +1,6 @@
package org.jetbrains.jet.j2k.ast.types package org.jetbrains.jet.j2k.ast.types
import org.jetbrains.jet.j2k.ast.types.Type 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 open class VarArg(val `type` : Type) : Type(false) {
public override fun toKotlin() : String = `type`.toKotlin() public override fun toKotlin() : String = `type`.toKotlin()
+4 -4
View File
@@ -18,7 +18,7 @@ package org.jetbrains.jet.j2k.util;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.j2k.ast.INode; import org.jetbrains.jet.j2k.ast.Node;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@@ -46,7 +46,7 @@ public class AstUtil {
return buffer.toString(); return buffer.toString();
} }
public static String joinNodes(@NotNull final List<? extends INode> nodes, final String delimiter) { public static String joinNodes(@NotNull final List<? extends Node> nodes, final String delimiter) {
return join(nodesToKotlin(nodes), delimiter); return join(nodesToKotlin(nodes), delimiter);
} }
@@ -55,9 +55,9 @@ public class AstUtil {
} }
@NotNull @NotNull
public static List<String> nodesToKotlin(@NotNull List<? extends INode> nodes) { public static List<String> nodesToKotlin(@NotNull List<? extends Node> nodes) {
List<String> result = new LinkedList<String>(); List<String> result = new LinkedList<String>();
for (INode n : nodes) for (Node n : nodes)
result.add(n.toKotlin()); result.add(n.toKotlin());
return result; return result;
} }
@@ -20,7 +20,7 @@ public open class ElementVisitor(val myConverter : Converter) : JavaElementVisit
public override fun visitLocalVariable(variable : PsiLocalVariable?) : Unit { public override fun visitLocalVariable(variable : PsiLocalVariable?) : Unit {
val theVariable = variable!! val theVariable = variable!!
myResult = LocalVariable(IdentifierImpl(theVariable.getName()), myResult = LocalVariable(Identifier(theVariable.getName()),
Converter.modifiersListToModifiersSet(theVariable.getModifierList()), Converter.modifiersListToModifiersSet(theVariable.getModifierList()),
myConverter.typeToType(theVariable.getType(), isAnnotatedAsNotNull(theVariable.getModifierList())), myConverter.typeToType(theVariable.getType(), isAnnotatedAsNotNull(theVariable.getModifierList())),
myConverter.expressionToExpression(theVariable.getInitializer(), theVariable.getType())) myConverter.expressionToExpression(theVariable.getInitializer(), theVariable.getType()))
@@ -34,18 +34,18 @@ public open class ElementVisitor(val myConverter : Converter) : JavaElementVisit
val theReference = reference!! val theReference = reference!!
val types : List<Type> = myConverter.typesToTypeList(theReference.getTypeParameters()).requireNoNulls() val types : List<Type> = myConverter.typesToTypeList(theReference.getTypeParameters()).requireNoNulls()
if (!theReference.isQualified()) { if (!theReference.isQualified()) {
myResult = ReferenceElement(IdentifierImpl(theReference.getReferenceName()), types) myResult = ReferenceElement(Identifier(theReference.getReferenceName()), types)
} }
else { else {
var result : String = IdentifierImpl(reference?.getReferenceName()).toKotlin() var result : String = Identifier(reference?.getReferenceName()).toKotlin()
var qualifier : PsiElement? = theReference.getQualifier() var qualifier : PsiElement? = theReference.getQualifier()
while (qualifier != null) while (qualifier != null)
{ {
val p : PsiJavaCodeReferenceElement = (qualifier as PsiJavaCodeReferenceElement) val p : PsiJavaCodeReferenceElement = (qualifier as PsiJavaCodeReferenceElement)
result = IdentifierImpl(p.getReferenceName()).toKotlin() + "." + result result = Identifier(p.getReferenceName()).toKotlin() + "." + result
qualifier = p.getQualifier() qualifier = p.getQualifier()
} }
myResult = ReferenceElement(IdentifierImpl(result), types) myResult = ReferenceElement(Identifier(result), types)
} }
} }
@@ -54,7 +54,7 @@ public open class ElementVisitor(val myConverter : Converter) : JavaElementVisit
} }
public override fun visitTypeParameter(classParameter : PsiTypeParameter?) : Unit { public override fun visitTypeParameter(classParameter : PsiTypeParameter?) : Unit {
myResult = TypeParameter(IdentifierImpl(classParameter!!.getName()), myResult = TypeParameter(Identifier(classParameter!!.getName()),
classParameter!!.getExtendsListTypes().map { myConverter.typeToType(it) } ) classParameter!!.getExtendsListTypes().map { myConverter.typeToType(it) } )
} }
@@ -231,7 +231,7 @@ public class ExpressionVisitor extends StatementVisitor {
isQuotingNeeded = false; isQuotingNeeded = false;
} }
} }
myResult = new LiteralExpression(new IdentifierImpl(text, false, isQuotingNeeded)); myResult = new LiteralExpression(new Identifier(text, false, isQuotingNeeded));
} }
@Override @Override
@@ -289,9 +289,9 @@ public class ExpressionVisitor extends StatementVisitor {
? getConverter().typesToTypeList(reference.getTypeParameters()) ? getConverter().typesToTypeList(reference.getTypeParameters())
: Collections.<Type>emptyList(); : Collections.<Type>emptyList();
return new CallChainExpression( return new CallChainExpression(
new IdentifierImpl(constructor.getName(), false), new Identifier(constructor.getName(), false),
new MethodCallExpression( new MethodCallExpression(
new IdentifierImpl("init"), new Identifier("init"),
getConverter().expressionsToExpressionList(arguments), getConverter().expressionsToExpressionList(arguments),
typeParameters, false)); typeParameters, false));
} }
@@ -353,14 +353,14 @@ public class ExpressionVisitor extends StatementVisitor {
final boolean isNullable = getConverter().typeToType(expression.getType()).getNullable(); 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 Identifier(expression.getReferenceName(), isNullable);
final String __ = "__"; final String __ = "__";
if (hasReceiver) { if (hasReceiver) {
identifier = new CallChainExpression(new IdentifierImpl(__, false), new IdentifierImpl(expression.getReferenceName(), isNullable)); identifier = new CallChainExpression(new Identifier(__, false), new Identifier(expression.getReferenceName(), isNullable));
} }
else if (insideSecondaryConstructor && isThis) { else if (insideSecondaryConstructor && isThis) {
identifier = new IdentifierImpl("val __ = " + className); // TODO: hack identifier = new Identifier("val __ = " + className); // TODO: hack
} }
myResult = new CallChainExpression( myResult = new CallChainExpression(
@@ -467,7 +467,7 @@ public class ExpressionVisitor extends StatementVisitor {
final PsiJavaCodeReferenceElement qualifier = expression.getQualifier(); final PsiJavaCodeReferenceElement qualifier = expression.getQualifier();
myResult = new SuperExpression( myResult = new SuperExpression(
qualifier != null ? qualifier != null ?
new IdentifierImpl(qualifier.getQualifiedName()) : new Identifier(qualifier.getQualifiedName()) :
Identifier.EMPTY_IDENTIFIER Identifier.EMPTY_IDENTIFIER
); );
} }
@@ -478,7 +478,7 @@ public class ExpressionVisitor extends StatementVisitor {
final PsiJavaCodeReferenceElement qualifier = expression.getQualifier(); final PsiJavaCodeReferenceElement qualifier = expression.getQualifier();
myResult = new ThisExpression( myResult = new ThisExpression(
qualifier != null ? qualifier != null ?
new IdentifierImpl(qualifier.getQualifiedName()) : new Identifier(qualifier.getQualifiedName()) :
Identifier.EMPTY_IDENTIFIER Identifier.EMPTY_IDENTIFIER
); );
} }
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.j2k.Converter; import org.jetbrains.jet.j2k.Converter;
import org.jetbrains.jet.j2k.ast.DummyMethodCallExpression; import org.jetbrains.jet.j2k.ast.DummyMethodCallExpression;
import org.jetbrains.jet.j2k.ast.DummyStringExpression; import org.jetbrains.jet.j2k.ast.DummyStringExpression;
import org.jetbrains.jet.j2k.ast.IdentifierImpl; import org.jetbrains.jet.j2k.ast.Identifier;
import static com.intellij.psi.CommonClassNames.JAVA_LANG_OBJECT; import static com.intellij.psi.CommonClassNames.JAVA_LANG_OBJECT;
@@ -36,10 +36,10 @@ public class ExpressionVisitorForDirectObjectInheritors extends ExpressionVisito
@Override @Override
public void visitMethodCallExpression(@NotNull final PsiMethodCallExpression expression) { public void visitMethodCallExpression(@NotNull final PsiMethodCallExpression expression) {
if (superMethodInvocation(expression.getMethodExpression(), "hashCode")) { if (superMethodInvocation(expression.getMethodExpression(), "hashCode")) {
myResult = new DummyMethodCallExpression(new IdentifierImpl("System"), "identityHashCode", new IdentifierImpl("this")); myResult = new DummyMethodCallExpression(new Identifier("System"), "identityHashCode", new Identifier("this"));
} }
else if (superMethodInvocation(expression.getMethodExpression(), "equals")) { else if (superMethodInvocation(expression.getMethodExpression(), "equals")) {
myResult = new DummyMethodCallExpression(new IdentifierImpl("this"), "identityEquals", getConverter().elementToElement(expression.getArgumentList())); myResult = new DummyMethodCallExpression(new Identifier("this"), "identityEquals", getConverter().elementToElement(expression.getArgumentList()));
} }
else if (superMethodInvocation(expression.getMethodExpression(), "toString")) { else if (superMethodInvocation(expression.getMethodExpression(), "toString")) {
myResult = new DummyStringExpression(String.format("getJavaClass<%s>.getName() + '@' + Integer.toHexString(hashCode())", getClassName(expression.getMethodExpression()))); myResult = new DummyStringExpression(String.format("getJavaClass<%s>.getName() + '@' + Integer.toHexString(hashCode())", getClassName(expression.getMethodExpression())));
@@ -164,10 +164,10 @@ public class StatementVisitor extends ElementVisitor {
) { ) {
final Expression end = getConverter().expressionToExpression(((PsiBinaryExpression) condition).getROperand()); final Expression end = getConverter().expressionToExpression(((PsiBinaryExpression) condition).getROperand());
final Expression endExpression = operationTokenType == JavaTokenType.LT ? final Expression endExpression = operationTokenType == JavaTokenType.LT ?
new BinaryExpression(end, new IdentifierImpl("1"), "-") : new BinaryExpression(end, new Identifier("1"), "-") :
end; end;
myResult = new ForeachWithRangeStatement( myResult = new ForeachWithRangeStatement(
new IdentifierImpl(firstChild.getName()), new org.jetbrains.jet.j2k.ast.Identifier(firstChild.getName()),
getConverter().expressionToExpression(firstChild.getInitializer()), getConverter().expressionToExpression(firstChild.getInitializer()),
endExpression, endExpression,
getConverter().statementToStatement(body) getConverter().statementToStatement(body)
@@ -18,15 +18,14 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
public override fun visitPrimitiveType(primitiveType: PsiPrimitiveType?) : Type { public override fun visitPrimitiveType(primitiveType: PsiPrimitiveType?) : Type {
val name : String = primitiveType?.getCanonicalText()!! val name : String = primitiveType?.getCanonicalText()!!
val identifier : IdentifierImpl = IdentifierImpl(name)
if (name == "void") { if (name == "void") {
myResult = PrimitiveType(IdentifierImpl("Unit")) myResult = PrimitiveType(Identifier("Unit"))
} }
else if (Node.PRIMITIVE_TYPES.contains(name)) { else if (Node.PRIMITIVE_TYPES.contains(name)) {
myResult = PrimitiveType(IdentifierImpl(AstUtil.upperFirstCharacter(name))) myResult = PrimitiveType(Identifier(AstUtil.upperFirstCharacter(name)))
} }
else { else {
myResult = PrimitiveType(identifier) myResult = PrimitiveType(Identifier(name))
} }
return myResult return myResult
} }
@@ -41,7 +40,7 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
public override fun visitClassType(classType : PsiClassType?) : Type { public override fun visitClassType(classType : PsiClassType?) : Type {
if (classType == null) return myResult if (classType == null) return myResult
val identifier : IdentifierImpl = constructClassTypeIdentifier(classType) val identifier : Identifier = constructClassTypeIdentifier(classType)
val resolvedClassTypeParams : List<Type> = createRawTypesForResolvedReference(classType) val resolvedClassTypeParams : List<Type> = createRawTypesForResolvedReference(classType)
if (classType.getParameterCount() == 0 && resolvedClassTypeParams.size() > 0) { if (classType.getParameterCount() == 0 && resolvedClassTypeParams.size() > 0) {
myResult = ClassType(identifier, resolvedClassTypeParams, true) myResult = ClassType(identifier, resolvedClassTypeParams, true)
@@ -52,21 +51,21 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
return myResult return myResult
} }
private fun constructClassTypeIdentifier(classType : PsiClassType) : IdentifierImpl { private fun constructClassTypeIdentifier(classType : PsiClassType) : Identifier {
val psiClass : PsiClass? = classType.resolve() val psiClass : PsiClass? = classType.resolve()
if (psiClass != null) { if (psiClass != null) {
val qualifiedName: String? = psiClass.getQualifiedName() val qualifiedName: String? = psiClass.getQualifiedName()
if (qualifiedName != null) { if (qualifiedName != null) {
if (!qualifiedName.equals("java.lang.Object") && myConverter.hasFlag(J2KConverterFlags.FULLY_QUALIFIED_TYPE_NAMES)) { if (!qualifiedName.equals("java.lang.Object") && myConverter.hasFlag(J2KConverterFlags.FULLY_QUALIFIED_TYPE_NAMES)) {
return IdentifierImpl(qualifiedName) return Identifier(qualifiedName)
} }
if (qualifiedName.equals(CommonClassNames.JAVA_LANG_ITERABLE)) { if (qualifiedName.equals(CommonClassNames.JAVA_LANG_ITERABLE)) {
return IdentifierImpl(CommonClassNames.JAVA_LANG_ITERABLE) return Identifier(CommonClassNames.JAVA_LANG_ITERABLE)
} }
if (qualifiedName.equals(CommonClassNames.JAVA_UTIL_ITERATOR)) { if (qualifiedName.equals(CommonClassNames.JAVA_UTIL_ITERATOR)) {
return IdentifierImpl(CommonClassNames.JAVA_UTIL_ITERATOR) return Identifier(CommonClassNames.JAVA_UTIL_ITERATOR)
} }
} }
} }
@@ -74,10 +73,10 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
val classTypeName : String? = createQualifiedName(classType) val classTypeName : String? = createQualifiedName(classType)
if (classTypeName?.isEmpty().sure()) if (classTypeName?.isEmpty().sure())
{ {
return IdentifierImpl(getClassTypeName(classType)) return Identifier(getClassTypeName(classType))
} }
return IdentifierImpl(classTypeName) return Identifier(classTypeName)
} }
private fun createRawTypesForResolvedReference(classType : PsiClassType) : List<Type> { private fun createRawTypesForResolvedReference(classType : PsiClassType) : List<Type> {
@@ -89,7 +88,7 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
for (p : PsiTypeParameter? in (resolve as PsiClass).getTypeParameters()) { for (p : PsiTypeParameter? in (resolve as PsiClass).getTypeParameters()) {
val superTypes = p!!.getSuperTypes() val superTypes = p!!.getSuperTypes()
val boundType : Type = (if (superTypes.size > 0) val boundType : Type = (if (superTypes.size > 0)
ClassType(IdentifierImpl(getClassTypeName(superTypes[0]!!)), ClassType(Identifier(getClassTypeName(superTypes[0]!!)),
myConverter.typesToTypeList(superTypes[0]!!.getParameters()).requireNoNulls(), myConverter.typesToTypeList(superTypes[0]!!.getParameters()).requireNoNulls(),
true) true)
else else
@@ -130,12 +129,12 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
val reference : PsiJavaCodeReferenceElement? = (classType as PsiClassReferenceType).getReference() val reference : PsiJavaCodeReferenceElement? = (classType as PsiClassReferenceType).getReference()
if (reference != null && reference.isQualified()) if (reference != null && reference.isQualified())
{ {
var result : String = IdentifierImpl(reference.getReferenceName()).toKotlin() var result : String = Identifier(reference.getReferenceName()).toKotlin()
var qualifier : PsiElement? = reference.getQualifier() var qualifier : PsiElement? = reference.getQualifier()
while (qualifier != null) while (qualifier != null)
{ {
val p : PsiJavaCodeReferenceElement = (qualifier as PsiJavaCodeReferenceElement) val p : PsiJavaCodeReferenceElement = (qualifier as PsiJavaCodeReferenceElement)
result = IdentifierImpl(p.getReferenceName()).toKotlin() + "." + result result = Identifier(p.getReferenceName()).toKotlin() + "." + result
qualifier = p.getQualifier() qualifier = p.getQualifier()
} }
return result return result