import java.io.IOException;
import java.util.*;
-import java.util.concurrent.atomic.AtomicBoolean;
/**
* @author max
*/
public class InspectionProfileImpl extends ProfileEx implements ModifiableModel, InspectionProfile, ExternalizableScheme {
- @NonNls private static InspectionProfileImpl DEFAULT_PROFILE;
-
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.InspectionProfileImpl");
@NonNls private static final String VALID_VERSION = "1.0";
static final String NAME = "name";
public static boolean INIT_INSPECTIONS = false;
-//private String myBaseProfileName;
-
public void setModified(final boolean modified) {
myModified = modified;
}
private boolean myModified = false;
- private final AtomicBoolean myInitialized = new AtomicBoolean(false);
+ private volatile boolean myInitialized;
public InspectionProfileImpl(InspectionProfileImpl inspectionProfile) {
super(inspectionProfile.getName());
final ToolsImpl toolList1 = profile1.myTools.get(toolName);
final ToolsImpl toolList2 = profile2.myTools.get(toolName);
- if (toolList1 == null && toolList2 == null) {
- return true;
- }
- if (toolList1 != null && toolList2 != null) {
- return toolList1.equalTo(toolList2);
- }
- return false;
+ return toolList1 == null && toolList2 == null || toolList1 != null && toolList2 != null && toolList1.equalTo(toolList2);
}
public boolean isProperSetting(HighlightDisplayKey key) {
}
public void resetToBase() {
+ initInspectionTools();
+
copyToolsConfigurations(myBaseProfile);
myDisplayLevelMap = null;
}
}
public Set<HighlightSeverity> getUsedSeverities() {
- LOG.assertTrue(myInitialized.get());
+ LOG.assertTrue(myInitialized);
final Set<HighlightSeverity> result = new HashSet<HighlightSeverity>();
for (ToolsImpl tools : myTools.values()) {
for (ScopeToolState state : tools.getTools()) {
element.setAttribute(VERSION_TAG, VALID_VERSION);
element.setAttribute(IS_LOCKED, String.valueOf(myLockedProfile));
- if (!myInitialized.get()) {
+ if (!myInitialized) {
for (Element el : myDeinstalledInspectionsSettings.values()) {
element.addContent((Element)el.clone());
}
}
public boolean wasInitialized() {
- return myInitialized.get();
+ return myInitialized;
}
public void initInspectionTools() {
- if (ApplicationManager.getApplication().isUnitTestMode() && !INIT_INSPECTIONS) {
- return;
+ if (ApplicationManager.getApplication().isUnitTestMode() && !INIT_INSPECTIONS) return;
+ if (myInitialized) return;
+ synchronized (myExternalInfo) {
+ if (myInitialized) return;
+ myInitialized = initialize();
}
- synchronized (myInitialized) {
- if (!myInitialized.getAndSet(true)) {
- if (myBaseProfile != null) {
- myBaseProfile.initInspectionTools();
- }
+ }
- final InspectionTool[] tools;
- try {
- tools = myRegistrar.createTools();
+ private boolean initialize() {
+ if (myBaseProfile != null) {
+ myBaseProfile.initInspectionTools();
+ }
+
+ final InspectionTool[] tools;
+ try {
+ tools = myRegistrar.createTools();
+ }
+ catch (ProcessCanceledException e) {
+ return false;
+ }
+ for (InspectionTool tool : tools) {
+ final String shortName = tool.getShortName();
+ HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
+ if (key == null) {
+ if (tool instanceof LocalInspectionToolWrapper) {
+ key = HighlightDisplayKey.register(shortName, tool.getDisplayName(), ((LocalInspectionToolWrapper)tool).getTool().getID(),
+ ((LocalInspectionToolWrapper)tool).getTool().getAlternativeID());
}
- catch (ProcessCanceledException e) {
- myInitialized.set(false);
- return;
+ else {
+ key = HighlightDisplayKey.register(shortName);
}
- for (InspectionTool tool : tools) {
- final String shortName = tool.getShortName();
- HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
- if (key == null) {
- if (tool instanceof LocalInspectionToolWrapper) {
- key = HighlightDisplayKey.register(shortName, tool.getDisplayName(), ((LocalInspectionToolWrapper)tool).getTool().getID(),
- ((LocalInspectionToolWrapper)tool).getTool().getAlternativeID());
- }
- else {
- key = HighlightDisplayKey.register(shortName);
- }
- }
+ }
- LOG.assertTrue(key != null, shortName + " ; number of initialized tools: " + myTools.size());
- final ToolsImpl toolsList =
- new ToolsImpl(tool, myBaseProfile != null ? myBaseProfile.getErrorLevel(key) : tool.getDefaultLevel(),
- !myLockedProfile && (myBaseProfile != null ? myBaseProfile.isToolEnabled(key) : tool.isEnabledByDefault()));
- final Element element = myDeinstalledInspectionsSettings.remove(tool.getShortName());
- if (element != null) {
- try {
- toolsList.readExternal(element, this);
- }
- catch (InvalidDataException e) {
- LOG.error(e);
- }
- }
- myTools.put(tool.getShortName(), toolsList);
+ LOG.assertTrue(key != null, shortName + " ; number of initialized tools: " + myTools.size());
+ final ToolsImpl toolsList =
+ new ToolsImpl(tool, myBaseProfile != null ? myBaseProfile.getErrorLevel(key) : tool.getDefaultLevel(),
+ !myLockedProfile && (myBaseProfile != null ? myBaseProfile.isToolEnabled(key) : tool.isEnabledByDefault()));
+ final Element element = myDeinstalledInspectionsSettings.remove(tool.getShortName());
+ if (element != null) {
+ try {
+ toolsList.readExternal(element, this);
}
- if (mySource != null) {
- copyToolsConfigurations(mySource);
+ catch (InvalidDataException e) {
+ LOG.error(e);
}
}
+ myTools.put(tool.getShortName(), toolsList);
}
+ if (mySource != null) {
+ copyToolsConfigurations(mySource);
+ }
+ return true;
}
private HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey key) {
myBaseProfile = inspectionProfile.myBaseProfile;
}
- public void copyToolsConfigurations(InspectionProfileImpl profile) {
+ private void copyToolsConfigurations(InspectionProfileImpl profile) {
try {
- initInspectionTools();
for (ToolsImpl toolList : profile.myTools.values()) {
final ToolsImpl tools = myTools.get(toolList.getShortName());
final ScopeToolState defaultState = toolList.getDefaultState();
InspectionProfileManager.getInstance().fireProfileChanged(inspectionProfile);
}
- public static synchronized InspectionProfileImpl getDefaultProfile() {
- if (DEFAULT_PROFILE == null) {
- DEFAULT_PROFILE = new InspectionProfileImpl("Default");
- }
- return DEFAULT_PROFILE;
+ private static class InspectionProfileImplHolder {
+ private static final InspectionProfileImpl DEFAULT_PROFILE = new InspectionProfileImpl("Default");
+ }
+
+ public static InspectionProfileImpl getDefaultProfile() {
+ return InspectionProfileImplHolder.DEFAULT_PROFILE;
}
public Document saveToDocument() throws WriteExternalException {