J2K to not generate obsolete syntax for accessing java class

This commit is contained in:
Valentin Kipyatkov
2015-09-04 20:31:38 +03:00
parent d58a8437d7
commit 988b42bba8
9 changed files with 18 additions and 46 deletions
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.j2k
import com.intellij.codeInsight.NullableNotNullManager
import com.intellij.openapi.util.text.StringUtil
import com.intellij.psi.*
import com.intellij.psi.javadoc.PsiDocTag
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget
import org.jetbrains.kotlin.j2k.ast.*
import org.jetbrains.kotlin.j2k.ast.Annotation
@@ -178,8 +177,8 @@ class AnnotationConverter(private val converter: Converter) {
private fun convertExpressionValue(codeConverter: CodeConverter, value: PsiExpression, expectedType: PsiType?): Expression {
val expression = if (value is PsiClassObjectAccessExpression) {
val typeElement = converter.convertTypeElement(value.getOperand())
ClassLiteralExpression(typeElement.type.toNotNullType())
val type = converter.convertTypeElement(value.getOperand(), Nullability.NotNull)
ClassLiteralExpression(type)
}
else {
codeConverter.convertExpression(value, expectedType)
@@ -23,10 +23,8 @@ import com.intellij.psi.util.PsiMethodUtil
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.j2k.ast.*
import org.jetbrains.kotlin.j2k.ast.Annotation
import org.jetbrains.kotlin.j2k.ast.Class
import org.jetbrains.kotlin.j2k.ast.Enum
import org.jetbrains.kotlin.j2k.ast.Function
import org.jetbrains.kotlin.j2k.ast.Object
import org.jetbrains.kotlin.j2k.usageProcessing.FieldToPropertyProcessing
import org.jetbrains.kotlin.j2k.usageProcessing.UsageProcessing
import org.jetbrains.kotlin.j2k.usageProcessing.UsageProcessingExpressionConverter
@@ -532,8 +530,8 @@ class Converter private constructor(
return null
}
public fun convertTypeElement(element: PsiTypeElement?): TypeElement
= TypeElement(if (element == null) ErrorType().assignNoPrototype() else typeConverter.convertType(element.getType())).assignPrototype(element)
public fun convertTypeElement(element: PsiTypeElement?, nullability: Nullability): Type
= (if (element == null) ErrorType() else typeConverter.convertType(element.type, nullability)).assignPrototype(element)
private fun convertToNotNullableTypes(types: Array<out PsiType?>): List<Type>
= types.map { typeConverter.convertType(it, Nullability.NotNull) }
@@ -182,8 +182,8 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter {
FqName("java.lang.Void")
}
else {
val typeElement = converter.convertTypeElement(operand)
result = MethodCallExpression.buildNotNull(null, "javaClass", listOf(), listOf(typeElement.type.toNotNullType()))
val type = converter.convertTypeElement(operand, Nullability.NotNull)
result = QualifiedExpression(ClassLiteralExpression(type).assignNoPrototype(), Identifier("java").assignNoPrototype())
return
}
@@ -213,7 +213,7 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter {
override fun visitInstanceOfExpression(expression: PsiInstanceOfExpression) {
val checkType = expression.getCheckType()
result = IsOperator(codeConverter.convertExpression(expression.getOperand()),
converter.convertTypeElement(checkType))
converter.convertTypeElement(checkType, Nullability.NotNull))
}
override fun visitLiteralExpression(expression: PsiLiteralExpression) {
@@ -661,7 +661,7 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter {
private fun convertMethodReferenceQualifier(qualifier: PsiElement): String {
return when(qualifier) {
is PsiExpression -> codeConverter.convertExpression(qualifier).canonicalCode()
is PsiTypeElement -> converter.convertTypeElement(qualifier).type.canonicalCode()
is PsiTypeElement -> converter.convertTypeElement(qualifier, Nullability.NotNull).canonicalCode()
else -> qualifier.text
}
}
@@ -16,8 +16,8 @@
package org.jetbrains.kotlin.j2k.ast
import org.jetbrains.kotlin.types.expressions.OperatorConventions
import org.jetbrains.kotlin.j2k.*
import org.jetbrains.kotlin.j2k.CodeBuilder
import org.jetbrains.kotlin.j2k.append
class ArrayAccessExpression(val expression: Expression, val index: Expression, val lvalue: Boolean) : Expression() {
override fun generateCode(builder: CodeBuilder) {
@@ -54,9 +54,9 @@ class BinaryExpression(val left: Expression, val right: Expression, val op: Stri
}
}
class IsOperator(val expression: Expression, val typeElement: TypeElement) : Expression() {
class IsOperator(val expression: Expression, val type: Type) : Expression() {
override fun generateCode(builder: CodeBuilder) {
builder.appendOperand(this, expression).append(" is ").append(typeElement.type.toNotNullType())
builder.appendOperand(this, expression).append(" is ").append(type)
}
}
@@ -1,25 +0,0 @@
/*
* Copyright 2010-2015 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.kotlin.j2k.ast
import org.jetbrains.kotlin.j2k.*
class TypeElement(val type: Type) : Element() {
override fun generateCode(builder: CodeBuilder) {
builder.append(type)
}
}
@@ -1 +1 @@
val constrArgTypes = arrayOf(javaClass<Array<String>>(), javaClass<String>())
val constrArgTypes = arrayOf(Array<String>::class.java, String::class.java)
+1 -1
View File
@@ -1 +1 @@
javaClass<Any>()
Any::class.java
@@ -3,8 +3,8 @@ public object A {
println(Void.TYPE)
println(Integer.TYPE)
println(java.lang.Double.TYPE)
println(javaClass<IntArray>())
println(javaClass<Array<Any>>())
println(javaClass<Array<Array<Any>>>())
println(IntArray::class.java)
println(Array<Any>::class.java)
println(Array<Array<Any>>::class.java)
}
}
+1 -1
View File
@@ -1 +1 @@
javaClass<String>()
String::class.java