From 31a712b4240ac91d28378e59d55c641e2288d8c1 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 12 Sep 2013 22:23:37 +0400 Subject: [PATCH] Removed IDE templates support from plugin. --- idea/src/META-INF/plugin.xml | 2 - .../jet/plugin/JetFoldingBuilder.java | 17 --- .../JetTemplateParameterTraversalPolicy.java | 104 --------------- idea/testData/templates/IdeTemplates.kt | 42 ------ .../plugin/codeInsight/IdeTemplatesTest.java | 120 ------------------ 5 files changed, 285 deletions(-) delete mode 100644 idea/src/org/jetbrains/jet/plugin/completion/JetTemplateParameterTraversalPolicy.java delete mode 100644 idea/testData/templates/IdeTemplates.kt delete mode 100644 idea/tests/org/jetbrains/jet/plugin/codeInsight/IdeTemplatesTest.java diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index e0d75a22dfb..805b3f9eccd 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -162,8 +162,6 @@ displayName="Kotlin Compiler" parentId="project.propCompiler"/> - - diff --git a/idea/src/org/jetbrains/jet/plugin/JetFoldingBuilder.java b/idea/src/org/jetbrains/jet/plugin/JetFoldingBuilder.java index 1517c92a1eb..cb4494691c8 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetFoldingBuilder.java +++ b/idea/src/org/jetbrains/jet/plugin/JetFoldingBuilder.java @@ -34,7 +34,6 @@ import org.jetbrains.jet.lang.psi.JetImportDirective; import org.jetbrains.jet.lexer.JetTokens; import java.util.ArrayList; -import java.util.Collections; import java.util.List; public class JetFoldingBuilder extends FoldingBuilderEx implements DumbAware { @@ -68,16 +67,6 @@ public class JetFoldingBuilder extends FoldingBuilderEx implements DumbAware { !isOneLine(textRange, document)) { descriptors.add(new FoldingDescriptor(node, textRange)); } - else if (node.getElementType() == JetTokens.IDE_TEMPLATE_START) { - ASTNode next = node.getTreeNext(); - if (next != null) { - ASTNode nextNext = next.getTreeNext(); - if (nextNext != null && nextNext.getElementType() == JetTokens.IDE_TEMPLATE_END) { - TextRange range = new TextRange(node.getStartOffset(), nextNext.getStartOffset() + nextNext.getTextLength()); - descriptors.add(new FoldingDescriptor(next, range, null, Collections.emptySet(), true)); - } - } - } ASTNode child = node.getFirstChildNode(); while (child != null) { appendDescriptors(child, document, descriptors); @@ -91,12 +80,6 @@ public class JetFoldingBuilder extends FoldingBuilderEx implements DumbAware { @Override public String getPlaceholderText(@NotNull ASTNode node) { - ASTNode prev = node.getTreePrev(); - ASTNode next = node.getTreeNext(); - if (prev != null && next != null && prev.getElementType() == JetTokens.IDE_TEMPLATE_START - && next.getElementType() == JetTokens.IDE_TEMPLATE_END) { - return node.getText(); - } if (node.getElementType() == JetTokens.BLOCK_COMMENT) { return "/.../"; } diff --git a/idea/src/org/jetbrains/jet/plugin/completion/JetTemplateParameterTraversalPolicy.java b/idea/src/org/jetbrains/jet/plugin/completion/JetTemplateParameterTraversalPolicy.java deleted file mode 100644 index 6c601e8f982..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/completion/JetTemplateParameterTraversalPolicy.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2010-2013 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.completion; - -import com.intellij.codeInsight.completion.TemplateParameterTraversalPolicy; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.ScrollType; -import com.intellij.openapi.editor.SelectionModel; -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDocumentManager; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.util.PsiTreeUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.psi.JetFile; -import org.jetbrains.jet.lang.psi.JetIdeTemplate; -import org.jetbrains.jet.lexer.JetToken; -import org.jetbrains.jet.lexer.JetTokens; - -public class JetTemplateParameterTraversalPolicy implements TemplateParameterTraversalPolicy { - @Override - public boolean isValidForFile(Editor editor, PsiFile file) { - return file instanceof JetFile && PsiTreeUtil.findChildOfType(file, JetIdeTemplate.class) != null; - } - - @Override - public void invoke(Editor editor, PsiFile file, boolean next) { - Project project = editor.getProject(); - if (project == null) { - return; - } - PsiDocumentManager.getInstance(project).commitAllDocuments(); - - JetToken terminatingToken = next ? JetTokens.IDE_TEMPLATE_START : JetTokens.IDE_TEMPLATE_END; - - SelectionModel selModel = editor.getSelectionModel(); - PsiElement first = file.findElementAt((selModel.getSelectionStart() + selModel.getSelectionEnd()) / 2); - PsiElement current = first; - if (first != null) { - do { - if (current.getNode().getElementType() == terminatingToken) { - selectTemplate(editor, selModel, current, next); - return; - } - - current = goToNextPrevElement(current, next); - } while (current != first); - } - } - - @NotNull - private static PsiElement goToNextPrevElement(@NotNull PsiElement element, boolean next) { - if (next) { - PsiElement nextLeaf = PsiTreeUtil.nextLeaf(element); - if (nextLeaf == null) { - PsiElement root = PsiTreeUtil.getTopmostParentOfType(element, JetFile.class); - assert root != null; - return PsiTreeUtil.firstChild(root); - } - return nextLeaf; - } - else { - PsiElement prevLeaf = PsiTreeUtil.prevLeaf(element); - if (prevLeaf == null) { - PsiElement root = PsiTreeUtil.getTopmostParentOfType(element, JetFile.class); - assert root != null; - return PsiTreeUtil.lastChild(root); - } - return prevLeaf; - } - } - - private static void selectTemplate(Editor editor, SelectionModel selModel, PsiElement current, boolean next) { - PsiElement match = goToNextPrevElement(goToNextPrevElement(current, next), next); - JetToken expected = next ? JetTokens.IDE_TEMPLATE_END : JetTokens.IDE_TEMPLATE_START; - if (expected != match.getNode().getElementType()) return; - - int start = Math.min(current.getTextOffset(), match.getTextOffset()); - int end = Math.max(current.getTextOffset() + current.getTextLength(), - match.getTextOffset() + match.getTextLength()); - - editor.getCaretModel().moveToOffset(end); - editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); - - editor.getCaretModel().moveToOffset(start); - editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); - - selModel.setSelection(start, end); - } -} diff --git a/idea/testData/templates/IdeTemplates.kt b/idea/testData/templates/IdeTemplates.kt deleted file mode 100644 index f13e6d27dfb..00000000000 --- a/idea/testData/templates/IdeTemplates.kt +++ /dev/null @@ -1,42 +0,0 @@ -fun main(args : Array) { - if (<##>) { - <##> - } else { - <##> - } - - fun <##>(<##>) : <##> { - <##> - } - - for (<##> in <##>) { - <##> - } - - when (<##>) { - <##> -> <##> - else -> <##> - } - - var <##> = <##> - - class <##> { - <##> - } - - class <##> { - var <##> : <##> - get() { - <##> - } - set(value) { - <##> - } - - val <##> : <##> - get() { - <##> - } - } -} - diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/IdeTemplatesTest.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/IdeTemplatesTest.java deleted file mode 100644 index 0b71786ffe4..00000000000 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/IdeTemplatesTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2010-2013 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.codeInsight; - -import com.intellij.codeInsight.folding.CodeFoldingManager; -import com.intellij.ide.DataManager; -import com.intellij.openapi.actionSystem.ActionManager; -import com.intellij.openapi.actionSystem.ActionPlaces; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.editor.FoldRegion; -import com.intellij.openapi.editor.SelectionModel; -import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.plugin.PluginTestCaseBase; - -import java.util.ArrayList; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class IdeTemplatesTest extends LightCodeInsightFixtureTestCase { - private ArrayList myExpectedRegions; - - @Override - protected void setUp() throws Exception { - super.setUp(); - myFixture.setTestDataPath(PluginTestCaseBase.getTestDataPathBase() + "/templates/"); - } - - public void testAll() { - myFixture.configureByFile("IdeTemplates.kt"); - CodeFoldingManager.getInstance(myFixture.getProject()).buildInitialFoldings(myFixture.getEditor()); - - myExpectedRegions = getExpectedRegions(); - assertEquals(myExpectedRegions.toString(), getActualRegions().toString()); - - for (int i = 0; i <= myExpectedRegions.size(); i++) { - nextParam(); - checkSelectedRegion(i % myExpectedRegions.size()); - } - - for (int i = myExpectedRegions.size() - 1; i >= 0; i--) { - prevParam(); - checkSelectedRegion(i); - } - } - - private void checkSelectedRegion(int region) { - SelectionModel selectionModel = myFixture.getEditor().getSelectionModel(); - assertEquals(myExpectedRegions.get(region).start, selectionModel.getSelectionStart()); - assertEquals(myExpectedRegions.get(region).end, selectionModel.getSelectionEnd()); - } - - private void prevParam() { - doAction("PrevTemplateParameter"); - } - - private void nextParam() { - doAction("NextTemplateParameter"); - } - - private ArrayList getExpectedRegions() { - Pattern regex = Pattern.compile("<#<(\\w+)>#>"); - Matcher matcher = regex.matcher(myFixture.getEditor().getDocument().getText()); - ArrayList expected = new ArrayList(); - while (matcher.find()) { - expected.add(new Region(matcher.start(), matcher.end(), matcher.group(1))); - } - return expected; - } - - private ArrayList getActualRegions() { - ArrayList actual = new ArrayList(); - for (FoldRegion fr : myFixture.getEditor().getFoldingModel().getAllFoldRegions()) { - if (fr.shouldNeverExpand()) { - assertFalse(fr.isExpanded()); - actual.add(new Region(fr.getStartOffset(), fr.getEndOffset(), fr.getPlaceholderText())); - } - } - return actual; - } - - private void doAction(@NotNull String actionId) { - AnAction action = ActionManager.getInstance().getAction(actionId); - action.actionPerformed(new AnActionEvent(null, DataManager.getInstance().getDataContext(myFixture.getEditor().getComponent()), - ActionPlaces.UNKNOWN, action.getTemplatePresentation(), - ActionManager.getInstance(), 0)); - } - - private static class Region { - public int start; - public int end; - public String group; - - private Region(int start, int end, String group) { - this.start = start; - this.end = end; - this.group = group; - } - - @Override - public String toString() { - return String.format("%d..%d:%s", start, end, group); - } - } -}