From 453bb8b4f2407bbf82f139a2e30cd9c9fb8867d8 Mon Sep 17 00:00:00 2001 From: Santeri Hiltunen Date: Tue, 29 Jan 2013 16:00:01 +0200 Subject: [PATCH] Changed CRLF line-endings to LF --- src/META-INF/MANIFEST.MF | 6 +- src/org/jetbrains/jet/j2k/Converter.kt | 1696 ++++++++--------- .../jetbrains/jet/j2k/J2KConverterFlags.kt | 16 +- .../jetbrains/jet/j2k/JavaToKotlinCli.java | 292 +-- .../jet/j2k/JavaToKotlinTranslator.java | 468 ++--- .../j2k/SetupJavaCoreEnvironmentException.kt | 46 +- .../jet/j2k/actions/JavaToKotlinAction.kt | 86 +- .../jetbrains/jet/j2k/ast/AnonymousClass.kt | 34 +- .../jet/j2k/ast/ArrayInitializerExpression.kt | 120 +- .../ArrayWithoutInitializationExpression.kt | 78 +- .../jetbrains/jet/j2k/ast/AssertStatement.kt | 24 +- src/org/jetbrains/jet/j2k/ast/Block.kt | 42 +- .../jet/j2k/ast/CallChainExpression.kt | 32 +- src/org/jetbrains/jet/j2k/ast/Class.kt | 304 +-- src/org/jetbrains/jet/j2k/ast/Constructor.kt | 42 +- .../jet/j2k/ast/DummyStringExpression.kt | 12 +- src/org/jetbrains/jet/j2k/ast/Element.kt | 34 +- src/org/jetbrains/jet/j2k/ast/Enum.kt | 68 +- src/org/jetbrains/jet/j2k/ast/EnumConstant.kt | 40 +- src/org/jetbrains/jet/j2k/ast/Expression.kt | 30 +- .../jetbrains/jet/j2k/ast/ExpressionList.kt | 14 +- src/org/jetbrains/jet/j2k/ast/Expressions.kt | 116 +- src/org/jetbrains/jet/j2k/ast/Field.kt | 88 +- src/org/jetbrains/jet/j2k/ast/File.kt | 32 +- src/org/jetbrains/jet/j2k/ast/Function.kt | 142 +- src/org/jetbrains/jet/j2k/ast/Identifier.kt | 62 +- src/org/jetbrains/jet/j2k/ast/Import.kt | 12 +- src/org/jetbrains/jet/j2k/ast/Initializer.kt | 16 +- .../jetbrains/jet/j2k/ast/LocalVariable.kt | 38 +- src/org/jetbrains/jet/j2k/ast/Member.kt | 20 +- .../jet/j2k/ast/MethodCallExpression.kt | 48 +- src/org/jetbrains/jet/j2k/ast/Modifier.kt | 66 +- .../jet/j2k/ast/NewClassExpression.kt | 48 +- src/org/jetbrains/jet/j2k/ast/Node.kt | 22 +- src/org/jetbrains/jet/j2k/ast/Parameter.kt | 36 +- .../jetbrains/jet/j2k/ast/ParameterList.kt | 14 +- .../jet/j2k/ast/PolyadicExpression.kt | 18 +- .../jetbrains/jet/j2k/ast/ReferenceElement.kt | 14 +- src/org/jetbrains/jet/j2k/ast/Statements.kt | 264 +-- src/org/jetbrains/jet/j2k/ast/Trait.kt | 44 +- src/org/jetbrains/jet/j2k/ast/TypeElement.kt | 18 +- .../jetbrains/jet/j2k/ast/TypeParameter.kt | 44 +- src/org/jetbrains/jet/j2k/ast/Util.kt | 56 +- .../jetbrains/jet/j2k/ast/types/ArrayType.kt | 26 +- .../jetbrains/jet/j2k/ast/types/ClassType.kt | 48 +- .../jetbrains/jet/j2k/ast/types/EmptyType.kt | 10 +- .../jet/j2k/ast/types/InProjectionType.kt | 10 +- .../jet/j2k/ast/types/OutProjectionType.kt | 10 +- .../jet/j2k/ast/types/PrimitiveType.kt | 14 +- .../jet/j2k/ast/types/StarProjectionType.kt | 10 +- src/org/jetbrains/jet/j2k/ast/types/Type.kt | 34 +- src/org/jetbrains/jet/j2k/ast/types/VarArg.kt | 14 +- .../jet/j2k/visitors/ClassVisitor.kt | 42 +- .../jetbrains/jet/j2k/visitors/Dispatcher.kt | 14 +- .../jet/j2k/visitors/ElementVisitor.kt | 144 +- .../jet/j2k/visitors/ExpressionVisitor.kt | 980 +++++----- ...ressionVisitorForDirectObjectInheritors.kt | 82 +- .../jet/j2k/visitors/StatementVisitor.kt | 532 +++--- .../jet/j2k/visitors/SuperVisitor.kt | 52 +- .../jetbrains/jet/j2k/visitors/ThisVisitor.kt | 66 +- .../jetbrains/jet/j2k/visitors/TypeVisitor.kt | 324 ++-- .../StandaloneJavaToKotlinConverterTest.java | 356 ++-- .../jetbrains/jet/j2k/TestCaseBuilder.java | 220 +-- .../ast/annotations/file/jetbrainsNotNull.jav | 56 +- .../ast/annotations/file/jetbrainsNotNull.kt | 38 +- .../ast/anonymousBlock/file/oneAnonBlock.kt | 10 +- .../anonymousBlock/file/oneStaticAnonBlock.kt | 14 +- .../statement/doubleArrayWithVariables.kt | 6 +- .../statement/oneDimWithVariables.kt | 6 +- .../ast/arrayType/method/methodArrayArgs.kt | 2 +- .../assignmentExpression/file/nullability.jav | 18 +- .../assignmentExpression/file/nullability.kt | 14 +- tests/testData/ast/boxedType/file/kt-671.kt | 12 +- .../file/libraryFieldCall.kt | 18 +- .../file/libraryMethodCall.kt | 28 +- .../file/libraryMethodCallFromInstance.kt | 30 +- .../file/libraryStringFieldCall.kt | 14 +- .../testData/ast/class/class/abstractClass.kt | 10 +- .../ast/class/class/abstractClassShape.kt | 18 +- tests/testData/ast/class/class/class.kt | 2 +- .../ast/class/class/classWithEmptyMethods.kt | 14 +- .../ast/class/class/classWithFields.kt | 6 +- .../class/class/classWithMultiplyFields.kt | 8 +- tests/testData/ast/class/class/emptyClass.kt | 2 +- ...xtendsOneClassAndImplementsOneInterface.kt | 2 +- ...sOneClassAndImplementsSeveralInterfaces.kt | 2 +- tests/testData/ast/class/class/finalClass.kt | 2 +- .../testData/ast/class/class/genericClass.kt | 2 +- .../ast/class/class/innerEmptyClass.kt | 6 +- .../ast/class/class/innerStaticClass.kt | 10 +- .../testData/ast/class/class/internalClass.kt | 2 +- .../class/class/oneStaticFieldOneNonStatic.kt | 14 +- .../ast/class/class/oneStaticMethod.kt | 12 +- .../class/oneStaticMethodOneNonStatic.kt | 18 +- tests/testData/ast/class/class/pivateClass.kt | 2 +- .../ast/class/class/protectedClass.kt | 2 +- tests/testData/ast/class/class/publicClass.kt | 2 +- .../ast/class/class/simpleInheritance.kt | 2 +- .../ast/class/class/twoStaticMethod.kt | 18 +- tests/testData/ast/class/file/kt-639.kt | 42 +- tests/testData/ast/class/file/privateInit.kt | 6 +- .../expression/simpleConditionalExpression.kt | 6 +- .../ast/constructors/file/allCallsPrimary.kt | 40 +- .../ast/constructors/file/allCallsPrimary2.kt | 64 +- .../ast/constructors/file/customerBuilder.kt | 88 +- .../constructors/file/genericIdentifier.kt | 72 +- .../ast/constructors/file/identifier.kt | 72 +- .../file/withManyDefaultParams.kt | 78 +- .../statement/multiplyFinalIntDeclaration.kt | 4 +- .../statement/multiplyIntDeclaration.kt | 4 +- .../statement/whileWithBlock.kt | 10 +- .../statement/whileWithEmptyBlock.kt | 6 +- .../statement/whileWithExpression.kt | 4 +- .../statement/whileWithReturn.kt | 4 +- tests/testData/ast/enum/class/colorEnum.kt | 26 +- tests/testData/ast/enum/class/emptyEnum.kt | 6 +- .../enum/class/enumImplementsOneInterface.kt | 6 +- .../class/enumImplementsSeveralInterfaces.kt | 6 +- .../ast/enum/class/enumWithNameField.kt | 10 +- .../fieldsWithPrimaryPrivateConstructor.kt | 30 +- tests/testData/ast/enum/class/internalEnum.kt | 6 +- .../ast/enum/class/overrideToString.kt | 22 +- .../enum/class/primaryPrivateConstructor.kt | 22 +- tests/testData/ast/enum/class/privateEnum.kt | 6 +- .../testData/ast/enum/class/protectedEnum.kt | 6 +- tests/testData/ast/enum/class/publicEnum.kt | 6 +- .../ast/enum/class/runnableImplementation.kt | 22 +- tests/testData/ast/enum/class/typeSafeEnum.kt | 14 +- .../ast/field/file/classChildExtendsBase.kt | 10 +- .../testData/ast/field/file/internalField.kt | 4 +- tests/testData/ast/field/file/privateField.kt | 4 +- .../testData/ast/field/file/protectedField.kt | 4 +- tests/testData/ast/field/file/publicField.kt | 4 +- tests/testData/ast/field/file/valWithInit.kt | 4 +- tests/testData/ast/field/file/varWithInit.kt | 4 +- .../testData/ast/field/file/varWithoutInit.kt | 4 +- .../testData/ast/file/comp/intNullability.kt | 16 +- .../ast/file/file/packageWithClass.kt | 4 +- .../ast/file/file/packageWithClasses.kt | 6 +- .../ast/file/file/packageWithImports.kt | 4 +- .../ast/file/file/packageWithMixedImports.kt | 4 +- .../ast/file/file/packageWithOpenClass.kt | 4 +- .../ast/file/file/packageWithStaticImports.kt | 4 +- .../ast/for/statement/commonCaseForTest.kt | 18 +- .../ast/for/statement/forRangeWithLE.kt | 6 +- .../ast/for/statement/forRangeWithLT.kt | 6 +- .../ast/for/statement/forWithBlock.kt | 6 +- .../statement/forWithBlockAndDoubleUpdate.kt | 26 +- .../ast/for/statement/forWithEmptyBlock.kt | 22 +- .../ast/for/statement/forWithReturn.kt | 20 +- .../statement/enhancedForWithBlock.kt | 8 +- .../statement/enhancedForWithEmptyBlock.kt | 4 +- .../statement/enhancedForWithExpression.kt | 2 +- .../statement/enhancedForWithReturn.kt | 2 +- .../file/extendsBaseWhichExtendsObject.kt | 68 +- .../ast/function/file/functionInFinalClass.kt | 8 +- tests/testData/ast/function/file/override.kt | 14 +- .../ast/function/file/overrideAndOpen.kt | 22 +- .../ast/function/file/overrideObject.kt | 34 +- tests/testData/ast/function/file/varVararg.kt | 10 +- .../ast/function/file/writableParameter.kt | 12 +- .../ast/function/method/classGenericParam.kt | 2 +- .../ast/function/method/emptyVoidMethod.kt | 2 +- tests/testData/ast/function/method/final.kt | 4 +- .../testData/ast/function/method/internal.kt | 2 +- tests/testData/ast/function/method/main.kt | 6 +- .../ast/function/method/methodClassType.kt | 2 +- .../function/method/methodPrimitiveType.kt | 2 +- .../function/method/methodPrimitiveType2.kt | 2 +- .../method/methodWithReturnStatement.kt | 4 +- tests/testData/ast/function/method/open.kt | 4 +- .../ast/function/method/ownGenericParam.kt | 2 +- .../method/ownSeveralGenericParams.kt | 2 +- tests/testData/ast/function/method/private.kt | 2 +- .../testData/ast/function/method/protected.kt | 2 +- tests/testData/ast/function/method/public.kt | 2 +- .../identifier/file/finalFieldReference.kt | 24 +- .../ast/identifier/statement/keywords.kt | 20 +- .../statement/ifStatementWithEmptyBlocks.kt | 10 +- .../ifStatementWithMultilineBlocks.kt | 16 +- .../statement/ifStatementWithOneLineBlocks.kt | 6 +- .../statement/ifStatementWithoutElse.kt | 8 +- .../file/importWithKeywords.kt | 6 +- .../importStatement/file/importWithStar.kt | 6 +- .../ast/importStatement/file/simpleImport.kt | 4 +- .../inProjectionType/method/methodParams.kt | 2 +- .../file/classOneExtendsBaseGeneric.kt | 14 +- .../file/classOneExtendsBaseWithOneParam.kt | 6 +- .../file/classOneExtendsBaseWithZeroParams.kt | 6 +- ...dsBaseWithZeroParamsNonEmptyConstructor.kt | 14 +- .../testData/ast/issues/file/arrayLength.jav | 10 +- tests/testData/ast/issues/file/arrayLength.kt | 12 +- tests/testData/ast/issues/file/comments.jav | 44 +- tests/testData/ast/issues/file/comments.kt | 32 +- tests/testData/ast/issues/file/kt-1016.kt | 12 +- tests/testData/ast/issues/file/kt-1048.kt | 26 +- tests/testData/ast/issues/file/kt-1074.kt | 24 +- .../testData/ast/issues/file/kt-543-boxed.kt | 20 +- .../testData/ast/issues/file/kt-543-mixed.kt | 16 +- tests/testData/ast/issues/file/kt-543.kt | 16 +- tests/testData/ast/issues/file/kt-638.kt | 74 +- tests/testData/ast/issues/file/kt-696.kt | 44 +- .../testData/ast/issues/file/kt-792-mixed.kt | 12 +- tests/testData/ast/issues/file/kt-792.kt | 12 +- .../testData/ast/issues/file/kt-794-mixed.kt | 16 +- tests/testData/ast/issues/file/kt-794.kt | 10 +- .../testData/ast/issues/file/kt-809-string.kt | 36 +- tests/testData/ast/issues/file/kt-809.kt | 36 +- .../testData/ast/issues/file/kt-820-field.kt | 22 +- .../testData/ast/issues/file/kt-820-string.kt | 14 +- tests/testData/ast/issues/file/kt-820.kt | 26 +- .../testData/ast/issues/file/kt-824-isDir.kt | 42 +- tests/testData/ast/issues/file/kt-824.kt | 50 +- tests/testData/ast/issues/file/kt-828.kt | 26 +- tests/testData/ast/issues/file/kt-836.kt | 48 +- tests/testData/ast/issues/file/kt-837.kt | 30 +- tests/testData/ast/issues/file/kt-852.kt | 24 +- tests/testData/ast/issues/file/kt-871.kt | 16 +- tests/testData/ast/issues/file/kt-879.kt | 44 +- tests/testData/ast/issues/file/kt-893.kt | 14 +- tests/testData/ast/issues/file/kt-963.kt | 12 +- .../ast/issues/file/qualifyStatic.jav | 14 +- .../testData/ast/issues/file/qualifyStatic.kt | 10 +- .../ast/kotlinExclusion/file/kt-656.kt | 36 +- .../complicatedExampleFromJavaTutorial.kt | 34 +- .../ast/literalExpression/file/char.kt | 10 +- .../file/dollarInsideString.kt | 20 +- .../ast/literalExpression/file/endsWithDFL.kt | 34 +- .../ast/literalExpression/file/hex.kt | 10 +- .../ast/literalExpression/file/octal.kt | 10 +- .../ast/literalExpression/file/trueOrFalse.kt | 14 +- .../file/genericMethod.kt | 20 +- .../expression/newClassWithAnonymousScope.kt | 8 +- .../file/fullQualifiedName.kt | 10 +- .../file/fullQualifiedName2.kt | 10 +- .../file/genericClassInvocation.kt | 10 +- .../file/newClassByFullName.kt | 14 +- .../newClassExpression/file/newInnerClass.kt | 20 +- .../file/newListAndNewMember.kt | 18 +- .../file/newStaticInnerClass.kt | 22 +- .../ast/objectLiteral/file/MyFrame.kt | 34 +- .../outProjectionType/method/methodParams.kt | 2 +- .../file/orgJetbrainsJetJ2kIn.kt | 6 +- .../ast/prefixOperator/statement/excl.kt | 2 +- .../ast/prefixOperator/statement/kt-667.kt | 2 +- .../prefixOperator/statement/nullableIf.jav | 4 +- .../prefixOperator/statement/nullableIf.kt | 6 +- .../ast/prefixOperator/statement/tilde.kt | 2 +- .../ast/rawGenerics/file/kt-540-map.kt | 16 +- .../file/kt-540-rawGenericClass.kt | 24 +- tests/testData/ast/rawGenerics/file/kt-540.kt | 16 +- .../ast/rawGenerics/file/rawGenericMethod.kt | 24 +- .../starProjectionType/method/methodParams.kt | 2 +- .../superExpression/class/classAextendsB.kt | 18 +- .../superExpression/file/classAdotSuperFoo.kt | 18 +- .../ast/switch/file/comlicatedFallDown.kt | 174 +- tests/testData/ast/switch/file/fallDown.kt | 36 +- tests/testData/ast/switch/file/kt-539.kt | 102 +- .../statement/singleLineExample.kt | 4 +- .../thisExpression/file/classAdotThisFoo.kt | 20 +- .../ast/trait/class/abstactInterface.kt | 2 +- .../ast/trait/class/emptyInterface.kt | 2 +- ...sOneClassAndImplementsSeveralInterfaces.kt | 2 +- .../ast/trait/class/extendsOneInterface.kt | 2 +- .../ast/trait/class/interfaceWithFields.kt | 12 +- .../class/interfaceWithMethodDeclaration.kt | 6 +- .../trait/class/interfaceWithStaticFields.kt | 12 +- .../ast/trait/class/internalInterface.kt | 2 +- .../ast/trait/class/privateInterface.kt | 2 +- .../ast/trait/class/protectedInterface.kt | 2 +- .../ast/trait/class/publicInterface.kt | 2 +- .../statement/commonCaseForTryStatement.kt | 26 +- .../emptyTryWithTwoCatchesWithEmptyFinally.kt | 22 +- .../emptyTryWithTwoCatchesWithFinally.kt | 24 +- .../emptyTryWithTwoCatchesWithoutFinally.kt | 16 +- ...rametrizationWithTwoBoundsWithExtending.kt | 2 +- .../classParametrizationWithTwoBounds.kt | 2 +- ...rametrizationWithTwoBoundsWithExtending.kt | 2 +- .../class/complexExampleWithClassExtending.kt | 2 +- ...omplexExampleWithClassMultiplyExtending.kt | 2 +- .../ast/typeParameters/class/genericClass.kt | 2 +- ...rametrizationWithTwoBoundsWithExtending.kt | 2 +- ...ethodDoubleParametrizationWithTwoBounds.kt | 2 +- .../ast/typeParameters/method/where.kt | 2 +- .../varArg/method/ellipsisTypeSingleParams.kt | 2 +- .../statement/whileWithBlock.kt | 8 +- .../statement/whileWithEmptyBlock.kt | 4 +- .../statement/whileWithExpression.kt | 2 +- .../statement/whileWithReturn.kt | 2 +- 289 files changed, 5588 insertions(+), 5588 deletions(-) diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF index 84f4c3093d1..e71f8509eeb 100644 --- a/src/META-INF/MANIFEST.MF +++ b/src/META-INF/MANIFEST.MF @@ -1,3 +1,3 @@ -Manifest-Version: 1.0 -Main-Class: org.jetbrains.jet.j2k.JavaToKotlinCli - +Manifest-Version: 1.0 +Main-Class: org.jetbrains.jet.j2k.JavaToKotlinCli + diff --git a/src/org/jetbrains/jet/j2k/Converter.kt b/src/org/jetbrains/jet/j2k/Converter.kt index 482a92f6b19..0757ac16a72 100644 --- a/src/org/jetbrains/jet/j2k/Converter.kt +++ b/src/org/jetbrains/jet/j2k/Converter.kt @@ -1,848 +1,848 @@ -package org.jetbrains.jet.j2k - -import com.google.common.collect.ImmutableMap -import com.google.common.collect.ImmutableSet -import com.google.common.collect.Sets -import com.intellij.psi.* -import org.jetbrains.annotations.Nullable -import org.jetbrains.jet.j2k.ast.* -import org.jetbrains.jet.j2k.ast.Class -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.visitors.* -import org.jetbrains.jet.lang.types.expressions.OperatorConventions -import java.util.* -import com.intellij.psi.CommonClassNames.* -import org.jetbrains.jet.lang.types.expressions.OperatorConventions.* -import com.intellij.openapi.util.Pair -import java.text.MessageFormat -import com.intellij.psi.util.PsiUtil - -public open class Converter() { - private var classIdentifiers: MutableSet = Sets.newHashSet()!! - private val dispatcher: Dispatcher = Dispatcher(this) - private var methodReturnType: PsiType? = null - private val flags: MutableSet? = Sets.newHashSet() - public open fun addFlag(flag: J2KConverterFlags): Boolean { - return flags?.add(flag)!! - } - public open fun hasFlag(flag: J2KConverterFlags): Boolean { - return flags?.contains(flag)!! - } - - public open fun setClassIdentifiers(identifiers: MutableSet) { - classIdentifiers = identifiers - } - - public open fun getClassIdentifiers(): Set { - return Collections.unmodifiableSet(classIdentifiers)!! - } - - public open fun getMethodReturnType(): PsiType? { - return methodReturnType - } - - public open fun clearClassIdentifiers(): Unit { - classIdentifiers.clear() - } - - public open fun elementToKotlin(element: PsiElement): String { - val kElement = topElementToElement(element) - return kElement?.toKotlin() ?: "" - } - - public open fun topElementToElement(element: PsiElement?): Node? = when(element) { - is PsiJavaFile -> fileToFile(element) - is PsiClass -> classToClass(element) - is PsiMethod -> methodToFunction(element) - is PsiField -> fieldToField(element, element.getContainingClass()) - is PsiStatement -> statementToStatement(element) - is PsiExpression -> expressionToExpression(element) - is PsiComment -> Comment(element.getText()!!) - else -> null - } - - public open fun fileToFile(javaFile: PsiJavaFile): File { - return fileToFile(javaFile, Collections.emptyList()!!) - } - - public open fun fileToFileWithCompatibilityImport(javaFile: PsiJavaFile): File { - return fileToFile(javaFile, Collections.singletonList("kotlin.compatibility.*")!!) - } - - private fun fileToFile(javaFile: PsiJavaFile, additionalImports: List): File { - val importList: PsiImportList? = javaFile.getImportList() - val imports: MutableList = (if (importList == null) - arrayList() - else - ArrayList(importsToImportList(importList.getAllImportStatements()))) - for (i : String in additionalImports) - imports.add(Import(i)) - - val body: ArrayList = arrayList() - for(element in javaFile.getChildren()) { - if (element !is PsiImportStatementBase) { - val node = topElementToElement(element) - if (node != null) { - body.add(node) - } - } - } - return File(quoteKeywords(javaFile.getPackageName()), imports, body, createMainFunction(javaFile)) - } - - public open fun anonymousClassToAnonymousClass(anonymousClass: PsiAnonymousClass): AnonymousClass { - return AnonymousClass(this, getMembers(anonymousClass)) - } - - private fun getMembers(psiClass: PsiClass): MutableList { - val members = ArrayList() - val lbraceOffset = psiClass.getLBrace()?.getTextRange()?.getStartOffset() ?: 0 - for (e : PsiElement? in psiClass.getChildren()) { - val isDocComment = e?.getTextRange()?.getStartOffset() ?: 0 < lbraceOffset - if (isDocComment) continue - val converted = memberToMember(e, psiClass) - if (converted != null) members.add(converted) - } - return members - } - - private fun getDocComments(element: PsiElement): List { - val comments = ArrayList() - val textOffset = element.getTextOffset() - for (e : PsiElement? in element.getChildren()) { - if (e is PsiComment && e.getTextRange()?.getStartOffset() ?: 0 < textOffset) { - comments.add(Comment(e.getText()!!)); - } - } - return comments - } - - private fun memberToMember(e: PsiElement?, containingClass: PsiClass): Node? = when(e) { - is PsiMethod -> methodToFunction(e, true) - is PsiField -> fieldToField(e, containingClass) - is PsiClass -> classToClass(e) - is PsiClassInitializer -> initializerToInitializer(e) - is PsiComment -> Comment(e.getText()!!) - else -> null - } - - private fun classToClass(psiClass: PsiClass): Class { - val modifiers: Set = modifiersListToModifiersSet(psiClass.getModifierList()) - val fields: List = fieldsToFieldList(psiClass.getFields(), psiClass) - val typeParameters: List = elementsToElementList(psiClass.getTypeParameters()) - val implementsTypes: List = typesToNotNullableTypeList(psiClass.getImplementsListTypes()) - val extendsTypes: List = typesToNotNullableTypeList(psiClass.getExtendsListTypes()) - val name: Identifier = Identifier(psiClass.getName()!!) - val baseClassParams= ArrayList() - val members = getMembers(psiClass) - val docComments = getDocComments(psiClass) - val visitor: SuperVisitor = SuperVisitor() - psiClass.accept(visitor) - val resolvedSuperCallParameters = visitor.resolvedSuperCallParameters - if (resolvedSuperCallParameters.size() == 1) { - val psiExpressionList = resolvedSuperCallParameters.iterator().next() - baseClassParams.addAll(expressionsToExpressionList(psiExpressionList.getExpressions())) - } - - if (!psiClass.isEnum() && !psiClass.isInterface() && psiClass.getConstructors().size > 1 && - getPrimaryConstructorForThisCase(psiClass) == null) { - val finalOrWithEmptyInitializer: List = getFinalOrWithEmptyInitializer(fields) - val initializers = HashMap() - for (m in members) { - if (m is Constructor) { - if (!m.isPrimary) { - for (fo in finalOrWithEmptyInitializer){ - val init: String = getDefaultInitializer(fo) - initializers.put(fo.identifier.toKotlin(), init) - } - val newStatements = ArrayList() - for (s in m.block!!.statements) { - var isRemoved: Boolean = false - if (s is AssignmentExpression) { - val assignee = s.left - if (assignee is CallChainExpression) { - for (fo : Field in finalOrWithEmptyInitializer) { - val id: String = fo.identifier.toKotlin() - if (assignee.identifier.toKotlin().endsWith("." + id)) { - initializers.put(id, s.right.toKotlin()) - isRemoved = true - } - - } - } - - } - - if (!isRemoved) { - newStatements.add(s) - } - - } - newStatements.add(0, DummyStringExpression("val __ = " + createPrimaryConstructorInvocation(name.toKotlin(), finalOrWithEmptyInitializer, initializers))) - m.block = Block(newStatements) - } - } - } - members.add(Constructor(Identifier.EMPTY_IDENTIFIER, arrayList(), Collections.emptySet()!!, - ClassType(name, Collections.emptyList()!!, false), - Collections.emptyList()!!, - ParameterList(createParametersFromFields(finalOrWithEmptyInitializer)), - Block(createInitStatementsFromFields(finalOrWithEmptyInitializer)), - true)) - } - - if (psiClass.isInterface()) { - return Trait(this, name, docComments, modifiers, typeParameters, extendsTypes, Collections.emptyList()!!, implementsTypes, members) - } - - if (psiClass.isEnum()) { - return Enum(this, name, docComments, modifiers, typeParameters, Collections.emptyList()!!, Collections.emptyList()!!, implementsTypes, members) - } - - return Class(this, name, docComments, modifiers, typeParameters, extendsTypes, baseClassParams, implementsTypes, members) - } - - private fun initializerToInitializer(i: PsiClassInitializer): Initializer { - return Initializer(blockToBlock(i.getBody(), true), modifiersListToModifiersSet(i.getModifierList())) - } - - private fun fieldsToFieldList(fields: Array, psiClass: PsiClass): List { - return fields.map { fieldToField(it!!, psiClass) } - } - - private fun fieldToField(field: PsiField, psiClass: PsiClass?): Field { - val modifiers = modifiersListToModifiersSet(field.getModifierList()) - val docComments = getDocComments(field) - if (field is PsiEnumConstant) { - return EnumConstant(Identifier(field.getName()!!), - docComments, - modifiers, - typeToType(field.getType()), - elementToElement(field.getArgumentList())) - } - - var kType = typeToType(field.getType()) - if (field.hasModifierProperty(PsiModifier.FINAL) && isDefinitelyNotNull(field.getInitializer())) { - kType = kType.convertedToNotNull(); - } - - return Field(Identifier(field.getName()!!), - docComments, - modifiers, - kType, - expressionToExpression(field.getInitializer(), field.getType()), - countWritingAccesses(field, psiClass)) - } - - private fun methodToFunction(method: PsiMethod): Function { - return methodToFunction(method, true) - } - - private fun methodToFunction(method: PsiMethod, notEmpty: Boolean): Function { - if (isOverrideObjectDirect(method)) { - dispatcher.expressionVisitor = ExpressionVisitorForDirectObjectInheritors(this) - } - else { - dispatcher.expressionVisitor = ExpressionVisitor(this) - } - methodReturnType = method.getReturnType() - val identifier: Identifier = Identifier(method.getName()) - val returnType: Type = typeToType(method.getReturnType(), isAnnotatedAsNotNull(method.getModifierList())) - val body: Block = (if (hasFlag(J2KConverterFlags.SKIP_BODIES)) - Block.EMPTY_BLOCK - else - blockToBlock(method.getBody(), notEmpty)) - - val params: Element = createFunctionParameters(method) - val typeParameters = elementsToElementList(method.getTypeParameters()) - val modifiers = modifiersListToModifiersSet(method.getModifierList()) - val docComments = getDocComments(method) - if (isOverrideAnyMethodExceptMethodsFromObject(method)) { - modifiers.add(Modifier.OVERRIDE) - } - - val containingClass = method.getContainingClass() - if (containingClass != null && containingClass.isInterface()) { - modifiers.remove(Modifier.ABSTRACT) - } - - if (isNotOpenMethod(method)) { - modifiers.add(Modifier.NOT_OPEN) - } - - if (method.isConstructor()) { - val isPrimary: Boolean = isConstructorPrimary(method) - return Constructor(identifier, docComments, modifiers, returnType, typeParameters, params, - Block(removeEmpty(body.statements), false), isPrimary) - } - - return Function(identifier, docComments, modifiers, returnType, typeParameters, params, body) - } - - private fun createFunctionParameters(method: PsiMethod): ParameterList { - val result = ArrayList() - for (parameter : PsiParameter? in method.getParameterList().getParameters()) { - result.add(Parameter(Identifier(parameter?.getName()!!), - typeToType(parameter?.getType(), - isAnnotatedAsNotNull(parameter?.getModifierList())), - isReadOnly(parameter, method.getBody()))) - } - return ParameterList(result) - } - - private fun isOverrideAnyMethodExceptMethodsFromObject(method: PsiMethod): Boolean { - var counter: Boolean = normalCase(method) - if (counter) - { - return true - } - - if (isInheritFromObject(method)) - { - return caseForObject(method) - } - - return false - } - - private fun caseForObject(method: PsiMethod): Boolean { - val containing: PsiClass? = method.getContainingClass() - if (containing != null) { - for (s : PsiClassType? in containing.getSuperTypes()) { - val canonicalText: String? = s?.getCanonicalText() - if (canonicalText != JAVA_LANG_OBJECT && !getClassIdentifiers().contains(canonicalText)) { - return true - } - } - } - - return false - } - public open fun blockToBlock(block: PsiCodeBlock?, notEmpty: Boolean): Block { - if (block == null) - return Block.EMPTY_BLOCK - - return Block(removeEmpty(statementsToStatementList(block.getChildren())), notEmpty) - } - - public open fun blockToBlock(block: PsiCodeBlock?): Block { - return blockToBlock(block, true) - } - - public open fun statementsToStatementList(statements: Array): List { - return statements.filterNot { it is PsiWhiteSpace }.map { statementToStatement(it) } - } - - public open fun statementsToStatementList(statements: List): List { - return statements.filterNot { it is PsiWhiteSpace }.map { statementToStatement(it) } - } - - public open fun statementToStatement(s: PsiElement?): Element { - if (s == null) - return Statement.EMPTY_STATEMENT - - val statementVisitor: StatementVisitor = StatementVisitor(this) - s.accept(statementVisitor) - return statementVisitor.getResult() - } - - public open fun expressionsToExpressionList(expressions: Array): List { - val result = ArrayList() - for (e : PsiExpression? in expressions) - result.add(expressionToExpression(e)) - return result - } - - public open fun expressionToExpression(e: PsiExpression?): Expression { - if (e == null) - return Expression.EMPTY_EXPRESSION - - val expressionVisitor: ExpressionVisitor = dispatcher.expressionVisitor - e.accept(expressionVisitor) - return expressionVisitor.getResult() - } - - public open fun elementToElement(e: PsiElement?): Element { - if (e == null) - return Element.EMPTY_ELEMENT - - val elementVisitor: ElementVisitor = ElementVisitor(this) - e.accept(elementVisitor) - return elementVisitor.getResult() - } - - public open fun elementsToElementList(elements: Array): List { - val result = ArrayList() - for(element in elements) { - result.add(elementToElement(element)) - } - return result - } - - public open fun typeElementToTypeElement(element: PsiTypeElement?): TypeElement { - return TypeElement(if (element == null) - EmptyType() - else - typeToType(element.getType())) - } - - public open fun typeToType(`type`: PsiType?): Type { - if (`type` == null) - return EmptyType() - - val typeVisitor: TypeVisitor = TypeVisitor(this) - `type`.accept(typeVisitor) - return typeVisitor.getResult() - } - - public open fun typesToTypeList(types: Array): List { - return types.map { typeToType(it) } - } - - public open fun typeToType(`type`: PsiType?, notNull: Boolean): Type { - val result: Type = typeToType(`type`) - if (notNull) { - return result.convertedToNotNull() - } - - return result - } - - private fun typesToNotNullableTypeList(types: Array): List { - val result = ArrayList() - for(aType in types) { - result.add(typeToType(aType).convertedToNotNull()) - } - return result - } - - public open fun parametersToParameterList(parameters: Array): List { - return parameters.map { parameterToParameter(it!!) } - } - - public open fun parameterToParameter(parameter: PsiParameter, forceNotNull: Boolean = false): Parameter { - return Parameter(Identifier(parameter.getName()!!), - typeToType(parameter.getType(), - forceNotNull || isAnnotatedAsNotNull(parameter.getModifierList())), true) - } - - public open fun argumentsToExpressionList(expression: PsiCallExpression): List { - val argumentList: PsiExpressionList? = expression.getArgumentList() - val arguments: Array = (if (argumentList != null) - argumentList.getExpressions() - else - PsiExpression.EMPTY_ARRAY) - val result = ArrayList() - val resolved: PsiMethod? = expression.resolveMethod() - val expectedTypes = ArrayList() - if (resolved != null) { - for (p : PsiParameter? in resolved.getParameterList().getParameters()) - expectedTypes.add(p?.getType()) - } - - if (arguments.size == expectedTypes.size()) { - for (i in 0..expectedTypes.size() - 1) result.add(expressionToExpression(arguments[i], expectedTypes.get(i))) - } - else { - for (argument : PsiExpression? in arguments) { - result.add(expressionToExpression(argument)) - } - } - return result - } - - public open fun expressionToExpression(argument: PsiExpression?, expectedType: PsiType?): Expression { - if (argument == null) - return Identifier.EMPTY_IDENTIFIER - - var expression: Expression = expressionToExpression(argument) - val actualType: PsiType? = argument.getType() - val isPrimitiveTypeOrNull: Boolean = actualType == null || actualType is PsiPrimitiveType - if (isPrimitiveTypeOrNull && expression.isNullable()) { - expression = BangBangExpression(expression) - } - - if (actualType != null) { - if (isConversionNeeded(actualType, expectedType) && !(expression is LiteralExpression)) - { - val conversion: String? = PRIMITIVE_TYPE_CONVERSIONS.get(expectedType?.getCanonicalText()) - if (conversion != null) { - expression = MethodCallExpression.build(expression, conversion) - } - } - - } - - return expression - } - - class object { - public val NOT_NULL_ANNOTATIONS: Set = ImmutableSet.of("org.jetbrains.annotations.NotNull", "com.sun.istack.internal.NotNull", "javax.annotation.Nonnull")!! - public val PRIMITIVE_TYPE_CONVERSIONS: Map = ImmutableMap.builder() - ?.put("byte", BYTE.getName()) - ?.put("short", SHORT.getName()) - ?.put("int", INT.getName()) - ?.put("long", LONG.getName()) - ?.put("float", FLOAT.getName()) - ?.put("double", DOUBLE.getName()) - ?.put("char", CHAR.getName()) - ?.put(JAVA_LANG_BYTE, BYTE.getName()) - ?.put(JAVA_LANG_SHORT, SHORT.getName()) - ?.put(JAVA_LANG_INTEGER, INT.getName()) - ?.put(JAVA_LANG_LONG, LONG.getName()) - ?.put(JAVA_LANG_FLOAT, FLOAT.getName()) - ?.put(JAVA_LANG_DOUBLE, DOUBLE.getName()) - ?.put(JAVA_LANG_CHARACTER, CHAR.getName()) - ?.build()!! - - private fun quoteKeywords(packageName: String): String { - return packageName.split("\\.").map { Identifier(it).toKotlin() }.makeString(".") - } - - private fun getFinalOrWithEmptyInitializer(fields: List): List { - val result = ArrayList() - for (f : Field in fields) - if (f.isVal() || f.initializer.toKotlin().isEmpty()) { - result.add(f) - } - - return result - } - - private fun createParametersFromFields(fields: List): List { - return fields.map { Parameter(Identifier("_" + it.identifier.name), it.`type`, true) } - } - - private fun createInitStatementsFromFields(fields: List): List { - val result = ArrayList() - for (f : Field in fields) { - val identifierToKotlin: String? = f.identifier.toKotlin() - result.add(DummyStringExpression(identifierToKotlin + " = " + "_" + identifierToKotlin)) - } - return result - } - - private fun createPrimaryConstructorInvocation(s: String, fields: List, initializers: Map): String { - return s + "(" + fields.map { initializers[it.identifier.toKotlin()] }.makeString(", ") + ")" - } - - public open fun getDefaultInitializer(f: Field): String { - if (f.`type`.nullable) { - return "null" - } - else { - val typeToKotlin: String = f.`type`.toKotlin() - if (typeToKotlin.equals("Boolean")) - return "false" - - if (typeToKotlin.equals("Char")) - return "' '" - - if (typeToKotlin.equals("Double")) - return "0." + OperatorConventions.DOUBLE + "()" - - if (typeToKotlin.equals("Float")) - return "0." + OperatorConventions.FLOAT + "()" - - return "0" - } - } - - private fun getPrimaryConstructorForThisCase(psiClass: PsiClass): PsiMethod? { - val tv = ThisVisitor() - psiClass.accept(tv) - return tv.getPrimaryConstructor() - } - - public open fun isConstructorPrimary(constructor: PsiMethod): Boolean { - val parent = constructor.getParent() - if (parent is PsiClass) { - if (parent.getConstructors().size == 1) { - return true - } - else { - val c: PsiMethod? = getPrimaryConstructorForThisCase(parent) - if (c != null && c.hashCode() == constructor.hashCode()) { - return true - } - - } - } - - return false - } - private fun removeEmpty(statements: List): List { - return statements.filterNot { it == Statement.EMPTY_STATEMENT || - it == Expression.EMPTY_EXPRESSION || - it == Element.EMPTY_ELEMENT } - } - - private fun isNotOpenMethod(method: PsiMethod): Boolean { - val parent = method.getParent() - if (parent is PsiClass) { - val parentModifierList: PsiModifierList? = parent.getModifierList() - if ((parentModifierList != null && parentModifierList.hasExplicitModifier(PsiModifier.FINAL)) || parent.isEnum()) { - return true - } - - } - - return false - } - - private fun normalCase(method: PsiMethod): Boolean { - var counter: Int = 0 - for (s : HierarchicalMethodSignature? in method.getHierarchicalMethodSignature().getSuperSignatures()) - { - var containingClass: PsiClass? = s?.getMethod()?.getContainingClass() - var qualifiedName: String? = (if (containingClass != null) - containingClass?.getQualifiedName() - else - "") - if (qualifiedName != null && !qualifiedName.equals(JAVA_LANG_OBJECT)) - { - counter++ - } - - } - return counter > 0 - } - - private fun isInheritFromObject(method: PsiMethod): Boolean { - var superSignatures: List = method.getHierarchicalMethodSignature().getSuperSignatures()!! - for (s : HierarchicalMethodSignature? in superSignatures) { - var containingClass: PsiClass? = s?.getMethod()?.getContainingClass() - var qualifiedName: String? = (if (containingClass != null) - containingClass?.getQualifiedName() - else - "") - if (qualifiedName == JAVA_LANG_OBJECT) { - return true - } - - } - return false - } - - private fun isOverrideObjectDirect(method: PsiMethod): Boolean { - var superSignatures: List? = method.getHierarchicalMethodSignature().getSuperSignatures() - if (superSignatures?.size()!! == 1) - { - val containingClass: PsiClass? = superSignatures?.get(0)?.getMethod()?.getContainingClass() - val qualifiedName: String? = (if (containingClass != null) - containingClass.getQualifiedName() - else - "") - if (qualifiedName == JAVA_LANG_OBJECT) { - return true - } - - } - - return false - } - private fun importsToImportList(imports: Array): List { - val result = ArrayList() - for (i : PsiImportStatementBase? in imports) { - if (i == null) continue - val anImport: Import = importToImport(i) - val name: String = anImport.name - if (!name.isEmpty() && !NOT_NULL_ANNOTATIONS.contains(name)) { - result.add(anImport) - } - - } - return result - } - - private fun importToImport(i: PsiImportStatementBase): Import { - val reference: PsiJavaCodeReferenceElement? = i.getImportReference() - if (reference != null) { - return Import(quoteKeywords(reference.getQualifiedName()!!) + ((if (i.isOnDemand()) - ".*" - else - ""))) - } - - return Import("") - } - - public open fun identifierToIdentifier(identifier: PsiIdentifier?): Identifier { - if (identifier == null) - return Identifier.EMPTY_IDENTIFIER - - return Identifier(identifier.getText()!!) - } - - public open fun modifiersListToModifiersSet(modifierList: PsiModifierList?): MutableSet { - val modifiersSet: HashSet = hashSet() - if (modifierList != null) { - if (modifierList.hasExplicitModifier(PsiModifier.ABSTRACT)) - modifiersSet.add(Modifier.ABSTRACT) - - if (modifierList.hasModifierProperty(PsiModifier.FINAL)) - modifiersSet.add(Modifier.FINAL) - - if (modifierList.hasModifierProperty(PsiModifier.STATIC)) - modifiersSet.add(Modifier.STATIC) - - if (modifierList.hasExplicitModifier(PsiModifier.PUBLIC)) - modifiersSet.add(Modifier.PUBLIC) - - if (modifierList.hasExplicitModifier(PsiModifier.PROTECTED)) - modifiersSet.add(Modifier.PROTECTED) - - if (modifierList.hasExplicitModifier(PsiModifier.PACKAGE_LOCAL)) - modifiersSet.add(Modifier.INTERNAL) - - if (modifierList.hasExplicitModifier(PsiModifier.PRIVATE)) - modifiersSet.add(Modifier.PRIVATE) - } - - return modifiersSet - } - - private fun isConversionNeeded(actual: PsiType?, expected: PsiType?): Boolean { - if (actual == null || expected == null) { - return false - } - - val typeMap = HashMap() - typeMap.put(JAVA_LANG_BYTE, "byte") - typeMap.put(JAVA_LANG_SHORT, "short") - typeMap.put(JAVA_LANG_INTEGER, "int") - typeMap.put(JAVA_LANG_LONG, "long") - typeMap.put(JAVA_LANG_FLOAT, "float") - typeMap.put(JAVA_LANG_DOUBLE, "double") - typeMap.put(JAVA_LANG_CHARACTER, "char") - val expectedStr: String? = expected.getCanonicalText() - val actualStr: String? = actual.getCanonicalText() - val o1: Boolean = expectedStr == typeMap[actualStr] - val o2: Boolean = actualStr == typeMap[expectedStr] - return actualStr != expectedStr && (!(o1 xor o2)) - } - } -} - -public fun createMainFunction(file: PsiFile): String { - val classNamesWithMains = ArrayList?>() - for (c : PsiClass? in (file as PsiJavaFile).getClasses()) { - var main: PsiMethod? = findMainMethod(c) - if (main != null) { - classNamesWithMains.add(Pair(c?.getName(), main)) - } - } - - if (classNamesWithMains.size() > 0) { - var className: String? = classNamesWithMains.get(0)?.getFirst() - return MessageFormat.format("fun main(args : Array?) = {0}.main(args)", className)!! - } - - return "" - -} - -private fun findMainMethod(aClass: PsiClass?): PsiMethod? { - if (isMainClass(aClass)) { - val mainMethods: Array? = aClass?.findMethodsByName("main", false) - if (mainMethods != null) { - return findMainMethod(mainMethods) - } - } - return null -} - -private fun isMainClass(psiClass: PsiClass?): Boolean { - if (psiClass == null || psiClass is PsiAnonymousClass) - return false - - if (psiClass.isInterface()) - return false - - return psiClass.getContainingClass() == null || psiClass.hasModifierProperty(PsiModifier.STATIC) - -} - -private fun findMainMethod(mainMethods: Array): PsiMethod? { - return mainMethods.find { isMainMethod(it) } -} - -public fun isMainMethod(method: PsiMethod?): Boolean { - if (method == null || method.getContainingClass() == null) - return false - - if (PsiType.VOID != method.getReturnType()) - return false - - if (!method.hasModifierProperty(PsiModifier.STATIC)) - return false - - if (!method.hasModifierProperty(PsiModifier.PUBLIC)) - return false - - val parameters: Array? = method.getParameterList().getParameters() - if (parameters?.size!! != 1) - return false - - val `type`: PsiType? = parameters!![0]?.getType() - if (`type` !is PsiArrayType) - return false - - val componentType: PsiType? = `type`.getComponentType() - return componentType?.equalsToText("java.lang.String")!! -} - -public fun countWritingAccesses(element: PsiElement?, container: PsiElement?): Int { - var counter: Int = 0 - if (container != null) { - val visitor: ReferenceCollector = ReferenceCollector() - container.accept(visitor) - for (e : PsiReferenceExpression in visitor.getCollectedReferences()) - if (e?.isReferenceTo(element)!! && PsiUtil.isAccessedForWriting(e)) { - counter++ - } - } - - return counter -} - -open class ReferenceCollector(): JavaRecursiveElementVisitor() { - private val myCollectedReferences = ArrayList() - - public open fun getCollectedReferences(): List { - return myCollectedReferences - } - - public override fun visitReferenceExpression(expression: PsiReferenceExpression?): Unit { - super.visitReferenceExpression(expression) - if (expression != null) { - myCollectedReferences.add(expression) - } - } -} - -public fun isReadOnly(element: PsiElement?, container: PsiElement?): Boolean { - return countWritingAccesses(element, container) == 0 -} - -public fun isAnnotatedAsNotNull(modifierList: PsiModifierList?): Boolean { - if (modifierList != null) { - val annotations: Array = modifierList.getAnnotations() - for (a : PsiAnnotation in annotations) { - val qualifiedName: String? = a?.getQualifiedName() - if (qualifiedName != null && Converter.NOT_NULL_ANNOTATIONS.contains(qualifiedName)) { - return true - } - } - } - return false -} - -public fun isDefinitelyNotNull(element: PsiElement?): Boolean = when(element) { - is PsiLiteralExpression -> element.getValue() != null - is PsiNewExpression -> true - else -> false -} +package org.jetbrains.jet.j2k + +import com.google.common.collect.ImmutableMap +import com.google.common.collect.ImmutableSet +import com.google.common.collect.Sets +import com.intellij.psi.* +import org.jetbrains.annotations.Nullable +import org.jetbrains.jet.j2k.ast.* +import org.jetbrains.jet.j2k.ast.Class +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.visitors.* +import org.jetbrains.jet.lang.types.expressions.OperatorConventions +import java.util.* +import com.intellij.psi.CommonClassNames.* +import org.jetbrains.jet.lang.types.expressions.OperatorConventions.* +import com.intellij.openapi.util.Pair +import java.text.MessageFormat +import com.intellij.psi.util.PsiUtil + +public open class Converter() { + private var classIdentifiers: MutableSet = Sets.newHashSet()!! + private val dispatcher: Dispatcher = Dispatcher(this) + private var methodReturnType: PsiType? = null + private val flags: MutableSet? = Sets.newHashSet() + public open fun addFlag(flag: J2KConverterFlags): Boolean { + return flags?.add(flag)!! + } + public open fun hasFlag(flag: J2KConverterFlags): Boolean { + return flags?.contains(flag)!! + } + + public open fun setClassIdentifiers(identifiers: MutableSet) { + classIdentifiers = identifiers + } + + public open fun getClassIdentifiers(): Set { + return Collections.unmodifiableSet(classIdentifiers)!! + } + + public open fun getMethodReturnType(): PsiType? { + return methodReturnType + } + + public open fun clearClassIdentifiers(): Unit { + classIdentifiers.clear() + } + + public open fun elementToKotlin(element: PsiElement): String { + val kElement = topElementToElement(element) + return kElement?.toKotlin() ?: "" + } + + public open fun topElementToElement(element: PsiElement?): Node? = when(element) { + is PsiJavaFile -> fileToFile(element) + is PsiClass -> classToClass(element) + is PsiMethod -> methodToFunction(element) + is PsiField -> fieldToField(element, element.getContainingClass()) + is PsiStatement -> statementToStatement(element) + is PsiExpression -> expressionToExpression(element) + is PsiComment -> Comment(element.getText()!!) + else -> null + } + + public open fun fileToFile(javaFile: PsiJavaFile): File { + return fileToFile(javaFile, Collections.emptyList()!!) + } + + public open fun fileToFileWithCompatibilityImport(javaFile: PsiJavaFile): File { + return fileToFile(javaFile, Collections.singletonList("kotlin.compatibility.*")!!) + } + + private fun fileToFile(javaFile: PsiJavaFile, additionalImports: List): File { + val importList: PsiImportList? = javaFile.getImportList() + val imports: MutableList = (if (importList == null) + arrayList() + else + ArrayList(importsToImportList(importList.getAllImportStatements()))) + for (i : String in additionalImports) + imports.add(Import(i)) + + val body: ArrayList = arrayList() + for(element in javaFile.getChildren()) { + if (element !is PsiImportStatementBase) { + val node = topElementToElement(element) + if (node != null) { + body.add(node) + } + } + } + return File(quoteKeywords(javaFile.getPackageName()), imports, body, createMainFunction(javaFile)) + } + + public open fun anonymousClassToAnonymousClass(anonymousClass: PsiAnonymousClass): AnonymousClass { + return AnonymousClass(this, getMembers(anonymousClass)) + } + + private fun getMembers(psiClass: PsiClass): MutableList { + val members = ArrayList() + val lbraceOffset = psiClass.getLBrace()?.getTextRange()?.getStartOffset() ?: 0 + for (e : PsiElement? in psiClass.getChildren()) { + val isDocComment = e?.getTextRange()?.getStartOffset() ?: 0 < lbraceOffset + if (isDocComment) continue + val converted = memberToMember(e, psiClass) + if (converted != null) members.add(converted) + } + return members + } + + private fun getDocComments(element: PsiElement): List { + val comments = ArrayList() + val textOffset = element.getTextOffset() + for (e : PsiElement? in element.getChildren()) { + if (e is PsiComment && e.getTextRange()?.getStartOffset() ?: 0 < textOffset) { + comments.add(Comment(e.getText()!!)); + } + } + return comments + } + + private fun memberToMember(e: PsiElement?, containingClass: PsiClass): Node? = when(e) { + is PsiMethod -> methodToFunction(e, true) + is PsiField -> fieldToField(e, containingClass) + is PsiClass -> classToClass(e) + is PsiClassInitializer -> initializerToInitializer(e) + is PsiComment -> Comment(e.getText()!!) + else -> null + } + + private fun classToClass(psiClass: PsiClass): Class { + val modifiers: Set = modifiersListToModifiersSet(psiClass.getModifierList()) + val fields: List = fieldsToFieldList(psiClass.getFields(), psiClass) + val typeParameters: List = elementsToElementList(psiClass.getTypeParameters()) + val implementsTypes: List = typesToNotNullableTypeList(psiClass.getImplementsListTypes()) + val extendsTypes: List = typesToNotNullableTypeList(psiClass.getExtendsListTypes()) + val name: Identifier = Identifier(psiClass.getName()!!) + val baseClassParams= ArrayList() + val members = getMembers(psiClass) + val docComments = getDocComments(psiClass) + val visitor: SuperVisitor = SuperVisitor() + psiClass.accept(visitor) + val resolvedSuperCallParameters = visitor.resolvedSuperCallParameters + if (resolvedSuperCallParameters.size() == 1) { + val psiExpressionList = resolvedSuperCallParameters.iterator().next() + baseClassParams.addAll(expressionsToExpressionList(psiExpressionList.getExpressions())) + } + + if (!psiClass.isEnum() && !psiClass.isInterface() && psiClass.getConstructors().size > 1 && + getPrimaryConstructorForThisCase(psiClass) == null) { + val finalOrWithEmptyInitializer: List = getFinalOrWithEmptyInitializer(fields) + val initializers = HashMap() + for (m in members) { + if (m is Constructor) { + if (!m.isPrimary) { + for (fo in finalOrWithEmptyInitializer){ + val init: String = getDefaultInitializer(fo) + initializers.put(fo.identifier.toKotlin(), init) + } + val newStatements = ArrayList() + for (s in m.block!!.statements) { + var isRemoved: Boolean = false + if (s is AssignmentExpression) { + val assignee = s.left + if (assignee is CallChainExpression) { + for (fo : Field in finalOrWithEmptyInitializer) { + val id: String = fo.identifier.toKotlin() + if (assignee.identifier.toKotlin().endsWith("." + id)) { + initializers.put(id, s.right.toKotlin()) + isRemoved = true + } + + } + } + + } + + if (!isRemoved) { + newStatements.add(s) + } + + } + newStatements.add(0, DummyStringExpression("val __ = " + createPrimaryConstructorInvocation(name.toKotlin(), finalOrWithEmptyInitializer, initializers))) + m.block = Block(newStatements) + } + } + } + members.add(Constructor(Identifier.EMPTY_IDENTIFIER, arrayList(), Collections.emptySet()!!, + ClassType(name, Collections.emptyList()!!, false), + Collections.emptyList()!!, + ParameterList(createParametersFromFields(finalOrWithEmptyInitializer)), + Block(createInitStatementsFromFields(finalOrWithEmptyInitializer)), + true)) + } + + if (psiClass.isInterface()) { + return Trait(this, name, docComments, modifiers, typeParameters, extendsTypes, Collections.emptyList()!!, implementsTypes, members) + } + + if (psiClass.isEnum()) { + return Enum(this, name, docComments, modifiers, typeParameters, Collections.emptyList()!!, Collections.emptyList()!!, implementsTypes, members) + } + + return Class(this, name, docComments, modifiers, typeParameters, extendsTypes, baseClassParams, implementsTypes, members) + } + + private fun initializerToInitializer(i: PsiClassInitializer): Initializer { + return Initializer(blockToBlock(i.getBody(), true), modifiersListToModifiersSet(i.getModifierList())) + } + + private fun fieldsToFieldList(fields: Array, psiClass: PsiClass): List { + return fields.map { fieldToField(it!!, psiClass) } + } + + private fun fieldToField(field: PsiField, psiClass: PsiClass?): Field { + val modifiers = modifiersListToModifiersSet(field.getModifierList()) + val docComments = getDocComments(field) + if (field is PsiEnumConstant) { + return EnumConstant(Identifier(field.getName()!!), + docComments, + modifiers, + typeToType(field.getType()), + elementToElement(field.getArgumentList())) + } + + var kType = typeToType(field.getType()) + if (field.hasModifierProperty(PsiModifier.FINAL) && isDefinitelyNotNull(field.getInitializer())) { + kType = kType.convertedToNotNull(); + } + + return Field(Identifier(field.getName()!!), + docComments, + modifiers, + kType, + expressionToExpression(field.getInitializer(), field.getType()), + countWritingAccesses(field, psiClass)) + } + + private fun methodToFunction(method: PsiMethod): Function { + return methodToFunction(method, true) + } + + private fun methodToFunction(method: PsiMethod, notEmpty: Boolean): Function { + if (isOverrideObjectDirect(method)) { + dispatcher.expressionVisitor = ExpressionVisitorForDirectObjectInheritors(this) + } + else { + dispatcher.expressionVisitor = ExpressionVisitor(this) + } + methodReturnType = method.getReturnType() + val identifier: Identifier = Identifier(method.getName()) + val returnType: Type = typeToType(method.getReturnType(), isAnnotatedAsNotNull(method.getModifierList())) + val body: Block = (if (hasFlag(J2KConverterFlags.SKIP_BODIES)) + Block.EMPTY_BLOCK + else + blockToBlock(method.getBody(), notEmpty)) + + val params: Element = createFunctionParameters(method) + val typeParameters = elementsToElementList(method.getTypeParameters()) + val modifiers = modifiersListToModifiersSet(method.getModifierList()) + val docComments = getDocComments(method) + if (isOverrideAnyMethodExceptMethodsFromObject(method)) { + modifiers.add(Modifier.OVERRIDE) + } + + val containingClass = method.getContainingClass() + if (containingClass != null && containingClass.isInterface()) { + modifiers.remove(Modifier.ABSTRACT) + } + + if (isNotOpenMethod(method)) { + modifiers.add(Modifier.NOT_OPEN) + } + + if (method.isConstructor()) { + val isPrimary: Boolean = isConstructorPrimary(method) + return Constructor(identifier, docComments, modifiers, returnType, typeParameters, params, + Block(removeEmpty(body.statements), false), isPrimary) + } + + return Function(identifier, docComments, modifiers, returnType, typeParameters, params, body) + } + + private fun createFunctionParameters(method: PsiMethod): ParameterList { + val result = ArrayList() + for (parameter : PsiParameter? in method.getParameterList().getParameters()) { + result.add(Parameter(Identifier(parameter?.getName()!!), + typeToType(parameter?.getType(), + isAnnotatedAsNotNull(parameter?.getModifierList())), + isReadOnly(parameter, method.getBody()))) + } + return ParameterList(result) + } + + private fun isOverrideAnyMethodExceptMethodsFromObject(method: PsiMethod): Boolean { + var counter: Boolean = normalCase(method) + if (counter) + { + return true + } + + if (isInheritFromObject(method)) + { + return caseForObject(method) + } + + return false + } + + private fun caseForObject(method: PsiMethod): Boolean { + val containing: PsiClass? = method.getContainingClass() + if (containing != null) { + for (s : PsiClassType? in containing.getSuperTypes()) { + val canonicalText: String? = s?.getCanonicalText() + if (canonicalText != JAVA_LANG_OBJECT && !getClassIdentifiers().contains(canonicalText)) { + return true + } + } + } + + return false + } + public open fun blockToBlock(block: PsiCodeBlock?, notEmpty: Boolean): Block { + if (block == null) + return Block.EMPTY_BLOCK + + return Block(removeEmpty(statementsToStatementList(block.getChildren())), notEmpty) + } + + public open fun blockToBlock(block: PsiCodeBlock?): Block { + return blockToBlock(block, true) + } + + public open fun statementsToStatementList(statements: Array): List { + return statements.filterNot { it is PsiWhiteSpace }.map { statementToStatement(it) } + } + + public open fun statementsToStatementList(statements: List): List { + return statements.filterNot { it is PsiWhiteSpace }.map { statementToStatement(it) } + } + + public open fun statementToStatement(s: PsiElement?): Element { + if (s == null) + return Statement.EMPTY_STATEMENT + + val statementVisitor: StatementVisitor = StatementVisitor(this) + s.accept(statementVisitor) + return statementVisitor.getResult() + } + + public open fun expressionsToExpressionList(expressions: Array): List { + val result = ArrayList() + for (e : PsiExpression? in expressions) + result.add(expressionToExpression(e)) + return result + } + + public open fun expressionToExpression(e: PsiExpression?): Expression { + if (e == null) + return Expression.EMPTY_EXPRESSION + + val expressionVisitor: ExpressionVisitor = dispatcher.expressionVisitor + e.accept(expressionVisitor) + return expressionVisitor.getResult() + } + + public open fun elementToElement(e: PsiElement?): Element { + if (e == null) + return Element.EMPTY_ELEMENT + + val elementVisitor: ElementVisitor = ElementVisitor(this) + e.accept(elementVisitor) + return elementVisitor.getResult() + } + + public open fun elementsToElementList(elements: Array): List { + val result = ArrayList() + for(element in elements) { + result.add(elementToElement(element)) + } + return result + } + + public open fun typeElementToTypeElement(element: PsiTypeElement?): TypeElement { + return TypeElement(if (element == null) + EmptyType() + else + typeToType(element.getType())) + } + + public open fun typeToType(`type`: PsiType?): Type { + if (`type` == null) + return EmptyType() + + val typeVisitor: TypeVisitor = TypeVisitor(this) + `type`.accept(typeVisitor) + return typeVisitor.getResult() + } + + public open fun typesToTypeList(types: Array): List { + return types.map { typeToType(it) } + } + + public open fun typeToType(`type`: PsiType?, notNull: Boolean): Type { + val result: Type = typeToType(`type`) + if (notNull) { + return result.convertedToNotNull() + } + + return result + } + + private fun typesToNotNullableTypeList(types: Array): List { + val result = ArrayList() + for(aType in types) { + result.add(typeToType(aType).convertedToNotNull()) + } + return result + } + + public open fun parametersToParameterList(parameters: Array): List { + return parameters.map { parameterToParameter(it!!) } + } + + public open fun parameterToParameter(parameter: PsiParameter, forceNotNull: Boolean = false): Parameter { + return Parameter(Identifier(parameter.getName()!!), + typeToType(parameter.getType(), + forceNotNull || isAnnotatedAsNotNull(parameter.getModifierList())), true) + } + + public open fun argumentsToExpressionList(expression: PsiCallExpression): List { + val argumentList: PsiExpressionList? = expression.getArgumentList() + val arguments: Array = (if (argumentList != null) + argumentList.getExpressions() + else + PsiExpression.EMPTY_ARRAY) + val result = ArrayList() + val resolved: PsiMethod? = expression.resolveMethod() + val expectedTypes = ArrayList() + if (resolved != null) { + for (p : PsiParameter? in resolved.getParameterList().getParameters()) + expectedTypes.add(p?.getType()) + } + + if (arguments.size == expectedTypes.size()) { + for (i in 0..expectedTypes.size() - 1) result.add(expressionToExpression(arguments[i], expectedTypes.get(i))) + } + else { + for (argument : PsiExpression? in arguments) { + result.add(expressionToExpression(argument)) + } + } + return result + } + + public open fun expressionToExpression(argument: PsiExpression?, expectedType: PsiType?): Expression { + if (argument == null) + return Identifier.EMPTY_IDENTIFIER + + var expression: Expression = expressionToExpression(argument) + val actualType: PsiType? = argument.getType() + val isPrimitiveTypeOrNull: Boolean = actualType == null || actualType is PsiPrimitiveType + if (isPrimitiveTypeOrNull && expression.isNullable()) { + expression = BangBangExpression(expression) + } + + if (actualType != null) { + if (isConversionNeeded(actualType, expectedType) && !(expression is LiteralExpression)) + { + val conversion: String? = PRIMITIVE_TYPE_CONVERSIONS.get(expectedType?.getCanonicalText()) + if (conversion != null) { + expression = MethodCallExpression.build(expression, conversion) + } + } + + } + + return expression + } + + class object { + public val NOT_NULL_ANNOTATIONS: Set = ImmutableSet.of("org.jetbrains.annotations.NotNull", "com.sun.istack.internal.NotNull", "javax.annotation.Nonnull")!! + public val PRIMITIVE_TYPE_CONVERSIONS: Map = ImmutableMap.builder() + ?.put("byte", BYTE.getName()) + ?.put("short", SHORT.getName()) + ?.put("int", INT.getName()) + ?.put("long", LONG.getName()) + ?.put("float", FLOAT.getName()) + ?.put("double", DOUBLE.getName()) + ?.put("char", CHAR.getName()) + ?.put(JAVA_LANG_BYTE, BYTE.getName()) + ?.put(JAVA_LANG_SHORT, SHORT.getName()) + ?.put(JAVA_LANG_INTEGER, INT.getName()) + ?.put(JAVA_LANG_LONG, LONG.getName()) + ?.put(JAVA_LANG_FLOAT, FLOAT.getName()) + ?.put(JAVA_LANG_DOUBLE, DOUBLE.getName()) + ?.put(JAVA_LANG_CHARACTER, CHAR.getName()) + ?.build()!! + + private fun quoteKeywords(packageName: String): String { + return packageName.split("\\.").map { Identifier(it).toKotlin() }.makeString(".") + } + + private fun getFinalOrWithEmptyInitializer(fields: List): List { + val result = ArrayList() + for (f : Field in fields) + if (f.isVal() || f.initializer.toKotlin().isEmpty()) { + result.add(f) + } + + return result + } + + private fun createParametersFromFields(fields: List): List { + return fields.map { Parameter(Identifier("_" + it.identifier.name), it.`type`, true) } + } + + private fun createInitStatementsFromFields(fields: List): List { + val result = ArrayList() + for (f : Field in fields) { + val identifierToKotlin: String? = f.identifier.toKotlin() + result.add(DummyStringExpression(identifierToKotlin + " = " + "_" + identifierToKotlin)) + } + return result + } + + private fun createPrimaryConstructorInvocation(s: String, fields: List, initializers: Map): String { + return s + "(" + fields.map { initializers[it.identifier.toKotlin()] }.makeString(", ") + ")" + } + + public open fun getDefaultInitializer(f: Field): String { + if (f.`type`.nullable) { + return "null" + } + else { + val typeToKotlin: String = f.`type`.toKotlin() + if (typeToKotlin.equals("Boolean")) + return "false" + + if (typeToKotlin.equals("Char")) + return "' '" + + if (typeToKotlin.equals("Double")) + return "0." + OperatorConventions.DOUBLE + "()" + + if (typeToKotlin.equals("Float")) + return "0." + OperatorConventions.FLOAT + "()" + + return "0" + } + } + + private fun getPrimaryConstructorForThisCase(psiClass: PsiClass): PsiMethod? { + val tv = ThisVisitor() + psiClass.accept(tv) + return tv.getPrimaryConstructor() + } + + public open fun isConstructorPrimary(constructor: PsiMethod): Boolean { + val parent = constructor.getParent() + if (parent is PsiClass) { + if (parent.getConstructors().size == 1) { + return true + } + else { + val c: PsiMethod? = getPrimaryConstructorForThisCase(parent) + if (c != null && c.hashCode() == constructor.hashCode()) { + return true + } + + } + } + + return false + } + private fun removeEmpty(statements: List): List { + return statements.filterNot { it == Statement.EMPTY_STATEMENT || + it == Expression.EMPTY_EXPRESSION || + it == Element.EMPTY_ELEMENT } + } + + private fun isNotOpenMethod(method: PsiMethod): Boolean { + val parent = method.getParent() + if (parent is PsiClass) { + val parentModifierList: PsiModifierList? = parent.getModifierList() + if ((parentModifierList != null && parentModifierList.hasExplicitModifier(PsiModifier.FINAL)) || parent.isEnum()) { + return true + } + + } + + return false + } + + private fun normalCase(method: PsiMethod): Boolean { + var counter: Int = 0 + for (s : HierarchicalMethodSignature? in method.getHierarchicalMethodSignature().getSuperSignatures()) + { + var containingClass: PsiClass? = s?.getMethod()?.getContainingClass() + var qualifiedName: String? = (if (containingClass != null) + containingClass?.getQualifiedName() + else + "") + if (qualifiedName != null && !qualifiedName.equals(JAVA_LANG_OBJECT)) + { + counter++ + } + + } + return counter > 0 + } + + private fun isInheritFromObject(method: PsiMethod): Boolean { + var superSignatures: List = method.getHierarchicalMethodSignature().getSuperSignatures()!! + for (s : HierarchicalMethodSignature? in superSignatures) { + var containingClass: PsiClass? = s?.getMethod()?.getContainingClass() + var qualifiedName: String? = (if (containingClass != null) + containingClass?.getQualifiedName() + else + "") + if (qualifiedName == JAVA_LANG_OBJECT) { + return true + } + + } + return false + } + + private fun isOverrideObjectDirect(method: PsiMethod): Boolean { + var superSignatures: List? = method.getHierarchicalMethodSignature().getSuperSignatures() + if (superSignatures?.size()!! == 1) + { + val containingClass: PsiClass? = superSignatures?.get(0)?.getMethod()?.getContainingClass() + val qualifiedName: String? = (if (containingClass != null) + containingClass.getQualifiedName() + else + "") + if (qualifiedName == JAVA_LANG_OBJECT) { + return true + } + + } + + return false + } + private fun importsToImportList(imports: Array): List { + val result = ArrayList() + for (i : PsiImportStatementBase? in imports) { + if (i == null) continue + val anImport: Import = importToImport(i) + val name: String = anImport.name + if (!name.isEmpty() && !NOT_NULL_ANNOTATIONS.contains(name)) { + result.add(anImport) + } + + } + return result + } + + private fun importToImport(i: PsiImportStatementBase): Import { + val reference: PsiJavaCodeReferenceElement? = i.getImportReference() + if (reference != null) { + return Import(quoteKeywords(reference.getQualifiedName()!!) + ((if (i.isOnDemand()) + ".*" + else + ""))) + } + + return Import("") + } + + public open fun identifierToIdentifier(identifier: PsiIdentifier?): Identifier { + if (identifier == null) + return Identifier.EMPTY_IDENTIFIER + + return Identifier(identifier.getText()!!) + } + + public open fun modifiersListToModifiersSet(modifierList: PsiModifierList?): MutableSet { + val modifiersSet: HashSet = hashSet() + if (modifierList != null) { + if (modifierList.hasExplicitModifier(PsiModifier.ABSTRACT)) + modifiersSet.add(Modifier.ABSTRACT) + + if (modifierList.hasModifierProperty(PsiModifier.FINAL)) + modifiersSet.add(Modifier.FINAL) + + if (modifierList.hasModifierProperty(PsiModifier.STATIC)) + modifiersSet.add(Modifier.STATIC) + + if (modifierList.hasExplicitModifier(PsiModifier.PUBLIC)) + modifiersSet.add(Modifier.PUBLIC) + + if (modifierList.hasExplicitModifier(PsiModifier.PROTECTED)) + modifiersSet.add(Modifier.PROTECTED) + + if (modifierList.hasExplicitModifier(PsiModifier.PACKAGE_LOCAL)) + modifiersSet.add(Modifier.INTERNAL) + + if (modifierList.hasExplicitModifier(PsiModifier.PRIVATE)) + modifiersSet.add(Modifier.PRIVATE) + } + + return modifiersSet + } + + private fun isConversionNeeded(actual: PsiType?, expected: PsiType?): Boolean { + if (actual == null || expected == null) { + return false + } + + val typeMap = HashMap() + typeMap.put(JAVA_LANG_BYTE, "byte") + typeMap.put(JAVA_LANG_SHORT, "short") + typeMap.put(JAVA_LANG_INTEGER, "int") + typeMap.put(JAVA_LANG_LONG, "long") + typeMap.put(JAVA_LANG_FLOAT, "float") + typeMap.put(JAVA_LANG_DOUBLE, "double") + typeMap.put(JAVA_LANG_CHARACTER, "char") + val expectedStr: String? = expected.getCanonicalText() + val actualStr: String? = actual.getCanonicalText() + val o1: Boolean = expectedStr == typeMap[actualStr] + val o2: Boolean = actualStr == typeMap[expectedStr] + return actualStr != expectedStr && (!(o1 xor o2)) + } + } +} + +public fun createMainFunction(file: PsiFile): String { + val classNamesWithMains = ArrayList?>() + for (c : PsiClass? in (file as PsiJavaFile).getClasses()) { + var main: PsiMethod? = findMainMethod(c) + if (main != null) { + classNamesWithMains.add(Pair(c?.getName(), main)) + } + } + + if (classNamesWithMains.size() > 0) { + var className: String? = classNamesWithMains.get(0)?.getFirst() + return MessageFormat.format("fun main(args : Array?) = {0}.main(args)", className)!! + } + + return "" + +} + +private fun findMainMethod(aClass: PsiClass?): PsiMethod? { + if (isMainClass(aClass)) { + val mainMethods: Array? = aClass?.findMethodsByName("main", false) + if (mainMethods != null) { + return findMainMethod(mainMethods) + } + } + return null +} + +private fun isMainClass(psiClass: PsiClass?): Boolean { + if (psiClass == null || psiClass is PsiAnonymousClass) + return false + + if (psiClass.isInterface()) + return false + + return psiClass.getContainingClass() == null || psiClass.hasModifierProperty(PsiModifier.STATIC) + +} + +private fun findMainMethod(mainMethods: Array): PsiMethod? { + return mainMethods.find { isMainMethod(it) } +} + +public fun isMainMethod(method: PsiMethod?): Boolean { + if (method == null || method.getContainingClass() == null) + return false + + if (PsiType.VOID != method.getReturnType()) + return false + + if (!method.hasModifierProperty(PsiModifier.STATIC)) + return false + + if (!method.hasModifierProperty(PsiModifier.PUBLIC)) + return false + + val parameters: Array? = method.getParameterList().getParameters() + if (parameters?.size!! != 1) + return false + + val `type`: PsiType? = parameters!![0]?.getType() + if (`type` !is PsiArrayType) + return false + + val componentType: PsiType? = `type`.getComponentType() + return componentType?.equalsToText("java.lang.String")!! +} + +public fun countWritingAccesses(element: PsiElement?, container: PsiElement?): Int { + var counter: Int = 0 + if (container != null) { + val visitor: ReferenceCollector = ReferenceCollector() + container.accept(visitor) + for (e : PsiReferenceExpression in visitor.getCollectedReferences()) + if (e?.isReferenceTo(element)!! && PsiUtil.isAccessedForWriting(e)) { + counter++ + } + } + + return counter +} + +open class ReferenceCollector(): JavaRecursiveElementVisitor() { + private val myCollectedReferences = ArrayList() + + public open fun getCollectedReferences(): List { + return myCollectedReferences + } + + public override fun visitReferenceExpression(expression: PsiReferenceExpression?): Unit { + super.visitReferenceExpression(expression) + if (expression != null) { + myCollectedReferences.add(expression) + } + } +} + +public fun isReadOnly(element: PsiElement?, container: PsiElement?): Boolean { + return countWritingAccesses(element, container) == 0 +} + +public fun isAnnotatedAsNotNull(modifierList: PsiModifierList?): Boolean { + if (modifierList != null) { + val annotations: Array = modifierList.getAnnotations() + for (a : PsiAnnotation in annotations) { + val qualifiedName: String? = a?.getQualifiedName() + if (qualifiedName != null && Converter.NOT_NULL_ANNOTATIONS.contains(qualifiedName)) { + return true + } + } + } + return false +} + +public fun isDefinitelyNotNull(element: PsiElement?): Boolean = when(element) { + is PsiLiteralExpression -> element.getValue() != null + is PsiNewExpression -> true + else -> false +} diff --git a/src/org/jetbrains/jet/j2k/J2KConverterFlags.kt b/src/org/jetbrains/jet/j2k/J2KConverterFlags.kt index 863f9843abb..415aa0b195d 100644 --- a/src/org/jetbrains/jet/j2k/J2KConverterFlags.kt +++ b/src/org/jetbrains/jet/j2k/J2KConverterFlags.kt @@ -1,8 +1,8 @@ -package org.jetbrains.jet.j2k - - -public enum class J2KConverterFlags { - FULLY_QUALIFIED_TYPE_NAMES - SKIP_BODIES - SKIP_NON_PUBLIC_MEMBERS -} +package org.jetbrains.jet.j2k + + +public enum class J2KConverterFlags { + FULLY_QUALIFIED_TYPE_NAMES + SKIP_BODIES + SKIP_NON_PUBLIC_MEMBERS +} diff --git a/src/org/jetbrains/jet/j2k/JavaToKotlinCli.java b/src/org/jetbrains/jet/j2k/JavaToKotlinCli.java index f65d30a9b31..b876dd7991c 100644 --- a/src/org/jetbrains/jet/j2k/JavaToKotlinCli.java +++ b/src/org/jetbrains/jet/j2k/JavaToKotlinCli.java @@ -1,147 +1,147 @@ -//package org.jetbrains.jet.j2k; -// -//import com.intellij.psi.PsiFile; -//import com.intellij.psi.PsiJavaFile; -//import org.apache.commons.cli.*; -//import org.jetbrains.annotations.NotNull; -//import org.jetbrains.annotations.Nullable; -// -//import java.io.File; -//import java.io.FileNotFoundException; -//import java.io.IOException; -//import java.util.ArrayList; -//import java.util.Arrays; -//import java.util.List; -//import java.util.logging.Logger; -//import java.util.regex.Pattern; -// -//import static org.apache.commons.io.FileUtils.readFileToString; -//import static org.apache.commons.io.FileUtils.writeStringToFile; -// -///** -// * @author ignatov -// */ -//@SuppressWarnings({"CallToPrintStackTrace", "UseOfSystemOutOrSystemErr"}) -//public class JavaToKotlinCli { -// private static final Logger myLogger = Logger.getAnonymousLogger(); -// -// private JavaToKotlinCli() { -// } -// -// public static void main(String[] args) { -// CommandLineParser parser = new BasicParser(); -// Options options = new Options() -// .addOption("h", "help", false, "Print usage information") -// .addOption("f", "from", true, "Directory with Java sources") -// .addOption("t", "to", true, "Directory with Kotlin sources") -// .addOption("p", "public-only", false, "Only public and protected members") -// .addOption("fqn", "fqn", false, "Full qualified names") -// .addOption("d", "declarations-only", false, "Declarations only") -// ; -// -// try { -// CommandLine commandLine = parser.parse(options, args); -// -// if (commandLine.hasOption("help")) -// showHelpAndExit(); -// -// if (commandLine.hasOption("from") && commandLine.hasOption("to")) { -// String from = commandLine.getOptionValue("from"); -// String to = commandLine.getOptionValue("to"); -// -// for (Option o : commandLine.getOptions()) { -// Converter.addFlag(o.getLongOpt()); -// } -// -// if (!from.isEmpty() && !to.isEmpty()) -// convertSourceTree(from, to); -// else -// showHelpAndExit(); -// } else -// showHelpAndExit(); -// } catch (ParseException e) { -// e.printStackTrace(); -// } -// } -// -// @SuppressWarnings("ResultOfMethodCallIgnored") -// private static void convertSourceTree(String javaPath, String kotlinPath) { -// try { -// File javaDir = new File(javaPath); -// File kotlinDir = new File(kotlinPath); -// -// if (kotlinDir.exists()) -// kotlinDir.delete(); -// -// if (!kotlinDir.exists() && !kotlinDir.mkdir()) -// myLogger.warning("Creation failed: " + kotlinDir.getAbsolutePath()); -// -// for (File f : getJavaFiles(javaDir.getAbsolutePath())) { -// String relative = javaDir.toURI().relativize(f.toURI()).getPath().replace(".java", ".kt"); -// File file = new File(kotlinPath, relative); -// -// if (file.exists()) -// file.delete(); -// -// if (f.isDirectory()) -// if (!file.exists() && !file.mkdir()) -// myLogger.warning("Creation failed: " + file.getAbsolutePath()); -// -// if (f.isFile()) { -// writeStringToFile(file, fileToKotlin(f)); -// } -// } -// } catch (FileNotFoundException e) { -// e.printStackTrace(); -// } catch (IOException e) { -// e.printStackTrace(); -// } -// } -// -// @NotNull -// private static String fileToKotlin(File f) throws IOException { -// final String javaCode = readJavaFileToString(f); -// return generateKotlinCode(JavaToKotlinTranslator.createFile(JavaToKotlinTranslator.setUpJavaCoreEnvironment(), javaCode)); -// } -// -// @NotNull -// private static String generateKotlinCode(@Nullable PsiFile file) { -// if (file != null && file instanceof PsiJavaFile) { -// JavaToKotlinTranslator.setClassIdentifiers(file); -// return JavaToKotlinTranslator.prettify(Converter.fileToFile((PsiJavaFile) file).toKotlin()); -// } -// return ""; -// } -// -// @NotNull -// private static String readJavaFileToString(@NotNull File javaFile) throws IOException { -// return Pattern.compile("\\s*/\\*.*\\*/", Pattern.DOTALL).matcher(readFileToString(javaFile)).replaceAll(""); -// } -// -// private static void showHelpAndExit() { -// System.err.println("Usage: java -jar java2kotlin.jar -f -t "); -// System.exit(1); -// } -// -// static public List getJavaFiles(String startDirName) throws FileNotFoundException { -// return getJavaFiles(new File(startDirName)); -// } -// -// private static List getJavaFiles(File start) throws FileNotFoundException { -// List result = new ArrayList(); -// -// if (start.isFile()) -// return Arrays.asList(start); -// -// for (File file : Arrays.asList(start.listFiles())) { -// if ((file.isFile() && file.getName().endsWith(".java")) || file.isDirectory()) -// result.add(file); -// -// if (file.isDirectory()) { -// List deeperList = getJavaFiles(file); -// result.addAll(deeperList); -// } -// } -// return result; -// } +//package org.jetbrains.jet.j2k; +// +//import com.intellij.psi.PsiFile; +//import com.intellij.psi.PsiJavaFile; +//import org.apache.commons.cli.*; +//import org.jetbrains.annotations.NotNull; +//import org.jetbrains.annotations.Nullable; +// +//import java.io.File; +//import java.io.FileNotFoundException; +//import java.io.IOException; +//import java.util.ArrayList; +//import java.util.Arrays; +//import java.util.List; +//import java.util.logging.Logger; +//import java.util.regex.Pattern; +// +//import static org.apache.commons.io.FileUtils.readFileToString; +//import static org.apache.commons.io.FileUtils.writeStringToFile; +// +///** +// * @author ignatov +// */ +//@SuppressWarnings({"CallToPrintStackTrace", "UseOfSystemOutOrSystemErr"}) +//public class JavaToKotlinCli { +// private static final Logger myLogger = Logger.getAnonymousLogger(); +// +// private JavaToKotlinCli() { +// } +// +// public static void main(String[] args) { +// CommandLineParser parser = new BasicParser(); +// Options options = new Options() +// .addOption("h", "help", false, "Print usage information") +// .addOption("f", "from", true, "Directory with Java sources") +// .addOption("t", "to", true, "Directory with Kotlin sources") +// .addOption("p", "public-only", false, "Only public and protected members") +// .addOption("fqn", "fqn", false, "Full qualified names") +// .addOption("d", "declarations-only", false, "Declarations only") +// ; +// +// try { +// CommandLine commandLine = parser.parse(options, args); +// +// if (commandLine.hasOption("help")) +// showHelpAndExit(); +// +// if (commandLine.hasOption("from") && commandLine.hasOption("to")) { +// String from = commandLine.getOptionValue("from"); +// String to = commandLine.getOptionValue("to"); +// +// for (Option o : commandLine.getOptions()) { +// Converter.addFlag(o.getLongOpt()); +// } +// +// if (!from.isEmpty() && !to.isEmpty()) +// convertSourceTree(from, to); +// else +// showHelpAndExit(); +// } else +// showHelpAndExit(); +// } catch (ParseException e) { +// e.printStackTrace(); +// } +// } +// +// @SuppressWarnings("ResultOfMethodCallIgnored") +// private static void convertSourceTree(String javaPath, String kotlinPath) { +// try { +// File javaDir = new File(javaPath); +// File kotlinDir = new File(kotlinPath); +// +// if (kotlinDir.exists()) +// kotlinDir.delete(); +// +// if (!kotlinDir.exists() && !kotlinDir.mkdir()) +// myLogger.warning("Creation failed: " + kotlinDir.getAbsolutePath()); +// +// for (File f : getJavaFiles(javaDir.getAbsolutePath())) { +// String relative = javaDir.toURI().relativize(f.toURI()).getPath().replace(".java", ".kt"); +// File file = new File(kotlinPath, relative); +// +// if (file.exists()) +// file.delete(); +// +// if (f.isDirectory()) +// if (!file.exists() && !file.mkdir()) +// myLogger.warning("Creation failed: " + file.getAbsolutePath()); +// +// if (f.isFile()) { +// writeStringToFile(file, fileToKotlin(f)); +// } +// } +// } catch (FileNotFoundException e) { +// e.printStackTrace(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// +// @NotNull +// private static String fileToKotlin(File f) throws IOException { +// final String javaCode = readJavaFileToString(f); +// return generateKotlinCode(JavaToKotlinTranslator.createFile(JavaToKotlinTranslator.setUpJavaCoreEnvironment(), javaCode)); +// } +// +// @NotNull +// private static String generateKotlinCode(@Nullable PsiFile file) { +// if (file != null && file instanceof PsiJavaFile) { +// JavaToKotlinTranslator.setClassIdentifiers(file); +// return JavaToKotlinTranslator.prettify(Converter.fileToFile((PsiJavaFile) file).toKotlin()); +// } +// return ""; +// } +// +// @NotNull +// private static String readJavaFileToString(@NotNull File javaFile) throws IOException { +// return Pattern.compile("\\s*/\\*.*\\*/", Pattern.DOTALL).matcher(readFileToString(javaFile)).replaceAll(""); +// } +// +// private static void showHelpAndExit() { +// System.err.println("Usage: java -jar java2kotlin.jar -f -t "); +// System.exit(1); +// } +// +// static public List getJavaFiles(String startDirName) throws FileNotFoundException { +// return getJavaFiles(new File(startDirName)); +// } +// +// private static List getJavaFiles(File start) throws FileNotFoundException { +// List result = new ArrayList(); +// +// if (start.isFile()) +// return Arrays.asList(start); +// +// for (File file : Arrays.asList(start.listFiles())) { +// if ((file.isFile() && file.getName().endsWith(".java")) || file.isDirectory()) +// result.add(file); +// +// if (file.isDirectory()) { +// List deeperList = getJavaFiles(file); +// result.addAll(deeperList); +// } +// } +// return result; +// } //} \ No newline at end of file diff --git a/src/org/jetbrains/jet/j2k/JavaToKotlinTranslator.java b/src/org/jetbrains/jet/j2k/JavaToKotlinTranslator.java index 88107de50cc..ee894d7312f 100644 --- a/src/org/jetbrains/jet/j2k/JavaToKotlinTranslator.java +++ b/src/org/jetbrains/jet/j2k/JavaToKotlinTranslator.java @@ -1,234 +1,234 @@ -/* - * 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; - -import com.intellij.core.JavaCoreApplicationEnvironment; -import com.intellij.core.JavaCoreProjectEnvironment; -import com.intellij.lang.java.JavaLanguage; -import com.intellij.openapi.Disposable; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiFileFactory; -import com.intellij.psi.PsiJavaFile; -import com.intellij.util.Function; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.j2k.visitors.ClassVisitor; - -import java.io.File; -import java.io.IOException; -import java.io.PrintStream; -import java.net.URL; -import java.net.URLClassLoader; - -/** - * @author ignatov - */ -public class JavaToKotlinTranslator { - private JavaToKotlinTranslator() { - } - - private static final Converter CONVERTER = new Converter(); - - @Nullable - private static PsiFile createFile(@NotNull String text) { - JavaCoreProjectEnvironment javaCoreEnvironment = setUpJavaCoreEnvironment(); - return PsiFileFactory.getInstance(javaCoreEnvironment.getProject()).createFileFromText( - "test.java", JavaLanguage.INSTANCE, text - ); - } - - @Nullable - static PsiFile createFile(@NotNull JavaCoreProjectEnvironment javaCoreEnvironment, @NotNull String text) { - return PsiFileFactory.getInstance(javaCoreEnvironment.getProject()).createFileFromText( - "test.java", JavaLanguage.INSTANCE, text - ); - } - - @NotNull - static JavaCoreProjectEnvironment setUpJavaCoreEnvironment() { - Disposable parentDisposable = new Disposable() { - @Override - public void dispose() { - } - }; - JavaCoreApplicationEnvironment applicationEnvironment = new JavaCoreApplicationEnvironment(parentDisposable); - JavaCoreProjectEnvironment javaCoreEnvironment = new JavaCoreProjectEnvironment(parentDisposable, applicationEnvironment); - - javaCoreEnvironment.addJarToClassPath(findRtJar()); - File annotations = findAnnotations(); - if (annotations != null && annotations.exists()) { - javaCoreEnvironment.addJarToClassPath(annotations); - } - return javaCoreEnvironment; - } - - @NotNull - static String prettify(@Nullable String code) { - if (code == null) { - return ""; - } - return code - .trim() - .replaceAll("\r\n", "\n") - .replaceAll(" \n", "\n") - .replaceAll("\n ", "\n") - .replaceAll("\n+", "\n") - .replaceAll(" +", " ") - .trim() - ; - } - - @Nullable - private static File findRtJar() { - String javaHome = System.getenv("JAVA_HOME"); - File rtJar; - if (javaHome == null) { - rtJar = findActiveRtJar(true); - - if (rtJar == null) { - throw new SetupJavaCoreEnvironmentException("JAVA_HOME environment variable needs to be defined"); - } - } - else { - rtJar = findRtJar(javaHome); - } - - if (rtJar == null || !rtJar.exists()) { - rtJar = findActiveRtJar(true); - - if ((rtJar == null || !rtJar.exists())) { - throw new SetupJavaCoreEnvironmentException("No rt.jar found under JAVA_HOME=" + javaHome); - } - } - return rtJar; - } - - @Nullable - private static File findRtJar(String javaHome) { - File rtJar = new File(javaHome, "jre/lib/rt.jar"); - if (rtJar.exists()) { - return rtJar; - } - - File classesJar = new File(new File(javaHome).getParentFile().getAbsolutePath(), "Classes/classes.jar"); - if (classesJar.exists()) { - return classesJar; - } - return null; - } - - @Nullable - private static File findAnnotations() { - ClassLoader classLoader = JavaToKotlinTranslator.class.getClassLoader(); - while (classLoader != null) { - if (classLoader instanceof URLClassLoader) { - URLClassLoader loader = (URLClassLoader) classLoader; - for (URL url : loader.getURLs()) - if ("file".equals(url.getProtocol()) && url.getFile().endsWith("/annotations.jar")) { - return new File(url.getFile()); - } - } - classLoader = classLoader.getParent(); - } - return null; - } - - @Nullable - private static File findActiveRtJar(boolean failOnError) { - ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); - if (systemClassLoader instanceof URLClassLoader) { - URLClassLoader loader = (URLClassLoader) systemClassLoader; - for (URL url : loader.getURLs()) { - if ("file".equals(url.getProtocol())) { - if (url.getFile().endsWith("/lib/rt.jar")) { - return new File(url.getFile()); - } - if (url.getFile().endsWith("/Classes/classes.jar")) { - return new File(url.getFile()).getAbsoluteFile(); - } - } - } - if (failOnError) { - throw new SetupJavaCoreEnvironmentException("Could not find rt.jar in system class loader: " + StringUtil.join(loader.getURLs(), new Function() { - @NotNull - @Override - public String fun(@NotNull URL url) { - return url.toString() + "\n"; - } - }, ", ")); - } - } - else if (failOnError) { - throw new SetupJavaCoreEnvironmentException("System class loader is not an URLClassLoader: " + systemClassLoader); - } - return null; - } - - static void setClassIdentifiers(@NotNull Converter converter, @NotNull PsiElement psiFile) { - ClassVisitor c = new ClassVisitor(); - psiFile.accept(c); - converter.clearClassIdentifiers(); - converter.setClassIdentifiers(c.getClassIdentifiers()); - } - - @NotNull - static String generateKotlinCode(@NotNull String javaCode) { - PsiFile file = createFile(javaCode); - if (file != null && file instanceof PsiJavaFile) { - setClassIdentifiers(CONVERTER, file); - return prettify(CONVERTER.fileToFile((PsiJavaFile) file).toKotlin()); - } - return ""; - } - - @NotNull - static String generateKotlinCodeWithCompatibilityImport(@NotNull String javaCode) { - PsiFile file = createFile(javaCode); - if (file != null && file instanceof PsiJavaFile) { - setClassIdentifiers(CONVERTER, file); - return prettify(CONVERTER.fileToFileWithCompatibilityImport((PsiJavaFile) file).toKotlin()); - } - return ""; - } - - public static void main(@NotNull String[] args) throws IOException { - //noinspection UseOfSystemOutOrSystemErr - final PrintStream out = System.out; - if (args.length == 1) { - String kotlinCode = ""; - try { - kotlinCode = generateKotlinCode(args[0]); - } catch (Exception e) { - out.println("EXCEPTION: " + e.getMessage()); - } - if (kotlinCode.isEmpty()) { - out.println("EXCEPTION: generated code is empty."); - } - else { - out.println(kotlinCode); - } - } - else { - out.println("EXCEPTION: wrong number of arguments (should be 1)."); - } - } - - public static String translateToKotlin(String code) { - return generateKotlinCode(code); - } -} +/* + * 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; + +import com.intellij.core.JavaCoreApplicationEnvironment; +import com.intellij.core.JavaCoreProjectEnvironment; +import com.intellij.lang.java.JavaLanguage; +import com.intellij.openapi.Disposable; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiFileFactory; +import com.intellij.psi.PsiJavaFile; +import com.intellij.util.Function; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.j2k.visitors.ClassVisitor; + +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.net.URL; +import java.net.URLClassLoader; + +/** + * @author ignatov + */ +public class JavaToKotlinTranslator { + private JavaToKotlinTranslator() { + } + + private static final Converter CONVERTER = new Converter(); + + @Nullable + private static PsiFile createFile(@NotNull String text) { + JavaCoreProjectEnvironment javaCoreEnvironment = setUpJavaCoreEnvironment(); + return PsiFileFactory.getInstance(javaCoreEnvironment.getProject()).createFileFromText( + "test.java", JavaLanguage.INSTANCE, text + ); + } + + @Nullable + static PsiFile createFile(@NotNull JavaCoreProjectEnvironment javaCoreEnvironment, @NotNull String text) { + return PsiFileFactory.getInstance(javaCoreEnvironment.getProject()).createFileFromText( + "test.java", JavaLanguage.INSTANCE, text + ); + } + + @NotNull + static JavaCoreProjectEnvironment setUpJavaCoreEnvironment() { + Disposable parentDisposable = new Disposable() { + @Override + public void dispose() { + } + }; + JavaCoreApplicationEnvironment applicationEnvironment = new JavaCoreApplicationEnvironment(parentDisposable); + JavaCoreProjectEnvironment javaCoreEnvironment = new JavaCoreProjectEnvironment(parentDisposable, applicationEnvironment); + + javaCoreEnvironment.addJarToClassPath(findRtJar()); + File annotations = findAnnotations(); + if (annotations != null && annotations.exists()) { + javaCoreEnvironment.addJarToClassPath(annotations); + } + return javaCoreEnvironment; + } + + @NotNull + static String prettify(@Nullable String code) { + if (code == null) { + return ""; + } + return code + .trim() + .replaceAll("\r\n", "\n") + .replaceAll(" \n", "\n") + .replaceAll("\n ", "\n") + .replaceAll("\n+", "\n") + .replaceAll(" +", " ") + .trim() + ; + } + + @Nullable + private static File findRtJar() { + String javaHome = System.getenv("JAVA_HOME"); + File rtJar; + if (javaHome == null) { + rtJar = findActiveRtJar(true); + + if (rtJar == null) { + throw new SetupJavaCoreEnvironmentException("JAVA_HOME environment variable needs to be defined"); + } + } + else { + rtJar = findRtJar(javaHome); + } + + if (rtJar == null || !rtJar.exists()) { + rtJar = findActiveRtJar(true); + + if ((rtJar == null || !rtJar.exists())) { + throw new SetupJavaCoreEnvironmentException("No rt.jar found under JAVA_HOME=" + javaHome); + } + } + return rtJar; + } + + @Nullable + private static File findRtJar(String javaHome) { + File rtJar = new File(javaHome, "jre/lib/rt.jar"); + if (rtJar.exists()) { + return rtJar; + } + + File classesJar = new File(new File(javaHome).getParentFile().getAbsolutePath(), "Classes/classes.jar"); + if (classesJar.exists()) { + return classesJar; + } + return null; + } + + @Nullable + private static File findAnnotations() { + ClassLoader classLoader = JavaToKotlinTranslator.class.getClassLoader(); + while (classLoader != null) { + if (classLoader instanceof URLClassLoader) { + URLClassLoader loader = (URLClassLoader) classLoader; + for (URL url : loader.getURLs()) + if ("file".equals(url.getProtocol()) && url.getFile().endsWith("/annotations.jar")) { + return new File(url.getFile()); + } + } + classLoader = classLoader.getParent(); + } + return null; + } + + @Nullable + private static File findActiveRtJar(boolean failOnError) { + ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); + if (systemClassLoader instanceof URLClassLoader) { + URLClassLoader loader = (URLClassLoader) systemClassLoader; + for (URL url : loader.getURLs()) { + if ("file".equals(url.getProtocol())) { + if (url.getFile().endsWith("/lib/rt.jar")) { + return new File(url.getFile()); + } + if (url.getFile().endsWith("/Classes/classes.jar")) { + return new File(url.getFile()).getAbsoluteFile(); + } + } + } + if (failOnError) { + throw new SetupJavaCoreEnvironmentException("Could not find rt.jar in system class loader: " + StringUtil.join(loader.getURLs(), new Function() { + @NotNull + @Override + public String fun(@NotNull URL url) { + return url.toString() + "\n"; + } + }, ", ")); + } + } + else if (failOnError) { + throw new SetupJavaCoreEnvironmentException("System class loader is not an URLClassLoader: " + systemClassLoader); + } + return null; + } + + static void setClassIdentifiers(@NotNull Converter converter, @NotNull PsiElement psiFile) { + ClassVisitor c = new ClassVisitor(); + psiFile.accept(c); + converter.clearClassIdentifiers(); + converter.setClassIdentifiers(c.getClassIdentifiers()); + } + + @NotNull + static String generateKotlinCode(@NotNull String javaCode) { + PsiFile file = createFile(javaCode); + if (file != null && file instanceof PsiJavaFile) { + setClassIdentifiers(CONVERTER, file); + return prettify(CONVERTER.fileToFile((PsiJavaFile) file).toKotlin()); + } + return ""; + } + + @NotNull + static String generateKotlinCodeWithCompatibilityImport(@NotNull String javaCode) { + PsiFile file = createFile(javaCode); + if (file != null && file instanceof PsiJavaFile) { + setClassIdentifiers(CONVERTER, file); + return prettify(CONVERTER.fileToFileWithCompatibilityImport((PsiJavaFile) file).toKotlin()); + } + return ""; + } + + public static void main(@NotNull String[] args) throws IOException { + //noinspection UseOfSystemOutOrSystemErr + final PrintStream out = System.out; + if (args.length == 1) { + String kotlinCode = ""; + try { + kotlinCode = generateKotlinCode(args[0]); + } catch (Exception e) { + out.println("EXCEPTION: " + e.getMessage()); + } + if (kotlinCode.isEmpty()) { + out.println("EXCEPTION: generated code is empty."); + } + else { + out.println(kotlinCode); + } + } + else { + out.println("EXCEPTION: wrong number of arguments (should be 1)."); + } + } + + public static String translateToKotlin(String code) { + return generateKotlinCode(code); + } +} diff --git a/src/org/jetbrains/jet/j2k/SetupJavaCoreEnvironmentException.kt b/src/org/jetbrains/jet/j2k/SetupJavaCoreEnvironmentException.kt index 42ab325d2ba..3aa628ec4cd 100644 --- a/src/org/jetbrains/jet/j2k/SetupJavaCoreEnvironmentException.kt +++ b/src/org/jetbrains/jet/j2k/SetupJavaCoreEnvironmentException.kt @@ -1,23 +1,23 @@ -package org.jetbrains.jet.j2k - - -/* - * 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. - */ -/** - * @author ignatov - */ -public open class SetupJavaCoreEnvironmentException(s: String?): RuntimeException() { -} +package org.jetbrains.jet.j2k + + +/* + * 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. + */ +/** + * @author ignatov + */ +public open class SetupJavaCoreEnvironmentException(s: String?): RuntimeException() { +} diff --git a/src/org/jetbrains/jet/j2k/actions/JavaToKotlinAction.kt b/src/org/jetbrains/jet/j2k/actions/JavaToKotlinAction.kt index 8195d0efec3..cc563cd55c8 100644 --- a/src/org/jetbrains/jet/j2k/actions/JavaToKotlinAction.kt +++ b/src/org/jetbrains/jet/j2k/actions/JavaToKotlinAction.kt @@ -1,43 +1,43 @@ -//package org.jetbrains.jet.j2k.actions -// -//import com.intellij.openapi.actionSystem.AnAction -//import com.intellij.openapi.actionSystem.AnActionEvent -//import org.jetbrains.jet.j2k.Converter -//import com.intellij.openapi.actionSystem.PlatformDataKeys -//import com.intellij.openapi.actionSystem.LangDataKeys -//import com.intellij.psi.PsiJavaFile -//import com.intellij.openapi.util.io.FileUtil -//import com.intellij.openapi.fileEditor.FileDocumentManager -//import com.intellij.psi.PsiDocumentManager -//import com.intellij.openapi.command.WriteCommandAction -//import com.intellij.openapi.application.ApplicationManager -//import com.intellij.psi.codeStyle.CodeStyleManager -// -//class JavaToKotlinAction(): AnAction() { -// public override fun actionPerformed(event : AnActionEvent?) { -// val converter = Converter() -// val psiFile = event!!.getData(LangDataKeys.PSI_FILE)!! -// ApplicationManager.getApplication()?.runWriteAction(object : Runnable { -// public override fun run() { -// val result = converter.fileToFile(psiFile as PsiJavaFile).toKotlin() -// val newName = FileUtil.getNameWithoutExtension(psiFile.getName()) + ".kt" -// val newFile = psiFile.getContainingDirectory()?.createFile(newName)!! -// val project = psiFile.getProject() -// val psiDocumentManager = PsiDocumentManager.getInstance(project)!! -// val document = psiDocumentManager.getDocument(newFile)!! -// document.setText(result) -// psiDocumentManager.doPostponedOperationsAndUnblockDocument(document) -// psiDocumentManager.commitDocument(document) -// CodeStyleManager.getInstance(project)!!.reformat(newFile) -// psiFile.setName(psiFile.getName() + ".old") -// newFile.navigate(true) -// } -// }) -// } -// -// -// public override fun update(e : AnActionEvent?) { -// val psiFile = e!!.getData(LangDataKeys.PSI_FILE) -// e.getPresentation().setEnabled(psiFile is PsiJavaFile) -// } -//} +//package org.jetbrains.jet.j2k.actions +// +//import com.intellij.openapi.actionSystem.AnAction +//import com.intellij.openapi.actionSystem.AnActionEvent +//import org.jetbrains.jet.j2k.Converter +//import com.intellij.openapi.actionSystem.PlatformDataKeys +//import com.intellij.openapi.actionSystem.LangDataKeys +//import com.intellij.psi.PsiJavaFile +//import com.intellij.openapi.util.io.FileUtil +//import com.intellij.openapi.fileEditor.FileDocumentManager +//import com.intellij.psi.PsiDocumentManager +//import com.intellij.openapi.command.WriteCommandAction +//import com.intellij.openapi.application.ApplicationManager +//import com.intellij.psi.codeStyle.CodeStyleManager +// +//class JavaToKotlinAction(): AnAction() { +// public override fun actionPerformed(event : AnActionEvent?) { +// val converter = Converter() +// val psiFile = event!!.getData(LangDataKeys.PSI_FILE)!! +// ApplicationManager.getApplication()?.runWriteAction(object : Runnable { +// public override fun run() { +// val result = converter.fileToFile(psiFile as PsiJavaFile).toKotlin() +// val newName = FileUtil.getNameWithoutExtension(psiFile.getName()) + ".kt" +// val newFile = psiFile.getContainingDirectory()?.createFile(newName)!! +// val project = psiFile.getProject() +// val psiDocumentManager = PsiDocumentManager.getInstance(project)!! +// val document = psiDocumentManager.getDocument(newFile)!! +// document.setText(result) +// psiDocumentManager.doPostponedOperationsAndUnblockDocument(document) +// psiDocumentManager.commitDocument(document) +// CodeStyleManager.getInstance(project)!!.reformat(newFile) +// psiFile.setName(psiFile.getName() + ".old") +// newFile.navigate(true) +// } +// }) +// } +// +// +// public override fun update(e : AnActionEvent?) { +// val psiFile = e!!.getData(LangDataKeys.PSI_FILE) +// e.getPresentation().setEnabled(psiFile is PsiJavaFile) +// } +//} diff --git a/src/org/jetbrains/jet/j2k/ast/AnonymousClass.kt b/src/org/jetbrains/jet/j2k/ast/AnonymousClass.kt index 6747f39aa52..9c204f5961e 100644 --- a/src/org/jetbrains/jet/j2k/ast/AnonymousClass.kt +++ b/src/org/jetbrains/jet/j2k/ast/AnonymousClass.kt @@ -1,17 +1,17 @@ -package org.jetbrains.jet.j2k.ast - -import org.jetbrains.jet.j2k.Converter -import org.jetbrains.jet.j2k.ast.types.Type -import java.util.Collections - -public open class AnonymousClass(converter : Converter, members : List) - : Class(converter, - Identifier("anonClass"), - arrayList(), - Collections.emptySet()!!, - Collections.emptyList()!!, - Collections.emptyList()!!, - Collections.emptyList()!!, - Collections.emptyList()!!, members) { - public override fun toKotlin() = bodyToKotlin() -} +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.Converter +import org.jetbrains.jet.j2k.ast.types.Type +import java.util.Collections + +public open class AnonymousClass(converter : Converter, members : List) + : Class(converter, + Identifier("anonClass"), + arrayList(), + Collections.emptySet()!!, + Collections.emptyList()!!, + Collections.emptyList()!!, + Collections.emptyList()!!, + Collections.emptyList()!!, members) { + public override fun toKotlin() = bodyToKotlin() +} diff --git a/src/org/jetbrains/jet/j2k/ast/ArrayInitializerExpression.kt b/src/org/jetbrains/jet/j2k/ast/ArrayInitializerExpression.kt index ab8bd83b748..bf3e9199fe5 100644 --- a/src/org/jetbrains/jet/j2k/ast/ArrayInitializerExpression.kt +++ b/src/org/jetbrains/jet/j2k/ast/ArrayInitializerExpression.kt @@ -1,60 +1,60 @@ -package org.jetbrains.jet.j2k.ast - -import org.jetbrains.jet.j2k.ast.types.Type -import org.jetbrains.jet.lang.types.expressions.OperatorConventions -import java.util.* -import com.intellij.openapi.util.text.StringUtil - -public open class ArrayInitializerExpression(val `type` : Type, val initializers : List) : Expression() { - public override fun toKotlin() : String { - return createArrayFunction() + "(" + createInitializers() + ")" - } - - private fun createInitializers(): String { - return initializers.map { explicitConvertIfNeeded(it) }.makeString(", ") - } - - private fun createArrayFunction() : String { - var sType : String? = innerTypeStr() - if (Node.PRIMITIVE_TYPES.contains(sType)) { - return sType + "Array" - } - - return StringUtil.decapitalize(`type`.convertedToNotNull().toKotlin())!! - } - - private fun innerTypeStr() : String { - return `type`.convertedToNotNull().toKotlin().replace("Array", "").toLowerCase() - } - - private fun explicitConvertIfNeeded(i : Expression) : String { - val doubleOrFloatTypes = hashSet("double", "float", "java.lang.double", "java.lang.float") - val afterReplace : String = innerTypeStr().replace(">", "").replace("<", "").replace("?", "") - if (doubleOrFloatTypes.contains(afterReplace)) - { - if (i is LiteralExpression) { - if (i.toKotlin().contains(".")) { - return i.toKotlin() - } - - return i.toKotlin() + ".0" - } - - return "(" + i.toKotlin() + ")" + getConversion(afterReplace) - } - - return i.toKotlin() - } - - class object { - private open fun getConversion(afterReplace : String) : String { - if (afterReplace.contains("double")!!) - return "." + OperatorConventions.DOUBLE + "()" - - if (afterReplace.contains("float")!!) - return "." + OperatorConventions.FLOAT + "()" - - return "" - } - } -} +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.ast.types.Type +import org.jetbrains.jet.lang.types.expressions.OperatorConventions +import java.util.* +import com.intellij.openapi.util.text.StringUtil + +public open class ArrayInitializerExpression(val `type` : Type, val initializers : List) : Expression() { + public override fun toKotlin() : String { + return createArrayFunction() + "(" + createInitializers() + ")" + } + + private fun createInitializers(): String { + return initializers.map { explicitConvertIfNeeded(it) }.makeString(", ") + } + + private fun createArrayFunction() : String { + var sType : String? = innerTypeStr() + if (Node.PRIMITIVE_TYPES.contains(sType)) { + return sType + "Array" + } + + return StringUtil.decapitalize(`type`.convertedToNotNull().toKotlin())!! + } + + private fun innerTypeStr() : String { + return `type`.convertedToNotNull().toKotlin().replace("Array", "").toLowerCase() + } + + private fun explicitConvertIfNeeded(i : Expression) : String { + val doubleOrFloatTypes = hashSet("double", "float", "java.lang.double", "java.lang.float") + val afterReplace : String = innerTypeStr().replace(">", "").replace("<", "").replace("?", "") + if (doubleOrFloatTypes.contains(afterReplace)) + { + if (i is LiteralExpression) { + if (i.toKotlin().contains(".")) { + return i.toKotlin() + } + + return i.toKotlin() + ".0" + } + + return "(" + i.toKotlin() + ")" + getConversion(afterReplace) + } + + return i.toKotlin() + } + + class object { + private open fun getConversion(afterReplace : String) : String { + if (afterReplace.contains("double")!!) + return "." + OperatorConventions.DOUBLE + "()" + + if (afterReplace.contains("float")!!) + return "." + OperatorConventions.FLOAT + "()" + + return "" + } + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/ArrayWithoutInitializationExpression.kt b/src/org/jetbrains/jet/j2k/ast/ArrayWithoutInitializationExpression.kt index 45f2ec42c9c..054dea3464e 100644 --- a/src/org/jetbrains/jet/j2k/ast/ArrayWithoutInitializationExpression.kt +++ b/src/org/jetbrains/jet/j2k/ast/ArrayWithoutInitializationExpression.kt @@ -1,39 +1,39 @@ -package org.jetbrains.jet.j2k.ast - -import org.jetbrains.jet.j2k.ast.types.ArrayType -import org.jetbrains.jet.j2k.ast.types.Type - -public open class ArrayWithoutInitializationExpression(val `type` : Type, val expressions : List) : Expression() { - public override fun toKotlin() : String { - if (`type` is ArrayType) { - return constructInnerType(`type`, expressions) - } - - return getConstructorName(`type`) - } - - private fun constructInnerType(hostType : ArrayType, expressions: List) : String { - if (expressions.size() == 1) { - return oneDim(hostType, expressions[0]) - } - - val innerType = hostType.elementType - if (expressions.size() > 1 && innerType is ArrayType) { - return oneDim(hostType, expressions[0], "{" + constructInnerType(innerType, expressions.subList(1, expressions.size())) + "}") - } - - return getConstructorName(hostType) - } - - class object { - private open fun oneDim(`type` : Type, size : Expression) : String { - return oneDim(`type`, size, "") - } - - private open fun oneDim(`type` : Type, size : Expression, init : String) : String { - return getConstructorName(`type`) + "(" + size.toKotlin() + init.withPrefix(", ") + ")" - } - - private open fun getConstructorName(`type` : Type) : String = `type`.convertedToNotNull().toKotlin() - } -} +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.ast.types.ArrayType +import org.jetbrains.jet.j2k.ast.types.Type + +public open class ArrayWithoutInitializationExpression(val `type` : Type, val expressions : List) : Expression() { + public override fun toKotlin() : String { + if (`type` is ArrayType) { + return constructInnerType(`type`, expressions) + } + + return getConstructorName(`type`) + } + + private fun constructInnerType(hostType : ArrayType, expressions: List) : String { + if (expressions.size() == 1) { + return oneDim(hostType, expressions[0]) + } + + val innerType = hostType.elementType + if (expressions.size() > 1 && innerType is ArrayType) { + return oneDim(hostType, expressions[0], "{" + constructInnerType(innerType, expressions.subList(1, expressions.size())) + "}") + } + + return getConstructorName(hostType) + } + + class object { + private open fun oneDim(`type` : Type, size : Expression) : String { + return oneDim(`type`, size, "") + } + + private open fun oneDim(`type` : Type, size : Expression, init : String) : String { + return getConstructorName(`type`) + "(" + size.toKotlin() + init.withPrefix(", ") + ")" + } + + private open fun getConstructorName(`type` : Type) : String = `type`.convertedToNotNull().toKotlin() + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/AssertStatement.kt b/src/org/jetbrains/jet/j2k/ast/AssertStatement.kt index bc6df0f6986..6b732d61588 100644 --- a/src/org/jetbrains/jet/j2k/ast/AssertStatement.kt +++ b/src/org/jetbrains/jet/j2k/ast/AssertStatement.kt @@ -1,12 +1,12 @@ -package org.jetbrains.jet.j2k.ast - - -public open class AssertStatement(val condition : Expression, val detail : Expression) : Statement() { - public override fun toKotlin() : String { - var detail : String? = (if (detail != Expression.EMPTY_EXPRESSION) - "(" + detail.toKotlin() + ")" - else - "") - return "assert" + detail + " {" + condition.toKotlin() + "}" - } -} +package org.jetbrains.jet.j2k.ast + + +public open class AssertStatement(val condition : Expression, val detail : Expression) : Statement() { + public override fun toKotlin() : String { + var detail : String? = (if (detail != Expression.EMPTY_EXPRESSION) + "(" + detail.toKotlin() + ")" + else + "") + return "assert" + detail + " {" + condition.toKotlin() + "}" + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/Block.kt b/src/org/jetbrains/jet/j2k/ast/Block.kt index e407d1f723b..41cfe8f18bc 100644 --- a/src/org/jetbrains/jet/j2k/ast/Block.kt +++ b/src/org/jetbrains/jet/j2k/ast/Block.kt @@ -1,21 +1,21 @@ -package org.jetbrains.jet.j2k.ast - -import java.util.LinkedList - -public open class Block(val statements: List, val notEmpty: Boolean = false): Statement() { - public override fun isEmpty(): Boolean { - return !notEmpty && statements.size() == 0 - } - - public override fun toKotlin(): String { - if (!isEmpty()) { - return "{\n" + statements.toKotlin("\n") + "\n}" - } - - return "" - } - - class object { - public val EMPTY_BLOCK: Block = Block(arrayList()) - } -} +package org.jetbrains.jet.j2k.ast + +import java.util.LinkedList + +public open class Block(val statements: List, val notEmpty: Boolean = false): Statement() { + public override fun isEmpty(): Boolean { + return !notEmpty && statements.size() == 0 + } + + public override fun toKotlin(): String { + if (!isEmpty()) { + return "{\n" + statements.toKotlin("\n") + "\n}" + } + + return "" + } + + class object { + public val EMPTY_BLOCK: Block = Block(arrayList()) + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/CallChainExpression.kt b/src/org/jetbrains/jet/j2k/ast/CallChainExpression.kt index 22d411290c0..9d054b239f8 100644 --- a/src/org/jetbrains/jet/j2k/ast/CallChainExpression.kt +++ b/src/org/jetbrains/jet/j2k/ast/CallChainExpression.kt @@ -1,16 +1,16 @@ -package org.jetbrains.jet.j2k.ast - -public open class CallChainExpression(val expression : Expression, val identifier : Expression) : Expression() { - public override fun isNullable() : Boolean { - if (!expression.isEmpty() && expression.isNullable()) return true - return identifier.isNullable() - } - - public override fun toKotlin() : String { - if (!expression.isEmpty()) { - return expression.toKotlin() + (if (expression.isNullable()) "?." else ".") + identifier.toKotlin() - } - - return identifier.toKotlin() - } -} +package org.jetbrains.jet.j2k.ast + +public open class CallChainExpression(val expression : Expression, val identifier : Expression) : Expression() { + public override fun isNullable() : Boolean { + if (!expression.isEmpty() && expression.isNullable()) return true + return identifier.isNullable() + } + + public override fun toKotlin() : String { + if (!expression.isEmpty()) { + return expression.toKotlin() + (if (expression.isNullable()) "?." else ".") + identifier.toKotlin() + } + + return identifier.toKotlin() + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/Class.kt b/src/org/jetbrains/jet/j2k/ast/Class.kt index 71d86819e0f..436353c6a03 100644 --- a/src/org/jetbrains/jet/j2k/ast/Class.kt +++ b/src/org/jetbrains/jet/j2k/ast/Class.kt @@ -1,152 +1,152 @@ -package org.jetbrains.jet.j2k.ast - -import org.jetbrains.annotations.Nullable -import org.jetbrains.jet.j2k.Converter -import org.jetbrains.jet.j2k.J2KConverterFlags -import org.jetbrains.jet.j2k.ast.types.ClassType -import org.jetbrains.jet.j2k.ast.types.Type -import java.util.HashSet -import java.util.LinkedList -import java.util.ArrayList - -public open class Class(converter : Converter, - val name : Identifier, - val docComments: List, - modifiers : Set, - val typeParameters : List, - val extendsTypes : List, - val baseClassParams : List, - val implementsTypes : List, - members : List) : Member(modifiers) { - val members = getMembers(members, converter) - - open val TYPE: String - get() = "class" - - private fun getPrimaryConstructor() : Constructor? { - return members.find { it is Constructor && it.isPrimary } as Constructor? - } - - open fun primaryConstructorSignatureToKotlin() : String { - val maybeConstructor : Constructor? = getPrimaryConstructor() - return if (maybeConstructor != null) maybeConstructor.primarySignatureToKotlin() else "()" - } - - open fun primaryConstructorBodyToKotlin() : String? { - val maybeConstructor : Constructor? = getPrimaryConstructor() - if (maybeConstructor != null && !(maybeConstructor.block?.isEmpty() ?: true)) { - return maybeConstructor.primaryBodyToKotlin() - } - - return "" - } - - private fun hasWhere() : Boolean = typeParameters.any { it is TypeParameter && it.hasWhere() } - - open fun typeParameterWhereToKotlin() : String { - if (hasWhere()) { - val wheres = typeParameters.filter { it is TypeParameter }.map { (it as TypeParameter).getWhereToKotlin() } - return " where " + wheres.makeString(", ") + " " - } - return "" - } - - open fun membersExceptConstructors() : List = members.filterNot { it is Constructor } - - open fun secondaryConstructorsAsStaticInitFunction() : List { - return members.filter { it is Constructor && !it.isPrimary }.map { constructorToInit(it as Function) } - } - - private fun constructorToInit(f: Function): Function { - val modifiers = HashSet(f.modifiers) - modifiers.add(Modifier.STATIC) - val statements = ArrayList(f.block?.statements ?: listOf()) - statements.add(ReturnStatement(Identifier("__"))) - val block = Block(statements) - val constructorTypeParameters = ArrayList() - constructorTypeParameters.addAll(typeParameters) - constructorTypeParameters.addAll(f.typeParameters) - return Function(Identifier("init"), arrayList(), modifiers, ClassType(name, constructorTypeParameters, false), - constructorTypeParameters, f.params, block) - } - - open fun typeParametersToKotlin() : String = typeParameters.toKotlin(", ", "<", ">") - - open fun baseClassSignatureWithParams() : List { - if (TYPE.equals("class") && extendsTypes.size() == 1) { - val baseParams = baseClassParams.toKotlin(", ") - return arrayList(extendsTypes[0].toKotlin() + "(" + baseParams + ")") - } - return extendsTypes.map { it.toKotlin() } - } - - open fun implementTypesToKotlin() : String { - val allTypes = ArrayList() - allTypes.addAll(baseClassSignatureWithParams()) - allTypes.addAll(implementsTypes.map { it.toKotlin() }) - return if (allTypes.size() == 0) - "" - else - " : " + allTypes.makeString(", ") - } - - open fun modifiersToKotlin() : String { - val modifierList = ArrayList() - val modifier = accessModifier() - if (modifier != null) { - modifierList.add(modifier) - } - if (needAbstractModifier()) { - modifierList.add(Modifier.ABSTRACT) - } - - if (needOpenModifier()) { - modifierList.add(Modifier.OPEN) - } - return modifierList.toKotlin() - } - - open fun needOpenModifier() = !modifiers.contains(Modifier.FINAL) && !modifiers.contains(Modifier.ABSTRACT) - - open fun needAbstractModifier() = isAbstract() - - open fun bodyToKotlin() : String { - return " {\n" + getNonStatic(membersExceptConstructors()).toKotlin("\n") + "\n" + primaryConstructorBodyToKotlin() + "\n" + classObjectToKotlin() + "\n}" - } - - private fun classObjectToKotlin() : String { - val staticMembers = ArrayList() - staticMembers.addAll(secondaryConstructorsAsStaticInitFunction()) - staticMembers.addAll(getStatic(membersExceptConstructors())) - return staticMembers.toKotlin("\n", "class object {\n", "\n}") - } - - public override fun toKotlin() : String = - docComments.toKotlin("\n", "", "\n") + - modifiersToKotlin() + - TYPE + " " + name.toKotlin() + - typeParametersToKotlin() + - primaryConstructorSignatureToKotlin() + - implementTypesToKotlin() + - typeParameterWhereToKotlin() + - bodyToKotlin() - - class object { - open fun getMembers(members : List, converter : Converter) : List { - if (converter.hasFlag(J2KConverterFlags.SKIP_NON_PUBLIC_MEMBERS)) { - return members.filter { it is Comment || - (it as Member).accessModifier() == Modifier.PUBLIC || - (it as Member).accessModifier() == Modifier.PROTECTED } - } - return members - } - - private fun getStatic(members : List) : List { - return members.filter { it is Member && it.isStatic() } - } - - private fun getNonStatic(members : List) : List { - return members.filterNot { it is Member && it.isStatic() } - } - } -} +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.annotations.Nullable +import org.jetbrains.jet.j2k.Converter +import org.jetbrains.jet.j2k.J2KConverterFlags +import org.jetbrains.jet.j2k.ast.types.ClassType +import org.jetbrains.jet.j2k.ast.types.Type +import java.util.HashSet +import java.util.LinkedList +import java.util.ArrayList + +public open class Class(converter : Converter, + val name : Identifier, + val docComments: List, + modifiers : Set, + val typeParameters : List, + val extendsTypes : List, + val baseClassParams : List, + val implementsTypes : List, + members : List) : Member(modifiers) { + val members = getMembers(members, converter) + + open val TYPE: String + get() = "class" + + private fun getPrimaryConstructor() : Constructor? { + return members.find { it is Constructor && it.isPrimary } as Constructor? + } + + open fun primaryConstructorSignatureToKotlin() : String { + val maybeConstructor : Constructor? = getPrimaryConstructor() + return if (maybeConstructor != null) maybeConstructor.primarySignatureToKotlin() else "()" + } + + open fun primaryConstructorBodyToKotlin() : String? { + val maybeConstructor : Constructor? = getPrimaryConstructor() + if (maybeConstructor != null && !(maybeConstructor.block?.isEmpty() ?: true)) { + return maybeConstructor.primaryBodyToKotlin() + } + + return "" + } + + private fun hasWhere() : Boolean = typeParameters.any { it is TypeParameter && it.hasWhere() } + + open fun typeParameterWhereToKotlin() : String { + if (hasWhere()) { + val wheres = typeParameters.filter { it is TypeParameter }.map { (it as TypeParameter).getWhereToKotlin() } + return " where " + wheres.makeString(", ") + " " + } + return "" + } + + open fun membersExceptConstructors() : List = members.filterNot { it is Constructor } + + open fun secondaryConstructorsAsStaticInitFunction() : List { + return members.filter { it is Constructor && !it.isPrimary }.map { constructorToInit(it as Function) } + } + + private fun constructorToInit(f: Function): Function { + val modifiers = HashSet(f.modifiers) + modifiers.add(Modifier.STATIC) + val statements = ArrayList(f.block?.statements ?: listOf()) + statements.add(ReturnStatement(Identifier("__"))) + val block = Block(statements) + val constructorTypeParameters = ArrayList() + constructorTypeParameters.addAll(typeParameters) + constructorTypeParameters.addAll(f.typeParameters) + return Function(Identifier("init"), arrayList(), modifiers, ClassType(name, constructorTypeParameters, false), + constructorTypeParameters, f.params, block) + } + + open fun typeParametersToKotlin() : String = typeParameters.toKotlin(", ", "<", ">") + + open fun baseClassSignatureWithParams() : List { + if (TYPE.equals("class") && extendsTypes.size() == 1) { + val baseParams = baseClassParams.toKotlin(", ") + return arrayList(extendsTypes[0].toKotlin() + "(" + baseParams + ")") + } + return extendsTypes.map { it.toKotlin() } + } + + open fun implementTypesToKotlin() : String { + val allTypes = ArrayList() + allTypes.addAll(baseClassSignatureWithParams()) + allTypes.addAll(implementsTypes.map { it.toKotlin() }) + return if (allTypes.size() == 0) + "" + else + " : " + allTypes.makeString(", ") + } + + open fun modifiersToKotlin() : String { + val modifierList = ArrayList() + val modifier = accessModifier() + if (modifier != null) { + modifierList.add(modifier) + } + if (needAbstractModifier()) { + modifierList.add(Modifier.ABSTRACT) + } + + if (needOpenModifier()) { + modifierList.add(Modifier.OPEN) + } + return modifierList.toKotlin() + } + + open fun needOpenModifier() = !modifiers.contains(Modifier.FINAL) && !modifiers.contains(Modifier.ABSTRACT) + + open fun needAbstractModifier() = isAbstract() + + open fun bodyToKotlin() : String { + return " {\n" + getNonStatic(membersExceptConstructors()).toKotlin("\n") + "\n" + primaryConstructorBodyToKotlin() + "\n" + classObjectToKotlin() + "\n}" + } + + private fun classObjectToKotlin() : String { + val staticMembers = ArrayList() + staticMembers.addAll(secondaryConstructorsAsStaticInitFunction()) + staticMembers.addAll(getStatic(membersExceptConstructors())) + return staticMembers.toKotlin("\n", "class object {\n", "\n}") + } + + public override fun toKotlin() : String = + docComments.toKotlin("\n", "", "\n") + + modifiersToKotlin() + + TYPE + " " + name.toKotlin() + + typeParametersToKotlin() + + primaryConstructorSignatureToKotlin() + + implementTypesToKotlin() + + typeParameterWhereToKotlin() + + bodyToKotlin() + + class object { + open fun getMembers(members : List, converter : Converter) : List { + if (converter.hasFlag(J2KConverterFlags.SKIP_NON_PUBLIC_MEMBERS)) { + return members.filter { it is Comment || + (it as Member).accessModifier() == Modifier.PUBLIC || + (it as Member).accessModifier() == Modifier.PROTECTED } + } + return members + } + + private fun getStatic(members : List) : List { + return members.filter { it is Member && it.isStatic() } + } + + private fun getNonStatic(members : List) : List { + return members.filterNot { it is Member && it.isStatic() } + } + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/Constructor.kt b/src/org/jetbrains/jet/j2k/ast/Constructor.kt index bbdc4bba5bb..d46ff8e2e58 100644 --- a/src/org/jetbrains/jet/j2k/ast/Constructor.kt +++ b/src/org/jetbrains/jet/j2k/ast/Constructor.kt @@ -1,21 +1,21 @@ -package org.jetbrains.jet.j2k.ast - -import org.jetbrains.jet.j2k.ast.types.Type - -public open class Constructor(identifier : Identifier, - docComments: List, - modifiers : Set, - `type` : Type, - typeParameters : List, - params : Element, - block : Block, - val isPrimary : Boolean) : Function(identifier, docComments, modifiers, `type`, typeParameters, params, block) { - - public open fun primarySignatureToKotlin() : String { - return "(" + params.toKotlin() + ")" - } - - public open fun primaryBodyToKotlin() : String { - return block!!.toKotlin() - } -} +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.ast.types.Type + +public open class Constructor(identifier : Identifier, + docComments: List, + modifiers : Set, + `type` : Type, + typeParameters : List, + params : Element, + block : Block, + val isPrimary : Boolean) : Function(identifier, docComments, modifiers, `type`, typeParameters, params, block) { + + public open fun primarySignatureToKotlin() : String { + return "(" + params.toKotlin() + ")" + } + + public open fun primaryBodyToKotlin() : String { + return block!!.toKotlin() + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/DummyStringExpression.kt b/src/org/jetbrains/jet/j2k/ast/DummyStringExpression.kt index 286cbea4caa..466b0242aab 100644 --- a/src/org/jetbrains/jet/j2k/ast/DummyStringExpression.kt +++ b/src/org/jetbrains/jet/j2k/ast/DummyStringExpression.kt @@ -1,6 +1,6 @@ -package org.jetbrains.jet.j2k.ast - - -public open class DummyStringExpression(val string: String): Expression() { - public override fun toKotlin(): String = string -} +package org.jetbrains.jet.j2k.ast + + +public open class DummyStringExpression(val string: String): Expression() { + public override fun toKotlin(): String = string +} diff --git a/src/org/jetbrains/jet/j2k/ast/Element.kt b/src/org/jetbrains/jet/j2k/ast/Element.kt index a5533da574c..54e14041f41 100644 --- a/src/org/jetbrains/jet/j2k/ast/Element.kt +++ b/src/org/jetbrains/jet/j2k/ast/Element.kt @@ -1,17 +1,17 @@ -package org.jetbrains.jet.j2k.ast - - -public abstract class Element(): Node() { - public open fun isEmpty(): Boolean = false - - class object { - public val EMPTY_ELEMENT: Element = object : Element() { - override fun toKotlin() = "" - override fun isEmpty() = true - } - } -} - -public class Comment(val text: String): Element() { - override fun toKotlin() = text -} +package org.jetbrains.jet.j2k.ast + + +public abstract class Element(): Node() { + public open fun isEmpty(): Boolean = false + + class object { + public val EMPTY_ELEMENT: Element = object : Element() { + override fun toKotlin() = "" + override fun isEmpty() = true + } + } +} + +public class Comment(val text: String): Element() { + override fun toKotlin() = text +} diff --git a/src/org/jetbrains/jet/j2k/ast/Enum.kt b/src/org/jetbrains/jet/j2k/ast/Enum.kt index a092991df7c..28441f40214 100644 --- a/src/org/jetbrains/jet/j2k/ast/Enum.kt +++ b/src/org/jetbrains/jet/j2k/ast/Enum.kt @@ -1,34 +1,34 @@ -package org.jetbrains.jet.j2k.ast - -import org.jetbrains.jet.j2k.Converter -import org.jetbrains.jet.j2k.ast.types.Type - -public open class Enum(converter : Converter, - name : Identifier, - docComments: List, - modifiers : Set, - typeParameters : List, - extendsTypes : List, - baseClassParams : List, - implementsTypes : List, - members : List) : Class(converter, name, docComments, modifiers, typeParameters, - extendsTypes, baseClassParams, implementsTypes, members) { - - override fun primaryConstructorSignatureToKotlin() : String { - val s : String = super.primaryConstructorSignatureToKotlin() - return if (s.equals("()")) "" else s - } - - override fun needOpenModifier() = false - - public override fun toKotlin() : String { - return modifiersToKotlin() + - "enum class " + name.toKotlin() + - primaryConstructorSignatureToKotlin() + - typeParametersToKotlin() + - implementTypesToKotlin() + - " {\n" + membersExceptConstructors().toKotlin("\n") + "\n" + - primaryConstructorBodyToKotlin() + - "\npublic fun name() : String { return \"\" }\npublic fun order() : Int { return 0 }\n}" - } -} +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.Converter +import org.jetbrains.jet.j2k.ast.types.Type + +public open class Enum(converter : Converter, + name : Identifier, + docComments: List, + modifiers : Set, + typeParameters : List, + extendsTypes : List, + baseClassParams : List, + implementsTypes : List, + members : List) : Class(converter, name, docComments, modifiers, typeParameters, + extendsTypes, baseClassParams, implementsTypes, members) { + + override fun primaryConstructorSignatureToKotlin() : String { + val s : String = super.primaryConstructorSignatureToKotlin() + return if (s.equals("()")) "" else s + } + + override fun needOpenModifier() = false + + public override fun toKotlin() : String { + return modifiersToKotlin() + + "enum class " + name.toKotlin() + + primaryConstructorSignatureToKotlin() + + typeParametersToKotlin() + + implementTypesToKotlin() + + " {\n" + membersExceptConstructors().toKotlin("\n") + "\n" + + primaryConstructorBodyToKotlin() + + "\npublic fun name() : String { return \"\" }\npublic fun order() : Int { return 0 }\n}" + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/EnumConstant.kt b/src/org/jetbrains/jet/j2k/ast/EnumConstant.kt index ba38b6158cc..92d75a4f6d6 100644 --- a/src/org/jetbrains/jet/j2k/ast/EnumConstant.kt +++ b/src/org/jetbrains/jet/j2k/ast/EnumConstant.kt @@ -1,20 +1,20 @@ -package org.jetbrains.jet.j2k.ast - -import org.jetbrains.jet.j2k.ast.types.Type - -public open class EnumConstant(identifier : Identifier, - docComments: List, - modifiers : Set, - `type` : Type, - params : Element) : Field(identifier, docComments, modifiers, `type`.convertedToNotNull(), params, 0) { - - public override fun toKotlin() : String { - if (initializer.toKotlin().isEmpty()) { - return identifier.toKotlin() - } - - return identifier.toKotlin() + " : " + `type`.toKotlin() + "(" + initializer.toKotlin() + ")" - } - - -} +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.ast.types.Type + +public open class EnumConstant(identifier : Identifier, + docComments: List, + modifiers : Set, + `type` : Type, + params : Element) : Field(identifier, docComments, modifiers, `type`.convertedToNotNull(), params, 0) { + + public override fun toKotlin() : String { + if (initializer.toKotlin().isEmpty()) { + return identifier.toKotlin() + } + + return identifier.toKotlin() + " : " + `type`.toKotlin() + "(" + initializer.toKotlin() + ")" + } + + +} diff --git a/src/org/jetbrains/jet/j2k/ast/Expression.kt b/src/org/jetbrains/jet/j2k/ast/Expression.kt index 41f07c2d2fc..7407e1af4ef 100644 --- a/src/org/jetbrains/jet/j2k/ast/Expression.kt +++ b/src/org/jetbrains/jet/j2k/ast/Expression.kt @@ -1,15 +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 - } - } -} +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 + } + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/ExpressionList.kt b/src/org/jetbrains/jet/j2k/ast/ExpressionList.kt index 2875e2d889c..8cd8a22337b 100644 --- a/src/org/jetbrains/jet/j2k/ast/ExpressionList.kt +++ b/src/org/jetbrains/jet/j2k/ast/ExpressionList.kt @@ -1,7 +1,7 @@ -package org.jetbrains.jet.j2k.ast - -import org.jetbrains.jet.j2k.ast.types.Type - -public open class ExpressionList(val expressions: List): Expression() { - public override fun toKotlin(): String = expressions.map { it.toKotlin() }.makeString(", ") -} +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.ast.types.Type + +public open class ExpressionList(val expressions: List): Expression() { + public override fun toKotlin(): String = expressions.map { it.toKotlin() }.makeString(", ") +} diff --git a/src/org/jetbrains/jet/j2k/ast/Expressions.kt b/src/org/jetbrains/jet/j2k/ast/Expressions.kt index d3e9a028744..5b67b5b5fe1 100644 --- a/src/org/jetbrains/jet/j2k/ast/Expressions.kt +++ b/src/org/jetbrains/jet/j2k/ast/Expressions.kt @@ -1,58 +1,58 @@ -package org.jetbrains.jet.j2k.ast - -import org.jetbrains.jet.j2k.ast.types.Type - -public open class ArrayAccessExpression(val expression: Expression, val index: Expression, val lvalue: Boolean) : Expression() { - override fun toKotlin() = expression.toKotlin() + - (if (!lvalue && expression.isNullable()) "!!" else "") + - "[" + index.toKotlin() + "]" -} - -public open class AssignmentExpression(val left : Expression, val right : Expression, val op : String) : Expression() { - override fun toKotlin() = left.toKotlin() + " "+ op + " "+ right.toKotlin() -} - -public class BangBangExpression(val expr: Expression): Expression() { - override fun toKotlin() = expr.toKotlin() + "!!" -} - -public open class BinaryExpression(val left: Expression, val right: Expression, val op: String): Expression() { - override fun toKotlin() = left.toKotlin() + " " + op + " " + right.toKotlin() -} - -public open class ClassObjectAccessExpression(val typeElement: TypeElement): Expression() { - override fun toKotlin() = "javaClass<" + typeElement.toKotlinNotNull() + ">()" -} - -public open class IsOperator(val expression: Expression, val typeElement: TypeElement): Expression() { - override fun toKotlin() = expression.toKotlin() + " is " + typeElement.toKotlinNotNull() -} - -public open class TypeCastExpression(val `type` : Type, val expression : Expression) : Expression() { - override fun toKotlin() = "(" + expression.toKotlin() + " as " + `type`.toKotlin() + ")" -} - -public open class LiteralExpression(val literalText: String): Expression() { - override fun toKotlin() = literalText -} - -public open class ParenthesizedExpression(val expression : Expression) : Expression() { - override fun toKotlin() = "(" + expression.toKotlin() + ")" -} - -public open class PrefixOperator(val op: String, val expression: Expression): Expression() { - override fun toKotlin() = op + expression.toKotlin() - override fun isNullable() = expression.isNullable() -} - -public open class PostfixOperator(val op: String, val expression: Expression): Expression() { - override fun toKotlin() = expression.toKotlin() + op -} - -public open class ThisExpression(val identifier: Identifier) : Expression() { - override fun toKotlin() = "this" + identifier.withPrefix("@") -} - -public open class SuperExpression(val identifier : Identifier) : Expression() { - override fun toKotlin() = "super" + identifier.withPrefix("@") -} +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.ast.types.Type + +public open class ArrayAccessExpression(val expression: Expression, val index: Expression, val lvalue: Boolean) : Expression() { + override fun toKotlin() = expression.toKotlin() + + (if (!lvalue && expression.isNullable()) "!!" else "") + + "[" + index.toKotlin() + "]" +} + +public open class AssignmentExpression(val left : Expression, val right : Expression, val op : String) : Expression() { + override fun toKotlin() = left.toKotlin() + " "+ op + " "+ right.toKotlin() +} + +public class BangBangExpression(val expr: Expression): Expression() { + override fun toKotlin() = expr.toKotlin() + "!!" +} + +public open class BinaryExpression(val left: Expression, val right: Expression, val op: String): Expression() { + override fun toKotlin() = left.toKotlin() + " " + op + " " + right.toKotlin() +} + +public open class ClassObjectAccessExpression(val typeElement: TypeElement): Expression() { + override fun toKotlin() = "javaClass<" + typeElement.toKotlinNotNull() + ">()" +} + +public open class IsOperator(val expression: Expression, val typeElement: TypeElement): Expression() { + override fun toKotlin() = expression.toKotlin() + " is " + typeElement.toKotlinNotNull() +} + +public open class TypeCastExpression(val `type` : Type, val expression : Expression) : Expression() { + override fun toKotlin() = "(" + expression.toKotlin() + " as " + `type`.toKotlin() + ")" +} + +public open class LiteralExpression(val literalText: String): Expression() { + override fun toKotlin() = literalText +} + +public open class ParenthesizedExpression(val expression : Expression) : Expression() { + override fun toKotlin() = "(" + expression.toKotlin() + ")" +} + +public open class PrefixOperator(val op: String, val expression: Expression): Expression() { + override fun toKotlin() = op + expression.toKotlin() + override fun isNullable() = expression.isNullable() +} + +public open class PostfixOperator(val op: String, val expression: Expression): Expression() { + override fun toKotlin() = expression.toKotlin() + op +} + +public open class ThisExpression(val identifier: Identifier) : Expression() { + override fun toKotlin() = "this" + identifier.withPrefix("@") +} + +public open class SuperExpression(val identifier : Identifier) : Expression() { + override fun toKotlin() = "super" + identifier.withPrefix("@") +} diff --git a/src/org/jetbrains/jet/j2k/ast/Field.kt b/src/org/jetbrains/jet/j2k/ast/Field.kt index 1d81c890646..eeddca3c190 100644 --- a/src/org/jetbrains/jet/j2k/ast/Field.kt +++ b/src/org/jetbrains/jet/j2k/ast/Field.kt @@ -1,44 +1,44 @@ -package org.jetbrains.jet.j2k.ast - -import org.jetbrains.jet.j2k.ast.types.Type -import java.util.LinkedList -import org.jetbrains.jet.j2k.Converter -import java.util.ArrayList - -public open class Field(val identifier : Identifier, - val docComments: List, - modifiers : Set, - val `type` : Type, - val initializer : Element, - val writingAccesses : Int) : Member(modifiers) { - - open fun modifiersToKotlin() : String { - val modifierList = ArrayList() - if (isAbstract()) { - modifierList.add(Modifier.ABSTRACT) - } - - val modifier = accessModifier() - if (modifier != null) { - modifierList.add(modifier) - } - - return modifierList.toKotlin() + (if (isVal()) "val " else "var ") - } - - public open fun isVal() : Boolean = modifiers.contains(Modifier.FINAL) - public override fun isStatic() : Boolean = modifiers.contains(Modifier.STATIC) - - public override fun toKotlin() : String { - val declaration : String = docComments.toKotlin("\n", "", "\n") + - modifiersToKotlin() + identifier.toKotlin() + " : " + `type`.toKotlin() - if (initializer.isEmpty()) { - return declaration + ((if (isVal() && !isStatic() && writingAccesses == 1) - "" - else - " = " + Converter.getDefaultInitializer(this))) - } - - return declaration + " = " + initializer.toKotlin() - } -} +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.ast.types.Type +import java.util.LinkedList +import org.jetbrains.jet.j2k.Converter +import java.util.ArrayList + +public open class Field(val identifier : Identifier, + val docComments: List, + modifiers : Set, + val `type` : Type, + val initializer : Element, + val writingAccesses : Int) : Member(modifiers) { + + open fun modifiersToKotlin() : String { + val modifierList = ArrayList() + if (isAbstract()) { + modifierList.add(Modifier.ABSTRACT) + } + + val modifier = accessModifier() + if (modifier != null) { + modifierList.add(modifier) + } + + return modifierList.toKotlin() + (if (isVal()) "val " else "var ") + } + + public open fun isVal() : Boolean = modifiers.contains(Modifier.FINAL) + public override fun isStatic() : Boolean = modifiers.contains(Modifier.STATIC) + + public override fun toKotlin() : String { + val declaration : String = docComments.toKotlin("\n", "", "\n") + + modifiersToKotlin() + identifier.toKotlin() + " : " + `type`.toKotlin() + if (initializer.isEmpty()) { + return declaration + ((if (isVal() && !isStatic() && writingAccesses == 1) + "" + else + " = " + Converter.getDefaultInitializer(this))) + } + + return declaration + " = " + initializer.toKotlin() + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/File.kt b/src/org/jetbrains/jet/j2k/ast/File.kt index 3e542c9008e..1eed7fd8e49 100644 --- a/src/org/jetbrains/jet/j2k/ast/File.kt +++ b/src/org/jetbrains/jet/j2k/ast/File.kt @@ -1,16 +1,16 @@ -package org.jetbrains.jet.j2k.ast - -public open class File(val packageName: String, - val imports: MutableList, - val body: MutableList, - val mainFunction: String): Node() { - - public override fun toKotlin(): String { - val common: String = imports.toKotlin("\n") + "\n\n" + body.toKotlin("\n") + "\n" + mainFunction - if (packageName.isEmpty()) { - return common - } - - return "package " + packageName + "\n" + common - } -} +package org.jetbrains.jet.j2k.ast + +public open class File(val packageName: String, + val imports: MutableList, + val body: MutableList, + val mainFunction: String): Node() { + + public override fun toKotlin(): String { + val common: String = imports.toKotlin("\n") + "\n\n" + body.toKotlin("\n") + "\n" + mainFunction + if (packageName.isEmpty()) { + return common + } + + return "package " + packageName + "\n" + common + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/Function.kt b/src/org/jetbrains/jet/j2k/ast/Function.kt index 1f0f4ca9642..14aa520de93 100644 --- a/src/org/jetbrains/jet/j2k/ast/Function.kt +++ b/src/org/jetbrains/jet/j2k/ast/Function.kt @@ -1,71 +1,71 @@ -package org.jetbrains.jet.j2k.ast - -import java.util.LinkedList -import org.jetbrains.jet.j2k.ast.types.Type -import java.util.ArrayList - -public open class Function(val name : Identifier, - val docComments: List, - modifiers : Set, - val `type` : Type, - val typeParameters : List, - val params : Element, - var block : Block?) : Member(modifiers) { - private fun typeParametersToKotlin() : String { - return (if (typeParameters.size() > 0) - "<" + typeParameters.map { it.toKotlin() }.makeString(", ") + ">" - else - "") - } - - private fun hasWhere() : Boolean = typeParameters.any { it is TypeParameter && it.hasWhere() } - - private fun typeParameterWhereToKotlin() : String { - if (hasWhere()) - { - val wheres = typeParameters.filter { it is TypeParameter }.map { ((it as TypeParameter).getWhereToKotlin() )} - return " where " + wheres.makeString(", ") + " " - } - - return "" - } - - open fun modifiersToKotlin() : String { - val modifierList = ArrayList() - val accessModifier = accessModifier() - if (accessModifier != null) { - modifierList.add(accessModifier) - } - - if (isAbstract()) { - modifierList.add(Modifier.ABSTRACT) - } - - if (modifiers.contains(Modifier.OVERRIDE)) { - modifierList.add(Modifier.OVERRIDE) - } - - if (!modifiers.contains(Modifier.ABSTRACT) && - !modifiers.contains(Modifier.OVERRIDE) && - !modifiers.contains(Modifier.FINAL) && - !modifiers.contains(Modifier.PRIVATE)) { - modifierList.add(Modifier.OPEN) - } - - if (modifiers.contains(Modifier.NOT_OPEN)) { - modifierList.remove(Modifier.OPEN) - } - - return modifierList.toKotlin() - } - - public override fun toKotlin() : String { - return docComments.toKotlin("\n", "", "\n") + - modifiersToKotlin() + - "fun " + name.toKotlin() + - typeParametersToKotlin() + - "(" + params.toKotlin() + ") : " + - `type`.toKotlin() + " "+ typeParameterWhereToKotlin() + - block?.toKotlin() - } -} +package org.jetbrains.jet.j2k.ast + +import java.util.LinkedList +import org.jetbrains.jet.j2k.ast.types.Type +import java.util.ArrayList + +public open class Function(val name : Identifier, + val docComments: List, + modifiers : Set, + val `type` : Type, + val typeParameters : List, + val params : Element, + var block : Block?) : Member(modifiers) { + private fun typeParametersToKotlin() : String { + return (if (typeParameters.size() > 0) + "<" + typeParameters.map { it.toKotlin() }.makeString(", ") + ">" + else + "") + } + + private fun hasWhere() : Boolean = typeParameters.any { it is TypeParameter && it.hasWhere() } + + private fun typeParameterWhereToKotlin() : String { + if (hasWhere()) + { + val wheres = typeParameters.filter { it is TypeParameter }.map { ((it as TypeParameter).getWhereToKotlin() )} + return " where " + wheres.makeString(", ") + " " + } + + return "" + } + + open fun modifiersToKotlin() : String { + val modifierList = ArrayList() + val accessModifier = accessModifier() + if (accessModifier != null) { + modifierList.add(accessModifier) + } + + if (isAbstract()) { + modifierList.add(Modifier.ABSTRACT) + } + + if (modifiers.contains(Modifier.OVERRIDE)) { + modifierList.add(Modifier.OVERRIDE) + } + + if (!modifiers.contains(Modifier.ABSTRACT) && + !modifiers.contains(Modifier.OVERRIDE) && + !modifiers.contains(Modifier.FINAL) && + !modifiers.contains(Modifier.PRIVATE)) { + modifierList.add(Modifier.OPEN) + } + + if (modifiers.contains(Modifier.NOT_OPEN)) { + modifierList.remove(Modifier.OPEN) + } + + return modifierList.toKotlin() + } + + public override fun toKotlin() : String { + return docComments.toKotlin("\n", "", "\n") + + modifiersToKotlin() + + "fun " + name.toKotlin() + + typeParametersToKotlin() + + "(" + params.toKotlin() + ") : " + + `type`.toKotlin() + " "+ typeParameterWhereToKotlin() + + block?.toKotlin() + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/Identifier.kt b/src/org/jetbrains/jet/j2k/ast/Identifier.kt index 2ff5c86c2b2..40a21951c8e 100644 --- a/src/org/jetbrains/jet/j2k/ast/Identifier.kt +++ b/src/org/jetbrains/jet/j2k/ast/Identifier.kt @@ -1,31 +1,31 @@ -package org.jetbrains.jet.j2k.ast - - - -public open class Identifier(val name: String, - val myNullable: Boolean = true, - val quotingNeeded: Boolean = true): Expression() { - public override fun isEmpty() = name.length() == 0 - - private open fun ifNeedQuote(): String { - if (quotingNeeded && (ONLY_KOTLIN_KEYWORDS.contains(name)) || name.contains("$")) { - return quote(name) - } - - return name - } - - public override fun toKotlin(): String = ifNeedQuote() - public override fun isNullable(): Boolean = myNullable - - class object { - public val EMPTY_IDENTIFIER: Identifier = Identifier("") - private open fun quote(str: String): String { - return "`" + str + "`" - } - - public val ONLY_KOTLIN_KEYWORDS: Set = hashSet( - "package", "as", "type", "val", "var", "fun", "is", "in", "object", "when", "trait", "This" - ); - } -} +package org.jetbrains.jet.j2k.ast + + + +public open class Identifier(val name: String, + val myNullable: Boolean = true, + val quotingNeeded: Boolean = true): Expression() { + public override fun isEmpty() = name.length() == 0 + + private open fun ifNeedQuote(): String { + if (quotingNeeded && (ONLY_KOTLIN_KEYWORDS.contains(name)) || name.contains("$")) { + return quote(name) + } + + return name + } + + public override fun toKotlin(): String = ifNeedQuote() + public override fun isNullable(): Boolean = myNullable + + class object { + public val EMPTY_IDENTIFIER: Identifier = Identifier("") + private open fun quote(str: String): String { + return "`" + str + "`" + } + + public val ONLY_KOTLIN_KEYWORDS: Set = hashSet( + "package", "as", "type", "val", "var", "fun", "is", "in", "object", "when", "trait", "This" + ); + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/Import.kt b/src/org/jetbrains/jet/j2k/ast/Import.kt index 1d3ca5854b3..e7e6f111a75 100644 --- a/src/org/jetbrains/jet/j2k/ast/Import.kt +++ b/src/org/jetbrains/jet/j2k/ast/Import.kt @@ -1,6 +1,6 @@ -package org.jetbrains.jet.j2k.ast - - -public open class Import(val name: String): Node() { - public override fun toKotlin() = "import " + name -} +package org.jetbrains.jet.j2k.ast + + +public open class Import(val name: String): Node() { + public override fun toKotlin() = "import " + name +} diff --git a/src/org/jetbrains/jet/j2k/ast/Initializer.kt b/src/org/jetbrains/jet/j2k/ast/Initializer.kt index f32d9d2c194..e7ed361c05e 100644 --- a/src/org/jetbrains/jet/j2k/ast/Initializer.kt +++ b/src/org/jetbrains/jet/j2k/ast/Initializer.kt @@ -1,8 +1,8 @@ -package org.jetbrains.jet.j2k.ast - - -public open class Initializer(val block : Block, modifiers : Set) : Member(modifiers) { - public override fun toKotlin() : String { - return block.toKotlin() - } -} +package org.jetbrains.jet.j2k.ast + + +public open class Initializer(val block : Block, modifiers : Set) : Member(modifiers) { + public override fun toKotlin() : String { + return block.toKotlin() + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/LocalVariable.kt b/src/org/jetbrains/jet/j2k/ast/LocalVariable.kt index 74b5990f763..dc01898bec5 100644 --- a/src/org/jetbrains/jet/j2k/ast/LocalVariable.kt +++ b/src/org/jetbrains/jet/j2k/ast/LocalVariable.kt @@ -1,19 +1,19 @@ -package org.jetbrains.jet.j2k.ast - -import org.jetbrains.jet.j2k.ast.types.Type - -public open class LocalVariable(val identifier: Identifier, - val modifiersSet: Set, - val `type`: Type, - val initializer: Expression): Expression() { - - public open fun hasModifier(modifier: Modifier): Boolean = modifiersSet.contains(modifier) - - public override fun toKotlin(): String { - if (initializer.isEmpty()) { - return identifier.toKotlin() + " : " + `type`.toKotlin() - } - - return identifier.toKotlin() + " : " + `type`.toKotlin() + " = " + initializer.toKotlin() - } -} +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.ast.types.Type + +public open class LocalVariable(val identifier: Identifier, + val modifiersSet: Set, + val `type`: Type, + val initializer: Expression): Expression() { + + public open fun hasModifier(modifier: Modifier): Boolean = modifiersSet.contains(modifier) + + public override fun toKotlin(): String { + if (initializer.isEmpty()) { + return identifier.toKotlin() + " : " + `type`.toKotlin() + } + + return identifier.toKotlin() + " : " + `type`.toKotlin() + " = " + initializer.toKotlin() + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/Member.kt b/src/org/jetbrains/jet/j2k/ast/Member.kt index ca0cd0a5c1d..d0209b6621f 100644 --- a/src/org/jetbrains/jet/j2k/ast/Member.kt +++ b/src/org/jetbrains/jet/j2k/ast/Member.kt @@ -1,10 +1,10 @@ -package org.jetbrains.jet.j2k.ast - -public abstract class Member(val modifiers : Set) : Node() { - open fun accessModifier() : Modifier? { - return modifiers.find { m -> m == Modifier.PUBLIC || m == Modifier.PROTECTED || m == Modifier.PRIVATE } - } - - public open fun isAbstract() : Boolean = modifiers.contains(Modifier.ABSTRACT) - public open fun isStatic() : Boolean = modifiers.contains(Modifier.STATIC) -} +package org.jetbrains.jet.j2k.ast + +public abstract class Member(val modifiers : Set) : Node() { + open fun accessModifier() : Modifier? { + return modifiers.find { m -> m == Modifier.PUBLIC || m == Modifier.PROTECTED || m == Modifier.PRIVATE } + } + + public open fun isAbstract() : Boolean = modifiers.contains(Modifier.ABSTRACT) + public open fun isStatic() : Boolean = modifiers.contains(Modifier.STATIC) +} diff --git a/src/org/jetbrains/jet/j2k/ast/MethodCallExpression.kt b/src/org/jetbrains/jet/j2k/ast/MethodCallExpression.kt index c90a35cdaa7..95dd897effb 100644 --- a/src/org/jetbrains/jet/j2k/ast/MethodCallExpression.kt +++ b/src/org/jetbrains/jet/j2k/ast/MethodCallExpression.kt @@ -1,24 +1,24 @@ -package org.jetbrains.jet.j2k.ast - -import org.jetbrains.jet.j2k.ast.types.Type - -public open class MethodCallExpression(val methodCall: Expression, - val arguments: List, - val typeParameters: List, - val resultIsNullable: Boolean = false): Expression() { - public override fun isNullable(): Boolean = methodCall.isNullable() || resultIsNullable - - public override fun toKotlin(): String { - val typeParamsToKotlin: String = typeParameters.toKotlin(", ", "<", ">") - val argumentsMapped = arguments.map { it.toKotlin() } - return methodCall.toKotlin() + typeParamsToKotlin + "(" + argumentsMapped.makeString(", ") + ")" - } - - class object { - fun build(receiver: Expression, methodName: String, arguments: List = arrayList()): MethodCallExpression { - return MethodCallExpression(CallChainExpression(receiver, Identifier(methodName, false)), - arguments, - arrayList(), false) - } - } -} +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.ast.types.Type + +public open class MethodCallExpression(val methodCall: Expression, + val arguments: List, + val typeParameters: List, + val resultIsNullable: Boolean = false): Expression() { + public override fun isNullable(): Boolean = methodCall.isNullable() || resultIsNullable + + public override fun toKotlin(): String { + val typeParamsToKotlin: String = typeParameters.toKotlin(", ", "<", ">") + val argumentsMapped = arguments.map { it.toKotlin() } + return methodCall.toKotlin() + typeParamsToKotlin + "(" + argumentsMapped.makeString(", ") + ")" + } + + class object { + fun build(receiver: Expression, methodName: String, arguments: List = arrayList()): MethodCallExpression { + return MethodCallExpression(CallChainExpression(receiver, Identifier(methodName, false)), + arguments, + arrayList(), false) + } + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/Modifier.kt b/src/org/jetbrains/jet/j2k/ast/Modifier.kt index a80e39cee43..e204592d68a 100644 --- a/src/org/jetbrains/jet/j2k/ast/Modifier.kt +++ b/src/org/jetbrains/jet/j2k/ast/Modifier.kt @@ -1,33 +1,33 @@ -package org.jetbrains.jet.j2k.ast - - -/* - * 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. - */ -/** - * @author ignatov - */ -public enum class Modifier(val name: String) { - PUBLIC: Modifier("public") - PROTECTED: Modifier("protected") - PRIVATE: Modifier("private") - INTERNAL: Modifier("internal") - STATIC: Modifier("static") - ABSTRACT: Modifier("abstract") - FINAL: Modifier("final") - OPEN: Modifier("open") - NOT_OPEN: Modifier("not open") - OVERRIDE: Modifier("override") -} +package org.jetbrains.jet.j2k.ast + + +/* + * 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. + */ +/** + * @author ignatov + */ +public enum class Modifier(val name: String) { + PUBLIC: Modifier("public") + PROTECTED: Modifier("protected") + PRIVATE: Modifier("private") + INTERNAL: Modifier("internal") + STATIC: Modifier("static") + ABSTRACT: Modifier("abstract") + FINAL: Modifier("final") + OPEN: Modifier("open") + NOT_OPEN: Modifier("not open") + OVERRIDE: Modifier("override") +} diff --git a/src/org/jetbrains/jet/j2k/ast/NewClassExpression.kt b/src/org/jetbrains/jet/j2k/ast/NewClassExpression.kt index 55551140634..ff6102ad076 100644 --- a/src/org/jetbrains/jet/j2k/ast/NewClassExpression.kt +++ b/src/org/jetbrains/jet/j2k/ast/NewClassExpression.kt @@ -1,24 +1,24 @@ -package org.jetbrains.jet.j2k.ast - -import org.jetbrains.annotations.Nullable - -public open class NewClassExpression(val name: Element, - val arguments: List, - val qualifier: Expression = Expression.EMPTY_EXPRESSION, - val anonymousClass: AnonymousClass? = null): Expression() { - public override fun toKotlin(): String { - val callOperator: String? = (if (qualifier.isNullable()!!) - "?." - else - ".") - val qualifier: String? = (if (qualifier.isEmpty()!!) - "" - else - qualifier.toKotlin() + callOperator) - val appliedArguments: String = arguments.toKotlin(", ") - return (if (anonymousClass != null) - "object : " + qualifier + name.toKotlin() + "(" + appliedArguments + ")" + anonymousClass.toKotlin() - else - qualifier + name.toKotlin() + "(" + appliedArguments + ")") - } -} +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.annotations.Nullable + +public open class NewClassExpression(val name: Element, + val arguments: List, + val qualifier: Expression = Expression.EMPTY_EXPRESSION, + val anonymousClass: AnonymousClass? = null): Expression() { + public override fun toKotlin(): String { + val callOperator: String? = (if (qualifier.isNullable()!!) + "?." + else + ".") + val qualifier: String? = (if (qualifier.isEmpty()!!) + "" + else + qualifier.toKotlin() + callOperator) + val appliedArguments: String = arguments.toKotlin(", ") + return (if (anonymousClass != null) + "object : " + qualifier + name.toKotlin() + "(" + appliedArguments + ")" + anonymousClass.toKotlin() + else + qualifier + name.toKotlin() + "(" + appliedArguments + ")") + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/Node.kt b/src/org/jetbrains/jet/j2k/ast/Node.kt index 4e52c134ce1..fda9672fbf0 100644 --- a/src/org/jetbrains/jet/j2k/ast/Node.kt +++ b/src/org/jetbrains/jet/j2k/ast/Node.kt @@ -1,11 +1,11 @@ -package org.jetbrains.jet.j2k.ast - - -public abstract class Node() { - public abstract fun toKotlin(): String - - class object { - public val PRIMITIVE_TYPES: Set = hashSet( - "double", "float", "long", "int", "short", "byte", "boolean", "char") - } -} +package org.jetbrains.jet.j2k.ast + + +public abstract class Node() { + public abstract fun toKotlin(): String + + class object { + public val PRIMITIVE_TYPES: Set = hashSet( + "double", "float", "long", "int", "short", "byte", "boolean", "char") + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/Parameter.kt b/src/org/jetbrains/jet/j2k/ast/Parameter.kt index 598e87ab9b0..52f369a4c88 100644 --- a/src/org/jetbrains/jet/j2k/ast/Parameter.kt +++ b/src/org/jetbrains/jet/j2k/ast/Parameter.kt @@ -1,18 +1,18 @@ -package org.jetbrains.jet.j2k.ast - -import org.jetbrains.jet.j2k.ast.types.Type -import org.jetbrains.jet.j2k.ast.types.VarArg - -public open class Parameter(val identifier : Identifier, val `type` : Type, val readOnly: Boolean = true) : Expression() { - public override fun toKotlin() : String { - val vararg : String = (if (`type` is VarArg) - "vararg " - else - "") - val `var` : String? = (if (readOnly) - "" - else - "var ") - return vararg + `var` + identifier.toKotlin() + " : " + `type`.toKotlin() - } -} +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.ast.types.Type +import org.jetbrains.jet.j2k.ast.types.VarArg + +public open class Parameter(val identifier : Identifier, val `type` : Type, val readOnly: Boolean = true) : Expression() { + public override fun toKotlin() : String { + val vararg : String = (if (`type` is VarArg) + "vararg " + else + "") + val `var` : String? = (if (readOnly) + "" + else + "var ") + return vararg + `var` + identifier.toKotlin() + " : " + `type`.toKotlin() + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/ParameterList.kt b/src/org/jetbrains/jet/j2k/ast/ParameterList.kt index 1d60838398f..915c75d4460 100644 --- a/src/org/jetbrains/jet/j2k/ast/ParameterList.kt +++ b/src/org/jetbrains/jet/j2k/ast/ParameterList.kt @@ -1,7 +1,7 @@ -package org.jetbrains.jet.j2k.ast - - -public open class ParameterList(val parameters : List) : Expression() { - public override fun toKotlin() = parameters.map { it.toKotlin() }.makeString(", ") -} - +package org.jetbrains.jet.j2k.ast + + +public open class ParameterList(val parameters : List) : Expression() { + public override fun toKotlin() = parameters.map { it.toKotlin() }.makeString(", ") +} + diff --git a/src/org/jetbrains/jet/j2k/ast/PolyadicExpression.kt b/src/org/jetbrains/jet/j2k/ast/PolyadicExpression.kt index 133ab955168..ec46460b7f7 100644 --- a/src/org/jetbrains/jet/j2k/ast/PolyadicExpression.kt +++ b/src/org/jetbrains/jet/j2k/ast/PolyadicExpression.kt @@ -1,9 +1,9 @@ -package org.jetbrains.jet.j2k.ast - - -public open class PolyadicExpression(val expressions: List, val token: String): Expression() { - public override fun toKotlin(): String { - val expressionsWithConversions = expressions.map { it.toKotlin() } - return expressionsWithConversions.makeString(" " + token + " ") - } -} +package org.jetbrains.jet.j2k.ast + + +public open class PolyadicExpression(val expressions: List, val token: String): Expression() { + public override fun toKotlin(): String { + val expressionsWithConversions = expressions.map { it.toKotlin() } + return expressionsWithConversions.makeString(" " + token + " ") + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/ReferenceElement.kt b/src/org/jetbrains/jet/j2k/ast/ReferenceElement.kt index 09004afafee..dafba30e512 100644 --- a/src/org/jetbrains/jet/j2k/ast/ReferenceElement.kt +++ b/src/org/jetbrains/jet/j2k/ast/ReferenceElement.kt @@ -1,7 +1,7 @@ -package org.jetbrains.jet.j2k.ast - -import org.jetbrains.jet.j2k.ast.types.Type - -public open class ReferenceElement(val reference : Identifier, val types : List) : Element() { - public override fun toKotlin() = reference.toKotlin() + types.toKotlin(", ", "<", ">") -} +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.ast.types.Type + +public open class ReferenceElement(val reference : Identifier, val types : List) : Element() { + public override fun toKotlin() = reference.toKotlin() + types.toKotlin(", ", "<", ">") +} diff --git a/src/org/jetbrains/jet/j2k/ast/Statements.kt b/src/org/jetbrains/jet/j2k/ast/Statements.kt index 4d220691240..a924e7245e3 100644 --- a/src/org/jetbrains/jet/j2k/ast/Statements.kt +++ b/src/org/jetbrains/jet/j2k/ast/Statements.kt @@ -1,132 +1,132 @@ -package org.jetbrains.jet.j2k.ast - - -public abstract class Statement(): Element() { - class object { - public val EMPTY_STATEMENT: Statement = object : Statement() { - public override fun toKotlin() = "" - } - } -} - -public open class DeclarationStatement(val elements: List): Statement() { - public override fun toKotlin(): String { - return elements.filter { it is LocalVariable }.map { convertDeclaration(it as LocalVariable) }.makeString("\n") - } - - private fun convertDeclaration(v: LocalVariable): String { - val varKeyword: String? = (if (v.hasModifier(Modifier.FINAL)) - "val" - else - "var") - return varKeyword + " " + v.toKotlin() - } -} - -public open class ExpressionListStatement(val expressions: List): Expression() { - public override fun toKotlin() = expressions.toKotlin("\n") -} - -public open class LabelStatement(val name: Identifier, val statement: Element): Statement() { - public override fun toKotlin(): String = "@" + name.toKotlin() + " " + statement.toKotlin() -} - -public open class ReturnStatement(val expression: Expression): Statement() { - public override fun toKotlin() = "return " + expression.toKotlin() -} - -public open class IfStatement(val condition: Expression, - val thenStatement: Element, - val elseStatement: Element): Expression() { - public override fun toKotlin(): String { - val result: String = "if (" + condition.toKotlin() + ")\n" + thenStatement.toKotlin() + "\n" - if (elseStatement != Statement.EMPTY_STATEMENT) { - return result + "else\n" + elseStatement.toKotlin() - } - - return result - } -} - -// Loops -------------------------------------------------------------------------------------------------- - -public open class WhileStatement(val condition: Expression, val body: Element): Statement() { - public override fun toKotlin() = "while (" + condition.toKotlin() + ")\n" + body.toKotlin() -} - -public open class DoWhileStatement(condition: Expression, body: Element): WhileStatement(condition, body) { - public override fun toKotlin() = "do\n" + body.toKotlin() + "\nwhile (" + condition.toKotlin() + ")" -} - -public open class ForeachStatement(val variable: Parameter, - val expression: Expression, - val body: Element): Statement() { - public override fun toKotlin() = "for (" + variable.toKotlin() + " in " + - expression.toKotlin() + ")\n" + body.toKotlin() -} - -public open class ForeachWithRangeStatement(val identifier: Identifier, - val start: Expression, - val end: Expression, - val body: Element): Statement() { - public override fun toKotlin() = "for (" + identifier.toKotlin() + " in " + - start.toKotlin() + ".." + end.toKotlin() + ") " + body.toKotlin() -} - -public open class BreakStatement(val label: Identifier = Identifier.EMPTY_IDENTIFIER) : Statement() { - public override fun toKotlin() = "break" + label.withPrefix("@") -} - -public open class ContinueStatement(val label: Identifier = Identifier.EMPTY_IDENTIFIER): Statement() { - public override fun toKotlin() = "continue" + label.withPrefix("@") -} - -// Exceptions ---------------------------------------------------------------------------------------------- - -public open class TryStatement(val block: Block, val catches: List, val finallyBlock: Block): Statement() { - public override fun toKotlin(): String { - return "try\n" + block.toKotlin() + "\n" + catches.toKotlin("\n") + "\n" + (if (finallyBlock.isEmpty()) - "" - else - "finally\n" + finallyBlock.toKotlin()) - } -} - -public open class ThrowStatement(val expression: Expression): Expression() { - public override fun toKotlin() = "throw " + expression.toKotlin() -} - -public open class CatchStatement(val variable: Parameter, val block: Block): Statement() { - public override fun toKotlin(): String = "catch (" + variable.toKotlin() + ") " + block.toKotlin() -} - -// Switch -------------------------------------------------------------------------------------------------- - -public open class SwitchContainer(val expression: Expression, val caseContainers: List): Statement() { - public override fun toKotlin() = "when (" + expression.toKotlin() + ") {\n" + caseContainers.toKotlin("\n") + "\n}" -} - -public open class CaseContainer(val caseStatement: List, statements: List): Statement() { - private val myBlock: Block - - { - val newStatements = statements.filterNot { it is BreakStatement || it is ContinueStatement } - myBlock = Block(newStatements, false) - } - - public override fun toKotlin() = caseStatement.toKotlin(", ") + " -> " + myBlock.toKotlin() -} - -public open class SwitchLabelStatement(val expression: Expression): Statement() { - public override fun toKotlin() = expression.toKotlin() -} - -public open class DefaultSwitchLabelStatement(): Statement() { - public override fun toKotlin() = "else" -} - -// Other ------------------------------------------------------------------------------------------------------ - -public open class SynchronizedStatement(val expression: Expression, val block: Block): Statement() { - public override fun toKotlin() = "synchronized (" + expression.toKotlin() + ") "+ block.toKotlin() -} +package org.jetbrains.jet.j2k.ast + + +public abstract class Statement(): Element() { + class object { + public val EMPTY_STATEMENT: Statement = object : Statement() { + public override fun toKotlin() = "" + } + } +} + +public open class DeclarationStatement(val elements: List): Statement() { + public override fun toKotlin(): String { + return elements.filter { it is LocalVariable }.map { convertDeclaration(it as LocalVariable) }.makeString("\n") + } + + private fun convertDeclaration(v: LocalVariable): String { + val varKeyword: String? = (if (v.hasModifier(Modifier.FINAL)) + "val" + else + "var") + return varKeyword + " " + v.toKotlin() + } +} + +public open class ExpressionListStatement(val expressions: List): Expression() { + public override fun toKotlin() = expressions.toKotlin("\n") +} + +public open class LabelStatement(val name: Identifier, val statement: Element): Statement() { + public override fun toKotlin(): String = "@" + name.toKotlin() + " " + statement.toKotlin() +} + +public open class ReturnStatement(val expression: Expression): Statement() { + public override fun toKotlin() = "return " + expression.toKotlin() +} + +public open class IfStatement(val condition: Expression, + val thenStatement: Element, + val elseStatement: Element): Expression() { + public override fun toKotlin(): String { + val result: String = "if (" + condition.toKotlin() + ")\n" + thenStatement.toKotlin() + "\n" + if (elseStatement != Statement.EMPTY_STATEMENT) { + return result + "else\n" + elseStatement.toKotlin() + } + + return result + } +} + +// Loops -------------------------------------------------------------------------------------------------- + +public open class WhileStatement(val condition: Expression, val body: Element): Statement() { + public override fun toKotlin() = "while (" + condition.toKotlin() + ")\n" + body.toKotlin() +} + +public open class DoWhileStatement(condition: Expression, body: Element): WhileStatement(condition, body) { + public override fun toKotlin() = "do\n" + body.toKotlin() + "\nwhile (" + condition.toKotlin() + ")" +} + +public open class ForeachStatement(val variable: Parameter, + val expression: Expression, + val body: Element): Statement() { + public override fun toKotlin() = "for (" + variable.toKotlin() + " in " + + expression.toKotlin() + ")\n" + body.toKotlin() +} + +public open class ForeachWithRangeStatement(val identifier: Identifier, + val start: Expression, + val end: Expression, + val body: Element): Statement() { + public override fun toKotlin() = "for (" + identifier.toKotlin() + " in " + + start.toKotlin() + ".." + end.toKotlin() + ") " + body.toKotlin() +} + +public open class BreakStatement(val label: Identifier = Identifier.EMPTY_IDENTIFIER) : Statement() { + public override fun toKotlin() = "break" + label.withPrefix("@") +} + +public open class ContinueStatement(val label: Identifier = Identifier.EMPTY_IDENTIFIER): Statement() { + public override fun toKotlin() = "continue" + label.withPrefix("@") +} + +// Exceptions ---------------------------------------------------------------------------------------------- + +public open class TryStatement(val block: Block, val catches: List, val finallyBlock: Block): Statement() { + public override fun toKotlin(): String { + return "try\n" + block.toKotlin() + "\n" + catches.toKotlin("\n") + "\n" + (if (finallyBlock.isEmpty()) + "" + else + "finally\n" + finallyBlock.toKotlin()) + } +} + +public open class ThrowStatement(val expression: Expression): Expression() { + public override fun toKotlin() = "throw " + expression.toKotlin() +} + +public open class CatchStatement(val variable: Parameter, val block: Block): Statement() { + public override fun toKotlin(): String = "catch (" + variable.toKotlin() + ") " + block.toKotlin() +} + +// Switch -------------------------------------------------------------------------------------------------- + +public open class SwitchContainer(val expression: Expression, val caseContainers: List): Statement() { + public override fun toKotlin() = "when (" + expression.toKotlin() + ") {\n" + caseContainers.toKotlin("\n") + "\n}" +} + +public open class CaseContainer(val caseStatement: List, statements: List): Statement() { + private val myBlock: Block + + { + val newStatements = statements.filterNot { it is BreakStatement || it is ContinueStatement } + myBlock = Block(newStatements, false) + } + + public override fun toKotlin() = caseStatement.toKotlin(", ") + " -> " + myBlock.toKotlin() +} + +public open class SwitchLabelStatement(val expression: Expression): Statement() { + public override fun toKotlin() = expression.toKotlin() +} + +public open class DefaultSwitchLabelStatement(): Statement() { + public override fun toKotlin() = "else" +} + +// Other ------------------------------------------------------------------------------------------------------ + +public open class SynchronizedStatement(val expression: Expression, val block: Block): Statement() { + public override fun toKotlin() = "synchronized (" + expression.toKotlin() + ") "+ block.toKotlin() +} diff --git a/src/org/jetbrains/jet/j2k/ast/Trait.kt b/src/org/jetbrains/jet/j2k/ast/Trait.kt index 2ed12e0f4dc..03c519118e0 100644 --- a/src/org/jetbrains/jet/j2k/ast/Trait.kt +++ b/src/org/jetbrains/jet/j2k/ast/Trait.kt @@ -1,22 +1,22 @@ -package org.jetbrains.jet.j2k.ast - -import org.jetbrains.jet.j2k.Converter -import org.jetbrains.jet.j2k.ast.types.Type - -public open class Trait(converter : Converter, - name : Identifier, - docComments: List, - modifiers : Set, - typeParameters : List, - extendsTypes : List, - baseClassParams : List, - implementsTypes : List, - members : List) : Class(converter, name, docComments, modifiers, typeParameters, - extendsTypes, baseClassParams, implementsTypes, members) { - - override val TYPE: String - get() = "trait" - - override fun primaryConstructorSignatureToKotlin() = "" - override fun needOpenModifier() = false -} +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.Converter +import org.jetbrains.jet.j2k.ast.types.Type + +public open class Trait(converter : Converter, + name : Identifier, + docComments: List, + modifiers : Set, + typeParameters : List, + extendsTypes : List, + baseClassParams : List, + implementsTypes : List, + members : List) : Class(converter, name, docComments, modifiers, typeParameters, + extendsTypes, baseClassParams, implementsTypes, members) { + + override val TYPE: String + get() = "trait" + + override fun primaryConstructorSignatureToKotlin() = "" + override fun needOpenModifier() = false +} diff --git a/src/org/jetbrains/jet/j2k/ast/TypeElement.kt b/src/org/jetbrains/jet/j2k/ast/TypeElement.kt index f4671c17e77..2498971ac94 100644 --- a/src/org/jetbrains/jet/j2k/ast/TypeElement.kt +++ b/src/org/jetbrains/jet/j2k/ast/TypeElement.kt @@ -1,9 +1,9 @@ -package org.jetbrains.jet.j2k.ast - -import org.jetbrains.jet.j2k.ast.types.Type - -public open class TypeElement(val `type` : Type) : Element() { - override fun toKotlin() = `type`.toKotlin() - - public fun toKotlinNotNull(): String = `type`.convertedToNotNull().toKotlin() -} +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.ast.types.Type + +public open class TypeElement(val `type` : Type) : Element() { + override fun toKotlin() = `type`.toKotlin() + + public fun toKotlinNotNull(): String = `type`.convertedToNotNull().toKotlin() +} diff --git a/src/org/jetbrains/jet/j2k/ast/TypeParameter.kt b/src/org/jetbrains/jet/j2k/ast/TypeParameter.kt index c62b9af0ebc..004b55f8dca 100644 --- a/src/org/jetbrains/jet/j2k/ast/TypeParameter.kt +++ b/src/org/jetbrains/jet/j2k/ast/TypeParameter.kt @@ -1,22 +1,22 @@ -package org.jetbrains.jet.j2k.ast - -import org.jetbrains.jet.j2k.ast.types.Type - -public open class TypeParameter(val name : Identifier, val extendsTypes : List) : Element() { - public open fun hasWhere() : Boolean = extendsTypes.size() > 1 - public open fun getWhereToKotlin() : String { - if (hasWhere()) { - return name.toKotlin() + " : " + extendsTypes.get(1).toKotlin() - } - - return "" - } - - public override fun toKotlin() : String { - if (extendsTypes.size() > 0) { - return name.toKotlin() + " : " + extendsTypes [0].toKotlin() - } - - return name.toKotlin() - } -} +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.ast.types.Type + +public open class TypeParameter(val name : Identifier, val extendsTypes : List) : Element() { + public open fun hasWhere() : Boolean = extendsTypes.size() > 1 + public open fun getWhereToKotlin() : String { + if (hasWhere()) { + return name.toKotlin() + " : " + extendsTypes.get(1).toKotlin() + } + + return "" + } + + public override fun toKotlin() : String { + if (extendsTypes.size() > 0) { + return name.toKotlin() + " : " + extendsTypes [0].toKotlin() + } + + return name.toKotlin() + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/Util.kt b/src/org/jetbrains/jet/j2k/ast/Util.kt index 2e339529cee..70c4328315c 100644 --- a/src/org/jetbrains/jet/j2k/ast/Util.kt +++ b/src/org/jetbrains/jet/j2k/ast/Util.kt @@ -1,28 +1,28 @@ -package org.jetbrains.jet.j2k.ast - -fun List.toKotlin(separator: String, prefix: String = "", suffix: String = ""): String { - val result = StringBuilder() - if (size() > 0) { - result.append(prefix) - var first = true - for(x in this) { - if (!first) result.append(separator) - first = false - result.append(x.toKotlin()) - } - result.append(suffix) - } - return result.toString() -} - -fun Collection.toKotlin(separator: String = " "): String { - val result = StringBuilder() - for(x in this) { - result.append(x.name) - result.append(separator) - } - return result.toString() -} - -fun String.withPrefix(prefix: String) = if (isEmpty()) "" else prefix + this -fun Expression.withPrefix(prefix: String) = if (isEmpty()) "" else prefix + toKotlin() +package org.jetbrains.jet.j2k.ast + +fun List.toKotlin(separator: String, prefix: String = "", suffix: String = ""): String { + val result = StringBuilder() + if (size() > 0) { + result.append(prefix) + var first = true + for(x in this) { + if (!first) result.append(separator) + first = false + result.append(x.toKotlin()) + } + result.append(suffix) + } + return result.toString() +} + +fun Collection.toKotlin(separator: String = " "): String { + val result = StringBuilder() + for(x in this) { + result.append(x.name) + result.append(separator) + } + return result.toString() +} + +fun String.withPrefix(prefix: String) = if (isEmpty()) "" else prefix + this +fun Expression.withPrefix(prefix: String) = if (isEmpty()) "" else prefix + toKotlin() diff --git a/src/org/jetbrains/jet/j2k/ast/types/ArrayType.kt b/src/org/jetbrains/jet/j2k/ast/types/ArrayType.kt index d51e6ca1568..b1427e86395 100644 --- a/src/org/jetbrains/jet/j2k/ast/types/ArrayType.kt +++ b/src/org/jetbrains/jet/j2k/ast/types/ArrayType.kt @@ -1,13 +1,13 @@ -package org.jetbrains.jet.j2k.ast.types - -public open class ArrayType(val elementType : Type, nullable: Boolean) : Type(nullable) { - 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) -} +package org.jetbrains.jet.j2k.ast.types + +public open class ArrayType(val elementType : Type, nullable: Boolean) : Type(nullable) { + 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) +} diff --git a/src/org/jetbrains/jet/j2k/ast/types/ClassType.kt b/src/org/jetbrains/jet/j2k/ast/types/ClassType.kt index 40cbb8ebec0..7c4c0660954 100644 --- a/src/org/jetbrains/jet/j2k/ast/types/ClassType.kt +++ b/src/org/jetbrains/jet/j2k/ast/types/ClassType.kt @@ -1,24 +1,24 @@ -package org.jetbrains.jet.j2k.ast.types - -import org.jetbrains.jet.j2k.ast.Element -import org.jetbrains.jet.j2k.ast.Identifier -import java.util.Collections -import java.util.ArrayList - -public open class ClassType(val `type` : Identifier, val parameters : List, nullable : Boolean) : Type(nullable) { - public override fun toKotlin() : String { - // TODO change to map() when KT-2051 is fixed - val parametersToKotlin = 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) -} +package org.jetbrains.jet.j2k.ast.types + +import org.jetbrains.jet.j2k.ast.Element +import org.jetbrains.jet.j2k.ast.Identifier +import java.util.Collections +import java.util.ArrayList + +public open class ClassType(val `type` : Identifier, val parameters : List, nullable : Boolean) : Type(nullable) { + public override fun toKotlin() : String { + // TODO change to map() when KT-2051 is fixed + val parametersToKotlin = 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) +} diff --git a/src/org/jetbrains/jet/j2k/ast/types/EmptyType.kt b/src/org/jetbrains/jet/j2k/ast/types/EmptyType.kt index 948840c7307..4ab69a3931c 100644 --- a/src/org/jetbrains/jet/j2k/ast/types/EmptyType.kt +++ b/src/org/jetbrains/jet/j2k/ast/types/EmptyType.kt @@ -1,5 +1,5 @@ -package org.jetbrains.jet.j2k.ast.types - -public open class EmptyType() : Type(false) { - public override fun toKotlin() : String = "UNRESOLVED_TYPE" -} +package org.jetbrains.jet.j2k.ast.types + +public open class EmptyType() : Type(false) { + public override fun toKotlin() : String = "UNRESOLVED_TYPE" +} diff --git a/src/org/jetbrains/jet/j2k/ast/types/InProjectionType.kt b/src/org/jetbrains/jet/j2k/ast/types/InProjectionType.kt index dd01f68f261..246a24b221a 100644 --- a/src/org/jetbrains/jet/j2k/ast/types/InProjectionType.kt +++ b/src/org/jetbrains/jet/j2k/ast/types/InProjectionType.kt @@ -1,5 +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() -} +package org.jetbrains.jet.j2k.ast.types + +public open class InProjectionType(val bound : Type) : Type(false) { + public override fun toKotlin() : String = "in " + bound.toKotlin() +} diff --git a/src/org/jetbrains/jet/j2k/ast/types/OutProjectionType.kt b/src/org/jetbrains/jet/j2k/ast/types/OutProjectionType.kt index 5fd08dbf1f7..12a72fdfd55 100644 --- a/src/org/jetbrains/jet/j2k/ast/types/OutProjectionType.kt +++ b/src/org/jetbrains/jet/j2k/ast/types/OutProjectionType.kt @@ -1,5 +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() -} +package org.jetbrains.jet.j2k.ast.types + +public open class OutProjectionType(val bound : Type) : Type(false) { + public override fun toKotlin() : String = "out " + bound.toKotlin() +} diff --git a/src/org/jetbrains/jet/j2k/ast/types/PrimitiveType.kt b/src/org/jetbrains/jet/j2k/ast/types/PrimitiveType.kt index 9e3c1967aa8..afb5bc2288e 100644 --- a/src/org/jetbrains/jet/j2k/ast/types/PrimitiveType.kt +++ b/src/org/jetbrains/jet/j2k/ast/types/PrimitiveType.kt @@ -1,7 +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() -} +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() +} diff --git a/src/org/jetbrains/jet/j2k/ast/types/StarProjectionType.kt b/src/org/jetbrains/jet/j2k/ast/types/StarProjectionType.kt index 093a0840ab9..38358964bc2 100644 --- a/src/org/jetbrains/jet/j2k/ast/types/StarProjectionType.kt +++ b/src/org/jetbrains/jet/j2k/ast/types/StarProjectionType.kt @@ -1,5 +1,5 @@ -package org.jetbrains.jet.j2k.ast.types - -public open class StarProjectionType() : Type(false) { - public override fun toKotlin() : String = "*" -} +package org.jetbrains.jet.j2k.ast.types + +public open class StarProjectionType() : Type(false) { + public override fun toKotlin() : String = "*" +} diff --git a/src/org/jetbrains/jet/j2k/ast/types/Type.kt b/src/org/jetbrains/jet/j2k/ast/types/Type.kt index 3e5332da4ed..99ac8b91fe9 100644 --- a/src/org/jetbrains/jet/j2k/ast/types/Type.kt +++ b/src/org/jetbrains/jet/j2k/ast/types/Type.kt @@ -1,17 +1,17 @@ -package org.jetbrains.jet.j2k.ast.types - -import org.jetbrains.jet.j2k.ast.Element - -public abstract class Type(val nullable: Boolean) : Element() { - public open fun convertedToNotNull() : Type { - if (nullable) throw UnsupportedOperationException("convertedToNotNull must be defined") - return this - } - - public open fun isNullableStr() : String? { - return (if (nullable) - "?" - else - "") - } -} +package org.jetbrains.jet.j2k.ast.types + +import org.jetbrains.jet.j2k.ast.Element + +public abstract class Type(val nullable: Boolean) : Element() { + public open fun convertedToNotNull() : Type { + if (nullable) throw UnsupportedOperationException("convertedToNotNull must be defined") + return this + } + + public open fun isNullableStr() : String? { + return (if (nullable) + "?" + else + "") + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/types/VarArg.kt b/src/org/jetbrains/jet/j2k/ast/types/VarArg.kt index 919b93e3f4f..70a2ebc0455 100644 --- a/src/org/jetbrains/jet/j2k/ast/types/VarArg.kt +++ b/src/org/jetbrains/jet/j2k/ast/types/VarArg.kt @@ -1,7 +1,7 @@ -package org.jetbrains.jet.j2k.ast.types - -import org.jetbrains.jet.j2k.ast.types.Type - -public open class VarArg(val `type` : Type) : Type(false) { - public override fun toKotlin() : String = `type`.toKotlin() -} +package org.jetbrains.jet.j2k.ast.types + +import org.jetbrains.jet.j2k.ast.types.Type + +public open class VarArg(val `type` : Type) : Type(false) { + public override fun toKotlin() : String = `type`.toKotlin() +} diff --git a/src/org/jetbrains/jet/j2k/visitors/ClassVisitor.kt b/src/org/jetbrains/jet/j2k/visitors/ClassVisitor.kt index f782fb7022a..367415974d4 100644 --- a/src/org/jetbrains/jet/j2k/visitors/ClassVisitor.kt +++ b/src/org/jetbrains/jet/j2k/visitors/ClassVisitor.kt @@ -1,21 +1,21 @@ -package org.jetbrains.jet.j2k.visitors - -import com.intellij.psi.JavaRecursiveElementVisitor -import com.intellij.psi.PsiClass -import java.util.HashSet - -public open class ClassVisitor(): JavaRecursiveElementVisitor() { - private val myClassIdentifiers = HashSet() - - public open fun getClassIdentifiers(): Set { - return HashSet(myClassIdentifiers) - } - - public override fun visitClass(aClass: PsiClass?): Unit { - val qName = aClass?.getQualifiedName() - if (qName != null) { - myClassIdentifiers.add(qName) - } - super.visitClass(aClass) - } -} +package org.jetbrains.jet.j2k.visitors + +import com.intellij.psi.JavaRecursiveElementVisitor +import com.intellij.psi.PsiClass +import java.util.HashSet + +public open class ClassVisitor(): JavaRecursiveElementVisitor() { + private val myClassIdentifiers = HashSet() + + public open fun getClassIdentifiers(): Set { + return HashSet(myClassIdentifiers) + } + + public override fun visitClass(aClass: PsiClass?): Unit { + val qName = aClass?.getQualifiedName() + if (qName != null) { + myClassIdentifiers.add(qName) + } + super.visitClass(aClass) + } +} diff --git a/src/org/jetbrains/jet/j2k/visitors/Dispatcher.kt b/src/org/jetbrains/jet/j2k/visitors/Dispatcher.kt index 709baecb077..56fdba04450 100644 --- a/src/org/jetbrains/jet/j2k/visitors/Dispatcher.kt +++ b/src/org/jetbrains/jet/j2k/visitors/Dispatcher.kt @@ -1,7 +1,7 @@ -package org.jetbrains.jet.j2k.visitors - -import org.jetbrains.jet.j2k.Converter - -public open class Dispatcher(converter: Converter) { - public var expressionVisitor: ExpressionVisitor = ExpressionVisitor(converter) -} +package org.jetbrains.jet.j2k.visitors + +import org.jetbrains.jet.j2k.Converter + +public open class Dispatcher(converter: Converter) { + public var expressionVisitor: ExpressionVisitor = ExpressionVisitor(converter) +} diff --git a/src/org/jetbrains/jet/j2k/visitors/ElementVisitor.kt b/src/org/jetbrains/jet/j2k/visitors/ElementVisitor.kt index 92b0ce746e3..fa102009ec7 100644 --- a/src/org/jetbrains/jet/j2k/visitors/ElementVisitor.kt +++ b/src/org/jetbrains/jet/j2k/visitors/ElementVisitor.kt @@ -1,72 +1,72 @@ -package org.jetbrains.jet.j2k.visitors - -import com.intellij.psi.* -import org.jetbrains.jet.j2k.Converter -import org.jetbrains.jet.j2k.ast.* -import org.jetbrains.jet.j2k.ast.types.Type -import org.jetbrains.jet.j2k.isAnnotatedAsNotNull -import org.jetbrains.jet.j2k.isDefinitelyNotNull - -public open class ElementVisitor(val myConverter : Converter) : JavaElementVisitor() { - protected var myResult : Element = Element.EMPTY_ELEMENT - - public fun getConverter() : Converter { - return myConverter - } - - public open fun getResult() : Element { - return myResult - } - - public override fun visitLocalVariable(variable : PsiLocalVariable?) : Unit { - val theVariable = variable!! - var kType = myConverter.typeToType(theVariable.getType(), isAnnotatedAsNotNull(theVariable.getModifierList())) - if (theVariable.hasModifierProperty(PsiModifier.FINAL) && isDefinitelyNotNull(theVariable.getInitializer())) { - kType = kType.convertedToNotNull(); - } - myResult = LocalVariable(Identifier(theVariable.getName()!!), - Converter.modifiersListToModifiersSet(theVariable.getModifierList()), - kType, - myConverter.expressionToExpression(theVariable.getInitializer(), theVariable.getType())) - } - - public override fun visitExpressionList(list : PsiExpressionList?) : Unit { - myResult = ExpressionList(myConverter.expressionsToExpressionList(list!!.getExpressions())) - } - - public override fun visitReferenceElement(reference : PsiJavaCodeReferenceElement?) : Unit { - val theReference = reference!! - val types : List = myConverter.typesToTypeList(theReference.getTypeParameters()) - if (!theReference.isQualified()) { - myResult = ReferenceElement(Identifier(theReference.getReferenceName()!!), types) - } - else { - var result : String = Identifier(reference?.getReferenceName()!!).toKotlin() - var qualifier : PsiElement? = theReference.getQualifier() - while (qualifier != null) - { - val p : PsiJavaCodeReferenceElement = (qualifier as PsiJavaCodeReferenceElement) - result = Identifier(p.getReferenceName()!!).toKotlin() + "." + result - qualifier = p.getQualifier() - } - myResult = ReferenceElement(Identifier(result), types) - } - } - - public override fun visitTypeElement(`type` : PsiTypeElement?) : Unit { - myResult = TypeElement(myConverter.typeToType(`type`!!.getType())) - } - - public override fun visitTypeParameter(classParameter : PsiTypeParameter?) : Unit { - myResult = TypeParameter(Identifier(classParameter!!.getName()!!), - classParameter!!.getExtendsListTypes().map { myConverter.typeToType(it) } ) - } - - public override fun visitParameterList(list : PsiParameterList?) : Unit { - myResult = ParameterList(myConverter.parametersToParameterList(list!!.getParameters()).requireNoNulls()) - } - - public override fun visitComment(comment: PsiComment?) { - myResult = Comment(comment?.getText()!!) - } -} +package org.jetbrains.jet.j2k.visitors + +import com.intellij.psi.* +import org.jetbrains.jet.j2k.Converter +import org.jetbrains.jet.j2k.ast.* +import org.jetbrains.jet.j2k.ast.types.Type +import org.jetbrains.jet.j2k.isAnnotatedAsNotNull +import org.jetbrains.jet.j2k.isDefinitelyNotNull + +public open class ElementVisitor(val myConverter : Converter) : JavaElementVisitor() { + protected var myResult : Element = Element.EMPTY_ELEMENT + + public fun getConverter() : Converter { + return myConverter + } + + public open fun getResult() : Element { + return myResult + } + + public override fun visitLocalVariable(variable : PsiLocalVariable?) : Unit { + val theVariable = variable!! + var kType = myConverter.typeToType(theVariable.getType(), isAnnotatedAsNotNull(theVariable.getModifierList())) + if (theVariable.hasModifierProperty(PsiModifier.FINAL) && isDefinitelyNotNull(theVariable.getInitializer())) { + kType = kType.convertedToNotNull(); + } + myResult = LocalVariable(Identifier(theVariable.getName()!!), + Converter.modifiersListToModifiersSet(theVariable.getModifierList()), + kType, + myConverter.expressionToExpression(theVariable.getInitializer(), theVariable.getType())) + } + + public override fun visitExpressionList(list : PsiExpressionList?) : Unit { + myResult = ExpressionList(myConverter.expressionsToExpressionList(list!!.getExpressions())) + } + + public override fun visitReferenceElement(reference : PsiJavaCodeReferenceElement?) : Unit { + val theReference = reference!! + val types : List = myConverter.typesToTypeList(theReference.getTypeParameters()) + if (!theReference.isQualified()) { + myResult = ReferenceElement(Identifier(theReference.getReferenceName()!!), types) + } + else { + var result : String = Identifier(reference?.getReferenceName()!!).toKotlin() + var qualifier : PsiElement? = theReference.getQualifier() + while (qualifier != null) + { + val p : PsiJavaCodeReferenceElement = (qualifier as PsiJavaCodeReferenceElement) + result = Identifier(p.getReferenceName()!!).toKotlin() + "." + result + qualifier = p.getQualifier() + } + myResult = ReferenceElement(Identifier(result), types) + } + } + + public override fun visitTypeElement(`type` : PsiTypeElement?) : Unit { + myResult = TypeElement(myConverter.typeToType(`type`!!.getType())) + } + + public override fun visitTypeParameter(classParameter : PsiTypeParameter?) : Unit { + myResult = TypeParameter(Identifier(classParameter!!.getName()!!), + classParameter!!.getExtendsListTypes().map { myConverter.typeToType(it) } ) + } + + public override fun visitParameterList(list : PsiParameterList?) : Unit { + myResult = ParameterList(myConverter.parametersToParameterList(list!!.getParameters()).requireNoNulls()) + } + + public override fun visitComment(comment: PsiComment?) { + myResult = Comment(comment?.getText()!!) + } +} diff --git a/src/org/jetbrains/jet/j2k/visitors/ExpressionVisitor.kt b/src/org/jetbrains/jet/j2k/visitors/ExpressionVisitor.kt index d33b953278f..bc4f545b1f1 100644 --- a/src/org/jetbrains/jet/j2k/visitors/ExpressionVisitor.kt +++ b/src/org/jetbrains/jet/j2k/visitors/ExpressionVisitor.kt @@ -1,490 +1,490 @@ -package org.jetbrains.jet.j2k.visitors - -import com.intellij.psi.* -import com.intellij.psi.tree.IElementType -import org.jetbrains.annotations.Nullable -import org.jetbrains.jet.j2k.Converter -import org.jetbrains.jet.j2k.ast.* -import org.jetbrains.jet.j2k.ast.types.EmptyType -import org.jetbrains.jet.j2k.ast.types.Type -import org.jetbrains.jet.lang.types.expressions.OperatorConventions -import java.util.ArrayList -import java.util.Collections -import com.intellij.psi.CommonClassNames.* -import com.intellij.psi.util.PsiTreeUtil - -public open class ExpressionVisitor(converter: Converter): StatementVisitor(converter) { - { - myResult = Expression.EMPTY_EXPRESSION - } - - public override fun getResult(): Expression { - return myResult as Expression - } - - public override fun visitArrayAccessExpression(expression: PsiArrayAccessExpression?): Unit { - val assignment = PsiTreeUtil.getParentOfType(expression, javaClass()) - val lvalue = assignment != null && expression == assignment.getLExpression(); - myResult = ArrayAccessExpression(getConverter().expressionToExpression(expression?.getArrayExpression()), - getConverter().expressionToExpression(expression?.getIndexExpression()), - lvalue) - } - - public override fun visitArrayInitializerExpression(expression: PsiArrayInitializerExpression?): Unit { - myResult = ArrayInitializerExpression(getConverter().typeToType(expression?.getType()), - getConverter().expressionsToExpressionList(expression?.getInitializers()!!)) - } - - public override fun visitAssignmentExpression(expression: PsiAssignmentExpression?): Unit { - val tokenType: IElementType = expression?.getOperationSign()?.getTokenType()!! - val secondOp: String = when(tokenType) { - JavaTokenType.GTGTEQ -> "shr" - JavaTokenType.LTLTEQ -> "shl" - JavaTokenType.XOREQ -> "xor" - JavaTokenType.ANDEQ -> "and" - JavaTokenType.OREQ -> "or" - JavaTokenType.GTGTGTEQ -> "ushr" - else -> "" - } - - val lhs = getConverter().expressionToExpression(expression?.getLExpression()!!) - val rhs = getConverter().expressionToExpression(expression?.getRExpression()!!, expression?.getRExpression()?.getType()) - if (!secondOp.isEmpty()) { - myResult = AssignmentExpression(lhs, BinaryExpression(lhs, rhs, secondOp), "=") - } - else { - myResult = AssignmentExpression(lhs, rhs, expression?.getOperationSign()?.getText()!!) - } - } - - public override fun visitBinaryExpression(expression: PsiBinaryExpression?): Unit { - val lhs = getConverter().expressionToExpression(expression?.getLOperand()!!, expression?.getType()) - val rhs = getConverter().expressionToExpression(expression?.getROperand(), expression?.getType()) - if (expression?.getOperationSign()?.getTokenType() == JavaTokenType.GTGTGT) { - myResult = MethodCallExpression.build(lhs, "ushr", arrayList(rhs)) - } - else { - myResult = BinaryExpression(lhs, rhs, - getOperatorString(expression?.getOperationSign()?.getTokenType()!!)) - } - } - - public override fun visitClassObjectAccessExpression(expression: PsiClassObjectAccessExpression?): Unit { - myResult = ClassObjectAccessExpression(getConverter().typeElementToTypeElement(expression?.getOperand())) - } - - public override fun visitConditionalExpression(expression: PsiConditionalExpression?): Unit { - val condition: PsiExpression? = expression?.getCondition() - val `type`: PsiType? = condition?.getType() - val e: Expression = (if (`type` != null) - getConverter().expressionToExpression(condition, `type`) - else - getConverter().expressionToExpression(condition)) - myResult = ParenthesizedExpression(IfStatement(e, - getConverter().expressionToExpression(expression?.getThenExpression()), - getConverter().expressionToExpression(expression?.getElseExpression()))) - } - - public override fun visitExpressionList(list: PsiExpressionList?): Unit { - myResult = ExpressionList(getConverter().expressionsToExpressionList(list!!.getExpressions())) - } - - public override fun visitInstanceOfExpression(expression: PsiInstanceOfExpression?): Unit { - val checkType: PsiTypeElement? = expression?.getCheckType() - myResult = IsOperator(getConverter().expressionToExpression(expression?.getOperand()), - myConverter.typeElementToTypeElement(checkType)) - } - - public override fun visitLiteralExpression(expression: PsiLiteralExpression?): Unit { - val value: Any? = expression?.getValue() - var text: String = expression?.getText()!! - val `type`: PsiType? = expression?.getType() - if (`type` != null) { - val canonicalTypeStr: String? = `type`.getCanonicalText() - if (canonicalTypeStr?.equals("double")!! || canonicalTypeStr?.equals(JAVA_LANG_DOUBLE)!!) { - text = text.replace("D", "").replace("d", "") - if (!text.contains(".")) { - text += ".0" - } - - } - - if (canonicalTypeStr?.equals("float")!! || canonicalTypeStr?.equals(JAVA_LANG_FLOAT)!!) { - text = text.replace("F", "").replace("f", "") + "." + OperatorConventions.FLOAT + "()" - } - - if (canonicalTypeStr?.equals("long")!! || canonicalTypeStr?.equals(JAVA_LANG_LONG)!!) { - text = text.replace("L", "").replace("l", "") - } - - if (canonicalTypeStr?.equals("int")!! || canonicalTypeStr?.equals(JAVA_LANG_INTEGER)!!) { - text = (if (value != null) value.toString() else text) - } - } - - myResult = LiteralExpression(text) - } - - public override fun visitMethodCallExpression(expression: PsiMethodCallExpression?): Unit { - convertMethodCallExpression(expression!!) - } - - protected fun convertMethodCallExpression(expression: PsiMethodCallExpression) { - if (!SuperVisitor.isSuper(expression.getMethodExpression()) || !isInsidePrimaryConstructor(expression)) { - myResult = MethodCallExpression(getConverter().expressionToExpression(expression.getMethodExpression()), - getConverter().argumentsToExpressionList(expression), - getConverter().typesToTypeList(expression.getTypeArguments()), - getConverter().typeToType(expression.getType()).nullable) - } - } - - public override fun visitNewExpression(expression: PsiNewExpression?): Unit { - if (expression?.getArrayInitializer() != null) - { - myResult = createNewEmptyArray(expression) - } - else - if (expression?.getArrayDimensions()?.size!! > 0) { - myResult = createNewEmptyArrayWithoutInitialization(expression!!) - } - else - { - myResult = createNewClassExpression(expression) - } - } - - private fun createNewClassExpression(expression: PsiNewExpression?): Expression { - val anonymousClass: PsiAnonymousClass? = expression?.getAnonymousClass() - val constructor: PsiMethod? = expression?.resolveMethod() - var classReference: PsiJavaCodeReferenceElement? = expression?.getClassOrAnonymousClassReference() - val isNotConvertedClass: Boolean = classReference != null && !getConverter().getClassIdentifiers().contains(classReference?.getQualifiedName()) - var argumentList: PsiExpressionList? = expression?.getArgumentList() - var arguments: Array = (if (argumentList != null) - argumentList?.getExpressions()!! - else - array()) - if (constructor == null || Converter.isConstructorPrimary(constructor) || isNotConvertedClass) - { - return NewClassExpression(getConverter().elementToElement(classReference), - getConverter().argumentsToExpressionList(expression!!), - getConverter().expressionToExpression(expression?.getQualifier()), - (if (anonymousClass != null) - getConverter().anonymousClassToAnonymousClass(anonymousClass) - else - null)) - } - - val reference: PsiJavaCodeReferenceElement? = expression?.getClassReference() - val typeParameters: List = (if (reference != null) - getConverter().typesToTypeList(reference.getTypeParameters()) - else - Collections.emptyList()!!) - return CallChainExpression(Identifier(constructor.getName(), false), - MethodCallExpression(Identifier("init"), getConverter().expressionsToExpressionList(arguments), typeParameters, false)) - } - - private fun createNewEmptyArrayWithoutInitialization(expression: PsiNewExpression): Expression { - return ArrayWithoutInitializationExpression( - getConverter().typeToType(expression.getType(), true), - getConverter().expressionsToExpressionList(expression.getArrayDimensions())) - } - - private fun createNewEmptyArray(expression: PsiNewExpression?): Expression { - return getConverter().expressionToExpression(expression?.getArrayInitializer()) - } - - public override fun visitParenthesizedExpression(expression: PsiParenthesizedExpression?): Unit { - myResult = ParenthesizedExpression(getConverter().expressionToExpression(expression?.getExpression())) - } - - public override fun visitPostfixExpression(expression: PsiPostfixExpression?): Unit { - myResult = PostfixOperator(getOperatorString(expression!!.getOperationSign().getTokenType()!!), - getConverter().expressionToExpression(expression?.getOperand())) - } - - public override fun visitPrefixExpression(expression: PsiPrefixExpression?): Unit { - val operand = getConverter().expressionToExpression(expression?.getOperand(), expression?.getOperand()!!.getType()) - val token = expression?.getOperationTokenType()!! - if (token == JavaTokenType.TILDE) { - myResult = MethodCallExpression.build(ParenthesizedExpression(operand), "inv", arrayList()) - } - else { - myResult = PrefixOperator(getOperatorString(token), operand) - } - } - - public override fun visitReferenceExpression(expression: PsiReferenceExpression?): Unit { - val isFieldReference: Boolean = isFieldReference(expression!!, getContainingClass(expression!!)) - val insideSecondaryConstructor: Boolean = isInsideSecondaryConstructor(expression!!) - val hasReceiver: Boolean = isFieldReference && insideSecondaryConstructor - val isThis: Boolean = isThisExpression(expression!!) - val isNullable: Boolean = getConverter().typeToType(expression?.getType()).nullable - val className: String = getClassNameWithConstructor(expression!!) - val referencedName = expression?.getReferenceName()!! - var identifier: Expression = Identifier(referencedName, isNullable) - val __: String = "__" - val qualifier = expression?.getQualifierExpression() - if (hasReceiver){ - identifier = CallChainExpression(Identifier(__, false), Identifier(referencedName, isNullable)) - } - else if (insideSecondaryConstructor && isThis) { - identifier = Identifier("val __ = " + className) - } - else if (qualifier != null && qualifier.getType() is PsiArrayType && referencedName == "length") { - identifier = Identifier("size", isNullable) - } - else if (qualifier == null) { - val resolved = expression?.getReference()?.resolve() - if (resolved is PsiMember && resolved.hasModifierProperty(PsiModifier.STATIC) && - resolved.getContainingClass() != null && - PsiTreeUtil.getParentOfType(expression, javaClass()) != resolved.getContainingClass() && - !isStaticallyImported(resolved, expression!!)) { - var member = resolved as PsiMember - var result = Identifier(referencedName).toKotlin() - while(member.getContainingClass() != null) { - result = Identifier(member.getContainingClass()!!.getName()!!).toKotlin() + "." + result - member = member.getContainingClass()!! - } - myResult = Identifier(result, false, false) - return - } - } - - myResult = CallChainExpression(getConverter().expressionToExpression(qualifier), identifier) - } - - public override fun visitSuperExpression(expression: PsiSuperExpression?): Unit { - val qualifier: PsiJavaCodeReferenceElement? = expression?.getQualifier() - myResult = SuperExpression((if (qualifier != null) - Identifier(qualifier.getQualifiedName()!!) - else - Identifier.EMPTY_IDENTIFIER)) - } - - public override fun visitThisExpression(expression: PsiThisExpression?): Unit { - val qualifier: PsiJavaCodeReferenceElement? = expression?.getQualifier() - myResult = ThisExpression((if (qualifier != null) - Identifier(qualifier.getQualifiedName()!!) - else - Identifier.EMPTY_IDENTIFIER)) - } - - public override fun visitTypeCastExpression(expression: PsiTypeCastExpression?): Unit { - val castType: PsiTypeElement? = expression?.getCastType() - if (castType != null) { - val operand = expression?.getOperand() - val operandType = operand?.getType() - val typeText = castType.getType().getCanonicalText() - val typeConversion = Converter.PRIMITIVE_TYPE_CONVERSIONS[typeText] - if (operandType is PsiPrimitiveType && typeConversion != null) { - myResult = MethodCallExpression.build(getConverter().expressionToExpression(operand), typeConversion) - } - else { - myResult = TypeCastExpression(getConverter().typeToType(castType.getType()), - getConverter().expressionToExpression(operand)) - } - } - } - - public override fun visitPolyadicExpression(expression: PsiPolyadicExpression?): Unit { - var parameters = ArrayList() - for (operand : PsiExpression in expression?.getOperands()!!) { - parameters.add(getConverter().expressionToExpression(operand, expression?.getType())) - } - myResult = PolyadicExpression(parameters, getOperatorString(expression?.getOperationTokenType()!!)) - } - - class object { - private fun getOperatorString(tokenType: IElementType): String { - if (tokenType == JavaTokenType.PLUS) - return "+" - - if (tokenType == JavaTokenType.MINUS) - return "-" - - if (tokenType == JavaTokenType.ASTERISK) - return "*" - - if (tokenType == JavaTokenType.DIV) - return "/" - - if (tokenType == JavaTokenType.PERC) - return "%" - - if (tokenType == JavaTokenType.GTGT) - return "shr" - - if (tokenType == JavaTokenType.LTLT) - return "shl" - - if (tokenType == JavaTokenType.XOR) - return "xor" - - if (tokenType == JavaTokenType.AND) - return "and" - - if (tokenType == JavaTokenType.OR) - return "or" - - if (tokenType == JavaTokenType.GTGTGT) - return "ushr" - - if (tokenType == JavaTokenType.GT) - return ">" - - if (tokenType == JavaTokenType.LT) - return "<" - - if (tokenType == JavaTokenType.GE) - return ">=" - - if (tokenType == JavaTokenType.LE) - return "<=" - - if (tokenType == JavaTokenType.EQEQ) - return "==" - - if (tokenType == JavaTokenType.NE) - return "!=" - - if (tokenType == JavaTokenType.ANDAND) - return "&&" - - if (tokenType == JavaTokenType.OROR) - return "||" - - if (tokenType == JavaTokenType.PLUSPLUS) - return "++" - - if (tokenType == JavaTokenType.MINUSMINUS) - return "--" - - if (tokenType == JavaTokenType.EXCL) - return "!" - -// System.out.println("UNSUPPORTED TOKEN TYPE: " + tokenType?.toString()) - return "" - } - - private fun getClassNameWithConstructor(expression: PsiReferenceExpression): String { - var context: PsiElement? = expression.getContext() - while (context != null) { - if (context is PsiMethod && ((context as PsiMethod)).isConstructor()) { - val containingClass: PsiClass? = ((context as PsiMethod)).getContainingClass() - if (containingClass != null) { - val identifier: PsiIdentifier? = containingClass.getNameIdentifier() - if (identifier != null) { - return identifier.getText()!! - } - - } - - } - - context = context?.getContext() - } - return "" - } - - open fun getClassName(expression: PsiExpression): String { - var context: PsiElement? = expression.getContext() - while (context != null) - { - if ((context is PsiClass?)) { - val containingClass: PsiClass? = (context as PsiClass?) - val identifier: PsiIdentifier? = containingClass?.getNameIdentifier() - if (identifier != null) { - return identifier.getText()!! - } - - } - - context = context?.getContext() - } - return "" - } - - private fun isFieldReference(expression: PsiReferenceExpression, currentClass: PsiClass?): Boolean { - val reference: PsiReference? = expression.getReference() - if (reference != null) { - val resolvedReference: PsiElement? = reference.resolve() - if (resolvedReference is PsiField) { - return (resolvedReference as PsiField).getContainingClass() == currentClass - } - } - - return false - } - - private fun isInsideSecondaryConstructor(expression: PsiReferenceExpression): Boolean { - var context: PsiElement? = expression.getContext() - while (context != null) { - if (context is PsiMethod && (context as PsiMethod).isConstructor()) { - return !Converter.isConstructorPrimary((context as PsiMethod)) - } - - context = context?.getContext() - } - return false - } - - private fun isInsidePrimaryConstructor(expression: PsiExpression): Boolean { - var context: PsiElement? = expression.getContext() - while (context != null) { - if (context is PsiMethod && (context as PsiMethod).isConstructor()) { - return Converter.isConstructorPrimary(context as PsiMethod) - } - - context = context?.getContext() - } - return false - } - - private fun getContainingClass(expression: PsiExpression): PsiClass? { - var context: PsiElement? = expression.getContext() - while (context != null) - { - if (context is PsiMethod && (context as PsiMethod).isConstructor()) - { - return (context as PsiMethod).getContainingClass() - } - - context = context?.getContext() - } - return null - } - private fun isThisExpression(expression: PsiReferenceExpression): Boolean { - for (r : PsiReference? in expression.getReferences()) - if (r?.getCanonicalText()?.equals("this")!!) - { - val res: PsiElement? = r?.resolve() - if (res is PsiMethod && res.isConstructor()) { - return true - } - - } - - return false - } - } -} - -private fun isStaticallyImported(member: PsiMember, context: PsiElement): Boolean { - val containingFile = context.getContainingFile() - val targetContainingClass = member.getContainingClass() - if (containingFile is PsiJavaFile && targetContainingClass != null) { - val importList = containingFile.getImportList(); - if (importList != null) { - val importStatics = importList.getImportStaticStatements(); - return importStatics.any { importResolvesTo(it, member) } - } - } - return false -} - -private fun importResolvesTo(stmt: PsiImportStaticStatement?, member: PsiMember): Boolean { - val targetContainingClass = member.getContainingClass() - var importedClass = stmt?.resolveTargetClass() - return importedClass == targetContainingClass && (stmt?.isOnDemand() ?: false || - stmt?.getReferenceName() == member.getName()) -} +package org.jetbrains.jet.j2k.visitors + +import com.intellij.psi.* +import com.intellij.psi.tree.IElementType +import org.jetbrains.annotations.Nullable +import org.jetbrains.jet.j2k.Converter +import org.jetbrains.jet.j2k.ast.* +import org.jetbrains.jet.j2k.ast.types.EmptyType +import org.jetbrains.jet.j2k.ast.types.Type +import org.jetbrains.jet.lang.types.expressions.OperatorConventions +import java.util.ArrayList +import java.util.Collections +import com.intellij.psi.CommonClassNames.* +import com.intellij.psi.util.PsiTreeUtil + +public open class ExpressionVisitor(converter: Converter): StatementVisitor(converter) { + { + myResult = Expression.EMPTY_EXPRESSION + } + + public override fun getResult(): Expression { + return myResult as Expression + } + + public override fun visitArrayAccessExpression(expression: PsiArrayAccessExpression?): Unit { + val assignment = PsiTreeUtil.getParentOfType(expression, javaClass()) + val lvalue = assignment != null && expression == assignment.getLExpression(); + myResult = ArrayAccessExpression(getConverter().expressionToExpression(expression?.getArrayExpression()), + getConverter().expressionToExpression(expression?.getIndexExpression()), + lvalue) + } + + public override fun visitArrayInitializerExpression(expression: PsiArrayInitializerExpression?): Unit { + myResult = ArrayInitializerExpression(getConverter().typeToType(expression?.getType()), + getConverter().expressionsToExpressionList(expression?.getInitializers()!!)) + } + + public override fun visitAssignmentExpression(expression: PsiAssignmentExpression?): Unit { + val tokenType: IElementType = expression?.getOperationSign()?.getTokenType()!! + val secondOp: String = when(tokenType) { + JavaTokenType.GTGTEQ -> "shr" + JavaTokenType.LTLTEQ -> "shl" + JavaTokenType.XOREQ -> "xor" + JavaTokenType.ANDEQ -> "and" + JavaTokenType.OREQ -> "or" + JavaTokenType.GTGTGTEQ -> "ushr" + else -> "" + } + + val lhs = getConverter().expressionToExpression(expression?.getLExpression()!!) + val rhs = getConverter().expressionToExpression(expression?.getRExpression()!!, expression?.getRExpression()?.getType()) + if (!secondOp.isEmpty()) { + myResult = AssignmentExpression(lhs, BinaryExpression(lhs, rhs, secondOp), "=") + } + else { + myResult = AssignmentExpression(lhs, rhs, expression?.getOperationSign()?.getText()!!) + } + } + + public override fun visitBinaryExpression(expression: PsiBinaryExpression?): Unit { + val lhs = getConverter().expressionToExpression(expression?.getLOperand()!!, expression?.getType()) + val rhs = getConverter().expressionToExpression(expression?.getROperand(), expression?.getType()) + if (expression?.getOperationSign()?.getTokenType() == JavaTokenType.GTGTGT) { + myResult = MethodCallExpression.build(lhs, "ushr", arrayList(rhs)) + } + else { + myResult = BinaryExpression(lhs, rhs, + getOperatorString(expression?.getOperationSign()?.getTokenType()!!)) + } + } + + public override fun visitClassObjectAccessExpression(expression: PsiClassObjectAccessExpression?): Unit { + myResult = ClassObjectAccessExpression(getConverter().typeElementToTypeElement(expression?.getOperand())) + } + + public override fun visitConditionalExpression(expression: PsiConditionalExpression?): Unit { + val condition: PsiExpression? = expression?.getCondition() + val `type`: PsiType? = condition?.getType() + val e: Expression = (if (`type` != null) + getConverter().expressionToExpression(condition, `type`) + else + getConverter().expressionToExpression(condition)) + myResult = ParenthesizedExpression(IfStatement(e, + getConverter().expressionToExpression(expression?.getThenExpression()), + getConverter().expressionToExpression(expression?.getElseExpression()))) + } + + public override fun visitExpressionList(list: PsiExpressionList?): Unit { + myResult = ExpressionList(getConverter().expressionsToExpressionList(list!!.getExpressions())) + } + + public override fun visitInstanceOfExpression(expression: PsiInstanceOfExpression?): Unit { + val checkType: PsiTypeElement? = expression?.getCheckType() + myResult = IsOperator(getConverter().expressionToExpression(expression?.getOperand()), + myConverter.typeElementToTypeElement(checkType)) + } + + public override fun visitLiteralExpression(expression: PsiLiteralExpression?): Unit { + val value: Any? = expression?.getValue() + var text: String = expression?.getText()!! + val `type`: PsiType? = expression?.getType() + if (`type` != null) { + val canonicalTypeStr: String? = `type`.getCanonicalText() + if (canonicalTypeStr?.equals("double")!! || canonicalTypeStr?.equals(JAVA_LANG_DOUBLE)!!) { + text = text.replace("D", "").replace("d", "") + if (!text.contains(".")) { + text += ".0" + } + + } + + if (canonicalTypeStr?.equals("float")!! || canonicalTypeStr?.equals(JAVA_LANG_FLOAT)!!) { + text = text.replace("F", "").replace("f", "") + "." + OperatorConventions.FLOAT + "()" + } + + if (canonicalTypeStr?.equals("long")!! || canonicalTypeStr?.equals(JAVA_LANG_LONG)!!) { + text = text.replace("L", "").replace("l", "") + } + + if (canonicalTypeStr?.equals("int")!! || canonicalTypeStr?.equals(JAVA_LANG_INTEGER)!!) { + text = (if (value != null) value.toString() else text) + } + } + + myResult = LiteralExpression(text) + } + + public override fun visitMethodCallExpression(expression: PsiMethodCallExpression?): Unit { + convertMethodCallExpression(expression!!) + } + + protected fun convertMethodCallExpression(expression: PsiMethodCallExpression) { + if (!SuperVisitor.isSuper(expression.getMethodExpression()) || !isInsidePrimaryConstructor(expression)) { + myResult = MethodCallExpression(getConverter().expressionToExpression(expression.getMethodExpression()), + getConverter().argumentsToExpressionList(expression), + getConverter().typesToTypeList(expression.getTypeArguments()), + getConverter().typeToType(expression.getType()).nullable) + } + } + + public override fun visitNewExpression(expression: PsiNewExpression?): Unit { + if (expression?.getArrayInitializer() != null) + { + myResult = createNewEmptyArray(expression) + } + else + if (expression?.getArrayDimensions()?.size!! > 0) { + myResult = createNewEmptyArrayWithoutInitialization(expression!!) + } + else + { + myResult = createNewClassExpression(expression) + } + } + + private fun createNewClassExpression(expression: PsiNewExpression?): Expression { + val anonymousClass: PsiAnonymousClass? = expression?.getAnonymousClass() + val constructor: PsiMethod? = expression?.resolveMethod() + var classReference: PsiJavaCodeReferenceElement? = expression?.getClassOrAnonymousClassReference() + val isNotConvertedClass: Boolean = classReference != null && !getConverter().getClassIdentifiers().contains(classReference?.getQualifiedName()) + var argumentList: PsiExpressionList? = expression?.getArgumentList() + var arguments: Array = (if (argumentList != null) + argumentList?.getExpressions()!! + else + array()) + if (constructor == null || Converter.isConstructorPrimary(constructor) || isNotConvertedClass) + { + return NewClassExpression(getConverter().elementToElement(classReference), + getConverter().argumentsToExpressionList(expression!!), + getConverter().expressionToExpression(expression?.getQualifier()), + (if (anonymousClass != null) + getConverter().anonymousClassToAnonymousClass(anonymousClass) + else + null)) + } + + val reference: PsiJavaCodeReferenceElement? = expression?.getClassReference() + val typeParameters: List = (if (reference != null) + getConverter().typesToTypeList(reference.getTypeParameters()) + else + Collections.emptyList()!!) + return CallChainExpression(Identifier(constructor.getName(), false), + MethodCallExpression(Identifier("init"), getConverter().expressionsToExpressionList(arguments), typeParameters, false)) + } + + private fun createNewEmptyArrayWithoutInitialization(expression: PsiNewExpression): Expression { + return ArrayWithoutInitializationExpression( + getConverter().typeToType(expression.getType(), true), + getConverter().expressionsToExpressionList(expression.getArrayDimensions())) + } + + private fun createNewEmptyArray(expression: PsiNewExpression?): Expression { + return getConverter().expressionToExpression(expression?.getArrayInitializer()) + } + + public override fun visitParenthesizedExpression(expression: PsiParenthesizedExpression?): Unit { + myResult = ParenthesizedExpression(getConverter().expressionToExpression(expression?.getExpression())) + } + + public override fun visitPostfixExpression(expression: PsiPostfixExpression?): Unit { + myResult = PostfixOperator(getOperatorString(expression!!.getOperationSign().getTokenType()!!), + getConverter().expressionToExpression(expression?.getOperand())) + } + + public override fun visitPrefixExpression(expression: PsiPrefixExpression?): Unit { + val operand = getConverter().expressionToExpression(expression?.getOperand(), expression?.getOperand()!!.getType()) + val token = expression?.getOperationTokenType()!! + if (token == JavaTokenType.TILDE) { + myResult = MethodCallExpression.build(ParenthesizedExpression(operand), "inv", arrayList()) + } + else { + myResult = PrefixOperator(getOperatorString(token), operand) + } + } + + public override fun visitReferenceExpression(expression: PsiReferenceExpression?): Unit { + val isFieldReference: Boolean = isFieldReference(expression!!, getContainingClass(expression!!)) + val insideSecondaryConstructor: Boolean = isInsideSecondaryConstructor(expression!!) + val hasReceiver: Boolean = isFieldReference && insideSecondaryConstructor + val isThis: Boolean = isThisExpression(expression!!) + val isNullable: Boolean = getConverter().typeToType(expression?.getType()).nullable + val className: String = getClassNameWithConstructor(expression!!) + val referencedName = expression?.getReferenceName()!! + var identifier: Expression = Identifier(referencedName, isNullable) + val __: String = "__" + val qualifier = expression?.getQualifierExpression() + if (hasReceiver){ + identifier = CallChainExpression(Identifier(__, false), Identifier(referencedName, isNullable)) + } + else if (insideSecondaryConstructor && isThis) { + identifier = Identifier("val __ = " + className) + } + else if (qualifier != null && qualifier.getType() is PsiArrayType && referencedName == "length") { + identifier = Identifier("size", isNullable) + } + else if (qualifier == null) { + val resolved = expression?.getReference()?.resolve() + if (resolved is PsiMember && resolved.hasModifierProperty(PsiModifier.STATIC) && + resolved.getContainingClass() != null && + PsiTreeUtil.getParentOfType(expression, javaClass()) != resolved.getContainingClass() && + !isStaticallyImported(resolved, expression!!)) { + var member = resolved as PsiMember + var result = Identifier(referencedName).toKotlin() + while(member.getContainingClass() != null) { + result = Identifier(member.getContainingClass()!!.getName()!!).toKotlin() + "." + result + member = member.getContainingClass()!! + } + myResult = Identifier(result, false, false) + return + } + } + + myResult = CallChainExpression(getConverter().expressionToExpression(qualifier), identifier) + } + + public override fun visitSuperExpression(expression: PsiSuperExpression?): Unit { + val qualifier: PsiJavaCodeReferenceElement? = expression?.getQualifier() + myResult = SuperExpression((if (qualifier != null) + Identifier(qualifier.getQualifiedName()!!) + else + Identifier.EMPTY_IDENTIFIER)) + } + + public override fun visitThisExpression(expression: PsiThisExpression?): Unit { + val qualifier: PsiJavaCodeReferenceElement? = expression?.getQualifier() + myResult = ThisExpression((if (qualifier != null) + Identifier(qualifier.getQualifiedName()!!) + else + Identifier.EMPTY_IDENTIFIER)) + } + + public override fun visitTypeCastExpression(expression: PsiTypeCastExpression?): Unit { + val castType: PsiTypeElement? = expression?.getCastType() + if (castType != null) { + val operand = expression?.getOperand() + val operandType = operand?.getType() + val typeText = castType.getType().getCanonicalText() + val typeConversion = Converter.PRIMITIVE_TYPE_CONVERSIONS[typeText] + if (operandType is PsiPrimitiveType && typeConversion != null) { + myResult = MethodCallExpression.build(getConverter().expressionToExpression(operand), typeConversion) + } + else { + myResult = TypeCastExpression(getConverter().typeToType(castType.getType()), + getConverter().expressionToExpression(operand)) + } + } + } + + public override fun visitPolyadicExpression(expression: PsiPolyadicExpression?): Unit { + var parameters = ArrayList() + for (operand : PsiExpression in expression?.getOperands()!!) { + parameters.add(getConverter().expressionToExpression(operand, expression?.getType())) + } + myResult = PolyadicExpression(parameters, getOperatorString(expression?.getOperationTokenType()!!)) + } + + class object { + private fun getOperatorString(tokenType: IElementType): String { + if (tokenType == JavaTokenType.PLUS) + return "+" + + if (tokenType == JavaTokenType.MINUS) + return "-" + + if (tokenType == JavaTokenType.ASTERISK) + return "*" + + if (tokenType == JavaTokenType.DIV) + return "/" + + if (tokenType == JavaTokenType.PERC) + return "%" + + if (tokenType == JavaTokenType.GTGT) + return "shr" + + if (tokenType == JavaTokenType.LTLT) + return "shl" + + if (tokenType == JavaTokenType.XOR) + return "xor" + + if (tokenType == JavaTokenType.AND) + return "and" + + if (tokenType == JavaTokenType.OR) + return "or" + + if (tokenType == JavaTokenType.GTGTGT) + return "ushr" + + if (tokenType == JavaTokenType.GT) + return ">" + + if (tokenType == JavaTokenType.LT) + return "<" + + if (tokenType == JavaTokenType.GE) + return ">=" + + if (tokenType == JavaTokenType.LE) + return "<=" + + if (tokenType == JavaTokenType.EQEQ) + return "==" + + if (tokenType == JavaTokenType.NE) + return "!=" + + if (tokenType == JavaTokenType.ANDAND) + return "&&" + + if (tokenType == JavaTokenType.OROR) + return "||" + + if (tokenType == JavaTokenType.PLUSPLUS) + return "++" + + if (tokenType == JavaTokenType.MINUSMINUS) + return "--" + + if (tokenType == JavaTokenType.EXCL) + return "!" + +// System.out.println("UNSUPPORTED TOKEN TYPE: " + tokenType?.toString()) + return "" + } + + private fun getClassNameWithConstructor(expression: PsiReferenceExpression): String { + var context: PsiElement? = expression.getContext() + while (context != null) { + if (context is PsiMethod && ((context as PsiMethod)).isConstructor()) { + val containingClass: PsiClass? = ((context as PsiMethod)).getContainingClass() + if (containingClass != null) { + val identifier: PsiIdentifier? = containingClass.getNameIdentifier() + if (identifier != null) { + return identifier.getText()!! + } + + } + + } + + context = context?.getContext() + } + return "" + } + + open fun getClassName(expression: PsiExpression): String { + var context: PsiElement? = expression.getContext() + while (context != null) + { + if ((context is PsiClass?)) { + val containingClass: PsiClass? = (context as PsiClass?) + val identifier: PsiIdentifier? = containingClass?.getNameIdentifier() + if (identifier != null) { + return identifier.getText()!! + } + + } + + context = context?.getContext() + } + return "" + } + + private fun isFieldReference(expression: PsiReferenceExpression, currentClass: PsiClass?): Boolean { + val reference: PsiReference? = expression.getReference() + if (reference != null) { + val resolvedReference: PsiElement? = reference.resolve() + if (resolvedReference is PsiField) { + return (resolvedReference as PsiField).getContainingClass() == currentClass + } + } + + return false + } + + private fun isInsideSecondaryConstructor(expression: PsiReferenceExpression): Boolean { + var context: PsiElement? = expression.getContext() + while (context != null) { + if (context is PsiMethod && (context as PsiMethod).isConstructor()) { + return !Converter.isConstructorPrimary((context as PsiMethod)) + } + + context = context?.getContext() + } + return false + } + + private fun isInsidePrimaryConstructor(expression: PsiExpression): Boolean { + var context: PsiElement? = expression.getContext() + while (context != null) { + if (context is PsiMethod && (context as PsiMethod).isConstructor()) { + return Converter.isConstructorPrimary(context as PsiMethod) + } + + context = context?.getContext() + } + return false + } + + private fun getContainingClass(expression: PsiExpression): PsiClass? { + var context: PsiElement? = expression.getContext() + while (context != null) + { + if (context is PsiMethod && (context as PsiMethod).isConstructor()) + { + return (context as PsiMethod).getContainingClass() + } + + context = context?.getContext() + } + return null + } + private fun isThisExpression(expression: PsiReferenceExpression): Boolean { + for (r : PsiReference? in expression.getReferences()) + if (r?.getCanonicalText()?.equals("this")!!) + { + val res: PsiElement? = r?.resolve() + if (res is PsiMethod && res.isConstructor()) { + return true + } + + } + + return false + } + } +} + +private fun isStaticallyImported(member: PsiMember, context: PsiElement): Boolean { + val containingFile = context.getContainingFile() + val targetContainingClass = member.getContainingClass() + if (containingFile is PsiJavaFile && targetContainingClass != null) { + val importList = containingFile.getImportList(); + if (importList != null) { + val importStatics = importList.getImportStaticStatements(); + return importStatics.any { importResolvesTo(it, member) } + } + } + return false +} + +private fun importResolvesTo(stmt: PsiImportStaticStatement?, member: PsiMember): Boolean { + val targetContainingClass = member.getContainingClass() + var importedClass = stmt?.resolveTargetClass() + return importedClass == targetContainingClass && (stmt?.isOnDemand() ?: false || + stmt?.getReferenceName() == member.getName()) +} diff --git a/src/org/jetbrains/jet/j2k/visitors/ExpressionVisitorForDirectObjectInheritors.kt b/src/org/jetbrains/jet/j2k/visitors/ExpressionVisitorForDirectObjectInheritors.kt index c4bf7ab64ef..4632b09d29c 100644 --- a/src/org/jetbrains/jet/j2k/visitors/ExpressionVisitorForDirectObjectInheritors.kt +++ b/src/org/jetbrains/jet/j2k/visitors/ExpressionVisitorForDirectObjectInheritors.kt @@ -1,41 +1,41 @@ -package org.jetbrains.jet.j2k.visitors - -import com.intellij.psi.* -import org.jetbrains.jet.j2k.Converter -import org.jetbrains.jet.j2k.ast.DummyStringExpression -import org.jetbrains.jet.j2k.ast.Identifier -import com.intellij.psi.CommonClassNames.JAVA_LANG_OBJECT -import org.jetbrains.jet.j2k.ast.MethodCallExpression - -public open class ExpressionVisitorForDirectObjectInheritors(converter: Converter): ExpressionVisitor(converter) { - public override fun visitMethodCallExpression(expression: PsiMethodCallExpression?): Unit { - val methodExpression = expression?.getMethodExpression()!! - if (superMethodInvocation(methodExpression, "hashCode")) { - myResult = MethodCallExpression.build(Identifier("System", false), "identityHashCode", arrayList(Identifier("this"))) - } - else if (superMethodInvocation(methodExpression, "equals")) { - myResult = MethodCallExpression.build(Identifier("this", false), "identityEquals", getConverter().argumentsToExpressionList(expression!!)) - } - else if (superMethodInvocation(methodExpression, "toString")) { - myResult = DummyStringExpression(java.lang.String.format("getJavaClass<%s>.getName() + '@' + Integer.toHexString(hashCode())", - ExpressionVisitor.getClassName(methodExpression))!!) - } - else { - convertMethodCallExpression(expression!!) - } - } - - class object { - private fun superMethodInvocation(expression: PsiReferenceExpression, methodName: String?): Boolean { - val referenceName: String? = expression.getReferenceName() - val qualifierExpression: PsiExpression? = expression.getQualifierExpression() - if (referenceName == methodName && qualifierExpression is PsiSuperExpression) { - val `type`: PsiType? = qualifierExpression.getType() - if (`type` != null && `type`.getCanonicalText() == JAVA_LANG_OBJECT) { - return true - } - } - return false - } - } -} +package org.jetbrains.jet.j2k.visitors + +import com.intellij.psi.* +import org.jetbrains.jet.j2k.Converter +import org.jetbrains.jet.j2k.ast.DummyStringExpression +import org.jetbrains.jet.j2k.ast.Identifier +import com.intellij.psi.CommonClassNames.JAVA_LANG_OBJECT +import org.jetbrains.jet.j2k.ast.MethodCallExpression + +public open class ExpressionVisitorForDirectObjectInheritors(converter: Converter): ExpressionVisitor(converter) { + public override fun visitMethodCallExpression(expression: PsiMethodCallExpression?): Unit { + val methodExpression = expression?.getMethodExpression()!! + if (superMethodInvocation(methodExpression, "hashCode")) { + myResult = MethodCallExpression.build(Identifier("System", false), "identityHashCode", arrayList(Identifier("this"))) + } + else if (superMethodInvocation(methodExpression, "equals")) { + myResult = MethodCallExpression.build(Identifier("this", false), "identityEquals", getConverter().argumentsToExpressionList(expression!!)) + } + else if (superMethodInvocation(methodExpression, "toString")) { + myResult = DummyStringExpression(java.lang.String.format("getJavaClass<%s>.getName() + '@' + Integer.toHexString(hashCode())", + ExpressionVisitor.getClassName(methodExpression))!!) + } + else { + convertMethodCallExpression(expression!!) + } + } + + class object { + private fun superMethodInvocation(expression: PsiReferenceExpression, methodName: String?): Boolean { + val referenceName: String? = expression.getReferenceName() + val qualifierExpression: PsiExpression? = expression.getQualifierExpression() + if (referenceName == methodName && qualifierExpression is PsiSuperExpression) { + val `type`: PsiType? = qualifierExpression.getType() + if (`type` != null && `type`.getCanonicalText() == JAVA_LANG_OBJECT) { + return true + } + } + return false + } + } +} diff --git a/src/org/jetbrains/jet/j2k/visitors/StatementVisitor.kt b/src/org/jetbrains/jet/j2k/visitors/StatementVisitor.kt index 9ce0e5058a0..625e6357c6b 100644 --- a/src/org/jetbrains/jet/j2k/visitors/StatementVisitor.kt +++ b/src/org/jetbrains/jet/j2k/visitors/StatementVisitor.kt @@ -1,266 +1,266 @@ -package org.jetbrains.jet.j2k.visitors - -import com.intellij.psi.* -import com.intellij.psi.tree.IElementType -import org.jetbrains.annotations.Nullable -import org.jetbrains.jet.j2k.Converter -import org.jetbrains.jet.j2k.ast.* -import java.util.Arrays -import java.util.Collections -import java.util.LinkedList -import org.jetbrains.jet.j2k.countWritingAccesses -import java.util.ArrayList - -public open class StatementVisitor(converter: Converter): ElementVisitor(converter) { - public override fun visitAssertStatement(statement: PsiAssertStatement?): Unit { - myResult = AssertStatement(getConverter().expressionToExpression(statement?.getAssertCondition()), - getConverter().expressionToExpression(statement?.getAssertDescription())) - } - - public override fun visitBlockStatement(statement: PsiBlockStatement?): Unit { - myResult = myConverter.blockToBlock(statement?.getCodeBlock(), true) - } - - public override fun visitBreakStatement(statement: PsiBreakStatement?): Unit { - if (statement?.getLabelIdentifier() == null) { - myResult = BreakStatement(Identifier.EMPTY_IDENTIFIER) - } - else - { - myResult = BreakStatement(Converter.identifierToIdentifier(statement?.getLabelIdentifier())) - } - } - - public override fun visitContinueStatement(statement: PsiContinueStatement?): Unit { - if (statement?.getLabelIdentifier() == null) - { - myResult = ContinueStatement(Identifier.EMPTY_IDENTIFIER) - } - else - { - myResult = ContinueStatement(Converter.identifierToIdentifier(statement?.getLabelIdentifier())) - } - } - - public override fun visitDeclarationStatement(statement: PsiDeclarationStatement?): Unit { - myResult = DeclarationStatement(getConverter().elementsToElementList(statement?.getDeclaredElements()!!)) - } - - public override fun visitDoWhileStatement(statement: PsiDoWhileStatement?): Unit { - val condition: PsiExpression? = statement?.getCondition() - val expression: Expression = (if (condition != null && condition.getType() != null) - getConverter().expressionToExpression(condition, condition.getType()) - else - getConverter().expressionToExpression(condition)) - myResult = DoWhileStatement(expression, getConverter().statementToStatement(statement?.getBody())) - } - - public override fun visitExpressionStatement(statement: PsiExpressionStatement?): Unit { - myResult = getConverter().expressionToExpression(statement?.getExpression()) - } - - public override fun visitExpressionListStatement(statement: PsiExpressionListStatement?): Unit { - myResult = ExpressionListStatement(getConverter().expressionsToExpressionList( - statement?.getExpressionList()?.getExpressions()!!)) - } - - public override fun visitForStatement(statement: PsiForStatement?): Unit { - val initialization: PsiStatement? = statement?.getInitialization() - val update: PsiStatement? = statement?.getUpdate() - val condition: PsiExpression? = statement?.getCondition() - val body: PsiStatement? = statement?.getBody() - val firstChild: PsiLocalVariable? = (if (initialization != null && (initialization.getFirstChild() is PsiLocalVariable)) - (initialization.getFirstChild() as PsiLocalVariable) - else - null) - var bodyWriteCount: Int = countWritingAccesses(firstChild, body) - var conditionWriteCount: Int = countWritingAccesses(firstChild, condition) - var updateWriteCount: Int = countWritingAccesses(firstChild, update) - val onceWritableIterator: Boolean = updateWriteCount == 1 && bodyWriteCount + conditionWriteCount == 0 - val operationTokenType: IElementType? = (if (condition is PsiBinaryExpression) - condition.getOperationTokenType() - else - null) - if (initialization is PsiDeclarationStatement && initialization.getFirstChild() == initialization.getLastChild() && - condition != null && update != null && update.getChildren().size == 1 && - (isPlusPlusExpression(update.getChildren()[0]!!)) && (operationTokenType == JavaTokenType.LT || operationTokenType == JavaTokenType.LE) && - initialization.getFirstChild() != null && (initialization.getFirstChild() is PsiLocalVariable) && - firstChild != null && firstChild.getNameIdentifier() != null && onceWritableIterator) { - val end: Expression = getConverter().expressionToExpression((condition as PsiBinaryExpression).getROperand()) - val endExpression: Expression = (if (operationTokenType == JavaTokenType.LT) - BinaryExpression(end, Identifier("1"), "-") - else - end) - myResult = ForeachWithRangeStatement(Identifier(firstChild.getName()!!), - getConverter().expressionToExpression(firstChild.getInitializer()), - endExpression, - getConverter().statementToStatement(body)) - } - else { - var forStatements = ArrayList() - forStatements.add(getConverter().statementToStatement(initialization)) - forStatements.add(WhileStatement(getConverter().expressionToExpression(condition), - Block(arrayList(getConverter().statementToStatement(body), - Block(arrayList(getConverter().statementToStatement(update)), false)), false))) - myResult = Block(forStatements, false) - } - } - - public override fun visitForeachStatement(statement: PsiForeachStatement?): Unit { - myResult = ForeachStatement(getConverter().parameterToParameter(statement?.getIterationParameter()!!), - getConverter().expressionToExpression(statement?.getIteratedValue()), - getConverter().statementToStatement(statement?.getBody())) - } - - public override fun visitIfStatement(statement: PsiIfStatement?): Unit { - val condition: PsiExpression? = statement?.getCondition() - val expression: Expression = getConverter().expressionToExpression(condition, PsiType.BOOLEAN) - myResult = IfStatement(expression, - getConverter().statementToStatement(statement?.getThenBranch()), - getConverter().statementToStatement(statement?.getElseBranch())) - } - - public override fun visitLabeledStatement(statement: PsiLabeledStatement?): Unit { - myResult = LabelStatement(Converter.identifierToIdentifier(statement?.getLabelIdentifier()), - getConverter().statementToStatement(statement?.getStatement())) - } - - public override fun visitSwitchLabelStatement(statement: PsiSwitchLabelStatement?): Unit { - myResult = (if (statement?.isDefaultCase()!!) - DefaultSwitchLabelStatement() - else - SwitchLabelStatement(getConverter().expressionToExpression(statement?.getCaseValue()))) - } - - public override fun visitSwitchStatement(statement: PsiSwitchStatement?): Unit { - myResult = SwitchContainer(getConverter().expressionToExpression(statement?.getExpression()), - switchBodyToCases(statement?.getBody())) - } - - private open fun switchBodyToCases(body: PsiCodeBlock?): List { - val cases: List> = splitToCases(body) - val allSwitchStatements = ArrayList() - if (body != null) { - // TODO Arrays.asList() - for(s in body.getStatements()) allSwitchStatements.add(s) - } - val result = ArrayList() - var pendingLabels = ArrayList() - var i: Int = 0 - for (ls in cases) { - // TODO assert {(ls?.size()).sure() > 0} - var label = ls[0] - // TODO assert {(label is PsiSwitchLabelStatement?)} - // TODO assert("not a right index") {allSwitchStatements?.get(i) == label} - if (ls.size() > 1) { - pendingLabels.add(getConverter().statementToStatement(label)) - val slice: List = ls.subList(1, (ls.size())) - if (!containsBreak(slice)) { - val statements = ArrayList(getConverter().statementsToStatementList(slice)) - statements.addAll(getConverter().statementsToStatementList(getAllToNextBreak(allSwitchStatements, i + ls.size()))) - result.add(CaseContainer(pendingLabels, statements)) - pendingLabels = arrayList() - } - else { - result.add(CaseContainer(pendingLabels, getConverter().statementsToStatementList(slice))) - pendingLabels = arrayList() - } - } - else { - pendingLabels.add(getConverter().statementToStatement(label)) - } - i += ls.size() - } - return result - } - - public override fun visitSynchronizedStatement(statement: PsiSynchronizedStatement?): Unit { - myResult = SynchronizedStatement(getConverter().expressionToExpression(statement?.getLockExpression()), - getConverter().blockToBlock(statement?.getBody())) - } - - public override fun visitThrowStatement(statement: PsiThrowStatement?): Unit { - myResult = ThrowStatement(getConverter().expressionToExpression(statement?.getException())) - } - - public override fun visitTryStatement(statement: PsiTryStatement?): Unit { - val catches = ArrayList() - val catchBlocks = statement?.getCatchBlocks()!! - val catchBlockParameters = statement?.getCatchBlockParameters()!! - for (i in 0..catchBlocks.size - 1) { - catches.add(CatchStatement(getConverter().parameterToParameter(catchBlockParameters[i]!!, true), - getConverter().blockToBlock(catchBlocks[i], true))) - } - myResult = TryStatement(getConverter().blockToBlock(statement?.getTryBlock(), true), - catches, getConverter().blockToBlock(statement?.getFinallyBlock(), true)) - } - - public override fun visitWhileStatement(statement: PsiWhileStatement?): Unit { - var condition: PsiExpression? = statement?.getCondition() - val expression: Expression = (if (condition != null && condition?.getType() != null) - this.getConverter().expressionToExpression(condition, condition?.getType()) - else - getConverter().expressionToExpression(condition)) - myResult = WhileStatement(expression, getConverter().statementToStatement(statement?.getBody())) - } - - public override fun visitReturnStatement(statement: PsiReturnStatement?): Unit { - val returnValue: PsiExpression? = statement?.getReturnValue() - val methodReturnType: PsiType? = getConverter().getMethodReturnType() - val expression: Expression = (if (returnValue != null && methodReturnType != null) - this.getConverter().expressionToExpression(returnValue, methodReturnType) - else - getConverter().expressionToExpression(returnValue)) - myResult = ReturnStatement(expression) - } - - class object { - private open fun isPlusPlusExpression(psiElement: PsiElement): Boolean { - return (psiElement is PsiPostfixExpression && psiElement.getOperationTokenType() == JavaTokenType.PLUSPLUS) || - (psiElement is PsiPrefixExpression && psiElement.getOperationTokenType() == JavaTokenType.PLUSPLUS) - } - - private fun containsBreak(slice: List) = slice.any { it is PsiBreakStatement } - - private open fun getAllToNextBreak(allStatements: List, start: Int): List { - val result = ArrayList() - for (i in start..allStatements.size() - 1) { - val s = allStatements.get(i) - if (s is PsiBreakStatement || s is PsiReturnStatement) { - return result - } - - if (!(s is PsiSwitchLabelStatement)) { - result.add(s) - } - - } - return result - } - - private open fun splitToCases(body: PsiCodeBlock?): List> { - val cases = ArrayList>() - var currentCaseStatements = ArrayList() - var isFirst: Boolean = true - if (body != null) { - for (s in body.getChildren()) { - if (s !is PsiStatement && s !is PsiComment) continue - if (s is PsiSwitchLabelStatement) { - if (isFirst) { - isFirst = false - } - else { - cases.add(currentCaseStatements) - currentCaseStatements = arrayList() - } - } - - currentCaseStatements.add(s) - } - cases.add(currentCaseStatements) - } - - return cases - } - } -} +package org.jetbrains.jet.j2k.visitors + +import com.intellij.psi.* +import com.intellij.psi.tree.IElementType +import org.jetbrains.annotations.Nullable +import org.jetbrains.jet.j2k.Converter +import org.jetbrains.jet.j2k.ast.* +import java.util.Arrays +import java.util.Collections +import java.util.LinkedList +import org.jetbrains.jet.j2k.countWritingAccesses +import java.util.ArrayList + +public open class StatementVisitor(converter: Converter): ElementVisitor(converter) { + public override fun visitAssertStatement(statement: PsiAssertStatement?): Unit { + myResult = AssertStatement(getConverter().expressionToExpression(statement?.getAssertCondition()), + getConverter().expressionToExpression(statement?.getAssertDescription())) + } + + public override fun visitBlockStatement(statement: PsiBlockStatement?): Unit { + myResult = myConverter.blockToBlock(statement?.getCodeBlock(), true) + } + + public override fun visitBreakStatement(statement: PsiBreakStatement?): Unit { + if (statement?.getLabelIdentifier() == null) { + myResult = BreakStatement(Identifier.EMPTY_IDENTIFIER) + } + else + { + myResult = BreakStatement(Converter.identifierToIdentifier(statement?.getLabelIdentifier())) + } + } + + public override fun visitContinueStatement(statement: PsiContinueStatement?): Unit { + if (statement?.getLabelIdentifier() == null) + { + myResult = ContinueStatement(Identifier.EMPTY_IDENTIFIER) + } + else + { + myResult = ContinueStatement(Converter.identifierToIdentifier(statement?.getLabelIdentifier())) + } + } + + public override fun visitDeclarationStatement(statement: PsiDeclarationStatement?): Unit { + myResult = DeclarationStatement(getConverter().elementsToElementList(statement?.getDeclaredElements()!!)) + } + + public override fun visitDoWhileStatement(statement: PsiDoWhileStatement?): Unit { + val condition: PsiExpression? = statement?.getCondition() + val expression: Expression = (if (condition != null && condition.getType() != null) + getConverter().expressionToExpression(condition, condition.getType()) + else + getConverter().expressionToExpression(condition)) + myResult = DoWhileStatement(expression, getConverter().statementToStatement(statement?.getBody())) + } + + public override fun visitExpressionStatement(statement: PsiExpressionStatement?): Unit { + myResult = getConverter().expressionToExpression(statement?.getExpression()) + } + + public override fun visitExpressionListStatement(statement: PsiExpressionListStatement?): Unit { + myResult = ExpressionListStatement(getConverter().expressionsToExpressionList( + statement?.getExpressionList()?.getExpressions()!!)) + } + + public override fun visitForStatement(statement: PsiForStatement?): Unit { + val initialization: PsiStatement? = statement?.getInitialization() + val update: PsiStatement? = statement?.getUpdate() + val condition: PsiExpression? = statement?.getCondition() + val body: PsiStatement? = statement?.getBody() + val firstChild: PsiLocalVariable? = (if (initialization != null && (initialization.getFirstChild() is PsiLocalVariable)) + (initialization.getFirstChild() as PsiLocalVariable) + else + null) + var bodyWriteCount: Int = countWritingAccesses(firstChild, body) + var conditionWriteCount: Int = countWritingAccesses(firstChild, condition) + var updateWriteCount: Int = countWritingAccesses(firstChild, update) + val onceWritableIterator: Boolean = updateWriteCount == 1 && bodyWriteCount + conditionWriteCount == 0 + val operationTokenType: IElementType? = (if (condition is PsiBinaryExpression) + condition.getOperationTokenType() + else + null) + if (initialization is PsiDeclarationStatement && initialization.getFirstChild() == initialization.getLastChild() && + condition != null && update != null && update.getChildren().size == 1 && + (isPlusPlusExpression(update.getChildren()[0]!!)) && (operationTokenType == JavaTokenType.LT || operationTokenType == JavaTokenType.LE) && + initialization.getFirstChild() != null && (initialization.getFirstChild() is PsiLocalVariable) && + firstChild != null && firstChild.getNameIdentifier() != null && onceWritableIterator) { + val end: Expression = getConverter().expressionToExpression((condition as PsiBinaryExpression).getROperand()) + val endExpression: Expression = (if (operationTokenType == JavaTokenType.LT) + BinaryExpression(end, Identifier("1"), "-") + else + end) + myResult = ForeachWithRangeStatement(Identifier(firstChild.getName()!!), + getConverter().expressionToExpression(firstChild.getInitializer()), + endExpression, + getConverter().statementToStatement(body)) + } + else { + var forStatements = ArrayList() + forStatements.add(getConverter().statementToStatement(initialization)) + forStatements.add(WhileStatement(getConverter().expressionToExpression(condition), + Block(arrayList(getConverter().statementToStatement(body), + Block(arrayList(getConverter().statementToStatement(update)), false)), false))) + myResult = Block(forStatements, false) + } + } + + public override fun visitForeachStatement(statement: PsiForeachStatement?): Unit { + myResult = ForeachStatement(getConverter().parameterToParameter(statement?.getIterationParameter()!!), + getConverter().expressionToExpression(statement?.getIteratedValue()), + getConverter().statementToStatement(statement?.getBody())) + } + + public override fun visitIfStatement(statement: PsiIfStatement?): Unit { + val condition: PsiExpression? = statement?.getCondition() + val expression: Expression = getConverter().expressionToExpression(condition, PsiType.BOOLEAN) + myResult = IfStatement(expression, + getConverter().statementToStatement(statement?.getThenBranch()), + getConverter().statementToStatement(statement?.getElseBranch())) + } + + public override fun visitLabeledStatement(statement: PsiLabeledStatement?): Unit { + myResult = LabelStatement(Converter.identifierToIdentifier(statement?.getLabelIdentifier()), + getConverter().statementToStatement(statement?.getStatement())) + } + + public override fun visitSwitchLabelStatement(statement: PsiSwitchLabelStatement?): Unit { + myResult = (if (statement?.isDefaultCase()!!) + DefaultSwitchLabelStatement() + else + SwitchLabelStatement(getConverter().expressionToExpression(statement?.getCaseValue()))) + } + + public override fun visitSwitchStatement(statement: PsiSwitchStatement?): Unit { + myResult = SwitchContainer(getConverter().expressionToExpression(statement?.getExpression()), + switchBodyToCases(statement?.getBody())) + } + + private open fun switchBodyToCases(body: PsiCodeBlock?): List { + val cases: List> = splitToCases(body) + val allSwitchStatements = ArrayList() + if (body != null) { + // TODO Arrays.asList() + for(s in body.getStatements()) allSwitchStatements.add(s) + } + val result = ArrayList() + var pendingLabels = ArrayList() + var i: Int = 0 + for (ls in cases) { + // TODO assert {(ls?.size()).sure() > 0} + var label = ls[0] + // TODO assert {(label is PsiSwitchLabelStatement?)} + // TODO assert("not a right index") {allSwitchStatements?.get(i) == label} + if (ls.size() > 1) { + pendingLabels.add(getConverter().statementToStatement(label)) + val slice: List = ls.subList(1, (ls.size())) + if (!containsBreak(slice)) { + val statements = ArrayList(getConverter().statementsToStatementList(slice)) + statements.addAll(getConverter().statementsToStatementList(getAllToNextBreak(allSwitchStatements, i + ls.size()))) + result.add(CaseContainer(pendingLabels, statements)) + pendingLabels = arrayList() + } + else { + result.add(CaseContainer(pendingLabels, getConverter().statementsToStatementList(slice))) + pendingLabels = arrayList() + } + } + else { + pendingLabels.add(getConverter().statementToStatement(label)) + } + i += ls.size() + } + return result + } + + public override fun visitSynchronizedStatement(statement: PsiSynchronizedStatement?): Unit { + myResult = SynchronizedStatement(getConverter().expressionToExpression(statement?.getLockExpression()), + getConverter().blockToBlock(statement?.getBody())) + } + + public override fun visitThrowStatement(statement: PsiThrowStatement?): Unit { + myResult = ThrowStatement(getConverter().expressionToExpression(statement?.getException())) + } + + public override fun visitTryStatement(statement: PsiTryStatement?): Unit { + val catches = ArrayList() + val catchBlocks = statement?.getCatchBlocks()!! + val catchBlockParameters = statement?.getCatchBlockParameters()!! + for (i in 0..catchBlocks.size - 1) { + catches.add(CatchStatement(getConverter().parameterToParameter(catchBlockParameters[i]!!, true), + getConverter().blockToBlock(catchBlocks[i], true))) + } + myResult = TryStatement(getConverter().blockToBlock(statement?.getTryBlock(), true), + catches, getConverter().blockToBlock(statement?.getFinallyBlock(), true)) + } + + public override fun visitWhileStatement(statement: PsiWhileStatement?): Unit { + var condition: PsiExpression? = statement?.getCondition() + val expression: Expression = (if (condition != null && condition?.getType() != null) + this.getConverter().expressionToExpression(condition, condition?.getType()) + else + getConverter().expressionToExpression(condition)) + myResult = WhileStatement(expression, getConverter().statementToStatement(statement?.getBody())) + } + + public override fun visitReturnStatement(statement: PsiReturnStatement?): Unit { + val returnValue: PsiExpression? = statement?.getReturnValue() + val methodReturnType: PsiType? = getConverter().getMethodReturnType() + val expression: Expression = (if (returnValue != null && methodReturnType != null) + this.getConverter().expressionToExpression(returnValue, methodReturnType) + else + getConverter().expressionToExpression(returnValue)) + myResult = ReturnStatement(expression) + } + + class object { + private open fun isPlusPlusExpression(psiElement: PsiElement): Boolean { + return (psiElement is PsiPostfixExpression && psiElement.getOperationTokenType() == JavaTokenType.PLUSPLUS) || + (psiElement is PsiPrefixExpression && psiElement.getOperationTokenType() == JavaTokenType.PLUSPLUS) + } + + private fun containsBreak(slice: List) = slice.any { it is PsiBreakStatement } + + private open fun getAllToNextBreak(allStatements: List, start: Int): List { + val result = ArrayList() + for (i in start..allStatements.size() - 1) { + val s = allStatements.get(i) + if (s is PsiBreakStatement || s is PsiReturnStatement) { + return result + } + + if (!(s is PsiSwitchLabelStatement)) { + result.add(s) + } + + } + return result + } + + private open fun splitToCases(body: PsiCodeBlock?): List> { + val cases = ArrayList>() + var currentCaseStatements = ArrayList() + var isFirst: Boolean = true + if (body != null) { + for (s in body.getChildren()) { + if (s !is PsiStatement && s !is PsiComment) continue + if (s is PsiSwitchLabelStatement) { + if (isFirst) { + isFirst = false + } + else { + cases.add(currentCaseStatements) + currentCaseStatements = arrayList() + } + } + + currentCaseStatements.add(s) + } + cases.add(currentCaseStatements) + } + + return cases + } + } +} diff --git a/src/org/jetbrains/jet/j2k/visitors/SuperVisitor.kt b/src/org/jetbrains/jet/j2k/visitors/SuperVisitor.kt index 7cb4e1853f7..3c0a779a28e 100644 --- a/src/org/jetbrains/jet/j2k/visitors/SuperVisitor.kt +++ b/src/org/jetbrains/jet/j2k/visitors/SuperVisitor.kt @@ -1,26 +1,26 @@ -package org.jetbrains.jet.j2k.visitors - -import com.intellij.psi.* -import java.util.HashSet - -public open class SuperVisitor(): JavaRecursiveElementVisitor() { - public val resolvedSuperCallParameters: HashSet = hashSet() - - public override fun visitMethodCallExpression(expression: PsiMethodCallExpression?): Unit { - if (expression != null && isSuper(expression.getMethodExpression())) { - resolvedSuperCallParameters.add(expression.getArgumentList()) - } - } - class object { - open fun isSuper(r: PsiReference): Boolean { - if (r.getCanonicalText().equals("super")) { - val baseConstructor: PsiElement? = r.resolve() - if (baseConstructor != null && baseConstructor is PsiMethod && baseConstructor.isConstructor()) { - return true - } - } - - return false - } - } -} +package org.jetbrains.jet.j2k.visitors + +import com.intellij.psi.* +import java.util.HashSet + +public open class SuperVisitor(): JavaRecursiveElementVisitor() { + public val resolvedSuperCallParameters: HashSet = hashSet() + + public override fun visitMethodCallExpression(expression: PsiMethodCallExpression?): Unit { + if (expression != null && isSuper(expression.getMethodExpression())) { + resolvedSuperCallParameters.add(expression.getArgumentList()) + } + } + class object { + open fun isSuper(r: PsiReference): Boolean { + if (r.getCanonicalText().equals("super")) { + val baseConstructor: PsiElement? = r.resolve() + if (baseConstructor != null && baseConstructor is PsiMethod && baseConstructor.isConstructor()) { + return true + } + } + + return false + } + } +} diff --git a/src/org/jetbrains/jet/j2k/visitors/ThisVisitor.kt b/src/org/jetbrains/jet/j2k/visitors/ThisVisitor.kt index 4b30bdb2cbe..5fb360198c8 100644 --- a/src/org/jetbrains/jet/j2k/visitors/ThisVisitor.kt +++ b/src/org/jetbrains/jet/j2k/visitors/ThisVisitor.kt @@ -1,33 +1,33 @@ -package org.jetbrains.jet.j2k.visitors - -import com.intellij.psi.* -import org.jetbrains.annotations.Nullable -import java.util.LinkedHashSet - -public open class ThisVisitor(): JavaRecursiveElementVisitor() { - private val myResolvedConstructors = LinkedHashSet() - - public override fun visitReferenceExpression(expression: PsiReferenceExpression?): Unit { - for (r : PsiReference? in expression?.getReferences()!!) { - if (r?.getCanonicalText() == "this") { - val res: PsiElement? = r?.resolve() - if (res is PsiMethod && res.isConstructor()) { - myResolvedConstructors.add(res) - } - } - } - } - - public open fun getPrimaryConstructor(): PsiMethod? { - if (myResolvedConstructors.size() > 0) { - val first: PsiMethod = myResolvedConstructors.iterator().next() - for (m in myResolvedConstructors) - if (m.hashCode() != first.hashCode()) { - return null - } - - return first - } - return null - } -} +package org.jetbrains.jet.j2k.visitors + +import com.intellij.psi.* +import org.jetbrains.annotations.Nullable +import java.util.LinkedHashSet + +public open class ThisVisitor(): JavaRecursiveElementVisitor() { + private val myResolvedConstructors = LinkedHashSet() + + public override fun visitReferenceExpression(expression: PsiReferenceExpression?): Unit { + for (r : PsiReference? in expression?.getReferences()!!) { + if (r?.getCanonicalText() == "this") { + val res: PsiElement? = r?.resolve() + if (res is PsiMethod && res.isConstructor()) { + myResolvedConstructors.add(res) + } + } + } + } + + public open fun getPrimaryConstructor(): PsiMethod? { + if (myResolvedConstructors.size() > 0) { + val first: PsiMethod = myResolvedConstructors.iterator().next() + for (m in myResolvedConstructors) + if (m.hashCode() != first.hashCode()) { + return null + } + + return first + } + return null + } +} diff --git a/src/org/jetbrains/jet/j2k/visitors/TypeVisitor.kt b/src/org/jetbrains/jet/j2k/visitors/TypeVisitor.kt index dcc0cdf8934..3d94c4363f3 100644 --- a/src/org/jetbrains/jet/j2k/visitors/TypeVisitor.kt +++ b/src/org/jetbrains/jet/j2k/visitors/TypeVisitor.kt @@ -1,162 +1,162 @@ -package org.jetbrains.jet.j2k.visitors - -import com.intellij.psi.* -import com.intellij.psi.impl.source.PsiClassReferenceType -import org.jetbrains.jet.j2k.Converter -import org.jetbrains.jet.j2k.J2KConverterFlags -import org.jetbrains.jet.j2k.ast.* -import org.jetbrains.jet.j2k.ast.types.* -import java.util.LinkedList -import com.intellij.openapi.util.text.StringUtil - -public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisitor() { - private var myResult : Type = EmptyType() - public open fun getResult() : Type { - return myResult - } - - public override fun visitPrimitiveType(primitiveType: PsiPrimitiveType?) : Type { - val name : String = primitiveType?.getCanonicalText()!! - if (name == "void") { - myResult = PrimitiveType(Identifier("Unit")) - } - else if (Node.PRIMITIVE_TYPES.contains(name)) { - myResult = PrimitiveType(Identifier(StringUtil.capitalize(name))) - } - else { - myResult = PrimitiveType(Identifier(name)) - } - return myResult - } - - public override fun visitArrayType(arrayType: PsiArrayType?) : Type { - if (myResult is EmptyType) { - myResult = ArrayType(myConverter.typeToType(arrayType?.getComponentType()), true) - } - - return myResult - } - - public override fun visitClassType(classType : PsiClassType?) : Type { - if (classType == null) return myResult - val identifier : Identifier = constructClassTypeIdentifier(classType) - val resolvedClassTypeParams : List = createRawTypesForResolvedReference(classType) - if (classType.getParameterCount() == 0 && resolvedClassTypeParams.size() > 0) { - myResult = ClassType(identifier, resolvedClassTypeParams, true) - } - else { - myResult = ClassType(identifier, myConverter.typesToTypeList(classType.getParameters()), true) - } - return myResult - } - - private fun constructClassTypeIdentifier(classType : PsiClassType) : Identifier { - val psiClass : PsiClass? = classType.resolve() - if (psiClass != null) { - val qualifiedName: String? = psiClass.getQualifiedName() - if (qualifiedName != null) { - if (!qualifiedName.equals("java.lang.Object") && myConverter.hasFlag(J2KConverterFlags.FULLY_QUALIFIED_TYPE_NAMES)) { - return Identifier(qualifiedName) - } - - if (qualifiedName.equals(CommonClassNames.JAVA_LANG_ITERABLE)) { - return Identifier(CommonClassNames.JAVA_LANG_ITERABLE) - } - - if (qualifiedName.equals(CommonClassNames.JAVA_UTIL_ITERATOR)) { - return Identifier(CommonClassNames.JAVA_UTIL_ITERATOR) - } - } - } - - val classTypeName = createQualifiedName(classType) - if (classTypeName.isEmpty()) { - return Identifier(getClassTypeName(classType)) - } - - return Identifier(classTypeName) - } - - private fun createRawTypesForResolvedReference(classType : PsiClassType) : List { - val typeParams = LinkedList() - if (classType is PsiClassReferenceType) { - val reference : PsiJavaCodeReferenceElement? = (classType as PsiClassReferenceType).getReference() - val resolve : PsiElement? = reference?.resolve() - if (resolve is PsiClass) { - for (p : PsiTypeParameter? in (resolve as PsiClass).getTypeParameters()) { - val superTypes = p!!.getSuperTypes() - val boundType : Type = (if (superTypes.size > 0) - ClassType(Identifier(getClassTypeName(superTypes[0]!!)), - myConverter.typesToTypeList(superTypes[0]!!.getParameters()), - true) - else - StarProjectionType()) - typeParams.add(boundType) - } - } - } - - return typeParams - } - - public override fun visitWildcardType(wildcardType : PsiWildcardType?) : Type { - if (wildcardType!!.isExtends()) { - myResult = OutProjectionType(myConverter.typeToType(wildcardType!!.getExtendsBound())) - } - else - if (wildcardType!!.isSuper()) { - myResult = InProjectionType(myConverter.typeToType(wildcardType?.getSuperBound())) - } - else { - myResult = StarProjectionType() - } - return myResult - } - - public override fun visitEllipsisType(ellipsisType : PsiEllipsisType?) : Type { - myResult = VarArg(myConverter.typeToType(ellipsisType?.getComponentType())) - return myResult - } - - class object { - private fun createQualifiedName(classType : PsiClassType) : String { - if (classType is PsiClassReferenceType) - { - val reference : PsiJavaCodeReferenceElement? = (classType as PsiClassReferenceType).getReference() - if (reference != null && reference.isQualified()) { - var result : String = Identifier(reference.getReferenceName()!!).toKotlin() - var qualifier : PsiElement? = reference.getQualifier() - while (qualifier != null) - { - val p : PsiJavaCodeReferenceElement = (qualifier as PsiJavaCodeReferenceElement) - result = Identifier(p.getReferenceName()!!).toKotlin() + "." + result - qualifier = p.getQualifier() - } - return result - } - } - - return "" - } - - private fun getClassTypeName(classType : PsiClassType) : String { - var canonicalTypeStr : String? = classType.getCanonicalText() - return when(canonicalTypeStr) { - CommonClassNames.JAVA_LANG_OBJECT -> "Any" - CommonClassNames.JAVA_LANG_BYTE -> "Byte" - CommonClassNames.JAVA_LANG_CHARACTER -> "Char" - CommonClassNames.JAVA_LANG_DOUBLE -> "Double" - CommonClassNames.JAVA_LANG_FLOAT -> "Float" - CommonClassNames.JAVA_LANG_INTEGER -> "Int" - CommonClassNames.JAVA_LANG_LONG -> "Long" - CommonClassNames.JAVA_LANG_SHORT -> "Short" - CommonClassNames.JAVA_LANG_BOOLEAN -> "Boolean" - - else -> (if (classType.getClassName() != null) - classType.getClassName()!! - else - classType.getCanonicalText())!! - } - } - } -} +package org.jetbrains.jet.j2k.visitors + +import com.intellij.psi.* +import com.intellij.psi.impl.source.PsiClassReferenceType +import org.jetbrains.jet.j2k.Converter +import org.jetbrains.jet.j2k.J2KConverterFlags +import org.jetbrains.jet.j2k.ast.* +import org.jetbrains.jet.j2k.ast.types.* +import java.util.LinkedList +import com.intellij.openapi.util.text.StringUtil + +public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisitor() { + private var myResult : Type = EmptyType() + public open fun getResult() : Type { + return myResult + } + + public override fun visitPrimitiveType(primitiveType: PsiPrimitiveType?) : Type { + val name : String = primitiveType?.getCanonicalText()!! + if (name == "void") { + myResult = PrimitiveType(Identifier("Unit")) + } + else if (Node.PRIMITIVE_TYPES.contains(name)) { + myResult = PrimitiveType(Identifier(StringUtil.capitalize(name))) + } + else { + myResult = PrimitiveType(Identifier(name)) + } + return myResult + } + + public override fun visitArrayType(arrayType: PsiArrayType?) : Type { + if (myResult is EmptyType) { + myResult = ArrayType(myConverter.typeToType(arrayType?.getComponentType()), true) + } + + return myResult + } + + public override fun visitClassType(classType : PsiClassType?) : Type { + if (classType == null) return myResult + val identifier : Identifier = constructClassTypeIdentifier(classType) + val resolvedClassTypeParams : List = createRawTypesForResolvedReference(classType) + if (classType.getParameterCount() == 0 && resolvedClassTypeParams.size() > 0) { + myResult = ClassType(identifier, resolvedClassTypeParams, true) + } + else { + myResult = ClassType(identifier, myConverter.typesToTypeList(classType.getParameters()), true) + } + return myResult + } + + private fun constructClassTypeIdentifier(classType : PsiClassType) : Identifier { + val psiClass : PsiClass? = classType.resolve() + if (psiClass != null) { + val qualifiedName: String? = psiClass.getQualifiedName() + if (qualifiedName != null) { + if (!qualifiedName.equals("java.lang.Object") && myConverter.hasFlag(J2KConverterFlags.FULLY_QUALIFIED_TYPE_NAMES)) { + return Identifier(qualifiedName) + } + + if (qualifiedName.equals(CommonClassNames.JAVA_LANG_ITERABLE)) { + return Identifier(CommonClassNames.JAVA_LANG_ITERABLE) + } + + if (qualifiedName.equals(CommonClassNames.JAVA_UTIL_ITERATOR)) { + return Identifier(CommonClassNames.JAVA_UTIL_ITERATOR) + } + } + } + + val classTypeName = createQualifiedName(classType) + if (classTypeName.isEmpty()) { + return Identifier(getClassTypeName(classType)) + } + + return Identifier(classTypeName) + } + + private fun createRawTypesForResolvedReference(classType : PsiClassType) : List { + val typeParams = LinkedList() + if (classType is PsiClassReferenceType) { + val reference : PsiJavaCodeReferenceElement? = (classType as PsiClassReferenceType).getReference() + val resolve : PsiElement? = reference?.resolve() + if (resolve is PsiClass) { + for (p : PsiTypeParameter? in (resolve as PsiClass).getTypeParameters()) { + val superTypes = p!!.getSuperTypes() + val boundType : Type = (if (superTypes.size > 0) + ClassType(Identifier(getClassTypeName(superTypes[0]!!)), + myConverter.typesToTypeList(superTypes[0]!!.getParameters()), + true) + else + StarProjectionType()) + typeParams.add(boundType) + } + } + } + + return typeParams + } + + public override fun visitWildcardType(wildcardType : PsiWildcardType?) : Type { + if (wildcardType!!.isExtends()) { + myResult = OutProjectionType(myConverter.typeToType(wildcardType!!.getExtendsBound())) + } + else + if (wildcardType!!.isSuper()) { + myResult = InProjectionType(myConverter.typeToType(wildcardType?.getSuperBound())) + } + else { + myResult = StarProjectionType() + } + return myResult + } + + public override fun visitEllipsisType(ellipsisType : PsiEllipsisType?) : Type { + myResult = VarArg(myConverter.typeToType(ellipsisType?.getComponentType())) + return myResult + } + + class object { + private fun createQualifiedName(classType : PsiClassType) : String { + if (classType is PsiClassReferenceType) + { + val reference : PsiJavaCodeReferenceElement? = (classType as PsiClassReferenceType).getReference() + if (reference != null && reference.isQualified()) { + var result : String = Identifier(reference.getReferenceName()!!).toKotlin() + var qualifier : PsiElement? = reference.getQualifier() + while (qualifier != null) + { + val p : PsiJavaCodeReferenceElement = (qualifier as PsiJavaCodeReferenceElement) + result = Identifier(p.getReferenceName()!!).toKotlin() + "." + result + qualifier = p.getQualifier() + } + return result + } + } + + return "" + } + + private fun getClassTypeName(classType : PsiClassType) : String { + var canonicalTypeStr : String? = classType.getCanonicalText() + return when(canonicalTypeStr) { + CommonClassNames.JAVA_LANG_OBJECT -> "Any" + CommonClassNames.JAVA_LANG_BYTE -> "Byte" + CommonClassNames.JAVA_LANG_CHARACTER -> "Char" + CommonClassNames.JAVA_LANG_DOUBLE -> "Double" + CommonClassNames.JAVA_LANG_FLOAT -> "Float" + CommonClassNames.JAVA_LANG_INTEGER -> "Int" + CommonClassNames.JAVA_LANG_LONG -> "Long" + CommonClassNames.JAVA_LANG_SHORT -> "Short" + CommonClassNames.JAVA_LANG_BOOLEAN -> "Boolean" + + else -> (if (classType.getClassName() != null) + classType.getClassName()!! + else + classType.getCanonicalText())!! + } + } + } +} diff --git a/tests/test/org/jetbrains/jet/j2k/StandaloneJavaToKotlinConverterTest.java b/tests/test/org/jetbrains/jet/j2k/StandaloneJavaToKotlinConverterTest.java index af6a54de9cb..6d6ba9ceb7b 100644 --- a/tests/test/org/jetbrains/jet/j2k/StandaloneJavaToKotlinConverterTest.java +++ b/tests/test/org/jetbrains/jet/j2k/StandaloneJavaToKotlinConverterTest.java @@ -1,178 +1,178 @@ -/* - * 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; - -import com.intellij.core.JavaCoreProjectEnvironment; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiJavaFile; -import junit.framework.Assert; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.File; -import java.io.IOException; - -/** - * @author ignatov - */ -public class StandaloneJavaToKotlinConverterTest extends TestCase { - private final String myDataPath; - private final String myName; - @NotNull - private final static JavaCoreProjectEnvironment myJavaCoreEnvironment = JavaToKotlinTranslator.setUpJavaCoreEnvironment(); - - public StandaloneJavaToKotlinConverterTest(String dataPath, String name) { - myDataPath = dataPath; - myName = name; - } - - @Override - protected void runTest() throws Throwable { - Converter converter = new Converter(); - String javaPath = "tests/testData/" + getTestFilePath(); - String kotlinPath = javaPath.replace(".jav", ".kt"); - - final File kotlinFile = new File(kotlinPath); - if (!kotlinFile.exists()) { - FileUtil.writeToFile(kotlinFile, ""); - } - final String expected = StringUtil.convertLineSeparators(FileUtil.loadFile(kotlinFile)); - final File javaFile = new File(javaPath); - final String javaCode = FileUtil.loadFile(javaFile); - - String actual = ""; - String parentFileName = javaFile.getParentFile().getName(); - if (parentFileName.equals("expression")) { - actual = expressionToKotlin(converter, javaCode); - } - else if (parentFileName.equals("statement")) { - actual = statementToKotlin(converter, javaCode); - } - else if (parentFileName.equals("method")) { - actual = methodToKotlin(converter, javaCode); - } - else if (parentFileName.equals("class")) { - actual = fileToKotlin(converter, javaCode); - } - else if (parentFileName.equals("file")) { - actual = fileToKotlin(converter, javaCode); - } - else if (parentFileName.equals("comp")) actual = fileToFileWithCompatibilityImport(javaCode); - - actual = StringUtil.convertLineSeparators(actual); - - assert !actual.isEmpty() : "Specify what is it: file, class, method, statement or expression: " + javaPath + " parent: " + parentFileName; - - final File tmp = new File(kotlinPath + ".tmp"); - if (!expected.equals(actual)) FileUtil.writeToFile(tmp, actual); - if (expected.equals(actual) && tmp.exists()) //noinspection ResultOfMethodCallIgnored - { - tmp.delete(); - } - - Assert.assertEquals(expected, actual); - } - - @NotNull - String getTestFilePath() { - return myDataPath + "/" + myName + ".jav"; - } - - - @NotNull - @Override - public String getName() { - return "test_" + myName; - } - - @NotNull - public static Test suite() { - TestSuite suite = new TestSuite(); -// suite.addTest(new StandaloneJavaToKotlinConverterTest("ast/class/file", "kt-639")); - suite.addTest(TestCaseBuilder.suiteForDirectory("tests/testData", "/ast", new TestCaseBuilder.NamedTestFactory() { - @NotNull - @Override - public Test createTest(@NotNull String dataPath, @NotNull String name) { - return new StandaloneJavaToKotlinConverterTest(dataPath, name); - } - })); - return suite; - } - - @NotNull - private static String fileToFileWithCompatibilityImport(@NotNull String text) { - return JavaToKotlinTranslator.generateKotlinCodeWithCompatibilityImport(text); - } - - @NotNull - private String fileToKotlin(Converter converter, @NotNull String text) { - return generateKotlinCode(converter, JavaToKotlinTranslator.createFile(myJavaCoreEnvironment, text)); - } - - @NotNull - private static String generateKotlinCode(@NotNull Converter converter, @Nullable PsiFile file) { - if (file != null && file instanceof PsiJavaFile) { - JavaToKotlinTranslator.setClassIdentifiers(converter, file); - return prettify(converter.elementToKotlin(file)); - } - return ""; - } - - @NotNull - private String methodToKotlin(Converter converter, String text) throws IOException { - String result = fileToKotlin(converter, "final class C {" + text + "}") - .replaceAll("class C\\(\\) \\{", ""); - result = result.substring(0, result.lastIndexOf("}")); - return prettify(result); - } - - @NotNull - private String statementToKotlin(Converter converter, String text) throws Exception { - String result = methodToKotlin(converter, "void main() {" + text + "}"); - int pos = result.lastIndexOf("}"); - result = result.substring(0, pos).replaceFirst("fun main\\(\\) : Unit \\{", ""); - return prettify(result); - } - - @NotNull - private String expressionToKotlin(Converter converter, String code) throws Exception { - String result = statementToKotlin(converter, "Object o =" + code + "}"); - result = result.replaceFirst("var o : Any\\? =", ""); - return prettify(result); - } - - @NotNull - private static String prettify(@Nullable String code) { - if (code == null) { - return ""; - } - return code - .trim() - .replaceAll("\r\n", "\n") - .replaceAll(" \n", "\n") - .replaceAll("\n ", "\n") - .replaceAll("\n+", "\n") - .replaceAll(" +", " ") - .trim() - ; - } -} +/* + * 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; + +import com.intellij.core.JavaCoreProjectEnvironment; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiJavaFile; +import junit.framework.Assert; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.File; +import java.io.IOException; + +/** + * @author ignatov + */ +public class StandaloneJavaToKotlinConverterTest extends TestCase { + private final String myDataPath; + private final String myName; + @NotNull + private final static JavaCoreProjectEnvironment myJavaCoreEnvironment = JavaToKotlinTranslator.setUpJavaCoreEnvironment(); + + public StandaloneJavaToKotlinConverterTest(String dataPath, String name) { + myDataPath = dataPath; + myName = name; + } + + @Override + protected void runTest() throws Throwable { + Converter converter = new Converter(); + String javaPath = "tests/testData/" + getTestFilePath(); + String kotlinPath = javaPath.replace(".jav", ".kt"); + + final File kotlinFile = new File(kotlinPath); + if (!kotlinFile.exists()) { + FileUtil.writeToFile(kotlinFile, ""); + } + final String expected = StringUtil.convertLineSeparators(FileUtil.loadFile(kotlinFile)); + final File javaFile = new File(javaPath); + final String javaCode = FileUtil.loadFile(javaFile); + + String actual = ""; + String parentFileName = javaFile.getParentFile().getName(); + if (parentFileName.equals("expression")) { + actual = expressionToKotlin(converter, javaCode); + } + else if (parentFileName.equals("statement")) { + actual = statementToKotlin(converter, javaCode); + } + else if (parentFileName.equals("method")) { + actual = methodToKotlin(converter, javaCode); + } + else if (parentFileName.equals("class")) { + actual = fileToKotlin(converter, javaCode); + } + else if (parentFileName.equals("file")) { + actual = fileToKotlin(converter, javaCode); + } + else if (parentFileName.equals("comp")) actual = fileToFileWithCompatibilityImport(javaCode); + + actual = StringUtil.convertLineSeparators(actual); + + assert !actual.isEmpty() : "Specify what is it: file, class, method, statement or expression: " + javaPath + " parent: " + parentFileName; + + final File tmp = new File(kotlinPath + ".tmp"); + if (!expected.equals(actual)) FileUtil.writeToFile(tmp, actual); + if (expected.equals(actual) && tmp.exists()) //noinspection ResultOfMethodCallIgnored + { + tmp.delete(); + } + + Assert.assertEquals(expected, actual); + } + + @NotNull + String getTestFilePath() { + return myDataPath + "/" + myName + ".jav"; + } + + + @NotNull + @Override + public String getName() { + return "test_" + myName; + } + + @NotNull + public static Test suite() { + TestSuite suite = new TestSuite(); +// suite.addTest(new StandaloneJavaToKotlinConverterTest("ast/class/file", "kt-639")); + suite.addTest(TestCaseBuilder.suiteForDirectory("tests/testData", "/ast", new TestCaseBuilder.NamedTestFactory() { + @NotNull + @Override + public Test createTest(@NotNull String dataPath, @NotNull String name) { + return new StandaloneJavaToKotlinConverterTest(dataPath, name); + } + })); + return suite; + } + + @NotNull + private static String fileToFileWithCompatibilityImport(@NotNull String text) { + return JavaToKotlinTranslator.generateKotlinCodeWithCompatibilityImport(text); + } + + @NotNull + private String fileToKotlin(Converter converter, @NotNull String text) { + return generateKotlinCode(converter, JavaToKotlinTranslator.createFile(myJavaCoreEnvironment, text)); + } + + @NotNull + private static String generateKotlinCode(@NotNull Converter converter, @Nullable PsiFile file) { + if (file != null && file instanceof PsiJavaFile) { + JavaToKotlinTranslator.setClassIdentifiers(converter, file); + return prettify(converter.elementToKotlin(file)); + } + return ""; + } + + @NotNull + private String methodToKotlin(Converter converter, String text) throws IOException { + String result = fileToKotlin(converter, "final class C {" + text + "}") + .replaceAll("class C\\(\\) \\{", ""); + result = result.substring(0, result.lastIndexOf("}")); + return prettify(result); + } + + @NotNull + private String statementToKotlin(Converter converter, String text) throws Exception { + String result = methodToKotlin(converter, "void main() {" + text + "}"); + int pos = result.lastIndexOf("}"); + result = result.substring(0, pos).replaceFirst("fun main\\(\\) : Unit \\{", ""); + return prettify(result); + } + + @NotNull + private String expressionToKotlin(Converter converter, String code) throws Exception { + String result = statementToKotlin(converter, "Object o =" + code + "}"); + result = result.replaceFirst("var o : Any\\? =", ""); + return prettify(result); + } + + @NotNull + private static String prettify(@Nullable String code) { + if (code == null) { + return ""; + } + return code + .trim() + .replaceAll("\r\n", "\n") + .replaceAll(" \n", "\n") + .replaceAll("\n ", "\n") + .replaceAll("\n+", "\n") + .replaceAll(" +", " ") + .trim() + ; + } +} diff --git a/tests/test/org/jetbrains/jet/j2k/TestCaseBuilder.java b/tests/test/org/jetbrains/jet/j2k/TestCaseBuilder.java index a184d149e55..dc0fa1f8891 100644 --- a/tests/test/org/jetbrains/jet/j2k/TestCaseBuilder.java +++ b/tests/test/org/jetbrains/jet/j2k/TestCaseBuilder.java @@ -1,110 +1,110 @@ -/* - * 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; - -import com.intellij.openapi.application.PathManager; -import junit.framework.Test; -import junit.framework.TestSuite; -import org.jetbrains.annotations.NotNull; - -import java.io.File; -import java.io.FileFilter; -import java.io.FilenameFilter; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -/** - * @author ignatov - */ -abstract class TestCaseBuilder { - @NotNull - private static final FilenameFilter emptyFilter = new FilenameFilter() { - @Override - public boolean accept(File file, String name) { - return true; - } - }; - - @NotNull - public static String getTestDataPathBase() { - return "testData"; - } - - public static String getHomeDirectory() { - return new File(PathManager.getResourceRoot(TestCaseBuilder.class, "/org/jetbrains/jet/TestCaseBuilder.class")).getParentFile().getParentFile().getParent(); - } - - public interface NamedTestFactory { - @NotNull - Test createTest(@NotNull String dataPath, @NotNull String name); - } - - @NotNull - public static TestSuite suiteForDirectory(String baseDataDir, @NotNull final String dataPath, @NotNull NamedTestFactory factory) { - return suiteForDirectory(baseDataDir, dataPath, true, emptyFilter, factory); - } - - @NotNull - private static TestSuite suiteForDirectory(String baseDataDir, @NotNull final String dataPath, boolean recursive, @NotNull final FilenameFilter filter, @NotNull NamedTestFactory factory) { - TestSuite suite = new TestSuite(dataPath); - final String extensionJava = ".jav"; - - final FilenameFilter extensionFilter = new FilenameFilter() { - @Override - public boolean accept(File dir, @NotNull String name) { - return name.endsWith(extensionJava); - } - }; - FilenameFilter resultFilter; - if (filter != emptyFilter) { - resultFilter = new FilenameFilter() { - @Override - public boolean accept(File file, String s) { - return extensionFilter.accept(file, s) && filter.accept(file, s); - } - }; - } - else { - resultFilter = extensionFilter; - } - File dir = new File(baseDataDir + dataPath); - FileFilter dirFilter = new FileFilter() { - @Override - public boolean accept(@NotNull File pathname) { - return pathname.isDirectory(); - } - }; - if (recursive) { - File[] files = dir.listFiles(dirFilter); - assert files != null : dir; - List subdirs = Arrays.asList(files); - Collections.sort(subdirs); - for (File subdir : subdirs) { - suite.addTest(suiteForDirectory(baseDataDir, dataPath + "/" + subdir.getName(), recursive, filter, factory)); - } - } - List files = Arrays.asList(dir.listFiles(resultFilter)); - Collections.sort(files); - for (File file : files) { - String fileName = file.getName(); - assert fileName != null; - suite.addTest(factory.createTest(dataPath, fileName.substring(0, fileName.length() - extensionJava.length()))); - } - return suite; - } -} +/* + * 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; + +import com.intellij.openapi.application.PathManager; +import junit.framework.Test; +import junit.framework.TestSuite; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.io.FileFilter; +import java.io.FilenameFilter; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * @author ignatov + */ +abstract class TestCaseBuilder { + @NotNull + private static final FilenameFilter emptyFilter = new FilenameFilter() { + @Override + public boolean accept(File file, String name) { + return true; + } + }; + + @NotNull + public static String getTestDataPathBase() { + return "testData"; + } + + public static String getHomeDirectory() { + return new File(PathManager.getResourceRoot(TestCaseBuilder.class, "/org/jetbrains/jet/TestCaseBuilder.class")).getParentFile().getParentFile().getParent(); + } + + public interface NamedTestFactory { + @NotNull + Test createTest(@NotNull String dataPath, @NotNull String name); + } + + @NotNull + public static TestSuite suiteForDirectory(String baseDataDir, @NotNull final String dataPath, @NotNull NamedTestFactory factory) { + return suiteForDirectory(baseDataDir, dataPath, true, emptyFilter, factory); + } + + @NotNull + private static TestSuite suiteForDirectory(String baseDataDir, @NotNull final String dataPath, boolean recursive, @NotNull final FilenameFilter filter, @NotNull NamedTestFactory factory) { + TestSuite suite = new TestSuite(dataPath); + final String extensionJava = ".jav"; + + final FilenameFilter extensionFilter = new FilenameFilter() { + @Override + public boolean accept(File dir, @NotNull String name) { + return name.endsWith(extensionJava); + } + }; + FilenameFilter resultFilter; + if (filter != emptyFilter) { + resultFilter = new FilenameFilter() { + @Override + public boolean accept(File file, String s) { + return extensionFilter.accept(file, s) && filter.accept(file, s); + } + }; + } + else { + resultFilter = extensionFilter; + } + File dir = new File(baseDataDir + dataPath); + FileFilter dirFilter = new FileFilter() { + @Override + public boolean accept(@NotNull File pathname) { + return pathname.isDirectory(); + } + }; + if (recursive) { + File[] files = dir.listFiles(dirFilter); + assert files != null : dir; + List subdirs = Arrays.asList(files); + Collections.sort(subdirs); + for (File subdir : subdirs) { + suite.addTest(suiteForDirectory(baseDataDir, dataPath + "/" + subdir.getName(), recursive, filter, factory)); + } + } + List files = Arrays.asList(dir.listFiles(resultFilter)); + Collections.sort(files); + for (File file : files) { + String fileName = file.getName(); + assert fileName != null; + suite.addTest(factory.createTest(dataPath, fileName.substring(0, fileName.length() - extensionJava.length()))); + } + return suite; + } +} diff --git a/tests/testData/ast/annotations/file/jetbrainsNotNull.jav b/tests/testData/ast/annotations/file/jetbrainsNotNull.jav index 152fdd7b545..92c511d88a0 100644 --- a/tests/testData/ast/annotations/file/jetbrainsNotNull.jav +++ b/tests/testData/ast/annotations/file/jetbrainsNotNull.jav @@ -1,29 +1,29 @@ -package test; - -import org.jetbrains.annotations.NotNull; - -public class Test { - @NotNull String myStr = "String2"; - - public Test(@NotNull String str) { - myStr = str; - } - - public void sout(@NotNull String str) { - System.out.println(str); - } - - @NotNull - public String dummy(@NotNull String str) { - return str; - } - - public void test() { - sout("String"); - @NotNull String test = "String2"; - sout(test); - sout(dummy(test)); - - new Test(test); - } +package test; + +import org.jetbrains.annotations.NotNull; + +public class Test { + @NotNull String myStr = "String2"; + + public Test(@NotNull String str) { + myStr = str; + } + + public void sout(@NotNull String str) { + System.out.println(str); + } + + @NotNull + public String dummy(@NotNull String str) { + return str; + } + + public void test() { + sout("String"); + @NotNull String test = "String2"; + sout(test); + sout(dummy(test)); + + new Test(test); + } } \ No newline at end of file diff --git a/tests/testData/ast/annotations/file/jetbrainsNotNull.kt b/tests/testData/ast/annotations/file/jetbrainsNotNull.kt index 2dd54ccb75c..376befca75c 100644 --- a/tests/testData/ast/annotations/file/jetbrainsNotNull.kt +++ b/tests/testData/ast/annotations/file/jetbrainsNotNull.kt @@ -1,20 +1,20 @@ -package test -public open class Test(str : String) { -var myStr : String? = "String2" -public open fun sout(str : String) : Unit { -System.out?.println(str) -} -public open fun dummy(str : String) : String { -return str -} -public open fun test() : Unit { -sout("String") -var test : String = "String2" -sout(test) -sout(dummy(test)) -Test(test) -} -{ -myStr = str -} +package test +public open class Test(str : String) { +var myStr : String? = "String2" +public open fun sout(str : String) : Unit { +System.out?.println(str) +} +public open fun dummy(str : String) : String { +return str +} +public open fun test() : Unit { +sout("String") +var test : String = "String2" +sout(test) +sout(dummy(test)) +Test(test) +} +{ +myStr = str +} } \ No newline at end of file diff --git a/tests/testData/ast/anonymousBlock/file/oneAnonBlock.kt b/tests/testData/ast/anonymousBlock/file/oneAnonBlock.kt index db7bd511f4e..bf84ae34578 100644 --- a/tests/testData/ast/anonymousBlock/file/oneAnonBlock.kt +++ b/tests/testData/ast/anonymousBlock/file/oneAnonBlock.kt @@ -1,6 +1,6 @@ -open class Test() { -var str : String? = null -{ -str = "Ola" -} +open class Test() { +var str : String? = null +{ +str = "Ola" +} } \ No newline at end of file diff --git a/tests/testData/ast/anonymousBlock/file/oneStaticAnonBlock.kt b/tests/testData/ast/anonymousBlock/file/oneStaticAnonBlock.kt index 667290b27c9..5c8649fbcf0 100644 --- a/tests/testData/ast/anonymousBlock/file/oneStaticAnonBlock.kt +++ b/tests/testData/ast/anonymousBlock/file/oneStaticAnonBlock.kt @@ -1,8 +1,8 @@ -open class Test() { -var str : String? = null -class object { -{ -str = "Ola" -} -} +open class Test() { +var str : String? = null +class object { +{ +str = "Ola" +} +} } \ No newline at end of file diff --git a/tests/testData/ast/arrayInitializerExpression/statement/doubleArrayWithVariables.kt b/tests/testData/ast/arrayInitializerExpression/statement/doubleArrayWithVariables.kt index ad8267238f2..2ccb8da60c1 100644 --- a/tests/testData/ast/arrayInitializerExpression/statement/doubleArrayWithVariables.kt +++ b/tests/testData/ast/arrayInitializerExpression/statement/doubleArrayWithVariables.kt @@ -1,4 +1,4 @@ -var a : Double = 0 -var b : Double = 0 -var c : Double = 0 +var a : Double = 0 +var b : Double = 0 +var c : Double = 0 var ds : DoubleArray? = doubleArray((a).toDouble(), (b).toDouble(), (c).toDouble()) \ No newline at end of file diff --git a/tests/testData/ast/arrayInitializerExpression/statement/oneDimWithVariables.kt b/tests/testData/ast/arrayInitializerExpression/statement/oneDimWithVariables.kt index 8b7378486d8..a1b91cfa3ab 100644 --- a/tests/testData/ast/arrayInitializerExpression/statement/oneDimWithVariables.kt +++ b/tests/testData/ast/arrayInitializerExpression/statement/oneDimWithVariables.kt @@ -1,4 +1,4 @@ -var a : Int = 0 -var b : Int = 0 -var c : Int = 0 +var a : Int = 0 +var b : Int = 0 +var c : Int = 0 var `is` : IntArray? = intArray(a, b, c) \ No newline at end of file diff --git a/tests/testData/ast/arrayType/method/methodArrayArgs.kt b/tests/testData/ast/arrayType/method/methodArrayArgs.kt index 01360f90482..b095e2dd099 100644 --- a/tests/testData/ast/arrayType/method/methodArrayArgs.kt +++ b/tests/testData/ast/arrayType/method/methodArrayArgs.kt @@ -1,2 +1,2 @@ -fun fromArrayToCollection(a : Array?) : Unit { +fun fromArrayToCollection(a : Array?) : Unit { } \ No newline at end of file diff --git a/tests/testData/ast/assignmentExpression/file/nullability.jav b/tests/testData/ast/assignmentExpression/file/nullability.jav index 717edaf0d51..dc7800cc26e 100644 --- a/tests/testData/ast/assignmentExpression/file/nullability.jav +++ b/tests/testData/ast/assignmentExpression/file/nullability.jav @@ -1,9 +1,9 @@ -import java.util.BitSet; - -class Foo { - void foo(BitSet o) { - BitSet o2 = o; - int foo = 0; - foo = o2.size(); - } -} +import java.util.BitSet; + +class Foo { + void foo(BitSet o) { + BitSet o2 = o; + int foo = 0; + foo = o2.size(); + } +} diff --git a/tests/testData/ast/assignmentExpression/file/nullability.kt b/tests/testData/ast/assignmentExpression/file/nullability.kt index fe43fd11797..f54e56b0b80 100644 --- a/tests/testData/ast/assignmentExpression/file/nullability.kt +++ b/tests/testData/ast/assignmentExpression/file/nullability.kt @@ -1,8 +1,8 @@ -import java.util.BitSet -open class Foo() { -open fun foo(o : BitSet?) : Unit { -var o2 : BitSet? = o -var foo : Int = 0 -foo = o2?.size()!! -} +import java.util.BitSet +open class Foo() { +open fun foo(o : BitSet?) : Unit { +var o2 : BitSet? = o +var foo : Int = 0 +foo = o2?.size()!! +} } \ No newline at end of file diff --git a/tests/testData/ast/boxedType/file/kt-671.kt b/tests/testData/ast/boxedType/file/kt-671.kt index 2e152c13152..11419363e4b 100644 --- a/tests/testData/ast/boxedType/file/kt-671.kt +++ b/tests/testData/ast/boxedType/file/kt-671.kt @@ -1,7 +1,7 @@ -package demo -open class Test() { -open fun test() : Unit { -var i : Int? = Integer.valueOf(100) -var s : Short? = Short.valueOf(100) -} +package demo +open class Test() { +open fun test() : Unit { +var i : Int? = Integer.valueOf(100) +var s : Short? = Short.valueOf(100) +} } \ No newline at end of file diff --git a/tests/testData/ast/callChainExpression/file/libraryFieldCall.kt b/tests/testData/ast/callChainExpression/file/libraryFieldCall.kt index 378eea1a63c..48516916f25 100644 --- a/tests/testData/ast/callChainExpression/file/libraryFieldCall.kt +++ b/tests/testData/ast/callChainExpression/file/libraryFieldCall.kt @@ -1,10 +1,10 @@ -open class Library() { -class object { -val ourOut : java.io.PrintStream? = null -} -} -open class User() { -open fun main() : Unit { -Library.ourOut?.print() -} +open class Library() { +class object { +val ourOut : java.io.PrintStream? = null +} +} +open class User() { +open fun main() : Unit { +Library.ourOut?.print() +} } \ No newline at end of file diff --git a/tests/testData/ast/callChainExpression/file/libraryMethodCall.kt b/tests/testData/ast/callChainExpression/file/libraryMethodCall.kt index 5aee1de5bf7..3c0ee4c68a4 100644 --- a/tests/testData/ast/callChainExpression/file/libraryMethodCall.kt +++ b/tests/testData/ast/callChainExpression/file/libraryMethodCall.kt @@ -1,15 +1,15 @@ -open class Library() { -class object { -open fun call() : Unit { -} -open fun getString() : String? { -return "" -} -} -} -open class User() { -open fun main() : Unit { -Library.call() -Library.getString()?.isEmpty() -} +open class Library() { +class object { +open fun call() : Unit { +} +open fun getString() : String? { +return "" +} +} +} +open class User() { +open fun main() : Unit { +Library.call() +Library.getString()?.isEmpty() +} } \ No newline at end of file diff --git a/tests/testData/ast/callChainExpression/file/libraryMethodCallFromInstance.kt b/tests/testData/ast/callChainExpression/file/libraryMethodCallFromInstance.kt index 74d51867f1a..b8a02f01152 100644 --- a/tests/testData/ast/callChainExpression/file/libraryMethodCallFromInstance.kt +++ b/tests/testData/ast/callChainExpression/file/libraryMethodCallFromInstance.kt @@ -1,16 +1,16 @@ -open class Library() { -open fun call() : Unit { -} -open fun getString() : String? { -return "" -} -} -open class User() { -open fun main() : Unit { -var lib : Library? = Library() -lib?.call() -lib?.getString()?.isEmpty() -Library().call() -Library().getString()?.isEmpty() -} +open class Library() { +open fun call() : Unit { +} +open fun getString() : String? { +return "" +} +} +open class User() { +open fun main() : Unit { +var lib : Library? = Library() +lib?.call() +lib?.getString()?.isEmpty() +Library().call() +Library().getString()?.isEmpty() +} } \ No newline at end of file diff --git a/tests/testData/ast/callChainExpression/file/libraryStringFieldCall.kt b/tests/testData/ast/callChainExpression/file/libraryStringFieldCall.kt index cb6a3f85868..9e0de14ec3c 100644 --- a/tests/testData/ast/callChainExpression/file/libraryStringFieldCall.kt +++ b/tests/testData/ast/callChainExpression/file/libraryStringFieldCall.kt @@ -1,8 +1,8 @@ -open class Library() { -public val myString : String? = null -} -open class User() { -open fun main() : Unit { -Library.myString?.isEmpty() -} +open class Library() { +public val myString : String? = null +} +open class User() { +open fun main() : Unit { +Library.myString?.isEmpty() +} } \ No newline at end of file diff --git a/tests/testData/ast/class/class/abstractClass.kt b/tests/testData/ast/class/class/abstractClass.kt index 316e303dd1e..e7fb293e5af 100644 --- a/tests/testData/ast/class/class/abstractClass.kt +++ b/tests/testData/ast/class/class/abstractClass.kt @@ -1,6 +1,6 @@ -abstract class A() { -abstract fun callme() : Unit -open fun callmetoo() : Unit { -print("This is a concrete method.") -} +abstract class A() { +abstract fun callme() : Unit +open fun callmetoo() : Unit { +print("This is a concrete method.") +} } \ No newline at end of file diff --git a/tests/testData/ast/class/class/abstractClassShape.kt b/tests/testData/ast/class/class/abstractClassShape.kt index 99ff0d782d2..8525a28f1b8 100644 --- a/tests/testData/ast/class/class/abstractClassShape.kt +++ b/tests/testData/ast/class/class/abstractClassShape.kt @@ -1,10 +1,10 @@ -abstract class Shape() { -public var color : String? = null -public open fun setColor(c : String?) : Unit { -color = c -} -public open fun getColor() : String? { -return color -} -public abstract fun area() : Double +abstract class Shape() { +public var color : String? = null +public open fun setColor(c : String?) : Unit { +color = c +} +public open fun getColor() : String? { +return color +} +public abstract fun area() : Double } \ No newline at end of file diff --git a/tests/testData/ast/class/class/class.kt b/tests/testData/ast/class/class/class.kt index 12074d8ca63..bc29d4b27a1 100644 --- a/tests/testData/ast/class/class/class.kt +++ b/tests/testData/ast/class/class/class.kt @@ -1,2 +1,2 @@ -open class Test() { +open class Test() { } \ No newline at end of file diff --git a/tests/testData/ast/class/class/classWithEmptyMethods.kt b/tests/testData/ast/class/class/classWithEmptyMethods.kt index 8d93d9edbee..18ced74776d 100644 --- a/tests/testData/ast/class/class/classWithEmptyMethods.kt +++ b/tests/testData/ast/class/class/classWithEmptyMethods.kt @@ -1,8 +1,8 @@ -class T() { -fun main() : Unit { -} -fun i() : Int { -} -fun s() : String? { -} +class T() { +fun main() : Unit { +} +fun i() : Int { +} +fun s() : String? { +} } \ No newline at end of file diff --git a/tests/testData/ast/class/class/classWithFields.kt b/tests/testData/ast/class/class/classWithFields.kt index bc30d1369fb..defec3e4ac3 100644 --- a/tests/testData/ast/class/class/classWithFields.kt +++ b/tests/testData/ast/class/class/classWithFields.kt @@ -1,4 +1,4 @@ -class T() { -var a : String? = "abc" -var b : Int = 10 +class T() { +var a : String? = "abc" +var b : Int = 10 } \ No newline at end of file diff --git a/tests/testData/ast/class/class/classWithMultiplyFields.kt b/tests/testData/ast/class/class/classWithMultiplyFields.kt index f5c6b484de9..7f77e2e0cbd 100644 --- a/tests/testData/ast/class/class/classWithMultiplyFields.kt +++ b/tests/testData/ast/class/class/classWithMultiplyFields.kt @@ -1,5 +1,5 @@ -class T() { -var a : String? = null -var b : String? = null -var c : String? = "abc" +class T() { +var a : String? = null +var b : String? = null +var c : String? = "abc" } \ No newline at end of file diff --git a/tests/testData/ast/class/class/emptyClass.kt b/tests/testData/ast/class/class/emptyClass.kt index aa34bb7310a..161cb193d08 100644 --- a/tests/testData/ast/class/class/emptyClass.kt +++ b/tests/testData/ast/class/class/emptyClass.kt @@ -1,2 +1,2 @@ -class A() { +class A() { } \ No newline at end of file diff --git a/tests/testData/ast/class/class/extendsOneClassAndImplementsOneInterface.kt b/tests/testData/ast/class/class/extendsOneClassAndImplementsOneInterface.kt index 116ab42039f..7206c054962 100644 --- a/tests/testData/ast/class/class/extendsOneClassAndImplementsOneInterface.kt +++ b/tests/testData/ast/class/class/extendsOneClassAndImplementsOneInterface.kt @@ -1,2 +1,2 @@ -class A() : Base(), I { +class A() : Base(), I { } \ No newline at end of file diff --git a/tests/testData/ast/class/class/extendsOneClassAndImplementsSeveralInterfaces.kt b/tests/testData/ast/class/class/extendsOneClassAndImplementsSeveralInterfaces.kt index 33d88bf434b..7812e054bda 100644 --- a/tests/testData/ast/class/class/extendsOneClassAndImplementsSeveralInterfaces.kt +++ b/tests/testData/ast/class/class/extendsOneClassAndImplementsSeveralInterfaces.kt @@ -1,2 +1,2 @@ -class A() : Base(), I0, I1, I2 { +class A() : Base(), I0, I1, I2 { } \ No newline at end of file diff --git a/tests/testData/ast/class/class/finalClass.kt b/tests/testData/ast/class/class/finalClass.kt index e11f4f0f7dc..98c16b37053 100644 --- a/tests/testData/ast/class/class/finalClass.kt +++ b/tests/testData/ast/class/class/finalClass.kt @@ -1,2 +1,2 @@ -class Test() { +class Test() { } \ No newline at end of file diff --git a/tests/testData/ast/class/class/genericClass.kt b/tests/testData/ast/class/class/genericClass.kt index 72cf1720284..f3565e5ec30 100644 --- a/tests/testData/ast/class/class/genericClass.kt +++ b/tests/testData/ast/class/class/genericClass.kt @@ -1,2 +1,2 @@ -class Entry() { +class Entry() { } \ No newline at end of file diff --git a/tests/testData/ast/class/class/innerEmptyClass.kt b/tests/testData/ast/class/class/innerEmptyClass.kt index 1ead720d6e0..983e65e757e 100644 --- a/tests/testData/ast/class/class/innerEmptyClass.kt +++ b/tests/testData/ast/class/class/innerEmptyClass.kt @@ -1,4 +1,4 @@ -class A() { -class B() { -} +class A() { +class B() { +} } \ No newline at end of file diff --git a/tests/testData/ast/class/class/innerStaticClass.kt b/tests/testData/ast/class/class/innerStaticClass.kt index 7749f9ee5be..dc0ae41dff2 100644 --- a/tests/testData/ast/class/class/innerStaticClass.kt +++ b/tests/testData/ast/class/class/innerStaticClass.kt @@ -1,6 +1,6 @@ -class S() { -class object { -open class Inner() { -} -} +class S() { +class object { +open class Inner() { +} +} } \ No newline at end of file diff --git a/tests/testData/ast/class/class/internalClass.kt b/tests/testData/ast/class/class/internalClass.kt index 12074d8ca63..bc29d4b27a1 100644 --- a/tests/testData/ast/class/class/internalClass.kt +++ b/tests/testData/ast/class/class/internalClass.kt @@ -1,2 +1,2 @@ -open class Test() { +open class Test() { } \ No newline at end of file diff --git a/tests/testData/ast/class/class/oneStaticFieldOneNonStatic.kt b/tests/testData/ast/class/class/oneStaticFieldOneNonStatic.kt index 2862633ce5f..7be6598f76a 100644 --- a/tests/testData/ast/class/class/oneStaticFieldOneNonStatic.kt +++ b/tests/testData/ast/class/class/oneStaticFieldOneNonStatic.kt @@ -1,8 +1,8 @@ -class S() { -fun sB() : Boolean { -return true -} -class object { -var myI : Int = 10 -} +class S() { +fun sB() : Boolean { +return true +} +class object { +var myI : Int = 10 +} } \ No newline at end of file diff --git a/tests/testData/ast/class/class/oneStaticMethod.kt b/tests/testData/ast/class/class/oneStaticMethod.kt index 8a46f08d3df..beb564521e3 100644 --- a/tests/testData/ast/class/class/oneStaticMethod.kt +++ b/tests/testData/ast/class/class/oneStaticMethod.kt @@ -1,7 +1,7 @@ -class S() { -class object { -fun staticF() : Boolean { -return true -} -} +class S() { +class object { +fun staticF() : Boolean { +return true +} +} } \ No newline at end of file diff --git a/tests/testData/ast/class/class/oneStaticMethodOneNonStatic.kt b/tests/testData/ast/class/class/oneStaticMethodOneNonStatic.kt index ae38a2df074..cb96091ed53 100644 --- a/tests/testData/ast/class/class/oneStaticMethodOneNonStatic.kt +++ b/tests/testData/ast/class/class/oneStaticMethodOneNonStatic.kt @@ -1,10 +1,10 @@ -class S() { -fun sB() : Boolean { -return true -} -class object { -fun sI() : Int { -return 1 -} -} +class S() { +fun sB() : Boolean { +return true +} +class object { +fun sI() : Int { +return 1 +} +} } \ No newline at end of file diff --git a/tests/testData/ast/class/class/pivateClass.kt b/tests/testData/ast/class/class/pivateClass.kt index 59b49aed430..96001c69f28 100644 --- a/tests/testData/ast/class/class/pivateClass.kt +++ b/tests/testData/ast/class/class/pivateClass.kt @@ -1,2 +1,2 @@ -private open class Test() { +private open class Test() { } \ No newline at end of file diff --git a/tests/testData/ast/class/class/protectedClass.kt b/tests/testData/ast/class/class/protectedClass.kt index bedde57bda8..e82caa26cd0 100644 --- a/tests/testData/ast/class/class/protectedClass.kt +++ b/tests/testData/ast/class/class/protectedClass.kt @@ -1,2 +1,2 @@ -protected open class Test() { +protected open class Test() { } \ No newline at end of file diff --git a/tests/testData/ast/class/class/publicClass.kt b/tests/testData/ast/class/class/publicClass.kt index 89eb3715737..98e32f1aca0 100644 --- a/tests/testData/ast/class/class/publicClass.kt +++ b/tests/testData/ast/class/class/publicClass.kt @@ -1,2 +1,2 @@ -public open class Test() { +public open class Test() { } \ No newline at end of file diff --git a/tests/testData/ast/class/class/simpleInheritance.kt b/tests/testData/ast/class/class/simpleInheritance.kt index 7d43469a9e0..7bf6ef80f75 100644 --- a/tests/testData/ast/class/class/simpleInheritance.kt +++ b/tests/testData/ast/class/class/simpleInheritance.kt @@ -1,2 +1,2 @@ -class A() : Base() { +class A() : Base() { } \ No newline at end of file diff --git a/tests/testData/ast/class/class/twoStaticMethod.kt b/tests/testData/ast/class/class/twoStaticMethod.kt index 58f12c41e16..87bd397e519 100644 --- a/tests/testData/ast/class/class/twoStaticMethod.kt +++ b/tests/testData/ast/class/class/twoStaticMethod.kt @@ -1,10 +1,10 @@ -class S() { -class object { -fun sB() : Boolean { -return true -} -fun sI() : Int { -return 1 -} -} +class S() { +class object { +fun sB() : Boolean { +return true +} +fun sI() : Int { +return 1 +} +} } \ No newline at end of file diff --git a/tests/testData/ast/class/file/kt-639.kt b/tests/testData/ast/class/file/kt-639.kt index ab80d9cfefd..fe438a103ec 100644 --- a/tests/testData/ast/class/file/kt-639.kt +++ b/tests/testData/ast/class/file/kt-639.kt @@ -1,22 +1,22 @@ -package demo -import java.util.HashMap -open class Test() { -class object { -open fun init() : Test { -val __ = Test() -return __ -} -open fun init(s : String?) : Test { -val __ = Test() -return __ -} -} -} -open class User() { -open fun main() : Unit { -var m : HashMap? = HashMap(1) -var m2 : HashMap? = HashMap(10) -var t1 : Test? = Test.init() -var t2 : Test? = Test.init("") -} +package demo +import java.util.HashMap +open class Test() { +class object { +open fun init() : Test { +val __ = Test() +return __ +} +open fun init(s : String?) : Test { +val __ = Test() +return __ +} +} +} +open class User() { +open fun main() : Unit { +var m : HashMap? = HashMap(1) +var m2 : HashMap? = HashMap(10) +var t1 : Test? = Test.init() +var t2 : Test? = Test.init("") +} } \ No newline at end of file diff --git a/tests/testData/ast/class/file/privateInit.kt b/tests/testData/ast/class/file/privateInit.kt index 2ff24ba52fc..4f86265d153 100644 --- a/tests/testData/ast/class/file/privateInit.kt +++ b/tests/testData/ast/class/file/privateInit.kt @@ -1,4 +1,4 @@ -public open class MyClass() { -private fun init(arg1 : Int, arg2 : Int, arg3 : Int) : Unit { -} +public open class MyClass() { +private fun init(arg1 : Int, arg2 : Int, arg3 : Int) : Unit { +} } \ No newline at end of file diff --git a/tests/testData/ast/conditionalExpression/expression/simpleConditionalExpression.kt b/tests/testData/ast/conditionalExpression/expression/simpleConditionalExpression.kt index a29106ae10b..85131998260 100644 --- a/tests/testData/ast/conditionalExpression/expression/simpleConditionalExpression.kt +++ b/tests/testData/ast/conditionalExpression/expression/simpleConditionalExpression.kt @@ -1,4 +1,4 @@ -(if (a.isEmpty()) -0 -else +(if (a.isEmpty()) +0 +else 1) \ No newline at end of file diff --git a/tests/testData/ast/constructors/file/allCallsPrimary.kt b/tests/testData/ast/constructors/file/allCallsPrimary.kt index 4f4c919d74e..38a7eb1ddee 100644 --- a/tests/testData/ast/constructors/file/allCallsPrimary.kt +++ b/tests/testData/ast/constructors/file/allCallsPrimary.kt @@ -1,21 +1,21 @@ -open class C(arg1 : Int, arg2 : Int, arg3 : Int) { -class object { -open fun init(arg1 : Int, arg2 : Int) : C { -val __ = C(arg1, arg2, 0) -return __ -} -open fun init(arg1 : Int) : C { -val __ = C(arg1, 0, 0) -return __ -} -} -} -public open class User() { -class object { -public open fun main() : Unit { -var c1 : C? = C(100, 100, 100) -var c2 : C? = C.init(100, 100) -var c3 : C? = C.init(100) -} -} +open class C(arg1 : Int, arg2 : Int, arg3 : Int) { +class object { +open fun init(arg1 : Int, arg2 : Int) : C { +val __ = C(arg1, arg2, 0) +return __ +} +open fun init(arg1 : Int) : C { +val __ = C(arg1, 0, 0) +return __ +} +} +} +public open class User() { +class object { +public open fun main() : Unit { +var c1 : C? = C(100, 100, 100) +var c2 : C? = C.init(100, 100) +var c3 : C? = C.init(100) +} +} } \ No newline at end of file diff --git a/tests/testData/ast/constructors/file/allCallsPrimary2.kt b/tests/testData/ast/constructors/file/allCallsPrimary2.kt index 187238d0ca0..e6f383fa362 100644 --- a/tests/testData/ast/constructors/file/allCallsPrimary2.kt +++ b/tests/testData/ast/constructors/file/allCallsPrimary2.kt @@ -1,33 +1,33 @@ -open class C(arg1 : Int) { -val myArg1 : Int -var myArg2 : Int = 0 -var myArg3 : Int = 0 -{ -myArg1 = arg1 -myArg2 = 0 -myArg3 = 0 -} -class object { -open fun init(arg1 : Int, arg2 : Int, arg3 : Int) : C { -val __ = C(arg1) -__.myArg2 = arg2 -__.myArg3 = arg3 -return __ -} -open fun init(arg1 : Int, arg2 : Int) : C { -val __ = C(arg1) -__.myArg2 = arg2 -__.myArg3 = 0 -return __ -} -} -} -public open class User() { -class object { -public open fun main() : Unit { -var c1 : C? = C.init(100, 100, 100) -var c2 : C? = C.init(100, 100) -var c3 : C? = C(100) -} -} +open class C(arg1 : Int) { +val myArg1 : Int +var myArg2 : Int = 0 +var myArg3 : Int = 0 +{ +myArg1 = arg1 +myArg2 = 0 +myArg3 = 0 +} +class object { +open fun init(arg1 : Int, arg2 : Int, arg3 : Int) : C { +val __ = C(arg1) +__.myArg2 = arg2 +__.myArg3 = arg3 +return __ +} +open fun init(arg1 : Int, arg2 : Int) : C { +val __ = C(arg1) +__.myArg2 = arg2 +__.myArg3 = 0 +return __ +} +} +} +public open class User() { +class object { +public open fun main() : Unit { +var c1 : C? = C.init(100, 100, 100) +var c2 : C? = C.init(100, 100) +var c3 : C? = C(100) +} +} } \ No newline at end of file diff --git a/tests/testData/ast/constructors/file/customerBuilder.kt b/tests/testData/ast/constructors/file/customerBuilder.kt index 9ecdf8bf345..b2573d9b469 100644 --- a/tests/testData/ast/constructors/file/customerBuilder.kt +++ b/tests/testData/ast/constructors/file/customerBuilder.kt @@ -1,45 +1,45 @@ -package org.test.customer -open class Customer(first : String?, last : String?) { -public val _firstName : String? -public val _lastName : String? -public open fun getFirstName() : String? { -return _firstName -} -public open fun getLastName() : String? { -return _lastName -} -private fun doSmthBefore() : Unit { -} -private fun doSmthAfter() : Unit { -} -{ -doSmthBefore() -_firstName = first -_lastName = last -doSmthAfter() -} -} -open class CustomerBuilder() { -public var _firstName : String? = "Homer" -public var _lastName : String? = "Simpson" -public open fun WithFirstName(firstName : String?) : CustomerBuilder? { -_firstName = firstName -return this -} -public open fun WithLastName(lastName : String?) : CustomerBuilder? { -_lastName = lastName -return this -} -public open fun Build() : Customer? { -return Customer(_firstName, _lastName) -} -} -public open class User() { -class object { -public open fun main() : Unit { -var customer : Customer? = CustomerBuilder().WithFirstName("Homer")?.WithLastName("Simpson")?.Build() -System.out?.println(customer?.getFirstName()) -System.out?.println(customer?.getLastName()) -} -} +package org.test.customer +open class Customer(first : String?, last : String?) { +public val _firstName : String? +public val _lastName : String? +public open fun getFirstName() : String? { +return _firstName +} +public open fun getLastName() : String? { +return _lastName +} +private fun doSmthBefore() : Unit { +} +private fun doSmthAfter() : Unit { +} +{ +doSmthBefore() +_firstName = first +_lastName = last +doSmthAfter() +} +} +open class CustomerBuilder() { +public var _firstName : String? = "Homer" +public var _lastName : String? = "Simpson" +public open fun WithFirstName(firstName : String?) : CustomerBuilder? { +_firstName = firstName +return this +} +public open fun WithLastName(lastName : String?) : CustomerBuilder? { +_lastName = lastName +return this +} +public open fun Build() : Customer? { +return Customer(_firstName, _lastName) +} +} +public open class User() { +class object { +public open fun main() : Unit { +var customer : Customer? = CustomerBuilder().WithFirstName("Homer")?.WithLastName("Simpson")?.Build() +System.out?.println(customer?.getFirstName()) +System.out?.println(customer?.getLastName()) +} +} } \ No newline at end of file diff --git a/tests/testData/ast/constructors/file/genericIdentifier.kt b/tests/testData/ast/constructors/file/genericIdentifier.kt index 9b26b23022d..d049a45adce 100644 --- a/tests/testData/ast/constructors/file/genericIdentifier.kt +++ b/tests/testData/ast/constructors/file/genericIdentifier.kt @@ -1,37 +1,37 @@ -public open class Identifier(_myName : T?, _myHasDollar : Boolean) { -private val myName : T? = null -private var myHasDollar : Boolean = false -private var myNullable : Boolean = true -public open fun getName() : T? { -return myName -} -{ -myName = _myName -myHasDollar = _myHasDollar -} -class object { -public open fun init(name : T?) : Identifier { -val __ = Identifier(name, false) -return __ -} -public open fun init(name : T?, isNullable : Boolean) : Identifier { -val __ = Identifier(name, false) -__.myNullable = isNullable -return __ -} -public open fun init(name : T?, hasDollar : Boolean, isNullable : Boolean) : Identifier { -val __ = Identifier(name, hasDollar) -__.myNullable = isNullable -return __ -} -} -} -public open class User() { -class object { -public open fun main() : Unit { -var i1 : Identifier<*>? = Identifier.init("name", false, true) -var i2 : Identifier? = Identifier.init("name", false) -var i3 : Identifier? = Identifier.init("name") -} -} +public open class Identifier(_myName : T?, _myHasDollar : Boolean) { +private val myName : T? = null +private var myHasDollar : Boolean = false +private var myNullable : Boolean = true +public open fun getName() : T? { +return myName +} +{ +myName = _myName +myHasDollar = _myHasDollar +} +class object { +public open fun init(name : T?) : Identifier { +val __ = Identifier(name, false) +return __ +} +public open fun init(name : T?, isNullable : Boolean) : Identifier { +val __ = Identifier(name, false) +__.myNullable = isNullable +return __ +} +public open fun init(name : T?, hasDollar : Boolean, isNullable : Boolean) : Identifier { +val __ = Identifier(name, hasDollar) +__.myNullable = isNullable +return __ +} +} +} +public open class User() { +class object { +public open fun main() : Unit { +var i1 : Identifier<*>? = Identifier.init("name", false, true) +var i2 : Identifier? = Identifier.init("name", false) +var i3 : Identifier? = Identifier.init("name") +} +} } \ No newline at end of file diff --git a/tests/testData/ast/constructors/file/identifier.kt b/tests/testData/ast/constructors/file/identifier.kt index 906e1bc0acd..3ede387654c 100644 --- a/tests/testData/ast/constructors/file/identifier.kt +++ b/tests/testData/ast/constructors/file/identifier.kt @@ -1,37 +1,37 @@ -public open class Identifier(_myName : String?, _myHasDollar : Boolean) { -private val myName : String? = null -private var myHasDollar : Boolean = false -private var myNullable : Boolean = true -public open fun getName() : String? { -return myName -} -{ -myName = _myName -myHasDollar = _myHasDollar -} -class object { -public open fun init(name : String?) : Identifier { -val __ = Identifier(name, false) -return __ -} -public open fun init(name : String?, isNullable : Boolean) : Identifier { -val __ = Identifier(name, false) -__.myNullable = isNullable -return __ -} -public open fun init(name : String?, hasDollar : Boolean, isNullable : Boolean) : Identifier { -val __ = Identifier(name, hasDollar) -__.myNullable = isNullable -return __ -} -} -} -public open class User() { -class object { -public open fun main() : Unit { -var i1 : Identifier? = Identifier.init("name", false, true) -var i2 : Identifier? = Identifier.init("name", false) -var i3 : Identifier? = Identifier.init("name") -} -} +public open class Identifier(_myName : String?, _myHasDollar : Boolean) { +private val myName : String? = null +private var myHasDollar : Boolean = false +private var myNullable : Boolean = true +public open fun getName() : String? { +return myName +} +{ +myName = _myName +myHasDollar = _myHasDollar +} +class object { +public open fun init(name : String?) : Identifier { +val __ = Identifier(name, false) +return __ +} +public open fun init(name : String?, isNullable : Boolean) : Identifier { +val __ = Identifier(name, false) +__.myNullable = isNullable +return __ +} +public open fun init(name : String?, hasDollar : Boolean, isNullable : Boolean) : Identifier { +val __ = Identifier(name, hasDollar) +__.myNullable = isNullable +return __ +} +} +} +public open class User() { +class object { +public open fun main() : Unit { +var i1 : Identifier? = Identifier.init("name", false, true) +var i2 : Identifier? = Identifier.init("name", false) +var i3 : Identifier? = Identifier.init("name") +} +} } \ No newline at end of file diff --git a/tests/testData/ast/constructors/file/withManyDefaultParams.kt b/tests/testData/ast/constructors/file/withManyDefaultParams.kt index ca261d80a42..434c34a10b2 100644 --- a/tests/testData/ast/constructors/file/withManyDefaultParams.kt +++ b/tests/testData/ast/constructors/file/withManyDefaultParams.kt @@ -1,40 +1,40 @@ -public open class Test(_myName : String?, _a : Boolean, _b : Double, _c : Float, _d : Long, _e : Int, _f : Short, _g : Char) { -private val myName : String? -private var a : Boolean = false -private var b : Double = 0.toDouble() -private var c : Float = 0.toFloat() -private var d : Long = 0 -private var e : Int = 0 -private var f : Short = 0 -private var g : Char = ' ' -{ -myName = _myName -a = _a -b = _b -c = _c -d = _d -e = _e -f = _f -g = _g -} -class object { -public open fun init() : Test { -val __ = Test(null, false, 0.toDouble(), 0.toFloat(), 0, 0, 0, ' ') -return __ -} -public open fun init(name : String?) : Test { -val __ = Test(foo(name), false, 0.toDouble(), 0.toFloat(), 0, 0, 0, ' ') -return __ -} -open fun foo(n : String?) : String? { -return "" -} -} -} -public open class User() { -class object { -public open fun main() : Unit { -var t : Test? = Test.init("name") -} -} +public open class Test(_myName : String?, _a : Boolean, _b : Double, _c : Float, _d : Long, _e : Int, _f : Short, _g : Char) { +private val myName : String? +private var a : Boolean = false +private var b : Double = 0.toDouble() +private var c : Float = 0.toFloat() +private var d : Long = 0 +private var e : Int = 0 +private var f : Short = 0 +private var g : Char = ' ' +{ +myName = _myName +a = _a +b = _b +c = _c +d = _d +e = _e +f = _f +g = _g +} +class object { +public open fun init() : Test { +val __ = Test(null, false, 0.toDouble(), 0.toFloat(), 0, 0, 0, ' ') +return __ +} +public open fun init(name : String?) : Test { +val __ = Test(foo(name), false, 0.toDouble(), 0.toFloat(), 0, 0, 0, ' ') +return __ +} +open fun foo(n : String?) : String? { +return "" +} +} +} +public open class User() { +class object { +public open fun main() : Unit { +var t : Test? = Test.init("name") +} +} } \ No newline at end of file diff --git a/tests/testData/ast/declarationStatement/statement/multiplyFinalIntDeclaration.kt b/tests/testData/ast/declarationStatement/statement/multiplyFinalIntDeclaration.kt index 31534f1744c..08a84179833 100644 --- a/tests/testData/ast/declarationStatement/statement/multiplyFinalIntDeclaration.kt +++ b/tests/testData/ast/declarationStatement/statement/multiplyFinalIntDeclaration.kt @@ -1,3 +1,3 @@ -val k : Int -val l : Int +val k : Int +val l : Int val m : Int \ No newline at end of file diff --git a/tests/testData/ast/declarationStatement/statement/multiplyIntDeclaration.kt b/tests/testData/ast/declarationStatement/statement/multiplyIntDeclaration.kt index 573f5bf7bb1..357bb10b11e 100644 --- a/tests/testData/ast/declarationStatement/statement/multiplyIntDeclaration.kt +++ b/tests/testData/ast/declarationStatement/statement/multiplyIntDeclaration.kt @@ -1,3 +1,3 @@ -var k : Int -var l : Int +var k : Int +var l : Int var m : Int \ No newline at end of file diff --git a/tests/testData/ast/doWhileStatement/statement/whileWithBlock.kt b/tests/testData/ast/doWhileStatement/statement/whileWithBlock.kt index 56e9500dc79..d86f9999196 100644 --- a/tests/testData/ast/doWhileStatement/statement/whileWithBlock.kt +++ b/tests/testData/ast/doWhileStatement/statement/whileWithBlock.kt @@ -1,6 +1,6 @@ -do -{ -var i : Int = 1 -i = i + 1 -} +do +{ +var i : Int = 1 +i = i + 1 +} while (a > b) \ No newline at end of file diff --git a/tests/testData/ast/doWhileStatement/statement/whileWithEmptyBlock.kt b/tests/testData/ast/doWhileStatement/statement/whileWithEmptyBlock.kt index ab26ce3b053..7018b864e5e 100644 --- a/tests/testData/ast/doWhileStatement/statement/whileWithEmptyBlock.kt +++ b/tests/testData/ast/doWhileStatement/statement/whileWithEmptyBlock.kt @@ -1,4 +1,4 @@ -do -{ -} +do +{ +} while (true) \ No newline at end of file diff --git a/tests/testData/ast/doWhileStatement/statement/whileWithExpression.kt b/tests/testData/ast/doWhileStatement/statement/whileWithExpression.kt index 9ca3d8863a0..a20c7c5d83d 100644 --- a/tests/testData/ast/doWhileStatement/statement/whileWithExpression.kt +++ b/tests/testData/ast/doWhileStatement/statement/whileWithExpression.kt @@ -1,3 +1,3 @@ -do -i = i + 1 +do +i = i + 1 while (true) \ No newline at end of file diff --git a/tests/testData/ast/doWhileStatement/statement/whileWithReturn.kt b/tests/testData/ast/doWhileStatement/statement/whileWithReturn.kt index 89f8a80610c..21de9dff87a 100644 --- a/tests/testData/ast/doWhileStatement/statement/whileWithReturn.kt +++ b/tests/testData/ast/doWhileStatement/statement/whileWithReturn.kt @@ -1,3 +1,3 @@ -do -return 1 +do +return 1 while (true) \ No newline at end of file diff --git a/tests/testData/ast/enum/class/colorEnum.kt b/tests/testData/ast/enum/class/colorEnum.kt index d346ce8c70d..3f4198497a5 100644 --- a/tests/testData/ast/enum/class/colorEnum.kt +++ b/tests/testData/ast/enum/class/colorEnum.kt @@ -1,14 +1,14 @@ -package demo -enum class MyEnum(_color : Int) { -RED : MyEnum(10) -BLUE : MyEnum(20) -private val color : Int -public fun getColor() : Int { -return color -} -{ -color = _color -} -public fun name() : String { return "" } -public fun order() : Int { return 0 } +package demo +enum class MyEnum(_color : Int) { +RED : MyEnum(10) +BLUE : MyEnum(20) +private val color : Int +public fun getColor() : Int { +return color +} +{ +color = _color +} +public fun name() : String { return "" } +public fun order() : Int { return 0 } } \ No newline at end of file diff --git a/tests/testData/ast/enum/class/emptyEnum.kt b/tests/testData/ast/enum/class/emptyEnum.kt index 99bbbb0917f..5be09b23308 100644 --- a/tests/testData/ast/enum/class/emptyEnum.kt +++ b/tests/testData/ast/enum/class/emptyEnum.kt @@ -1,4 +1,4 @@ -enum class A { -public fun name() : String { return "" } -public fun order() : Int { return 0 } +enum class A { +public fun name() : String { return "" } +public fun order() : Int { return 0 } } \ No newline at end of file diff --git a/tests/testData/ast/enum/class/enumImplementsOneInterface.kt b/tests/testData/ast/enum/class/enumImplementsOneInterface.kt index 89b0d80fcd1..28b251cbf82 100644 --- a/tests/testData/ast/enum/class/enumImplementsOneInterface.kt +++ b/tests/testData/ast/enum/class/enumImplementsOneInterface.kt @@ -1,4 +1,4 @@ -enum class A : I { -public fun name() : String { return "" } -public fun order() : Int { return 0 } +enum class A : I { +public fun name() : String { return "" } +public fun order() : Int { return 0 } } \ No newline at end of file diff --git a/tests/testData/ast/enum/class/enumImplementsSeveralInterfaces.kt b/tests/testData/ast/enum/class/enumImplementsSeveralInterfaces.kt index c0d3ac08963..0ac77787c77 100644 --- a/tests/testData/ast/enum/class/enumImplementsSeveralInterfaces.kt +++ b/tests/testData/ast/enum/class/enumImplementsSeveralInterfaces.kt @@ -1,4 +1,4 @@ -enum class A : I0, I1, I2 { -public fun name() : String { return "" } -public fun order() : Int { return 0 } +enum class A : I0, I1, I2 { +public fun name() : String { return "" } +public fun order() : Int { return 0 } } \ No newline at end of file diff --git a/tests/testData/ast/enum/class/enumWithNameField.kt b/tests/testData/ast/enum/class/enumWithNameField.kt index b817dbec220..e92d13cb8ce 100644 --- a/tests/testData/ast/enum/class/enumWithNameField.kt +++ b/tests/testData/ast/enum/class/enumWithNameField.kt @@ -1,6 +1,6 @@ -enum class E { -I -private var name : String? = null -public fun name() : String { return "" } -public fun order() : Int { return 0 } +enum class E { +I +private var name : String? = null +public fun name() : String { return "" } +public fun order() : Int { return 0 } } \ No newline at end of file diff --git a/tests/testData/ast/enum/class/fieldsWithPrimaryPrivateConstructor.kt b/tests/testData/ast/enum/class/fieldsWithPrimaryPrivateConstructor.kt index d7474d3ff80..fa05a558601 100644 --- a/tests/testData/ast/enum/class/fieldsWithPrimaryPrivateConstructor.kt +++ b/tests/testData/ast/enum/class/fieldsWithPrimaryPrivateConstructor.kt @@ -1,16 +1,16 @@ -enum class Color(c : Int) { -WHITE : Color(21) -BLACK : Color(22) -RED : Color(23) -YELLOW : Color(24) -BLUE : Color(25) -private var code : Int = 0 -public fun getCode() : Int { -return code -} -{ -code = c -} -public fun name() : String { return "" } -public fun order() : Int { return 0 } +enum class Color(c : Int) { +WHITE : Color(21) +BLACK : Color(22) +RED : Color(23) +YELLOW : Color(24) +BLUE : Color(25) +private var code : Int = 0 +public fun getCode() : Int { +return code +} +{ +code = c +} +public fun name() : String { return "" } +public fun order() : Int { return 0 } } \ No newline at end of file diff --git a/tests/testData/ast/enum/class/internalEnum.kt b/tests/testData/ast/enum/class/internalEnum.kt index d1aa8f75084..baaffdb5561 100644 --- a/tests/testData/ast/enum/class/internalEnum.kt +++ b/tests/testData/ast/enum/class/internalEnum.kt @@ -1,4 +1,4 @@ -enum class Test { -public fun name() : String { return "" } -public fun order() : Int { return 0 } +enum class Test { +public fun name() : String { return "" } +public fun order() : Int { return 0 } } \ No newline at end of file diff --git a/tests/testData/ast/enum/class/overrideToString.kt b/tests/testData/ast/enum/class/overrideToString.kt index 59c036f47f4..7faa11f73ec 100644 --- a/tests/testData/ast/enum/class/overrideToString.kt +++ b/tests/testData/ast/enum/class/overrideToString.kt @@ -1,12 +1,12 @@ -enum class Color { -WHITE -BLACK -RED -YELLOW -BLUE -override fun toString() : String? { -return "COLOR" -} -public fun name() : String { return "" } -public fun order() : Int { return 0 } +enum class Color { +WHITE +BLACK +RED +YELLOW +BLUE +override fun toString() : String? { +return "COLOR" +} +public fun name() : String { return "" } +public fun order() : Int { return 0 } } \ No newline at end of file diff --git a/tests/testData/ast/enum/class/primaryPrivateConstructor.kt b/tests/testData/ast/enum/class/primaryPrivateConstructor.kt index 9842b0d00b4..7d0338d9a78 100644 --- a/tests/testData/ast/enum/class/primaryPrivateConstructor.kt +++ b/tests/testData/ast/enum/class/primaryPrivateConstructor.kt @@ -1,12 +1,12 @@ -package demo -enum class Color(c : Int) { -private var code : Int = 0 -public fun getCode() : Int { -return code -} -{ -code = c -} -public fun name() : String { return "" } -public fun order() : Int { return 0 } +package demo +enum class Color(c : Int) { +private var code : Int = 0 +public fun getCode() : Int { +return code +} +{ +code = c +} +public fun name() : String { return "" } +public fun order() : Int { return 0 } } \ No newline at end of file diff --git a/tests/testData/ast/enum/class/privateEnum.kt b/tests/testData/ast/enum/class/privateEnum.kt index dbc90decc7b..646c07af7fa 100644 --- a/tests/testData/ast/enum/class/privateEnum.kt +++ b/tests/testData/ast/enum/class/privateEnum.kt @@ -1,4 +1,4 @@ -private enum class Test { -public fun name() : String { return "" } -public fun order() : Int { return 0 } +private enum class Test { +public fun name() : String { return "" } +public fun order() : Int { return 0 } } \ No newline at end of file diff --git a/tests/testData/ast/enum/class/protectedEnum.kt b/tests/testData/ast/enum/class/protectedEnum.kt index e09280af16c..6f2b364651a 100644 --- a/tests/testData/ast/enum/class/protectedEnum.kt +++ b/tests/testData/ast/enum/class/protectedEnum.kt @@ -1,4 +1,4 @@ -protected enum class Test { -public fun name() : String { return "" } -public fun order() : Int { return 0 } +protected enum class Test { +public fun name() : String { return "" } +public fun order() : Int { return 0 } } \ No newline at end of file diff --git a/tests/testData/ast/enum/class/publicEnum.kt b/tests/testData/ast/enum/class/publicEnum.kt index 6a05d60c6cf..5e7e2c3cdd8 100644 --- a/tests/testData/ast/enum/class/publicEnum.kt +++ b/tests/testData/ast/enum/class/publicEnum.kt @@ -1,4 +1,4 @@ -public enum class Test { -public fun name() : String { return "" } -public fun order() : Int { return 0 } +public enum class Test { +public fun name() : String { return "" } +public fun order() : Int { return 0 } } \ No newline at end of file diff --git a/tests/testData/ast/enum/class/runnableImplementation.kt b/tests/testData/ast/enum/class/runnableImplementation.kt index 467e73bc48a..e3bce19be72 100644 --- a/tests/testData/ast/enum/class/runnableImplementation.kt +++ b/tests/testData/ast/enum/class/runnableImplementation.kt @@ -1,12 +1,12 @@ -enum class Color : Runnable { -WHITE -BLACK -RED -YELLOW -BLUE -public override fun run() : Unit { -System.out?.println("name()=" + name() + ", toString()=" + toString()) -} -public fun name() : String { return "" } -public fun order() : Int { return 0 } +enum class Color : Runnable { +WHITE +BLACK +RED +YELLOW +BLUE +public override fun run() : Unit { +System.out?.println("name()=" + name() + ", toString()=" + toString()) +} +public fun name() : String { return "" } +public fun order() : Int { return 0 } } \ No newline at end of file diff --git a/tests/testData/ast/enum/class/typeSafeEnum.kt b/tests/testData/ast/enum/class/typeSafeEnum.kt index e4728074b75..a8b4e8b2a83 100644 --- a/tests/testData/ast/enum/class/typeSafeEnum.kt +++ b/tests/testData/ast/enum/class/typeSafeEnum.kt @@ -1,8 +1,8 @@ -enum class Coin { -PENNY -NICKEL -DIME -QUARTER -public fun name() : String { return "" } -public fun order() : Int { return 0 } +enum class Coin { +PENNY +NICKEL +DIME +QUARTER +public fun name() : String { return "" } +public fun order() : Int { return 0 } } \ No newline at end of file diff --git a/tests/testData/ast/field/file/classChildExtendsBase.kt b/tests/testData/ast/field/file/classChildExtendsBase.kt index 11589309492..17681369b0b 100644 --- a/tests/testData/ast/field/file/classChildExtendsBase.kt +++ b/tests/testData/ast/field/file/classChildExtendsBase.kt @@ -1,6 +1,6 @@ -open class Base() { -private var myFirst : String? = null -} -open class Child() : Base() { -private var mySecond : String? = null +open class Base() { +private var myFirst : String? = null +} +open class Child() : Base() { +private var mySecond : String? = null } \ No newline at end of file diff --git a/tests/testData/ast/field/file/internalField.kt b/tests/testData/ast/field/file/internalField.kt index 28fb8db799b..5cd1a6ac9a9 100644 --- a/tests/testData/ast/field/file/internalField.kt +++ b/tests/testData/ast/field/file/internalField.kt @@ -1,3 +1,3 @@ -open class C() { -var f : Foo? = null +open class C() { +var f : Foo? = null } \ No newline at end of file diff --git a/tests/testData/ast/field/file/privateField.kt b/tests/testData/ast/field/file/privateField.kt index 29c0b479266..b2441bf0c24 100644 --- a/tests/testData/ast/field/file/privateField.kt +++ b/tests/testData/ast/field/file/privateField.kt @@ -1,3 +1,3 @@ -open class C() { -private var f : Foo? = null +open class C() { +private var f : Foo? = null } \ No newline at end of file diff --git a/tests/testData/ast/field/file/protectedField.kt b/tests/testData/ast/field/file/protectedField.kt index 922f359b70f..cba6200d896 100644 --- a/tests/testData/ast/field/file/protectedField.kt +++ b/tests/testData/ast/field/file/protectedField.kt @@ -1,3 +1,3 @@ -open class C() { -protected var f : Foo? = null +open class C() { +protected var f : Foo? = null } \ No newline at end of file diff --git a/tests/testData/ast/field/file/publicField.kt b/tests/testData/ast/field/file/publicField.kt index 1ccfa12a0ae..c79b38d6c5c 100644 --- a/tests/testData/ast/field/file/publicField.kt +++ b/tests/testData/ast/field/file/publicField.kt @@ -1,3 +1,3 @@ -open class C() { -public var f : Foo? = null +open class C() { +public var f : Foo? = null } \ No newline at end of file diff --git a/tests/testData/ast/field/file/valWithInit.kt b/tests/testData/ast/field/file/valWithInit.kt index 32d44347025..b311ebb6784 100644 --- a/tests/testData/ast/field/file/valWithInit.kt +++ b/tests/testData/ast/field/file/valWithInit.kt @@ -1,3 +1,3 @@ -open class C() { -val f : Foo = Foo(1, 2) +open class C() { +val f : Foo = Foo(1, 2) } \ No newline at end of file diff --git a/tests/testData/ast/field/file/varWithInit.kt b/tests/testData/ast/field/file/varWithInit.kt index c30af4b2a15..6d8dfd2b64c 100644 --- a/tests/testData/ast/field/file/varWithInit.kt +++ b/tests/testData/ast/field/file/varWithInit.kt @@ -1,3 +1,3 @@ -open class C() { -var f : Foo? = Foo(1, 2) +open class C() { +var f : Foo? = Foo(1, 2) } \ No newline at end of file diff --git a/tests/testData/ast/field/file/varWithoutInit.kt b/tests/testData/ast/field/file/varWithoutInit.kt index 28fb8db799b..5cd1a6ac9a9 100644 --- a/tests/testData/ast/field/file/varWithoutInit.kt +++ b/tests/testData/ast/field/file/varWithoutInit.kt @@ -1,3 +1,3 @@ -open class C() { -var f : Foo? = null +open class C() { +var f : Foo? = null } \ No newline at end of file diff --git a/tests/testData/ast/file/comp/intNullability.kt b/tests/testData/ast/file/comp/intNullability.kt index 4e81114caea..891c5720f20 100644 --- a/tests/testData/ast/file/comp/intNullability.kt +++ b/tests/testData/ast/file/comp/intNullability.kt @@ -1,9 +1,9 @@ -package demo -import kotlin.compatibility.* -open class Test() { -open fun test() : Unit { -var i : Int? = 10 -var j : Int? = 10 -System.out?.println(i + j) -} +package demo +import kotlin.compatibility.* +open class Test() { +open fun test() : Unit { +var i : Int? = 10 +var j : Int? = 10 +System.out?.println(i + j) +} } \ No newline at end of file diff --git a/tests/testData/ast/file/file/packageWithClass.kt b/tests/testData/ast/file/file/packageWithClass.kt index c8dc0cae797..3f205654c0b 100644 --- a/tests/testData/ast/file/file/packageWithClass.kt +++ b/tests/testData/ast/file/file/packageWithClass.kt @@ -1,3 +1,3 @@ -package test -class C() { +package test +class C() { } \ No newline at end of file diff --git a/tests/testData/ast/file/file/packageWithClasses.kt b/tests/testData/ast/file/file/packageWithClasses.kt index 6e17362fd12..4ed94efde09 100644 --- a/tests/testData/ast/file/file/packageWithClasses.kt +++ b/tests/testData/ast/file/file/packageWithClasses.kt @@ -1,4 +1,4 @@ -class A() { -} -class B() { +class A() { +} +class B() { } \ No newline at end of file diff --git a/tests/testData/ast/file/file/packageWithImports.kt b/tests/testData/ast/file/file/packageWithImports.kt index 574db38b2fc..d646d02ccc0 100644 --- a/tests/testData/ast/file/file/packageWithImports.kt +++ b/tests/testData/ast/file/file/packageWithImports.kt @@ -1,3 +1,3 @@ -package test -import ast +package test +import ast import ast2 \ No newline at end of file diff --git a/tests/testData/ast/file/file/packageWithMixedImports.kt b/tests/testData/ast/file/file/packageWithMixedImports.kt index 574db38b2fc..d646d02ccc0 100644 --- a/tests/testData/ast/file/file/packageWithMixedImports.kt +++ b/tests/testData/ast/file/file/packageWithMixedImports.kt @@ -1,3 +1,3 @@ -package test -import ast +package test +import ast import ast2 \ No newline at end of file diff --git a/tests/testData/ast/file/file/packageWithOpenClass.kt b/tests/testData/ast/file/file/packageWithOpenClass.kt index 0258fc072fb..d4336ffcc51 100644 --- a/tests/testData/ast/file/file/packageWithOpenClass.kt +++ b/tests/testData/ast/file/file/packageWithOpenClass.kt @@ -1,3 +1,3 @@ -package test -open class C() { +package test +open class C() { } \ No newline at end of file diff --git a/tests/testData/ast/file/file/packageWithStaticImports.kt b/tests/testData/ast/file/file/packageWithStaticImports.kt index 574db38b2fc..d646d02ccc0 100644 --- a/tests/testData/ast/file/file/packageWithStaticImports.kt +++ b/tests/testData/ast/file/file/packageWithStaticImports.kt @@ -1,3 +1,3 @@ -package test -import ast +package test +import ast import ast2 \ No newline at end of file diff --git a/tests/testData/ast/for/statement/commonCaseForTest.kt b/tests/testData/ast/for/statement/commonCaseForTest.kt index 329aa8c5572..0fab59caf33 100644 --- a/tests/testData/ast/for/statement/commonCaseForTest.kt +++ b/tests/testData/ast/for/statement/commonCaseForTest.kt @@ -1,10 +1,10 @@ -{ -init() -while (condition()) -{ -body() -{ -update() -} -} +{ +init() +while (condition()) +{ +body() +{ +update() +} +} } \ No newline at end of file diff --git a/tests/testData/ast/for/statement/forRangeWithLE.kt b/tests/testData/ast/for/statement/forRangeWithLE.kt index 5bd70a50082..79c11ab6288 100644 --- a/tests/testData/ast/for/statement/forRangeWithLE.kt +++ b/tests/testData/ast/for/statement/forRangeWithLE.kt @@ -1,4 +1,4 @@ -var array : IntArray? = IntArray(10) -for (i in 0..10) { -array[i] = i +var array : IntArray? = IntArray(10) +for (i in 0..10) { +array[i] = i } \ No newline at end of file diff --git a/tests/testData/ast/for/statement/forRangeWithLT.kt b/tests/testData/ast/for/statement/forRangeWithLT.kt index 9026bd5ce21..f31b904afa4 100644 --- a/tests/testData/ast/for/statement/forRangeWithLT.kt +++ b/tests/testData/ast/for/statement/forRangeWithLT.kt @@ -1,4 +1,4 @@ -var array : IntArray? = IntArray(10) -for (i in 0..10 - 1) { -array[i] = i +var array : IntArray? = IntArray(10) +for (i in 0..10 - 1) { +array[i] = i } \ No newline at end of file diff --git a/tests/testData/ast/for/statement/forWithBlock.kt b/tests/testData/ast/for/statement/forWithBlock.kt index 9026bd5ce21..f31b904afa4 100644 --- a/tests/testData/ast/for/statement/forWithBlock.kt +++ b/tests/testData/ast/for/statement/forWithBlock.kt @@ -1,4 +1,4 @@ -var array : IntArray? = IntArray(10) -for (i in 0..10 - 1) { -array[i] = i +var array : IntArray? = IntArray(10) +for (i in 0..10 - 1) { +array[i] = i } \ No newline at end of file diff --git a/tests/testData/ast/for/statement/forWithBlockAndDoubleUpdate.kt b/tests/testData/ast/for/statement/forWithBlockAndDoubleUpdate.kt index e8c068d22a0..4fd380f6ffe 100644 --- a/tests/testData/ast/for/statement/forWithBlockAndDoubleUpdate.kt +++ b/tests/testData/ast/for/statement/forWithBlockAndDoubleUpdate.kt @@ -1,14 +1,14 @@ -{ -var i : Int = 0 -while (i < 0) -{ -{ -var i : Int = 1 -i++ -} -{ -j++ -i++ -} -} +{ +var i : Int = 0 +while (i < 0) +{ +{ +var i : Int = 1 +i++ +} +{ +j++ +i++ +} +} } \ No newline at end of file diff --git a/tests/testData/ast/for/statement/forWithEmptyBlock.kt b/tests/testData/ast/for/statement/forWithEmptyBlock.kt index a3110901bdf..a5743d94b32 100644 --- a/tests/testData/ast/for/statement/forWithEmptyBlock.kt +++ b/tests/testData/ast/for/statement/forWithEmptyBlock.kt @@ -1,12 +1,12 @@ -{ -var i : Int = 0 -while (i < 0) -{ -{ -} -{ -j++ -i++ -} -} +{ +var i : Int = 0 +while (i < 0) +{ +{ +} +{ +j++ +i++ +} +} } \ No newline at end of file diff --git a/tests/testData/ast/for/statement/forWithReturn.kt b/tests/testData/ast/for/statement/forWithReturn.kt index 14780c27b21..1c9a6cb9016 100644 --- a/tests/testData/ast/for/statement/forWithReturn.kt +++ b/tests/testData/ast/for/statement/forWithReturn.kt @@ -1,11 +1,11 @@ -{ -var i : Int = 0 -while (i < 0) -{ -return i -{ -j++ -i++ -} -} +{ +var i : Int = 0 +while (i < 0) +{ +return i +{ +j++ +i++ +} +} } \ No newline at end of file diff --git a/tests/testData/ast/foreachStatement/statement/enhancedForWithBlock.kt b/tests/testData/ast/foreachStatement/statement/enhancedForWithBlock.kt index e0ff78334cf..43cfc79c100 100644 --- a/tests/testData/ast/foreachStatement/statement/enhancedForWithBlock.kt +++ b/tests/testData/ast/foreachStatement/statement/enhancedForWithBlock.kt @@ -1,5 +1,5 @@ -for (n : Node? in list) -{ -var i : Int = 1 -i++ +for (n : Node? in list) +{ +var i : Int = 1 +i++ } \ No newline at end of file diff --git a/tests/testData/ast/foreachStatement/statement/enhancedForWithEmptyBlock.kt b/tests/testData/ast/foreachStatement/statement/enhancedForWithEmptyBlock.kt index 945006d2dd9..96f7cee4323 100644 --- a/tests/testData/ast/foreachStatement/statement/enhancedForWithEmptyBlock.kt +++ b/tests/testData/ast/foreachStatement/statement/enhancedForWithEmptyBlock.kt @@ -1,3 +1,3 @@ -for (n : Node? in list) -{ +for (n : Node? in list) +{ } \ No newline at end of file diff --git a/tests/testData/ast/foreachStatement/statement/enhancedForWithExpression.kt b/tests/testData/ast/foreachStatement/statement/enhancedForWithExpression.kt index 6e3ea34d942..7affa022577 100644 --- a/tests/testData/ast/foreachStatement/statement/enhancedForWithExpression.kt +++ b/tests/testData/ast/foreachStatement/statement/enhancedForWithExpression.kt @@ -1,2 +1,2 @@ -for (n : Node? in list) +for (n : Node? in list) i++ \ No newline at end of file diff --git a/tests/testData/ast/foreachStatement/statement/enhancedForWithReturn.kt b/tests/testData/ast/foreachStatement/statement/enhancedForWithReturn.kt index 143f7767a85..cb66b9552f4 100644 --- a/tests/testData/ast/foreachStatement/statement/enhancedForWithReturn.kt +++ b/tests/testData/ast/foreachStatement/statement/enhancedForWithReturn.kt @@ -1,2 +1,2 @@ -for (n : Node? in list) +for (n : Node? in list) return n \ No newline at end of file diff --git a/tests/testData/ast/function/file/extendsBaseWhichExtendsObject.kt b/tests/testData/ast/function/file/extendsBaseWhichExtendsObject.kt index 284cd37ffcd..491c63b601e 100644 --- a/tests/testData/ast/function/file/extendsBaseWhichExtendsObject.kt +++ b/tests/testData/ast/function/file/extendsBaseWhichExtendsObject.kt @@ -1,35 +1,35 @@ -package test -open class Test() : Base() { -public override fun hashCode() : Int { -return super.hashCode() -} -public override fun equals(o : Any?) : Boolean { -return super.equals(o) -} -protected override fun clone() : Any? { -return super.clone() -} -public override fun toString() : String? { -return super.toString() -} -protected override fun finalize() : Unit { -super.finalize() -} -} -open class Base() { -public open fun hashCode() : Int { -return System.identityHashCode(this) -} -public open fun equals(o : Any?) : Boolean { -return this.identityEquals(o) -} -protected open fun clone() : Any? { -return super.clone() -} -public open fun toString() : String? { -return getJavaClass.getName() + '@' + Integer.toHexString(hashCode()) -} -protected open fun finalize() : Unit { -super.finalize() -} +package test +open class Test() : Base() { +public override fun hashCode() : Int { +return super.hashCode() +} +public override fun equals(o : Any?) : Boolean { +return super.equals(o) +} +protected override fun clone() : Any? { +return super.clone() +} +public override fun toString() : String? { +return super.toString() +} +protected override fun finalize() : Unit { +super.finalize() +} +} +open class Base() { +public open fun hashCode() : Int { +return System.identityHashCode(this) +} +public open fun equals(o : Any?) : Boolean { +return this.identityEquals(o) +} +protected open fun clone() : Any? { +return super.clone() +} +public open fun toString() : String? { +return getJavaClass.getName() + '@' + Integer.toHexString(hashCode()) +} +protected open fun finalize() : Unit { +super.finalize() +} } \ No newline at end of file diff --git a/tests/testData/ast/function/file/functionInFinalClass.kt b/tests/testData/ast/function/file/functionInFinalClass.kt index 5546a9ff4ab..def36e1f8de 100644 --- a/tests/testData/ast/function/file/functionInFinalClass.kt +++ b/tests/testData/ast/function/file/functionInFinalClass.kt @@ -1,5 +1,5 @@ -package demo -class Final() { -fun test() : Unit { -} +package demo +class Final() { +fun test() : Unit { +} } \ No newline at end of file diff --git a/tests/testData/ast/function/file/override.kt b/tests/testData/ast/function/file/override.kt index 775e07afd6a..d895be5bb27 100644 --- a/tests/testData/ast/function/file/override.kt +++ b/tests/testData/ast/function/file/override.kt @@ -1,8 +1,8 @@ -open class A() { -open fun a() : Unit { -} -} -class B() : A() { -override fun a() : Unit { -} +open class A() { +open fun a() : Unit { +} +} +class B() : A() { +override fun a() : Unit { +} } \ No newline at end of file diff --git a/tests/testData/ast/function/file/overrideAndOpen.kt b/tests/testData/ast/function/file/overrideAndOpen.kt index a4335071798..678a37a4a70 100644 --- a/tests/testData/ast/function/file/overrideAndOpen.kt +++ b/tests/testData/ast/function/file/overrideAndOpen.kt @@ -1,12 +1,12 @@ -open class A() { -open fun foo() : Unit { -} -} -open class B() : A() { -override fun foo() : Unit { -} -} -open class C() : B() { -override fun foo() : Unit { -} +open class A() { +open fun foo() : Unit { +} +} +open class B() : A() { +override fun foo() : Unit { +} +} +open class C() : B() { +override fun foo() : Unit { +} } \ No newline at end of file diff --git a/tests/testData/ast/function/file/overrideObject.kt b/tests/testData/ast/function/file/overrideObject.kt index f7301f7b196..55f017c4656 100644 --- a/tests/testData/ast/function/file/overrideObject.kt +++ b/tests/testData/ast/function/file/overrideObject.kt @@ -1,18 +1,18 @@ -package test -open class Test() { -public open fun hashCode() : Int { -return System.identityHashCode(this) -} -public open fun equals(o : Any?) : Boolean { -return this.identityEquals(o) -} -protected open fun clone() : Any? { -return super.clone() -} -public open fun toString() : String? { -return getJavaClass.getName() + '@' + Integer.toHexString(hashCode()) -} -protected open fun finalize() : Unit { -super.finalize() -} +package test +open class Test() { +public open fun hashCode() : Int { +return System.identityHashCode(this) +} +public open fun equals(o : Any?) : Boolean { +return this.identityEquals(o) +} +protected open fun clone() : Any? { +return super.clone() +} +public open fun toString() : String? { +return getJavaClass.getName() + '@' + Integer.toHexString(hashCode()) +} +protected open fun finalize() : Unit { +super.finalize() +} } \ No newline at end of file diff --git a/tests/testData/ast/function/file/varVararg.kt b/tests/testData/ast/function/file/varVararg.kt index c3cfa02dc73..6d364141a95 100644 --- a/tests/testData/ast/function/file/varVararg.kt +++ b/tests/testData/ast/function/file/varVararg.kt @@ -1,6 +1,6 @@ -package demo -open class Test() { -open fun test(vararg var args : Any?) : Unit { -args = array(1, 2, 3) -} +package demo +open class Test() { +open fun test(vararg var args : Any?) : Unit { +args = array(1, 2, 3) +} } \ No newline at end of file diff --git a/tests/testData/ast/function/file/writableParameter.kt b/tests/testData/ast/function/file/writableParameter.kt index 388363d3a75..b098e657066 100644 --- a/tests/testData/ast/function/file/writableParameter.kt +++ b/tests/testData/ast/function/file/writableParameter.kt @@ -1,7 +1,7 @@ -package demo -open class Test() { -open fun test(var i : Int) : Int { -i = 10 -return i + 20 -} +package demo +open class Test() { +open fun test(var i : Int) : Int { +i = 10 +return i + 20 +} } \ No newline at end of file diff --git a/tests/testData/ast/function/method/classGenericParam.kt b/tests/testData/ast/function/method/classGenericParam.kt index cb91ad7b095..b9ea1d49799 100644 --- a/tests/testData/ast/function/method/classGenericParam.kt +++ b/tests/testData/ast/function/method/classGenericParam.kt @@ -1,2 +1,2 @@ -fun getT() : T? { +fun getT() : T? { } \ No newline at end of file diff --git a/tests/testData/ast/function/method/emptyVoidMethod.kt b/tests/testData/ast/function/method/emptyVoidMethod.kt index db28ea9ebcb..ae299eb173a 100644 --- a/tests/testData/ast/function/method/emptyVoidMethod.kt +++ b/tests/testData/ast/function/method/emptyVoidMethod.kt @@ -1,2 +1,2 @@ -fun main() : Unit { +fun main() : Unit { } \ No newline at end of file diff --git a/tests/testData/ast/function/method/final.kt b/tests/testData/ast/function/method/final.kt index 3ed88375ea7..e6cf12b2b3f 100644 --- a/tests/testData/ast/function/method/final.kt +++ b/tests/testData/ast/function/method/final.kt @@ -1,3 +1,3 @@ -fun getString() : String? { -return "" +fun getString() : String? { +return "" } \ No newline at end of file diff --git a/tests/testData/ast/function/method/internal.kt b/tests/testData/ast/function/method/internal.kt index a0118c99e7f..5b3e9634f3f 100644 --- a/tests/testData/ast/function/method/internal.kt +++ b/tests/testData/ast/function/method/internal.kt @@ -1,2 +1,2 @@ -fun test() : Unit { +fun test() : Unit { } \ No newline at end of file diff --git a/tests/testData/ast/function/method/main.kt b/tests/testData/ast/function/method/main.kt index 1ed23f6e5ae..164c099f986 100644 --- a/tests/testData/ast/function/method/main.kt +++ b/tests/testData/ast/function/method/main.kt @@ -1,4 +1,4 @@ -class object { -public fun main(args : Array?) : Unit { -} +class object { +public fun main(args : Array?) : Unit { +} } \ No newline at end of file diff --git a/tests/testData/ast/function/method/methodClassType.kt b/tests/testData/ast/function/method/methodClassType.kt index d3a97e16a3f..196c45b6bf8 100644 --- a/tests/testData/ast/function/method/methodClassType.kt +++ b/tests/testData/ast/function/method/methodClassType.kt @@ -1,2 +1,2 @@ -fun main() : String? { +fun main() : String? { } \ No newline at end of file diff --git a/tests/testData/ast/function/method/methodPrimitiveType.kt b/tests/testData/ast/function/method/methodPrimitiveType.kt index dc03fed3cd9..c6ef43f8a14 100644 --- a/tests/testData/ast/function/method/methodPrimitiveType.kt +++ b/tests/testData/ast/function/method/methodPrimitiveType.kt @@ -1,2 +1,2 @@ -fun main() : Int { +fun main() : Int { } \ No newline at end of file diff --git a/tests/testData/ast/function/method/methodPrimitiveType2.kt b/tests/testData/ast/function/method/methodPrimitiveType2.kt index b4df54adcaf..c978e93e7aa 100644 --- a/tests/testData/ast/function/method/methodPrimitiveType2.kt +++ b/tests/testData/ast/function/method/methodPrimitiveType2.kt @@ -1,2 +1,2 @@ -fun main() : Boolean { +fun main() : Boolean { } \ No newline at end of file diff --git a/tests/testData/ast/function/method/methodWithReturnStatement.kt b/tests/testData/ast/function/method/methodWithReturnStatement.kt index 40fc1144ad3..acfbd1010d8 100644 --- a/tests/testData/ast/function/method/methodWithReturnStatement.kt +++ b/tests/testData/ast/function/method/methodWithReturnStatement.kt @@ -1,3 +1,3 @@ -fun isTrue() : Boolean { -return true +fun isTrue() : Boolean { +return true } \ No newline at end of file diff --git a/tests/testData/ast/function/method/open.kt b/tests/testData/ast/function/method/open.kt index 3ed88375ea7..e6cf12b2b3f 100644 --- a/tests/testData/ast/function/method/open.kt +++ b/tests/testData/ast/function/method/open.kt @@ -1,3 +1,3 @@ -fun getString() : String? { -return "" +fun getString() : String? { +return "" } \ No newline at end of file diff --git a/tests/testData/ast/function/method/ownGenericParam.kt b/tests/testData/ast/function/method/ownGenericParam.kt index 51205bef614..e5533fdcb5f 100644 --- a/tests/testData/ast/function/method/ownGenericParam.kt +++ b/tests/testData/ast/function/method/ownGenericParam.kt @@ -1,2 +1,2 @@ -fun putU(u : U?) : Unit { +fun putU(u : U?) : Unit { } \ No newline at end of file diff --git a/tests/testData/ast/function/method/ownSeveralGenericParams.kt b/tests/testData/ast/function/method/ownSeveralGenericParams.kt index b9dd3c684e1..19fb6188681 100644 --- a/tests/testData/ast/function/method/ownSeveralGenericParams.kt +++ b/tests/testData/ast/function/method/ownSeveralGenericParams.kt @@ -1,2 +1,2 @@ -fun putUVW(u : U?, v : V?, w : W?) : Unit { +fun putUVW(u : U?, v : V?, w : W?) : Unit { } \ No newline at end of file diff --git a/tests/testData/ast/function/method/private.kt b/tests/testData/ast/function/method/private.kt index be8571b7f24..45e5e8bab00 100644 --- a/tests/testData/ast/function/method/private.kt +++ b/tests/testData/ast/function/method/private.kt @@ -1,2 +1,2 @@ -private fun test() : Unit { +private fun test() : Unit { } \ No newline at end of file diff --git a/tests/testData/ast/function/method/protected.kt b/tests/testData/ast/function/method/protected.kt index 3cf7e568df7..dbbc30b447b 100644 --- a/tests/testData/ast/function/method/protected.kt +++ b/tests/testData/ast/function/method/protected.kt @@ -1,2 +1,2 @@ -protected fun test() : Unit { +protected fun test() : Unit { } \ No newline at end of file diff --git a/tests/testData/ast/function/method/public.kt b/tests/testData/ast/function/method/public.kt index 166c7ec8136..d835330ec86 100644 --- a/tests/testData/ast/function/method/public.kt +++ b/tests/testData/ast/function/method/public.kt @@ -1,2 +1,2 @@ -public fun test() : Unit { +public fun test() : Unit { } \ No newline at end of file diff --git a/tests/testData/ast/identifier/file/finalFieldReference.kt b/tests/testData/ast/identifier/file/finalFieldReference.kt index d015ea5ef32..3e5423839fb 100644 --- a/tests/testData/ast/identifier/file/finalFieldReference.kt +++ b/tests/testData/ast/identifier/file/finalFieldReference.kt @@ -1,13 +1,13 @@ -open class `$$$$$`() { -} -open class `$`() { -} -open class `$$`(`$$$$` : `$$$$$`?) : `$`() { -val `$$$` : `$$$$$`? -public open fun `$$$$$$`() : `$$$$$`? { -return `$$$` -} -{ -`$$$` = `$$$$` -} +open class `$$$$$`() { +} +open class `$`() { +} +open class `$$`(`$$$$` : `$$$$$`?) : `$`() { +val `$$$` : `$$$$$`? +public open fun `$$$$$$`() : `$$$$$`? { +return `$$$` +} +{ +`$$$` = `$$$$` +} } \ No newline at end of file diff --git a/tests/testData/ast/identifier/statement/keywords.kt b/tests/testData/ast/identifier/statement/keywords.kt index 9d4b718fafe..5395a402d72 100644 --- a/tests/testData/ast/identifier/statement/keywords.kt +++ b/tests/testData/ast/identifier/statement/keywords.kt @@ -1,11 +1,11 @@ -var `as` : Int -var `type` : Int -var `val` : Int -var `var` : Int -var `fun` : Int -var `is` : Int -var `in` : Int -var `object` : Int -var `when` : Int -var `trait` : Int +var `as` : Int +var `type` : Int +var `val` : Int +var `var` : Int +var `fun` : Int +var `is` : Int +var `in` : Int +var `object` : Int +var `when` : Int +var `trait` : Int var `This` : Int \ No newline at end of file diff --git a/tests/testData/ast/ifStatement/statement/ifStatementWithEmptyBlocks.kt b/tests/testData/ast/ifStatement/statement/ifStatementWithEmptyBlocks.kt index b48926727df..4587b89bf1e 100644 --- a/tests/testData/ast/ifStatement/statement/ifStatementWithEmptyBlocks.kt +++ b/tests/testData/ast/ifStatement/statement/ifStatementWithEmptyBlocks.kt @@ -1,6 +1,6 @@ -if (1 > 0) -{ -} -else -{ +if (1 > 0) +{ +} +else +{ } \ No newline at end of file diff --git a/tests/testData/ast/ifStatement/statement/ifStatementWithMultilineBlocks.kt b/tests/testData/ast/ifStatement/statement/ifStatementWithMultilineBlocks.kt index 27ae7424666..41cfc10ac2d 100644 --- a/tests/testData/ast/ifStatement/statement/ifStatementWithMultilineBlocks.kt +++ b/tests/testData/ast/ifStatement/statement/ifStatementWithMultilineBlocks.kt @@ -1,9 +1,9 @@ -if (1 > 0) -{ -var n : Int = 1 -return n -} -else -{ -return 0 +if (1 > 0) +{ +var n : Int = 1 +return n +} +else +{ +return 0 } \ No newline at end of file diff --git a/tests/testData/ast/ifStatement/statement/ifStatementWithOneLineBlocks.kt b/tests/testData/ast/ifStatement/statement/ifStatementWithOneLineBlocks.kt index 057d6294846..923c0d36318 100644 --- a/tests/testData/ast/ifStatement/statement/ifStatementWithOneLineBlocks.kt +++ b/tests/testData/ast/ifStatement/statement/ifStatementWithOneLineBlocks.kt @@ -1,4 +1,4 @@ -if (true) -return 1 -else +if (true) +return 1 +else return 0 \ No newline at end of file diff --git a/tests/testData/ast/ifStatement/statement/ifStatementWithoutElse.kt b/tests/testData/ast/ifStatement/statement/ifStatementWithoutElse.kt index 6dcf6d7b346..a63a714b79c 100644 --- a/tests/testData/ast/ifStatement/statement/ifStatementWithoutElse.kt +++ b/tests/testData/ast/ifStatement/statement/ifStatementWithoutElse.kt @@ -1,5 +1,5 @@ -if (1 > 0) -{ -var n : Int = 1 -return n +if (1 > 0) +{ +var n : Int = 1 +return n } \ No newline at end of file diff --git a/tests/testData/ast/importStatement/file/importWithKeywords.kt b/tests/testData/ast/importStatement/file/importWithKeywords.kt index 7eda4b24938..63b5935201f 100644 --- a/tests/testData/ast/importStatement/file/importWithKeywords.kt +++ b/tests/testData/ast/importStatement/file/importWithKeywords.kt @@ -1,4 +1,4 @@ -package test -import `as`.`type`.`val`.`var`.`fun`.`is`.`in`.`object`.`when`.`trait`.`This` -open class Test() { +package test +import `as`.`type`.`val`.`var`.`fun`.`is`.`in`.`object`.`when`.`trait`.`This` +open class Test() { } \ No newline at end of file diff --git a/tests/testData/ast/importStatement/file/importWithStar.kt b/tests/testData/ast/importStatement/file/importWithStar.kt index 6727a6e8fcb..c390c539acc 100644 --- a/tests/testData/ast/importStatement/file/importWithStar.kt +++ b/tests/testData/ast/importStatement/file/importWithStar.kt @@ -1,4 +1,4 @@ -package org.jetbrains.jet.j2k -import org.jetbrains.annotations.* -public open class Converter() { +package org.jetbrains.jet.j2k +import org.jetbrains.annotations.* +public open class Converter() { } \ No newline at end of file diff --git a/tests/testData/ast/importStatement/file/simpleImport.kt b/tests/testData/ast/importStatement/file/simpleImport.kt index 21028179d15..c35720004e5 100644 --- a/tests/testData/ast/importStatement/file/simpleImport.kt +++ b/tests/testData/ast/importStatement/file/simpleImport.kt @@ -1,3 +1,3 @@ -package org.jetbrains.jet.j2k -public open class Converter() { +package org.jetbrains.jet.j2k +public open class Converter() { } \ No newline at end of file diff --git a/tests/testData/ast/inProjectionType/method/methodParams.kt b/tests/testData/ast/inProjectionType/method/methodParams.kt index 9e225d237c2..6888dcd5c36 100644 --- a/tests/testData/ast/inProjectionType/method/methodParams.kt +++ b/tests/testData/ast/inProjectionType/method/methodParams.kt @@ -1,2 +1,2 @@ -fun popAll(dst : Collection?) : Unit { +fun popAll(dst : Collection?) : Unit { } \ No newline at end of file diff --git a/tests/testData/ast/inheritance/file/classOneExtendsBaseGeneric.kt b/tests/testData/ast/inheritance/file/classOneExtendsBaseGeneric.kt index 2d413b3fca1..a324e8503b5 100644 --- a/tests/testData/ast/inheritance/file/classOneExtendsBaseGeneric.kt +++ b/tests/testData/ast/inheritance/file/classOneExtendsBaseGeneric.kt @@ -1,8 +1,8 @@ -open class Base(name : T?) { -} -open class One(name : T?, second : K?) : Base(name) { -private var mySecond : K? = null -{ -mySecond = second -} +open class Base(name : T?) { +} +open class One(name : T?, second : K?) : Base(name) { +private var mySecond : K? = null +{ +mySecond = second +} } \ No newline at end of file diff --git a/tests/testData/ast/inheritance/file/classOneExtendsBaseWithOneParam.kt b/tests/testData/ast/inheritance/file/classOneExtendsBaseWithOneParam.kt index 56b9315c50b..3e82be38c5c 100644 --- a/tests/testData/ast/inheritance/file/classOneExtendsBaseWithOneParam.kt +++ b/tests/testData/ast/inheritance/file/classOneExtendsBaseWithOneParam.kt @@ -1,4 +1,4 @@ -open class Base(name : String?) { -} -open class One(name : String?, second : String?) : Base(name) { +open class Base(name : String?) { +} +open class One(name : String?, second : String?) : Base(name) { } \ No newline at end of file diff --git a/tests/testData/ast/inheritance/file/classOneExtendsBaseWithZeroParams.kt b/tests/testData/ast/inheritance/file/classOneExtendsBaseWithZeroParams.kt index 2b63632703e..94f907016db 100644 --- a/tests/testData/ast/inheritance/file/classOneExtendsBaseWithZeroParams.kt +++ b/tests/testData/ast/inheritance/file/classOneExtendsBaseWithZeroParams.kt @@ -1,4 +1,4 @@ -open class Base() { -} -open class One() : Base() { +open class Base() { +} +open class One() : Base() { } \ No newline at end of file diff --git a/tests/testData/ast/inheritance/file/classOneExtendsBaseWithZeroParamsNonEmptyConstructor.kt b/tests/testData/ast/inheritance/file/classOneExtendsBaseWithZeroParamsNonEmptyConstructor.kt index a1f95b2666f..cd9b7f3b8e9 100644 --- a/tests/testData/ast/inheritance/file/classOneExtendsBaseWithZeroParamsNonEmptyConstructor.kt +++ b/tests/testData/ast/inheritance/file/classOneExtendsBaseWithZeroParamsNonEmptyConstructor.kt @@ -1,8 +1,8 @@ -open class Base(name : String?) { -} -open class One(name : String?, second : String?) : Base(name) { -private var mySecond : String? = null -{ -mySecond = second -} +open class Base(name : String?) { +} +open class One(name : String?, second : String?) : Base(name) { +private var mySecond : String? = null +{ +mySecond = second +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/arrayLength.jav b/tests/testData/ast/issues/file/arrayLength.jav index 781dd730887..418cf61f079 100644 --- a/tests/testData/ast/issues/file/arrayLength.jav +++ b/tests/testData/ast/issues/file/arrayLength.jav @@ -1,5 +1,5 @@ -class Test { - public static int foo(String[] args) { - return args.length; - } -} +class Test { + public static int foo(String[] args) { + return args.length; + } +} diff --git a/tests/testData/ast/issues/file/arrayLength.kt b/tests/testData/ast/issues/file/arrayLength.kt index 3d3f227c751..c8082cf2e65 100644 --- a/tests/testData/ast/issues/file/arrayLength.kt +++ b/tests/testData/ast/issues/file/arrayLength.kt @@ -1,7 +1,7 @@ -open class Test() { -class object { -public open fun foo(args : Array?) : Int { -return args?.size!! -} -} +open class Test() { +class object { +public open fun foo(args : Array?) : Int { +return args?.size!! +} +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/comments.jav b/tests/testData/ast/issues/file/comments.jav index 74978823f3e..1220e5f6776 100644 --- a/tests/testData/ast/issues/file/comments.jav +++ b/tests/testData/ast/issues/file/comments.jav @@ -1,22 +1,22 @@ -// This is an end-of-line comment - -/* -This is a block comment -*/ - - -class C { - // This is a class comment - - /** - * This is a field doc comment. - */ - private int i; - - /** - * This is a function doc comment. - */ - public void foo() { - /* This is a function comment */ - } -} +// This is an end-of-line comment + +/* +This is a block comment +*/ + + +class C { + // This is a class comment + + /** + * This is a field doc comment. + */ + private int i; + + /** + * This is a function doc comment. + */ + public void foo() { + /* This is a function comment */ + } +} diff --git a/tests/testData/ast/issues/file/comments.kt b/tests/testData/ast/issues/file/comments.kt index 536f6f45847..e98e6e431d5 100644 --- a/tests/testData/ast/issues/file/comments.kt +++ b/tests/testData/ast/issues/file/comments.kt @@ -1,17 +1,17 @@ -// This is an end-of-line comment -/* -This is a block comment -*/ -open class C() { -// This is a class comment -/** - * This is a field doc comment. - */ -private var i : Int = 0 -/** - * This is a function doc comment. - */ -public open fun foo() : Unit { -/* This is a function comment */ -} +// This is an end-of-line comment +/* +This is a block comment +*/ +open class C() { +// This is a class comment +/** + * This is a field doc comment. + */ +private var i : Int = 0 +/** + * This is a function doc comment. + */ +public open fun foo() : Unit { +/* This is a function comment */ +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-1016.kt b/tests/testData/ast/issues/file/kt-1016.kt index 07cad7e659a..801abcf6e5a 100644 --- a/tests/testData/ast/issues/file/kt-1016.kt +++ b/tests/testData/ast/issues/file/kt-1016.kt @@ -1,7 +1,7 @@ -package demo -open class C(i : Int) { -private val i : Int -{ -this.i = i -} +package demo +open class C(i : Int) { +private val i : Int +{ +this.i = i +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-1048.kt b/tests/testData/ast/issues/file/kt-1048.kt index 27544583cf0..69d30dfa1a3 100644 --- a/tests/testData/ast/issues/file/kt-1048.kt +++ b/tests/testData/ast/issues/file/kt-1048.kt @@ -1,14 +1,14 @@ -import java.util.HashMap -open class G(t : T?) { -} -public open class Java() { -open fun test() : Unit { -var m : HashMap? = HashMap() -m?.put(1, 1) -} -open fun test2() : Unit { -var m : HashMap<*, *>? = HashMap() -var g : G? = G("") -var g2 : G? = G("") -} +import java.util.HashMap +open class G(t : T?) { +} +public open class Java() { +open fun test() : Unit { +var m : HashMap? = HashMap() +m?.put(1, 1) +} +open fun test2() : Unit { +var m : HashMap<*, *>? = HashMap() +var g : G? = G("") +var g2 : G? = G("") +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-1074.kt b/tests/testData/ast/issues/file/kt-1074.kt index ee08f5c2856..652697c03b5 100644 --- a/tests/testData/ast/issues/file/kt-1074.kt +++ b/tests/testData/ast/issues/file/kt-1074.kt @@ -1,13 +1,13 @@ -package demo -open class Test() { -class object { -open fun subListRangeCheck(fromIndex : Int, toIndex : Int, size : Int) : Unit { -if (fromIndex < 0) -throw IndexOutOfBoundsException("fromIndex = " + fromIndex) -if (toIndex > size) -throw IndexOutOfBoundsException("toIndex = " + toIndex) -if (fromIndex > toIndex) -throw IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")") -} -} +package demo +open class Test() { +class object { +open fun subListRangeCheck(fromIndex : Int, toIndex : Int, size : Int) : Unit { +if (fromIndex < 0) +throw IndexOutOfBoundsException("fromIndex = " + fromIndex) +if (toIndex > size) +throw IndexOutOfBoundsException("toIndex = " + toIndex) +if (fromIndex > toIndex) +throw IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")") +} +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-543-boxed.kt b/tests/testData/ast/issues/file/kt-543-boxed.kt index 8744235cc24..2465167cd1d 100644 --- a/tests/testData/ast/issues/file/kt-543-boxed.kt +++ b/tests/testData/ast/issues/file/kt-543-boxed.kt @@ -1,11 +1,11 @@ -package demo -open class Test() { -open fun putInt(i : Int?) : Unit { -} -open fun test() : Unit { -var b : Byte = 10 -putInt(b.toInt()) -var b2 : Byte? = 10 -putInt(b2?.toInt()) -} +package demo +open class Test() { +open fun putInt(i : Int?) : Unit { +} +open fun test() : Unit { +var b : Byte = 10 +putInt(b.toInt()) +var b2 : Byte? = 10 +putInt(b2?.toInt()) +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-543-mixed.kt b/tests/testData/ast/issues/file/kt-543-mixed.kt index b3e646c16a9..566c7766284 100644 --- a/tests/testData/ast/issues/file/kt-543-mixed.kt +++ b/tests/testData/ast/issues/file/kt-543-mixed.kt @@ -1,9 +1,9 @@ -package demo -open class Test() { -open fun putInt(i : Int?) : Unit { -} -open fun test() : Unit { -var i : Int = 10 -putInt(i) -} +package demo +open class Test() { +open fun putInt(i : Int?) : Unit { +} +open fun test() : Unit { +var i : Int = 10 +putInt(i) +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-543.kt b/tests/testData/ast/issues/file/kt-543.kt index a37983ba916..dc9dcb3b7f7 100644 --- a/tests/testData/ast/issues/file/kt-543.kt +++ b/tests/testData/ast/issues/file/kt-543.kt @@ -1,9 +1,9 @@ -package demo -open class Test() { -open fun putInt(i : Int) : Unit { -} -open fun test() : Unit { -var b : Byte = 10 -putInt(b.toInt()) -} +package demo +open class Test() { +open fun putInt(i : Int) : Unit { +} +open fun test() : Unit { +var b : Byte = 10 +putInt(b.toInt()) +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-638.kt b/tests/testData/ast/issues/file/kt-638.kt index 7983c393681..2bdbed1b2d5 100644 --- a/tests/testData/ast/issues/file/kt-638.kt +++ b/tests/testData/ast/issues/file/kt-638.kt @@ -1,38 +1,38 @@ -public open class Identifier(_myName : T?, _myHasDollar : Boolean) { -private val myName : T? = null -private var myHasDollar : Boolean = false -private var myNullable : Boolean = true -public open fun getName() : T? { -return myName -} -{ -myName = _myName -myHasDollar = _myHasDollar -} -class object { -public open fun init(name : T?) : Identifier { -val __ = Identifier(name, false) -return __ -} -public open fun init(name : T?, isNullable : Boolean) : Identifier { -val __ = Identifier(name, false) -__.myNullable = isNullable -return __ -} -public open fun init(name : T?, hasDollar : Boolean, isNullable : Boolean) : Identifier { -val __ = Identifier(name, hasDollar) -__.myNullable = isNullable -return __ -} -} -} -public open class User() { -class object { -public open fun main(args : Array?) : Unit { -var i1 : Identifier<*>? = Identifier.init("name", false, true) -var i2 : Identifier? = Identifier.init("name", false) -var i3 : Identifier? = Identifier.init("name") -} -} -} +public open class Identifier(_myName : T?, _myHasDollar : Boolean) { +private val myName : T? = null +private var myHasDollar : Boolean = false +private var myNullable : Boolean = true +public open fun getName() : T? { +return myName +} +{ +myName = _myName +myHasDollar = _myHasDollar +} +class object { +public open fun init(name : T?) : Identifier { +val __ = Identifier(name, false) +return __ +} +public open fun init(name : T?, isNullable : Boolean) : Identifier { +val __ = Identifier(name, false) +__.myNullable = isNullable +return __ +} +public open fun init(name : T?, hasDollar : Boolean, isNullable : Boolean) : Identifier { +val __ = Identifier(name, hasDollar) +__.myNullable = isNullable +return __ +} +} +} +public open class User() { +class object { +public open fun main(args : Array?) : Unit { +var i1 : Identifier<*>? = Identifier.init("name", false, true) +var i2 : Identifier? = Identifier.init("name", false) +var i3 : Identifier? = Identifier.init("name") +} +} +} fun main(args : Array?) = User.main(args) \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-696.kt b/tests/testData/ast/issues/file/kt-696.kt index eac7522715b..173b4205ee4 100644 --- a/tests/testData/ast/issues/file/kt-696.kt +++ b/tests/testData/ast/issues/file/kt-696.kt @@ -1,23 +1,23 @@ -package test -open class Base() { -public open fun hashCode() : Int { -return System.identityHashCode(this) -} -public open fun equals(o : Any?) : Boolean { -return this.identityEquals(o) -} -public open fun toString() : String? { -return getJavaClass.getName() + '@' + Integer.toHexString(hashCode()) -} -} -open class Child() : Base() { -public override fun hashCode() : Int { -return super.hashCode() -} -public override fun equals(o : Any?) : Boolean { -return super.equals(o) -} -public override fun toString() : String? { -return super.toString() -} +package test +open class Base() { +public open fun hashCode() : Int { +return System.identityHashCode(this) +} +public open fun equals(o : Any?) : Boolean { +return this.identityEquals(o) +} +public open fun toString() : String? { +return getJavaClass.getName() + '@' + Integer.toHexString(hashCode()) +} +} +open class Child() : Base() { +public override fun hashCode() : Int { +return super.hashCode() +} +public override fun equals(o : Any?) : Boolean { +return super.equals(o) +} +public override fun toString() : String? { +return super.toString() +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-792-mixed.kt b/tests/testData/ast/issues/file/kt-792-mixed.kt index eac219d8c6f..fa82740445e 100644 --- a/tests/testData/ast/issues/file/kt-792-mixed.kt +++ b/tests/testData/ast/issues/file/kt-792-mixed.kt @@ -1,7 +1,7 @@ -package demo -open class Test(i : Int?) { -open fun test() : Unit { -var i : Int = 10 -Test(i) -} +package demo +open class Test(i : Int?) { +open fun test() : Unit { +var i : Int = 10 +Test(i) +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-792.kt b/tests/testData/ast/issues/file/kt-792.kt index c11e69dc440..2a6929f3456 100644 --- a/tests/testData/ast/issues/file/kt-792.kt +++ b/tests/testData/ast/issues/file/kt-792.kt @@ -1,7 +1,7 @@ -package demo -open class Test(i : Int) { -open fun test() : Unit { -var b : Byte = 10 -Test(b.toInt()) -} +package demo +open class Test(i : Int) { +open fun test() : Unit { +var b : Byte = 10 +Test(b.toInt()) +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-794-mixed.kt b/tests/testData/ast/issues/file/kt-794-mixed.kt index f2224f10a3b..4ec128cbf11 100644 --- a/tests/testData/ast/issues/file/kt-794-mixed.kt +++ b/tests/testData/ast/issues/file/kt-794-mixed.kt @@ -1,9 +1,9 @@ -package demo -open class Test() { -open fun getInteger(i : Int?) : Int? { -return i -} -open fun test() : Unit { -var i : Int = getInteger(10) -} +package demo +open class Test() { +open fun getInteger(i : Int?) : Int? { +return i +} +open fun test() : Unit { +var i : Int = getInteger(10) +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-794.kt b/tests/testData/ast/issues/file/kt-794.kt index 61f9cc80f03..f27c7dcba3e 100644 --- a/tests/testData/ast/issues/file/kt-794.kt +++ b/tests/testData/ast/issues/file/kt-794.kt @@ -1,6 +1,6 @@ -open class Test() { -open fun getInt() : Int { -var b : Byte = 10 -return b.toInt() -} +open class Test() { +open fun getInt() : Int { +var b : Byte = 10 +return b.toInt() +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-809-string.kt b/tests/testData/ast/issues/file/kt-809-string.kt index 00b343142e4..9dea26fc2eb 100644 --- a/tests/testData/ast/issues/file/kt-809-string.kt +++ b/tests/testData/ast/issues/file/kt-809-string.kt @@ -1,19 +1,19 @@ -package demo -open class Container() { -var myString : String? = "1" -} -open class One() { -class object { -var myContainer : Container? = Container() -} -} -open class StringContainer(s : String?) { -} -open class Test() { -open fun putString(s : String?) : Unit { -} -open fun test() : Unit { -putString(One.myContainer?.myString) -StringContainer(One.myContainer?.myString) -} +package demo +open class Container() { +var myString : String? = "1" +} +open class One() { +class object { +var myContainer : Container? = Container() +} +} +open class StringContainer(s : String?) { +} +open class Test() { +open fun putString(s : String?) : Unit { +} +open fun test() : Unit { +putString(One.myContainer?.myString) +StringContainer(One.myContainer?.myString) +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-809.kt b/tests/testData/ast/issues/file/kt-809.kt index f341103f8f5..598912b4016 100644 --- a/tests/testData/ast/issues/file/kt-809.kt +++ b/tests/testData/ast/issues/file/kt-809.kt @@ -1,19 +1,19 @@ -package demo -open class Container() { -var myInt : Int = 1 -} -open class One() { -class object { -var myContainer : Container? = Container() -} -} -open class IntContainer(i : Int) { -} -open class Test() { -open fun putInt(i : Int) : Unit { -} -open fun test() : Unit { -putInt(One.myContainer?.myInt!!) -IntContainer(One.myContainer?.myInt!!) -} +package demo +open class Container() { +var myInt : Int = 1 +} +open class One() { +class object { +var myContainer : Container? = Container() +} +} +open class IntContainer(i : Int) { +} +open class Test() { +open fun putInt(i : Int) : Unit { +} +open fun test() : Unit { +putInt(One.myContainer?.myInt!!) +IntContainer(One.myContainer?.myInt!!) +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-820-field.kt b/tests/testData/ast/issues/file/kt-820-field.kt index edea1336672..5f9141abcc7 100644 --- a/tests/testData/ast/issues/file/kt-820-field.kt +++ b/tests/testData/ast/issues/file/kt-820-field.kt @@ -1,12 +1,12 @@ -package demo -open class Container() { -var myInt : Int = 1 -} -open class One() { -class object { -var myContainer : Container? = Container() -} -} -open class Test() { -var b : Byte = One.myContainer?.myInt!!.toByte() +package demo +open class Container() { +var myInt : Int = 1 +} +open class One() { +class object { +var myContainer : Container? = Container() +} +} +open class Test() { +var b : Byte = One.myContainer?.myInt!!.toByte() } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-820-string.kt b/tests/testData/ast/issues/file/kt-820-string.kt index a742b94fac2..762e1aa8f90 100644 --- a/tests/testData/ast/issues/file/kt-820-string.kt +++ b/tests/testData/ast/issues/file/kt-820-string.kt @@ -1,8 +1,8 @@ -open class Test() { -class object { -public open fun toFileSystemSafeName(name : String?) : String? { -var size : Int = name?.length()!! -return name -} -} +open class Test() { +class object { +public open fun toFileSystemSafeName(name : String?) : String? { +var size : Int = name?.length()!! +return name +} +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-820.kt b/tests/testData/ast/issues/file/kt-820.kt index 7cb6d042228..77fbee788f3 100644 --- a/tests/testData/ast/issues/file/kt-820.kt +++ b/tests/testData/ast/issues/file/kt-820.kt @@ -1,14 +1,14 @@ -package demo -open class Container() { -var myInt : Int = 1 -} -open class One() { -class object { -var myContainer : Container? = Container() -} -} -open class Test() { -open fun test() : Unit { -var b : Byte = One.myContainer?.myInt!!.toByte() -} +package demo +open class Container() { +var myInt : Int = 1 +} +open class One() { +class object { +var myContainer : Container? = Container() +} +} +open class Test() { +open fun test() : Unit { +var b : Byte = One.myContainer?.myInt!!.toByte() +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-824-isDir.kt b/tests/testData/ast/issues/file/kt-824-isDir.kt index 0248b413bbd..715092216b6 100644 --- a/tests/testData/ast/issues/file/kt-824-isDir.kt +++ b/tests/testData/ast/issues/file/kt-824-isDir.kt @@ -1,22 +1,22 @@ -package test -import java.io.File -/** -* User: ignatov -*/ -public open class Test() { -class object { -public open fun isDir(parent : File?) : Boolean { -if (parent == null || !parent?.exists()!!) -{ -return false -} -var result : Boolean = true -if (parent?.isDirectory()!!) -{ -return true -} -else -return false -} -} +package test +import java.io.File +/** +* User: ignatov +*/ +public open class Test() { +class object { +public open fun isDir(parent : File?) : Boolean { +if (parent == null || !parent?.exists()!!) +{ +return false +} +var result : Boolean = true +if (parent?.isDirectory()!!) +{ +return true +} +else +return false +} +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-824.kt b/tests/testData/ast/issues/file/kt-824.kt index c831f3b811c..065f372cb69 100644 --- a/tests/testData/ast/issues/file/kt-824.kt +++ b/tests/testData/ast/issues/file/kt-824.kt @@ -1,26 +1,26 @@ -package demo -open class Container() { -var myBoolean : Boolean = true -} -open class One() { -class object { -var myContainer : Container? = Container() -} -} -open class Test() { -open fun test() : Unit { -if (One.myContainer?.myBoolean!!) -System.out?.println("Ok") -var s : String? = (if (One.myContainer?.myBoolean!!) -"YES" -else -"NO") -while (One.myContainer?.myBoolean!!) -System.out?.println("Ok") -do -{ -System.out?.println("Ok") -} -while (One.myContainer?.myBoolean!!) -} +package demo +open class Container() { +var myBoolean : Boolean = true +} +open class One() { +class object { +var myContainer : Container? = Container() +} +} +open class Test() { +open fun test() : Unit { +if (One.myContainer?.myBoolean!!) +System.out?.println("Ok") +var s : String? = (if (One.myContainer?.myBoolean!!) +"YES" +else +"NO") +while (One.myContainer?.myBoolean!!) +System.out?.println("Ok") +do +{ +System.out?.println("Ok") +} +while (One.myContainer?.myBoolean!!) +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-828.kt b/tests/testData/ast/issues/file/kt-828.kt index 62ec4f7e4f1..3ed25233de4 100644 --- a/tests/testData/ast/issues/file/kt-828.kt +++ b/tests/testData/ast/issues/file/kt-828.kt @@ -1,14 +1,14 @@ -open class Test() { -open fun test() : Unit { -var res : Boolean = true -res = res and false -res = res or false -res = res xor false -System.out?.println(true and false) -System.out?.println(true or false) -System.out?.println(true xor false) -System.out?.println(!true) -System.out?.println(true && false) -System.out?.println(true || false) -} +open class Test() { +open fun test() : Unit { +var res : Boolean = true +res = res and false +res = res or false +res = res xor false +System.out?.println(true and false) +System.out?.println(true or false) +System.out?.println(true xor false) +System.out?.println(!true) +System.out?.println(true && false) +System.out?.println(true || false) +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-836.kt b/tests/testData/ast/issues/file/kt-836.kt index 2a1ba4c5786..938269632b7 100644 --- a/tests/testData/ast/issues/file/kt-836.kt +++ b/tests/testData/ast/issues/file/kt-836.kt @@ -1,25 +1,25 @@ -package com.voltvoodoo.saplo4j.model -import java.io.Serializable -public open class Language(code : String?) : Serializable { -protected var code : String? = null -public override fun toString() : String? { -return this.code -} -{ -this.code = code -} -} -open class Base() { -open fun test() : Unit { -} -open fun toString() : String? { -return "BASE" -} -} -open class Child() : Base() { -override fun test() : Unit { -} -override fun toString() : String? { -return "Child" -} +package com.voltvoodoo.saplo4j.model +import java.io.Serializable +public open class Language(code : String?) : Serializable { +protected var code : String? = null +public override fun toString() : String? { +return this.code +} +{ +this.code = code +} +} +open class Base() { +open fun test() : Unit { +} +open fun toString() : String? { +return "BASE" +} +} +open class Child() : Base() { +override fun test() : Unit { +} +override fun toString() : String? { +return "Child" +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-837.kt b/tests/testData/ast/issues/file/kt-837.kt index bf5b16010d4..a04124924ea 100644 --- a/tests/testData/ast/issues/file/kt-837.kt +++ b/tests/testData/ast/issues/file/kt-837.kt @@ -1,16 +1,16 @@ -package com.voltvoodoo.saplo4j.model -import java.io.Serializable -public open class Language(code : String?) : Serializable { -protected var code : String? = null -public open fun equals(other : Language?) : Boolean { -return other?.toString()?.equals(this.toString())!! -} -{ -this.code = code -} -class object { -public var ENGLISH : Language? = Language("en") -public var SWEDISH : Language? = Language("sv") -private val serialVersionUID : Long = -2442762969929206780 -} +package com.voltvoodoo.saplo4j.model +import java.io.Serializable +public open class Language(code : String?) : Serializable { +protected var code : String? = null +public open fun equals(other : Language?) : Boolean { +return other?.toString()?.equals(this.toString())!! +} +{ +this.code = code +} +class object { +public var ENGLISH : Language? = Language("en") +public var SWEDISH : Language? = Language("sv") +private val serialVersionUID : Long = -2442762969929206780 +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-852.kt b/tests/testData/ast/issues/file/kt-852.kt index 59929786c3d..1dc37fb5e16 100644 --- a/tests/testData/ast/issues/file/kt-852.kt +++ b/tests/testData/ast/issues/file/kt-852.kt @@ -1,13 +1,13 @@ -package demo -open class Test() { -open fun test() : String? { -var s1 : String? = "" -var s2 : String? = "" -var s3 : String? = "" -if (s1?.isEmpty()!! && s2?.isEmpty()!!) -return "OK" -if (s1?.isEmpty()!! && s2?.isEmpty()!! && s3?.isEmpty()!!) -return "OOOK" -return "" -} +package demo +open class Test() { +open fun test() : String? { +var s1 : String? = "" +var s2 : String? = "" +var s3 : String? = "" +if (s1?.isEmpty()!! && s2?.isEmpty()!!) +return "OK" +if (s1?.isEmpty()!! && s2?.isEmpty()!! && s3?.isEmpty()!!) +return "OOOK" +return "" +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-871.kt b/tests/testData/ast/issues/file/kt-871.kt index 6af74ed4561..69d9bdeef56 100644 --- a/tests/testData/ast/issues/file/kt-871.kt +++ b/tests/testData/ast/issues/file/kt-871.kt @@ -1,9 +1,9 @@ -package demo -open class Program() { -class object { -public open fun main(args : Array?) : Unit { -System.out?.println("Halo!") -} -} -} +package demo +open class Program() { +class object { +public open fun main(args : Array?) : Unit { +System.out?.println("Halo!") +} +} +} fun main(args : Array?) = Program.main(args) \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-879.kt b/tests/testData/ast/issues/file/kt-879.kt index 2fb5abe82a5..b52d1403a85 100644 --- a/tests/testData/ast/issues/file/kt-879.kt +++ b/tests/testData/ast/issues/file/kt-879.kt @@ -1,23 +1,23 @@ -open class Test() { -class object { -public open fun getInt(i : Int) : Int { -when (i) { -0 -> { -return 0 -} -1 -> { -return 1 -} -2 -> { -return 2 -} -3 -> { -return 3 -} -else -> { -return -1 -} -} -} -} +open class Test() { +class object { +public open fun getInt(i : Int) : Int { +when (i) { +0 -> { +return 0 +} +1 -> { +return 1 +} +2 -> { +return 2 +} +3 -> { +return 3 +} +else -> { +return -1 +} +} +} +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-893.kt b/tests/testData/ast/issues/file/kt-893.kt index 1c1c545a9a5..7e5d3bb6509 100644 --- a/tests/testData/ast/issues/file/kt-893.kt +++ b/tests/testData/ast/issues/file/kt-893.kt @@ -1,8 +1,8 @@ -package demo -open class Test() { -open fun test() : Unit { -for (i in 0..10 - 1) { -System.out?.println(i) -} -} +package demo +open class Test() { +open fun test() : Unit { +for (i in 0..10 - 1) { +System.out?.println(i) +} +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/kt-963.kt b/tests/testData/ast/issues/file/kt-963.kt index d921cbb041a..2e024295a77 100644 --- a/tests/testData/ast/issues/file/kt-963.kt +++ b/tests/testData/ast/issues/file/kt-963.kt @@ -1,7 +1,7 @@ -package demo -open class C(a : Int) { -var abc : Int = 0 -{ -abc = a * 2 -} +package demo +open class C(a : Int) { +var abc : Int = 0 +{ +abc = a * 2 +} } \ No newline at end of file diff --git a/tests/testData/ast/issues/file/qualifyStatic.jav b/tests/testData/ast/issues/file/qualifyStatic.jav index d11b710e625..35b26e68374 100644 --- a/tests/testData/ast/issues/file/qualifyStatic.jav +++ b/tests/testData/ast/issues/file/qualifyStatic.jav @@ -1,7 +1,7 @@ -import java.util.Calendar - -abstract class MyCalendar extends Calendar { - public void foo() { - int i = ALL_STYLES; - } -} +import java.util.Calendar + +abstract class MyCalendar extends Calendar { + public void foo() { + int i = ALL_STYLES; + } +} diff --git a/tests/testData/ast/issues/file/qualifyStatic.kt b/tests/testData/ast/issues/file/qualifyStatic.kt index a3bcd4c4838..0a32e4017fd 100644 --- a/tests/testData/ast/issues/file/qualifyStatic.kt +++ b/tests/testData/ast/issues/file/qualifyStatic.kt @@ -1,6 +1,6 @@ -import java.util.Calendar -abstract class MyCalendar() : Calendar() { -public open fun foo() : Unit { -var i : Int = Calendar.ALL_STYLES -} +import java.util.Calendar +abstract class MyCalendar() : Calendar() { +public open fun foo() : Unit { +var i : Int = Calendar.ALL_STYLES +} } \ No newline at end of file diff --git a/tests/testData/ast/kotlinExclusion/file/kt-656.kt b/tests/testData/ast/kotlinExclusion/file/kt-656.kt index 6def227ab25..d42a74320de 100644 --- a/tests/testData/ast/kotlinExclusion/file/kt-656.kt +++ b/tests/testData/ast/kotlinExclusion/file/kt-656.kt @@ -1,19 +1,19 @@ -package demo -open class Test() : java.lang.Iterable { -public override fun iterator() : java.util.Iterator? { -return null -} -public open fun push(i : java.util.Iterator?) : java.util.Iterator? { -var j : java.util.Iterator? = i -return j -} -} -open class FullTest() : java.lang.Iterable { -public override fun iterator() : java.util.Iterator? { -return null -} -public open fun push(i : java.util.Iterator?) : java.util.Iterator? { -var j : java.util.Iterator? = i -return j -} +package demo +open class Test() : java.lang.Iterable { +public override fun iterator() : java.util.Iterator? { +return null +} +public open fun push(i : java.util.Iterator?) : java.util.Iterator? { +var j : java.util.Iterator? = i +return j +} +} +open class FullTest() : java.lang.Iterable { +public override fun iterator() : java.util.Iterator? { +return null +} +public open fun push(i : java.util.Iterator?) : java.util.Iterator? { +var j : java.util.Iterator? = i +return j +} } \ No newline at end of file diff --git a/tests/testData/ast/labelStatement/statement/complicatedExampleFromJavaTutorial.kt b/tests/testData/ast/labelStatement/statement/complicatedExampleFromJavaTutorial.kt index a2e5946c884..bb5b07c2f36 100644 --- a/tests/testData/ast/labelStatement/statement/complicatedExampleFromJavaTutorial.kt +++ b/tests/testData/ast/labelStatement/statement/complicatedExampleFromJavaTutorial.kt @@ -1,18 +1,18 @@ -@test for (i in 0..max) { -var n : Int = substring.length() -var j : Int = i -var k : Int = 0 -while (n-- != 0) -{ -if (searchMe.charAt(j++) != substring.charAt(k++)) -{ -continue@test -} -} -foundIt = true -break@test -} -System.out?.println((if (foundIt) -"Found it" -else +@test for (i in 0..max) { +var n : Int = substring.length() +var j : Int = i +var k : Int = 0 +while (n-- != 0) +{ +if (searchMe.charAt(j++) != substring.charAt(k++)) +{ +continue@test +} +} +foundIt = true +break@test +} +System.out?.println((if (foundIt) +"Found it" +else "Didn't find it")) \ No newline at end of file diff --git a/tests/testData/ast/literalExpression/file/char.kt b/tests/testData/ast/literalExpression/file/char.kt index 681dfca3a2a..d8749cea99d 100644 --- a/tests/testData/ast/literalExpression/file/char.kt +++ b/tests/testData/ast/literalExpression/file/char.kt @@ -1,6 +1,6 @@ -open class Test() { -open fun test() : Unit { -var c1 : Char = 'c' -var c2 : Char? = 'C' -} +open class Test() { +open fun test() : Unit { +var c1 : Char = 'c' +var c2 : Char? = 'C' +} } \ No newline at end of file diff --git a/tests/testData/ast/literalExpression/file/dollarInsideString.kt b/tests/testData/ast/literalExpression/file/dollarInsideString.kt index 643aab84188..6a42dcad2c9 100644 --- a/tests/testData/ast/literalExpression/file/dollarInsideString.kt +++ b/tests/testData/ast/literalExpression/file/dollarInsideString.kt @@ -1,11 +1,11 @@ -package demo -open class Test() { -open fun test() : Unit { -var name : String? = "$$$$" -name = name?.replaceAll("\\$[0-9]+", "\\$") -var c : Char = '$' -System.out?.println(c) -var C : Char? = '$' -System.out?.println(C) -} +package demo +open class Test() { +open fun test() : Unit { +var name : String? = "$$$$" +name = name?.replaceAll("\\$[0-9]+", "\\$") +var c : Char = '$' +System.out?.println(c) +var C : Char? = '$' +System.out?.println(C) +} } \ No newline at end of file diff --git a/tests/testData/ast/literalExpression/file/endsWithDFL.kt b/tests/testData/ast/literalExpression/file/endsWithDFL.kt index 21a178c18ce..00e8dd282f5 100644 --- a/tests/testData/ast/literalExpression/file/endsWithDFL.kt +++ b/tests/testData/ast/literalExpression/file/endsWithDFL.kt @@ -1,18 +1,18 @@ -open class Test() { -open fun test() : Unit { -var l1 : Long = 10 -var d1 : Double = 10.0 -var f1 : Float = 10.0.toFloat() -var l2 : Long = 10 -var d2 : Double = 10.0 -var f2 : Float = 10.0.toFloat() -} -open fun testBoxed() : Unit { -var l1 : Long? = 10 -var d1 : Double? = 10.0 -var f1 : Float? = 10.0.toFloat() -var l2 : Long? = 10 -var d2 : Double? = 10.0 -var f2 : Float? = 10.0.toFloat() -} +open class Test() { +open fun test() : Unit { +var l1 : Long = 10 +var d1 : Double = 10.0 +var f1 : Float = 10.0.toFloat() +var l2 : Long = 10 +var d2 : Double = 10.0 +var f2 : Float = 10.0.toFloat() +} +open fun testBoxed() : Unit { +var l1 : Long? = 10 +var d1 : Double? = 10.0 +var f1 : Float? = 10.0.toFloat() +var l2 : Long? = 10 +var d2 : Double? = 10.0 +var f2 : Float? = 10.0.toFloat() +} } \ No newline at end of file diff --git a/tests/testData/ast/literalExpression/file/hex.kt b/tests/testData/ast/literalExpression/file/hex.kt index 71c7898650f..0bd6b37ae40 100644 --- a/tests/testData/ast/literalExpression/file/hex.kt +++ b/tests/testData/ast/literalExpression/file/hex.kt @@ -1,6 +1,6 @@ -open class Test() { -open fun test() : Unit { -var i1 : Int = 33 -var i2 : Int? = 51 -} +open class Test() { +open fun test() : Unit { +var i1 : Int = 33 +var i2 : Int? = 51 +} } \ No newline at end of file diff --git a/tests/testData/ast/literalExpression/file/octal.kt b/tests/testData/ast/literalExpression/file/octal.kt index 78f7d81ce13..83165bcc6fc 100644 --- a/tests/testData/ast/literalExpression/file/octal.kt +++ b/tests/testData/ast/literalExpression/file/octal.kt @@ -1,6 +1,6 @@ -open class Test() { -open fun test() : Unit { -var i1 : Int = 37 -var i2 : Int? = 26 -} +open class Test() { +open fun test() : Unit { +var i1 : Int = 37 +var i2 : Int? = 26 +} } \ No newline at end of file diff --git a/tests/testData/ast/literalExpression/file/trueOrFalse.kt b/tests/testData/ast/literalExpression/file/trueOrFalse.kt index 58ab3c7464c..ad61883202e 100644 --- a/tests/testData/ast/literalExpression/file/trueOrFalse.kt +++ b/tests/testData/ast/literalExpression/file/trueOrFalse.kt @@ -1,8 +1,8 @@ -open class Test() { -open fun test() : Unit { -var t1 : Boolean = true -var t2 : Boolean? = true -var f1 : Boolean = false -var f2 : Boolean? = false -} +open class Test() { +open fun test() : Unit { +var t1 : Boolean = true +var t2 : Boolean? = true +var f1 : Boolean = false +var f2 : Boolean? = false +} } \ No newline at end of file diff --git a/tests/testData/ast/methodCallExpression/file/genericMethod.kt b/tests/testData/ast/methodCallExpression/file/genericMethod.kt index 47c2f73a646..b130cbc9376 100644 --- a/tests/testData/ast/methodCallExpression/file/genericMethod.kt +++ b/tests/testData/ast/methodCallExpression/file/genericMethod.kt @@ -1,11 +1,11 @@ -package demo -open class Map() { -open fun put(k : K?, v : V?) : Unit { -} -} -open class U() { -open fun test() : Unit { -var m : Map? = Map() -m?.put("10", 10) -} +package demo +open class Map() { +open fun put(k : K?, v : V?) : Unit { +} +} +open class U() { +open fun test() : Unit { +var m : Map? = Map() +m?.put("10", 10) +} } \ No newline at end of file diff --git a/tests/testData/ast/newClassExpression/expression/newClassWithAnonymousScope.kt b/tests/testData/ast/newClassExpression/expression/newClassWithAnonymousScope.kt index 1d1d845045a..29038a298dc 100644 --- a/tests/testData/ast/newClassExpression/expression/newClassWithAnonymousScope.kt +++ b/tests/testData/ast/newClassExpression/expression/newClassWithAnonymousScope.kt @@ -1,5 +1,5 @@ -object : Runnable() { -public override fun run() : Unit { -System.out?.println("Run") -} +object : Runnable() { +public override fun run() : Unit { +System.out?.println("Run") +} } \ No newline at end of file diff --git a/tests/testData/ast/newClassExpression/file/fullQualifiedName.kt b/tests/testData/ast/newClassExpression/file/fullQualifiedName.kt index 8dd3c3ce459..d433f687e0b 100644 --- a/tests/testData/ast/newClassExpression/file/fullQualifiedName.kt +++ b/tests/testData/ast/newClassExpression/file/fullQualifiedName.kt @@ -1,6 +1,6 @@ -package test -open class User() { -open fun main() : Unit { -var list : List? = java.util.LinkedList() -} +package test +open class User() { +open fun main() : Unit { +var list : List? = java.util.LinkedList() +} } \ No newline at end of file diff --git a/tests/testData/ast/newClassExpression/file/fullQualifiedName2.kt b/tests/testData/ast/newClassExpression/file/fullQualifiedName2.kt index 08358dcfd43..09e95bef826 100644 --- a/tests/testData/ast/newClassExpression/file/fullQualifiedName2.kt +++ b/tests/testData/ast/newClassExpression/file/fullQualifiedName2.kt @@ -1,6 +1,6 @@ -package test -open class User() { -open fun main() : Unit { -var list : java.util.List? = java.util.LinkedList() -} +package test +open class User() { +open fun main() : Unit { +var list : java.util.List? = java.util.LinkedList() +} } \ No newline at end of file diff --git a/tests/testData/ast/newClassExpression/file/genericClassInvocation.kt b/tests/testData/ast/newClassExpression/file/genericClassInvocation.kt index 4d26ef6b445..e6b8fa1387f 100644 --- a/tests/testData/ast/newClassExpression/file/genericClassInvocation.kt +++ b/tests/testData/ast/newClassExpression/file/genericClassInvocation.kt @@ -1,6 +1,6 @@ -import java.util.LinkedList -open class User() { -open fun main() : Unit { -var list : List? = LinkedList() -} +import java.util.LinkedList +open class User() { +open fun main() : Unit { +var list : List? = LinkedList() +} } \ No newline at end of file diff --git a/tests/testData/ast/newClassExpression/file/newClassByFullName.kt b/tests/testData/ast/newClassExpression/file/newClassByFullName.kt index 49208751d9d..adb7fce935a 100644 --- a/tests/testData/ast/newClassExpression/file/newClassByFullName.kt +++ b/tests/testData/ast/newClassExpression/file/newClassByFullName.kt @@ -1,8 +1,8 @@ -package org.test -open class Library() { -} -open class User() { -open fun main() : Unit { -var lib : Library? = Library() -} +package org.test +open class Library() { +} +open class User() { +open fun main() : Unit { +var lib : Library? = Library() +} } \ No newline at end of file diff --git a/tests/testData/ast/newClassExpression/file/newInnerClass.kt b/tests/testData/ast/newClassExpression/file/newInnerClass.kt index 1b563c85428..93c7fec3411 100644 --- a/tests/testData/ast/newClassExpression/file/newInnerClass.kt +++ b/tests/testData/ast/newClassExpression/file/newInnerClass.kt @@ -1,11 +1,11 @@ -package org.test -open class OuterClass() { -open class InnerClass() { -} -} -open class User() { -open fun main() : Unit { -var outerObject : OuterClass? = OuterClass() -var innerObject : OuterClass.InnerClass? = outerObject?.InnerClass() -} +package org.test +open class OuterClass() { +open class InnerClass() { +} +} +open class User() { +open fun main() : Unit { +var outerObject : OuterClass? = OuterClass() +var innerObject : OuterClass.InnerClass? = outerObject?.InnerClass() +} } \ No newline at end of file diff --git a/tests/testData/ast/newClassExpression/file/newListAndNewMember.kt b/tests/testData/ast/newClassExpression/file/newListAndNewMember.kt index a4fa42c7670..8965ba6cb1b 100644 --- a/tests/testData/ast/newClassExpression/file/newListAndNewMember.kt +++ b/tests/testData/ast/newClassExpression/file/newListAndNewMember.kt @@ -1,10 +1,10 @@ -package org.test -import java.util.LinkedList -open class Member() { -} -open class User() { -open fun main() : Unit { -var members : List? = LinkedList() -members?.add(Member()) -} +package org.test +import java.util.LinkedList +open class Member() { +} +open class User() { +open fun main() : Unit { +var members : List? = LinkedList() +members?.add(Member()) +} } \ No newline at end of file diff --git a/tests/testData/ast/newClassExpression/file/newStaticInnerClass.kt b/tests/testData/ast/newClassExpression/file/newStaticInnerClass.kt index 89d4f149311..3a6a440f397 100644 --- a/tests/testData/ast/newClassExpression/file/newStaticInnerClass.kt +++ b/tests/testData/ast/newClassExpression/file/newStaticInnerClass.kt @@ -1,12 +1,12 @@ -package demo -open class Foo() { -class object { -open class Bar() { -} -} -} -open class User() { -open fun main() : Unit { -var boo : Foo.Bar? = Foo.Bar() -} +package demo +open class Foo() { +class object { +open class Bar() { +} +} +} +open class User() { +open fun main() : Unit { +var boo : Foo.Bar? = Foo.Bar() +} } \ No newline at end of file diff --git a/tests/testData/ast/objectLiteral/file/MyFrame.kt b/tests/testData/ast/objectLiteral/file/MyFrame.kt index f8544462e3e..270a5e9625f 100644 --- a/tests/testData/ast/objectLiteral/file/MyFrame.kt +++ b/tests/testData/ast/objectLiteral/file/MyFrame.kt @@ -1,18 +1,18 @@ -package demo -open class WindowAdapter() { -public open fun windowClosing() : Unit { -} -} -public class Client() : Frame() { -{ -var a : WindowAdapter? = object : WindowAdapter() { -public override fun windowClosing() : Unit { -} -} -addWindowListener(a) -addWindowListener(object : WindowAdapter() { -public override fun windowClosing() : Unit { -} -}) -} +package demo +open class WindowAdapter() { +public open fun windowClosing() : Unit { +} +} +public class Client() : Frame() { +{ +var a : WindowAdapter? = object : WindowAdapter() { +public override fun windowClosing() : Unit { +} +} +addWindowListener(a) +addWindowListener(object : WindowAdapter() { +public override fun windowClosing() : Unit { +} +}) +} } \ No newline at end of file diff --git a/tests/testData/ast/outProjectionType/method/methodParams.kt b/tests/testData/ast/outProjectionType/method/methodParams.kt index bd4fb48a56b..373c01e629f 100644 --- a/tests/testData/ast/outProjectionType/method/methodParams.kt +++ b/tests/testData/ast/outProjectionType/method/methodParams.kt @@ -1,2 +1,2 @@ -fun pushAll(src : Collection?) : Unit { +fun pushAll(src : Collection?) : Unit { } \ No newline at end of file diff --git a/tests/testData/ast/packageStatement/file/orgJetbrainsJetJ2kIn.kt b/tests/testData/ast/packageStatement/file/orgJetbrainsJetJ2kIn.kt index 6577e7b6c8d..a673d540277 100644 --- a/tests/testData/ast/packageStatement/file/orgJetbrainsJetJ2kIn.kt +++ b/tests/testData/ast/packageStatement/file/orgJetbrainsJetJ2kIn.kt @@ -1,4 +1,4 @@ -package org.jetbrains.jet.j2k.`in` -import org.jetbrains.annotations.Nullable -public open class Converter() { +package org.jetbrains.jet.j2k.`in` +import org.jetbrains.annotations.Nullable +public open class Converter() { } \ No newline at end of file diff --git a/tests/testData/ast/prefixOperator/statement/excl.kt b/tests/testData/ast/prefixOperator/statement/excl.kt index adf3dc99d50..54a88090fcb 100644 --- a/tests/testData/ast/prefixOperator/statement/excl.kt +++ b/tests/testData/ast/prefixOperator/statement/excl.kt @@ -1,2 +1,2 @@ -var i : Boolean = true +var i : Boolean = true var j : Boolean = !i \ No newline at end of file diff --git a/tests/testData/ast/prefixOperator/statement/kt-667.kt b/tests/testData/ast/prefixOperator/statement/kt-667.kt index df5a51082e3..529e9a8b422 100644 --- a/tests/testData/ast/prefixOperator/statement/kt-667.kt +++ b/tests/testData/ast/prefixOperator/statement/kt-667.kt @@ -1,2 +1,2 @@ -var i : Int = (10).inv() +var i : Int = (10).inv() var j : Int = ((i * 100)).inv() \ No newline at end of file diff --git a/tests/testData/ast/prefixOperator/statement/nullableIf.jav b/tests/testData/ast/prefixOperator/statement/nullableIf.jav index 539180d48fb..521960489a3 100644 --- a/tests/testData/ast/prefixOperator/statement/nullableIf.jav +++ b/tests/testData/ast/prefixOperator/statement/nullableIf.jav @@ -1,2 +1,2 @@ -String s = null; -if (!s.isEmpty()) { } +String s = null; +if (!s.isEmpty()) { } diff --git a/tests/testData/ast/prefixOperator/statement/nullableIf.kt b/tests/testData/ast/prefixOperator/statement/nullableIf.kt index bd253b95ddf..fde5ffa225e 100644 --- a/tests/testData/ast/prefixOperator/statement/nullableIf.kt +++ b/tests/testData/ast/prefixOperator/statement/nullableIf.kt @@ -1,4 +1,4 @@ -var s : String? = null -if (!s?.isEmpty()!!) -{ +var s : String? = null +if (!s?.isEmpty()!!) +{ } \ No newline at end of file diff --git a/tests/testData/ast/prefixOperator/statement/tilde.kt b/tests/testData/ast/prefixOperator/statement/tilde.kt index f3b7ac754e1..96d67f4d028 100644 --- a/tests/testData/ast/prefixOperator/statement/tilde.kt +++ b/tests/testData/ast/prefixOperator/statement/tilde.kt @@ -1,2 +1,2 @@ -var i : Int = 10 +var i : Int = 10 var j : Int = (10).inv() \ No newline at end of file diff --git a/tests/testData/ast/rawGenerics/file/kt-540-map.kt b/tests/testData/ast/rawGenerics/file/kt-540-map.kt index 51784d9a76d..ce580f8680a 100644 --- a/tests/testData/ast/rawGenerics/file/kt-540-map.kt +++ b/tests/testData/ast/rawGenerics/file/kt-540-map.kt @@ -1,9 +1,9 @@ -package demo -import java.util.HashMap -open class Test() { -open fun main() : Unit { -var commonMap : HashMap? = HashMap() -var rawMap : HashMap? = HashMap() -var superRawMap : HashMap? = HashMap() -} +package demo +import java.util.HashMap +open class Test() { +open fun main() : Unit { +var commonMap : HashMap? = HashMap() +var rawMap : HashMap? = HashMap() +var superRawMap : HashMap? = HashMap() +} } \ No newline at end of file diff --git a/tests/testData/ast/rawGenerics/file/kt-540-rawGenericClass.kt b/tests/testData/ast/rawGenerics/file/kt-540-rawGenericClass.kt index 22e2f6d8328..976f317b913 100644 --- a/tests/testData/ast/rawGenerics/file/kt-540-rawGenericClass.kt +++ b/tests/testData/ast/rawGenerics/file/kt-540-rawGenericClass.kt @@ -1,13 +1,13 @@ -package demo -open class Collection(e : E?) { -{ -System.out?.println(e) -} -} -open class Test() { -open fun main() : Unit { -var raw1 : Collection? = Collection(1) -var raw2 : Collection? = Collection(1) -var raw3 : Collection? = Collection("1") -} +package demo +open class Collection(e : E?) { +{ +System.out?.println(e) +} +} +open class Test() { +open fun main() : Unit { +var raw1 : Collection? = Collection(1) +var raw2 : Collection? = Collection(1) +var raw3 : Collection? = Collection("1") +} } \ No newline at end of file diff --git a/tests/testData/ast/rawGenerics/file/kt-540.kt b/tests/testData/ast/rawGenerics/file/kt-540.kt index 52f7d7421f0..8aa33d1132f 100644 --- a/tests/testData/ast/rawGenerics/file/kt-540.kt +++ b/tests/testData/ast/rawGenerics/file/kt-540.kt @@ -1,9 +1,9 @@ -package demo -import java.util.LinkedList -open class Test() { -open fun main() : Unit { -var common : List? = LinkedList() -var raw : List? = LinkedList() -var superRaw : List? = LinkedList() -} +package demo +import java.util.LinkedList +open class Test() { +open fun main() : Unit { +var common : List? = LinkedList() +var raw : List? = LinkedList() +var superRaw : List? = LinkedList() +} } \ No newline at end of file diff --git a/tests/testData/ast/rawGenerics/file/rawGenericMethod.kt b/tests/testData/ast/rawGenerics/file/rawGenericMethod.kt index 15ca4c5ac6f..ea3e08d5bdb 100644 --- a/tests/testData/ast/rawGenerics/file/rawGenericMethod.kt +++ b/tests/testData/ast/rawGenerics/file/rawGenericMethod.kt @@ -1,13 +1,13 @@ -package demo -open class TestT() { -open fun getT() : Unit { -} -} -open class U() { -open fun main() : Unit { -var t : TestT? = TestT() -t?.getT() -t?.getT() -t?.getT() -} +package demo +open class TestT() { +open fun getT() : Unit { +} +} +open class U() { +open fun main() : Unit { +var t : TestT? = TestT() +t?.getT() +t?.getT() +t?.getT() +} } \ No newline at end of file diff --git a/tests/testData/ast/starProjectionType/method/methodParams.kt b/tests/testData/ast/starProjectionType/method/methodParams.kt index 41a86faf443..01ea4c15302 100644 --- a/tests/testData/ast/starProjectionType/method/methodParams.kt +++ b/tests/testData/ast/starProjectionType/method/methodParams.kt @@ -1,2 +1,2 @@ -fun wtf(w : Collection<*>?) : Unit { +fun wtf(w : Collection<*>?) : Unit { } \ No newline at end of file diff --git a/tests/testData/ast/superExpression/class/classAextendsB.kt b/tests/testData/ast/superExpression/class/classAextendsB.kt index b89ebce366d..b9c5e29b288 100644 --- a/tests/testData/ast/superExpression/class/classAextendsB.kt +++ b/tests/testData/ast/superExpression/class/classAextendsB.kt @@ -1,10 +1,10 @@ -open class B(i : Int) { -open fun call() : Int { -return 1 -} -} -open class A() : B(10) { -override fun call() : Int { -return super.call() -} +open class B(i : Int) { +open fun call() : Int { +return 1 +} +} +open class A() : B(10) { +override fun call() : Int { +return super.call() +} } \ No newline at end of file diff --git a/tests/testData/ast/superExpression/file/classAdotSuperFoo.kt b/tests/testData/ast/superExpression/file/classAdotSuperFoo.kt index 5ce2249b587..a6495ce0571 100644 --- a/tests/testData/ast/superExpression/file/classAdotSuperFoo.kt +++ b/tests/testData/ast/superExpression/file/classAdotSuperFoo.kt @@ -1,10 +1,10 @@ -open class Base() { -open fun foo() : Unit -} -open class A() : Base() { -open class C() { -open fun test() : Unit { -super@A.foo() -} -} +open class Base() { +open fun foo() : Unit +} +open class A() : Base() { +open class C() { +open fun test() : Unit { +super@A.foo() +} +} } \ No newline at end of file diff --git a/tests/testData/ast/switch/file/comlicatedFallDown.kt b/tests/testData/ast/switch/file/comlicatedFallDown.kt index 888c5d181c8..60f4dd0466e 100644 --- a/tests/testData/ast/switch/file/comlicatedFallDown.kt +++ b/tests/testData/ast/switch/file/comlicatedFallDown.kt @@ -1,88 +1,88 @@ -package demo -public open class SwitchDemo() { -class object { -public open fun print(o : Any?) : Unit { -System.out?.println(o) -} -public open fun test(i : Int) : Unit { -var monthString : String? = "" -when (i) { -1 -> { -print(1) -print(2) -print(3) -print(4) -print(5) -} -2 -> { -print(2) -print(3) -print(4) -print(5) -} -3 -> { -print(3) -print(4) -print(5) -} -4 -> { -print(4) -print(5) -} -5 -> { -print(5) -} -6 -> { -print(6) -print(7) -print(8) -print(9) -print(10) -print(11) -monthString = "December" -} -7 -> { -print(7) -print(8) -print(9) -print(10) -print(11) -monthString = "December" -} -8 -> { -print(8) -print(9) -print(10) -print(11) -monthString = "December" -} -9 -> { -print(9) -print(10) -print(11) -monthString = "December" -} -10 -> { -print(10) -print(11) -monthString = "December" -} -11 -> { -print(11) -monthString = "December" -} -12 -> { -monthString = "December" -} -else -> { -monthString = "Invalid month" -} -} -System.out?.println(monthString) -} -public open fun main(args : Array?) : Unit { -for (i in 1..12) test(i) -} -} -} +package demo +public open class SwitchDemo() { +class object { +public open fun print(o : Any?) : Unit { +System.out?.println(o) +} +public open fun test(i : Int) : Unit { +var monthString : String? = "" +when (i) { +1 -> { +print(1) +print(2) +print(3) +print(4) +print(5) +} +2 -> { +print(2) +print(3) +print(4) +print(5) +} +3 -> { +print(3) +print(4) +print(5) +} +4 -> { +print(4) +print(5) +} +5 -> { +print(5) +} +6 -> { +print(6) +print(7) +print(8) +print(9) +print(10) +print(11) +monthString = "December" +} +7 -> { +print(7) +print(8) +print(9) +print(10) +print(11) +monthString = "December" +} +8 -> { +print(8) +print(9) +print(10) +print(11) +monthString = "December" +} +9 -> { +print(9) +print(10) +print(11) +monthString = "December" +} +10 -> { +print(10) +print(11) +monthString = "December" +} +11 -> { +print(11) +monthString = "December" +} +12 -> { +monthString = "December" +} +else -> { +monthString = "Invalid month" +} +} +System.out?.println(monthString) +} +public open fun main(args : Array?) : Unit { +for (i in 1..12) test(i) +} +} +} fun main(args : Array?) = SwitchDemo.main(args) \ No newline at end of file diff --git a/tests/testData/ast/switch/file/fallDown.kt b/tests/testData/ast/switch/file/fallDown.kt index 64c48e85d5e..e27df742d64 100644 --- a/tests/testData/ast/switch/file/fallDown.kt +++ b/tests/testData/ast/switch/file/fallDown.kt @@ -1,19 +1,19 @@ -package switch_demo -public open class SwitchDemo() { -class object { -public open fun main(args : Array?) : Unit { -var month : Int = 8 -var monthString : String? -when (month) { -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 -> { -monthString = "December" -} -else -> { -monthString = "Invalid month" -} -} -System.out?.println(monthString) -} -} -} +package switch_demo +public open class SwitchDemo() { +class object { +public open fun main(args : Array?) : Unit { +var month : Int = 8 +var monthString : String? +when (month) { +1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 -> { +monthString = "December" +} +else -> { +monthString = "Invalid month" +} +} +System.out?.println(monthString) +} +} +} fun main(args : Array?) = SwitchDemo.main(args) \ No newline at end of file diff --git a/tests/testData/ast/switch/file/kt-539.kt b/tests/testData/ast/switch/file/kt-539.kt index b7c37eaf387..aa9105769d8 100644 --- a/tests/testData/ast/switch/file/kt-539.kt +++ b/tests/testData/ast/switch/file/kt-539.kt @@ -1,52 +1,52 @@ -package switch_demo -public open class SwitchDemo() { -class object { -public open fun main(args : Array?) : Unit { -var month : Int = 8 -var monthString : String? -when (month) { -1 -> { -monthString = "January" -} -2 -> { -monthString = "February" -} -3 -> { -monthString = "March" -} -4 -> { -monthString = "April" -} -5 -> { -monthString = "May" -} -6 -> { -monthString = "June" -} -7 -> { -monthString = "July" -} -8 -> { -monthString = "August" -} -9 -> { -monthString = "September" -} -10 -> { -monthString = "October" -} -11 -> { -monthString = "November" -} -12 -> { -monthString = "December" -} -else -> { -monthString = "Invalid month" -} -} -System.out?.println(monthString) -} -} -} +package switch_demo +public open class SwitchDemo() { +class object { +public open fun main(args : Array?) : Unit { +var month : Int = 8 +var monthString : String? +when (month) { +1 -> { +monthString = "January" +} +2 -> { +monthString = "February" +} +3 -> { +monthString = "March" +} +4 -> { +monthString = "April" +} +5 -> { +monthString = "May" +} +6 -> { +monthString = "June" +} +7 -> { +monthString = "July" +} +8 -> { +monthString = "August" +} +9 -> { +monthString = "September" +} +10 -> { +monthString = "October" +} +11 -> { +monthString = "November" +} +12 -> { +monthString = "December" +} +else -> { +monthString = "Invalid month" +} +} +System.out?.println(monthString) +} +} +} fun main(args : Array?) = SwitchDemo.main(args) \ No newline at end of file diff --git a/tests/testData/ast/synchronizedStatement/statement/singleLineExample.kt b/tests/testData/ast/synchronizedStatement/statement/singleLineExample.kt index f8c00c2d9cd..6665fbbba33 100644 --- a/tests/testData/ast/synchronizedStatement/statement/singleLineExample.kt +++ b/tests/testData/ast/synchronizedStatement/statement/singleLineExample.kt @@ -1,3 +1,3 @@ -synchronized (s) { -doSomething(s) +synchronized (s) { +doSomething(s) } \ No newline at end of file diff --git a/tests/testData/ast/thisExpression/file/classAdotThisFoo.kt b/tests/testData/ast/thisExpression/file/classAdotThisFoo.kt index 4956f6eaad0..615b3b5dc0a 100644 --- a/tests/testData/ast/thisExpression/file/classAdotThisFoo.kt +++ b/tests/testData/ast/thisExpression/file/classAdotThisFoo.kt @@ -1,11 +1,11 @@ -open class Base() { -open fun foo() : Unit { -} -} -open class A() : Base() { -open class C() { -open fun test() : Unit { -this@A.foo() -} -} +open class Base() { +open fun foo() : Unit { +} +} +open class A() : Base() { +open class C() { +open fun test() : Unit { +this@A.foo() +} +} } \ No newline at end of file diff --git a/tests/testData/ast/trait/class/abstactInterface.kt b/tests/testData/ast/trait/class/abstactInterface.kt index dba106cf0f2..97c0b5c0bed 100644 --- a/tests/testData/ast/trait/class/abstactInterface.kt +++ b/tests/testData/ast/trait/class/abstactInterface.kt @@ -1,2 +1,2 @@ -abstract trait I { +abstract trait I { } \ No newline at end of file diff --git a/tests/testData/ast/trait/class/emptyInterface.kt b/tests/testData/ast/trait/class/emptyInterface.kt index 549f15fa37a..670cabdb241 100644 --- a/tests/testData/ast/trait/class/emptyInterface.kt +++ b/tests/testData/ast/trait/class/emptyInterface.kt @@ -1,2 +1,2 @@ -trait A { +trait A { } \ No newline at end of file diff --git a/tests/testData/ast/trait/class/extendsOneClassAndImplementsSeveralInterfaces.kt b/tests/testData/ast/trait/class/extendsOneClassAndImplementsSeveralInterfaces.kt index aba2655ddea..3bbc299803d 100644 --- a/tests/testData/ast/trait/class/extendsOneClassAndImplementsSeveralInterfaces.kt +++ b/tests/testData/ast/trait/class/extendsOneClassAndImplementsSeveralInterfaces.kt @@ -1,2 +1,2 @@ -trait A : I0, I1, I2 { +trait A : I0, I1, I2 { } \ No newline at end of file diff --git a/tests/testData/ast/trait/class/extendsOneInterface.kt b/tests/testData/ast/trait/class/extendsOneInterface.kt index eebabe79c39..a5d59a56576 100644 --- a/tests/testData/ast/trait/class/extendsOneInterface.kt +++ b/tests/testData/ast/trait/class/extendsOneInterface.kt @@ -1,2 +1,2 @@ -trait A : I { +trait A : I { } \ No newline at end of file diff --git a/tests/testData/ast/trait/class/interfaceWithFields.kt b/tests/testData/ast/trait/class/interfaceWithFields.kt index 22feead449c..f8fdfeacaf4 100644 --- a/tests/testData/ast/trait/class/interfaceWithFields.kt +++ b/tests/testData/ast/trait/class/interfaceWithFields.kt @@ -1,7 +1,7 @@ -trait INode { -class object { -val IN : String = "in" -val AT : String = "@" -val COMMA_WITH_SPACE : String? = COMMA + SPACE -} +trait INode { +class object { +val IN : String = "in" +val AT : String = "@" +val COMMA_WITH_SPACE : String? = COMMA + SPACE +} } \ No newline at end of file diff --git a/tests/testData/ast/trait/class/interfaceWithMethodDeclaration.kt b/tests/testData/ast/trait/class/interfaceWithMethodDeclaration.kt index 560cab9d45a..aff8b40c610 100644 --- a/tests/testData/ast/trait/class/interfaceWithMethodDeclaration.kt +++ b/tests/testData/ast/trait/class/interfaceWithMethodDeclaration.kt @@ -1,4 +1,4 @@ -trait INode { -open fun getTag() : Tag? -open fun toKotlin() : String? +trait INode { +open fun getTag() : Tag? +open fun toKotlin() : String? } \ No newline at end of file diff --git a/tests/testData/ast/trait/class/interfaceWithStaticFields.kt b/tests/testData/ast/trait/class/interfaceWithStaticFields.kt index d991ddf2892..0f1ab7c26f1 100644 --- a/tests/testData/ast/trait/class/interfaceWithStaticFields.kt +++ b/tests/testData/ast/trait/class/interfaceWithStaticFields.kt @@ -1,7 +1,7 @@ -public trait INode { -class object { -public val IN : String = "in" -public val AT : String = "@" -public val COMMA_WITH_SPACE : String? = COMMA + SPACE -} +public trait INode { +class object { +public val IN : String = "in" +public val AT : String = "@" +public val COMMA_WITH_SPACE : String? = COMMA + SPACE +} } \ No newline at end of file diff --git a/tests/testData/ast/trait/class/internalInterface.kt b/tests/testData/ast/trait/class/internalInterface.kt index d13645c059f..802809a5724 100644 --- a/tests/testData/ast/trait/class/internalInterface.kt +++ b/tests/testData/ast/trait/class/internalInterface.kt @@ -1,2 +1,2 @@ -trait Test { +trait Test { } \ No newline at end of file diff --git a/tests/testData/ast/trait/class/privateInterface.kt b/tests/testData/ast/trait/class/privateInterface.kt index 37018e058af..72942402d0b 100644 --- a/tests/testData/ast/trait/class/privateInterface.kt +++ b/tests/testData/ast/trait/class/privateInterface.kt @@ -1,2 +1,2 @@ -private trait Test { +private trait Test { } \ No newline at end of file diff --git a/tests/testData/ast/trait/class/protectedInterface.kt b/tests/testData/ast/trait/class/protectedInterface.kt index 3a62403e685..359d3b99929 100644 --- a/tests/testData/ast/trait/class/protectedInterface.kt +++ b/tests/testData/ast/trait/class/protectedInterface.kt @@ -1,2 +1,2 @@ -protected trait Test { +protected trait Test { } \ No newline at end of file diff --git a/tests/testData/ast/trait/class/publicInterface.kt b/tests/testData/ast/trait/class/publicInterface.kt index bb4bd3f780f..14565fbd6b3 100644 --- a/tests/testData/ast/trait/class/publicInterface.kt +++ b/tests/testData/ast/trait/class/publicInterface.kt @@ -1,2 +1,2 @@ -public trait Test { +public trait Test { } \ No newline at end of file diff --git a/tests/testData/ast/tryStatement/statement/commonCaseForTryStatement.kt b/tests/testData/ast/tryStatement/statement/commonCaseForTryStatement.kt index 97e0efb08e3..ce5da7da296 100644 --- a/tests/testData/ast/tryStatement/statement/commonCaseForTryStatement.kt +++ b/tests/testData/ast/tryStatement/statement/commonCaseForTryStatement.kt @@ -1,14 +1,14 @@ -try -{ -callMethod(params) -} -catch (e : Exception) { -println(1) -} -catch (e : IOException) { -println(0) -} -finally -{ -println(3) +try +{ +callMethod(params) +} +catch (e : Exception) { +println(1) +} +catch (e : IOException) { +println(0) +} +finally +{ +println(3) } \ No newline at end of file diff --git a/tests/testData/ast/tryStatement/statement/emptyTryWithTwoCatchesWithEmptyFinally.kt b/tests/testData/ast/tryStatement/statement/emptyTryWithTwoCatchesWithEmptyFinally.kt index da8e67915a0..40e83f0667f 100644 --- a/tests/testData/ast/tryStatement/statement/emptyTryWithTwoCatchesWithEmptyFinally.kt +++ b/tests/testData/ast/tryStatement/statement/emptyTryWithTwoCatchesWithEmptyFinally.kt @@ -1,12 +1,12 @@ -try -{ -} -catch (e : Exception) { -println(1) -} -catch (e : IOException) { -println(0) -} -finally -{ +try +{ +} +catch (e : Exception) { +println(1) +} +catch (e : IOException) { +println(0) +} +finally +{ } \ No newline at end of file diff --git a/tests/testData/ast/tryStatement/statement/emptyTryWithTwoCatchesWithFinally.kt b/tests/testData/ast/tryStatement/statement/emptyTryWithTwoCatchesWithFinally.kt index bf23b61c5d5..92e60f280d4 100644 --- a/tests/testData/ast/tryStatement/statement/emptyTryWithTwoCatchesWithFinally.kt +++ b/tests/testData/ast/tryStatement/statement/emptyTryWithTwoCatchesWithFinally.kt @@ -1,13 +1,13 @@ -try -{ -} -catch (e : Exception) { -println(1) -} -catch (e : IOException) { -println(0) -} -finally -{ -println(3) +try +{ +} +catch (e : Exception) { +println(1) +} +catch (e : IOException) { +println(0) +} +finally +{ +println(3) } \ No newline at end of file diff --git a/tests/testData/ast/tryStatement/statement/emptyTryWithTwoCatchesWithoutFinally.kt b/tests/testData/ast/tryStatement/statement/emptyTryWithTwoCatchesWithoutFinally.kt index 9d98b8278e1..2f5deb07c0b 100644 --- a/tests/testData/ast/tryStatement/statement/emptyTryWithTwoCatchesWithoutFinally.kt +++ b/tests/testData/ast/tryStatement/statement/emptyTryWithTwoCatchesWithoutFinally.kt @@ -1,9 +1,9 @@ -try -{ -} -catch (e : Exception) { -println(1) -} -catch (e : IOException) { -println(0) +try +{ +} +catch (e : Exception) { +println(1) +} +catch (e : IOException) { +println(0) } \ No newline at end of file diff --git a/tests/testData/ast/typeParameters/class/classDoubleParametrizationWithTwoBoundsWithExtending.kt b/tests/testData/ast/typeParameters/class/classDoubleParametrizationWithTwoBoundsWithExtending.kt index 52746a3168b..f40a6cda574 100644 --- a/tests/testData/ast/typeParameters/class/classDoubleParametrizationWithTwoBoundsWithExtending.kt +++ b/tests/testData/ast/typeParameters/class/classDoubleParametrizationWithTwoBoundsWithExtending.kt @@ -1,2 +1,2 @@ -class CC() : A() where T : Comparable?, K : Collection? { +class CC() : A() where T : Comparable?, K : Collection? { } \ No newline at end of file diff --git a/tests/testData/ast/typeParameters/class/classParametrizationWithTwoBounds.kt b/tests/testData/ast/typeParameters/class/classParametrizationWithTwoBounds.kt index cff642a5829..e6fa0f4ce21 100644 --- a/tests/testData/ast/typeParameters/class/classParametrizationWithTwoBounds.kt +++ b/tests/testData/ast/typeParameters/class/classParametrizationWithTwoBounds.kt @@ -1,2 +1,2 @@ -class C() where T : Comparable? { +class C() where T : Comparable? { } \ No newline at end of file diff --git a/tests/testData/ast/typeParameters/class/classParametrizationWithTwoBoundsWithExtending.kt b/tests/testData/ast/typeParameters/class/classParametrizationWithTwoBoundsWithExtending.kt index 31037f0e57a..e05e75db415 100644 --- a/tests/testData/ast/typeParameters/class/classParametrizationWithTwoBoundsWithExtending.kt +++ b/tests/testData/ast/typeParameters/class/classParametrizationWithTwoBoundsWithExtending.kt @@ -1,2 +1,2 @@ -class C() : A() where T : Comparable? { +class C() : A() where T : Comparable? { } \ No newline at end of file diff --git a/tests/testData/ast/typeParameters/class/complexExampleWithClassExtending.kt b/tests/testData/ast/typeParameters/class/complexExampleWithClassExtending.kt index b22bbbcd177..077c6618b24 100644 --- a/tests/testData/ast/typeParameters/class/complexExampleWithClassExtending.kt +++ b/tests/testData/ast/typeParameters/class/complexExampleWithClassExtending.kt @@ -1,2 +1,2 @@ -trait CommandHandler { +trait CommandHandler { } \ No newline at end of file diff --git a/tests/testData/ast/typeParameters/class/complexExampleWithClassMultiplyExtending.kt b/tests/testData/ast/typeParameters/class/complexExampleWithClassMultiplyExtending.kt index a132e4f8bd9..4c3fd7537b6 100644 --- a/tests/testData/ast/typeParameters/class/complexExampleWithClassMultiplyExtending.kt +++ b/tests/testData/ast/typeParameters/class/complexExampleWithClassMultiplyExtending.kt @@ -1,2 +1,2 @@ -trait CommandHandler { +trait CommandHandler { } \ No newline at end of file diff --git a/tests/testData/ast/typeParameters/class/genericClass.kt b/tests/testData/ast/typeParameters/class/genericClass.kt index 9a6063c348c..dd8d1147200 100644 --- a/tests/testData/ast/typeParameters/class/genericClass.kt +++ b/tests/testData/ast/typeParameters/class/genericClass.kt @@ -1,2 +1,2 @@ -class Comparable() { +class Comparable() { } \ No newline at end of file diff --git a/tests/testData/ast/typeParameters/class/traitDoubleParametrizationWithTwoBoundsWithExtending.kt b/tests/testData/ast/typeParameters/class/traitDoubleParametrizationWithTwoBoundsWithExtending.kt index 57fea19b2c7..f73bbabea8b 100644 --- a/tests/testData/ast/typeParameters/class/traitDoubleParametrizationWithTwoBoundsWithExtending.kt +++ b/tests/testData/ast/typeParameters/class/traitDoubleParametrizationWithTwoBoundsWithExtending.kt @@ -1,2 +1,2 @@ -trait I : II where T : Comparable?, K : Collection? { +trait I : II where T : Comparable?, K : Collection? { } \ No newline at end of file diff --git a/tests/testData/ast/typeParameters/method/methodDoubleParametrizationWithTwoBounds.kt b/tests/testData/ast/typeParameters/method/methodDoubleParametrizationWithTwoBounds.kt index 09103a8d9d4..21f892b7d8d 100644 --- a/tests/testData/ast/typeParameters/method/methodDoubleParametrizationWithTwoBounds.kt +++ b/tests/testData/ast/typeParameters/method/methodDoubleParametrizationWithTwoBounds.kt @@ -1,2 +1,2 @@ -fun max(coll : Collection?) : T? where T : Comparable?, K : Collection? { +fun max(coll : Collection?) : T? where T : Comparable?, K : Collection? { } \ No newline at end of file diff --git a/tests/testData/ast/typeParameters/method/where.kt b/tests/testData/ast/typeParameters/method/where.kt index 6283664079b..6a1ccaeeec6 100644 --- a/tests/testData/ast/typeParameters/method/where.kt +++ b/tests/testData/ast/typeParameters/method/where.kt @@ -1,2 +1,2 @@ -fun max(coll : Collection?) : T? where T : Comparable? { +fun max(coll : Collection?) : T? where T : Comparable? { } \ No newline at end of file diff --git a/tests/testData/ast/varArg/method/ellipsisTypeSingleParams.kt b/tests/testData/ast/varArg/method/ellipsisTypeSingleParams.kt index d6f51ef1270..5219629e1e3 100644 --- a/tests/testData/ast/varArg/method/ellipsisTypeSingleParams.kt +++ b/tests/testData/ast/varArg/method/ellipsisTypeSingleParams.kt @@ -1,2 +1,2 @@ -fun pushAll(vararg objs : Any?) : Unit { +fun pushAll(vararg objs : Any?) : Unit { } \ No newline at end of file diff --git a/tests/testData/ast/whileStatement/statement/whileWithBlock.kt b/tests/testData/ast/whileStatement/statement/whileWithBlock.kt index 30b97616a1b..88e9992f59a 100644 --- a/tests/testData/ast/whileStatement/statement/whileWithBlock.kt +++ b/tests/testData/ast/whileStatement/statement/whileWithBlock.kt @@ -1,5 +1,5 @@ -while (a > b) -{ -var i : Int = 1 -i = i + 1 +while (a > b) +{ +var i : Int = 1 +i = i + 1 } \ No newline at end of file diff --git a/tests/testData/ast/whileStatement/statement/whileWithEmptyBlock.kt b/tests/testData/ast/whileStatement/statement/whileWithEmptyBlock.kt index bd7461448e0..7c69899ce77 100644 --- a/tests/testData/ast/whileStatement/statement/whileWithEmptyBlock.kt +++ b/tests/testData/ast/whileStatement/statement/whileWithEmptyBlock.kt @@ -1,3 +1,3 @@ -while (true) -{ +while (true) +{ } \ No newline at end of file diff --git a/tests/testData/ast/whileStatement/statement/whileWithExpression.kt b/tests/testData/ast/whileStatement/statement/whileWithExpression.kt index ca00a409410..fd2a7536a52 100644 --- a/tests/testData/ast/whileStatement/statement/whileWithExpression.kt +++ b/tests/testData/ast/whileStatement/statement/whileWithExpression.kt @@ -1,2 +1,2 @@ -while (true) +while (true) i = i + 1 \ No newline at end of file diff --git a/tests/testData/ast/whileStatement/statement/whileWithReturn.kt b/tests/testData/ast/whileStatement/statement/whileWithReturn.kt index 29b446b5b2e..ec1e88ceed8 100644 --- a/tests/testData/ast/whileStatement/statement/whileWithReturn.kt +++ b/tests/testData/ast/whileStatement/statement/whileWithReturn.kt @@ -1,2 +1,2 @@ -while (true) +while (true) return 1 \ No newline at end of file