Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/codan
diff options
context:
space:
mode:
authorAlena Laskavaia2009-04-09 12:48:44 +0000
committerAlena Laskavaia2009-04-09 12:48:44 +0000
commit26460663849b0b09ee3f642691d8f90b9f8f9834 (patch)
tree2684107e7865337d81c7f002527e164fab8a4485 /codan
parent724390a35fbce63e3a2a6e4ae6457b64e26b3284 (diff)
downloadorg.eclipse.cdt-26460663849b0b09ee3f642691d8f90b9f8f9834.tar.gz
org.eclipse.cdt-26460663849b0b09ee3f642691d8f90b9f8f9834.tar.xz
org.eclipse.cdt-26460663849b0b09ee3f642691d8f90b9f8f9834.zip
initial commit
Diffstat (limited to 'codan')
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/.classpath7
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/.project28
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/META-INF/MANIFEST.MF13
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/build.properties5
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/plugin.xml19
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/Activator.java50
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/AssignmentInConditionChecker.java62
-rw-r--r--codan/org.eclipse.cdt.codan.core/.classpath7
-rw-r--r--codan/org.eclipse.cdt.codan.core/.project28
-rw-r--r--codan/org.eclipse.cdt.codan.core/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--codan/org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF15
-rw-r--r--codan/org.eclipse.cdt.codan.core/build.properties6
-rw-r--r--codan/org.eclipse.cdt.codan.core/plugin.xml47
-rw-r--r--codan/org.eclipse.cdt.codan.core/schema/checkers.exsd246
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java83
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodanBuilder.java120
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodeAnlysisNature.java88
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractChecker.java30
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractIndexAstChecker.java70
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CheckersRegisry.java183
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanProblem.java59
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanProblemCategory.java52
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanSeverity.java27
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ErrorReporter.java68
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICAstChecker.java21
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IChecker.java19
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblem.java24
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemCategory.java21
29 files changed, 1414 insertions, 0 deletions
diff --git a/codan/org.eclipse.cdt.codan.checkers/.classpath b/codan/org.eclipse.cdt.codan.checkers/.classpath
new file mode 100644
index 00000000000..ad32c83a788
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.checkers/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/codan/org.eclipse.cdt.codan.checkers/.project b/codan/org.eclipse.cdt.codan.checkers/.project
new file mode 100644
index 00000000000..6b76138faa3
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.checkers/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.cdt.codan.checkers</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/codan/org.eclipse.cdt.codan.checkers/.settings/org.eclipse.jdt.core.prefs b/codan/org.eclipse.cdt.codan.checkers/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..4e9c2546d9a
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.checkers/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Sun Apr 05 18:00:01 EDT 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/codan/org.eclipse.cdt.codan.checkers/META-INF/MANIFEST.MF b/codan/org.eclipse.cdt.codan.checkers/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..7e6aaf9f39a
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.checkers/META-INF/MANIFEST.MF
@@ -0,0 +1,13 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Checkers
+Bundle-SymbolicName: org.eclipse.cdt.codan.checkers;singleton:=true
+Bundle-Version: 1.0.0
+Bundle-Activator: org.eclipse.cdt.codan.checkers.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.core.resources;bundle-version="3.5.0",
+ org.eclipse.cdt.core;bundle-version="5.1.0",
+ org.eclipse.cdt.codan.core;bundle-version="1.0.0"
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
diff --git a/codan/org.eclipse.cdt.codan.checkers/build.properties b/codan/org.eclipse.cdt.codan.checkers/build.properties
new file mode 100644
index 00000000000..e9863e281ea
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.checkers/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/codan/org.eclipse.cdt.codan.checkers/plugin.xml b/codan/org.eclipse.cdt.codan.checkers/plugin.xml
new file mode 100644
index 00000000000..99cf3432354
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.checkers/plugin.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.cdt.codan.core.checkers">
+
+ <checker
+ class="org.eclipse.cdt.codan.checkers.sample.AssignmentInConditionChecker"
+ id="org.eclipse.cdt.codan.checkers.checker1"
+ name="Assignment in condition">
+ <problem
+ defaultSeverity="Warning"
+ id="org.eclipse.cdt.codan.checkers.sample.assignment_in_condition"
+ name="Assignment in condition">
+ </problem>
+ </checker>
+ </extension>
+
+</plugin>
diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/Activator.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/Activator.java
new file mode 100644
index 00000000000..72e751f25d1
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/Activator.java
@@ -0,0 +1,50 @@
+package org.eclipse.cdt.codan.checkers;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.cdt.codan.checkers";
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#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 Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/AssignmentInConditionChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/AssignmentInConditionChecker.java
new file mode 100644
index 00000000000..69fc3d6638b
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/AssignmentInConditionChecker.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * 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.checkers.sample;
+
+import org.eclipse.cdt.codan.core.model.AbstractIndexAstChecker;
+import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
+import org.eclipse.cdt.core.dom.ast.ASTVisitor;
+import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTForStatement;
+import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+
+public class AssignmentInConditionChecker extends AbstractIndexAstChecker {
+ private static final String ER_ID = "org.eclipse.cdt.codan.checkers.sample.assignment_in_condition";
+
+ @Override
+ public void processAst(IASTTranslationUnit ast) {
+ // traverse the ast using the visitor pattern.
+ ast.accept(new CheckCodeVisitor());
+ }
+
+ class CheckCodeVisitor extends ASTVisitor {
+ CheckCodeVisitor() {
+ shouldVisitExpressions = true;
+ }
+
+ public int visit(IASTExpression expression) {
+ if (isAssignmentExpression(expression)
+ && isUsedAsCondition(expression)) {
+ reportProblem(ER_ID, getFile(), expression.getFileLocation()
+ .getStartingLineNumber(),
+ "Possible assignment in condition");
+ }
+ return PROCESS_CONTINUE;
+ }
+
+ private boolean isAssignmentExpression(IASTExpression e) {
+ if (e instanceof IASTBinaryExpression) {
+ IASTBinaryExpression binExpr = (IASTBinaryExpression) e;
+ return binExpr.getOperator() == IASTBinaryExpression.op_assign;
+ }
+ return false;
+ }
+
+ private boolean isUsedAsCondition(IASTExpression expression) {
+ ASTNodeProperty prop = expression.getPropertyInParent();
+ if (prop == IASTForStatement.CONDITION
+ || prop == IASTIfStatement.CONDITION)
+ return true;
+ return false;
+ }
+ }
+}
diff --git a/codan/org.eclipse.cdt.codan.core/.classpath b/codan/org.eclipse.cdt.codan.core/.classpath
new file mode 100644
index 00000000000..ad32c83a788
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/codan/org.eclipse.cdt.codan.core/.project b/codan/org.eclipse.cdt.codan.core/.project
new file mode 100644
index 00000000000..8ba33e61574
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.cdt.codan.core</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/codan/org.eclipse.cdt.codan.core/.settings/org.eclipse.jdt.core.prefs b/codan/org.eclipse.cdt.codan.core/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..1c23d3d40c6
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Tue Apr 07 21:22:12 EDT 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/codan/org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF b/codan/org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..520827b6981
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF
@@ -0,0 +1,15 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Code Analisys Core
+Bundle-SymbolicName: org.eclipse.cdt.codan.core;singleton:=true
+Bundle-Version: 1.0.0
+Bundle-Activator: org.eclipse.cdt.codan.core.CodanCorePlugin
+Bundle-Vendor: CDT
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.core.resources,
+ org.eclipse.cdt.core
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ActivationPolicy: lazy
+Export-Package: org.eclipse.cdt.codan.core,
+ org.eclipse.cdt.codan.core.builder,
+ org.eclipse.cdt.codan.core.model
diff --git a/codan/org.eclipse.cdt.codan.core/build.properties b/codan/org.eclipse.cdt.codan.core/build.properties
new file mode 100644
index 00000000000..3595411e85a
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/build.properties
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ schema/
diff --git a/codan/org.eclipse.cdt.codan.core/plugin.xml b/codan/org.eclipse.cdt.codan.core/plugin.xml
new file mode 100644
index 00000000000..954c0210f13
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/plugin.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension-point id="checkers" name="Code Analysis Checkers" schema="schema/checkers.exsd"/>
+
+ <extension
+ id="codanBuilder"
+ name="Code Analysis Project Builder"
+ point="org.eclipse.core.resources.builders">
+ <builder
+ hasNature="true">
+ <run
+ class="org.eclipse.cdt.codan.core.builder.CodanBuilder">
+ </run>
+ </builder>
+ </extension>
+ <extension
+ id="codanNature"
+ name="CDT Code Analysis Nature"
+ point="org.eclipse.core.resources.natures">
+ <runtime>
+ <run
+ class="org.eclipse.cdt.codan.core.builder.CodeAnlysisNature">
+ </run>
+ </runtime>
+ <builder
+ id="org.eclipse.cdt.codan.core.codanBuilder">
+ </builder>
+ </extension>
+ <extension
+ id="codanProblem"
+ name="Code Analisys Problem"
+ point="org.eclipse.core.resources.markers">
+ <super
+ type="org.eclipse.core.resources.problemmarker">
+ </super>
+ <persistent
+ value="true">
+ </persistent>
+ </extension>
+ <extension
+ point="org.eclipse.core.runtime.preferences">
+ </extension>
+
+
+
+</plugin>
diff --git a/codan/org.eclipse.cdt.codan.core/schema/checkers.exsd b/codan/org.eclipse.cdt.codan.core/schema/checkers.exsd
new file mode 100644
index 00000000000..71808a5bfa0
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/schema/checkers.exsd
@@ -0,0 +1,246 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.cdt.codan.ui" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.cdt.codan.ui" id="checkers" name="Code Analysis Checkers"/>
+ </appinfo>
+ <documentation>
+ Define chckers for Code Analysis framework.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence minOccurs="1" maxOccurs="unbounded">
+ <choice>
+ <element ref="checker"/>
+ <element ref="category"/>
+ </choice>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="checker">
+ <annotation>
+ <documentation>
+ Checker Element. Sets id, name and class that implements checker
+ </documentation>
+ </annotation>
+ <complexType>
+ <sequence minOccurs="0" maxOccurs="unbounded">
+ <choice>
+ <element ref="problem"/>
+ </choice>
+ </sequence>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+ Checker id.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+ Checker class. Must implement IChecker.
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.cdt.codan.core.model.IChecker"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+ User Friendly name of the chcker or error. Would be display to enable/disable an error.
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="problem">
+ <annotation>
+ <documentation>
+ Problem description (Error, Warning, Info produced by a checker)
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+ Error id. Should be prefixed by plugin name in general.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+ User Friendly name of the error. Would be display to enable/disable an error.
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="defaultSeverity" use="default" value="Warning">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ <simpleType>
+ <restriction base="string">
+ <enumeration value="Error">
+ </enumeration>
+ <enumeration value="Warning">
+ </enumeration>
+ <enumeration value="Info">
+ </enumeration>
+ </restriction>
+ </simpleType>
+ </attribute>
+ <attribute name="category" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="identifier" basedOn="org.eclipse.cdt.codan.core.checkers/category/@id"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="category">
+ <complexType>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="parentCategory" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="identifier" basedOn="org.eclipse.cdt.codan.core.checkers/category/@id"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ 1.0
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ The following is an example of a single checker definition:
+&lt;p&gt;
+&lt;pre&gt;
+ &lt;extension
+ point=&quot;org.eclipse.cdt.codan.ui.checkers&quot;&gt;
+ &lt;checker
+ class=&quot;org.aaa.AssignmentInConditionChecker&quot;
+ id=&quot;org.aaa.AssignmentInConditionChecker&quot;
+ name=&quot;Possible Assignment in Condition instead of comparision&quot;&gt;
+ &lt;/checker&gt;
+ &lt;/extension&gt;
+&lt;/pre&gt;
+&lt;/p&gt;
+The following is an example of a checker that produces two types of errors:
+&lt;p&gt;
+&lt;pre&gt;
+ &lt;extension
+ point=&quot;org.eclipse.cdt.codan.ui.checkers&quot;&gt;
+
+ &lt;checker
+ class=&quot;org.aaa.NullPointerDereferenceChecker&quot;
+ id=&quot;org.aaa.NullPointerDereferenceChecker&quot;
+ name=&quot;Null Pointer Dereference checker&quot;&gt;
+ &lt;problem id=&quot;org.aaa.npe_must&quot; name=&quot;Null Pointer Dereference&quot;/ defaultSeverity=&quot;Error&quot;&gt;
+ &lt;problem id=&quot;org.aaa.npe_may&quot; name=&quot;Possible Null Pointer Dereference&quot;/&gt;
+ &lt;/checker&gt;
+ &lt;/extension&gt;
+&lt;/pre&gt;
+&lt;/p&gt;
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiinfo"/>
+ </appinfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="implementation"/>
+ </appinfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
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
new file mode 100644
index 00000000000..1810762e144
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java
@@ -0,0 +1,83 @@
+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.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";
+ // The shared instance
+ private static CodanCorePlugin plugin;
+
+ /**
+ * The constructor
+ */
+ public CodanCorePlugin() {
+ }
+
+ /*
+ * (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/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodanBuilder.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodanBuilder.java
new file mode 100644
index 00000000000..045ad426fca
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodanBuilder.java
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * 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.Map;
+
+import org.eclipse.cdt.codan.core.CodanCorePlugin;
+import org.eclipse.cdt.codan.core.model.CheckersRegisry;
+import org.eclipse.cdt.codan.core.model.ErrorReporter;
+import org.eclipse.cdt.codan.core.model.IChecker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
+import org.eclipse.core.resources.IResourceVisitor;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+public class CodanBuilder extends IncrementalProjectBuilder {
+ public static final String BUILDER_ID = "org.eclipse.cdt.codan.core.codanBuilder";
+
+ public class CodanDeltaVisitor implements IResourceDeltaVisitor {
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse
+ * .core.resources.IResourceDelta)
+ */
+ public boolean visit(IResourceDelta delta) throws CoreException {
+ IResource resource = delta.getResource();
+ switch (delta.getKind()) {
+ case IResourceDelta.ADDED:
+ // handle added resource
+ processResource(resource);
+ break;
+ case IResourceDelta.REMOVED:
+ // handle removed resource
+ break;
+ case IResourceDelta.CHANGED:
+ // handle changed resource
+ processResource(resource);
+ break;
+ }
+ // return true to continue visiting children.
+ return true;
+ }
+ }
+
+ public class CodanResourceVisitor implements IResourceVisitor {
+ public boolean visit(IResource resource) {
+ processResource(resource);
+ // return true to continue visiting children.
+ return true;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.internal.events.InternalBuilder#build(int,
+ * java.util.Map, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected IProject[] build(int kind, Map args, IProgressMonitor monitor)
+ throws CoreException {
+ if (kind == FULL_BUILD) {
+ fullBuild(monitor);
+ } else {
+ IResourceDelta delta = getDelta(getProject());
+ if (delta == null) {
+ fullBuild(monitor);
+ } else {
+ incrementalBuild(delta, monitor);
+ }
+ }
+ return null;
+ }
+
+ public void processResource(IResource resource) {
+ // String string = Platform.getPreferencesService().getString(
+ // CodanCorePlugin.PLUGIN_ID, "problems", "", null);
+ // System.err.println("set = " + string);
+ // delete general markers
+ ErrorReporter.deleteMarkers(resource);
+ for (IChecker checker : CheckersRegisry.getInstance()) {
+ try {
+ boolean run = false;
+ if (checker.enabledInContext(resource))
+ run = true;
+ if (run)
+ checker.processResource(resource);
+ } catch (Throwable e) {
+ CodanCorePlugin.log(e);
+ }
+ }
+ }
+
+ protected void fullBuild(final IProgressMonitor monitor)
+ throws CoreException {
+ try {
+ getProject().accept(new CodanResourceVisitor());
+ } catch (CoreException e) {
+ }
+ }
+
+ protected void incrementalBuild(IResourceDelta delta,
+ IProgressMonitor monitor) throws CoreException {
+ // the visitor does the work.
+ delta.accept(new CodanDeltaVisitor());
+ }
+}
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodeAnlysisNature.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodeAnlysisNature.java
new file mode 100644
index 00000000000..4f06e716c36
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/builder/CodeAnlysisNature.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * 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 org.eclipse.core.resources.ICommand;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IProjectNature;
+import org.eclipse.core.runtime.CoreException;
+
+public class CodeAnlysisNature implements IProjectNature {
+ /**
+ * ID of this project nature
+ */
+ public static final String NATURE_ID = "org.eclipse.cdt.codan.core.codanNature";
+ private IProject project;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.resources.IProjectNature#configure()
+ */
+ public void configure() throws CoreException {
+ IProjectDescription desc = project.getDescription();
+ ICommand[] commands = desc.getBuildSpec();
+ for (int i = 0; i < commands.length; ++i) {
+ if (commands[i].getBuilderName().equals(CodanBuilder.BUILDER_ID)) {
+ return;
+ }
+ }
+ ICommand[] newCommands = new ICommand[commands.length + 1];
+ System.arraycopy(commands, 0, newCommands, 0, commands.length);
+ ICommand command = desc.newCommand();
+ command.setBuilderName(CodanBuilder.BUILDER_ID);
+ newCommands[newCommands.length - 1] = command;
+ desc.setBuildSpec(newCommands);
+ project.setDescription(desc, null);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.resources.IProjectNature#deconfigure()
+ */
+ public void deconfigure() throws CoreException {
+ IProjectDescription description = getProject().getDescription();
+ ICommand[] commands = description.getBuildSpec();
+ for (int i = 0; i < commands.length; ++i) {
+ if (commands[i].getBuilderName().equals(CodanBuilder.BUILDER_ID)) {
+ ICommand[] newCommands = new ICommand[commands.length - 1];
+ System.arraycopy(commands, 0, newCommands, 0, i);
+ System.arraycopy(commands, i + 1, newCommands, i,
+ commands.length - i - 1);
+ description.setBuildSpec(newCommands);
+ project.setDescription(description, null);
+ return;
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.resources.IProjectNature#getProject()
+ */
+ public IProject getProject() {
+ return project;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core
+ * .resources.IProject)
+ */
+ public void setProject(IProject project) {
+ this.project = project;
+ }
+}
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractChecker.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractChecker.java
new file mode 100644
index 00000000000..e56437dc65e
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractChecker.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * 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;
+import org.eclipse.core.resources.IResource;
+
+public abstract class AbstractChecker implements IChecker {
+ String name;
+
+ public AbstractChecker() {
+ }
+
+ public boolean enabledInContext(IResource res) {
+ return true;
+ }
+
+ public void reportProblem(String id, IFile file, int lineNumber,
+ String message) {
+ ErrorReporter.reportProblem(id, file, lineNumber, message);
+ }
+}
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
new file mode 100644
index 00000000000..5b6855784f4
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractIndexAstChecker.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * 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.IASTTranslationUnit;
+import org.eclipse.cdt.core.index.IIndex;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * @author Alena
+ *
+ */
+public abstract class AbstractIndexAstChecker extends AbstractChecker implements
+ ICAstChecker {
+ private IFile file;
+
+ public IFile getFile() {
+ return file;
+ }
+
+ void processFile(IFile file) throws CoreException, InterruptedException {
+ this.file = file;
+ // create translation unit and access index
+ ITranslationUnit tu = (ITranslationUnit) CoreModel.getDefault().create(
+ file);
+ 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.
+ processAst(ast);
+ } finally {
+ 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;
+ }
+}
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
new file mode 100644
index 00000000000..d2dd4975b46
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CheckersRegisry.java
@@ -0,0 +1,183 @@
+/*******************************************************************************
+ * 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 java.util.Iterator;
+
+import org.eclipse.cdt.codan.core.CodanCorePlugin;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.Platform;
+
+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 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 CheckersRegisry() {
+ instance = this;
+ readCheckersRegistry();
+ }
+
+ private void readCheckersRegistry() {
+ IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint(
+ CodanCorePlugin.PLUGIN_ID, EXTENSION_POINT_NAME);
+ if (ep == null)
+ return;
+ IConfigurationElement[] elements = ep.getConfigurationElements();
+ // process categories
+ // process shared problems
+ for (int i = 0; i < elements.length; i++) {
+ IConfigurationElement configurationElement = elements[i];
+ processProblem(configurationElement);
+ }
+ // process checkers
+ for (int i = 0; i < elements.length; i++) {
+ IConfigurationElement configurationElement = elements[i];
+ processChecker(configurationElement);
+ }
+ }
+
+ /**
+ * @param configurationElement
+ */
+ private void processChecker(IConfigurationElement configurationElement) {
+ try {
+ if (configurationElement.getName().equals(CHECKER_ELEMENT)) {
+ String id = getAtt(configurationElement, "id");
+ if (id == null)
+ return;
+ String name = getAtt(configurationElement, "name", false);
+ if (name == null)
+ name = id;
+ IChecker checkerObj = null;
+ try {
+ Object checker = configurationElement
+ .createExecutableExtension("class");
+ checkerObj = (IChecker) checker;
+ addChecker(checkerObj);
+ } catch (CoreException e) {
+ CodanCorePlugin.log(e);
+ return;
+ }
+ IConfigurationElement[] children1 = configurationElement
+ .getChildren("problemRef");
+ boolean hasRef = false;
+ IConfigurationElement[] children2 = configurationElement
+ .getChildren(PROBLEM_ELEMENT);
+ if (children2 != null) {
+ for (IConfigurationElement ref : children2) {
+ IProblem p = processProblem(ref);
+ addRefProblem(checkerObj, p);
+ hasRef = true;
+ }
+ }
+ if (children1 != null) {
+ for (IConfigurationElement ref : children1) {
+ hasRef = true;
+ IProblem p = getProblemById(ref.getAttribute("refId"),
+ null);
+ addRefProblem(checkerObj, p);
+ }
+ }
+ if (!hasRef) {
+ addProblem(new CodanProblem(id, name));
+ }
+ }
+ } catch (Exception e) {
+ CodanCorePlugin.log(e);
+ }
+ }
+
+ /**
+ * @param configurationElement
+ * @return
+ */
+ private CodanProblem processProblem(
+ IConfigurationElement configurationElement) {
+ if (configurationElement.getName().equals(PROBLEM_ELEMENT)) {
+ String id = getAtt(configurationElement, "id");
+ if (id == null)
+ return null;
+ String name = getAtt(configurationElement, "name");
+ if (name == null)
+ name = id;
+ CodanProblem p = new CodanProblem(id, name);
+ addProblem(p);
+ return p;
+ }
+ return null;
+ }
+
+ private static String getAtt(IConfigurationElement configurationElement,
+ String name) {
+ return getAtt(configurationElement, name, true);
+ }
+
+ private static String getAtt(IConfigurationElement configurationElement,
+ String name, boolean req) {
+ String elementValue = configurationElement.getAttribute(name);
+ if (elementValue == null && req)
+ CodanCorePlugin.log("Extension "
+ + configurationElement.getDeclaringExtension()
+ .getUniqueIdentifier()
+ + " missing required attribute: " + name);
+ return elementValue;
+ }
+
+ public Iterator<IChecker> iterator() {
+ return checkers.iterator();
+ }
+
+ public static CheckersRegisry getInstance() {
+ if (instance == null)
+ new CheckersRegisry();
+ return instance;
+ }
+
+ public void addChecker(IChecker checker) {
+ checkers.add(checker);
+ }
+
+ public void addProblem(IProblem p) {
+ problems.add(p); // TODO category
+ ((CodanProblemCategory) rootCategory).addChild(p);
+ }
+
+ public Object getProblemsTree() {
+ return rootCategory;
+ }
+
+ public void addRefProblem(IChecker c, IProblem p) {
+ }
+
+ 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 null;
+ }
+
+ public IProblem getProblemById(String id, IFile file) {
+ return findProblem(id);
+ }
+}
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
new file mode 100644
index 00000000000..7cc86d02758
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanProblem.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * 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 class CodanProblem implements IProblem {
+ private String id;
+ private String name;
+ private CodanSeverity severity = CodanSeverity.Warning;
+ private boolean enabled = true;
+
+ public CodanSeverity getSeverity() {
+ return severity;
+ }
+
+ public CodanProblem(String id2, String name2) {
+ this.id = id2;
+ this.name = name2;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public IProblemCategory getCategory() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setSeverity(CodanSeverity sev) {
+ if (sev == null)
+ throw new NullPointerException();
+ this.severity = sev;
+ }
+
+ public void setEnabled(boolean checked) {
+ this.enabled = checked;
+ }
+}
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
new file mode 100644
index 00000000000..2a47418751e
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanProblemCategory.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;
+
+import java.util.ArrayList;
+
+
+public class CodanProblemCategory implements IProblemCategory {
+ private String id;
+ private String name;
+
+ private ArrayList list = new ArrayList();
+ public CodanProblemCategory(String id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+ public Object[] getChildren() {
+ return list.toArray();
+ }
+
+ public void addChild(IProblem p) {
+ list.add(p);
+ }
+
+ public IProblemCategory getParent() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+}
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanSeverity.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanSeverity.java
new file mode 100644
index 00000000000..49fc484538e
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanSeverity.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * 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;
+ }
+}
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
new file mode 100644
index 00000000000..8196ca531b5
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ErrorReporter.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * 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;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+
+public class ErrorReporter {
+ public static final String GENERIC_CODE_ANALYSIS_MARKER_TYPE = "org.eclipse.cdt.codan.core.codanProblem";
+
+ public static void reportProblem(String id, IFile file, int lineNumber,
+ String message) {
+ try {
+ if (file == null)
+ throw new NullPointerException("file");
+ if (id == null)
+ throw new NullPointerException("id");
+ IProblem problem = CheckersRegisry.getInstance().getProblemById(id,
+ file);
+ if (problem == null)
+ throw new IllegalArgumentException("Id is not registered");
+ if (problem.isEnabled() == false)
+ return; // skip
+ int severity = problem.getSeverity().intValue();
+ IMarker marker = file
+ .createMarker(GENERIC_CODE_ANALYSIS_MARKER_TYPE);
+ marker.setAttribute(IMarker.MESSAGE, message);
+ marker.setAttribute(IMarker.SEVERITY, severity);
+ if (lineNumber == -1) {
+ lineNumber = 1;
+ }
+ marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void deleteMarkers(IResource file) {
+ try {
+ file.deleteMarkers(GENERIC_CODE_ANALYSIS_MARKER_TYPE, false,
+ IResource.DEPTH_ZERO);
+ } catch (CoreException ce) {
+ }
+ }
+
+ public static void deleteAllMarkers() {
+ try {
+ // TODO delete contributed markers too
+ ResourcesPlugin.getWorkspace().getRoot().deleteMarkers(
+ GENERIC_CODE_ANALYSIS_MARKER_TYPE, false,
+ IResource.DEPTH_INFINITE);
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICAstChecker.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICAstChecker.java
new file mode 100644
index 00000000000..461c0fa6f6c
--- /dev/null
+++ b/codan/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/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IChecker.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IChecker.java
new file mode 100644
index 00000000000..c1ccd96bea6
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IChecker.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;
+
+import org.eclipse.core.resources.IResource;
+
+public interface IChecker {
+ public boolean processResource(IResource resource);
+
+ boolean enabledInContext(IResource resource);
+}
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
new file mode 100644
index 00000000000..6079963dd98
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblem.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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 IProblem {
+ String getName();
+
+ String getId();
+
+ boolean isEnabled();
+
+ CodanSeverity getSeverity();
+
+ IProblemCategory getCategory();
+}
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
new file mode 100644
index 00000000000..bd9c60d66da
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemCategory.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;
+
+public interface IProblemCategory {
+ String getName();
+
+ String getId();
+ Object[] getChildren();
+
+ IProblemCategory getParent();
+
+}

Back to the top