mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup
This commit is contained in:
+2
-1
@@ -38,6 +38,7 @@ import static com.intellij.codeInspection.bytecodeAnalysis.ProjectBytecodeAnalys
|
||||
public class BytecodeAnalysisConverter {
|
||||
|
||||
private static final ThreadLocalCachedValue<MessageDigest> HASHER_CACHE = new ThreadLocalCachedValue<MessageDigest>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public MessageDigest create() {
|
||||
try {
|
||||
@@ -48,7 +49,7 @@ public class BytecodeAnalysisConverter {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(MessageDigest value) {
|
||||
protected void init(@NotNull MessageDigest value) {
|
||||
value.reset();
|
||||
}
|
||||
};
|
||||
|
||||
+51
-63
@@ -12,7 +12,6 @@ import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Splitter;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packageDependencies.DependenciesToolWindow;
|
||||
import com.intellij.packageDependencies.DependencyUISettings;
|
||||
import com.intellij.packageDependencies.ui.*;
|
||||
@@ -31,8 +30,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreeNode;
|
||||
import javax.swing.tree.TreePath;
|
||||
@@ -72,20 +69,12 @@ public class CyclicDependenciesPanel extends JPanel implements Disposable, DataP
|
||||
mySettings.UI_SHOW_MODULES = false; //exist without modules - and doesn't with
|
||||
|
||||
final Splitter treeSplitter = new Splitter();
|
||||
Disposer.register(this, new Disposable(){
|
||||
public void dispose() {
|
||||
treeSplitter.dispose();
|
||||
}
|
||||
});
|
||||
Disposer.register(this, () -> treeSplitter.dispose());
|
||||
treeSplitter.setFirstComponent(ScrollPaneFactory.createScrollPane(myLeftTree));
|
||||
treeSplitter.setSecondComponent(ScrollPaneFactory.createScrollPane(myRightTree));
|
||||
|
||||
final Splitter splitter = new Splitter(true);
|
||||
Disposer.register(this, new Disposable() {
|
||||
public void dispose() {
|
||||
splitter.dispose();
|
||||
}
|
||||
});
|
||||
Disposer.register(this, () -> splitter.dispose());
|
||||
splitter.setFirstComponent(treeSplitter);
|
||||
splitter.setSecondComponent(myUsagesPanel);
|
||||
add(splitter, BorderLayout.CENTER);
|
||||
@@ -97,39 +86,36 @@ public class CyclicDependenciesPanel extends JPanel implements Disposable, DataP
|
||||
updateLeftTreeModel();
|
||||
updateRightTreeModel();
|
||||
|
||||
myLeftTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
|
||||
public void valueChanged(TreeSelectionEvent e) {
|
||||
updateRightTreeModel();
|
||||
myUsagesPanel.setToInitialPosition();
|
||||
}
|
||||
myLeftTree.getSelectionModel().addTreeSelectionListener(__ -> {
|
||||
updateRightTreeModel();
|
||||
myUsagesPanel.setToInitialPosition();
|
||||
});
|
||||
|
||||
myRightTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
|
||||
public void valueChanged(TreeSelectionEvent e) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
Set<PsiFile> searchIn = getSelectedScope(myRightTree);
|
||||
final PackageNode selectedPackageNode = getSelectedPackage(myRightTree);
|
||||
if (selectedPackageNode == null) {
|
||||
return;
|
||||
}
|
||||
final PackageDependenciesNode nextPackageNode = getNextPackageNode(selectedPackageNode);
|
||||
Set<PsiFile> searchFor = new HashSet<>();
|
||||
Set<PackageNode> packNodes = new HashSet<>();
|
||||
getPackageNodesHierarchy(selectedPackageNode, packNodes);
|
||||
for (PackageNode packageNode : packNodes) {
|
||||
searchFor.addAll(myBuilder.getDependentFilesInPackage((PsiPackage)packageNode.getPsiElement(),
|
||||
((PsiPackage)nextPackageNode.getPsiElement())));
|
||||
}
|
||||
if (searchIn.isEmpty() || searchFor.isEmpty()) {
|
||||
myUsagesPanel.setToInitialPosition();
|
||||
}
|
||||
else {
|
||||
myBuilder.setRootNodeNameInUsageView(AnalysisScopeBundle.message("cyclic.dependencies.usage.view.root.node.text", ((PsiPackage)nextPackageNode.getPsiElement()).getQualifiedName(), ((PsiPackage)selectedPackageNode.getPsiElement()).getQualifiedName()));
|
||||
myUsagesPanel.findUsages(searchIn, searchFor);
|
||||
}
|
||||
});
|
||||
myRightTree.getSelectionModel().addTreeSelectionListener(__ -> SwingUtilities.invokeLater(() -> {
|
||||
Set<PsiFile> searchIn = getSelectedScope(myRightTree);
|
||||
final PackageNode selectedPackageNode = getSelectedPackage(myRightTree);
|
||||
if (selectedPackageNode == null) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
final PackageDependenciesNode nextPackageNode = getNextPackageNode(selectedPackageNode);
|
||||
Set<PackageNode> packNodes = new HashSet<>();
|
||||
getPackageNodesHierarchy(selectedPackageNode, packNodes);
|
||||
Set<PsiFile> searchFor = new HashSet<>();
|
||||
for (PackageNode packageNode : packNodes) {
|
||||
searchFor.addAll(myBuilder.getDependentFilesInPackage((PsiPackage)packageNode.getPsiElement(),
|
||||
(PsiPackage)nextPackageNode.getPsiElement()));
|
||||
}
|
||||
if (searchIn.isEmpty() || searchFor.isEmpty()) {
|
||||
myUsagesPanel.setToInitialPosition();
|
||||
}
|
||||
else {
|
||||
String pack1Name = ((PsiPackage)nextPackageNode.getPsiElement()).getQualifiedName();
|
||||
String pack2Name = ((PsiPackage)selectedPackageNode.getPsiElement()).getQualifiedName();
|
||||
myBuilder.setRootNodeNameInUsageView(AnalysisScopeBundle.message("cyclic.dependencies.usage.view.root.node.text",
|
||||
pack1Name, pack2Name));
|
||||
myUsagesPanel.findUsages(searchIn, searchFor);
|
||||
}
|
||||
}));
|
||||
|
||||
initTree(myLeftTree);
|
||||
initTree(myRightTree);
|
||||
@@ -175,7 +161,7 @@ public class CyclicDependenciesPanel extends JPanel implements Disposable, DataP
|
||||
}
|
||||
|
||||
private static PackageDependenciesNode hideEmptyMiddlePackages(PackageDependenciesNode node, StringBuffer result){
|
||||
if (node.getChildCount() == 0 || node.getChildCount() > 1 || (node.getChildCount() == 1 && node.getChildAt(0) instanceof FileNode)){
|
||||
if (node.getChildCount() == 0 || node.getChildCount() > 1 || node.getChildCount() == 1 && node.getChildAt(0) instanceof FileNode){
|
||||
result.append(result.length() != 0 ? "." : "").append(node.toString().equals(DEFAULT_PACKAGE_ABBREVIATION) ? "" : node.toString());//toString()
|
||||
} else {
|
||||
if (node.getChildCount() == 1){
|
||||
@@ -245,11 +231,7 @@ public class CyclicDependenciesPanel extends JPanel implements Disposable, DataP
|
||||
mySettings.UI_FLATTEN_PACKAGES = true;
|
||||
mySettings.UI_SHOW_FILES = false;
|
||||
myLeftTreeExpansionMonitor.freeze();
|
||||
myLeftTree.setModel(TreeModelBuilder.createTreeModel(myProject, false, psiFiles, new Marker() {
|
||||
public boolean isMarked(@NotNull VirtualFile file) {
|
||||
return false;
|
||||
}
|
||||
}, mySettings));
|
||||
myLeftTree.setModel(TreeModelBuilder.createTreeModel(myProject, false, psiFiles, __ -> false, mySettings));
|
||||
myLeftTreeExpansionMonitor.restore();
|
||||
expandFirstLevel(myLeftTree);
|
||||
mySettings.UI_SHOW_FILES = showFiles;
|
||||
@@ -280,11 +262,7 @@ public class CyclicDependenciesPanel extends JPanel implements Disposable, DataP
|
||||
final Set<PsiFile> dependentFilesInPackage = myBuilder.getDependentFilesInPackage(prevPackage, psiPackage, nextPackage);
|
||||
|
||||
final PackageDependenciesNode pack = (PackageDependenciesNode)TreeModelBuilder
|
||||
.createTreeModel(myProject, false, dependentFilesInPackage, new Marker() {
|
||||
public boolean isMarked(@NotNull VirtualFile file) {
|
||||
return false;
|
||||
}
|
||||
}, mySettings).getRoot();
|
||||
.createTreeModel(myProject, false, dependentFilesInPackage, __ -> false, mySettings).getRoot();
|
||||
nodes[i] = hideEmptyMiddlePackages((PackageDependenciesNode)pack.getChildAt(0), new StringBuffer());
|
||||
}
|
||||
|
||||
@@ -364,10 +342,12 @@ public class CyclicDependenciesPanel extends JPanel implements Disposable, DataP
|
||||
myContent = content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
TreeModelBuilder.clearCaches(myProject);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
@NonNls
|
||||
public Object getData(@NonNls String dataId) {
|
||||
@@ -380,11 +360,12 @@ public class CyclicDependenciesPanel extends JPanel implements Disposable, DataP
|
||||
private class MyTreeCellRenderer extends ColoredTreeCellRenderer {
|
||||
private final boolean myLeftTree;
|
||||
|
||||
public MyTreeCellRenderer(boolean isLeftTree) {
|
||||
MyTreeCellRenderer(boolean isLeftTree) {
|
||||
myLeftTree = isLeftTree;
|
||||
}
|
||||
|
||||
public void customizeCellRenderer(JTree tree,
|
||||
@Override
|
||||
public void customizeCellRenderer(@NotNull JTree tree,
|
||||
Object value,
|
||||
boolean selected,
|
||||
boolean expanded,
|
||||
@@ -420,7 +401,8 @@ public class CyclicDependenciesPanel extends JPanel implements Disposable, DataP
|
||||
AllIcons.Actions.Cancel);
|
||||
}
|
||||
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
Disposer.dispose(myUsagesPanel);
|
||||
DependenciesToolWindow.getInstance(myProject).closeContent(myContent);
|
||||
mySettings.copyToApplicationDependencySettings();
|
||||
@@ -433,10 +415,12 @@ public class CyclicDependenciesPanel extends JPanel implements Disposable, DataP
|
||||
AllIcons.FileTypes.Java);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected(AnActionEvent event) {
|
||||
return mySettings.UI_SHOW_FILES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(AnActionEvent event, boolean flag) {
|
||||
DependencyUISettings.getInstance().UI_SHOW_FILES = flag;
|
||||
mySettings.UI_SHOW_FILES = flag;
|
||||
@@ -445,7 +429,7 @@ public class CyclicDependenciesPanel extends JPanel implements Disposable, DataP
|
||||
}
|
||||
|
||||
private final class HideOutOfCyclePackagesAction extends ToggleAction {
|
||||
@NonNls public static final String SHOW_PACKAGES_FROM_CYCLES_ONLY = "Hide packages without cyclic dependencies";
|
||||
@NonNls static final String SHOW_PACKAGES_FROM_CYCLES_ONLY = "Hide packages without cyclic dependencies";
|
||||
|
||||
HideOutOfCyclePackagesAction() {
|
||||
super(SHOW_PACKAGES_FROM_CYCLES_ONLY, SHOW_PACKAGES_FROM_CYCLES_ONLY, AllIcons.General.Filter);
|
||||
@@ -470,10 +454,12 @@ public class CyclicDependenciesPanel extends JPanel implements Disposable, DataP
|
||||
AllIcons.Actions.GroupByTestProduction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected(AnActionEvent event) {
|
||||
return mySettings.UI_GROUP_BY_SCOPE_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(AnActionEvent event, boolean flag) {
|
||||
DependencyUISettings.getInstance().UI_GROUP_BY_SCOPE_TYPE = flag;
|
||||
mySettings.UI_GROUP_BY_SCOPE_TYPE = flag;
|
||||
@@ -482,16 +468,18 @@ public class CyclicDependenciesPanel extends JPanel implements Disposable, DataP
|
||||
}
|
||||
|
||||
private class RerunAction extends AnAction {
|
||||
public RerunAction(JComponent comp) {
|
||||
RerunAction(JComponent comp) {
|
||||
super(CommonBundle.message("action.rerun"), AnalysisScopeBundle.message("action.rerun.dependency"), AllIcons.Actions.Rerun);
|
||||
registerCustomShortcutSet(CommonShortcuts.getRerun(), comp);
|
||||
}
|
||||
|
||||
public void update(AnActionEvent e) {
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
e.getPresentation().setEnabled(myBuilder.getScope().isValid());
|
||||
}
|
||||
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
DependenciesToolWindow.getInstance(myProject).closeContent(myContent);
|
||||
mySettings.copyToApplicationDependencySettings();
|
||||
SwingUtilities.invokeLater(() -> new CyclicDependenciesHandler(myProject, myBuilder.getScope()).analyze());
|
||||
@@ -499,6 +487,7 @@ public class CyclicDependenciesPanel extends JPanel implements Disposable, DataP
|
||||
}
|
||||
|
||||
private static class MyTree extends Tree implements DataProvider {
|
||||
@Override
|
||||
public Object getData(String dataId) {
|
||||
PackageDependenciesNode node = getSelectedNode();
|
||||
if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
|
||||
@@ -514,9 +503,8 @@ public class CyclicDependenciesPanel extends JPanel implements Disposable, DataP
|
||||
final Object lastPathComponent = paths[0].getLastPathComponent();
|
||||
if (lastPathComponent instanceof PackageDependenciesNode) {
|
||||
return (PackageDependenciesNode)lastPathComponent;
|
||||
} else {
|
||||
return (PackageDependenciesNode)((DefaultMutableTreeNode)lastPathComponent).getUserObject();
|
||||
}
|
||||
return (PackageDependenciesNode)((DefaultMutableTreeNode)lastPathComponent).getUserObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+95
-82
@@ -7,6 +7,7 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.PackageEntry;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import org.intellij.lang.annotations.Language;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
public class LightOptimizeImportsTest extends LightCodeInsightFixtureTestCase {
|
||||
@@ -17,40 +18,44 @@ public class LightOptimizeImportsTest extends LightCodeInsightFixtureTestCase {
|
||||
myFixture.addClass("package p; public class A2 {}");
|
||||
myFixture.addClass("package p; public class ArrayList {}");
|
||||
myFixture.addClass("package p1; public class ArrayList {}");
|
||||
|
||||
myFixture.configureByText(StdFileTypes.JAVA, "\n" +
|
||||
"import java.util.*;\n" +
|
||||
"import p.*;\n" +
|
||||
"import p1.ArrayList;\n" +
|
||||
"import p1.ArrayList;\n" +
|
||||
"public class Optimize {\n" +
|
||||
" Class[] c = {\n" +
|
||||
" Collection.class,\n" +
|
||||
" List.class,\n" +
|
||||
" ArrayList.class,\n" +
|
||||
" A1.class,\n" +
|
||||
" A2.class\n" +
|
||||
" };\n" +
|
||||
"}\n");
|
||||
|
||||
@Language("JAVA")
|
||||
String text = "\n" +
|
||||
"import java.util.*;\n" +
|
||||
"import p.*;\n" +
|
||||
"import p1.ArrayList;\n" +
|
||||
"import p1.ArrayList;\n" +
|
||||
"public class Optimize {\n" +
|
||||
" Class[] c = {\n" +
|
||||
" Collection.class,\n" +
|
||||
" List.class,\n" +
|
||||
" ArrayList.class,\n" +
|
||||
" A1.class,\n" +
|
||||
" A2.class\n" +
|
||||
" };\n" +
|
||||
"}\n";
|
||||
myFixture.configureByText(StdFileTypes.JAVA, text);
|
||||
|
||||
JavaCodeStyleSettings javaSettings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
javaSettings.CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 2;
|
||||
|
||||
WriteCommandAction.runWriteCommandAction(getProject(), () -> JavaCodeStyleManager.getInstance(getProject()).optimizeImports(getFile()));
|
||||
|
||||
myFixture.checkResult("import p.*;\n" +
|
||||
"import p1.ArrayList;\n" +
|
||||
"\n" +
|
||||
"import java.util.*;\n" +
|
||||
"public class Optimize {\n" +
|
||||
" Class[] c = {\n" +
|
||||
" Collection.class,\n" +
|
||||
" List.class,\n" +
|
||||
" ArrayList.class,\n" +
|
||||
" A1.class,\n" +
|
||||
" A2.class\n" +
|
||||
" };\n" +
|
||||
"}\n");
|
||||
@Language("JAVA")
|
||||
String result = "import p.*;\n" +
|
||||
"import p1.ArrayList;\n" +
|
||||
"\n" +
|
||||
"import java.util.*;\n" +
|
||||
"public class Optimize {\n" +
|
||||
" Class[] c = {\n" +
|
||||
" Collection.class,\n" +
|
||||
" List.class,\n" +
|
||||
" ArrayList.class,\n" +
|
||||
" A1.class,\n" +
|
||||
" A2.class\n" +
|
||||
" };\n" +
|
||||
"}\n";
|
||||
myFixture.checkResult(result);
|
||||
}
|
||||
|
||||
public void testStaticImportsOrder() throws Exception {
|
||||
@@ -63,40 +68,44 @@ public class LightOptimizeImportsTest extends LightCodeInsightFixtureTestCase {
|
||||
" public static String Long;\n" +
|
||||
" public static String Field4;" +
|
||||
"}");
|
||||
|
||||
myFixture.configureByText(StdFileTypes.JAVA, "\n" +
|
||||
"import static p.C1.*;\n" +
|
||||
"import static p.C1.Byte;\n" +
|
||||
"import static p.C2.Long;\n" +
|
||||
"import static p.C2.*;\n" +
|
||||
"\n" +
|
||||
"public class Main {\n" +
|
||||
" public static void main(String[] args) {\n" +
|
||||
" System.out.println(Byte);\n" +
|
||||
" System.out.println(Field2);\n" +
|
||||
" System.out.println(Long);\n" +
|
||||
" System.out.println(Field4);\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
|
||||
@Language("JAVA")
|
||||
String text = "\n" +
|
||||
"import static p.C1.*;\n" +
|
||||
"import static p.C1.Byte;\n" +
|
||||
"import static p.C2.Long;\n" +
|
||||
"import static p.C2.*;\n" +
|
||||
"\n" +
|
||||
"public class Main {\n" +
|
||||
" public static void main(String[] args) {\n" +
|
||||
" System.out.println(Byte);\n" +
|
||||
" System.out.println(Field2);\n" +
|
||||
" System.out.println(Long);\n" +
|
||||
" System.out.println(Field4);\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
myFixture.configureByText(StdFileTypes.JAVA, text);
|
||||
|
||||
JavaCodeStyleSettings javaSettings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
javaSettings.NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND = 1;
|
||||
|
||||
WriteCommandAction.runWriteCommandAction(getProject(), () -> JavaCodeStyleManager.getInstance(getProject()).optimizeImports(getFile()));
|
||||
|
||||
myFixture.checkResult("import static p.C1.Byte;\n" +
|
||||
"import static p.C1.*;\n" +
|
||||
"import static p.C2.Long;\n" +
|
||||
"import static p.C2.*;\n" +
|
||||
"\n" +
|
||||
"public class Main {\n" +
|
||||
" public static void main(String[] args) {\n" +
|
||||
" System.out.println(Byte);\n" +
|
||||
" System.out.println(Field2);\n" +
|
||||
" System.out.println(Long);\n" +
|
||||
" System.out.println(Field4);\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
@Language("JAVA")
|
||||
String result = "import static p.C1.Byte;\n" +
|
||||
"import static p.C1.*;\n" +
|
||||
"import static p.C2.Long;\n" +
|
||||
"import static p.C2.*;\n" +
|
||||
"\n" +
|
||||
"public class Main {\n" +
|
||||
" public static void main(String[] args) {\n" +
|
||||
" System.out.println(Byte);\n" +
|
||||
" System.out.println(Field2);\n" +
|
||||
" System.out.println(Long);\n" +
|
||||
" System.out.println(Field4);\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
myFixture.checkResult(result);
|
||||
}
|
||||
|
||||
public void testStaticImportOnMethodFromSuperClass() {
|
||||
@@ -109,38 +118,42 @@ public class LightOptimizeImportsTest extends LightCodeInsightFixtureTestCase {
|
||||
" public static void m3() {}\n" +
|
||||
" public static void m4() {}\n" +
|
||||
"}");
|
||||
|
||||
myFixture.configureByText(StdFileTypes.JAVA, "\n" +
|
||||
"import static p.A.m1;\n" +
|
||||
"import static p.A.m2;\n" +
|
||||
"import static p.B.m3;\n" +
|
||||
"import static p.B.m4;\n" +
|
||||
"\n" +
|
||||
"public class Main {\n" +
|
||||
" public static void main(String[] args) {\n" +
|
||||
" m1();\n" +
|
||||
" m2();\n" +
|
||||
" m3();\n" +
|
||||
" m4();\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
|
||||
@Language("JAVA")
|
||||
String text = "\n" +
|
||||
"import static p.A.m1;\n" +
|
||||
"import static p.A.m2;\n" +
|
||||
"import static p.B.m3;\n" +
|
||||
"import static p.B.m4;\n" +
|
||||
"\n" +
|
||||
"public class Main {\n" +
|
||||
" public static void main(String[] args) {\n" +
|
||||
" m1();\n" +
|
||||
" m2();\n" +
|
||||
" m3();\n" +
|
||||
" m4();\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
myFixture.configureByText(StdFileTypes.JAVA, text);
|
||||
|
||||
JavaCodeStyleSettings javaSettings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
javaSettings.NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND = 1;
|
||||
|
||||
WriteCommandAction.runWriteCommandAction(getProject(), () -> JavaCodeStyleManager.getInstance(getProject()).optimizeImports(getFile()));
|
||||
|
||||
myFixture.checkResult("import static p.A.*;\n" +
|
||||
"import static p.B.*;\n" +
|
||||
"\n" +
|
||||
"public class Main {\n" +
|
||||
" public static void main(String[] args) {\n" +
|
||||
" m1();\n" +
|
||||
" m2();\n" +
|
||||
" m3();\n" +
|
||||
" m4();\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
@Language("JAVA")
|
||||
String result = "import static p.A.*;\n" +
|
||||
"import static p.B.*;\n" +
|
||||
"\n" +
|
||||
"public class Main {\n" +
|
||||
" public static void main(String[] args) {\n" +
|
||||
" m1();\n" +
|
||||
" m2();\n" +
|
||||
" m3();\n" +
|
||||
" m4();\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
myFixture.checkResult(result);
|
||||
}
|
||||
|
||||
public void testConflictingSingleImportUsedInReferenceQualifier() {
|
||||
|
||||
@@ -427,6 +427,7 @@ public class SyntaxTraverser<T> extends FilteredTraverserBase<T, SyntaxTraverser
|
||||
private final UserDataHolder userDataHolder = new UserDataHolderBase();
|
||||
private final ThreadLocalCachedValue<FlyweightCapableTreeStructure<LighterASTNode>> structure =
|
||||
new ThreadLocalCachedValue<FlyweightCapableTreeStructure<LighterASTNode>>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected FlyweightCapableTreeStructure<LighterASTNode> create() {
|
||||
return builder.getLightTree();
|
||||
|
||||
+16
-20
@@ -36,15 +36,15 @@ public class CoreProgressManager extends ProgressManager implements Disposable {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.progress.impl.CoreProgressManager");
|
||||
|
||||
static final int CHECK_CANCELED_DELAY_MILLIS = 10;
|
||||
private final AtomicInteger myCurrentUnsafeProgressCount = new AtomicInteger(0);
|
||||
private final AtomicInteger myUnsafeProgressCount = new AtomicInteger(0);
|
||||
|
||||
public static final boolean ENABLED = !"disabled".equals(System.getProperty("idea.ProcessCanceledException"));
|
||||
private static CheckCanceledHook ourCheckCanceledHook;
|
||||
private ScheduledFuture<?> myCheckCancelledFuture; // guarded by threadsUnderIndicator
|
||||
|
||||
// indicator -> threads which are running under this indicator. guarded by threadsUnderIndicator.
|
||||
// indicator -> threads which are running under this indicator.
|
||||
// THashMap is avoided here because of tombstones overhead
|
||||
private static final Map<ProgressIndicator, Set<Thread>> threadsUnderIndicator = new HashMap<>();
|
||||
private static final Map<ProgressIndicator, Set<Thread>> threadsUnderIndicator = new HashMap<>(); // guarded by threadsUnderIndicator
|
||||
// the active indicator for the thread id
|
||||
private static final ConcurrentLongObjectMap<ProgressIndicator> currentIndicators = ContainerUtil.createConcurrentLongObjectMap();
|
||||
// top-level indicators for the thread id
|
||||
@@ -136,7 +136,7 @@ public class CoreProgressManager extends ProgressManager implements Disposable {
|
||||
|
||||
@Override
|
||||
public boolean hasUnsafeProgressIndicator() {
|
||||
return myCurrentUnsafeProgressCount.get() > 0;
|
||||
return myUnsafeProgressCount.get() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -513,19 +513,20 @@ public class CoreProgressManager extends ProgressManager implements Disposable {
|
||||
|
||||
@Override
|
||||
public void executeProcessUnderProgress(@NotNull Runnable process, ProgressIndicator progress) throws ProcessCanceledException {
|
||||
if (progress == null) myCurrentUnsafeProgressCount.incrementAndGet();
|
||||
if (progress == null) myUnsafeProgressCount.incrementAndGet();
|
||||
|
||||
try {
|
||||
ProgressIndicator oldIndicator = null;
|
||||
boolean set = progress != null && progress != (oldIndicator = getProgressIndicator());
|
||||
if (set) {
|
||||
Thread currentThread = Thread.currentThread();
|
||||
setCurrentIndicator(currentThread, progress);
|
||||
long threadId = currentThread.getId();
|
||||
setCurrentIndicator(threadId, progress);
|
||||
try {
|
||||
registerIndicatorAndRun(progress, currentThread, oldIndicator, process);
|
||||
}
|
||||
finally {
|
||||
setCurrentIndicator(currentThread, oldIndicator);
|
||||
setCurrentIndicator(threadId, oldIndicator);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -533,7 +534,7 @@ public class CoreProgressManager extends ProgressManager implements Disposable {
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (progress == null) myCurrentUnsafeProgressCount.decrementAndGet();
|
||||
if (progress == null) myUnsafeProgressCount.decrementAndGet();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -550,11 +551,7 @@ public class CoreProgressManager extends ProgressManager implements Disposable {
|
||||
List<Set<Thread>> threadsUnderThisIndicator = new ArrayList<>();
|
||||
synchronized (threadsUnderIndicator) {
|
||||
for (ProgressIndicator thisIndicator = indicator; thisIndicator != null; thisIndicator = thisIndicator instanceof WrappedProgressIndicator ? ((WrappedProgressIndicator)thisIndicator).getOriginalProgressIndicator() : null) {
|
||||
Set<Thread> underIndicator = threadsUnderIndicator.get(thisIndicator);
|
||||
if (underIndicator == null) {
|
||||
underIndicator = new SmartHashSet<>();
|
||||
threadsUnderIndicator.put(thisIndicator, underIndicator);
|
||||
}
|
||||
Set<Thread> underIndicator = threadsUnderIndicator.computeIfAbsent(thisIndicator, __ -> new SmartHashSet<>());
|
||||
boolean alreadyUnder = !underIndicator.add(currentThread);
|
||||
threadsUnderThisIndicator.add(alreadyUnder ? null : underIndicator);
|
||||
|
||||
@@ -674,16 +671,15 @@ public class CoreProgressManager extends ProgressManager implements Disposable {
|
||||
return modality != null ? modality : ModalityState.NON_MODAL;
|
||||
}
|
||||
|
||||
private static void setCurrentIndicator(@NotNull Thread currentThread, ProgressIndicator indicator) {
|
||||
long id = currentThread.getId();
|
||||
private static void setCurrentIndicator(long threadId, ProgressIndicator indicator) {
|
||||
if (indicator == null) {
|
||||
currentIndicators.remove(id);
|
||||
threadTopLevelIndicators.remove(id);
|
||||
currentIndicators.remove(threadId);
|
||||
threadTopLevelIndicators.remove(threadId);
|
||||
}
|
||||
else {
|
||||
currentIndicators.put(id, indicator);
|
||||
if (!threadTopLevelIndicators.containsKey(id)) {
|
||||
threadTopLevelIndicators.put(id, indicator);
|
||||
currentIndicators.put(threadId, indicator);
|
||||
if (!threadTopLevelIndicators.containsKey(threadId)) {
|
||||
threadTopLevelIndicators.put(threadId, indicator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ class LineMarkersUtil {
|
||||
highlighter.putUserData(LINE_MARKER_INFO, info);
|
||||
|
||||
LineMarkerInfo.LineMarkerGutterIconRenderer oldRenderer = highlighter.getGutterIconRenderer() instanceof LineMarkerInfo.LineMarkerGutterIconRenderer ? (LineMarkerInfo.LineMarkerGutterIconRenderer)highlighter.getGutterIconRenderer() : null;
|
||||
boolean rendererChanged = oldRenderer == null || newRenderer == null || !newRenderer.equals(oldRenderer);
|
||||
boolean rendererChanged = newRenderer == null || !newRenderer.equals(oldRenderer);
|
||||
boolean lineSeparatorColorChanged = !Comparing.equal(highlighter.getLineSeparatorColor(), info.separatorColor);
|
||||
boolean lineSeparatorPlacementChanged = !Comparing.equal(highlighter.getLineSeparatorPlacement(), info.separatorPlacement);
|
||||
|
||||
|
||||
+2
-1
@@ -32,13 +32,14 @@ import java.util.Arrays;
|
||||
|
||||
public class ContentHashesUtil {
|
||||
public static final ThreadLocalCachedValue<MessageDigest> HASHER_CACHE = new ThreadLocalCachedValue<MessageDigest>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public MessageDigest create() {
|
||||
return createHashDigest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(MessageDigest value) {
|
||||
protected void init(@NotNull MessageDigest value) {
|
||||
value.reset();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,10 +5,7 @@ import com.intellij.openapi.diagnostic.LoggerRt;
|
||||
import com.intellij.openapi.util.SystemInfoRt;
|
||||
import com.intellij.openapi.util.text.StringUtilRt;
|
||||
import com.intellij.util.ArrayUtilRt;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
@@ -188,6 +185,7 @@ public class FileUtilRt {
|
||||
return getExtension(fileName, "");
|
||||
}
|
||||
|
||||
@Contract("_,!null -> !null")
|
||||
public static CharSequence getExtension(@NotNull CharSequence fileName, @Nullable String defaultValue) {
|
||||
int index = StringUtilRt.lastIndexOf(fileName, '.', 0, fileName.length());
|
||||
if (index < 0) {
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.intellij.openapi.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.ref.SoftReference;
|
||||
|
||||
public abstract class ThreadLocalCachedValue<T> {
|
||||
@@ -25,14 +27,16 @@ public abstract class ThreadLocalCachedValue<T> {
|
||||
if (value == null) {
|
||||
value = create();
|
||||
myThreadLocal.set(new SoftReference<T>(value));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
init(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
protected void init(T value) {
|
||||
protected void init(@NotNull T value) {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract T create();
|
||||
}
|
||||
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
package com.intellij.util.io;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/* Unsync version of java.io.DataOutputStream */
|
||||
public class DataOutputStream extends java.io.DataOutputStream {
|
||||
@@ -39,7 +40,7 @@ public class DataOutputStream extends java.io.DataOutputStream {
|
||||
return written;
|
||||
}
|
||||
|
||||
public int resetWrittenBytesCount() {
|
||||
int resetWrittenBytesCount() {
|
||||
int result = written;
|
||||
written = 0;
|
||||
return result;
|
||||
|
||||
@@ -84,6 +84,7 @@ public class IOUtil {
|
||||
}
|
||||
|
||||
private static final ThreadLocalCachedValue<byte[]> ourReadWriteBuffersCache = new ThreadLocalCachedValue<byte[]>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected byte[] create() {
|
||||
return allocReadWriteUTFBuffer();
|
||||
@@ -134,6 +135,7 @@ public class IOUtil {
|
||||
|
||||
public static final Charset US_ASCII = Charset.forName("US-ASCII");
|
||||
private static final ThreadLocalCachedValue<char[]> spareBufferLocal = new ThreadLocalCachedValue<char[]>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected char[] create() {
|
||||
return new char[STRING_LENGTH_THRESHOLD];
|
||||
|
||||
@@ -481,6 +481,7 @@ public class PersistentHashMap<Key, Value> extends PersistentEnumeratorDelegate<
|
||||
}
|
||||
|
||||
private static final ThreadLocalCachedValue<AppendStream> ourFlyweightAppenderStream = new ThreadLocalCachedValue<AppendStream>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected AppendStream create() {
|
||||
return new AppendStream();
|
||||
|
||||
@@ -57,6 +57,7 @@ public class CharSequenceSubSequence implements CharSequence, CharArrayExternali
|
||||
return new CharSequenceSubSequence(myChars, myStart + start, myStart + end);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String toString() {
|
||||
if (myChars instanceof String) return ((String)myChars).substring(myStart, myEnd);
|
||||
|
||||
@@ -39,7 +39,7 @@ public class GroovyFileTypeLoader extends FileTypeFactory{
|
||||
return strings;
|
||||
}
|
||||
|
||||
public static List<String> getAllGroovyExtensions() {
|
||||
private static List<String> getAllGroovyExtensions() {
|
||||
final ArrayList<String> strings = new ArrayList<>();
|
||||
strings.add(GroovyFileType.DEFAULT_EXTENSION);
|
||||
strings.addAll(getCustomGroovyScriptExtensions());
|
||||
|
||||
@@ -36,6 +36,7 @@ public class TerminalSessionFileType extends FakeFileType {
|
||||
return getName() + " Fake File Type";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMyFileType(@NotNull VirtualFile file) {
|
||||
return file instanceof TerminalSessionVirtualFileImpl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user