Merge remote-tracking branch 'origin/master'

This commit is contained in:
pTalanov
2012-02-27 19:57:37 +04:00
68 changed files with 1350 additions and 310 deletions
+3
View File
@@ -128,6 +128,9 @@
<annotator language="jet" implementationClass="org.jetbrains.jet.plugin.annotations.JetPsiChecker"/>
<annotator language="jet" implementationClass="org.jetbrains.jet.plugin.annotations.DebugInfoAnnotator"/>
<extendWordSelectionHandler implementation="org.jetbrains.jet.plugin.JetStatementGroupSelectioner"/>
<extendWordSelectionHandler implementation="org.jetbrains.jet.plugin.JetCodeBlockSelectioner"/>
<documentationProvider implementation="org.jetbrains.jet.plugin.JetQuickDocumentationProvider"/>
<configurationType implementation="org.jetbrains.jet.plugin.run.JetRunConfigurationType"/>
<configurationProducer implementation="org.jetbrains.jet.plugin.run.JetRunConfigurationProducer"/>
@@ -0,0 +1,93 @@
/*
* Copyright 2000-2012 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;
import com.intellij.codeInsight.editorActions.wordSelection.BasicSelectioner;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.impl.source.tree.LeafPsiElement;
import org.jetbrains.jet.lang.psi.JetBlockExpression;
import org.jetbrains.jet.lang.psi.JetWhenExpression;
import org.jetbrains.jet.lexer.JetTokens;
import java.util.ArrayList;
import java.util.List;
/**
* Originally from IDEA platform: CodeBlockOrInitializerSelectioner
*/
public class JetCodeBlockSelectioner extends BasicSelectioner {
public boolean canSelect(PsiElement e) {
return e instanceof JetBlockExpression || e instanceof JetWhenExpression;
}
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
List<TextRange> result = new ArrayList<TextRange>();
ASTNode[] children = e.getNode().getChildren(null);
int start = findOpeningBrace(children);
int end = findClosingBrace(children, start);
result.add(e.getTextRange());
result.addAll(expandToWholeLine(editorText, new TextRange(start, end)));
return result;
}
public static int findOpeningBrace(ASTNode[] children) {
int start = children[children.length - 1].getTextRange().getStartOffset();
for (int i = 0; i < children.length; i++) {
PsiElement child = children[i].getPsi();
if (child instanceof LeafPsiElement) {
if (((LeafPsiElement) child).getElementType() == JetTokens.LBRACE) {
int j = i + 1;
while (children[j] instanceof PsiWhiteSpace) {
j++;
}
start = children[j].getTextRange().getStartOffset();
}
}
}
return start;
}
public static int findClosingBrace(ASTNode[] children, int startOffset) {
int end = children[children.length - 1].getTextRange().getEndOffset();
for (int i = 0; i < children.length; i++) {
PsiElement child = children[i].getPsi();
if (child instanceof LeafPsiElement) {
if (((LeafPsiElement) child).getElementType() == JetTokens.RBRACE) {
int j = i - 1;
while (children[j] instanceof PsiWhiteSpace && children[j].getTextRange().getStartOffset() > startOffset) {
j--;
}
end = children[j].getTextRange().getEndOffset();
}
}
}
return end;
}
}
@@ -0,0 +1,112 @@
/*
* Copyright 2000-2012 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;
import com.intellij.codeInsight.editorActions.wordSelection.BasicSelectioner;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.LineTokenizer;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.impl.source.tree.LeafPsiElement;
import org.jetbrains.jet.lang.psi.JetBlockExpression;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetWhenEntry;
import org.jetbrains.jet.lang.psi.JetWhenExpression;
import org.jetbrains.jet.lexer.JetTokens;
import java.util.ArrayList;
import java.util.List;
/**
* Originally from IDEA platform: StatementGroupSelectioner
*/
public class JetStatementGroupSelectioner extends BasicSelectioner {
public boolean canSelect(PsiElement e) {
return e instanceof JetExpression || e instanceof JetWhenEntry;
}
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
List<TextRange> result = new ArrayList<TextRange>();
PsiElement parent = e.getParent();
if (!(parent instanceof JetBlockExpression) && !(parent instanceof JetWhenExpression)) {
return result;
}
PsiElement startElement = e;
PsiElement endElement = e;
while (startElement.getPrevSibling() != null) {
PsiElement sibling = startElement.getPrevSibling();
if (sibling instanceof LeafPsiElement) {
if (((LeafPsiElement) sibling).getElementType() == JetTokens.LBRACE) {
break;
}
}
if (sibling instanceof PsiWhiteSpace) {
PsiWhiteSpace whiteSpace = (PsiWhiteSpace) sibling;
String[] strings = LineTokenizer.tokenize(whiteSpace.getText().toCharArray(), false);
if (strings.length > 2) {
break;
}
}
startElement = sibling;
}
while (startElement instanceof PsiWhiteSpace) {
startElement = startElement.getNextSibling();
}
while (endElement.getNextSibling() != null) {
PsiElement sibling = endElement.getNextSibling();
if (sibling instanceof LeafPsiElement) {
if (((LeafPsiElement) sibling).getElementType() == JetTokens.RBRACE) {
break;
}
}
if (sibling instanceof PsiWhiteSpace) {
PsiWhiteSpace whiteSpace = (PsiWhiteSpace) sibling;
String[] strings = LineTokenizer.tokenize(whiteSpace.getText().toCharArray(), false);
if (strings.length > 2) {
break;
}
}
endElement = sibling;
}
while (endElement instanceof PsiWhiteSpace) {
endElement = endElement.getPrevSibling();
}
result.addAll(expandToWholeLine(editorText, new TextRange(startElement.getTextRange().getStartOffset(),
endElement.getTextRange().getEndOffset())));
return result;
}
}
@@ -90,7 +90,7 @@ public class JetFunctionInsertHandler implements InsertHandler<LookupElement> {
// Insert () if it's not already exist
document.insertString(endOffset, "()");
bothParentheses = true;
} else if (endOffset + 1 < documentText.length() && documentText.charAt(endOffset) == ')') {
} else if (endOffset + 1 < documentText.length() && documentText.charAt(endOffset + 1) == ')') {
bothParentheses = true;
}
@@ -44,6 +44,8 @@ public class JetFormattingModelBuilder implements FormattingModelBuilder {
private static SpacingBuilder createSpacingBuilder(CodeStyleSettings settings) {
return new SpacingBuilder(settings)
.after(NAMESPACE_HEADER).blankLines(1)
.before(IMPORT_DIRECTIVE).lineBreakInCode()
.between(IMPORT_DIRECTIVE, CLASS).blankLines(1)
.between(IMPORT_DIRECTIVE, FUN).blankLines(1)
@@ -89,9 +89,14 @@ public class ImportClassHelper {
}
else {
List<JetDeclaration> declarations = file.getDeclarations();
assert !declarations.isEmpty();
JetDeclaration firstDeclaration = declarations.iterator().next();
firstDeclaration.getParent().addBefore(newDirective, firstDeclaration);
if (!declarations.isEmpty()) {
JetDeclaration firstDeclaration = declarations.iterator().next();
firstDeclaration.getParent().addBefore(newDirective, firstDeclaration);
}
else {
file.getNamespaceHeader().getParent().addAfter(newDirective, file.getNamespaceHeader());
}
}
}
@@ -19,6 +19,7 @@ package org.jetbrains.jet.plugin.references;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.psi.JetArrayAccessExpression;
import org.jetbrains.jet.lang.psi.JetContainerNode;
@@ -44,7 +45,7 @@ class JetArrayAccessReference extends JetPsiReference implements MultiRangeRefer
return indicesNode == null ? PsiReference.EMPTY_ARRAY : new PsiReference[] { new JetArrayAccessReference(expression) };
}
public JetArrayAccessReference(JetArrayAccessExpression expression) {
public JetArrayAccessReference(@NotNull JetArrayAccessExpression expression) {
super(expression);
this.expression = expression;
}
@@ -17,7 +17,6 @@
package org.jetbrains.jet.plugin.references;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.compiler.TipsManager;
import org.jetbrains.jet.lang.psi.JetFile;
@@ -33,7 +32,7 @@ public class JetPackageReference extends JetPsiReference {
private JetNamespaceHeader packageExpression;
public JetPackageReference(JetNamespaceHeader expression) {
public JetPackageReference(@NotNull JetNamespaceHeader expression) {
super(expression);
packageExpression = expression;
}
@@ -48,11 +47,10 @@ public class JetPackageReference extends JetPsiReference {
bindingContext, TipsManager.getReferenceVariants(packageExpression, bindingContext));
}
@NotNull
@Override
public TextRange getRangeInElement() {
PsiElement element = getElement();
if (element == null) return null;
return new TextRange(0, element.getTextLength());
return new TextRange(0, getElement().getTextLength());
}
@NotNull
@@ -22,6 +22,7 @@ import com.intellij.psi.PsiPolyVariantReference;
import com.intellij.psi.ResolveResult;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
@@ -36,12 +37,15 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.AMBIGUOUS_REFERENCE_
import static org.jetbrains.jet.lang.resolve.BindingContext.DESCRIPTOR_TO_DECLARATION;
public abstract class JetPsiReference implements PsiPolyVariantReference {
@NotNull
protected final JetReferenceExpression myExpression;
protected JetPsiReference(JetReferenceExpression expression) {
protected JetPsiReference(@NotNull JetReferenceExpression expression) {
this.myExpression = expression;
}
@NotNull
@Override
public PsiElement getElement() {
return myExpression;
@@ -69,6 +73,7 @@ public abstract class JetPsiReference implements PsiPolyVariantReference {
throw new IncorrectOperationException();
}
@NotNull
@Override
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
throw new IncorrectOperationException();
@@ -90,6 +95,7 @@ public abstract class JetPsiReference implements PsiPolyVariantReference {
return false;
}
@Nullable
protected PsiElement doResolve() {
JetFile file = (JetFile) getElement().getContainingFile();
BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file);
@@ -33,23 +33,29 @@ import org.jetbrains.jet.plugin.completion.DescriptorLookupConverter;
*/
public class JetSimpleNameReference extends JetPsiReference {
@NotNull
private final JetSimpleNameExpression myExpression;
public JetSimpleNameReference(JetSimpleNameExpression jetSimpleNameExpression) {
public JetSimpleNameReference(@NotNull JetSimpleNameExpression jetSimpleNameExpression) {
super(jetSimpleNameExpression);
myExpression = jetSimpleNameExpression;
}
@NotNull
@Override
public PsiElement getElement() {
return myExpression.getReferencedNameElement();
}
@NotNull
public JetSimpleNameExpression getExpression() {
return myExpression;
}
@NotNull
@Override
public TextRange getRangeInElement() {
PsiElement element = getElement();
if (element == null) return null;
return new TextRange(0, element.getTextLength());
return new TextRange(0, getElement().getTextLength());
}
@NotNull
@@ -7,7 +7,7 @@ fun test(s: String?) {
val <warning>d</warning>: Int = s?.length ?: <error>"empty"</error>
val e: String = <error>s?.length</error> ?: "empty"
val <warning>f</warning>: Int = s?.length ?: b ?: 1
val <warning>g</warning>: Int? = e? startsWith("s")?.length
val <warning>g</warning>: Boolean? = e.startsWith("s")//?.length
}
fun String.startsWith(<warning>s</warning>: String): Boolean = true
@@ -0,0 +1,24 @@
fun main(args : Array<String>) {
for (i in 1..100) {
when {
i%3 == 0 -> {print("Fizz"); continue;}
i%5 == 0 -> {print("Buzz"); continue;}
(i%3 != 0 && i%5 != 0) -> {print(i); continue;}
else -> println()
}
}
}
fun foo() : Unit {
println() {
println()
<selection>pr<caret>intln</selection>()
println()
}
println(array(1, 2, 3))
println()
}
@@ -0,0 +1,24 @@
fun main(args : Array<String>) {
for (i in 1..100) {
when {
i%3 == 0 -> {print("Fizz"); continue;}
i%5 == 0 -> {print("Buzz"); continue;}
(i%3 != 0 && i%5 != 0) -> {print(i); continue;}
else -> println()
}
}
}
<selection>fun foo() : Unit {
println() {
println()
pr<caret>intln()
println()
}
println(array(1, 2, 3))
println()
}</selection>
@@ -0,0 +1,24 @@
<selection>fun main(args : Array<String>) {
for (i in 1..100) {
when {
i%3 == 0 -> {print("Fizz"); continue;}
i%5 == 0 -> {print("Buzz"); continue;}
(i%3 != 0 && i%5 != 0) -> {print(i); continue;}
else -> println()
}
}
}
fun foo() : Unit {
println() {
println()
pr<caret>intln()
println()
}
println(array(1, 2, 3))
println()
}</selection>
@@ -0,0 +1,24 @@
fun main(args : Array<String>) {
for (i in 1..100) {
when {
i%3 == 0 -> {print("Fizz"); continue;}
i%5 == 0 -> {print("Buzz"); continue;}
(i%3 != 0 && i%5 != 0) -> {print(i); continue;}
else -> println()
}
}
}
fun foo() : Unit {
println() {
println()
<selection>pr<caret>intln()</selection>
println()
}
println(array(1, 2, 3))
println()
}
@@ -0,0 +1,24 @@
fun main(args : Array<String>) {
for (i in 1..100) {
when {
i%3 == 0 -> {print("Fizz"); continue;}
i%5 == 0 -> {print("Buzz"); continue;}
(i%3 != 0 && i%5 != 0) -> {print(i); continue;}
else -> println()
}
}
}
fun foo() : Unit {
println() {
println()
<selection> pr<caret>intln()
</selection> println()
}
println(array(1, 2, 3))
println()
}
@@ -0,0 +1,24 @@
fun main(args : Array<String>) {
for (i in 1..100) {
when {
i%3 == 0 -> {print("Fizz"); continue;}
i%5 == 0 -> {print("Buzz"); continue;}
(i%3 != 0 && i%5 != 0) -> {print(i); continue;}
else -> println()
}
}
}
fun foo() : Unit {
println() {
println()
<selection> pr<caret>intln()
println()
</selection> }
println(array(1, 2, 3))
println()
}
@@ -0,0 +1,24 @@
fun main(args : Array<String>) {
for (i in 1..100) {
when {
i%3 == 0 -> {print("Fizz"); continue;}
i%5 == 0 -> {print("Buzz"); continue;}
(i%3 != 0 && i%5 != 0) -> {print(i); continue;}
else -> println()
}
}
}
fun foo() : Unit {
println() {
<selection> println()
pr<caret>intln()
println()
</selection> }
println(array(1, 2, 3))
println()
}
@@ -0,0 +1,24 @@
fun main(args : Array<String>) {
for (i in 1..100) {
when {
i%3 == 0 -> {print("Fizz"); continue;}
i%5 == 0 -> {print("Buzz"); continue;}
(i%3 != 0 && i%5 != 0) -> {print(i); continue;}
else -> println()
}
}
}
fun foo() : Unit {
println() <selection>{
println()
pr<caret>intln()
println()
}
</selection>
println(array(1, 2, 3))
println()
}
@@ -0,0 +1,24 @@
fun main(args : Array<String>) {
for (i in 1..100) {
when {
i%3 == 0 -> {print("Fizz"); continue;}
i%5 == 0 -> {print("Buzz"); continue;}
(i%3 != 0 && i%5 != 0) -> {print(i); continue;}
else -> println()
}
}
}
fun foo() : Unit {
<selection> println() {
println()
pr<caret>intln()
println()
}
</selection>
println(array(1, 2, 3))
println()
}
@@ -0,0 +1,24 @@
fun main(args : Array<String>) {
for (i in 1..100) {
when {
i%3 == 0 -> {print("Fizz"); continue;}
i%5 == 0 -> {print("Buzz"); continue;}
(i%3 != 0 && i%5 != 0) -> {print(i); continue;}
else -> println()
}
}
}
fun foo() : Unit {
<selection> println() {
println()
pr<caret>intln()
println()
}
println(array(1, 2, 3))
println()
</selection>}
@@ -0,0 +1,24 @@
fun main(args : Array<String>) {
for (i in 1..100) {
when {
i%3 == 0 -> {print("Fizz"); continue;}
i%5 == 0 -> {print("Buzz"); continue;}
(i%3 != 0 && i%5 != 0) -> {print(i); continue;}
else -> println()
}
}
}
fun foo() : Unit <selection>{
println() {
println()
pr<caret>intln()
println()
}
println(array(1, 2, 3))
println()
}</selection>
+24
View File
@@ -0,0 +1,24 @@
fun main(args : Array<String>) {
for (i in 1..100) {
when {
i%3 == 0 -> {print("Fizz"); continue;}
i%5 == 0 -> {print("Buzz"); continue;}
(i%3 != 0 && i%5 != 0) -> {print(i); continue;}
else -> println()
}
}
}
fun foo() : Unit {
println() {
println()
pr<caret>intln()
println()
}
println(array(1, 2, 3))
println()
}
@@ -0,0 +1,24 @@
fun main(args : Array<String>) {
for (i in 1..100) {
when {
i%3 == 0 -> {print("Fizz"); continue;}
i%5 == 0 -> {print("Buzz"); continue;}
(i%3 != 0 && i%5 != 0) -> <selection>{print(i); continue;}<caret></selection>
else -> println()
}
}
}
fun foo() : Unit {
println() {
println()
println()
println()
}
println(array(1, 2, 3))
println()
}
@@ -0,0 +1,24 @@
fun main(args : Array<String>) {
for (i in 1..100) {
when {
i%3 == 0 -> {print("Fizz"); continue;}
i%5 == 0 -> {print("Buzz"); continue;}
<selection>(i%3 != 0 && i%5 != 0) -> {print(i); continue;}<caret></selection>
else -> println()
}
}
}
fun foo() : Unit {
println() {
println()
println()
println()
}
println(array(1, 2, 3))
println()
}
@@ -0,0 +1,24 @@
fun main(args : Array<String>) {
for (i in 1..100) {
when {
i%3 == 0 -> {print("Fizz"); continue;}
i%5 == 0 -> {print("Buzz"); continue;}
<selection> (i%3 != 0 && i%5 != 0) -> {print(i); continue;}<caret>
</selection> else -> println()
}
}
}
fun foo() : Unit {
println() {
println()
println()
println()
}
println(array(1, 2, 3))
println()
}
@@ -0,0 +1,24 @@
fun main(args : Array<String>) {
for (i in 1..100) {
when {
i%3 == 0 -> {print("Fizz"); continue;}
i%5 == 0 -> {print("Buzz"); continue;}
<selection> (i%3 != 0 && i%5 != 0) -> {print(i); continue;}<caret>
else -> println()
</selection> }
}
}
fun foo() : Unit {
println() {
println()
println()
println()
}
println(array(1, 2, 3))
println()
}
@@ -0,0 +1,24 @@
fun main(args : Array<String>) {
for (i in 1..100) {
when {
<selection> i%3 == 0 -> {print("Fizz"); continue;}
i%5 == 0 -> {print("Buzz"); continue;}
(i%3 != 0 && i%5 != 0) -> {print(i); continue;}<caret>
else -> println()
</selection> }
}
}
fun foo() : Unit {
println() {
println()
println()
println()
}
println(array(1, 2, 3))
println()
}
@@ -0,0 +1,24 @@
fun main(args : Array<String>) {
for (i in 1..100) {
<selection>when {
i%3 == 0 -> {print("Fizz"); continue;}
i%5 == 0 -> {print("Buzz"); continue;}
(i%3 != 0 && i%5 != 0) -> {print(i); continue;}<caret>
else -> println()
}</selection>
}
}
fun foo() : Unit {
println() {
println()
println()
println()
}
println(array(1, 2, 3))
println()
}
@@ -0,0 +1,24 @@
fun main(args : Array<String>) {
for (i in 1..100) {
when {
i%3 == 0 -> {print("Fizz"); continue;}
i%5 == 0 -> {print("Buzz"); continue;}
(i%3 != 0 && i%5 != 0) -> {print(i); <selection>continue;}<caret></selection>
else -> println()
}
}
}
fun foo() : Unit {
println() {
println()
println()
println()
}
println(array(1, 2, 3))
println()
}
@@ -0,0 +1,56 @@
/*
* Copyright 2000-2012 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;
import com.intellij.testFramework.fixtures.CodeInsightTestUtil;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import org.jetbrains.jet.plugin.PluginTestCaseBase;
import java.io.File;
/**
* @author Evgeny Gerashchenko
* @since 2/24/12
*/
public class WordSelectionTest extends LightCodeInsightFixtureTestCase {
public void testStatements() {
doTest(11);
}
public void testWhenEntries() {
doTest(6);
}
private void doTest(int howMany) {
String testName = getTestName(false);
String[] afterFiles = new String[howMany];
for (int i = 1; i <= howMany; i++) {
afterFiles[i - 1] = String.format("%s.%d.kt", testName, i);
}
CodeInsightTestUtil.doWordSelectionTest(myFixture, testName + ".kt", afterFiles);
}
@Override
public void setUp() throws Exception {
super.setUp();
final String testRelativeDir = "wordSelection";
myFixture.setTestDataPath(new File(PluginTestCaseBase.getTestDataPathBase(), testRelativeDir).getPath() +
File.separator);
}
}
@@ -21,6 +21,8 @@ import com.intellij.openapi.application.ApplicationManager;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.plugin.PluginTestCaseBase;
import java.io.IOException;
/**
* @author Nikolay Krasko
*/
@@ -48,6 +50,30 @@ public class ImportClassHelperTest extends LightDaemonAnalyzerTestCase {
checkResultByFile(getTestName(false) + ".kt.after");
}
public void testInsertInEmptyFile() throws IOException {
configureFromFileText("testInsertInEmptyFile.kt", "");
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
ImportClassHelper.addImportDirective("java.util.ArrayList", (JetFile) getFile());
}
});
checkResultByText("import java.util.ArrayList");
}
public void testInsertInPackageOnlyFile() throws IOException {
configureFromFileText("testInsertInPackageOnlyFile.kt", "package some");
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
ImportClassHelper.addImportDirective("java.util.ArrayList", (JetFile) getFile());
}
});
checkResultByText("package some\n\nimport java.util.ArrayList");
}
@Override
protected String getTestDataPath() {
return PluginTestCaseBase.getTestDataPathBase() + "/quickfix/importHelper/";