Auto-import before object declaration corrupts code

This commit is contained in:
Nikolay Krasko
2012-02-29 19:36:46 +04:00
parent 042dc82bd5
commit a9bab96e33
4 changed files with 25 additions and 14 deletions
@@ -50,6 +50,7 @@ public class JetFormattingModelBuilder implements FormattingModelBuilder {
.between(IMPORT_DIRECTIVE, CLASS).blankLines(1)
.between(IMPORT_DIRECTIVE, FUN).blankLines(1)
.between(IMPORT_DIRECTIVE, PROPERTY).blankLines(1)
.between(IMPORT_DIRECTIVE, OBJECT_DECLARATION).blankLines(1)
.before(FUN).lineBreakInCode()
.before(PROPERTY).lineBreakInCode()
@@ -0,0 +1,2 @@
object some {
}
@@ -0,0 +1,4 @@
import java.util.HashSet
object some {
}
@@ -28,26 +28,19 @@ import java.io.IOException;
*/
public class ImportClassHelperTest extends LightDaemonAnalyzerTestCase {
public void testDoNotImportIfGeneralExist() {
configureByFile(getTestName(false) + ".kt");
ImportClassHelper.addImportDirective("jettesting.data.testFunction", (JetFile) getFile());
checkResultByFile(getTestName(false) + ".kt.after");
testImportInFile("jettesting.data.testFunction");
}
public void testDoNotImportIfGeneralSpaceExist() {
configureByFile(getTestName(false) + ".kt");
ImportClassHelper.addImportDirective("jettesting.data.testFunction", (JetFile) getFile());
checkResultByFile(getTestName(false) + ".kt.after");
testImportInFile("jettesting.data.testFunction");
}
public void testNoDefaultImport() {
configureByFile(getTestName(false) + ".kt");
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
ImportClassHelper.addImportDirective("std.io.println", (JetFile) getFile());
}
});
checkResultByFile(getTestName(false) + ".kt.after");
testImportInFile("std.io.println");
}
public void testImportBeforeObject() {
testImportInFile("java.util.HashSet");
}
public void testInsertInEmptyFile() throws IOException {
@@ -74,6 +67,17 @@ public class ImportClassHelperTest extends LightDaemonAnalyzerTestCase {
checkResultByText("package some\n\nimport java.util.ArrayList");
}
public void testImportInFile(final String importString) {
configureByFile(getTestName(false) + ".kt");
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
ImportClassHelper.addImportDirective(importString, (JetFile) getFile());
}
});
checkResultByFile(getTestName(false) + ".kt.after");
}
@Override
protected String getTestDataPath() {
return PluginTestCaseBase.getTestDataPathBase() + "/quickfix/importHelper/";