From 40bd9fbdf3de31b5e9034dd8f1a52c72cc1ff3d1 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Tue, 21 Oct 2014 11:14:16 +0400 Subject: [PATCH] Refactoring: move functions --- .../jet/lang/psi/JetModifiableBlockHelper.kt | 83 ------------------- .../KotlinCodeBlockModificationListener.kt | 72 ++++++++++++++-- 2 files changed, 67 insertions(+), 88 deletions(-) delete mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetModifiableBlockHelper.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetModifiableBlockHelper.kt b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetModifiableBlockHelper.kt deleted file mode 100644 index f37613c026b..00000000000 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetModifiableBlockHelper.kt +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2010-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.lang.psi - -import com.intellij.psi.PsiElement -import com.intellij.psi.util.PsiTreeUtil - -/** - * Tested in OutOfBlockModificationTestGenerated - */ -public fun shouldChangeModificationCount(place: PsiElement): Boolean { - // false -> inside code block - // true -> means nothing, parent will be checked - - val declaration = PsiTreeUtil.getParentOfType(place, javaClass(), true) - if (declaration == null) return true - - return when (declaration) { - is JetNamedFunction -> { - val function: JetNamedFunction = declaration - if (function.hasDeclaredReturnType() || function.hasBlockBody()) { - takePartInDeclarationTypeInference(function) - } - else { - shouldChangeModificationCount(function) - } - } - is JetPropertyAccessor -> { - takePartInDeclarationTypeInference(declaration) - } - is JetProperty -> { - val property = declaration as JetProperty - if (property.getTypeReference() != null) { - takePartInDeclarationTypeInference(property) - } - else { - shouldChangeModificationCount(property) - } - } - is JetMultiDeclaration, is JetMultiDeclarationEntry, is JetFunctionLiteral -> { - shouldChangeModificationCount(declaration) - } - else -> { - true - } - } -} - -private fun takePartInDeclarationTypeInference(place: PsiElement): Boolean { - val declaration = PsiTreeUtil.getParentOfType(place, javaClass(), true) - if (declaration != null) { - if (declaration is JetNamedFunction) { - val function = declaration as JetNamedFunction - if (!function.hasDeclaredReturnType() && !function.hasBlockBody()) { - return true - } - } - else if (declaration is JetProperty) { - val property = declaration as JetProperty - if (property.getTypeReference() == null) { - return true - } - } - - return takePartInDeclarationTypeInference(declaration) - } - - return false -} \ No newline at end of file diff --git a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinCodeBlockModificationListener.kt b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinCodeBlockModificationListener.kt index ed5c6c9355e..b7e64b85f2d 100644 --- a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinCodeBlockModificationListener.kt +++ b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinCodeBlockModificationListener.kt @@ -23,11 +23,12 @@ import com.intellij.psi.impl.PsiTreeChangeEventImpl.PsiEventType.* import com.intellij.psi.impl.PsiTreeChangeEventImpl import com.intellij.psi.impl.PsiTreeChangePreprocessor import com.intellij.psi.util.PsiModificationTracker -import org.jetbrains.jet.lang.psi.JetBlockExpression -import org.jetbrains.jet.lang.psi.JetClass -import org.jetbrains.jet.lang.psi.JetFile -import org.jetbrains.jet.lang.psi.shouldChangeModificationCount +import org.jetbrains.jet.lang.psi.* +import com.intellij.psi.util.PsiTreeUtil +/** + * Tested in OutOfBlockModificationTestGenerated + */ public class KotlinCodeBlockModificationListener(modificationTracker: PsiModificationTracker) : PsiTreeChangePreprocessor { private val myModificationTracker = modificationTracker as PsiModificationTrackerImpl @@ -65,7 +66,7 @@ public class KotlinCodeBlockModificationListener(modificationTracker: PsiModific } } - private fun processChange(parent: PsiElement?, child1: PsiElement, child2: PsiElement?) { + private fun processChange(parent: PsiElement?, child1: PsiElement?, child2: PsiElement?) { try { if (!isInsideCodeBlock(parent)) { if (parent != null && parent.getContainingFile() is JetFile) { @@ -121,5 +122,66 @@ public class KotlinCodeBlockModificationListener(modificationTracker: PsiModific return false } + + public fun shouldChangeModificationCount(place: PsiElement): Boolean { + // false -> inside code block + // true -> means nothing, parent will be checked + + val declaration = PsiTreeUtil.getParentOfType(place, javaClass(), true) + if (declaration == null) return true + + return when (declaration) { + is JetNamedFunction -> { + val function: JetNamedFunction = declaration + if (function.hasDeclaredReturnType() || function.hasBlockBody()) { + takePartInDeclarationTypeInference(function) + } + else { + shouldChangeModificationCount(function) + } + } + is JetPropertyAccessor -> { + takePartInDeclarationTypeInference(declaration) + } + is JetProperty -> { + val property = declaration as JetProperty + if (property.getTypeReference() != null) { + takePartInDeclarationTypeInference(property) + } + else { + shouldChangeModificationCount(property) + } + } + is JetMultiDeclaration, is JetMultiDeclarationEntry, is JetFunctionLiteral -> { + shouldChangeModificationCount(declaration) + } + else -> { + true + } + } + } + + private fun takePartInDeclarationTypeInference(place: PsiElement): Boolean { + val declaration = PsiTreeUtil.getParentOfType(place, javaClass(), true) + if (declaration != null) { + if (declaration is JetNamedFunction) { + val function = declaration as JetNamedFunction + if (!function.hasDeclaredReturnType() && !function.hasBlockBody()) { + return true + } + } + else if (declaration is JetProperty) { + val property = declaration as JetProperty + if (property.getTypeReference() == null) { + return true + } + } + + return takePartInDeclarationTypeInference(declaration) + } + + return false + } } } +