If then to elvis: applied in IDEA, front-end & J2K modules
This commit is contained in:
@@ -825,7 +825,7 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter {
|
||||
else if (specialMethod != null) {
|
||||
val factory = PsiElementFactory.SERVICE.getInstance(converter.project)
|
||||
val fakeReceiver = receiver?.let {
|
||||
val psiExpression = if (qualifier is PsiExpression) qualifier else factory.createExpressionFromText("fakeReceiver", null)
|
||||
val psiExpression = qualifier as? PsiExpression ?: factory.createExpressionFromText("fakeReceiver", null)
|
||||
psiExpression.convertedExpression = it.first
|
||||
psiExpression
|
||||
}
|
||||
|
||||
@@ -477,7 +477,7 @@ enum class SpecialMethod(val qualifiedClassName: String?, val methodName: String
|
||||
private fun castQualifierToType(codeConverter: CodeConverter, qualifier: PsiExpression, type: String): TypeCastExpression? {
|
||||
val convertedQualifier = codeConverter.convertExpression(qualifier)
|
||||
val qualifierType = codeConverter.typeConverter.convertType(qualifier.type)
|
||||
val typeArgs = if (qualifierType is ClassType) qualifierType.referenceElement.typeArgs else emptyList()
|
||||
val typeArgs = (qualifierType as? ClassType)?.referenceElement?.typeArgs ?: emptyList()
|
||||
val referenceElement = ReferenceElement(Identifier.withNoPrototype(type), typeArgs).assignNoPrototype()
|
||||
val newType = ClassType(referenceElement, Nullability.Default, codeConverter.settings).assignNoPrototype()
|
||||
return TypeCastExpression(newType, convertedQualifier).assignNoPrototype()
|
||||
|
||||
@@ -191,10 +191,7 @@ class DefaultStatementConverter : JavaElementVisitor(), StatementConverter {
|
||||
val blockConverted = codeConverter.convertBlock(block)
|
||||
val annotations = converter.convertAnnotations(parameter)
|
||||
val parameterType = parameter.type
|
||||
val types = if (parameterType is PsiDisjunctionType)
|
||||
parameterType.disjunctions
|
||||
else
|
||||
listOf(parameterType)
|
||||
val types = (parameterType as? PsiDisjunctionType)?.disjunctions ?: listOf(parameterType)
|
||||
for (t in types) {
|
||||
val convertedType = codeConverter.typeConverter.convertType(t, Nullability.NotNull)
|
||||
val convertedParameter = FunctionParameter(parameter.declarationIdentifier(),
|
||||
|
||||
@@ -94,7 +94,7 @@ class SwitchConverter(private val codeConverter: CodeConverter) {
|
||||
}
|
||||
else {
|
||||
val block = case.statements.singleOrNull() as? PsiBlockStatement
|
||||
val statements = if (block != null) block.codeBlock.statements.toList() else case.statements
|
||||
val statements = block?.codeBlock?.statements?.toList() ?: case.statements
|
||||
!statements.any { it is PsiBreakStatement || it is PsiContinueStatement || it is PsiReturnStatement || it is PsiThrowStatement }
|
||||
}
|
||||
return if (fallsThrough) // we fall through into the next case
|
||||
|
||||
@@ -106,10 +106,8 @@ class FieldToPropertyProcessing(
|
||||
|
||||
is PsiPrefixExpression, is PsiPostfixExpression -> {
|
||||
//TODO: what if it's used as value?
|
||||
val operationType = if (parent is PsiPrefixExpression)
|
||||
parent.operationTokenType
|
||||
else
|
||||
(parent as PsiPostfixExpression).operationTokenType
|
||||
val operationType = (parent as? PsiPrefixExpression)?.operationTokenType
|
||||
?: (parent as PsiPostfixExpression).operationTokenType
|
||||
val opText = when (operationType) {
|
||||
JavaTokenType.PLUSPLUS -> "+"
|
||||
JavaTokenType.MINUSMINUS -> "-"
|
||||
|
||||
Reference in New Issue
Block a user