Skip to main content
aboutsummaryrefslogtreecommitdiffstats
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/org.eclipse.cdt.codan.core
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/org.eclipse.cdt.codan.core')
-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
3 files changed, 92 insertions, 85 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;
+ }
}

Back to the top