Fixes couple exceptions
This commit is contained in:
@@ -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/";
|
||||
|
||||
Reference in New Issue
Block a user