IDEA-260215 - reverted copying extensions for each method call, caching extensions as jdom.Elements to refresh the options

GitOrigin-RevId: cd95325f997b3bd45ce73ebcba3ca5bc34cbdb58
This commit is contained in:
Ilyas Selimov
2021-03-03 10:40:19 +00:00
committed by intellij-monorepo-bot
parent d9a615a4d6
commit 93ac26e818
2 changed files with 34 additions and 6 deletions
@@ -32,7 +32,7 @@ import org.jetbrains.annotations.TestOnly;
import org.jetbrains.uast.*;
import java.util.*;
import java.util.stream.Collectors;
import java.util.concurrent.ConcurrentHashMap;
public class UnusedDeclarationInspectionBase extends GlobalInspectionTool {
private static final Logger LOG = Logger.getInstance(UnusedDeclarationInspectionBase.class);
@@ -53,6 +53,11 @@ public class UnusedDeclarationInspectionBase extends GlobalInspectionTool {
private final boolean myEnabledInEditor;
/**
* We can't have a direct link on the entry points as it blocks dynamic unloading of the plugins e.g. TestNG
*/
private final Map<String, Element> entryPointElements = new ConcurrentHashMap<>();
@SuppressWarnings("TestOnlyProblems")
public UnusedDeclarationInspectionBase() {
this(!ApplicationManager.getApplication().isUnitTestMode());
@@ -115,12 +120,19 @@ public class UnusedDeclarationInspectionBase extends GlobalInspectionTool {
myLocalInspectionBase.readSettings(node);
for (EntryPoint extension : getExtensions()) {
extension.readExternal(node);
saveEntryPointElement(extension);
}
final String testEntriesAttr = node.getAttributeValue("test_entries");
TEST_ENTRY_POINTS = testEntriesAttr == null || Boolean.parseBoolean(testEntriesAttr);
}
protected void saveEntryPointElement(@NotNull EntryPoint entryPoint) {
Element element = new Element("root");
entryPoint.writeExternal(element);
entryPointElements.put(entryPoint.getDisplayName(), element);
}
@Override
public void writeSettings(@NotNull Element node) throws WriteExternalException {
myLocalInspectionBase.writeSettings(node);
@@ -700,10 +712,23 @@ public class UnusedDeclarationInspectionBase extends GlobalInspectionTool {
}
public List<EntryPoint> getExtensions() {
return EntryPointsManagerBase.DEAD_CODE_EP_NAME.getExtensionList()
.stream()
.sorted((o1, o2) -> o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName()))
.collect(Collectors.toList());
List<EntryPoint> extensions = EntryPointsManagerBase.DEAD_CODE_EP_NAME.getExtensionList();
List<EntryPoint> deadCodeAddIns = new ArrayList<>(extensions.size());
for (EntryPoint entryPoint : extensions) {
try {
EntryPoint clone = entryPoint.clone();
Element element = entryPointElements.get(entryPoint.getDisplayName());
if (element != null) {
clone.readExternal(element);
}
deadCodeAddIns.add(clone);
}
catch (Exception e) {
LOG.error(e);
}
}
deadCodeAddIns.sort((o1, o2) -> o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName()));
return deadCodeAddIns;
}
public static String getDisplayNameText() {
@@ -188,7 +188,10 @@ public final class UnusedDeclarationInspection extends UnusedDeclarationInspecti
if (extension.showUI()) {
final JCheckBox extCheckbox = new JCheckBox(extension.getDisplayName());
extCheckbox.setSelected(extension.isSelected());
extCheckbox.addActionListener(e -> extension.setSelected(extCheckbox.isSelected()));
extCheckbox.addActionListener(e -> {
extension.setSelected(extCheckbox.isSelected());
saveEntryPointElement(extension);
});
add(extCheckbox, gc);
gc.gridy++;
}