back to compilable and working state
This commit is contained in:
committed by
Pavel V. Talanov
parent
5932eb3539
commit
0e2d0a4a5b
@@ -107,7 +107,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: Identifier = Identifier(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()
|
||||||
@@ -187,10 +187,13 @@ 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(Identifier(field.getName()), modifiers, typeToType(field.getType()), elementToElement(field.getArgumentList()))
|
return EnumConstant(Identifier(field.getName()!!),
|
||||||
|
modifiers,
|
||||||
|
typeToType(field.getType()),
|
||||||
|
elementToElement(field.getArgumentList()))
|
||||||
}
|
}
|
||||||
|
|
||||||
return Field(Identifier(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()),
|
||||||
@@ -242,9 +245,8 @@ public open class Converter() {
|
|||||||
|
|
||||||
private fun createFunctionParameters(method: PsiMethod): ParameterList {
|
private fun createFunctionParameters(method: PsiMethod): ParameterList {
|
||||||
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(Identifier(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())))
|
||||||
@@ -376,7 +378,7 @@ public open class Converter() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public open fun parameterToParameter(parameter: PsiParameter): Parameter {
|
public open fun parameterToParameter(parameter: PsiParameter): Parameter {
|
||||||
return Parameter(Identifier(parameter.getName()),
|
return Parameter(Identifier(parameter.getName()!!),
|
||||||
typeToType(parameter.getType(),
|
typeToType(parameter.getType(),
|
||||||
ConverterUtil.isAnnotatedAsNotNull(parameter.getModifierList())), true)
|
ConverterUtil.isAnnotatedAsNotNull(parameter.getModifierList())), true)
|
||||||
}
|
}
|
||||||
@@ -420,12 +422,10 @@ public open class Converter() {
|
|||||||
if (actualType != null) {
|
if (actualType != null) {
|
||||||
if (isConversionNeeded(actualType, expectedType) && !(expression is LiteralExpression))
|
if (isConversionNeeded(actualType, expectedType) && !(expression is LiteralExpression))
|
||||||
{
|
{
|
||||||
var conversion: String? = PRIMITIVE_TYPE_CONVERSIONS.get(expectedType?.getCanonicalText())
|
val conversion: String? = PRIMITIVE_TYPE_CONVERSIONS.get(expectedType?.getCanonicalText())
|
||||||
if (conversion != null)
|
if (conversion != null) {
|
||||||
{
|
|
||||||
expression = DummyMethodCallExpression(expression, conversion, Identifier.EMPTY_IDENTIFIER)
|
expression = DummyMethodCallExpression(expression, conversion, Identifier.EMPTY_IDENTIFIER)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -467,7 +467,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(Identifier("_" + it.identifier.getName()), it.`type`, true) }
|
return fields.map { Parameter(Identifier("_" + it.identifier.name), it.`type`, true) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createInitStatementsFromFields(fields: List<out Field>): List<Statement> {
|
private fun createInitStatementsFromFields(fields: List<out Field>): List<Statement> {
|
||||||
@@ -529,7 +529,7 @@ public open class Converter() {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
private fun removeEmpty(statements: List<Statement>): List<Statement> {
|
private fun removeEmpty(statements: List<Statement>): List<Statement> {
|
||||||
return statements.filterNot { it is EmptyStatement || it == Expression.EMPTY_EXPRESSION }
|
return statements.filterNot { it == Statement.EMPTY_STATEMENT || it == Expression.EMPTY_EXPRESSION }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isNotOpenMethod(method: PsiMethod): Boolean {
|
private fun isNotOpenMethod(method: PsiMethod): Boolean {
|
||||||
@@ -547,7 +547,7 @@ public open class Converter() {
|
|||||||
|
|
||||||
private fun normalCase(method: PsiMethod): Boolean {
|
private fun normalCase(method: PsiMethod): Boolean {
|
||||||
var counter: Int = 0
|
var counter: Int = 0
|
||||||
for (s : HierarchicalMethodSignature? in method.getHierarchicalMethodSignature()?.getSuperSignatures())
|
for (s : HierarchicalMethodSignature? in method.getHierarchicalMethodSignature().getSuperSignatures())
|
||||||
{
|
{
|
||||||
var containingClass: PsiClass? = s?.getMethod()?.getContainingClass()
|
var containingClass: PsiClass? = s?.getMethod()?.getContainingClass()
|
||||||
var qualifiedName: String? = (if (containingClass != null)
|
var qualifiedName: String? = (if (containingClass != null)
|
||||||
@@ -580,16 +580,15 @@ public open class Converter() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun isOverrideObjectDirect(method: PsiMethod): Boolean {
|
private fun isOverrideObjectDirect(method: PsiMethod): Boolean {
|
||||||
var superSignatures: List<HierarchicalMethodSignature?>? = method?.getHierarchicalMethodSignature()?.getSuperSignatures()
|
var superSignatures: List<HierarchicalMethodSignature?>? = method.getHierarchicalMethodSignature().getSuperSignatures()
|
||||||
if (superSignatures?.size()!! == 1)
|
if (superSignatures?.size()!! == 1)
|
||||||
{
|
{
|
||||||
val containingClass: PsiClass? = superSignatures?.get(0)?.getMethod()?.getContainingClass()
|
val containingClass: PsiClass? = superSignatures?.get(0)?.getMethod()?.getContainingClass()
|
||||||
val qualifiedName: String? = (if (containingClass != null)
|
val qualifiedName: String? = (if (containingClass != null)
|
||||||
containingClass?.getQualifiedName()
|
containingClass.getQualifiedName()
|
||||||
else
|
else
|
||||||
"")
|
"")
|
||||||
if (qualifiedName != null && qualifiedName?.equals(JAVA_LANG_OBJECT)!!)
|
if (qualifiedName == JAVA_LANG_OBJECT) {
|
||||||
{
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -627,7 +626,7 @@ public open class Converter() {
|
|||||||
if (identifier == null)
|
if (identifier == null)
|
||||||
return Identifier.EMPTY_IDENTIFIER
|
return Identifier.EMPTY_IDENTIFIER
|
||||||
|
|
||||||
return Identifier(identifier?.getText())
|
return Identifier(identifier.getText()!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
public open fun modifiersListToModifiersSet(modifierList: PsiModifierList?): Set<String> {
|
public open fun modifiersListToModifiersSet(modifierList: PsiModifierList?): Set<String> {
|
||||||
|
|||||||
@@ -1,47 +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 Expression extends Statement {
|
|
||||||
@NotNull
|
|
||||||
public static final Expression EMPTY_EXPRESSION = new EmptyExpression();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author ignatov
|
|
||||||
*/
|
|
||||||
private static class EmptyExpression extends Expression {
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String toKotlin() {
|
|
||||||
return EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isNullable() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.jetbrains.jet.j2k.ast
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class Expression(): Statement() {
|
||||||
|
public open fun isNullable(): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
class object {
|
||||||
|
public val EMPTY_EXPRESSION: Expression = object: Expression() {
|
||||||
|
public override fun toKotlin()= ""
|
||||||
|
public override fun isEmpty() = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,15 @@
|
|||||||
package org.jetbrains.jet.j2k.ast
|
package org.jetbrains.jet.j2k.ast
|
||||||
|
|
||||||
|
import java.util.Set
|
||||||
|
|
||||||
|
|
||||||
public open class Identifier(val name: String,
|
public open class Identifier(val name: String,
|
||||||
val nullable: Boolean = true,
|
val myNullable: Boolean = true,
|
||||||
val quotingNeeded: Boolean = true): Expression() {
|
val quotingNeeded: Boolean = true): Expression() {
|
||||||
public override fun isEmpty(): Boolean {
|
public override fun isEmpty() = name.length() == 0
|
||||||
return name.length() == 0
|
|
||||||
}
|
private open fun ifNeedQuote(): String {
|
||||||
private open fun ifNeedQuote(): String {
|
if (quotingNeeded && (ONLY_KOTLIN_KEYWORDS.contains(name)) || name.contains("$")) {
|
||||||
if (quotingNeeded && (ONLY_KOTLIN_KEYWORDS?.contains(name)) || name.contains("$"))) {
|
|
||||||
return quote(name)
|
return quote(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,11 +17,16 @@ public open class Identifier(val name: String,
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override fun toKotlin(): String = ifNeedQuote()
|
public override fun toKotlin(): String = ifNeedQuote()
|
||||||
|
public override fun isNullable(): Boolean = myNullable
|
||||||
|
|
||||||
class object {
|
class object {
|
||||||
public val EMPTY_IDENTIFIER: Identifier = Identifier("")
|
public val EMPTY_IDENTIFIER: Identifier = Identifier("")
|
||||||
private open fun quote(str: String): String {
|
private open fun quote(str: String): String {
|
||||||
return "`" + str + "`"
|
return "`" + str + "`"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public val ONLY_KOTLIN_KEYWORDS: Set<String> = hashSet(
|
||||||
|
"package", "as", "type", "val", "var", "fun", "is", "in", "object", "when", "trait", "This"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package org.jetbrains.jet.j2k.ast
|
package org.jetbrains.jet.j2k.ast
|
||||||
|
|
||||||
|
|
||||||
public open class LiteralExpression(val identifier: Identifier): Expression() {
|
public open class LiteralExpression(val literalText: String): Expression() {
|
||||||
public override fun toKotlin() = identifier.toKotlin()
|
public override fun toKotlin() = literalText
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,10 +27,6 @@ import java.util.Set;
|
|||||||
* @author ignatov
|
* @author ignatov
|
||||||
*/
|
*/
|
||||||
public abstract class Node {
|
public abstract class Node {
|
||||||
@NotNull
|
|
||||||
final static Set<String> ONLY_KOTLIN_KEYWORDS = new HashSet<String>(Arrays.asList(
|
|
||||||
"package", "as", "type", "val", "var", "fun", "is", "in", "object", "when", "trait", "This"
|
|
||||||
));
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public final static Set<String> PRIMITIVE_TYPES = new HashSet<String>(Arrays.asList(
|
public final static Set<String> PRIMITIVE_TYPES = new HashSet<String>(Arrays.asList(
|
||||||
|
|||||||
@@ -2,5 +2,5 @@ package org.jetbrains.jet.j2k.ast
|
|||||||
|
|
||||||
|
|
||||||
public open class PostfixOperator(val op: String, val expression: Expression): Expression() {
|
public open class PostfixOperator(val op: String, val expression: Expression): Expression() {
|
||||||
public override fun toKotlin() = expression.toKotlin() + op
|
public override fun toKotlin(): String = expression.toKotlin() + op
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.util.List
|
|||||||
|
|
||||||
public abstract class Statement(): Element() {
|
public abstract class Statement(): Element() {
|
||||||
class object {
|
class object {
|
||||||
public val EMPTY_STATEMENT = object : Statement {
|
public val EMPTY_STATEMENT: Statement = object : Statement() {
|
||||||
public override fun toKotlin() = ""
|
public override fun toKotlin() = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ public open class ReturnStatement(val expression: Expression): Statement() {
|
|||||||
public open class IfStatement(val condition: Expression, val thenStatement: Statement, val elseStatement: Statement): Expression() {
|
public open class IfStatement(val condition: Expression, val thenStatement: Statement, val elseStatement: Statement): Expression() {
|
||||||
public override fun toKotlin(): String {
|
public override fun toKotlin(): String {
|
||||||
val result: String = "if (" + condition.toKotlin() + ")\n" + thenStatement.toKotlin() + "\n"
|
val result: String = "if (" + condition.toKotlin() + ")\n" + thenStatement.toKotlin() + "\n"
|
||||||
if (elseStatement !is EmptyStatement) {
|
if (elseStatement != Statement.EMPTY_STATEMENT) {
|
||||||
return result + "else\n" + elseStatement.toKotlin()
|
return result + "else\n" + elseStatement.toKotlin()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,12 +7,16 @@ import java.util.Set
|
|||||||
|
|
||||||
public open class ClassVisitor(): JavaRecursiveElementVisitor() {
|
public open class ClassVisitor(): JavaRecursiveElementVisitor() {
|
||||||
private val myClassIdentifiers: Set<String> = HashSet<String>()
|
private val myClassIdentifiers: Set<String> = HashSet<String>()
|
||||||
|
|
||||||
public open fun getClassIdentifiers(): Set<String> {
|
public open fun getClassIdentifiers(): Set<String> {
|
||||||
return HashSet<String>(myClassIdentifiers)
|
return HashSet<String>(myClassIdentifiers)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override fun visitClass(aClass: PsiClass?): Unit {
|
public override fun visitClass(aClass: PsiClass?): Unit {
|
||||||
myClassIdentifiers.add(aClass?.getQualifiedName()!!)
|
val qName = aClass?.getQualifiedName()
|
||||||
|
if (qName != null) {
|
||||||
|
myClassIdentifiers.add(qName)
|
||||||
|
}
|
||||||
super.visitClass(aClass)
|
super.visitClass(aClass)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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(Identifier(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,15 +34,15 @@ public open class ElementVisitor(val myConverter : Converter) : JavaElementVisit
|
|||||||
val theReference = reference!!
|
val theReference = reference!!
|
||||||
val types : List<Type> = myConverter.typesToTypeList(theReference.getTypeParameters())
|
val types : List<Type> = myConverter.typesToTypeList(theReference.getTypeParameters())
|
||||||
if (!theReference.isQualified()) {
|
if (!theReference.isQualified()) {
|
||||||
myResult = ReferenceElement(Identifier(theReference.getReferenceName()), types)
|
myResult = ReferenceElement(Identifier(theReference.getReferenceName()!!), types)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var result : String = Identifier(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 = Identifier(p.getReferenceName()).toKotlin() + "." + result
|
result = Identifier(p.getReferenceName()!!).toKotlin() + "." + result
|
||||||
qualifier = p.getQualifier()
|
qualifier = p.getQualifier()
|
||||||
}
|
}
|
||||||
myResult = ReferenceElement(Identifier(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(Identifier(classParameter!!.getName()),
|
myResult = TypeParameter(Identifier(classParameter!!.getName()!!),
|
||||||
classParameter!!.getExtendsListTypes().map { myConverter.typeToType(it) } )
|
classParameter!!.getExtendsListTypes().map { myConverter.typeToType(it) } )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,9 +101,8 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
|||||||
var text: String = expression?.getText()!!
|
var text: String = expression?.getText()!!
|
||||||
var isQuotingNeeded: Boolean = true
|
var isQuotingNeeded: Boolean = true
|
||||||
val `type`: PsiType? = expression?.getType()
|
val `type`: PsiType? = expression?.getType()
|
||||||
if (`type` != null)
|
if (`type` != null) {
|
||||||
{
|
val canonicalTypeStr: String? = `type`.getCanonicalText()
|
||||||
var canonicalTypeStr: String? = `type`.getCanonicalText()
|
|
||||||
if (canonicalTypeStr?.equals("double")!! || canonicalTypeStr?.equals(JAVA_LANG_DOUBLE)!!) {
|
if (canonicalTypeStr?.equals("double")!! || canonicalTypeStr?.equals(JAVA_LANG_DOUBLE)!!) {
|
||||||
text = text.replace("D", "").replace("d", "")
|
text = text.replace("D", "").replace("d", "")
|
||||||
if (!text.contains(".")) {
|
if (!text.contains(".")) {
|
||||||
@@ -123,18 +122,9 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
|||||||
if (canonicalTypeStr?.equals("int")!! || canonicalTypeStr?.equals(JAVA_LANG_INTEGER)!!) {
|
if (canonicalTypeStr?.equals("int")!! || canonicalTypeStr?.equals(JAVA_LANG_INTEGER)!!) {
|
||||||
text = (if (value != null) value.toString() else text)
|
text = (if (value != null) value.toString() else text)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canonicalTypeStr?.equals(JAVA_LANG_STRING)!!) {
|
|
||||||
isQuotingNeeded = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (canonicalTypeStr?.equals("char")!! || canonicalTypeStr?.equals(JAVA_LANG_CHARACTER)!!) {
|
|
||||||
isQuotingNeeded = false
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
myResult = LiteralExpression(Identifier(text, false, isQuotingNeeded))
|
myResult = LiteralExpression(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override fun visitMethodCallExpression(expression: PsiMethodCallExpression?): Unit {
|
public override fun visitMethodCallExpression(expression: PsiMethodCallExpression?): Unit {
|
||||||
@@ -197,8 +187,8 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
|||||||
|
|
||||||
private fun createNewEmptyArrayWithoutInitialization(expression: PsiNewExpression): Expression {
|
private fun createNewEmptyArrayWithoutInitialization(expression: PsiNewExpression): Expression {
|
||||||
return ArrayWithoutInitializationExpression(
|
return ArrayWithoutInitializationExpression(
|
||||||
getConverter().typeToType(expression?.getType(), true),
|
getConverter().typeToType(expression.getType(), true),
|
||||||
getConverter().expressionsToExpressionList(expression?.getArrayDimensions()))
|
getConverter().expressionsToExpressionList(expression.getArrayDimensions()))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createNewEmptyArray(expression: PsiNewExpression?): Expression {
|
private fun createNewEmptyArray(expression: PsiNewExpression?): Expression {
|
||||||
@@ -232,10 +222,10 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
|||||||
val isThis: Boolean = isThisExpression(expression!!)
|
val isThis: Boolean = isThisExpression(expression!!)
|
||||||
val isNullable: Boolean = getConverter().typeToType(expression?.getType()).nullable
|
val isNullable: Boolean = getConverter().typeToType(expression?.getType()).nullable
|
||||||
val className: String = getClassNameWithConstructor(expression!!)
|
val className: String = getClassNameWithConstructor(expression!!)
|
||||||
var identifier: Expression = Identifier(expression?.getReferenceName(), isNullable)
|
var identifier: Expression = Identifier(expression?.getReferenceName()!!, isNullable)
|
||||||
val __: String? = "__"
|
val __: String = "__"
|
||||||
if (hasReceiver){
|
if (hasReceiver){
|
||||||
identifier = CallChainExpression(Identifier(__, false), Identifier(expression?.getReferenceName(), isNullable))
|
identifier = CallChainExpression(Identifier(__, false), Identifier(expression?.getReferenceName()!!, isNullable))
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (insideSecondaryConstructor && isThis) {
|
if (insideSecondaryConstructor && isThis) {
|
||||||
@@ -248,7 +238,7 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
|||||||
public override fun visitSuperExpression(expression: PsiSuperExpression?): Unit {
|
public override fun visitSuperExpression(expression: PsiSuperExpression?): Unit {
|
||||||
val qualifier: PsiJavaCodeReferenceElement? = expression?.getQualifier()
|
val qualifier: PsiJavaCodeReferenceElement? = expression?.getQualifier()
|
||||||
myResult = SuperExpression((if (qualifier != null)
|
myResult = SuperExpression((if (qualifier != null)
|
||||||
Identifier(qualifier.getQualifiedName())
|
Identifier(qualifier.getQualifiedName()!!)
|
||||||
else
|
else
|
||||||
Identifier.EMPTY_IDENTIFIER))
|
Identifier.EMPTY_IDENTIFIER))
|
||||||
}
|
}
|
||||||
@@ -256,7 +246,7 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
|||||||
public override fun visitThisExpression(expression: PsiThisExpression?): Unit {
|
public override fun visitThisExpression(expression: PsiThisExpression?): Unit {
|
||||||
val qualifier: PsiJavaCodeReferenceElement? = expression?.getQualifier()
|
val qualifier: PsiJavaCodeReferenceElement? = expression?.getQualifier()
|
||||||
myResult = ThisExpression((if (qualifier != null)
|
myResult = ThisExpression((if (qualifier != null)
|
||||||
Identifier(qualifier.getQualifiedName())
|
Identifier(qualifier.getQualifiedName()!!)
|
||||||
else
|
else
|
||||||
Identifier.EMPTY_IDENTIFIER))
|
Identifier.EMPTY_IDENTIFIER))
|
||||||
}
|
}
|
||||||
@@ -264,7 +254,7 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
|||||||
public override fun visitTypeCastExpression(expression: PsiTypeCastExpression?): Unit {
|
public override fun visitTypeCastExpression(expression: PsiTypeCastExpression?): Unit {
|
||||||
val castType: PsiTypeElement? = expression?.getCastType()
|
val castType: PsiTypeElement? = expression?.getCastType()
|
||||||
if (castType != null) {
|
if (castType != null) {
|
||||||
myResult = TypeCastExpression(getConverter()?.typeToType(castType.getType()),
|
myResult = TypeCastExpression(getConverter().typeToType(castType.getType()),
|
||||||
getConverter().expressionToExpression(expression?.getOperand()))
|
getConverter().expressionToExpression(expression?.getOperand()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -272,7 +262,7 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
|||||||
public override fun visitPolyadicExpression(expression: PsiPolyadicExpression?): Unit {
|
public override fun visitPolyadicExpression(expression: PsiPolyadicExpression?): Unit {
|
||||||
var parameters: List<Expression> = ArrayList<Expression>()
|
var parameters: List<Expression> = ArrayList<Expression>()
|
||||||
for (operand : PsiExpression? in expression?.getOperands()) {
|
for (operand : PsiExpression? in expression?.getOperands()) {
|
||||||
parameters?.add(getConverter().expressionToExpression(operand, expression?.getType()))
|
parameters.add(getConverter().expressionToExpression(operand, expression?.getType()))
|
||||||
}
|
}
|
||||||
myResult = PolyadicExpression(parameters, getOperatorString(expression?.getOperationTokenType()!!))
|
myResult = PolyadicExpression(parameters, getOperatorString(expression?.getOperationTokenType()!!))
|
||||||
}
|
}
|
||||||
@@ -345,17 +335,17 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
|||||||
if (tokenType == JavaTokenType.EXCL)
|
if (tokenType == JavaTokenType.EXCL)
|
||||||
return "!"
|
return "!"
|
||||||
|
|
||||||
System.out?.println("UNSUPPORTED TOKEN TYPE: " + tokenType?.toString())
|
// System.out.println("UNSUPPORTED TOKEN TYPE: " + tokenType?.toString())
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getClassNameWithConstructor(expression: PsiReferenceExpression): String {
|
private fun getClassNameWithConstructor(expression: PsiReferenceExpression): String {
|
||||||
var context: PsiElement? = expression?.getContext()
|
var context: PsiElement? = expression.getContext()
|
||||||
while (context != null) {
|
while (context != null) {
|
||||||
if (context is PsiMethod && ((context as PsiMethod)).isConstructor()) {
|
if (context is PsiMethod && ((context as PsiMethod)).isConstructor()) {
|
||||||
val containingClass: PsiClass? = ((context as PsiMethod)).getContainingClass()
|
val containingClass: PsiClass? = ((context as PsiMethod)).getContainingClass()
|
||||||
if (containingClass != null) {
|
if (containingClass != null) {
|
||||||
val identifier: PsiIdentifier? = containingClass?.getNameIdentifier()
|
val identifier: PsiIdentifier? = containingClass.getNameIdentifier()
|
||||||
if (identifier != null) {
|
if (identifier != null) {
|
||||||
return identifier.getText()!!
|
return identifier.getText()!!
|
||||||
}
|
}
|
||||||
@@ -388,9 +378,9 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun isFieldReference(expression: PsiReferenceExpression, currentClass: PsiClass?): Boolean {
|
private fun isFieldReference(expression: PsiReferenceExpression, currentClass: PsiClass?): Boolean {
|
||||||
val reference: PsiReference? = expression?.getReference()
|
val reference: PsiReference? = expression.getReference()
|
||||||
if (reference != null) {
|
if (reference != null) {
|
||||||
val resolvedReference: PsiElement? = reference?.resolve()
|
val resolvedReference: PsiElement? = reference.resolve()
|
||||||
if (resolvedReference is PsiField) {
|
if (resolvedReference is PsiField) {
|
||||||
return (resolvedReference as PsiField).getContainingClass() == currentClass
|
return (resolvedReference as PsiField).getContainingClass() == currentClass
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ public open class ExpressionVisitorForDirectObjectInheritors(converter: Converte
|
|||||||
myResult = DummyMethodCallExpression(Identifier("this"), "identityEquals", getConverter().elementToElement(expression?.getArgumentList()))
|
myResult = DummyMethodCallExpression(Identifier("this"), "identityEquals", getConverter().elementToElement(expression?.getArgumentList()))
|
||||||
}
|
}
|
||||||
else if (superMethodInvocation(methodExpression, "toString")) {
|
else if (superMethodInvocation(methodExpression, "toString")) {
|
||||||
myResult = DummyStringExpression(String.format("getJavaClass<%s>.getName() + '@' + Integer.toHexString(hashCode())", ExpressionVisitor.getClassName(methodExpression)))
|
myResult = DummyStringExpression(String.format("getJavaClass<%s>.getName() + '@' + Integer.toHexString(hashCode())",
|
||||||
|
ExpressionVisitor.getClassName(methodExpression))!!)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
convertMethodCallExpression(expression!!)
|
convertMethodCallExpression(expression!!)
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ import java.util.List
|
|||||||
import org.jetbrains.jet.j2k.ConverterUtil.countWritingAccesses
|
import org.jetbrains.jet.j2k.ConverterUtil.countWritingAccesses
|
||||||
|
|
||||||
public open class StatementVisitor(converter: Converter): ElementVisitor(converter) {
|
public open class StatementVisitor(converter: Converter): ElementVisitor(converter) {
|
||||||
private var myResult: Statement =
|
private var myResult: Statement = Statement.EMPTY_STATEMENT
|
||||||
|
|
||||||
public override fun getResult(): Statement {
|
public override fun getResult(): Statement {
|
||||||
return myResult
|
return myResult
|
||||||
}
|
}
|
||||||
@@ -97,7 +98,7 @@ public open class StatementVisitor(converter: Converter): ElementVisitor(convert
|
|||||||
BinaryExpression(end, Identifier("1"), "-")
|
BinaryExpression(end, Identifier("1"), "-")
|
||||||
else
|
else
|
||||||
end)
|
end)
|
||||||
myResult = ForeachWithRangeStatement(Identifier(firstChild.getName()),
|
myResult = ForeachWithRangeStatement(Identifier(firstChild.getName()!!),
|
||||||
getConverter().expressionToExpression(firstChild.getInitializer()),
|
getConverter().expressionToExpression(firstChild.getInitializer()),
|
||||||
endExpression,
|
endExpression,
|
||||||
getConverter().statementToStatement(body))
|
getConverter().statementToStatement(body))
|
||||||
|
|||||||
@@ -70,9 +70,8 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val classTypeName : String? = createQualifiedName(classType)
|
val classTypeName = createQualifiedName(classType)
|
||||||
if (classTypeName?.isEmpty().sure())
|
if (classTypeName.isEmpty()) {
|
||||||
{
|
|
||||||
return Identifier(getClassTypeName(classType))
|
return Identifier(getClassTypeName(classType))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,14 +124,13 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
|
|||||||
if (classType is PsiClassReferenceType)
|
if (classType is PsiClassReferenceType)
|
||||||
{
|
{
|
||||||
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 = Identifier(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 = Identifier(p.getReferenceName()).toKotlin() + "." + result
|
result = Identifier(p.getReferenceName()!!).toKotlin() + "." + result
|
||||||
qualifier = p.getQualifier()
|
qualifier = p.getQualifier()
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user