comments processing finished
This commit is contained in:
committed by
Pavel V. Talanov
parent
4bb3731272
commit
5664283a30
@@ -93,21 +93,32 @@ public open class Converter() {
|
||||
}
|
||||
|
||||
public open fun anonymousClassToAnonymousClass(anonymousClass: PsiAnonymousClass): AnonymousClass {
|
||||
return AnonymousClass(this, getMembers(anonymousClass, false))
|
||||
return AnonymousClass(this, getMembers(anonymousClass))
|
||||
}
|
||||
|
||||
private fun getMembers(psiClass: PsiClass, takeDocComments: Boolean): List<Node> {
|
||||
private fun getMembers(psiClass: PsiClass): List<Node> {
|
||||
val members: List<Node> = arrayList()
|
||||
val lbraceOffset = psiClass.getLBrace()?.getTextRange()?.getStartOffset() ?: 0
|
||||
for (e : PsiElement? in psiClass.getChildren()) {
|
||||
val isDocComment = e?.getTextRange()?.getStartOffset() ?: 0 < lbraceOffset
|
||||
if (isDocComment != takeDocComments) continue
|
||||
if (isDocComment) continue
|
||||
val converted = memberToMember(e, psiClass)
|
||||
if (converted != null) members.add(converted)
|
||||
}
|
||||
return members
|
||||
}
|
||||
|
||||
private fun getDocComments(element: PsiElement): List<Node> {
|
||||
val comments: List<Node> = 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)
|
||||
@@ -125,8 +136,8 @@ public open class Converter() {
|
||||
val extendsTypes: List<Type> = typesToNotNullableTypeList(psiClass.getExtendsListTypes())
|
||||
val name: Identifier = Identifier(psiClass.getName()!!)
|
||||
val baseClassParams: List<Expression> = arrayList()
|
||||
val members: List<Node> = getMembers(psiClass, false)
|
||||
val docComments = getMembers(psiClass, true)
|
||||
val members: List<Node> = getMembers(psiClass)
|
||||
val docComments = getDocComments(psiClass)
|
||||
val visitor: SuperVisitor = SuperVisitor()
|
||||
psiClass.accept(visitor)
|
||||
val resolvedSuperCallParameters = visitor.resolvedSuperCallParameters
|
||||
@@ -146,8 +157,8 @@ public open class Converter() {
|
||||
val init: String = getDefaultInitializer(fo)
|
||||
initializers.put(fo.identifier.toKotlin(), init)
|
||||
}
|
||||
val newStatements: List<Statement> = arrayList()
|
||||
for (s : Statement? in m.block!!.statements) {
|
||||
val newStatements: List<Element> = arrayList()
|
||||
for (s in m.block!!.statements) {
|
||||
var isRemoved: Boolean = false
|
||||
if (s is AssignmentExpression) {
|
||||
val assignee = s.left
|
||||
@@ -165,7 +176,7 @@ public open class Converter() {
|
||||
}
|
||||
|
||||
if (!isRemoved) {
|
||||
newStatements.add(s!!)
|
||||
newStatements.add(s)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -174,7 +185,7 @@ public open class Converter() {
|
||||
}
|
||||
}
|
||||
}
|
||||
members.add(Constructor(Identifier.EMPTY_IDENTIFIER, Collections.emptySet<String>()!!,
|
||||
members.add(Constructor(Identifier.EMPTY_IDENTIFIER, arrayList(), Collections.emptySet<String>()!!,
|
||||
ClassType(name, Collections.emptyList<Element>()!!, false),
|
||||
Collections.emptyList<Element>()!!,
|
||||
ParameterList(createParametersFromFields(finalOrWithEmptyInitializer)),
|
||||
@@ -203,14 +214,17 @@ public open class Converter() {
|
||||
|
||||
private fun fieldToField(field: PsiField, psiClass: PsiClass?): Field {
|
||||
val modifiers: Set<String> = modifiersListToModifiersSet(field.getModifierList())
|
||||
if (field is PsiEnumConstant?) {
|
||||
val docComments = getDocComments(field)
|
||||
if (field is PsiEnumConstant) {
|
||||
return EnumConstant(Identifier(field.getName()!!),
|
||||
docComments,
|
||||
modifiers,
|
||||
typeToType(field.getType()),
|
||||
elementToElement(field.getArgumentList()))
|
||||
}
|
||||
|
||||
return Field(Identifier(field.getName()!!),
|
||||
docComments,
|
||||
modifiers,
|
||||
typeToType(field.getType()),
|
||||
expressionToExpression(field.getInitializer(), field.getType()),
|
||||
@@ -237,8 +251,9 @@ public open class Converter() {
|
||||
blockToBlock(method.getBody(), notEmpty))
|
||||
|
||||
val params: Element = createFunctionParameters(method)
|
||||
val typeParameters: List<Element> = elementsToElementList(method.getTypeParameters())
|
||||
val modifiers: Set<String> = modifiersListToModifiersSet(method.getModifierList())
|
||||
val typeParameters = elementsToElementList(method.getTypeParameters())
|
||||
val modifiers = modifiersListToModifiersSet(method.getModifierList())
|
||||
val docComments = getDocComments(method)
|
||||
if (isOverrideAnyMethodExceptMethodsFromObject(method)) {
|
||||
modifiers.add(Modifier.OVERRIDE)
|
||||
}
|
||||
@@ -254,10 +269,11 @@ public open class Converter() {
|
||||
|
||||
if (method.isConstructor()) {
|
||||
val isPrimary: Boolean = isConstructorPrimary(method)
|
||||
return Constructor(identifier, modifiers, returnType, typeParameters, params, Block(removeEmpty(body.statements), false), isPrimary)
|
||||
return Constructor(identifier, docComments, modifiers, returnType, typeParameters, params,
|
||||
Block(removeEmpty(body.statements), false), isPrimary)
|
||||
}
|
||||
|
||||
return Function(identifier, modifiers, returnType, typeParameters, params, body)
|
||||
return Function(identifier, docComments, modifiers, returnType, typeParameters, params, body)
|
||||
}
|
||||
|
||||
private fun createFunctionParameters(method: PsiMethod): ParameterList {
|
||||
@@ -303,22 +319,22 @@ public open class Converter() {
|
||||
if (block == null)
|
||||
return Block.EMPTY_BLOCK
|
||||
|
||||
return Block(statementsToStatementList(block.getStatements()), notEmpty)
|
||||
return Block(block.getChildren().map { statementToStatement(it) }, notEmpty)
|
||||
}
|
||||
|
||||
public open fun blockToBlock(block: PsiCodeBlock?): Block {
|
||||
return blockToBlock(block, true)
|
||||
}
|
||||
|
||||
public open fun statementsToStatementList(statements: Array<PsiStatement?>): List<Statement> {
|
||||
public open fun statementsToStatementList(statements: Array<PsiElement?>): List<Element> {
|
||||
return statements.map { statementToStatement(it) }
|
||||
}
|
||||
|
||||
public open fun statementsToStatementList(statements: List<PsiStatement?>): List<Statement> {
|
||||
public open fun statementsToStatementList(statements: List<PsiElement?>): List<Element> {
|
||||
return statements.map { statementToStatement(it) }
|
||||
}
|
||||
|
||||
public open fun statementToStatement(s: PsiStatement?): Statement {
|
||||
public open fun statementToStatement(s: PsiElement?): Element {
|
||||
if (s == null)
|
||||
return Statement.EMPTY_STATEMENT
|
||||
|
||||
@@ -487,8 +503,8 @@ public open class Converter() {
|
||||
return fields.map { Parameter(Identifier("_" + it.identifier.name), it.`type`, true) }
|
||||
}
|
||||
|
||||
private fun createInitStatementsFromFields(fields: List<out Field>): List<Statement> {
|
||||
val result: List<Statement> = arrayList()
|
||||
private fun createInitStatementsFromFields(fields: List<out Field>): List<Element> {
|
||||
val result: List<Element> = arrayList()
|
||||
for (f : Field in fields) {
|
||||
val identifierToKotlin: String? = f.identifier.toKotlin()
|
||||
result.add(DummyStringExpression(identifierToKotlin + " = " + "_" + identifierToKotlin))
|
||||
@@ -545,8 +561,10 @@ public open class Converter() {
|
||||
|
||||
return false
|
||||
}
|
||||
private fun removeEmpty(statements: List<Statement>): List<Statement> {
|
||||
return statements.filterNot { it == Statement.EMPTY_STATEMENT || it == Expression.EMPTY_EXPRESSION }
|
||||
private fun removeEmpty(statements: List<Element>): List<Element> {
|
||||
return statements.filterNot { it == Statement.EMPTY_STATEMENT ||
|
||||
it == Expression.EMPTY_EXPRESSION ||
|
||||
it == Element.EMPTY_ELEMENT }
|
||||
}
|
||||
|
||||
private fun isNotOpenMethod(method: PsiMethod): Boolean {
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.jetbrains.jet.j2k.ast
|
||||
import java.util.LinkedList
|
||||
import java.util.List
|
||||
|
||||
public open class Block(val statements: List<Statement>, val notEmpty: Boolean = false): Statement() {
|
||||
public open class Block(val statements: List<Element>, val notEmpty: Boolean = false): Statement() {
|
||||
public override fun isEmpty(): Boolean {
|
||||
return !notEmpty && statements.size() == 0
|
||||
}
|
||||
|
||||
@@ -62,13 +62,13 @@ public open class Class(converter : Converter,
|
||||
private fun constructorToInit(f: Function): Function {
|
||||
val modifiers : Set<String> = HashSet<String>(f.getModifiers())
|
||||
modifiers.add(Modifier.STATIC)
|
||||
val statements : List<Statement> = f.block?.statements ?: arrayList()
|
||||
val statements : List<Element> = f.block?.statements ?: arrayList()
|
||||
statements.add(ReturnStatement(Identifier("__")))
|
||||
val block : Block = Block(statements)
|
||||
val block = Block(statements)
|
||||
val constructorTypeParameters : List<Element> = arrayList()
|
||||
constructorTypeParameters.addAll(typeParameters)
|
||||
constructorTypeParameters.addAll(f.typeParameters)
|
||||
return Function(Identifier("init"), modifiers, ClassType(name, constructorTypeParameters, false),
|
||||
return Function(Identifier("init"), arrayList(), modifiers, ClassType(name, constructorTypeParameters, false),
|
||||
constructorTypeParameters, f.params, block)
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ public open class Class(converter : Converter,
|
||||
}
|
||||
|
||||
open fun implementTypesToKotlin() : String {
|
||||
val allTypes : List<String?> = arrayList()
|
||||
val allTypes : List<String> = arrayList()
|
||||
allTypes.addAll(baseClassSignatureWithParams())
|
||||
allTypes.addAll(implementsTypes.map { it.toKotlin() })
|
||||
return if (allTypes.size() == 0)
|
||||
|
||||
@@ -5,12 +5,13 @@ import java.util.Set
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
public open class Constructor(identifier : Identifier,
|
||||
docComments: List<Node>,
|
||||
modifiers : Set<String>,
|
||||
`type` : Type,
|
||||
typeParameters : List<Element>,
|
||||
params : Element,
|
||||
block : Block,
|
||||
val isPrimary : Boolean) : Function(identifier, modifiers, `type`, typeParameters, params, block) {
|
||||
val isPrimary : Boolean) : Function(identifier, docComments, modifiers, `type`, typeParameters, params, block) {
|
||||
|
||||
public open fun primarySignatureToKotlin() : String {
|
||||
return "(" + params.toKotlin() + ")"
|
||||
|
||||
@@ -2,11 +2,13 @@ package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import java.util.Set
|
||||
import java.util.List
|
||||
|
||||
public open class EnumConstant(identifier : Identifier,
|
||||
docComments: List<Node>,
|
||||
modifiers : Set<String>,
|
||||
`type` : Type,
|
||||
params : Element) : Field(identifier, modifiers, `type`.convertedToNotNull(), params, 0) {
|
||||
params : Element) : Field(identifier, docComments, modifiers, `type`.convertedToNotNull(), params, 0) {
|
||||
|
||||
public override fun toKotlin() : String {
|
||||
if (initializer.toKotlin().isEmpty()) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.Set
|
||||
import org.jetbrains.jet.j2k.Converter
|
||||
|
||||
public open class Field(val identifier : Identifier,
|
||||
val docComments: List<Node>,
|
||||
modifiers : Set<String>,
|
||||
val `type` : Type,
|
||||
val initializer : Element,
|
||||
@@ -37,7 +38,8 @@ public open class Field(val identifier : Identifier,
|
||||
}
|
||||
|
||||
public override fun toKotlin() : String {
|
||||
val declaration : String? = modifiersToKotlin() + identifier.toKotlin() + " : " + `type`.toKotlin()
|
||||
val declaration : String = docComments.toKotlin("\n", "", "\n") +
|
||||
modifiersToKotlin() + identifier.toKotlin() + " : " + `type`.toKotlin()
|
||||
if (initializer.isEmpty()) {
|
||||
return declaration + ((if (isVal() && !isStatic() && writingAccesses == 1)
|
||||
""
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.Set
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
public open class Function(val name : Identifier,
|
||||
val docComments: List<Node>,
|
||||
modifiers : Set<String>,
|
||||
val `type` : Type,
|
||||
val typeParameters : List<Element>,
|
||||
@@ -33,18 +34,15 @@ public open class Function(val name : Identifier,
|
||||
open fun modifiersToKotlin() : String {
|
||||
val modifierList: List<String> = arrayList()
|
||||
val accessModifier : String = accessModifier()
|
||||
if (!accessModifier.isEmpty())
|
||||
{
|
||||
if (!accessModifier.isEmpty()) {
|
||||
modifierList.add(accessModifier)
|
||||
}
|
||||
|
||||
if (isAbstract())
|
||||
{
|
||||
if (isAbstract()) {
|
||||
modifierList.add(Modifier.ABSTRACT)
|
||||
}
|
||||
|
||||
if (myModifiers.contains(Modifier.OVERRIDE))
|
||||
{
|
||||
if (myModifiers.contains(Modifier.OVERRIDE)) {
|
||||
modifierList.add(Modifier.OVERRIDE)
|
||||
}
|
||||
|
||||
@@ -56,13 +54,11 @@ public open class Function(val name : Identifier,
|
||||
modifierList.add(Modifier.OPEN)
|
||||
}
|
||||
|
||||
if (myModifiers.contains(Modifier.NOT_OPEN))
|
||||
{
|
||||
if (myModifiers.contains(Modifier.NOT_OPEN)) {
|
||||
modifierList.remove(Modifier.OPEN)
|
||||
}
|
||||
|
||||
if (modifierList.size() > 0)
|
||||
{
|
||||
if (modifierList.size() > 0) {
|
||||
return modifierList.makeString(" ") + " "
|
||||
}
|
||||
|
||||
@@ -70,7 +66,12 @@ public open class Function(val name : Identifier,
|
||||
}
|
||||
|
||||
public override fun toKotlin() : String {
|
||||
return modifiersToKotlin() + "fun " + name.toKotlin() + typeParametersToKotlin() + "(" + params.toKotlin() + ") : " + `type`.toKotlin() + " "+ typeParameterWhereToKotlin() + block?.toKotlin()
|
||||
return docComments.toKotlin("\n", "", "\n") +
|
||||
modifiersToKotlin() +
|
||||
"fun " + name.toKotlin() +
|
||||
typeParametersToKotlin() +
|
||||
"(" + params.toKotlin() + ") : " +
|
||||
`type`.toKotlin() + " "+ typeParameterWhereToKotlin() +
|
||||
block?.toKotlin()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public open class ExpressionListStatement(val expressions: List<Expression>): Ex
|
||||
public override fun toKotlin() = expressions.toKotlin("\n")
|
||||
}
|
||||
|
||||
public open class LabelStatement(val name: Identifier, val statement: Statement): Statement() {
|
||||
public open class LabelStatement(val name: Identifier, val statement: Element): Statement() {
|
||||
public override fun toKotlin(): String = "@" + name.toKotlin() + " " + statement.toKotlin()
|
||||
}
|
||||
|
||||
@@ -36,7 +36,9 @@ public open class ReturnStatement(val expression: Expression): Statement() {
|
||||
public override fun toKotlin() = "return " + expression.toKotlin()
|
||||
}
|
||||
|
||||
public open class IfStatement(val condition: Expression, val thenStatement: Statement, val elseStatement: Statement): Expression() {
|
||||
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) {
|
||||
@@ -49,25 +51,25 @@ public open class IfStatement(val condition: Expression, val thenStatement: Stat
|
||||
|
||||
// Loops --------------------------------------------------------------------------------------------------
|
||||
|
||||
public open class WhileStatement(val condition: Expression, val statement: Statement): Statement() {
|
||||
public override fun toKotlin() = "while (" + condition.toKotlin() + ")\n" + statement.toKotlin()
|
||||
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, statement: Statement): WhileStatement(condition, statement) {
|
||||
public override fun toKotlin() = "do\n" + statement.toKotlin() + "\nwhile (" + condition.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 statement: Statement): Statement() {
|
||||
val body: Element): Statement() {
|
||||
public override fun toKotlin() = "for (" + variable.toKotlin() + " in " +
|
||||
expression.toKotlin() + ")\n" + statement.toKotlin()
|
||||
expression.toKotlin() + ")\n" + body.toKotlin()
|
||||
}
|
||||
|
||||
public open class ForeachWithRangeStatement(val identifier: Identifier,
|
||||
val start: Expression,
|
||||
val end: Expression,
|
||||
val body: Statement): Statement() {
|
||||
val body: Element): Statement() {
|
||||
public override fun toKotlin() = "for (" + identifier.toKotlin() + " in " +
|
||||
start.toKotlin() + ".." + end.toKotlin() + ") " + body.toKotlin()
|
||||
}
|
||||
@@ -105,11 +107,11 @@ public open class SwitchContainer(val expression: Expression, val caseContainers
|
||||
public override fun toKotlin() = "when (" + expression.toKotlin() + ") {\n" + caseContainers.toKotlin("\n") + "\n}"
|
||||
}
|
||||
|
||||
public open class CaseContainer(val caseStatement: List<Statement>, statements: List<Statement>): Statement() {
|
||||
public open class CaseContainer(val caseStatement: List<Element>, statements: List<Element>): Statement() {
|
||||
private val myBlock: Block
|
||||
|
||||
{
|
||||
val newStatements: List<Statement> = statements.filterNot { it is BreakStatement || it is ContinueStatement }
|
||||
val newStatements = statements.filterNot { it is BreakStatement || it is ContinueStatement }
|
||||
myBlock = Block(newStatements, false)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.List
|
||||
import org.jetbrains.jet.j2k.ConverterUtil.isAnnotatedAsNotNull
|
||||
|
||||
public open class ElementVisitor(val myConverter : Converter) : JavaElementVisitor() {
|
||||
private var myResult : Element = Element.EMPTY_ELEMENT
|
||||
protected var myResult : Element = Element.EMPTY_ELEMENT
|
||||
|
||||
public fun getConverter() : Converter {
|
||||
return myConverter
|
||||
|
||||
@@ -14,14 +14,12 @@ import java.util.List
|
||||
import com.intellij.psi.CommonClassNames.*
|
||||
|
||||
public open class ExpressionVisitor(converter: Converter): StatementVisitor(converter) {
|
||||
var myResult: Expression = Expression.EMPTY_EXPRESSION
|
||||
|
||||
public override fun visitExpression(expression: PsiExpression?): Unit {
|
||||
{
|
||||
myResult = Expression.EMPTY_EXPRESSION
|
||||
}
|
||||
|
||||
public override fun getResult(): Expression {
|
||||
return myResult
|
||||
return myResult as Expression
|
||||
}
|
||||
|
||||
public override fun visitArrayAccessExpression(expression: PsiArrayAccessExpression?): Unit {
|
||||
|
||||
@@ -12,20 +12,13 @@ import java.util.List
|
||||
import org.jetbrains.jet.j2k.ConverterUtil.countWritingAccesses
|
||||
|
||||
public open class StatementVisitor(converter: Converter): ElementVisitor(converter) {
|
||||
private var myResult: Statement = Statement.EMPTY_STATEMENT
|
||||
|
||||
public override fun getResult(): Statement {
|
||||
return myResult
|
||||
}
|
||||
|
||||
public override fun visitAssertStatement(statement: PsiAssertStatement?): Unit {
|
||||
myResult = AssertStatement(getConverter().expressionToExpression(statement?.getAssertCondition()),
|
||||
getConverter().expressionToExpression(statement?.getAssertDescription()))
|
||||
}
|
||||
|
||||
public override fun visitBlockStatement(statement: PsiBlockStatement?): Unit {
|
||||
val statements: Array<PsiStatement?> = statement?.getCodeBlock()?.getStatements()!!
|
||||
myResult = Block(getConverter().statementsToStatementList(statements), true)
|
||||
myResult = myConverter.blockToBlock(statement?.getCodeBlock(), true)
|
||||
}
|
||||
|
||||
public override fun visitBreakStatement(statement: PsiBreakStatement?): Unit {
|
||||
@@ -104,7 +97,7 @@ public open class StatementVisitor(converter: Converter): ElementVisitor(convert
|
||||
getConverter().statementToStatement(body))
|
||||
}
|
||||
else {
|
||||
var forStatements: List<Statement> = arrayList()
|
||||
var forStatements: List<Element> = arrayList()
|
||||
forStatements.add(getConverter().statementToStatement(initialization))
|
||||
forStatements.add(WhileStatement(getConverter().expressionToExpression(condition),
|
||||
Block(arrayList(getConverter().statementToStatement(body),
|
||||
@@ -145,23 +138,23 @@ public open class StatementVisitor(converter: Converter): ElementVisitor(convert
|
||||
}
|
||||
|
||||
private open fun switchBodyToCases(body: PsiCodeBlock?): List<CaseContainer> {
|
||||
val cases: List<List<PsiStatement?>> = splitToCases(body)
|
||||
val allSwitchStatements: List<PsiStatement?> = arrayList()
|
||||
val cases: List<List<PsiElement?>> = splitToCases(body)
|
||||
val allSwitchStatements: List<PsiElement?> = arrayList()
|
||||
if (body != null) {
|
||||
// TODO Arrays.asList()
|
||||
for(s in body.getStatements()) allSwitchStatements.add(s)
|
||||
}
|
||||
val result: List<CaseContainer> = arrayList()
|
||||
var pendingLabels: List<Statement> = arrayList()
|
||||
var pendingLabels: List<Element> = arrayList()
|
||||
var i: Int = 0
|
||||
for (ls : List<PsiStatement?> in cases) {
|
||||
for (ls in cases) {
|
||||
// TODO assert {(ls?.size()).sure() > 0}
|
||||
var label: PsiStatement? = ls[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<PsiStatement?> = ls.subList(1, (ls.size()))
|
||||
val slice: List<PsiElement?> = ls.subList(1, (ls.size()))
|
||||
if (!containsBreak(slice)) {
|
||||
val statements = getConverter().statementsToStatementList(slice)
|
||||
statements.addAll(getConverter().statementsToStatementList(getAllToNextBreak(allSwitchStatements, i + ls.size())))
|
||||
@@ -227,20 +220,12 @@ public open class StatementVisitor(converter: Converter): ElementVisitor(convert
|
||||
(psiElement is PsiPrefixExpression && psiElement.getOperationTokenType() == JavaTokenType.PLUSPLUS)
|
||||
}
|
||||
|
||||
private open fun containsBreak(slice: List<PsiStatement?>): Boolean {
|
||||
for (s : PsiStatement? in slice)
|
||||
if ((s is PsiBreakStatement?))
|
||||
{
|
||||
return true
|
||||
}
|
||||
private fun containsBreak(slice: List<PsiElement?>) = slice.any { it is PsiBreakStatement }
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private open fun getAllToNextBreak(allStatements: List<PsiStatement?>, start: Int): List<PsiStatement?> {
|
||||
var result: List<PsiStatement?> = LinkedList<PsiStatement?>()
|
||||
private open fun getAllToNextBreak(allStatements: List<PsiElement?>, start: Int): List<PsiElement?> {
|
||||
val result: List<PsiElement?> = arrayList()
|
||||
for (i in start..allStatements.size() - 1) {
|
||||
var s: PsiStatement? = allStatements.get(i)
|
||||
val s = allStatements.get(i)
|
||||
if (s is PsiBreakStatement || s is PsiReturnStatement) {
|
||||
return result
|
||||
}
|
||||
@@ -253,19 +238,20 @@ public open class StatementVisitor(converter: Converter): ElementVisitor(convert
|
||||
return result
|
||||
}
|
||||
|
||||
private open fun splitToCases(body: PsiCodeBlock?): List<List<PsiStatement?>> {
|
||||
val cases: List<List<PsiStatement?>> = arrayList()
|
||||
var currentCaseStatements: List<PsiStatement?> = arrayList()
|
||||
private open fun splitToCases(body: PsiCodeBlock?): List<List<PsiElement?>> {
|
||||
val cases: List<List<PsiElement?>> = arrayList()
|
||||
var currentCaseStatements: List<PsiElement?> = arrayList()
|
||||
var isFirst: Boolean = true
|
||||
if (body != null) {
|
||||
for (s : PsiStatement? in body.getStatements()) {
|
||||
if ((s is PsiSwitchLabelStatement?)) {
|
||||
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 = LinkedList<PsiStatement?>()
|
||||
currentCaseStatements = arrayList()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,17 @@ This is a block comment
|
||||
|
||||
|
||||
class C {
|
||||
// This is a comment
|
||||
// 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 comment */
|
||||
/* This is a function comment */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,3 +2,16 @@
|
||||
/*
|
||||
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 */
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user