diff options
author | Alena Laskavaia | 2009-04-16 01:46:57 +0000 |
---|---|---|
committer | Alena Laskavaia | 2009-04-16 01:46:57 +0000 |
commit | 8ebbd32496cb2cdb7f7cd431602146e64f85bd93 (patch) | |
tree | eb6cc2112fbbc52353ae2252ef658b7bbe8c92d0 /codan/org.eclipse.cdt.codan.core | |
parent | d99739839b5dc6daf3b56b5c6174fa7983b3d39f (diff) | |
download | org.eclipse.cdt-8ebbd32496cb2cdb7f7cd431602146e64f85bd93.tar.gz org.eclipse.cdt-8ebbd32496cb2cdb7f7cd431602146e64f85bd93.tar.xz org.eclipse.cdt-8ebbd32496cb2cdb7f7cd431602146e64f85bd93.zip |
- updated property store to initialize from core
Diffstat (limited to 'codan/org.eclipse.cdt.codan.core')
13 files changed, 465 insertions, 35 deletions
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java index 1810762e144..00b554abd86 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java @@ -3,6 +3,8 @@ package org.eclipse.cdt.codan.core; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; import org.osgi.framework.BundleContext; /** @@ -20,6 +22,10 @@ public class CodanCorePlugin extends Plugin { public CodanCorePlugin() { } + public IEclipsePreferences getStorePreferences() { + return new InstanceScope().getNode(PLUGIN_ID); + } + /* * (non-Javadoc) * 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 new file mode 100644 index 00000000000..a309ae3751a --- /dev/null +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/PreferenceConstants.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2009 Alena Laskavaia + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.core; + +/** + * Constant definitions for plug-in preferences + */ +public class PreferenceConstants { + public static final String P_RUN_ON_BUILD = "booleanPreference"; + public static final String P_PROBLEMS = "problems"; +} 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 new file mode 100644 index 00000000000..7419498d433 --- /dev/null +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodanPreferencesLoader.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright (c) 2009 Alena Laskavaia + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +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.IProblemsProfile; + +/** + * @author Alena + * + */ +public class CodanPreferencesLoader { + private static String LIST_SEP = ","; + private IProblemsProfile baseModel; + + /** + * @param workspaceProfile + */ + public CodanPreferencesLoader(IProblemsProfile profile) { + setInput(profile); + } + + /** + * + */ + public CodanPreferencesLoader() { + } + + public void setInput(Object model) { + baseModel = (IProblemsProfile) model; + } + + /** + * 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(); + } + + 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]; + } + CodanSeverity sev; + try { + sev = CodanSeverity.valueOf(arg); + } catch (RuntimeException e) { + sev = CodanSeverity.Warning; + } + IProblem prob = baseModel.findProblem(id); + if (prob instanceof CodanProblem) { + ((CodanProblem) prob).setSeverity(sev); + } + return prob; + } + + /** + * 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> + * + * @return the combined string + * @see #parseString + */ + 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(); + } + + /** + * @param input + * @param hashMap + * @return + */ + private Map<Object, Boolean> fillChecked(Object element, + HashMap<Object, Boolean> hashMap) { + if (element instanceof IProblemsProfile) { + IProblemsProfile profile = (IProblemsProfile) element; + IProblem[] problems = profile.getProblems(); + for (IProblem iProblem : problems) { + hashMap.put(iProblem, iProblem.isEnabled()); + } + } + return hashMap; + } +} diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractIndexAstChecker.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractIndexAstChecker.java index 5b6855784f4..070ddca7941 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractIndexAstChecker.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractIndexAstChecker.java @@ -15,6 +15,7 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; @@ -35,8 +36,10 @@ public abstract class AbstractIndexAstChecker extends AbstractChecker implements void processFile(IFile file) throws CoreException, InterruptedException { this.file = file; // create translation unit and access index - ITranslationUnit tu = (ITranslationUnit) CoreModel.getDefault().create( - file); + ICElement model = CoreModel.getDefault().create(file); + if (!(model instanceof ITranslationUnit)) + return; + ITranslationUnit tu = (ITranslationUnit) model; if (tu == null) return; // not a C/C++ file IIndex index = CCorePlugin.getIndexManager().getIndex(tu.getCProject()); 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 d2dd4975b46..7d5e2fb754b 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 @@ -12,27 +12,34 @@ package org.eclipse.cdt.codan.core.model; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; import org.eclipse.cdt.codan.core.CodanCorePlugin; -import org.eclipse.core.resources.IFile; +import org.eclipse.cdt.codan.core.PreferenceConstants; +import org.eclipse.cdt.codan.core.builder.CodanPreferencesLoader; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ProjectScope; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; public class CheckersRegisry implements Iterable<IChecker> { private static final String EXTENSION_POINT_NAME = "checkers"; private static final String CHECKER_ELEMENT = "checker"; private static final String PROBLEM_ELEMENT = "problem"; + private static final Object DEFAULT = "DEFAULT"; private Collection<IChecker> checkers = new ArrayList<IChecker>(); private static CheckersRegisry instance; - private IProblemCategory rootCategory = new CodanProblemCategory("root", - "root"); - private Collection<IProblem> problems = new ArrayList<IProblem>(); + private HashMap<Object, IProblemsProfile> profiles = new HashMap<Object, IProblemsProfile>(); private CheckersRegisry() { instance = this; + profiles.put(DEFAULT, new ProblemsProfile()); readCheckersRegistry(); } @@ -92,13 +99,13 @@ public class CheckersRegisry implements Iterable<IChecker> { if (children1 != null) { for (IConfigurationElement ref : children1) { hasRef = true; - IProblem p = getProblemById(ref.getAttribute("refId"), - null); + IProblem p = getDefaultProfile().findProblem( + ref.getAttribute("refId")); addRefProblem(checkerObj, p); } } if (!hasRef) { - addProblem(new CodanProblem(id, name)); + addProblem(new CodanProblem(id, name), null); } } } catch (Exception e) { @@ -120,7 +127,8 @@ public class CheckersRegisry implements Iterable<IChecker> { if (name == null) name = id; CodanProblem p = new CodanProblem(id, name); - addProblem(p); + String category = getAtt(configurationElement, "category"); + addProblem(p, category); return p; } return null; @@ -156,28 +164,68 @@ public class CheckersRegisry implements Iterable<IChecker> { checkers.add(checker); } - public void addProblem(IProblem p) { - problems.add(p); // TODO category - ((CodanProblemCategory) rootCategory).addChild(p); + public void addProblem(IProblem p, String category) { + ((ProblemsProfile) getDefaultProfile()).addProblem(p, + getDefaultProfile().getRoot()); } - public Object getProblemsTree() { - return rootCategory; + public void addRefProblem(IChecker c, IProblem p) { } - public void addRefProblem(IChecker c, IProblem p) { + /** + * @return + */ + public IProblemsProfile getDefaultProfile() { + return profiles.get(DEFAULT); } - public IProblem findProblem(String id) { - for (Iterator iterator = problems.iterator(); iterator.hasNext();) { - IProblem p = (IProblem) iterator.next(); - if (p.getId().equals(id)) - return p; + /** + * @return + */ + public IProblemsProfile getWorkspaceProfile() { + IProblemsProfile wp = profiles.get(ResourcesPlugin.getWorkspace()); + if (wp == null) { + try { + wp = (IProblemsProfile) getDefaultProfile().clone(); + // load default values + CodanPreferencesLoader loader = new CodanPreferencesLoader(wp); + String s = CodanCorePlugin.getDefault().getStorePreferences() + .get(PreferenceConstants.P_PROBLEMS, ""); + loader.modelFromString(s); + } catch (CloneNotSupportedException e) { + wp = getDefaultProfile(); + } } - return null; + return wp; } - public IProblem getProblemById(String id, IFile file) { - return findProblem(id); + /** + * @param element + * @return + */ + public IProblemsProfile getResourceProfile(IResource element) { + IProblemsProfile prof = profiles.get(element); + if (prof == null) { + if (element instanceof IProject) { + try { + prof = (IProblemsProfile) getWorkspaceProfile().clone(); + // load default values + CodanPreferencesLoader loader = new CodanPreferencesLoader( + prof); + IEclipsePreferences node = new ProjectScope( + (IProject) element) + .getNode(CodanCorePlugin.PLUGIN_ID); + String s = node.get(PreferenceConstants.P_PROBLEMS, ""); + loader.modelFromString(s); + } catch (CloneNotSupportedException e) { + // cant + } + } else if (element.getParent() != null) { + prof = getResourceProfile(element.getParent()); + } else { + prof = getResourceProfile(element.getProject()); + } + } + return prof; } } diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanProblem.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanProblem.java index 7cc86d02758..b83ab1509d6 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanProblem.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanProblem.java @@ -56,4 +56,14 @@ public class CodanProblem implements IProblem { public void setEnabled(boolean checked) { this.enabled = checked; } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#clone() + */ + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } } diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanProblemCategory.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanProblemCategory.java index 2a47418751e..9e5e0096dc4 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanProblemCategory.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanProblemCategory.java @@ -11,13 +11,13 @@ package org.eclipse.cdt.codan.core.model; import java.util.ArrayList; +import java.util.Iterator; - -public class CodanProblemCategory implements IProblemCategory { +public class CodanProblemCategory implements IProblemCategory, Cloneable { private String id; private String name; + private ArrayList<IProblemElement> list = new ArrayList<IProblemElement>(); - private ArrayList list = new ArrayList(); public CodanProblemCategory(String id, String name) { this.id = id; this.name = name; @@ -35,6 +35,7 @@ public class CodanProblemCategory implements IProblemCategory { public String toString() { return name; } + public Object[] getChildren() { return list.toArray(); } @@ -43,10 +44,56 @@ public class CodanProblemCategory implements IProblemCategory { list.add(p); } - public IProblemCategory getParent() { - // TODO Auto-generated method stub + public IProblem findProblem(String id) { + Object[] children = this.getChildren(); + for (Object object : children) { + if (object instanceof IProblemCategory) { + IProblemCategory cat = (IProblemCategory) object; + IProblem found = cat.findProblem(id); + if (found != null) + return found; + } else if (object instanceof IProblem) { + IProblem p = (IProblem) object; + if (p.getId().equals(id)) + return p; + } + } return null; } + public IProblemCategory findCategory(String id) { + if (getId().equals(id)) + return this; + Object[] children = getChildren(); + for (Object object : children) { + if (object instanceof IProblemCategory) { + IProblemCategory cat = (IProblemCategory) object; + IProblemCategory found = cat.findCategory(id); + if (found != null) + return found; + } + } + return null; + } + /* + * (non-Javadoc) + * + * @see java.lang.Object#clone() + */ + @Override + public Object clone() { + try { + CodanProblemCategory clone = (CodanProblemCategory) super.clone(); + clone.list = new ArrayList<IProblemElement>(); + for (Iterator<IProblemElement> iterator = this.list.iterator(); iterator + .hasNext();) { + IProblemElement child = iterator.next(); + clone.list.add((IProblemElement) child.clone()); + } + return clone; + } catch (CloneNotSupportedException e) { + return this; + } + } } diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ErrorReporter.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ErrorReporter.java index 8196ca531b5..baff427ae1a 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ErrorReporter.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ErrorReporter.java @@ -26,8 +26,8 @@ public class ErrorReporter { throw new NullPointerException("file"); if (id == null) throw new NullPointerException("id"); - IProblem problem = CheckersRegisry.getInstance().getProblemById(id, - file); + IProblem problem = CheckersRegisry.getInstance() + .getResourceProfile(file).findProblem(id); if (problem == null) throw new IllegalArgumentException("Id is not registered"); if (problem.isEnabled() == false) diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblem.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblem.java index 6079963dd98..5f262a6dedc 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblem.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblem.java @@ -10,8 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.codan.core.model; - -public interface IProblem { +public interface IProblem extends IProblemElement { String getName(); String getId(); diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemCategory.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemCategory.java index bd9c60d66da..45a62a0a294 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemCategory.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemCategory.java @@ -10,12 +10,22 @@ *******************************************************************************/ package org.eclipse.cdt.codan.core.model; -public interface IProblemCategory { +public interface IProblemCategory extends IProblemElement { String getName(); String getId(); + Object[] getChildren(); - IProblemCategory getParent(); + /** + * @param id + * @return + */ + IProblem findProblem(String id); + /** + * @param id + * @return + */ + IProblemCategory findCategory(String id); } diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemElement.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemElement.java new file mode 100644 index 00000000000..b9f7fb8a378 --- /dev/null +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemElement.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2009 Alena Laskavaia + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.core.model; + +/** + * @author Alena + * + */ +public interface IProblemElement extends Cloneable { + Object clone() throws CloneNotSupportedException; +} diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemsProfile.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemsProfile.java new file mode 100644 index 00000000000..82ad198be5e --- /dev/null +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemsProfile.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2009 Alena Laskavaia + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.core.model; + +/** + * @author Alena + * + */ +public interface IProblemsProfile extends IProblemElement { + IProblemCategory getRoot(); + + IProblem findProblem(String id); + + IProblem[] getProblems(); +} diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ProblemsProfile.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ProblemsProfile.java new file mode 100644 index 00000000000..d2b81f45fa0 --- /dev/null +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ProblemsProfile.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2009 Alena Laskavaia + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.core.model; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * @author Alena + * + */ +public class ProblemsProfile implements IProblemsProfile, Cloneable { + private IProblemCategory rootCategory = new CodanProblemCategory("root", + "root"); + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.cdt.codan.core.model.IProblemsProfile#getProblem(java.lang + * .String) + */ + @Override + public IProblem findProblem(String id) { + return getRoot().findProblem(id); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.codan.core.model.IProblemsProfile#getProblems() + */ + @Override + public IProblem[] getProblems() { + Collection<IProblem> problems = new ArrayList<IProblem>(); + collectProblems(getRoot(), problems); + return problems.toArray(new IProblem[problems.size()]); + } + + /** + * @param root + * @param problems + */ + protected void collectProblems(IProblemCategory parent, + Collection<IProblem> problems) { + Object[] children = parent.getChildren(); + for (Object object : children) { + if (object instanceof IProblemCategory) { + IProblemCategory cat = (IProblemCategory) object; + collectProblems(cat, problems); + } else if (object instanceof IProblem) { + problems.add((IProblem) object); + } + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.codan.core.model.IProblemsProfile#getRoot() + */ + @Override + public IProblemCategory getRoot() { + return rootCategory; + } + + public void addProblem(IProblem p, IProblemCategory cat) { + if (cat == null) + cat = getRoot(); + ((CodanProblemCategory) cat).addChild(p); + } + + public IProblemCategory findCategory(String id) { + return getRoot().findCategory(id); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#clone() + */ + @Override + public Object clone() { + try { + ProblemsProfile clone = (ProblemsProfile) super.clone(); + clone.rootCategory = (IProblemCategory) ((CodanProblemCategory) this.rootCategory) + .clone(); + return clone; + } catch (CloneNotSupportedException e) { + return this; + } + } +} |