IDE: folding imports
This commit is contained in:
@@ -31,6 +31,7 @@ import org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveDescriptorRenderer
|
||||
import org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveNamespaceComparingTest;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveTest;
|
||||
import org.jetbrains.jet.plugin.codeInsight.surroundWith.AbstractSurroundWithTest;
|
||||
import org.jetbrains.jet.plugin.folding.AbstractKotlinFoldingTest;
|
||||
import org.jetbrains.jet.plugin.highlighter.AbstractDeprecatedHighlightingTest;
|
||||
import org.jetbrains.jet.plugin.quickfix.AbstractQuickFixMultiFileTest;
|
||||
import org.jetbrains.jet.plugin.quickfix.AbstractQuickFixTest;
|
||||
@@ -231,6 +232,13 @@ public class GenerateTests {
|
||||
testModel("idea/testData/highlighter/deprecated")
|
||||
);
|
||||
|
||||
generateTest(
|
||||
"idea/tests/",
|
||||
"KotlinFoldingTestGenerated",
|
||||
AbstractKotlinFoldingTest.class,
|
||||
testModel("idea/testData/folding")
|
||||
);
|
||||
|
||||
generateTest(
|
||||
"idea/tests/",
|
||||
"SurroundWithTestGenerated",
|
||||
|
||||
@@ -26,6 +26,8 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -36,7 +38,22 @@ public class JetFoldingBuilder extends FoldingBuilderEx implements DumbAware {
|
||||
@NotNull
|
||||
@Override
|
||||
public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) {
|
||||
if (!(root instanceof JetFile)) {
|
||||
return FoldingDescriptor.EMPTY;
|
||||
}
|
||||
List<FoldingDescriptor> descriptors = new ArrayList<FoldingDescriptor>();
|
||||
JetFile file = (JetFile) root;
|
||||
|
||||
List<JetImportDirective> importList = file.getImportDirectives();
|
||||
if (importList != null && !importList.isEmpty()) {
|
||||
JetImportDirective firstImport = importList.get(0);
|
||||
PsiElement importKeyword = firstImport.getFirstChild();
|
||||
int startOffset = importKeyword.getTextRange().getEndOffset() + 1;
|
||||
int endOffset = importList.get(importList.size() - 1).getTextRange().getEndOffset();
|
||||
TextRange range = new TextRange(startOffset, endOffset);
|
||||
descriptors.add(new FoldingDescriptor(firstImport, range));
|
||||
}
|
||||
|
||||
appendDescriptors(root.getNode(), document, descriptors);
|
||||
return descriptors.toArray(new FoldingDescriptor[descriptors.size()]);
|
||||
}
|
||||
@@ -77,6 +94,9 @@ public class JetFoldingBuilder extends FoldingBuilderEx implements DumbAware {
|
||||
&& next.getElementType() == JetTokens.IDE_TEMPLATE_END) {
|
||||
return astNode.getText();
|
||||
}
|
||||
if (astNode.getPsi() instanceof JetImportDirective) {
|
||||
return "...";
|
||||
}
|
||||
return "{...}";
|
||||
}
|
||||
|
||||
@@ -87,6 +107,9 @@ public class JetFoldingBuilder extends FoldingBuilderEx implements DumbAware {
|
||||
|
||||
@Override
|
||||
public boolean isCollapsedByDefault(@NotNull ASTNode astNode) {
|
||||
if (astNode.getPsi() instanceof JetImportDirective) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
class A <fold text='{...}'>{
|
||||
val a = 1
|
||||
val b = 1
|
||||
}</fold>
|
||||
@@ -0,0 +1,4 @@
|
||||
fun foo() <fold text='{...}'>{
|
||||
val a = 1
|
||||
val b = 1
|
||||
}</fold>
|
||||
@@ -0,0 +1,6 @@
|
||||
import <fold text='...'>kotlin.*
|
||||
import kotlin.*
|
||||
import kotlin.*
|
||||
import kotlin.*</fold>
|
||||
|
||||
fun foo() {}
|
||||
@@ -0,0 +1,4 @@
|
||||
object A <fold text='{...}'>{
|
||||
val a = 1
|
||||
val b = 1
|
||||
}</fold>
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.folding;
|
||||
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.plugin.JetLightProjectDescriptor;
|
||||
|
||||
public abstract class AbstractKotlinFoldingTest extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
protected void doTest(@NotNull String path) {
|
||||
myFixture.testFolding(path);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JetLightProjectDescriptor.INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.folding;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
|
||||
import org.jetbrains.jet.plugin.folding.AbstractKotlinFoldingTest;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("idea/testData/folding")
|
||||
public class KotlinFoldingTestGenerated extends AbstractKotlinFoldingTest {
|
||||
public void testAllFilesPresentInFolding() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/folding"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("class.kt")
|
||||
public void testClass() throws Exception {
|
||||
doTest("idea/testData/folding/class.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("function.kt")
|
||||
public void testFunction() throws Exception {
|
||||
doTest("idea/testData/folding/function.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("imports.kt")
|
||||
public void testImports() throws Exception {
|
||||
doTest("idea/testData/folding/imports.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("object.kt")
|
||||
public void testObject() throws Exception {
|
||||
doTest("idea/testData/folding/object.kt");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user