replace null checks with elvis operator
This commit is contained in:
@@ -17,9 +17,9 @@
|
|||||||
package org.jetbrains.kotlin.idea.editor.fixers
|
package org.jetbrains.kotlin.idea.editor.fixers
|
||||||
|
|
||||||
import com.intellij.lang.SmartEnterProcessorWithFixers
|
import com.intellij.lang.SmartEnterProcessorWithFixers
|
||||||
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.idea.editor.KotlinSmartEnterHandler
|
import org.jetbrains.kotlin.idea.editor.KotlinSmartEnterHandler
|
||||||
import com.intellij.openapi.editor.Editor
|
|
||||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||||
|
|
||||||
|
|
||||||
@@ -29,8 +29,7 @@ class KotlinFunctionParametersFixer : SmartEnterProcessorWithFixers.Fixer<Kotlin
|
|||||||
|
|
||||||
val parameterList = psiElement.valueParameterList
|
val parameterList = psiElement.valueParameterList
|
||||||
if (parameterList == null) {
|
if (parameterList == null) {
|
||||||
val identifier = psiElement.nameIdentifier
|
val identifier = psiElement.nameIdentifier ?: return
|
||||||
if (identifier == null) return
|
|
||||||
|
|
||||||
// Insert () after name or after type parameters list when it placed after name
|
// Insert () after name or after type parameters list when it placed after name
|
||||||
val offset = Math.max(identifier.range.end, psiElement.typeParameterList?.range?.end ?: psiElement.range.start)
|
val offset = Math.max(identifier.range.end, psiElement.typeParameterList?.range?.end ?: psiElement.range.start)
|
||||||
@@ -38,8 +37,7 @@ class KotlinFunctionParametersFixer : SmartEnterProcessorWithFixers.Fixer<Kotlin
|
|||||||
processor.registerUnresolvedError(offset + 1)
|
processor.registerUnresolvedError(offset + 1)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val rParen = parameterList.lastChild
|
val rParen = parameterList.lastChild ?: return
|
||||||
if (rParen == null) return
|
|
||||||
|
|
||||||
if (")" != rParen.text) {
|
if (")" != rParen.text) {
|
||||||
val params = parameterList.parameters
|
val params = parameterList.parameters
|
||||||
|
|||||||
+4
-5
@@ -17,13 +17,13 @@
|
|||||||
package org.jetbrains.kotlin.idea.editor.fixers
|
package org.jetbrains.kotlin.idea.editor.fixers
|
||||||
|
|
||||||
import com.intellij.lang.SmartEnterProcessorWithFixers
|
import com.intellij.lang.SmartEnterProcessorWithFixers
|
||||||
import org.jetbrains.kotlin.idea.editor.KotlinSmartEnterHandler
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.psi.KtWhileExpression
|
import org.jetbrains.kotlin.idea.editor.KotlinSmartEnterHandler
|
||||||
import org.jetbrains.kotlin.psi.KtBlockExpression
|
import org.jetbrains.kotlin.psi.KtBlockExpression
|
||||||
import org.jetbrains.kotlin.psi.KtLoopExpression
|
|
||||||
import org.jetbrains.kotlin.psi.KtForExpression
|
import org.jetbrains.kotlin.psi.KtForExpression
|
||||||
|
import org.jetbrains.kotlin.psi.KtLoopExpression
|
||||||
|
import org.jetbrains.kotlin.psi.KtWhileExpression
|
||||||
|
|
||||||
class KotlinMissingForOrWhileBodyFixer : SmartEnterProcessorWithFixers.Fixer<KotlinSmartEnterHandler>() {
|
class KotlinMissingForOrWhileBodyFixer : SmartEnterProcessorWithFixers.Fixer<KotlinSmartEnterHandler>() {
|
||||||
override fun apply(editor: Editor, processor: KotlinSmartEnterHandler, element: PsiElement) {
|
override fun apply(editor: Editor, processor: KotlinSmartEnterHandler, element: PsiElement) {
|
||||||
@@ -39,8 +39,7 @@ class KotlinMissingForOrWhileBodyFixer : SmartEnterProcessorWithFixers.Fixer<Kot
|
|||||||
|
|
||||||
if (body != null && body.startLine(doc) == loopExpression.startLine(doc)) return
|
if (body != null && body.startLine(doc) == loopExpression.startLine(doc)) return
|
||||||
|
|
||||||
val rParen = loopExpression.rightParenthesis
|
val rParen = loopExpression.rightParenthesis ?: return
|
||||||
if (rParen == null) return
|
|
||||||
|
|
||||||
doc.insertString(rParen.range.end, "{}")
|
doc.insertString(rParen.range.end, "{}")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,14 +17,13 @@
|
|||||||
package org.jetbrains.kotlin.idea.editor.fixers
|
package org.jetbrains.kotlin.idea.editor.fixers
|
||||||
|
|
||||||
import com.intellij.lang.SmartEnterProcessorWithFixers
|
import com.intellij.lang.SmartEnterProcessorWithFixers
|
||||||
import org.jetbrains.kotlin.idea.editor.KotlinSmartEnterHandler
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.kotlin.idea.editor.KotlinSmartEnterHandler
|
||||||
|
|
||||||
abstract class MissingConditionFixer<T: PsiElement>() : SmartEnterProcessorWithFixers.Fixer<KotlinSmartEnterHandler>() {
|
abstract class MissingConditionFixer<T: PsiElement>() : SmartEnterProcessorWithFixers.Fixer<KotlinSmartEnterHandler>() {
|
||||||
override fun apply(editor: Editor, processor: KotlinSmartEnterHandler, element: PsiElement) {
|
override fun apply(editor: Editor, processor: KotlinSmartEnterHandler, element: PsiElement) {
|
||||||
val workElement = getElement(element)
|
val workElement = getElement(element) ?: return
|
||||||
if (workElement == null) return
|
|
||||||
|
|
||||||
val doc = editor.document
|
val doc = editor.document
|
||||||
val lParen = getLeftParenthesis(workElement)
|
val lParen = getLeftParenthesis(workElement)
|
||||||
|
|||||||
Reference in New Issue
Block a user