replace null checks with elvis operator

This commit is contained in:
Kirill Rakhman
2016-02-23 16:35:12 +01:00
parent c71c344b8a
commit c1a2570dd4
3 changed files with 9 additions and 13 deletions
@@ -17,9 +17,9 @@
package org.jetbrains.kotlin.idea.editor.fixers
import com.intellij.lang.SmartEnterProcessorWithFixers
import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.idea.editor.KotlinSmartEnterHandler
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.psi.KtNamedFunction
@@ -29,8 +29,7 @@ class KotlinFunctionParametersFixer : SmartEnterProcessorWithFixers.Fixer<Kotlin
val parameterList = psiElement.valueParameterList
if (parameterList == null) {
val identifier = psiElement.nameIdentifier
if (identifier == null) return
val identifier = psiElement.nameIdentifier ?: return
// 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)
@@ -38,8 +37,7 @@ class KotlinFunctionParametersFixer : SmartEnterProcessorWithFixers.Fixer<Kotlin
processor.registerUnresolvedError(offset + 1)
}
else {
val rParen = parameterList.lastChild
if (rParen == null) return
val rParen = parameterList.lastChild ?: return
if (")" != rParen.text) {
val params = parameterList.parameters
@@ -17,13 +17,13 @@
package org.jetbrains.kotlin.idea.editor.fixers
import com.intellij.lang.SmartEnterProcessorWithFixers
import org.jetbrains.kotlin.idea.editor.KotlinSmartEnterHandler
import com.intellij.openapi.editor.Editor
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.KtLoopExpression
import org.jetbrains.kotlin.psi.KtForExpression
import org.jetbrains.kotlin.psi.KtLoopExpression
import org.jetbrains.kotlin.psi.KtWhileExpression
class KotlinMissingForOrWhileBodyFixer : SmartEnterProcessorWithFixers.Fixer<KotlinSmartEnterHandler>() {
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
val rParen = loopExpression.rightParenthesis
if (rParen == null) return
val rParen = loopExpression.rightParenthesis ?: return
doc.insertString(rParen.range.end, "{}")
}
@@ -17,14 +17,13 @@
package org.jetbrains.kotlin.idea.editor.fixers
import com.intellij.lang.SmartEnterProcessorWithFixers
import org.jetbrains.kotlin.idea.editor.KotlinSmartEnterHandler
import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.idea.editor.KotlinSmartEnterHandler
abstract class MissingConditionFixer<T: PsiElement>() : SmartEnterProcessorWithFixers.Fixer<KotlinSmartEnterHandler>() {
override fun apply(editor: Editor, processor: KotlinSmartEnterHandler, element: PsiElement) {
val workElement = getElement(element)
if (workElement == null) return
val workElement = getElement(element) ?: return
val doc = editor.document
val lParen = getLeftParenthesis(workElement)