From 879f0d201e9dbe7c7eb0e849dc65930a6163fa49 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Wed, 1 Oct 2014 13:23:13 +0400 Subject: [PATCH] Converted JetDeclarationJoinLinesHandler to Kotlin --- .../codeInsight/editorActions/annotations.xml | 16 ++++++ .../JetDeclarationJoinLinesHandler.java | 52 ------------------- .../JetDeclarationJoinLinesHandler.kt | 41 +++++++++++++++ 3 files changed, 57 insertions(+), 52 deletions(-) delete mode 100644 idea/src/org/jetbrains/jet/plugin/intentions/declarations/JetDeclarationJoinLinesHandler.java create mode 100644 idea/src/org/jetbrains/jet/plugin/intentions/declarations/JetDeclarationJoinLinesHandler.kt diff --git a/annotations/com/intellij/codeInsight/editorActions/annotations.xml b/annotations/com/intellij/codeInsight/editorActions/annotations.xml index 889d139f2f3..460373c801a 100644 --- a/annotations/com/intellij/codeInsight/editorActions/annotations.xml +++ b/annotations/com/intellij/codeInsight/editorActions/annotations.xml @@ -168,4 +168,20 @@ name='com.intellij.codeInsight.editorActions.CopyPasteReferenceProcessor void restoreReferences(com.intellij.codeInsight.editorActions.ReferenceData[], TRef[]) 1'> + + + + + + + + + + + + diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/declarations/JetDeclarationJoinLinesHandler.java b/idea/src/org/jetbrains/jet/plugin/intentions/declarations/JetDeclarationJoinLinesHandler.java deleted file mode 100644 index bf959a99655..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/intentions/declarations/JetDeclarationJoinLinesHandler.java +++ /dev/null @@ -1,52 +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.plugin.intentions.declarations; - -import com.intellij.codeInsight.editorActions.JoinRawLinesHandlerDelegate; -import com.intellij.openapi.editor.Document; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.util.ArrayUtil; -import kotlin.Function1; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.psi.JetPsiUtil; -import org.jetbrains.jet.lang.psi.psiUtil.PsiUtilPackage; - -public class JetDeclarationJoinLinesHandler implements JoinRawLinesHandlerDelegate { - private static final Function1 IS_APPLICABLE = new Function1() { - @Override - public Boolean invoke(@Nullable PsiElement input) { - return input != null && DeclarationUtils.checkAndGetPropertyAndInitializer(input) != null; - } - }; - - @Override - public int tryJoinRawLines(Document document, PsiFile file, int start, int end) { - PsiElement element = JetPsiUtil.skipSiblingsBackwardByPredicate(file.findElementAt(start), DeclarationUtils.SKIP_DELIMITERS); - - //noinspection unchecked - PsiElement target = PsiUtilPackage.getParentByTypesAndPredicate(element, false, ArrayUtil.EMPTY_CLASS_ARRAY, IS_APPLICABLE); - if (target == null) return -1; - - return DeclarationUtils.joinPropertyDeclarationWithInitializer(target).getTextRange().getStartOffset(); - } - - @Override - public int tryJoinLines(Document document, PsiFile file, int start, int end) { - return -1; - } -} \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/declarations/JetDeclarationJoinLinesHandler.kt b/idea/src/org/jetbrains/jet/plugin/intentions/declarations/JetDeclarationJoinLinesHandler.kt new file mode 100644 index 00000000000..81392d0380f --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/intentions/declarations/JetDeclarationJoinLinesHandler.kt @@ -0,0 +1,41 @@ +/* + * 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.plugin.intentions.declarations + +import com.intellij.codeInsight.editorActions.JoinRawLinesHandlerDelegate +import com.intellij.openapi.editor.Document +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiFile +import com.intellij.util.ArrayUtil +import org.jetbrains.jet.lang.psi.JetPsiUtil +import org.jetbrains.jet.lang.psi.psiUtil.* + +public class JetDeclarationJoinLinesHandler : JoinRawLinesHandlerDelegate { + + override fun tryJoinRawLines(document: Document, file: PsiFile, start: Int, end: Int): Int { + val element = JetPsiUtil.skipSiblingsBackwardByPredicate(file.findElementAt(start), DeclarationUtils.SKIP_DELIMITERS) + + val target = element?.getParentByTypesAndPredicate(strict = false) { + DeclarationUtils.checkAndGetPropertyAndInitializer(it) != null + } ?: return -1 + + return DeclarationUtils.joinPropertyDeclarationWithInitializer(target).getTextRange()!!.getStartOffset() + } + + override fun tryJoinLines(document: Document, file: PsiFile, start: Int, end: Int) + = -1 +} \ No newline at end of file