New J2K: Cleanup
This commit is contained in:
committed by
Ilya Kirillov
parent
254179321c
commit
9ca6829bda
@@ -23,8 +23,9 @@ import com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl
|
||||
import com.intellij.psi.impl.source.tree.java.PsiNewExpressionImpl
|
||||
import com.intellij.psi.impl.source.tree.java.PsiReferenceExpressionImpl
|
||||
import org.jetbrains.kotlin.j2k.tree.*
|
||||
import org.jetbrains.kotlin.j2k.tree.conveersionCache.JKMultiverseClass
|
||||
import org.jetbrains.kotlin.j2k.tree.conveersionCache.ReferenceTargetProvider
|
||||
import org.jetbrains.kotlin.j2k.tree.multiverse.JKMDeclarationList
|
||||
import org.jetbrains.kotlin.j2k.tree.multiverse.JKMultiverseClass
|
||||
import org.jetbrains.kotlin.j2k.tree.multiverse.ReferenceTargetProvider
|
||||
import org.jetbrains.kotlin.j2k.tree.impl.*
|
||||
|
||||
|
||||
@@ -32,7 +33,7 @@ class JavaToJKTreeBuilder : ReferenceTargetProvider {
|
||||
override fun resolveClassReference(clazz: PsiClass): JKClass {
|
||||
val name = clazz.qualifiedName ?: TODO()
|
||||
return universe[name] ?: multiverse[name] ?: run {
|
||||
val clazz = JKMultiverseClass(JKNameIdentifierImpl(name), mutableListOf(), JKClass.ClassKind.CLASS, JKModifierListImpl())
|
||||
val clazz = JKMultiverseClass(JKNameIdentifierImpl(name), JKMDeclarationList(emptyList()), JKClass.ClassKind.CLASS, JKModifierListImpl())
|
||||
multiverse[name] = clazz
|
||||
clazz
|
||||
}
|
||||
@@ -41,7 +42,7 @@ class JavaToJKTreeBuilder : ReferenceTargetProvider {
|
||||
override fun resolveClassReference(identifier: String): JKClass {
|
||||
return universe[identifier] ?: multiverse[identifier] ?: run {
|
||||
val clazz =
|
||||
JKMultiverseClass(JKNameIdentifierImpl(identifier), mutableListOf(), JKClass.ClassKind.CLASS, JKModifierListImpl())
|
||||
JKMultiverseClass(JKNameIdentifierImpl(identifier), JKMDeclarationList(emptyList()), JKClass.ClassKind.CLASS, JKModifierListImpl())
|
||||
multiverse[identifier] = clazz
|
||||
clazz
|
||||
}
|
||||
@@ -252,9 +253,13 @@ class JavaToJKTreeBuilder : ReferenceTargetProvider {
|
||||
isInterface -> JKClass.ClassKind.INTERFACE
|
||||
else -> JKClass.ClassKind.CLASS
|
||||
}
|
||||
val psi = this
|
||||
return JKClassImpl(with(modifierMapper) { modifierList.toJK() }, JKNameIdentifierImpl(name!!), classKind).apply {
|
||||
declarations =
|
||||
children.mapNotNull { ElementVisitor(this@DeclarationMapper).apply { it.accept(this) }.resultElement as? JKUniverseDeclaration }
|
||||
declarationList.apply {
|
||||
declarations = psi.children.mapNotNull {
|
||||
ElementVisitor(this@DeclarationMapper).apply { it.accept(this) }.resultElement as? JKUniverseDeclaration
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,10 +45,10 @@ class NewCodeBuilder {
|
||||
printer.print(classKindString(universeClass.classKind))
|
||||
builder.append(" ")
|
||||
printer.print(universeClass.name.name)
|
||||
if (universeClass.declarations.isNotEmpty()) {
|
||||
if (universeClass.declarationList.declarations.isNotEmpty()) {
|
||||
printer.println("{")
|
||||
printer.pushIndent()
|
||||
universeClass.declarations.forEach { it.accept(this, data) }
|
||||
universeClass.declarationList.declarations.forEach { it.accept(this, data) }
|
||||
printer.popIndent()
|
||||
printer.println("}")
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class JKListChild<T : JKTreeElement>() : ReadWriteProperty<JKMutableBranchElemen
|
||||
thisRef.children.forEach { it.parent = null }
|
||||
value.forEach { it.parent = thisRef }
|
||||
thisRef.children.clear()
|
||||
thisRef.children.addAll(value as List<JKTreeElement>)
|
||||
thisRef.children.addAll(value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ abstract class JKElementListBase: JKElementBase(), JKMutableBranchElement {
|
||||
}
|
||||
}
|
||||
|
||||
class JKDeclarationListImpl : JKElementListBase(), JKDeclarationList {
|
||||
class JKUDeclarationListImpl : JKElementListBase(), JKUDeclarationList {
|
||||
override var declarations: List<JKUniverseDeclaration> by children()
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ class JKClassImpl(modifierList: JKModifierList, name: JKNameIdentifier, override
|
||||
override var modifierList by child(modifierList)
|
||||
override val valid: Boolean = true
|
||||
|
||||
override val declarationList by child(JKDeclarationListImpl())
|
||||
override val declarationList by child(JKUDeclarationListImpl())
|
||||
|
||||
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitUniverseClass(this, data)
|
||||
}
|
||||
@@ -145,7 +145,7 @@ class JKPostfixExpressionImpl(expression: JKExpression, override var operator: J
|
||||
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitPostfixExpression(this, data)
|
||||
}
|
||||
|
||||
class JKExpressionListImpl(expressions: MutableList<JKExpression> = mutableListOf()) : JKExpressionList, JKElementListBase() {
|
||||
class JKExpressionListImpl(expressions: List<JKExpression> = emptyList()) : JKExpressionList, JKElementListBase() {
|
||||
override var expressions by children(expressions)
|
||||
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitExpressionList(this, data)
|
||||
}
|
||||
|
||||
@@ -28,11 +28,15 @@ interface JKTreeElement : JKElement {
|
||||
interface JKUniverseDeclaration : JKTreeElement, JKDeclaration
|
||||
|
||||
interface JKDeclarationList : JKElement {
|
||||
var declarations: List<JKUniverseDeclaration>
|
||||
val declarations: List<JKDeclaration>
|
||||
}
|
||||
|
||||
interface JKUDeclarationList : JKDeclarationList {
|
||||
override var declarations: List<JKUniverseDeclaration>
|
||||
}
|
||||
|
||||
interface JKUniverseClass : JKUniverseDeclaration, JKClass {
|
||||
override val declarationList: JKDeclarationList
|
||||
override val declarationList: JKUDeclarationList
|
||||
}
|
||||
|
||||
interface JKModifier : JKTreeElement
|
||||
|
||||
+1
-1
@@ -14,4 +14,4 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.j2k.tree.conveersionCache
|
||||
package org.jetbrains.kotlin.j2k.tree.multiverse
|
||||
+5
-3
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.j2k.tree.conveersionCache
|
||||
package org.jetbrains.kotlin.j2k.tree.multiverse
|
||||
|
||||
import org.jetbrains.kotlin.j2k.tree.*
|
||||
import org.jetbrains.kotlin.j2k.tree.impl.JKJavaPrimitiveTypeImpl
|
||||
@@ -46,9 +46,11 @@ class JKMultiverseMethod(override var name: JKNameIdentifier) : JKMethod, JKMult
|
||||
}
|
||||
|
||||
class JKMultiverseClass(
|
||||
override var name: JKNameIdentifier, override var declarations: List<JKDeclaration>,
|
||||
override var name: JKNameIdentifier, override val declarationList: JKMDeclarationList,
|
||||
override var classKind: JKClass.ClassKind, override var modifierList: JKModifierList
|
||||
) : JKClass, JKMultiverseElementBase() {
|
||||
override val valid: Boolean
|
||||
get() = true
|
||||
}
|
||||
}
|
||||
|
||||
class JKMDeclarationList(override val declarations: List<JKDeclaration>) : JKMultiverseElementBase(), JKDeclarationList
|
||||
+5
-3
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.j2k.tree.conveersionCache
|
||||
package org.jetbrains.kotlin.j2k.tree.multiverse
|
||||
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiField
|
||||
@@ -37,7 +37,9 @@ interface ReferenceTargetProvider {
|
||||
}
|
||||
|
||||
fun resolveFieldReference(clazz: JKClass, field: PsiField): JKField {
|
||||
return clazz.declarations.asSequence().filter { it is JKJavaField && it.name.name == field.name }.firstOrNull() as JKField?
|
||||
?: JKMultiverseField(JKNameIdentifierImpl(field.name)).also { clazz.cast<JKMultiverseClass>().declarations += it }
|
||||
return clazz.declarationList.declarations.asSequence().filter { it is JKJavaField && it.name.name == field.name }.firstOrNull() as JKField?
|
||||
?: JKMultiverseField(JKNameIdentifierImpl(field.name)).also {
|
||||
clazz.cast<JKMultiverseClass>().declarationList.declarations += it
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user