[java] non-mandatory import list

This commit is contained in:
Roman Shevchenko
2016-06-29 21:02:18 +03:00
parent f22dd502a3
commit ebb84bbd3d
5 changed files with 32 additions and 25 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -167,8 +167,7 @@ public class JavaElementSignatureProvider extends AbstractElementSignatureProvid
@Nullable StringBuilder processingInfoStorage)
{
if (type.equals("imports")) {
if (!(file instanceof PsiJavaFile)) return null;
return ((PsiJavaFile)file).getImportList();
return file instanceof PsiJavaFile ? ((PsiJavaFile)file).getImportList() : null;
}
else if (type.equals("method")) {
String name = tokenizer.nextToken();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -66,6 +66,9 @@ public class ImportHelper{
}
public PsiImportList prepareOptimizeImportsResult(@NotNull final PsiJavaFile file) {
PsiImportList oldList = file.getImportList();
if (oldList == null) return null;
// Java parser works in a way that comments may be included to the import list, e.g.:
// import a;
// /* comment */
@@ -98,8 +101,8 @@ public class ImportHelper{
codeStyleManager.reformat(dummyFile);
PsiImportList newImportList = dummyFile.getImportList();
assert newImportList != null : dummyFile.getText();
PsiImportList result = (PsiImportList)newImportList.copy();
PsiImportList oldList = file.getImportList();
if (oldList.isReplaceEquivalent(result)) return null;
if (!nonImports.isEmpty()) {
PsiElement firstPrevious = newImportList.getPrevSibling();
@@ -431,6 +434,7 @@ public class ImportHelper{
try {
PsiImportList importList = file.getImportList();
assert importList != null : file;
PsiImportStatement statement = useOnDemand ? factory.createImportStatementOnDemand(packageName) : factory.createImportStatement(refClass);
importList.add(statement);
if (useOnDemand) {