New J2K: Add throws list for java method & add JKClassLiteralExpression
This commit is contained in:
committed by
Ilya Kirillov
parent
69633e7a0f
commit
3ea4ee9110
@@ -64,6 +64,7 @@ class JavaToJKTreeBuilder(var symbolProvider: JKSymbolProvider) {
|
|||||||
)
|
)
|
||||||
is PsiArrayInitializerExpression -> toJK()
|
is PsiArrayInitializerExpression -> toJK()
|
||||||
is PsiLambdaExpression -> toJK()
|
is PsiLambdaExpression -> toJK()
|
||||||
|
is PsiClassObjectAccessExpressionImpl -> toJK()
|
||||||
else -> {
|
else -> {
|
||||||
throw RuntimeException("Not supported: ${this::class}")
|
throw RuntimeException("Not supported: ${this::class}")
|
||||||
}
|
}
|
||||||
@@ -72,6 +73,15 @@ class JavaToJKTreeBuilder(var symbolProvider: JKSymbolProvider) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun PsiClassObjectAccessExpressionImpl.toJK(): JKClassLiteralExpression {
|
||||||
|
val type = operand.toJK()
|
||||||
|
return JKClassLiteralExpressionImpl(
|
||||||
|
type,
|
||||||
|
if (type.type is JKJavaPrimitiveType) JKClassLiteralExpression.LiteralType.JAVA_PRIMITIVE_CLASS
|
||||||
|
else JKClassLiteralExpression.LiteralType.JAVA_CLASS
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun PsiInstanceOfExpression.toJK(): JKJavaInstanceOfExpression {
|
fun PsiInstanceOfExpression.toJK(): JKJavaInstanceOfExpression {
|
||||||
return JKJavaInstanceOfExpressionImpl(operand.toJK(), checkType?.toJK() ?: TODO())
|
return JKJavaInstanceOfExpressionImpl(operand.toJK(), checkType?.toJK() ?: TODO())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -743,7 +743,22 @@ class NewCodeBuilder {
|
|||||||
|
|
||||||
override fun visitAnnotation(annotation: JKAnnotation) {
|
override fun visitAnnotation(annotation: JKAnnotation) {
|
||||||
printer.printWithNoIndent("@")
|
printer.printWithNoIndent("@")
|
||||||
annotation.name.accept(this)
|
printer.printWithNoIndent(annotation.classSymbol.name)
|
||||||
|
if (annotation.arguments.expressions.isNotEmpty()) {
|
||||||
|
printer.par {
|
||||||
|
annotation.arguments.accept(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitClassLiteralExpression(classLiteralExpression: JKClassLiteralExpression) {
|
||||||
|
renderType(classLiteralExpression.classType.type.updateNullability(Nullability.NotNull))
|
||||||
|
printer.printWithNoIndent("::")
|
||||||
|
when (classLiteralExpression.literalType) {
|
||||||
|
JKClassLiteralExpression.LiteralType.KOTLIN_CLASS -> printer.printWithNoIndent("class")
|
||||||
|
JKClassLiteralExpression.LiteralType.JAVA_CLASS -> printer.printWithNoIndent("class.java")
|
||||||
|
JKClassLiteralExpression.LiteralType.JAVA_PRIMITIVE_CLASS -> printer.printWithNoIndent("class.javaPrimitiveType")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitKtWhenCase(ktWhenCase: JKKtWhenCase) {
|
override fun visitKtWhenCase(ktWhenCase: JKKtWhenCase) {
|
||||||
@@ -778,10 +793,21 @@ class NewCodeBuilder {
|
|||||||
javaNewExpression.acceptChildren(this)
|
javaNewExpression.acceptChildren(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitTypeElement(typeElement: JKTypeElement) {
|
// override fun visitTypeElement(typeElement: JKTypeElement, data: Nothing?) {
|
||||||
val type = typeElement.type
|
// val classType = typeElement.type as? JKClassType ?: return
|
||||||
|
// collectedFqNames.add(FqName(classType.classReference.fqName!!))
|
||||||
|
// }
|
||||||
|
|
||||||
|
override fun visitClassLiteralExpression(classLiteralExpression: JKClassLiteralExpression) {
|
||||||
|
val type = classLiteralExpression.classType.type
|
||||||
if (type is JKClassType) {
|
if (type is JKClassType) {
|
||||||
collectedFqNames.add(FqName(type.classReference.fqName!!))
|
val fqName = type.classReference.fqName!!
|
||||||
|
val isDefaultImport = fqName.split('.').let {
|
||||||
|
it.size == 2 && it.first() == "kotlin"
|
||||||
|
}
|
||||||
|
if (!isDefaultImport) {
|
||||||
|
collectedFqNames.add(FqName(fqName))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -188,3 +188,13 @@ fun kotlinAssert(assertion: JKExpression, message: JKExpression?, symbolProvider
|
|||||||
),
|
),
|
||||||
JKExpressionListImpl(listOfNotNull(assertion, message))
|
JKExpressionListImpl(listOfNotNull(assertion, message))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun throwAnnotation(throws: List<JKType>, symbolProvider: JKSymbolProvider) =
|
||||||
|
JKAnnotationImpl(
|
||||||
|
symbolProvider.provideByFqName("kotlin.jvm.Throws"),
|
||||||
|
JKExpressionListImpl(
|
||||||
|
throws.map {
|
||||||
|
JKClassLiteralExpressionImpl(JKTypeElementImpl(it), JKClassLiteralExpression.LiteralType.KOTLIN_CLASS)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ class JKJavaMethodImpl(
|
|||||||
override var block: JKBlock by child(block)
|
override var block: JKBlock by child(block)
|
||||||
override var typeParameterList: JKTypeParameterList by child(typeParameterList)
|
override var typeParameterList: JKTypeParameterList by child(typeParameterList)
|
||||||
override var annotationList: JKAnnotationList by child(annotationList)
|
override var annotationList: JKAnnotationList by child(annotationList)
|
||||||
|
override var throwsList: List<JKTypeElement> by children(throwsList)
|
||||||
}
|
}
|
||||||
|
|
||||||
class JKJavaLiteralExpressionImpl(
|
class JKJavaLiteralExpressionImpl(
|
||||||
|
|||||||
@@ -484,8 +484,11 @@ class JKAnnotationListImpl(annotations: List<JKAnnotation> = emptyList()) : JKAn
|
|||||||
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitAnnotationList(this, data)
|
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitAnnotationList(this, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
class JKAnnotationImpl(name: JKNameIdentifier) : JKAnnotation, JKBranchElementBase() {
|
class JKAnnotationImpl(
|
||||||
override var name: JKNameIdentifier by child(name)
|
override val classSymbol: JKClassSymbol,
|
||||||
|
arguments: JKExpressionList
|
||||||
|
) : JKAnnotation, JKBranchElementBase() {
|
||||||
|
override var arguments: JKExpressionList by child(arguments)
|
||||||
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitAnnotation(this, data)
|
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitAnnotation(this, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -495,3 +498,12 @@ class JKTypeArgumentListImpl(typeArguments: List<JKTypeElement> = emptyList()) :
|
|||||||
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitTypeArgumentList(this, data)
|
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitTypeArgumentList(this, data)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class JKClassLiteralExpressionImpl(
|
||||||
|
classType: JKTypeElement,
|
||||||
|
override var literalType: JKClassLiteralExpression.LiteralType
|
||||||
|
) : JKClassLiteralExpression, JKBranchElementBase(), PsiOwner by PsiOwnerImpl() {
|
||||||
|
override val classType: JKTypeElement by child(classType)
|
||||||
|
|
||||||
|
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitClassLiteralExpression(this, data)
|
||||||
|
}
|
||||||
@@ -24,6 +24,7 @@ interface JKField : JKVariable, JKVisibilityOwner, JKMutabilityOwner, JKModality
|
|||||||
interface JKJavaField : JKField, JKBranchElement
|
interface JKJavaField : JKField, JKBranchElement
|
||||||
|
|
||||||
interface JKJavaMethod : JKMethod, JKBranchElement {
|
interface JKJavaMethod : JKMethod, JKBranchElement {
|
||||||
|
var throwsList: List<JKTypeElement>
|
||||||
}
|
}
|
||||||
|
|
||||||
interface JKJavaMethodCallExpression : JKMethodCallExpression
|
interface JKJavaMethodCallExpression : JKMethodCallExpression
|
||||||
|
|||||||
@@ -70,7 +70,8 @@ interface JKAnnotationList : JKTreeElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface JKAnnotation : JKTreeElement {
|
interface JKAnnotation : JKTreeElement {
|
||||||
var name: JKNameIdentifier//TODO
|
val classSymbol: JKClassSymbol
|
||||||
|
var arguments: JKExpressionList
|
||||||
}
|
}
|
||||||
|
|
||||||
interface JKAnnotationListOwner : JKTreeElement {
|
interface JKAnnotationListOwner : JKTreeElement {
|
||||||
@@ -383,3 +384,14 @@ interface JKForInStatement : JKStatement {
|
|||||||
interface JKPackageDeclaration : JKDeclaration {
|
interface JKPackageDeclaration : JKDeclaration {
|
||||||
var packageName: JKNameIdentifier
|
var packageName: JKNameIdentifier
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface JKClassLiteralExpression : JKExpression {
|
||||||
|
val classType: JKTypeElement
|
||||||
|
val literalType: LiteralType
|
||||||
|
|
||||||
|
enum class LiteralType {
|
||||||
|
KOTLIN_CLASS,
|
||||||
|
JAVA_CLASS,
|
||||||
|
JAVA_PRIMITIVE_CLASS
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user