summaryrefslogtreecommitdiffstats
path: root/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/ProblemProfile.java
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/ProblemProfile.java')
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/ProblemProfile.java105
1 files changed, 105 insertions, 0 deletions
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/ProblemProfile.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/ProblemProfile.java
new file mode 100644
index 0000000..d2330f1
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/ProblemProfile.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * 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.internal.core.model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.cdt.codan.core.model.IProblem;
+import org.eclipse.cdt.codan.core.model.IProblemCategory;
+import org.eclipse.cdt.codan.core.model.IProblemProfile;
+
+/**
+ * @author Alena
+ *
+ */
+public class ProblemProfile implements IProblemProfile, Cloneable {
+ private IProblemCategory rootCategory = new CodanProblemCategory("root",
+ "root");
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.cdt.codan.core.model.IProblemProfile#getProblem(java.lang
+ * .String)
+ */
+ public IProblem findProblem(String id) {
+ return getRoot().findProblem(id);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.codan.core.model.IProblemProfile#getProblems()
+ */
+ 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);
+ }
+ }
+ }
+
+ 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 {
+ ProblemProfile clone = (ProblemProfile) super.clone();
+ clone.rootCategory = (IProblemCategory) ((CodanProblemCategory) this.rootCategory)
+ .clone();
+ return clone;
+ } catch (CloneNotSupportedException e) {
+ return this;
+ }
+ }
+
+ /**
+ * @param p
+ * @param cat
+ */
+ public void addCategory(IProblemCategory category, IProblemCategory parent) {
+ ((CodanProblemCategory) parent).addChild(category);
+ }
+}