New J2K: ArrayType and PrimitiveType

This commit is contained in:
Dimach
2018-03-07 22:43:17 +02:00
committed by Ilya Kirillov
parent 09d52d13b8
commit fb32783168
5 changed files with 23 additions and 6 deletions
@@ -219,8 +219,17 @@ class JavaToJKTreeBuilder : ReferenceTargetProvider {
}
fun PsiType.toJK(): JKType {
val ref = JKClassReferenceImpl(this@JavaToJKTreeBuilder.resolveClassReference((this as PsiClassType).resolve() ?: TODO())) //TODO support other types
return JKClassTypeImpl(ref, parameters.map { it.toJK() })
return when (this) {
is PsiClassType -> JKClassTypeImpl(resolve()!!.convertClassReference(), parameters.map { it.toJK() })
is PsiArrayType -> JKJavaArrayTypeImpl(componentType.toJK())
is PsiPrimitiveType -> when (presentableText) {
"int" -> JKJavaPrimitiveTypeImpl.INT
"byte" -> JKJavaPrimitiveTypeImpl.BYTE
"boolean" -> JKJavaPrimitiveTypeImpl.BOOLEAN
else -> throw Exception("Invalid PSI")
}
else -> throw Exception("Invalid PSI")
}
}
}
@@ -44,6 +44,7 @@ private class DebugTreePrinter : JKVisitorVoid {
printer.indented {
javaMethod.block?.accept(this, null)
javaMethod.modifierList.accept(this, null)
javaMethod.valueArguments.forEach { it.accept(this, null) }
}
printer.println("]")
}
@@ -94,6 +95,15 @@ private class DebugTreePrinter : JKVisitorVoid {
}
printer.println("\"")
}
override fun visitType(type: JKType) {
printer.println(type.classNameWithoutJK(), " \"")
printer.indented {
if(type is JKClassType)
printer.println(type.classReference.target.name.name)
}
printer.println("\"")
}
}
private fun Any.classNameWithoutJK(): String = this.javaClass.simpleName.removePrefix("JK")
@@ -165,8 +165,7 @@ sealed class JKJavaPrimitiveTypeImpl(override val name: String) : JKJavaPrimitiv
object INT : JKJavaPrimitiveTypeImpl("int")
}
class JKJavaArrayTypeImpl(override val type: JKType, override val dimensionCount: Int) : JKJavaArrayType, JKElementBase() {
class JKJavaArrayTypeImpl(override val type: JKType) : JKJavaArrayType, JKElementBase() {
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitJavaArrayType(this, data)
override fun <D> acceptChildren(visitor: JKVisitor<Unit, D>, data: D) {
@@ -34,7 +34,6 @@ interface JKJavaPrimitiveType : JKType {
interface JKJavaArrayType : JKType {
val type: JKType
val dimensionCount : Int
}
interface JKJavaStringLiteralExpression : JKLiteralExpression {
+1 -1
View File
@@ -3,7 +3,7 @@ package p;
public class Some {
public String test=""+"a";
public static void main(String args) {
public static void main(String[][][] args, int[] b) {
System.out.println("Test");
}
}