Removed IDE templates support from plugin.

This commit is contained in:
Evgeny Gerashchenko
2013-09-12 22:23:37 +04:00
parent 859b0b845a
commit 31a712b424
5 changed files with 0 additions and 285 deletions
-2
View File
@@ -162,8 +162,6 @@
displayName="Kotlin Compiler"
parentId="project.propCompiler"/>
<templateParameterTraversalPolicy implementation="org.jetbrains.jet.plugin.completion.JetTemplateParameterTraversalPolicy"/>
<codeInsight.parameterInfo language="jet" implementationClass="org.jetbrains.jet.plugin.parameterInfo.JetFunctionParameterInfoHandler"/>
<codeInsight.gotoSuper language="jet" implementationClass="org.jetbrains.jet.plugin.codeInsight.GotoSuperActionHandler"/>
@@ -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.<Object>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 "/.../";
}
@@ -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);
}
}
-42
View File
@@ -1,42 +0,0 @@
fun main(args : Array<String>) {
if (<#<condition>#>) {
<#<block>#>
} else {
<#<block>#>
}
fun <#<name>#>(<#<params>#>) : <#<returnType>#> {
<#<body>#>
}
for (<#<i>#> in <#<elements>#>) {
<#<body>#>
}
when (<#<expression>#>) {
<#<condition>#> -> <#<value>#>
else -> <#<elseValue>#>
}
var <#<name>#> = <#<value>#>
class <#<name>#> {
<#<body>#>
}
class <#<name>#> {
var <#<name>#> : <#<varType>#>
get() {
<#<body>#>
}
set(value) {
<#<body>#>
}
val <#<name>#> : <#<valType>#>
get() {
<#<body>#>
}
}
}
@@ -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<Region> 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<Region> getExpectedRegions() {
Pattern regex = Pattern.compile("<#<(\\w+)>#>");
Matcher matcher = regex.matcher(myFixture.getEditor().getDocument().getText());
ArrayList<Region> expected = new ArrayList<Region>();
while (matcher.find()) {
expected.add(new Region(matcher.start(), matcher.end(), matcher.group(1)));
}
return expected;
}
private ArrayList<Region> getActualRegions() {
ArrayList<Region> actual = new ArrayList<Region>();
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);
}
}
}