summaryrefslogtreecommitdiffstats
path: root/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core')
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CVS/Entries7
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CVS/Repository1
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CVS/Root1
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanApplication.java94
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java91
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanPreferencesLoader.java119
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanRuntime.java54
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/PreferenceConstants.java20
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractChecker.java76
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractIndexAstChecker.java97
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Entries16
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Repository1
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Root1
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanSeverity.java40
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICAstChecker.java21
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IChecker.java28
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICheckersRegistry.java66
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICodanAstReconciler.java22
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICodanBuilder.java22
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblem.java37
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemCategory.java31
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemElement.java19
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemLocation.java54
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemProfile.java52
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemReporter.java28
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ProblemLocation.java109
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ProblemProfile.java103
27 files changed, 1210 insertions, 0 deletions
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CVS/Entries b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CVS/Entries
new file mode 100644
index 0000000..fec4197
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CVS/Entries
@@ -0,0 +1,7 @@
+/CodanApplication.java/1.2/Sat Aug 22 21:16:48 2009//
+/CodanCorePlugin.java/1.3/Sat Aug 22 21:16:48 2009//
+/CodanPreferencesLoader.java/1.1/Sat Aug 22 21:16:49 2009//
+/CodanRuntime.java/1.1/Sat Aug 22 21:16:48 2009//
+/PreferenceConstants.java/1.2/Sat Apr 18 04:01:43 2009//
+D/builder////
+D/model////
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CVS/Repository b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CVS/Repository
new file mode 100644
index 0000000..7f0ac5c
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CVS/Repository
@@ -0,0 +1 @@
+org.eclipse.cdt/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CVS/Root b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CVS/Root
new file mode 100644
index 0000000..04efa23
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CVS/Root
@@ -0,0 +1 @@
+:pserver:anonymous@dev.eclipse.org:/cvsroot/tools
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanApplication.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanApplication.java
new file mode 100644
index 0000000..e0287b1
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanApplication.java
@@ -0,0 +1,94 @@
+package org.eclipse.cdt.codan.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.cdt.codan.internal.core.CodanBuilder;
+import org.eclipse.cdt.codan.internal.core.model.CodanMarkerProblemReporter;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.equinox.app.IApplication;
+import org.eclipse.equinox.app.IApplicationContext;
+
+public class CodanApplication implements IApplication {
+ private Collection<String> projects = new ArrayList<String>();
+ private boolean verbose = false;
+ private boolean all = false;
+
+ public Object start(IApplicationContext context) throws Exception {
+ String[] args = (String[]) context.getArguments().get(
+ "application.args");
+ if (args == null || args.length == 0) {
+ help();
+ return EXIT_OK;
+ }
+ extractArguments(args);
+ CodanBuilder codanBuilder = new CodanBuilder();
+ CodanRuntime runtime = CodanRuntime.getInstance();
+ runtime.setProblemReporter(new CodanMarkerProblemReporter() {
+ @Override
+ public void reportProblem(String id, int severity, IFile file,
+ int lineNumber, int startChar, int endChar, String message) {
+ System.out.println(file.getLocation() + ":" + lineNumber + ": "
+ + message);
+ }
+ });
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ if (all) {
+ log("Launching analysis on workspace");
+ root.accept(codanBuilder.new CodanResourceVisitor());
+ } else {
+ for (String project : projects) {
+ log("Launching analysis on project " + project);
+ IProject wProject = root.getProject(project);
+ if (!wProject.exists()) {
+ System.err.println("Error: project " + project
+ + " does not exist");
+ continue;
+ }
+ wProject.accept(codanBuilder.new CodanResourceVisitor());
+ }
+ }
+ return EXIT_OK;
+ }
+
+ /**
+ * @param string
+ */
+ private void log(String string) {
+ if (verbose)
+ System.err.println(string);
+ }
+
+ /**
+ * @param args
+ */
+ private void extractArguments(String[] args) {
+ for (int i = 0; i < args.length; i++) {
+ String string = args[i];
+ if (string.equals("-verbose")) {
+ verbose = true;
+ } else if (string.equals("-all")) {
+ all = true;
+ } else {
+ projects.add(string);
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ private void help() {
+ System.out.println("Usage: [options] <project1> <project2> ...");
+ System.out.println("Options:");
+ System.out.println(" -all - run on all projects in workspace");
+ System.out.println(" -verbose - print extra build information");
+ }
+
+ public void stop() {
+ // nothing
+ }
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java
new file mode 100644
index 0000000..d60262b
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java
@@ -0,0 +1,91 @@
+package org.eclipse.cdt.codan.core;
+
+import org.eclipse.cdt.codan.internal.core.CodeAnlysisNature;
+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;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class CodanCorePlugin extends Plugin {
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.cdt.codan.core";
+ public static final String NATURE_ID = CodeAnlysisNature.NATURE_ID;
+ // The shared instance
+ private static CodanCorePlugin plugin;
+
+ /**
+ * The constructor
+ */
+ public CodanCorePlugin() {
+ }
+
+ public IEclipsePreferences getStorePreferences() {
+ return new InstanceScope().getNode(PLUGIN_ID);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static CodanCorePlugin getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Logs the specified status with this plug-in's log.
+ *
+ * @param status
+ * status to log
+ */
+ public static void log(IStatus status) {
+ getDefault().getLog().log(status);
+ }
+
+ /**
+ * Logs an internal error with the specified throwable
+ *
+ * @param e
+ * the exception to be logged
+ */
+ public static void log(Throwable e) {
+ log(new Status(IStatus.ERROR, PLUGIN_ID, 1, "Internal Error", e)); //$NON-NLS-1$
+ }
+
+ /**
+ * Logs an internal error with the specified message.
+ *
+ * @param message
+ * the error message to log
+ */
+ public static void log(String message) {
+ log(new Status(IStatus.ERROR, PLUGIN_ID, 1, message, null));
+ }
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanPreferencesLoader.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanPreferencesLoader.java
new file mode 100644
index 0000000..6fd6318
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanPreferencesLoader.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * 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;
+
+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.cdt.codan.internal.core.model.CodanProblem;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+
+/**
+ * @author Alena
+ *
+ */
+public class CodanPreferencesLoader {
+ private IProblemProfile baseModel;
+
+ /**
+ * @param workspaceProfile
+ */
+ public CodanPreferencesLoader(IProblemProfile profile) {
+ setInput(profile);
+ }
+
+ /**
+ *
+ */
+ public CodanPreferencesLoader() {
+ }
+
+ public void setInput(Object model) {
+ baseModel = (IProblemProfile) model;
+ }
+
+ /**
+ * @return
+ */
+ public IProblem[] getProblems() {
+ IProblem[] problems = baseModel.getProblems();
+ return problems;
+ }
+
+ /**
+ * @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(sevs);
+ } catch (RuntimeException e) {
+ sev = CodanSeverity.Warning;
+ }
+ ((CodanProblem) prob).setSeverity(sev);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return getInput().toString();
+ }
+
+ /**
+ * @return
+ */
+ public IProblemProfile getInput() {
+ return baseModel;
+ }
+
+ /**
+ * @param id
+ * @return
+ */
+ 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);
+ }
+ }
+ }
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanRuntime.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanRuntime.java
new file mode 100644
index 0000000..16375cf
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanRuntime.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * 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;
+
+import org.eclipse.cdt.codan.core.model.ICheckersRegistry;
+import org.eclipse.cdt.codan.core.model.ICodanAstReconciler;
+import org.eclipse.cdt.codan.core.model.ICodanBuilder;
+import org.eclipse.cdt.codan.core.model.IProblemReporter;
+import org.eclipse.cdt.codan.internal.core.CheckersRegisry;
+import org.eclipse.cdt.codan.internal.core.CodanBuilder;
+import org.eclipse.cdt.codan.internal.core.model.CodanMarkerProblemReporter;
+
+/**
+ * Runtime singleton class to get access to Codan framework parts
+ *
+ */
+public class CodanRuntime {
+ private static CodanRuntime instance = new CodanRuntime();
+ private IProblemReporter problemReporter = new CodanMarkerProblemReporter();
+ private CodanBuilder builder = new CodanBuilder();
+ private CheckersRegisry checkers = CheckersRegisry.getInstance();
+
+ public IProblemReporter getProblemReporter() {
+ return problemReporter;
+ }
+
+ public void setProblemReporter(IProblemReporter reporter) {
+ problemReporter = reporter;
+ }
+
+ public static CodanRuntime getInstance() {
+ return instance;
+ }
+
+ public ICodanBuilder getBuilder() {
+ return builder;
+ }
+
+ public ICodanAstReconciler getAstQuickBuilder() {
+ return builder;
+ }
+
+ public ICheckersRegistry getChechersRegistry() {
+ return checkers;
+ }
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/PreferenceConstants.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/PreferenceConstants.java
new file mode 100644
index 0000000..a4a1374
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/PreferenceConstants.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * 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";
+ public static final String P_USE_PARENT = "useParentScope";
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractChecker.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractChecker.java
new file mode 100644
index 0000000..f1e5028
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractChecker.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * 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 org.eclipse.cdt.codan.core.CodanRuntime;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+
+public abstract class AbstractChecker implements IChecker {
+ protected String name;
+
+ public AbstractChecker() {
+ }
+
+ /**
+ * @return true if checker is enabled in context of resource, if returns
+ * false checker's "processResource" method won't be called
+ */
+ public boolean enabledInContext(IResource res) {
+ return true;
+ }
+
+ /**
+ * Reports a simple problem for given file and line
+ *
+ * @param id
+ * - problem id
+ * @param file
+ * - file
+ * @param lineNumber
+ * - line
+ * @param arg
+ * - problem argument, if problem does not define error message
+ * it will be error message (not recommended because of
+ * internationalization)
+ */
+ public void reportProblem(String id, IFile file, int lineNumber, String arg) {
+ getProblemReporter().reportProblem(id,
+ new ProblemLocation(file, lineNumber), arg);
+ }
+
+ /**
+ * Reports a simple problem for given file and line, error message comes
+ * from problem definition
+ *
+ * @param id
+ * - problem id
+ * @param file
+ * - file
+ * @param lineNumber
+ * - line
+ */
+ public void reportProblem(String id, IFile file, int lineNumber) {
+ getProblemReporter().reportProblem(id,
+ new ProblemLocation(file, lineNumber), new Object[] {});
+ }
+
+ /**
+ * @return problem reporter for given checker
+ */
+ protected IProblemReporter getProblemReporter() {
+ return CodanRuntime.getInstance().getProblemReporter();
+ }
+
+ public boolean runInEditor() {
+ return false;
+ }
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractIndexAstChecker.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractIndexAstChecker.java
new file mode 100644
index 0000000..2c87b07
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractIndexAstChecker.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * 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 org.eclipse.cdt.codan.core.CodanCorePlugin;
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+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;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+/**
+ * @author Alena
+ *
+ */
+public abstract class AbstractIndexAstChecker extends AbstractChecker implements
+ ICAstChecker {
+ private IFile file;
+
+ protected IFile getFile() {
+ return file;
+ }
+
+ void processFile(IFile file) throws CoreException, InterruptedException {
+ // create translation unit and access index
+ 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());
+ // lock the index for read access
+ index.acquireReadLock();
+ try {
+ // create index based ast
+ IASTTranslationUnit ast = tu.getAST(index,
+ ITranslationUnit.AST_SKIP_INDEXED_HEADERS);
+ // traverse the ast using the visitor pattern.
+ this.file = file;
+ processAst(ast);
+ } finally {
+ this.file = null;
+ index.releaseReadLock();
+ }
+ }
+
+ public boolean processResource(IResource resource) {
+ if (resource instanceof IFile) {
+ IFile file = (IFile) resource;
+ try {
+ processFile(file);
+ } catch (CoreException e) {
+ CodanCorePlugin.log(e);
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ return false;
+ }
+ return true;
+ }
+
+ public void reportProblem(String id, IASTNode astNode, String message) {
+ IASTFileLocation astLocation = astNode.getFileLocation();
+ IPath location = new Path(astLocation.getFileName());
+ IFile astFile = ResourcesPlugin.getWorkspace().getRoot()
+ .getFileForLocation(location);
+ if (astFile == null) {
+ astFile = file;
+ }
+ getProblemReporter().reportProblem(
+ id,
+ new ProblemLocation(astFile, astLocation
+ .getStartingLineNumber()), message);
+ }
+
+ public boolean runInEditor() {
+ return true;
+ }
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Entries b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Entries
new file mode 100644
index 0000000..9043127
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Entries
@@ -0,0 +1,16 @@
+/AbstractChecker.java/1.4/Sat Aug 22 21:31:29 2009//
+/AbstractIndexAstChecker.java/1.5/Sat Aug 22 21:31:29 2009//
+/CodanSeverity.java/1.2/Wed Apr 22 01:26:56 2009//
+/ICAstChecker.java/1.1/Thu Apr 9 12:46:50 2009//
+/IChecker.java/1.2/Sat Aug 22 21:31:29 2009//
+/ICheckersRegistry.java/1.1/Sat Aug 22 21:16:48 2009//
+/ICodanAstReconciler.java/1.1/Sat Aug 22 21:16:48 2009//
+/ICodanBuilder.java/1.1/Sat Aug 22 21:16:48 2009//
+/IProblem.java/1.3/Sat Aug 22 21:16:48 2009//
+/IProblemCategory.java/1.2/Thu Apr 16 01:46:57 2009//
+/IProblemElement.java/1.1/Thu Apr 16 01:46:57 2009//
+/IProblemLocation.java/1.1/Sat Aug 22 21:16:48 2009//
+/IProblemProfile.java/1.3/Sat May 9 01:54:38 2009//
+/IProblemReporter.java/1.1/Sat Aug 22 21:16:48 2009//
+/ProblemLocation.java/1.1/Sat Aug 22 21:16:48 2009//
+/ProblemProfile.java/1.4/Sat Aug 22 21:16:48 2009//
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Repository b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Repository
new file mode 100644
index 0000000..48894f7
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Repository
@@ -0,0 +1 @@
+org.eclipse.cdt/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Root b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Root
new file mode 100644
index 0000000..04efa23
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Root
@@ -0,0 +1 @@
+:pserver:anonymous@dev.eclipse.org:/cvsroot/tools
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanSeverity.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanSeverity.java
new file mode 100644
index 0000000..acfa4d1
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanSeverity.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * 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 org.eclipse.core.resources.IMarker;
+
+public enum CodanSeverity {
+ Info(IMarker.SEVERITY_INFO), Warning(IMarker.SEVERITY_WARNING), Error(
+ IMarker.SEVERITY_ERROR);
+ private int value;
+
+ private CodanSeverity(int value) {
+ this.value = value;
+ }
+
+ public int intValue() {
+ return value;
+ }
+
+ /**
+ * @return
+ */
+ public static String[] stringValues() {
+ CodanSeverity[] values = values();
+ String[] svalues = new String[values.length];
+ for (int i = 0; i < values.length; i++) {
+ CodanSeverity sev = values[i];
+ svalues[i] = sev.toString();
+ }
+ return svalues;
+ }
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICAstChecker.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICAstChecker.java
new file mode 100644
index 0000000..461c0fa
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICAstChecker.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * 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 org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+
+/**
+ * @author Alena
+ *
+ */
+public interface ICAstChecker extends IChecker {
+ void processAst(IASTTranslationUnit ast);
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IChecker.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IChecker.java
new file mode 100644
index 0000000..4f995db
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IChecker.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * 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 org.eclipse.core.resources.IResource;
+
+public interface IChecker {
+ public boolean processResource(IResource resource);
+
+ boolean enabledInContext(IResource resource);
+
+ /**
+ * Checker must implement this method to determine if it can run in editor
+ * "as you type", checker must be really light weight to run in this mode
+ *
+ * @return true if need to be run in editor as user types, and false
+ * otherwise
+ */
+ boolean runInEditor();
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICheckersRegistry.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICheckersRegistry.java
new file mode 100644
index 0000000..052d868
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICheckersRegistry.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * 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.Iterator;
+
+import org.eclipse.core.resources.IResource;
+
+/**
+ * @author Alena
+ *
+ */
+public interface ICheckersRegistry {
+ public abstract Iterator<IChecker> iterator();
+
+ public abstract void addChecker(IChecker checker);
+
+ public abstract void addProblem(IProblem p, String category);
+
+ public abstract void addCategory(IProblemCategory p, String category);
+
+ public abstract void addRefProblem(IChecker c, IProblem p);
+
+ /**
+ * @return
+ */
+ public abstract IProblemProfile getDefaultProfile();
+
+ /**
+ * @return
+ */
+ public abstract IProblemProfile getWorkspaceProfile();
+
+ /**
+ * @param element
+ * @return
+ */
+ public abstract IProblemProfile getResourceProfile(IResource element);
+
+ /**
+ * @param element
+ * @return
+ */
+ public abstract IProblemProfile getResourceProfileWorkingCopy(
+ IResource element);
+
+ /**
+ * Set profile for resource. This method is called by UI, and should not be
+ * called by clients directly
+ *
+ * @param resource
+ * - resource
+ * @param profile
+ * - problems profile
+ */
+ public abstract void updateProfile(IResource resource,
+ IProblemProfile profile);
+} \ No newline at end of file
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICodanAstReconciler.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICodanAstReconciler.java
new file mode 100644
index 0000000..17bc8f7
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICodanAstReconciler.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * 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 org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * @author Alena
+ *
+ */
+public interface ICodanAstReconciler {
+ public void reconcileAst(IASTTranslationUnit ast, IProgressMonitor monitor);
+} \ No newline at end of file
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICodanBuilder.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICodanBuilder.java
new file mode 100644
index 0000000..ce1f668
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICodanBuilder.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * 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 org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * @author Alena
+ *
+ */
+public interface ICodanBuilder {
+ public void processResource(IResource resource, IProgressMonitor monitor);
+} \ No newline at end of file
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblem.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblem.java
new file mode 100644
index 0000000..52cfff2
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblem.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * 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.Collection;
+
+public interface IProblem extends IProblemElement {
+ String getName();
+
+ String getId();
+
+ boolean isEnabled();
+
+ CodanSeverity getSeverity();
+
+ String getMessagePattern();
+
+ void setSeverity(CodanSeverity sev);
+
+ void setEnabled(boolean checked);
+
+ void setMessagePattern(String message);
+
+ public void setProperty(Object key, Object value);
+
+ public Object getProperty(Object key);
+
+ public Collection<Object> getPropertyKeys();
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemCategory.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemCategory.java
new file mode 100644
index 0000000..45a62a0
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemCategory.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * 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;
+
+public interface IProblemCategory extends IProblemElement {
+ String getName();
+
+ String getId();
+
+ Object[] getChildren();
+
+ /**
+ * @param id
+ * @return
+ */
+ IProblem findProblem(String id);
+
+ /**
+ * @param id
+ * @return
+ */
+ IProblemCategory findCategory(String id);
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemElement.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemElement.java
new file mode 100644
index 0000000..b9f7fb8
--- /dev/null
+++ b/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/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemLocation.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemLocation.java
new file mode 100644
index 0000000..f5e4f23
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemLocation.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * 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 org.eclipse.core.resources.IFile;
+
+/**
+ * Interface to describe problem location. Usually contains file and linenumber,
+ * also supports character positions for sophisticated errors.
+ *
+ */
+public interface IProblemLocation {
+ /**
+ *
+ * @return File for the problem - absolute full paths
+ */
+ IFile getFile();
+
+ /**
+ *
+ * @return Primary line for the problem, lines start with 1 for file. If -1
+ * char position would be used.
+ */
+ int getLineNumber();
+
+ /**
+ *
+ * @return character position where problem starts within file, first char
+ * is 0, inclusive, tab count as one. If unknown return -1.
+ */
+ int getStartingChar();
+
+ /**
+ *
+ * @return character position where problem ends within file, first char is
+ * 0, exclusive, tab count as one. If unknown return -1.
+ */
+ int getEndingChar();
+
+ /**
+ *
+ * @return extra data for problem location, checker specific, can be
+ * backtrace for example
+ */
+ Object getData();
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemProfile.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemProfile.java
new file mode 100644
index 0000000..9dc465e
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemProfile.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Problem Profile contains tree of categories and problems. Profiles can have
+ * different categories and different problems set, problems with the same id
+ * can have different severities/enablement in different profiles. To obtain
+ * profile use class {@link CheckersRegisry#getResourceProfile,
+ * CheckersRegisry#getDefaultProfile() or CheckersRegisry#getWorkspaceProfile()}
+ * .
+ *
+ */
+public interface IProblemProfile extends IProblemElement {
+ /**
+ * @return root category in profile
+ */
+ IProblemCategory getRoot();
+
+ /**
+ * Find and return problem by id
+ *
+ * @param id
+ * - problem id
+ * @return problem instance
+ */
+ IProblem findProblem(String id);
+
+ /**
+ * Find and return category by id
+ *
+ * @param id
+ * - category id
+ * @return category instance
+ */
+ IProblemCategory findCategory(String id);
+
+ /**
+ * Get all defined problems
+ *
+ * @return array of problems defined in profile
+ */
+ IProblem[] getProblems();
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemReporter.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemReporter.java
new file mode 100644
index 0000000..814cc40
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemReporter.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * 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;
+
+
+/**
+ * IProblemReporter - interface to report problems
+ *
+ */
+public interface IProblemReporter {
+ /**
+ * Report a problem with "problemId" id on location determined by "loc",
+ * using problem specific error message customised by args.
+ * @param problemId - id of the problem registers with checker
+ * @param loc - location object
+ * @param args - custom args, can be null, in this case default message is reported
+ */
+ public void reportProblem(String problemId, IProblemLocation loc,
+ Object ... args);
+} \ No newline at end of file
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ProblemLocation.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ProblemLocation.java
new file mode 100644
index 0000000..ced12f0
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ProblemLocation.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * 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 org.eclipse.core.resources.IFile;
+
+/**
+ * Implementation of IProblemLocation
+ *
+ */
+public class ProblemLocation implements IProblemLocation {
+ protected IFile file;
+ protected int line;
+ protected int posStart;
+ protected int posEnd;
+ protected Object extra;
+
+ /**
+ * @param file
+ * @param line
+ * @param lineEnd
+ * @param posStart
+ * @param posEnd
+ */
+ public ProblemLocation(IFile file, int line) {
+ this.file = file;
+ this.line = line;
+ this.posStart = -1;
+ this.posEnd = -1;
+ }
+
+ /**
+ * @param file
+ * @param startingLineNumber
+ * @param endingLineNumber
+ */
+ public ProblemLocation(IFile file, int startChar, int endChar) {
+ this.file = file;
+ this.line = -1;
+ this.posStart = startChar;
+ this.posEnd = endChar;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.codan.core.model.IProblemLocation#getData()
+ */
+ public Object getData() {
+ return extra;
+ }
+
+ public void setData(Object data) {
+ this.extra = data;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.codan.core.model.IProblemLocation#getFile()
+ */
+ public IFile getFile() {
+ return file;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.codan.core.model.IProblemLocation#getLine()
+ */
+ public int getLineNumber() {
+ return getStartingLineNumber();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.codan.core.model.IProblemLocation#getStartLine()
+ */
+ public int getStartingLineNumber() {
+ return line;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.codan.core.model.IProblemLocation#getStartPos()
+ */
+ public int getStartingChar() {
+ return posStart;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.codan.core.model.IProblemLocation#getEndingChar()
+ */
+ public int getEndingChar() {
+ return posEnd;
+ }
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ProblemProfile.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ProblemProfile.java
new file mode 100644
index 0000000..ae90e76
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ProblemProfile.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * 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;
+
+import org.eclipse.cdt.codan.internal.core.model.CodanProblemCategory;
+
+/**
+ * @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);
+ }
+}