提交 010090cd 编写于 作者: N Nikolay Krasko

Fixes couple exceptions

上级 782ea7b1
......@@ -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());
}
}
}
......
......@@ -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/";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册