mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
initial commit
This commit is contained in:
parent
724390a35f
commit
2646066384
29 changed files with 1414 additions and 0 deletions
7
codan/org.eclipse.cdt.codan.checkers/.classpath
Normal file
7
codan/org.eclipse.cdt.codan.checkers/.classpath
Normal file
|
@ -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>
|
28
codan/org.eclipse.cdt.codan.checkers/.project
Normal file
28
codan/org.eclipse.cdt.codan.checkers/.project
Normal file
|
@ -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>
|
|
@ -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
|
13
codan/org.eclipse.cdt.codan.checkers/META-INF/MANIFEST.MF
Normal file
13
codan/org.eclipse.cdt.codan.checkers/META-INF/MANIFEST.MF
Normal file
|
@ -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
|
5
codan/org.eclipse.cdt.codan.checkers/build.properties
Normal file
5
codan/org.eclipse.cdt.codan.checkers/build.properties
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
source.. = src/
|
||||||
|
output.. = bin/
|
||||||
|
bin.includes = META-INF/,\
|
||||||
|
.,\
|
||||||
|
plugin.xml
|
19
codan/org.eclipse.cdt.codan.checkers/plugin.xml
Normal file
19
codan/org.eclipse.cdt.codan.checkers/plugin.xml
Normal file
|
@ -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>
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
7
codan/org.eclipse.cdt.codan.core/.classpath
Normal file
7
codan/org.eclipse.cdt.codan.core/.classpath
Normal file
|
@ -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>
|
28
codan/org.eclipse.cdt.codan.core/.project
Normal file
28
codan/org.eclipse.cdt.codan.core/.project
Normal file
|
@ -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>
|
|
@ -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
|
15
codan/org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF
Normal file
15
codan/org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF
Normal file
|
@ -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
|
6
codan/org.eclipse.cdt.codan.core/build.properties
Normal file
6
codan/org.eclipse.cdt.codan.core/build.properties
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
source.. = src/
|
||||||
|
output.. = bin/
|
||||||
|
bin.includes = META-INF/,\
|
||||||
|
.,\
|
||||||
|
plugin.xml,\
|
||||||
|
schema/
|
47
codan/org.eclipse.cdt.codan.core/plugin.xml
Normal file
47
codan/org.eclipse.cdt.codan.core/plugin.xml
Normal file
|
@ -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>
|
246
codan/org.eclipse.cdt.codan.core/schema/checkers.exsd
Normal file
246
codan/org.eclipse.cdt.codan.core/schema/checkers.exsd
Normal file
|
@ -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:
|
||||||
|
<p>
|
||||||
|
<pre>
|
||||||
|
<extension
|
||||||
|
point="org.eclipse.cdt.codan.ui.checkers">
|
||||||
|
<checker
|
||||||
|
class="org.aaa.AssignmentInConditionChecker"
|
||||||
|
id="org.aaa.AssignmentInConditionChecker"
|
||||||
|
name="Possible Assignment in Condition instead of comparision">
|
||||||
|
</checker>
|
||||||
|
</extension>
|
||||||
|
</pre>
|
||||||
|
</p>
|
||||||
|
The following is an example of a checker that produces two types of errors:
|
||||||
|
<p>
|
||||||
|
<pre>
|
||||||
|
<extension
|
||||||
|
point="org.eclipse.cdt.codan.ui.checkers">
|
||||||
|
|
||||||
|
<checker
|
||||||
|
class="org.aaa.NullPointerDereferenceChecker"
|
||||||
|
id="org.aaa.NullPointerDereferenceChecker"
|
||||||
|
name="Null Pointer Dereference checker">
|
||||||
|
<problem id="org.aaa.npe_must" name="Null Pointer Dereference"/ defaultSeverity="Error">
|
||||||
|
<problem id="org.aaa.npe_may" name="Possible Null Pointer Dereference"/>
|
||||||
|
</checker>
|
||||||
|
</extension>
|
||||||
|
</pre>
|
||||||
|
</p>
|
||||||
|
</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>
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
|
@ -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();
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue