mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Don't optimize imports if formatting is disabled
This commit is contained in:
+1
-1
@@ -103,7 +103,7 @@ public class JavaCodeStyleManagerImpl extends JavaCodeStyleManager {
|
||||
@Override
|
||||
public void optimizeImports(@NotNull PsiFile file) throws IncorrectOperationException {
|
||||
CheckUtil.checkWritable(file);
|
||||
if (file instanceof PsiJavaFile) {
|
||||
if (file instanceof PsiJavaFile && CodeStyle.isFormattingEnabled(file)) {
|
||||
PsiImportList newList = prepareOptimizeImportsResult((PsiJavaFile)file);
|
||||
if (newList != null) {
|
||||
final PsiImportList importList = ((PsiJavaFile)file).getImportList();
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import java.util.Date;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public List<String> foo(){
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import java.util.Date;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public List<String> foo(){
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,10 @@
|
||||
*/
|
||||
package com.intellij.java.psi;
|
||||
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
import com.intellij.formatting.fileSet.NamedScopeDescriptor;
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
|
||||
public class OptimizeImportsTest extends OptimizeImportsTestCase {
|
||||
private static final String BASE_PATH = PathManagerEx.getTestDataPath() + "/psi/optimizeImports";
|
||||
@@ -61,6 +64,14 @@ public class OptimizeImportsTest extends OptimizeImportsTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDisabledFormatting() {
|
||||
CodeStyleSettings temp = new CodeStyleSettings();
|
||||
NamedScopeDescriptor descriptor = new NamedScopeDescriptor("Test");
|
||||
descriptor.setPattern("file:*.java");
|
||||
temp.getExcludedFiles().addDescriptor(descriptor);
|
||||
CodeStyle.doWithTemporarySettings(getProject(), temp, () -> doTest());
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(".java");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user