mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
[kotlin] J2K: cleanup
GitOrigin-RevId: 99c45e33354d3ece84debcffb342d19662ede20c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
162b403110
commit
1ec624b1b9
@@ -349,7 +349,7 @@ val JKElement.psi: PsiElement?
|
||||
inline fun <reified Elem : PsiElement> JKElement.psi(): Elem? =
|
||||
(this as? PsiOwner)?.psi as? Elem
|
||||
|
||||
fun JKTypeElement.present(): Boolean = type != JKNoType
|
||||
fun JKTypeElement.isPresent(): Boolean = type != JKNoType
|
||||
|
||||
fun JKStatement.isEmpty(): Boolean = when (this) {
|
||||
is JKEmptyStatement -> true
|
||||
@@ -358,7 +358,7 @@ fun JKStatement.isEmpty(): Boolean = when (this) {
|
||||
else -> false
|
||||
}
|
||||
|
||||
fun JKInheritanceInfo.present(): Boolean =
|
||||
fun JKInheritanceInfo.isPresent(): Boolean =
|
||||
extends.isNotEmpty() || implements.isNotEmpty()
|
||||
|
||||
fun JKInheritanceInfo.supertypeCount(): Int =
|
||||
|
||||
@@ -2,10 +2,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.nj2k.printing
|
||||
|
||||
import com.intellij.psi.PsiMethod
|
||||
import com.intellij.psi.PsiMethodCallExpression
|
||||
import com.intellij.psi.PsiNewExpression
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginModeProvider
|
||||
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginModeProvider.Companion.isK1Mode
|
||||
@@ -18,8 +14,6 @@ import org.jetbrains.kotlin.nj2k.tree.Modality.FINAL
|
||||
import org.jetbrains.kotlin.nj2k.tree.Visibility.PUBLIC
|
||||
import org.jetbrains.kotlin.nj2k.tree.visitors.JKVisitorWithCommentsPrinting
|
||||
import org.jetbrains.kotlin.nj2k.types.*
|
||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
class JKCodeBuilder(context: NewJ2kConverterContext) {
|
||||
@@ -197,7 +191,7 @@ class JKCodeBuilder(context: NewJ2kConverterContext) {
|
||||
val primaryConstructor = klass.primaryConstructor()
|
||||
primaryConstructor?.accept(this)
|
||||
|
||||
if (klass.inheritance.present()) {
|
||||
if (klass.inheritance.isPresent()) {
|
||||
printer.printWithSurroundingSpaces(":")
|
||||
klass.inheritance.accept(this)
|
||||
}
|
||||
@@ -241,7 +235,7 @@ class JKCodeBuilder(context: NewJ2kConverterContext) {
|
||||
}
|
||||
renderModifiersList(field)
|
||||
field.name.accept(this)
|
||||
if (field.type.present()) {
|
||||
if (field.type.isPresent()) {
|
||||
printer.print(": ")
|
||||
field.type.accept(this)
|
||||
}
|
||||
@@ -307,7 +301,7 @@ class JKCodeBuilder(context: NewJ2kConverterContext) {
|
||||
|
||||
private fun renderVariableDeclarationNameAndType(variable: JKVariable) {
|
||||
variable.name.accept(this)
|
||||
if (variable.type.present() && variable.type.type !is JKContextType) {
|
||||
if (variable.type.isPresent() && variable.type.type !is JKContextType) {
|
||||
printer.print(": ")
|
||||
variable.type.accept(this)
|
||||
}
|
||||
@@ -326,7 +320,7 @@ class JKCodeBuilder(context: NewJ2kConverterContext) {
|
||||
override fun visitForLoopVariableRaw(forLoopVariable: JKForLoopVariable) {
|
||||
forLoopVariable.annotationList.accept(this)
|
||||
forLoopVariable.name.accept(this)
|
||||
if (!forLoopVariable.type.present() || forLoopVariable.type.type is JKContextType) return
|
||||
if (!forLoopVariable.type.isPresent() || forLoopVariable.type.type is JKContextType) return
|
||||
|
||||
val needExplicitType = isK1Mode() || // for K1 nullability inference
|
||||
settings.specifyLocalVariableTypeByDefault ||
|
||||
@@ -806,7 +800,7 @@ class JKCodeBuilder(context: NewJ2kConverterContext) {
|
||||
}
|
||||
|
||||
override fun visitLambdaExpressionRaw(lambdaExpression: JKLambdaExpression) {
|
||||
if (lambdaExpression.functionalType.present()) {
|
||||
if (lambdaExpression.functionalType.isPresent()) {
|
||||
// print SAM constructor
|
||||
printer.renderType(lambdaExpression.functionalType.type, lambdaExpression)
|
||||
printer.print(" ")
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.intellij.psi.PsiMethodCallExpression
|
||||
import com.intellij.psi.PsiNewExpression
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.kotlin.nj2k.escaped
|
||||
import org.jetbrains.kotlin.nj2k.present
|
||||
import org.jetbrains.kotlin.nj2k.isPresent
|
||||
import org.jetbrains.kotlin.nj2k.psi
|
||||
import org.jetbrains.kotlin.nj2k.tree.*
|
||||
import org.jetbrains.kotlin.nj2k.types.isKotlinFunctionalType
|
||||
@@ -41,7 +41,7 @@ internal fun canMoveLambdaOutsideParentheses(argumentList: JKArgumentList): Bool
|
||||
return true
|
||||
}
|
||||
|
||||
if (lambda.functionalType.present()) {
|
||||
if (lambda.functionalType.isPresent()) {
|
||||
// If the functional type (SAM constructor) exists and is not redundant,
|
||||
// then the lambda can't be moved outside the parentheses.
|
||||
// However, if it is redundant, we can move the lambda and not print the functional type.
|
||||
|
||||
@@ -62,7 +62,7 @@ class JKPostfixExpression(
|
||||
override fun accept(visitor: JKVisitor) = visitor.visitPostfixExpression(this)
|
||||
}
|
||||
|
||||
open class JKQualifiedExpression(
|
||||
class JKQualifiedExpression(
|
||||
receiver: JKExpression,
|
||||
selector: JKExpression,
|
||||
override val expressionType: JKType? = null,
|
||||
@@ -82,7 +82,6 @@ class JKArrayAccessExpression(
|
||||
override fun accept(visitor: JKVisitor) = visitor.visitArrayAccessExpression(this)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param shouldBePreserved - parentheses came from original Java code and should be preserved
|
||||
* (don't run "Remove unnecessary parentheses" inspection on them)
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
public class C {
|
||||
public static void main(String[] args) {
|
||||
switch (args.length) {
|
||||
case 1: {
|
||||
int a = 1;
|
||||
System.out.print("1");
|
||||
}
|
||||
public class C {
|
||||
public static void main(String[] args) {
|
||||
switch (args.length) {
|
||||
case 1: {
|
||||
int a = 1;
|
||||
System.out.print("1");
|
||||
}
|
||||
|
||||
case 2: {
|
||||
int a = 2;
|
||||
System.out.print("2");
|
||||
}
|
||||
case 2: {
|
||||
int a = 2;
|
||||
System.out.print("2");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user