Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/codan
diff options
context:
space:
mode:
authorAlena Laskavaia2009-04-18 04:01:44 +0000
committerAlena Laskavaia2009-04-18 04:01:44 +0000
commit59cf9d5fad6bf7a4c01bea7d41543be18374e1a2 (patch)
tree17c415dab732c74c675ffcdb3e76050678d36bf9 /codan
parent3ccd43f5ed84780feb9b919a48a7355944580744 (diff)
downloadorg.eclipse.cdt-59cf9d5fad6bf7a4c01bea7d41543be18374e1a2.tar.gz
org.eclipse.cdt-59cf9d5fad6bf7a4c01bea7d41543be18374e1a2.tar.xz
org.eclipse.cdt-59cf9d5fad6bf7a4c01bea7d41543be18374e1a2.zip
- to make workspace/project override of properties work, change to store indiviual checkers id in properties
Diffstat (limited to 'codan')
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/PreferenceConstants.java1
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodanPreferencesLoader.java134
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CheckersRegisry.java42
-rw-r--r--codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CheckedTreeEditor.java1
-rw-r--r--codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java24
-rw-r--r--codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FieldEditorOverlayPage.java35
-rw-r--r--codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ProblemsTreeEditor.java53
7 files changed, 173 insertions, 117 deletions
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/PreferenceConstants.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/PreferenceConstants.java
index a309ae3751a..a4a13741a67 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/PreferenceConstants.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/PreferenceConstants.java
@@ -16,4 +16,5 @@ package org.eclipse.cdt.codan.core;
public class PreferenceConstants {
public static final String P_RUN_ON_BUILD = "booleanPreference";
public static final String P_PROBLEMS = "problems";
+ public static final String P_USE_PARENT = "useParentScope";
}
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodanPreferencesLoader.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodanPreferencesLoader.java
index 1e689729849..bf17ba3b362 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodanPreferencesLoader.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodanPreferencesLoader.java
@@ -10,21 +10,17 @@
*******************************************************************************/
package org.eclipse.cdt.codan.core.builder;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
import org.eclipse.cdt.codan.core.model.CodanProblem;
import org.eclipse.cdt.codan.core.model.CodanSeverity;
import org.eclipse.cdt.codan.core.model.IProblem;
import org.eclipse.cdt.codan.core.model.IProblemProfile;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
/**
* @author Alena
*
*/
public class CodanPreferencesLoader {
- private static String LIST_SEP = ",";
private IProblemProfile baseModel;
/**
@@ -45,101 +41,79 @@ public class CodanPreferencesLoader {
}
/**
- * Stored as element=true|false,...
- *
- * @param stringList
* @return
*/
- public Object modelFromString(String stringList) {
- String[] arr = stringList.split(LIST_SEP);
- for (int i = 0; i < arr.length; i++) {
- String elem = arr[i];
- String[] pair = elem.split("=", 2);
- if (pair.length == 0)
- continue;
- String id = pair[0];
- IProblem p = problemFromString(id);
- if (p == null) {
- System.err.println("cannot find '" + id + "'");
- continue;
- }
- if (pair.length == 1) {
- ((CodanProblem) p).setEnabled(true);
- } else {
- String check = pair[1];
- Boolean c = Boolean.valueOf(check);
- ((CodanProblem) p).setEnabled(c);
- }
- }
- return baseModel;
- }
-
- protected String problemToString(Object element) {
- IProblem p = ((IProblem) element);
- return p.getId() + ":" + p.getSeverity();
+ public IProblem[] getProblems() {
+ IProblem[] problems = baseModel.getProblems();
+ return problems;
}
- protected IProblem problemFromString(String string) {
- String[] pair = string.split(":");
- if (pair.length == 0)
- return null;
- String id = pair[0];
- String arg = "";
- if (pair.length > 1) {
- arg = pair[1];
+ /**
+ * @param id
+ * @param s
+ */
+ public void setProperty(String id, String s) {
+ IProblem prob = baseModel.findProblem(id);
+ if (!(prob instanceof CodanProblem))
+ return;
+ String sevs = s;
+ boolean enabled = true;
+ if (sevs.startsWith("-")) {
+ sevs = sevs.substring(1);
+ enabled = false;
}
+ ((CodanProblem) prob).setEnabled(enabled);
CodanSeverity sev;
try {
- sev = CodanSeverity.valueOf(arg);
+ sev = CodanSeverity.valueOf(sevs);
} catch (RuntimeException e) {
sev = CodanSeverity.Warning;
}
- IProblem prob = baseModel.findProblem(id);
- if (prob instanceof CodanProblem) {
- ((CodanProblem) prob).setSeverity(sev);
- }
- return prob;
+ ((CodanProblem) prob).setSeverity(sev);
}
- /**
- * Combines the given list of items into a single string. This method is the
- * converse of <code>parseString</code>.
- * <p>
- * Subclasses may implement this method.
- * </p>
+ /*
+ * (non-Javadoc)
*
- * @return the combined string
- * @see #parseString
+ * @see java.lang.Object#toString()
*/
- public String modelToString(Object model) {
- StringBuffer buf = new StringBuffer();
- Map<Object, Boolean> map = fillChecked(model,
- new HashMap<Object, Boolean>());
- for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
- Object element = iterator.next();
- buf.append(problemToString(element));
- buf.append('=');
- buf.append(map.get(element));
- if (iterator.hasNext())
- buf.append(LIST_SEP);
- }
- return buf.toString();
+ @Override
+ public String toString() {
+ return getInput().toString();
+ }
+
+ /**
+ * @return
+ */
+ public IProblemProfile getInput() {
+ return baseModel;
}
/**
- * @param input
- * @param hashMap
+ * @param id
* @return
*/
- private Map<Object, Boolean> fillChecked(Object element,
- HashMap<Object, Boolean> hashMap) {
- if (element instanceof IProblemProfile) {
- IProblemProfile profile = (IProblemProfile) element;
- IProblem[] problems = profile.getProblems();
- for (IProblem iProblem : problems) {
- hashMap.put(iProblem, iProblem.isEnabled());
+ public String getProperty(String id) {
+ IProblem prob = baseModel.findProblem(id);
+ if (!(prob instanceof CodanProblem))
+ return null;
+ String enabled = prob.isEnabled() ? "" : "-";
+ String severity = prob.getSeverity().toString();
+ String res = enabled + severity;
+ return res;
+ }
+
+ /**
+ * @param storePreferences
+ */
+ public void load(IEclipsePreferences storePreferences) {
+ IProblem[] probs = getProblems();
+ for (int i = 0; i < probs.length; i++) {
+ String id = probs[i].getId();
+ String s = storePreferences.get(id, null);
+ if (s != null) {
+ setProperty(id, s);
}
}
- return hashMap;
}
}
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CheckersRegisry.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CheckersRegisry.java
index 9ecfd9770ba..69b01d34bfc 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CheckersRegisry.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CheckersRegisry.java
@@ -192,9 +192,7 @@ public class CheckersRegisry implements Iterable<IChecker> {
wp = (IProblemProfile) getDefaultProfile().clone();
// load default values
CodanPreferencesLoader loader = new CodanPreferencesLoader(wp);
- String s = CodanCorePlugin.getDefault().getStorePreferences()
- .get(PreferenceConstants.P_PROBLEMS, "");
- loader.modelFromString(s);
+ loader.load(CodanCorePlugin.getDefault().getStorePreferences());
} catch (CloneNotSupportedException e) {
wp = getDefaultProfile();
}
@@ -202,6 +200,13 @@ public class CheckersRegisry implements Iterable<IChecker> {
return wp;
}
+ public void updateProfile(IResource element, IProblemProfile profile) {
+ if (profile == null)
+ profiles.remove(element);
+ else
+ profiles.put(element, profile);
+ }
+
/**
* @param element
* @return
@@ -218,8 +223,12 @@ public class CheckersRegisry implements Iterable<IChecker> {
IEclipsePreferences node = new ProjectScope(
(IProject) element)
.getNode(CodanCorePlugin.PLUGIN_ID);
- String s = node.get(PreferenceConstants.P_PROBLEMS, "");
- loader.modelFromString(s);
+ boolean useWorkspace = node.getBoolean(
+ PreferenceConstants.P_USE_PARENT, false);
+ if (!useWorkspace) {
+ loader.load(node);
+ }
+ updateProfile(element, prof);
} catch (CloneNotSupportedException e) {
// cant
}
@@ -228,7 +237,30 @@ public class CheckersRegisry implements Iterable<IChecker> {
} else {
prof = getResourceProfile(element.getProject());
}
+ } else {
}
return prof;
}
+
+ /**
+ * @param element
+ * @return
+ */
+ public IProblemProfile getResourceProfileWorkingCopy(IResource element) {
+ if (element instanceof IProject) {
+ try {
+ IProblemProfile prof = (IProblemProfile) getWorkspaceProfile()
+ .clone();
+ // load default values
+ CodanPreferencesLoader loader = new CodanPreferencesLoader(prof);
+ IEclipsePreferences node = new ProjectScope((IProject) element)
+ .getNode(CodanCorePlugin.PLUGIN_ID);
+ loader.load(node);
+ return prof;
+ } catch (CloneNotSupportedException e) {
+ // cant
+ }
+ }
+ return null;
+ }
}
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CheckedTreeEditor.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CheckedTreeEditor.java
index 684ea502848..ace13b12219 100644
--- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CheckedTreeEditor.java
+++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CheckedTreeEditor.java
@@ -187,7 +187,6 @@ public abstract class CheckedTreeEditor extends FieldEditor implements
*/
protected void doLoadDefault() {
if (getTreeControl() != null) {
- treeViewer.refresh();
String s = getPreferenceStore().getDefaultString(
getPreferenceName());
getViewer().setInput(modelFromString(s));
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java
index 1bcfe36f0ab..412b6f06a6c 100644
--- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java
+++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java
@@ -12,6 +12,7 @@ package org.eclipse.cdt.codan.internal.ui.preferences;
import org.eclipse.cdt.codan.core.CodanCorePlugin;
import org.eclipse.cdt.codan.core.model.CheckersRegisry;
+import org.eclipse.cdt.codan.core.model.IProblemProfile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.ui.IWorkbench;
@@ -30,6 +31,8 @@ import org.eclipse.ui.preferences.ScopedPreferenceStore;
*/
public class CodanPreferencePage extends FieldEditorOverlayPage implements
IWorkbenchPreferencePage {
+ private IProblemProfile profile;
+
public CodanPreferencePage() {
super(GRID);
setPreferenceStore(new ScopedPreferenceStore(new InstanceScope(),
@@ -47,17 +50,30 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
* editor knows how to save and restore itself.
*/
public void createFieldEditors() {
+ profile = isPropertyPage() ? CheckersRegisry.getInstance()
+ .getResourceProfileWorkingCopy((IResource) getElement())
+ : CheckersRegisry.getInstance().getWorkspaceProfile();
CheckedTreeEditor checkedTreeEditor = new ProblemsTreeEditor(
- getFieldEditorParent(), isPropertyPage() ? CheckersRegisry
- .getInstance().getResourceProfile(
- (IResource) getElement()) : CheckersRegisry
- .getInstance().getWorkspaceProfile());
+ getFieldEditorParent(), profile);
addField(checkedTreeEditor);
}
/*
* (non-Javadoc)
*
+ * @see org.eclipse.jface.preference.PreferencePage#performApply()
+ */
+ @Override
+ public boolean performOk() {
+ if (isPropertyPage())
+ CheckersRegisry.getInstance().updateProfile(
+ (IResource) getElement(), null);
+ return super.performOk();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @see
* org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
*/
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FieldEditorOverlayPage.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FieldEditorOverlayPage.java
index dee50942ffb..e617a7541f0 100644
--- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FieldEditorOverlayPage.java
+++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FieldEditorOverlayPage.java
@@ -15,12 +15,10 @@ import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.codan.core.CodanCorePlugin;
+import org.eclipse.cdt.codan.core.PreferenceConstants;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ProjectScope;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.preference.FieldEditor;
@@ -49,13 +47,6 @@ import org.eclipse.ui.preferences.ScopedPreferenceStore;
*/
public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage
implements IWorkbenchPropertyPage {
- /***
- * Name of resource property for the selection of workbench or project
- * settings
- ***/
- public static final String USEPROJECTSETTINGS = "useProjectSettings"; //$NON-NLS-1$
- private static final String FALSE = "false"; //$NON-NLS-1$
- private static final String TRUE = "true"; //$NON-NLS-1$
// Stores all created field editors
private List editors = new ArrayList();
// Stores owning element of properties
@@ -223,15 +214,15 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage
});
// Set workspace/project radio buttons
try {
- String use = ((IResource) getElement())
- .getPersistentProperty(new QualifiedName(pageId,
- USEPROJECTSETTINGS));
- if (TRUE.equals(use)) {
+ Boolean useWorkspace = getPreferenceStore().getBoolean(
+ PreferenceConstants.P_USE_PARENT);
+ if (useWorkspace) {
+ useWorkspaceSettingsButton.setSelection(true);
+ } else {
useProjectSettingsButton.setSelection(true);
configureButton.setEnabled(false);
- } else
- useWorkspaceSettingsButton.setSelection(true);
- } catch (CoreException e) {
+ }
+ } catch (Exception e) {
useWorkspaceSettingsButton.setSelection(true);
}
}
@@ -306,14 +297,8 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage
boolean result = super.performOk();
if (result && isPropertyPage()) {
// Save state of radiobuttons in project properties
- IResource resource = (IResource) getElement();
- try {
- String value = (useProjectSettingsButton.getSelection()) ? TRUE
- : FALSE;
- resource.setPersistentProperty(new QualifiedName(pageId,
- USEPROJECTSETTINGS), value);
- } catch (CoreException e) {
- }
+ getPreferenceStore().setValue(PreferenceConstants.P_USE_PARENT,
+ !useProjectSettingsButton.getSelection());
}
return result;
}
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ProblemsTreeEditor.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ProblemsTreeEditor.java
index e1dbed213da..fa14390a1bb 100644
--- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ProblemsTreeEditor.java
+++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ProblemsTreeEditor.java
@@ -186,12 +186,61 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
/*
* (non-Javadoc)
*
+ * @see
+ * org.eclipse.cdt.codan.internal.ui.preferences.CheckedTreeEditor#doLoad()
+ */
+ @Override
+ protected void doLoad() {
+ if (getTreeControl() != null) {
+ IProblem[] probs = codanPreferencesLoader.getProblems();
+ for (int i = 0; i < probs.length; i++) {
+ String id = probs[i].getId();
+ String s = getPreferenceStore().getString(id);
+ codanPreferencesLoader.setProperty(id, s);
+ }
+ getViewer().setInput(codanPreferencesLoader.getInput());
+ }
+ }
+
+ @Override
+ protected void doLoadDefault() {
+ if (getTreeControl() != null) {
+ IProblem[] probs = codanPreferencesLoader.getProblems();
+ for (int i = 0; i < probs.length; i++) {
+ String id = probs[i].getId();
+ String s = getPreferenceStore().getDefaultString(id);
+ codanPreferencesLoader.setProperty(id, s);
+ }
+ getViewer().setInput(codanPreferencesLoader.getInput());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.cdt.codan.internal.ui.preferences.CheckedTreeEditor#doStore()
+ */
+ @Override
+ protected void doStore() {
+ codanPreferencesLoader.setInput(getViewer().getInput());
+ IProblem[] probs = codanPreferencesLoader.getProblems();
+ for (int i = 0; i < probs.length; i++) {
+ String id = probs[i].getId();
+ String s = codanPreferencesLoader.getProperty(id);
+ getPreferenceStore().setValue(id, s);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @seeorg.eclipse.cdt.codan.internal.ui.preferences.CheckedTreeEditor#
* modelFromString(java.lang.String)
*/
@Override
protected Object modelFromString(String s) {
- return codanPreferencesLoader.modelFromString(s);
+ return codanPreferencesLoader.getInput();
}
/*
@@ -203,6 +252,6 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
*/
@Override
protected String modelToString(Object model) {
- return codanPreferencesLoader.modelToString(model);
+ return "";
}
}

Back to the top