Cleanup: fix some compiler warnings (mostly deprecations, javaClass)
This commit is contained in:
@@ -205,12 +205,12 @@ class AnnotationConverter(private val converter: Converter) {
|
||||
}
|
||||
|
||||
is PsiAnnotation -> {
|
||||
listOf({ codeConverter ->
|
||||
listOf({ _ ->
|
||||
val (name, arguments) = convertAnnotationValue(value)!!
|
||||
AnnotationConstructorCall(name, arguments).assignPrototype(value)
|
||||
})
|
||||
}
|
||||
else -> listOf({ codeConverter -> DummyStringExpression(value?.text ?: "").assignPrototype(value) })
|
||||
else -> listOf({ _ -> DummyStringExpression(value?.text ?: "").assignPrototype(value) })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ class AnnotationConverter(private val converter: Converter) {
|
||||
if (expectedType is PsiArrayType && !isVararg) {
|
||||
return convertArrayInitializerValue(codeConverter,
|
||||
value.text,
|
||||
listOf({ codeConverter -> expression }),
|
||||
listOf({ _ -> expression }),
|
||||
expectedType,
|
||||
false
|
||||
).assignPrototype(value)
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.j2k
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.CommonClassNames.*
|
||||
import org.jetbrains.kotlin.j2k.ast.*
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||
|
||||
class CodeConverter(
|
||||
val converter: Converter,
|
||||
@@ -81,7 +80,7 @@ class CodeConverter(
|
||||
fun convertLocalVariable(variable: PsiLocalVariable): LocalVariable {
|
||||
val isVal = canChangeType(variable)
|
||||
val type = typeConverter.convertVariableType(variable)
|
||||
val explicitType = type.check { settings.specifyLocalVariableTypeByDefault || converter.shouldDeclareVariableType(variable, type, isVal) }
|
||||
val explicitType = type.takeIf { settings.specifyLocalVariableTypeByDefault || converter.shouldDeclareVariableType(variable, type, isVal) }
|
||||
return LocalVariable(variable.declarationIdentifier(),
|
||||
converter.convertAnnotations(variable),
|
||||
converter.convertModifiers(variable, false),
|
||||
|
||||
@@ -170,7 +170,7 @@ class ConstructorConverter(
|
||||
}
|
||||
}
|
||||
else {
|
||||
{ it -> Block.Empty }
|
||||
{ Block.Empty }
|
||||
}
|
||||
|
||||
// we need to replace renamed parameter usages in base class constructor arguments and in default values
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.jetbrains.kotlin.j2k.usageProcessing.UsageProcessingExpressionConvert
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions.*
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
||||
import java.lang.IllegalArgumentException
|
||||
import java.util.*
|
||||
|
||||
@@ -395,7 +394,7 @@ class Converter private constructor(
|
||||
|
||||
var setter: PropertyAccessor? = null
|
||||
if (propertyInfo.needExplicitSetter) {
|
||||
val accessorModifiers = Modifiers(propertyInfo.specialSetterAccess.singletonOrEmptyList()).assignNoPrototype()
|
||||
val accessorModifiers = Modifiers(listOfNotNull(propertyInfo.specialSetterAccess)).assignNoPrototype()
|
||||
if (setMethod != null && !propertyInfo.isSetMethodBodyFieldAccess) {
|
||||
val method = convertMethod(setMethod, null, null, null, classKind)!!
|
||||
if (method.modifiers.contains(Modifier.EXTERNAL))
|
||||
@@ -729,6 +728,7 @@ class Converter private constructor(
|
||||
when (nullability) {
|
||||
Nullability.NotNull -> type = type.toNotNullType()
|
||||
Nullability.Nullable -> type = type.toNullableType()
|
||||
Nullability.Default -> {}
|
||||
}
|
||||
return FunctionParameter(parameter.declarationIdentifier(), type, varValModifier,
|
||||
convertAnnotations(parameter), modifiers, defaultValue).assignPrototype(parameter, CommentsAndSpacesInheritance.LINE_BREAKS)
|
||||
|
||||
@@ -189,7 +189,7 @@ class JavaToKotlinConverter(
|
||||
private fun processUsages(refs: Collection<ReferenceInfo>) {
|
||||
for (fileRefs in refs.groupBy { it.file }.values) { // group by file for faster sorting
|
||||
ReferenceLoop@
|
||||
for ((reference, target, file, processings) in fileRefs.sortedWith(ReferenceComparator)) {
|
||||
for ((reference, _, _, processings) in fileRefs.sortedWith(ReferenceComparator)) {
|
||||
val processors = when (reference.element.language) {
|
||||
JavaLanguage.INSTANCE -> processings.flatMap { it.javaCodeProcessors }
|
||||
KotlinLanguage.INSTANCE -> processings.flatMap { it.kotlinCodeProcessors }
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.intellij.psi.CommonClassNames.JAVA_LANG_OBJECT
|
||||
import com.intellij.psi.CommonClassNames.JAVA_LANG_STRING
|
||||
import com.intellij.psi.impl.PsiExpressionEvaluator
|
||||
import org.jetbrains.kotlin.j2k.ast.*
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||
import java.io.PrintStream
|
||||
import java.util.*
|
||||
|
||||
@@ -346,7 +345,7 @@ enum class SpecialMethod(val qualifiedClassName: String?, val methodName: String
|
||||
|
||||
STRING_GET_BYTES(JAVA_LANG_STRING, "getBytes", null) {
|
||||
override fun ConvertCallData.convertCall(): MethodCallExpression {
|
||||
val charsetArg = arguments.lastOrNull()?.check { it.type?.canonicalText == JAVA_LANG_STRING }
|
||||
val charsetArg = arguments.lastOrNull()?.takeIf { it.type?.canonicalText == JAVA_LANG_STRING }
|
||||
val convertedArguments = codeConverter.convertExpressionsInList(arguments).map {
|
||||
if (charsetArg != null && it.prototypes?.singleOrNull()?.element == charsetArg)
|
||||
MethodCallExpression.buildNonNull(null, "charset", ArgumentList.withNoPrototype(it)).assignNoPrototype()
|
||||
@@ -523,7 +522,7 @@ enum class SpecialMethod(val qualifiedClassName: String?, val methodName: String
|
||||
val candidates = valuesByName[method.name] ?: return null
|
||||
return candidates
|
||||
.firstOrNull { it.matches(method, services.superMethodsSearcher) }
|
||||
?.check { it.parameterCount == null || it.parameterCount == argumentCount } // if parameterCount is specified we should make sure that argument count is correct
|
||||
?.takeIf { it.parameterCount == null || it.parameterCount == argumentCount } // if parameterCount is specified we should make sure that argument count is correct
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ class FunctionParameter(identifier: Identifier,
|
||||
when (varVal) {
|
||||
VarValModifier.Var -> builder.append("var ")
|
||||
VarValModifier.Val -> builder.append("val ")
|
||||
VarValModifier.None -> {}
|
||||
}
|
||||
|
||||
builder.append(identifier)
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.renderer.render
|
||||
import org.jetbrains.kotlin.resolve.annotations.hasJvmStaticAnnotation
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
import org.jetbrains.kotlin.utils.singletonOrEmptyList
|
||||
|
||||
fun Converter.convertImportList(importList: PsiImportList): ImportList {
|
||||
val imports = importList.allImportStatements
|
||||
@@ -134,7 +133,7 @@ private fun convertStaticExplicitImport(fqName: FqName, target: PsiElement?): Li
|
||||
is KtClassBody -> {
|
||||
val parentClass = originParent.parent as KtClassOrObject
|
||||
if (parentClass is KtObjectDeclaration && parentClass.isCompanion()) {
|
||||
return parentClass.getFqName()?.child(nameToImport)?.render().singletonOrEmptyList()
|
||||
return listOfNotNull(parentClass.getFqName()?.child(nameToImport)?.render())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.psi.KtProperty
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||
import java.util.*
|
||||
|
||||
class PropertyInfo(
|
||||
@@ -227,7 +226,7 @@ private class PropertyDetector(
|
||||
converter.convertModifiers(field, false).accessModifier()
|
||||
else
|
||||
propertyAccess
|
||||
val specialSetterAccess = setterAccess?.check { it != propertyAccess }
|
||||
val specialSetterAccess = setterAccess?.takeIf { it != propertyAccess }
|
||||
|
||||
val propertyInfo = PropertyInfo(Identifier.withNoPrototype(propertyName),
|
||||
isVar,
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.j2k.CodeConverter
|
||||
import org.jetbrains.kotlin.j2k.ast.*
|
||||
import org.jetbrains.kotlin.j2k.dot
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonList
|
||||
|
||||
class AccessorToPropertyProcessing(val accessorMethod: PsiMethod, val accessorKind: AccessorKind, val propertyName: String) : UsageProcessing {
|
||||
override val targetElement: PsiElement get() = accessorMethod
|
||||
@@ -42,7 +41,7 @@ class AccessorToPropertyProcessing(val accessorMethod: PsiMethod, val accessorKi
|
||||
propertyName
|
||||
|
||||
if (accessorKind == AccessorKind.GETTER) {
|
||||
if (arguments.size != 0) return null // incorrect call
|
||||
if (arguments.isNotEmpty()) return null // incorrect call
|
||||
return propertyAccess
|
||||
}
|
||||
else {
|
||||
@@ -59,7 +58,7 @@ class AccessorToPropertyProcessing(val accessorMethod: PsiMethod, val accessorKi
|
||||
if (accessorMethod.hasModifierProperty(PsiModifier.PRIVATE))
|
||||
emptyList()
|
||||
else
|
||||
AccessorToPropertyProcessor().singletonList()
|
||||
listOf(AccessorToPropertyProcessor())
|
||||
|
||||
inner class AccessorToPropertyProcessor: ExternalCodeProcessor {
|
||||
override fun processUsage(reference: PsiReference): Array<PsiReference>? {
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.j2k.AccessorKind
|
||||
import org.jetbrains.kotlin.j2k.CodeConverter
|
||||
import org.jetbrains.kotlin.j2k.ast.*
|
||||
import org.jetbrains.kotlin.j2k.dot
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonList
|
||||
|
||||
class FieldToPropertyProcessing(
|
||||
private val field: PsiField,
|
||||
@@ -43,11 +42,11 @@ class FieldToPropertyProcessing(
|
||||
else if (field.name != propertyName)
|
||||
listOf(ElementRenamedCodeProcessor(propertyName), UseAccessorsJavaCodeProcessor())
|
||||
else
|
||||
UseAccessorsJavaCodeProcessor().singletonList()
|
||||
listOf(UseAccessorsJavaCodeProcessor())
|
||||
|
||||
override val kotlinCodeProcessors =
|
||||
if (field.name != propertyName)
|
||||
ElementRenamedCodeProcessor(propertyName).singletonList()
|
||||
listOf(ElementRenamedCodeProcessor(propertyName))
|
||||
else
|
||||
emptyList()
|
||||
|
||||
|
||||
@@ -17,14 +17,13 @@
|
||||
package org.jetbrains.kotlin.j2k.usageProcessing
|
||||
|
||||
import com.intellij.psi.*
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonList
|
||||
|
||||
class MemberIntoObjectProcessing(private val member: PsiMember, private val objectName: String) : UsageProcessing {
|
||||
override val targetElement: PsiElement get() = member
|
||||
|
||||
override val convertedCodeProcessor: ConvertedCodeProcessor? get() = null
|
||||
|
||||
override val javaCodeProcessors = AppendObjectNameProcessor().singletonList()
|
||||
override val javaCodeProcessors = listOf(AppendObjectNameProcessor())
|
||||
|
||||
override val kotlinCodeProcessors = emptyList<ExternalCodeProcessor>()
|
||||
|
||||
|
||||
+1
-2
@@ -18,14 +18,13 @@ package org.jetbrains.kotlin.j2k.usageProcessing
|
||||
|
||||
import com.intellij.psi.*
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonList
|
||||
|
||||
class ToObjectWithOnlyMethodsProcessing(private val psiClass: PsiClass) : UsageProcessing {
|
||||
override val targetElement: PsiElement get() = psiClass
|
||||
|
||||
override val convertedCodeProcessor: ConvertedCodeProcessor? get() = null
|
||||
|
||||
override val javaCodeProcessors = ToObjectWithOnlyMethodsProcessor().singletonList()
|
||||
override val javaCodeProcessors = listOf(ToObjectWithOnlyMethodsProcessor())
|
||||
|
||||
override val kotlinCodeProcessors = emptyList<ExternalCodeProcessor>()
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ abstract class AbstractJavaToKotlinConverterMultiFileTest : AbstractJavaToKotlin
|
||||
val project = LightPlatformTestCase.getProject()!!
|
||||
val psiManager = PsiManager.getInstance(project)
|
||||
|
||||
val filesToConvert = File(dirPath).listFiles { file, name -> name.endsWith(".java") }
|
||||
val filesToConvert = File(dirPath).listFiles { _, name -> name.endsWith(".java") }
|
||||
val psiFilesToConvert = ArrayList<PsiJavaFile>()
|
||||
for (javaFile in filesToConvert) {
|
||||
val virtualFile = addFile(javaFile, "test")
|
||||
@@ -44,7 +44,7 @@ abstract class AbstractJavaToKotlinConverterMultiFileTest : AbstractJavaToKotlin
|
||||
psiFilesToConvert.add(psiFile)
|
||||
}
|
||||
|
||||
val externalFiles = File(dirPath + File.separator + "external").listFiles { file, name -> name.endsWith(".java") || name.endsWith(".kt") }
|
||||
val externalFiles = File(dirPath + File.separator + "external").listFiles { _, name -> name.endsWith(".java") || name.endsWith(".kt") }
|
||||
val externalPsiFiles = ArrayList<PsiFile>()
|
||||
for (file in externalFiles) {
|
||||
val virtualFile = addFile(file, "test")
|
||||
|
||||
Reference in New Issue
Block a user