1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

[279740] API scrub

This commit is contained in:
Alena Laskavaia 2010-03-08 19:51:33 +00:00
parent b99ecd97c7
commit c8dd92b392
61 changed files with 656 additions and 417 deletions

View file

@ -20,9 +20,15 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
</natures>
</projectDescription>

View file

@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: Checkers Ui
Bundle-SymbolicName: org.eclipse.cdt.codan.checkers.ui;singleton:=true
Bundle-Version: 1.0.0
Bundle-Activator: org.eclipse.cdt.codan.checkers.ui.CheckersUiActivator
Bundle-Activator: org.eclipse.cdt.codan.internal.checkers.ui.CheckersUiActivator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.ui.ide;bundle-version="3.5.0",

View file

@ -3,7 +3,3 @@ output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml
src.includes = src/,\
plugin.xml,\
build.properties,\
META-INF/

View file

@ -1,4 +1,4 @@
package org.eclipse.cdt.codan.checkers.ui;
package org.eclipse.cdt.codan.internal.checkers.ui;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

View file

@ -20,9 +20,15 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
</natures>
</projectDescription>

View file

@ -3,7 +3,3 @@ output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml
src.includes = src/,\
plugin.xml,\
META-INF/,\
build.properties

View file

@ -3,74 +3,74 @@
<plugin>
<extension
point="org.eclipse.cdt.codan.core.checkers"
id="org.eclipse.cdt.codan.core.checkers.sample">
id="org.eclipse.cdt.codan.core.examples.checkers">
<checker
class="org.eclipse.cdt.codan.internal.checkers.sample.AssignmentInConditionChecker"
id="org.eclipse.cdt.codan.checkers.sample.AssignmentInConditionChecker"
class="org.eclipse.cdt.codan.examples.checkers.AssignmentInConditionChecker"
id="org.eclipse.cdt.codan.examples.checkers.AssignmentInConditionChecker"
name="Assignment in condition">
<problem
defaultSeverity="Warning"
id="org.eclipse.cdt.codan.checkers.sample.AssignmentInConditionProblem"
id="org.eclipse.cdt.codan.examples.checkers.AssignmentInConditionProblem"
name="Assignment in condition">
</problem>
</checker>
<checker
class="org.eclipse.cdt.codan.internal.checkers.sample.StatementHasNoEffectChecker"
id="org.eclipse.cdt.codan.checkers.sample.StatementHasNoEffectChecker"
class="org.eclipse.cdt.codan.examples.checkers.StatementHasNoEffectChecker"
id="org.eclipse.cdt.codan.examples.checkers.StatementHasNoEffectChecker"
name="StatementHasNoEffectChecker">
<problem
category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems"
defaultSeverity="Warning"
id="org.eclipse.cdt.codan.checkers.sample.StatementHasNoEffectProblem"
id="org.eclipse.cdt.codan.examples.checkers.StatementHasNoEffectProblem"
name="Statement has no effect">
</problem>
</checker>
<checker
class="org.eclipse.cdt.codan.internal.checkers.sample.NonVirtualDestructor"
id="org.eclipse.cdt.codan.checkers.sample.NonVirtualDescructor"
class="org.eclipse.cdt.codan.examples.checkers.NonVirtualDestructor"
id="org.eclipse.cdt.codan.examples.checkers.NonVirtualDescructor"
name="NonVirtualDescructorChecker">
<problem
category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems"
defaultSeverity="Warning"
id="org.eclipse.cdt.codan.checkers.sample.NonVirtualDestructorProblem"
id="org.eclipse.cdt.codan.examples.checkers.NonVirtualDestructorProblem"
name="Class has a virtual method and non-virtual destructor">
</problem>
</checker>
<checker
class="org.eclipse.cdt.codan.internal.checkers.sample.CatchUsesReference"
id="org.eclipse.cdt.codan.checkers.sample.CatchUsesReference"
class="org.eclipse.cdt.codan.examples.checkers.CatchUsesReference"
id="org.eclipse.cdt.codan.examples.checkers.CatchUsesReference"
name="CatchUsesReferenceChecker">
<problem
category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems"
defaultSeverity="Warning"
id="org.eclipse.cdt.codan.checkers.sample.CatchUsesReference"
id="org.eclipse.cdt.codan.examples.checkers.CatchUsesReference"
name="Catch uses reference to exception">
</problem>
</checker>
<checker
class="org.eclipse.cdt.codan.internal.checkers.sample.SuggestedParenthesisChecker"
id="org.eclipse.cdt.codan.checkers.sample.SuggestedParenthesisChecker"
class="org.eclipse.cdt.codan.examples.checkers.SuggestedParenthesisChecker"
id="org.eclipse.cdt.codan.examples.checkers.SuggestedParenthesisChecker"
name="SuggestedParenthesisChecker">
<problem
category="org.eclipse.cdt.codan.core.categories.ProgrammingProblems"
defaultSeverity="Warning"
id="org.eclipse.cdt.codan.checkers.sample.SuggestedParenthesisProblem"
id="org.eclipse.cdt.codan.examples.checkers.SuggestedParenthesisProblem"
name="Suggested parenthesis around expression">
</problem>
</checker>
<checker
class="org.eclipse.cdt.codan.internal.checkers.sample.NamingConventionFunctionChecker"
id="org.eclipse.cdt.codan.checkers.sample.NamingConventionFunctionChecker"
class="org.eclipse.cdt.codan.examples.checkers.NamingConventionFunctionChecker"
id="org.eclipse.cdt.codan.examples.checkers.NamingConventionFunctionChecker"
name="NamingConventionFunctionChecker">
<problem
category="org.eclipse.cdt.codan.core.categories.CodeStyle"
defaultSeverity="Warning"
id="org.eclipse.cdt.codan.checkers.sample.NamingConventionFunctionProblem"
id="org.eclipse.cdt.codan.examples.checkers.NamingConventionFunctionProblem"
name="Name convention for function">
</problem>
</checker>

View file

@ -8,7 +8,7 @@
* Contributors:
* Alena Laskavaia - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.codan.internal.checkers.sample;
package org.eclipse.cdt.codan.examples.checkers;
import org.eclipse.cdt.codan.core.model.AbstractIndexAstChecker;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
@ -20,7 +20,7 @@ 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.internal.checkers.sample.AssignmentInConditionProblem";
private static final String ER_ID = "org.eclipse.cdt.codan.examples.checkers.AssignmentInConditionProblem";
public void processAst(IASTTranslationUnit ast) {
// traverse the ast using the visitor pattern.

View file

@ -9,7 +9,7 @@
* Alena Laskavaia - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.codan.internal.checkers.sample;
package org.eclipse.cdt.codan.examples.checkers;
import org.eclipse.cdt.codan.core.model.AbstractIndexAstChecker;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
@ -28,7 +28,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement;
*
*/
public class CatchUsesReference extends AbstractIndexAstChecker {
private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.sample.CatchUsesReference";
private static final String ER_ID = "org.eclipse.cdt.codan.examples.checkers.CatchUsesReference";
public void processAst(IASTTranslationUnit ast) {
// traverse the ast using the visitor pattern.

View file

@ -8,7 +8,7 @@
* Contributors:
* Alena Laskavaia - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.codan.internal.checkers.sample;
package org.eclipse.cdt.codan.examples.checkers;
import java.util.regex.Pattern;
import org.eclipse.cdt.codan.core.model.AbstractCIndexChecker;
@ -27,8 +27,8 @@ import org.eclipse.core.runtime.CoreException;
*/
public class NamingConventionFunctionChecker extends AbstractCIndexChecker
implements ICheckerWithParameters {
public static final String PARAM_KEY = "pattern";
private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.sample.NamingConventionFunctionProblem";
public static final String PARAM_KEY = "pattern"; //$NON-NLS-1$
private static final String ER_ID = "org.eclipse.cdt.codan.examples.checkers.NamingConventionFunctionProblem"; //$NON-NLS-1$
/*
* (non-Javadoc)

View file

@ -8,7 +8,7 @@
* Contributors:
* Alena Laskavaia - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.codan.internal.checkers.sample;
package org.eclipse.cdt.codan.examples.checkers;
import java.text.MessageFormat;
@ -33,7 +33,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
*
*/
public class NonVirtualDestructor extends AbstractIndexAstChecker {
private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.sample.NonVirtualDestructorProblem";
private static final String ER_ID = "org.eclipse.cdt.codan.examples.checkers.NonVirtualDestructorProblem";
public void processAst(IASTTranslationUnit ast) {
// traverse the ast using the visitor pattern.

View file

@ -8,7 +8,7 @@
* Contributors:
* Alena Laskavaia - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.codan.internal.checkers.sample;
package org.eclipse.cdt.codan.examples.checkers;
import org.eclipse.cdt.codan.core.model.AbstractIndexAstChecker;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
@ -36,7 +36,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
*
*/
public class StatementHasNoEffectChecker extends AbstractIndexAstChecker {
private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.sample.StatementHasNoEffectProblem";
private static final String ER_ID = "org.eclipse.cdt.codan.examples.checkers.StatementHasNoEffectProblem";
public void processAst(IASTTranslationUnit ast) {
// traverse the ast using the visitor pattern.

View file

@ -8,7 +8,7 @@
* Contributors:
* Alena Laskavaia - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.codan.internal.checkers.sample;
package org.eclipse.cdt.codan.examples.checkers;
import org.eclipse.cdt.codan.core.model.AbstractIndexAstChecker;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
@ -29,7 +29,7 @@ import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
*
*/
public class SuggestedParenthesisChecker extends AbstractIndexAstChecker {
private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.sample.SuggestedParenthesisProblem";
private static final String ER_ID = "org.eclipse.cdt.codan.examples.checkers.SuggestedParenthesisProblem";
public void processAst(IASTTranslationUnit ast) {
// traverse the ast using the visitor pattern.

View file

@ -3,3 +3,4 @@ output.. = bin/
bin.includes = META-INF/,\
.,\
src/org/eclipse/cdt/codan/core/checkers/
jre.compilation.profile = J2SE-1.5

View file

@ -20,9 +20,15 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
</natures>
</projectDescription>

View file

@ -4,8 +4,4 @@ bin.includes = META-INF/,\
.,\
plugin.xml,\
schema/
src.includes = src/,\
schema/,\
plugin.xml,\
build.properties,\
META-INF/
src.includes = schema/

View file

@ -65,7 +65,7 @@
thread="main"
visible="true">
<run
class="org.eclipse.cdt.codan.core.CodanApplication">
class="org.eclipse.cdt.codan.internal.core.CodanApplication">
</run>
</application>
</extension>

View file

@ -13,7 +13,7 @@ import org.osgi.framework.BundleContext;
*/
public class CodanCorePlugin extends Plugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.cdt.codan.core";
public static final String PLUGIN_ID = "org.eclipse.cdt.codan.core"; //$NON-NLS-1$
public static final String NATURE_ID = CodeAnlysisNature.NATURE_ID;
// The shared instance
private static CodanCorePlugin plugin;
@ -34,6 +34,7 @@ public class CodanCorePlugin extends Plugin {
* @see
* org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
*/
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
@ -45,6 +46,7 @@ public class CodanCorePlugin extends Plugin {
* @see
* org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
*/
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);

View file

@ -13,42 +13,94 @@ package org.eclipse.cdt.codan.core;
import org.eclipse.cdt.codan.core.model.ICheckersRegistry;
import org.eclipse.cdt.codan.core.model.ICodanAstReconciler;
import org.eclipse.cdt.codan.core.model.ICodanBuilder;
import org.eclipse.cdt.codan.core.model.IProblemLocationFactory;
import org.eclipse.cdt.codan.core.model.IProblemReporter;
import org.eclipse.cdt.codan.internal.core.CheckersRegisry;
import org.eclipse.cdt.codan.internal.core.CodanBuilder;
import org.eclipse.cdt.codan.internal.core.model.CodanMarkerProblemReporter;
import org.eclipse.cdt.codan.internal.core.model.ProblemLocationFactory;
/**
* Runtime singleton class to get access to Codan framework parts
*
* Clients may extend this class to override default framework parts.
*/
public class CodanRuntime {
private static CodanRuntime instance = new CodanRuntime();
private IProblemReporter problemReporter = new CodanMarkerProblemReporter();
private CodanBuilder builder = new CodanBuilder();
private CheckersRegisry checkers = CheckersRegisry.getInstance();
private IProblemLocationFactory locFactory = new ProblemLocationFactory();
/**
* CodanRuntime - only can be called by subclasses to override default constructor
*/
protected CodanRuntime() {
// nothing here
}
/**
* Get runtime problem reporter. Default reported generated problem markers.
* @return
*/
public IProblemReporter getProblemReporter() {
return problemReporter;
}
/**
* Set different problem reporter.
* @param reporter
*/
public void setProblemReporter(IProblemReporter reporter) {
problemReporter = reporter;
}
/**
* Get instance of of Codan Runtime
* @return
*/
public static CodanRuntime getInstance() {
return instance;
}
/**
* Get builder. Builder can used to run code analysis on given resource using API.
* @return
*/
public ICodanBuilder getBuilder() {
return builder;
}
/**
* Get quick builder. Can be used to run code analysis on given ast.
* @return
*/
public ICodanAstReconciler getAstQuickBuilder() {
return builder;
}
/**
* Get checkers registry.
* @return
*/
public ICheckersRegistry getChechersRegistry() {
return checkers;
}
/**
* Get problem location factory.
* @return
*/
public IProblemLocationFactory getProblemLocationFactory() {
return locFactory;
}
/**
* Set another problem location factory - only need if default is not sufficient, i.e
* IProblemLocation is implemented differently
* @param factory
*/
public void setProblemLocationFactory(IProblemLocationFactory factory) {
locFactory = factory;
}
}

View file

@ -14,7 +14,7 @@ package org.eclipse.cdt.codan.core;
* Constant definitions for plug-in preferences
*/
public class PreferenceConstants {
public static final String P_RUN_ON_BUILD = "booleanPreference";
public static final String P_PROBLEMS = "problems";
public static final String P_USE_PARENT = "useParentScope";
public static final String P_RUN_ON_BUILD = "booleanPreference"; //$NON-NLS-1$
public static final String P_PROBLEMS = "problems"; //$NON-NLS-1$
public static final String P_USE_PARENT = "useParentScope"; //$NON-NLS-1$
}

View file

@ -21,11 +21,11 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
/**
* Checker that works with C-Index of a file (but not AST)
* Implementation of IChecker that works with C-Index of a file (but not AST)
*
* Clients may extend this class.
*/
public abstract class AbstractCIndexChecker extends AbstractChecker implements
ICIndexChecker {
public abstract class AbstractCIndexChecker extends AbstractChecker implements ICIndexChecker {
private IFile file;
protected IIndex index;
@ -36,11 +36,8 @@ public abstract class AbstractCIndexChecker extends AbstractChecker implements
void processFile(IFile file) throws CoreException, InterruptedException {
// create translation unit and access index
ICElement model = CoreModel.getDefault().create(file);
if (!(model instanceof ITranslationUnit))
return;
if (!(model instanceof ITranslationUnit)) return; // not a C/C++ file
ITranslationUnit tu = (ITranslationUnit) model;
if (tu == null)
return; // not a C/C++ file
index = CCorePlugin.getIndexManager().getIndex(tu.getCProject());
// lock the index for read access
index.acquireReadLock();

View file

@ -15,6 +15,12 @@ import org.eclipse.cdt.codan.internal.core.CheckersRegisry;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
/**
* Convenience implementation of IChecker interface.
* Has a default implementation for common methods.
*
* Clients may extend this class.
*/
public abstract class AbstractChecker implements IChecker {
protected String name;
@ -44,15 +50,18 @@ public abstract class AbstractChecker implements IChecker {
* internationalization)
*/
public void reportProblem(String id, IFile file, int lineNumber, String arg) {
getProblemReporter().reportProblem(id,
new ProblemLocation(file, lineNumber), arg);
getProblemReporter().reportProblem(id, createProblemLocation(file, lineNumber), arg);
}
/**
* Finds an instance of problem by given id, in user profile registered for specific file
* @param id - problem id
* @param file - file in scope
* @return problem instance
*/
public IProblem getProblemById(String id, IFile file) {
IProblem problem = CheckersRegisry.getInstance().getResourceProfile(
file).findProblem(id);
if (problem == null)
throw new IllegalArgumentException("Id is not registered");
IProblem problem = CheckersRegisry.getInstance().getResourceProfile(file).findProblem(id);
if (problem == null) throw new IllegalArgumentException("Id is not registered"); //$NON-NLS-1$
return problem;
}
@ -68,8 +77,7 @@ public abstract class AbstractChecker implements IChecker {
* - line
*/
public void reportProblem(String id, IFile file, int lineNumber) {
getProblemReporter().reportProblem(id,
new ProblemLocation(file, lineNumber), new Object[] {});
getProblemReporter().reportProblem(id, createProblemLocation(file, lineNumber), new Object[] {});
}
/**
@ -79,6 +87,35 @@ public abstract class AbstractChecker implements IChecker {
return CodanRuntime.getInstance().getProblemReporter();
}
/**
* Convenience method to return codan runtime
* @return
*/
protected CodanRuntime getRuntime() {
return CodanRuntime.getInstance();
}
/**
* Convenience method to create and return instance of IProblemLocation
* @param file - file where problem is found
* @param line - line number 1-relative
* @return instance of IProblemLocation
*/
protected IProblemLocation createProblemLocation(IFile file, int line) {
return getRuntime().getProblemLocationFactory().createProblemLocation(file, line);
}
/**
* Convenience method to create and return instance of IProblemLocation
* @param file - file where problem is found
* @param startChar - start char of the problem in the file, is zero-relative
* @param endChar - end char of the problem in the file, is zero-relative and exclusive.
* @return instance of IProblemLocation
*/
protected IProblemLocation createProblemLocation(IFile file, int startChar, int endChar) {
return getRuntime().getProblemLocationFactory().createProblemLocation(file, startChar, endChar);
}
public boolean runInEditor() {
return false;
}

View file

@ -27,11 +27,11 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
/**
* @author Alena
* Convenience implementation of checker that work on index based ast of a c/c++ program.
*
* Clients may extend this class.
*/
public abstract class AbstractIndexAstChecker extends AbstractChecker implements
ICAstChecker {
public abstract class AbstractIndexAstChecker extends AbstractChecker implements ICAstChecker {
private IFile file;
protected IFile getFile() {
@ -41,18 +41,14 @@ public abstract class AbstractIndexAstChecker extends AbstractChecker implements
void processFile(IFile file) throws CoreException, InterruptedException {
// create translation unit and access index
ICElement model = CoreModel.getDefault().create(file);
if (!(model instanceof ITranslationUnit))
return;
if (!(model instanceof ITranslationUnit)) return; // not a C/C++ file
ITranslationUnit tu = (ITranslationUnit) model;
if (tu == null)
return; // not a C/C++ file
IIndex index = CCorePlugin.getIndexManager().getIndex(tu.getCProject());
// lock the index for read access
index.acquireReadLock();
try {
// create index based ast
IASTTranslationUnit ast = tu.getAST(index,
ITranslationUnit.AST_SKIP_INDEXED_HEADERS);
IASTTranslationUnit ast = tu.getAST(index, ITranslationUnit.AST_SKIP_INDEXED_HEADERS);
// traverse the ast using the visitor pattern.
this.file = file;
processAst(ast);
@ -80,19 +76,16 @@ public abstract class AbstractIndexAstChecker extends AbstractChecker implements
public void reportProblem(String id, IASTNode astNode, String message) {
IASTFileLocation astLocation = astNode.getFileLocation();
IPath location = new Path(astLocation.getFileName());
IFile astFile = ResourcesPlugin.getWorkspace().getRoot()
.getFileForLocation(location);
IFile astFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(location);
if (astFile == null) {
astFile = file;
}
ProblemLocation loc;
if (astLocation.getStartingLineNumber() == astLocation
.getEndingLineNumber())
loc = new ProblemLocation(astFile, astLocation.getNodeOffset(),
astLocation.getNodeOffset() + astLocation.getNodeLength());
else
loc = new ProblemLocation(astFile, astLocation
.getStartingLineNumber());
IProblemLocation loc;
if (astLocation.getStartingLineNumber() == astLocation.getEndingLineNumber()) loc = getRuntime()
.getProblemLocationFactory().createProblemLocation(astFile, astLocation.getNodeOffset(),
astLocation.getNodeOffset() + astLocation.getNodeLength());
else loc = getRuntime().getProblemLocationFactory().createProblemLocation(astFile,
astLocation.getStartingLineNumber());
getProblemReporter().reportProblem(id, loc, message);
}

View file

@ -12,9 +12,17 @@ package org.eclipse.cdt.codan.core.model;
import org.eclipse.core.resources.IMarker;
/**
*
* Represents Severity of the codan problem. It is directly mapped to markers severity,
* therefore not intended to be extended.
*
* @noextend This class is not intended to be extended by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
*
*/
public enum CodanSeverity {
Info(IMarker.SEVERITY_INFO), Warning(IMarker.SEVERITY_WARNING), Error(
IMarker.SEVERITY_ERROR);
Info(IMarker.SEVERITY_INFO), Warning(IMarker.SEVERITY_WARNING), Error(IMarker.SEVERITY_ERROR);
private int value;
private CodanSeverity(int value) {
@ -26,7 +34,7 @@ public enum CodanSeverity {
}
/**
* @return
* @return array of string value for all severities
*/
public static String[] stringValues() {
CodanSeverity[] values = values();

View file

@ -13,9 +13,16 @@ package org.eclipse.cdt.codan.core.model;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
/**
* @author Alena
* Checker that can/want to process C/C++ AST (Abstract Syntax Tree) of a program
* Default implementation {@link AbstractIndexAstChecker}
*
* Clients may implement and extend this interface.
*/
public interface ICAstChecker extends IChecker {
/**
* Run this checker on a given ast.
* Ast locks would be obtained by the framework before calling this method.
* @param ast
*/
void processAst(IASTTranslationUnit ast);
}

View file

@ -13,9 +13,15 @@ package org.eclipse.cdt.codan.core.model;
import org.eclipse.cdt.core.model.ITranslationUnit;
/**
* @author Alena
* Extension of IChecker that works with C-Index of a file (but not AST)
* Default implementation {@link AbstractCIndexChecker}
*
* Client may implement this interface.
*/
public interface ICIndexChecker extends IChecker {
/**
* Run checker on translation unit
* @param unit - translation unit
*/
void processUnit(ITranslationUnit unit);
}

View file

@ -14,6 +14,8 @@ import org.eclipse.core.resources.IResource;
/**
* Interface that checker must implement. CDT Checker must be able to process a resource.
*
* Clients may implement and extend this interface.
*/
public interface IChecker {
/**
@ -26,7 +28,7 @@ public interface IChecker {
/**
* Implement this method to trim down type of resource you are interested in,
* usually it will be c/c++ files only
* @param resource
* @param resource - resource to run on
* @return
*/
boolean enabledInContext(IResource resource);

View file

@ -11,9 +11,15 @@
package org.eclipse.cdt.codan.core.model;
/**
* @author Alena
* Interface for checker with parameters, if checker implements this
* interface method would be called on initialization so checker has
* a chance to set default values for its parameters
*
*/
public interface ICheckerWithParameters {
/**
* Implement this method to set default parameters for checkers with parameters.
* @param problem - instance of problem working copy
*/
void initParameters(IProblemWorkingCopy problem);
}

View file

@ -15,52 +15,82 @@ import java.util.Iterator;
import org.eclipse.core.resources.IResource;
/**
* @author Alena
* This interface an API to add/remove checker and problems programmatically,
* get problem profiles and change problem default settings
*
*/
public interface ICheckersRegistry {
public interface ICheckersRegistry extends Iterable<IChecker> {
/**
* Iterator for registered checkers
* @return
*/
public abstract Iterator<IChecker> iterator();
/**
* Add another checker
* @param checker
*/
public abstract void addChecker(IChecker checker);
public abstract void addProblem(IProblem p, String category);
/**
* Add problem p with default category by category id into default profile, category must exists in default profile
* @param p - problem
* @param categoryId - category id
*/
public abstract void addProblem(IProblem p, String categoryId);
public abstract void addCategory(IProblemCategory p, String category);
/**
* Add subcategory with id categoryId into parent category,
* if parent does not exist in default, profile - if not will be added to the root
* @param category - new category
* @param parentCategoryId - parent category id
*/
public abstract void addCategory(IProblemCategory category, String parentCategoryId);
/**
* Add problem reference to a checker, i.e. claim that checker can produce this problem.
* If checker does not claim any problems it cannot be enabled.
* @param c - checker
* @param p - problem
*/
public abstract void addRefProblem(IChecker c, IProblem p);
/**
* Get default profile, default profile is kind of "Installation Default". Always the same, comes from default in checker extensions
* @return
*/
public abstract IProblemProfile getDefaultProfile();
/**
* @return
* Get workspace profile. User can change setting for workspace profile.
* @return profile
*/
public abstract IProblemProfile getWorkspaceProfile();
/**
* @param element
* @return
* Get resource profile. For example given directory can have different profile
* than parent project.
*
* @param element - resource
* @return profile
*/
public abstract IProblemProfile getResourceProfile(IResource element);
/**
* Returns profile working copy for given resource element. (If profile is not
* specified for given element it will search for parent resource and so on).
* @param element
* @return
*/
public abstract IProblemProfile getResourceProfileWorkingCopy(
IResource element);
public abstract IProblemProfile getResourceProfileWorkingCopy(IResource element);
/**
* Set profile for resource. This method is called by UI, and should not be
* called by clients directly
*
* Set profile for resource.
* @noreference This method is not intended to be referenced by clients.
* @param resource
* - resource
* @param profile
* - problems profile
*/
public abstract void updateProfile(IResource resource,
IProblemProfile profile);
public abstract void updateProfile(IResource resource, IProblemProfile profile);
}

View file

@ -14,9 +14,17 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.core.runtime.IProgressMonitor;
/**
* @author Alena
* Allows to run all checkers that can run on ast via editing using API
*
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*
*/
public interface ICodanAstReconciler {
/**
* Run code analysis on ast
* @param ast - ast to be reconciled
* @param monitor - progress monitor
*/
public void reconcileAst(IASTTranslationUnit ast, IProgressMonitor monitor);
}

View file

@ -14,9 +14,19 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
/**
* @author Alena
* Interface for "Codan Builder". Clients can cann processResource method to
* traverse the resource tree, calling all the checker (this interface allows
* to call framework without using UI). You can obtain instance of this
* class as CodanRuntime.getInstance().getBuilder()
*
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface ICodanBuilder {
/**
* Run code analysis on given resource
* @param resource - resource to process
* @param monitor - progress monitor
*/
public void processResource(IResource resource, IProgressMonitor monitor);
}

View file

@ -10,9 +10,14 @@
*******************************************************************************/
package org.eclipse.cdt.codan.core.model;
/**
* Interface representing code analysis problem
* Interface representing code analysis problem type. For example "Null Pointer Dereference"
* is a problem. It has user visible Name and Message (translatable), as well as some other
* parameters, changeable by user such as enablement, severity and so on. Same problem
* cannot have two severities determined by runtime. If it is the case - two Problem should
* be created (i.e. one for error and one for warning).
*
* Clients may implement and extend this interface.
*
*/
public interface IProblem extends IProblemElement {
@ -53,8 +58,9 @@ public interface IProblem extends IProblemElement {
public Object getParameter(Object key);
/**
* Get root paramterInfo - contains description of types of all the
* parameters or null if not defined
* Get parameter info root - contains description of types of all the
* parameters or null if not defined (used by ui to generate user controls
* for changing parameters)
*
* @return
*/

View file

@ -11,8 +11,9 @@
package org.eclipse.cdt.codan.core.model;
/**
* Problem category
*
* Problem category.
*
* Clients may extend and implement this interface.
*/
public interface IProblemCategory extends IProblemElement {
/**
@ -32,17 +33,4 @@ public interface IProblemCategory extends IProblemElement {
*/
IProblemElement[] getChildren();
/**
* Find problem by id within children recursively
* @param id
* @return
*/
IProblem findProblem(String id);
/**
* Find category by id within children recursively
* @param id
* @return
*/
IProblemCategory findCategory(String id);
}

View file

@ -11,9 +11,17 @@
package org.eclipse.cdt.codan.core.model;
/**
* Problem category or problem
* Problem category {@link IProblemCategory} or problem {@link IProblem}
*
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface IProblemElement extends Cloneable {
/**
* clone method should be implemented to support problem cloning
* @see {@link Object#clone}
* @return new object which is copy of this one
* @throws CloneNotSupportedException - it is declared with this exception but it should NOT throw it
*/
Object clone() throws CloneNotSupportedException;
}

View file

@ -16,6 +16,8 @@ import org.eclipse.core.resources.IFile;
* Interface to describe problem location. Usually contains file and linenumber,
* also supports character positions for sophisticated errors.
*
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface IProblemLocation {
/**

View file

@ -0,0 +1,39 @@
/*******************************************************************************
* 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;
/**
* Factory interface that allows to create problem locations.
*
* Clients may implement and extend this interface.
*/
public interface IProblemLocationFactory {
/**
* Create and return instance of IProblemLocation
* @param file - file where problem is found
* @param line - line number where problem is found, starts with 1
* @return instance of IProblemLocation
*/
public IProblemLocation createProblemLocation(IFile file, int line);
/**
* Create and return instance of IProblemLocation
* @param file - file where problem is found
* @param startChar - start char of the problem in the file, is zero-relative
* @param endChar - end char of the problem in the file, is zero-relative and exclusive.
* @return instance of IProblemLocation
*/
public IProblemLocation createProblemLocation(IFile file, int startChar, int endChar);
}

View file

@ -11,15 +11,15 @@
package org.eclipse.cdt.codan.core.model;
/**
* Problem parameter usually key=value settings that allow to alter checker
* Problem parameter usually key=value settings that allows to alter checker
* behaviour for given problem. For example if checker finds violation of naming
* conventions for function, parameter would be the pattern of allowed names.
* ProblemParameterInfo represent parameter meta-info for the ui.
* If more that one parameter required ParameterInfo should describe hash or array of parameters.
* This is only needed for auto-generated ui for parameter editing. For complex case custom ui control should be used
*
* @author Alena
*
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface IProblemParameterInfo {
String getKey();
@ -42,13 +42,14 @@ public interface IProblemParameterInfo {
String getUiInfo();
/**
* User visible label for the control in UI
* User visible label for the parameter control in UI
* @return the label
*/
String getLabel();
/**
* Available if type is list or hash. Returns value of subparamer with the
* name of key. For the "list" key must be "#".
* name of key. For the "list" type key is the number (index).
*
* @param key
* - name of the subparameter.

View file

@ -11,15 +11,21 @@
package org.eclipse.cdt.codan.core.model;
/**
* Problem Profile contains tree of categories and problems. For user profile is quick way
* to switch between problems sets depends on task he is doing (i.e. find real bugs, vs doing code style report)
* User can set different profiles in different projects.
* Profiles can have different categories and different problems set, problems with the same id
* can have different severities/enablement in different profiles. To obtain
* profile use class {@link CheckersRegisry#getResourceProfile,
* Problem Profile contains tree of categories and problems. For the user
* the profile is quick way to switch between problem sets depending on the
* task he is doing (i.e. find real bugs, vs doing code style report)
* User can set different profiles for different projects.
* Profiles can have different categories and different problem sets,
* problems with the same id can have different severities/enablement in different profiles.
* Category tree can have few reference to a same problem, but only instance of Problem
* with the same id can exist in the same profile (i.e. two category can have same problem listed in both,
* but they both should point to the same problem instance).
*
* To obtain read-only profile use method {@link CheckersRegisry#getResourceProfile,
* CheckersRegisry#getDefaultProfile() or CheckersRegisry#getWorkspaceProfile()}
* .
*
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface IProblemProfile extends IProblemElement {
/**
@ -28,7 +34,7 @@ public interface IProblemProfile extends IProblemElement {
IProblemCategory getRoot();
/**
* Find and return problem by id
* Find and return problem by id if it contained in this profile
*
* @param id
* - problem id
@ -37,7 +43,7 @@ public interface IProblemProfile extends IProblemElement {
IProblem findProblem(String id);
/**
* Find and return category by id
* Find and return category by id if it is contained in this profile
*
* @param id
* - category id
@ -46,7 +52,7 @@ public interface IProblemProfile extends IProblemElement {
IProblemCategory findCategory(String id);
/**
* Get all defined problems
* Get all problems defined in this profile (if problem duplicated in a category tree, it returns only one instance of each)
*
* @return array of problems defined in profile
*/

View file

@ -10,20 +10,20 @@
*******************************************************************************/
package org.eclipse.cdt.codan.core.model;
/**
* IProblemReporter - interface to report problems
*
*
* Clients may implement and extend this interface
*/
public interface IProblemReporter {
public static final String GENERIC_CODE_ANALYSIS_MARKER_TYPE = "org.eclipse.cdt.codan.core.codanProblem";
public static final String GENERIC_CODE_ANALYSIS_MARKER_TYPE = "org.eclipse.cdt.codan.core.codanProblem"; //$NON-NLS-1$
/**
* Report a problem with "problemId" id on location determined by "loc",
* using problem specific error message customised by args.
* @param problemId - id of the problem registers with checker
* Report a problem with "problemId" id on the location determined by "loc",
* using problem specific error message customized by args.
* @param problemId - id of the problem registered with a checker
* @param loc - location object
* @param args - custom args, can be null, in this case default message is reported
* @param args - custom arguments, can be null, in this case default message is reported
*/
public void reportProblem(String problemId, IProblemLocation loc,
Object ... args);
public void reportProblem(String problemId, IProblemLocation loc, Object... args);
}

View file

@ -10,22 +10,43 @@
*******************************************************************************/
package org.eclipse.cdt.codan.core.model;
/**
* Modifiable problem
* @author Alena
*
* Clients may extend and implement this interface
*/
public interface IProblemWorkingCopy extends IProblem {
/**
* Set severity for this this problem instance. Severity can only be changed in profile
* not by checker when printing problems.
* @param sev - codan severity
*/
void setSeverity(CodanSeverity sev);
void setEnabled(boolean checked);
/**
* Set checker enablement.
* @param enabled - true if problem is enabled in profile
*/
void setEnabled(boolean enabled);
void setMessagePattern(String message);
/**
* Set default message pattern. UI would call this method if user does not like default
* settings, checker should not use method, default message pattern should be set in
* checker extension
* @param messagePattern - java style message patter i.e. "Variable {0} is never used"
*/
void setMessagePattern(String messagePattern);
/**
* Set value for the checker parameter, checker may set value during initialization only
* @param key - key of the parameter
* @param value - parameter value
*/
public void setParameter(Object key, Object value);
public IProblemCategory getCategory();
/**
* Set parameter info object for the given problem, see {@link IProblemParameterInfo}
* @param info
*/
public void setParameterInfo(IProblemParameterInfo info);
}

View file

@ -13,36 +13,25 @@ package org.eclipse.cdt.codan.core.model;
import org.eclipse.core.resources.IFile;
/**
* Implementation of IProblemLocation
* Abstract Implementation of IProblemLocation
*
* Clients may extend this class.
*/
public class ProblemLocation implements IProblemLocation {
public abstract class ProblemLocation implements IProblemLocation {
protected IFile file;
protected int line;
protected int posStart;
protected int posEnd;
protected Object extra;
/**
* @param file
* @param line
* @param lineEnd
* @param posStart
* @param posEnd
*/
public ProblemLocation(IFile file, int line) {
protected ProblemLocation(IFile file, int line) {
this.file = file;
this.line = line;
this.posStart = -1;
this.posEnd = -1;
}
/**
* @param file
* @param startingLineNumber
* @param endingLineNumber
*/
public ProblemLocation(IFile file, int startChar, int endChar) {
protected ProblemLocation(IFile file, int startChar, int endChar) {
this.file = file;
this.line = -1;
this.posStart = startChar;

View file

@ -38,11 +38,13 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
public class CheckersRegisry implements Iterable<IChecker>, ICheckersRegistry {
private static final String EXTENSION_POINT_NAME = "checkers";
private static final String CHECKER_ELEMENT = "checker";
private static final String PROBLEM_ELEMENT = "problem";
private static final String CATEGORY_ELEMENT = "category";
private static final Object DEFAULT = "DEFAULT";
private static final String NAME_ATTR = "name"; //$NON-NLS-1$
private static final String ID_ATTR = "id"; //$NON-NLS-1$
private static final String EXTENSION_POINT_NAME = "checkers"; //$NON-NLS-1$
private static final String CHECKER_ELEMENT = "checker"; //$NON-NLS-1$
private static final String PROBLEM_ELEMENT = "problem"; //$NON-NLS-1$
private static final String CATEGORY_ELEMENT = "category"; //$NON-NLS-1$
private static final Object DEFAULT = "DEFAULT"; //$NON-NLS-1$
private Collection<IChecker> checkers = new ArrayList<IChecker>();
private static CheckersRegisry instance;
private HashMap<Object, IProblemProfile> profiles = new HashMap<Object, IProblemProfile>();
@ -55,10 +57,9 @@ public class CheckersRegisry implements Iterable<IChecker>, ICheckersRegistry {
}
private void readCheckersRegistry() {
IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint(
CodanCorePlugin.PLUGIN_ID, EXTENSION_POINT_NAME);
if (ep == null)
return;
IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint(CodanCorePlugin.PLUGIN_ID,
EXTENSION_POINT_NAME);
if (ep == null) return;
IConfigurationElement[] elements = ep.getConfigurationElements();
// process categories
for (int i = 0; i < elements.length; i++) {
@ -76,16 +77,14 @@ public class CheckersRegisry implements Iterable<IChecker>, ICheckersRegistry {
processChecker(configurationElement);
}
// init parameters for checkers with parameters
for (Iterator iterator = problemList.keySet().iterator(); iterator
.hasNext();) {
IChecker c = (IChecker) iterator.next();
for (Iterator<IChecker> iterator = problemList.keySet().iterator(); iterator.hasNext();) {
IChecker c = iterator.next();
if (c instanceof ICheckerWithParameters) {
Collection<IProblem> list = problemList.get(c);
for (Iterator iterator2 = list.iterator(); iterator2.hasNext();) {
IProblem p = (IProblem) iterator2.next();
for (Iterator<IProblem> iterator2 = list.iterator(); iterator2.hasNext();) {
IProblem p = iterator2.next();
if (p instanceof IProblemWorkingCopy) {
((ICheckerWithParameters) c)
.initParameters((IProblemWorkingCopy) p);
((ICheckerWithParameters) c).initParameters((IProblemWorkingCopy) p);
}
}
}
@ -97,15 +96,12 @@ public class CheckersRegisry implements Iterable<IChecker>, ICheckersRegistry {
*/
private void processCategories(IConfigurationElement configurationElement) {
if (configurationElement.getName().equals(CATEGORY_ELEMENT)) {
String id = getAtt(configurationElement, "id");
if (id == null)
return;
String name = getAtt(configurationElement, "name");
if (name == null)
return;
String id = getAtt(configurationElement, ID_ATTR);
if (id == null) return;
String name = getAtt(configurationElement, NAME_ATTR);
if (name == null) return;
CodanProblemCategory cat = new CodanProblemCategory(id, name);
String category = getAtt(configurationElement, "parentCategory",
false);
String category = getAtt(configurationElement, "parentCategory", false); //$NON-NLS-1$
addCategory(cat, category);
}
}
@ -116,27 +112,22 @@ public class CheckersRegisry implements Iterable<IChecker>, ICheckersRegistry {
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;
String id = getAtt(configurationElement, ID_ATTR);
if (id == null) return;
String name = getAtt(configurationElement, NAME_ATTR, false);
if (name == null) name = id;
IChecker checkerObj = null;
try {
Object checker = configurationElement
.createExecutableExtension("class");
Object checker = configurationElement.createExecutableExtension("class"); //$NON-NLS-1$
checkerObj = (IChecker) checker;
addChecker(checkerObj);
} catch (CoreException e) {
CodanCorePlugin.log(e);
return;
}
IConfigurationElement[] children1 = configurationElement
.getChildren("problemRef");
IConfigurationElement[] children1 = configurationElement.getChildren("problemRef"); //$NON-NLS-1$
boolean hasRef = false;
IConfigurationElement[] children2 = configurationElement
.getChildren(PROBLEM_ELEMENT);
IConfigurationElement[] children2 = configurationElement.getChildren(PROBLEM_ELEMENT);
if (children2 != null) {
for (IConfigurationElement ref : children2) {
IProblem p = processProblem(ref);
@ -147,8 +138,7 @@ public class CheckersRegisry implements Iterable<IChecker>, ICheckersRegistry {
if (children1 != null) {
for (IConfigurationElement ref : children1) {
hasRef = true;
IProblem p = getDefaultProfile().findProblem(
ref.getAttribute("refId"));
IProblem p = getDefaultProfile().findProblem(ref.getAttribute("refId")); //$NON-NLS-1$
addRefProblem(checkerObj, p);
}
}
@ -167,39 +157,30 @@ public class CheckersRegisry implements Iterable<IChecker>, ICheckersRegistry {
* @param configurationElement
* @return
*/
private CodanProblem processProblem(
IConfigurationElement configurationElement) {
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;
String id = getAtt(configurationElement, ID_ATTR);
if (id == null) return null;
String name = getAtt(configurationElement, NAME_ATTR);
if (name == null) name = id;
CodanProblem p = new CodanProblem(id, name);
String category = getAtt(configurationElement, "category", false);
if (category == null)
category = "org.eclipse.cdt.codan.core.categories.ProgrammingProblems";
String category = getAtt(configurationElement, "category", false); //$NON-NLS-1$
if (category == null) category = "org.eclipse.cdt.codan.core.categories.ProgrammingProblems"; //$NON-NLS-1$
addProblem(p, category);
return p;
}
return null;
}
private static String getAtt(IConfigurationElement configurationElement,
String name) {
private static String getAtt(IConfigurationElement configurationElement, String name) {
return getAtt(configurationElement, name, true);
}
private static String getAtt(IConfigurationElement configurationElement,
String name, boolean req) {
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: "
+ configurationElement.getName() + "." + name);
CodanCorePlugin.log("Extension " + configurationElement.getDeclaringExtension().getUniqueIdentifier() //$NON-NLS-1$
+ " missing required attribute: " + configurationElement.getName() + "." + name); //$NON-NLS-1$ //$NON-NLS-2$
return elementValue;
}
@ -213,8 +194,7 @@ public class CheckersRegisry implements Iterable<IChecker>, ICheckersRegistry {
}
public static CheckersRegisry getInstance() {
if (instance == null)
new CheckersRegisry();
if (instance == null) return new CheckersRegisry();
return instance;
}
@ -238,8 +218,7 @@ public class CheckersRegisry implements Iterable<IChecker>, ICheckersRegistry {
*/
public void addProblem(IProblem p, String category) {
IProblemCategory cat = getDefaultProfile().findCategory(category);
if (cat == null)
cat = getDefaultProfile().getRoot();
if (cat == null) cat = getDefaultProfile().getRoot();
((ProblemProfile) getDefaultProfile()).addProblem(p, cat);
}
@ -252,8 +231,7 @@ public class CheckersRegisry implements Iterable<IChecker>, ICheckersRegistry {
*/
public void addCategory(IProblemCategory p, String category) {
IProblemCategory cat = getDefaultProfile().findCategory(category);
if (cat == null)
cat = getDefaultProfile().getRoot();
if (cat == null) cat = getDefaultProfile().getRoot();
((ProblemProfile) getDefaultProfile()).addCategory(p, cat);
}
@ -310,15 +288,17 @@ public class CheckersRegisry implements Iterable<IChecker>, ICheckersRegistry {
} catch (CloneNotSupportedException e) {
wp = getDefaultProfile();
}
profiles.put(ResourcesPlugin.getWorkspace(), wp);
}
return wp;
}
public void updateProfile(IResource element, IProblemProfile profile) {
if (profile == null)
profiles.remove(element);
else
profiles.put(element, profile);
// updating profile can invalidate all cached profiles
IProblemProfile defaultProfile = getDefaultProfile();
profiles.clear();
profiles.put(DEFAULT, defaultProfile);
if (profile != null && element != null) profiles.put(element, profile);
}
/*
@ -335,17 +315,13 @@ public class CheckersRegisry implements Iterable<IChecker>, ICheckersRegistry {
try {
prof = (IProblemProfile) getWorkspaceProfile().clone();
// load default values
CodanPreferencesLoader loader = new CodanPreferencesLoader(
prof);
IEclipsePreferences node = new ProjectScope(
(IProject) element)
.getNode(CodanCorePlugin.PLUGIN_ID);
boolean useWorkspace = node.getBoolean(
PreferenceConstants.P_USE_PARENT, false);
CodanPreferencesLoader loader = new CodanPreferencesLoader(prof);
IEclipsePreferences node = new ProjectScope((IProject) element).getNode(CodanCorePlugin.PLUGIN_ID);
boolean useWorkspace = node.getBoolean(PreferenceConstants.P_USE_PARENT, false);
if (!useWorkspace) {
loader.load(node);
}
updateProfile(element, prof);
profiles.put(element, prof);
} catch (CloneNotSupportedException e) {
// cant
}
@ -366,20 +342,13 @@ public class CheckersRegisry implements Iterable<IChecker>, ICheckersRegistry {
* getResourceProfileWorkingCopy(org.eclipse.core.resources.IResource)
*/
public IProblemProfile getResourceProfileWorkingCopy(IResource element) {
if (element instanceof IProject) {
try {
IProblemProfile prof = (IProblemProfile) getWorkspaceProfile()
.clone();
// load default values
CodanPreferencesLoader loader = new CodanPreferencesLoader(prof);
IEclipsePreferences node = new ProjectScope((IProject) element)
.getNode(CodanCorePlugin.PLUGIN_ID);
loader.load(node);
return prof;
} catch (CloneNotSupportedException e) {
// cant
}
try {
IProblemProfile prof = (IProblemProfile) getResourceProfile(element).clone();
return prof;
} catch (CloneNotSupportedException e) {
// cant
return null;
}
return null;
}
}

View file

@ -1,9 +1,9 @@
package org.eclipse.cdt.codan.core;
package org.eclipse.cdt.codan.internal.core;
import java.util.ArrayList;
import java.util.Collection;
import org.eclipse.cdt.codan.internal.core.CodanBuilder;
import org.eclipse.cdt.codan.core.CodanRuntime;
import org.eclipse.cdt.codan.internal.core.model.CodanMarkerProblemReporter;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@ -12,14 +12,20 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
/**
*
* Application to support headless build
*
* @noextend This class is not intended to be extended by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
*/
public class CodanApplication implements IApplication {
private Collection<String> projects = new ArrayList<String>();
private boolean verbose = false;
private boolean all = false;
public Object start(IApplicationContext context) throws Exception {
String[] args = (String[]) context.getArguments().get(
"application.args");
String[] args = (String[]) context.getArguments().get("application.args"); //$NON-NLS-1$
if (args == null || args.length == 0) {
help();
return EXIT_OK;
@ -29,10 +35,9 @@ public class CodanApplication implements IApplication {
CodanRuntime runtime = CodanRuntime.getInstance();
runtime.setProblemReporter(new CodanMarkerProblemReporter() {
@Override
public void reportProblem(String id, int severity, IFile file,
int lineNumber, int startChar, int endChar, String message) {
System.out.println(file.getLocation() + ":" + lineNumber + ": "
+ message);
public void reportProblem(String id, int severity, IFile file, int lineNumber, int startChar, int endChar,
String message) {
System.out.println(file.getLocation() + ":" + lineNumber + ": " + message);
}
});
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
@ -44,8 +49,7 @@ public class CodanApplication implements IApplication {
log("Launching analysis on project " + project);
IProject wProject = root.getProject(project);
if (!wProject.exists()) {
System.err.println("Error: project " + project
+ " does not exist");
System.err.println("Error: project " + project + " does not exist");
continue;
}
wProject.accept(codanBuilder.new CodanResourceVisitor());
@ -58,8 +62,7 @@ public class CodanApplication implements IApplication {
* @param string
*/
private void log(String string) {
if (verbose)
System.err.println(string);
if (verbose) System.err.println(string);
}
/**

View file

@ -41,9 +41,8 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
public class CodanBuilder extends IncrementalProjectBuilder implements
ICodanBuilder, ICodanAstReconciler {
public static final String BUILDER_ID = "org.eclipse.cdt.codan.core.codanBuilder";
public class CodanBuilder extends IncrementalProjectBuilder implements ICodanBuilder, ICodanAstReconciler {
public static final String BUILDER_ID = "org.eclipse.cdt.codan.core.codanBuilder"; //$NON-NLS-1$
public class CodanDeltaVisitor implements IResourceDeltaVisitor {
/*
@ -63,17 +62,17 @@ public class CodanBuilder extends IncrementalProjectBuilder implements
public boolean visit(IResourceDelta delta) throws CoreException {
IResource resource = delta.getResource();
switch (delta.getKind()) {
case IResourceDelta.ADDED:
// handle added resource
processResource(resource, new NullProgressMonitor());
break;
case IResourceDelta.REMOVED:
// handle removed resource
break;
case IResourceDelta.CHANGED:
// handle changed resource
processResource(resource, new NullProgressMonitor());
break;
case IResourceDelta.ADDED:
// handle added resource
processResource(resource, new NullProgressMonitor());
break;
case IResourceDelta.REMOVED:
// handle removed resource
break;
case IResourceDelta.CHANGED:
// handle changed resource
processResource(resource, new NullProgressMonitor());
break;
}
// return true to continue visiting children.
return true;
@ -82,8 +81,7 @@ public class CodanBuilder extends IncrementalProjectBuilder implements
public class CodanResourceVisitor implements IResourceVisitor {
public boolean visit(IResource resource) {
if (!(resource instanceof IProject))
processResource(resource, new NullProgressMonitor());
if (!(resource instanceof IProject)) processResource(resource, new NullProgressMonitor());
// return true to continue visiting children.
return true;
}
@ -95,8 +93,9 @@ public class CodanBuilder extends IncrementalProjectBuilder implements
* @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 {
@SuppressWarnings("rawtypes")
@Override
protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
if (kind == FULL_BUILD) {
fullBuild(monitor);
} else {
@ -115,21 +114,16 @@ public class CodanBuilder extends IncrementalProjectBuilder implements
// CodanCorePlugin.PLUGIN_ID, "problems", "", null);
// System.err.println("set = " + string);
// delete general markers
IProblemReporter problemReporter = CodanRuntime.getInstance()
.getProblemReporter();
IProblemReporter problemReporter = CodanRuntime.getInstance().getProblemReporter();
if (problemReporter instanceof CodanMarkerProblemReporter) {
((CodanMarkerProblemReporter) problemReporter)
.deleteMarkers(resource);
((CodanMarkerProblemReporter) problemReporter).deleteMarkers(resource);
}
for (IChecker checker : CheckersRegisry.getInstance()) {
try {
boolean run = false;
if (checker.enabledInContext(resource))
run = true;
if (areProblemsForCheckerEnabled(checker, resource))
run = true;
if (run)
checker.processResource(resource);
if (checker.enabledInContext(resource)) run = true;
if (areProblemsForCheckerEnabled(checker, resource)) run = true;
if (run) checker.processResource(resource);
} catch (Throwable e) {
CodanCorePlugin.log(e);
}
@ -144,8 +138,7 @@ public class CodanBuilder extends IncrementalProjectBuilder implements
}
public void reconcileAst(IASTTranslationUnit ast, IProgressMonitor monitor) {
if (ast == null)
return;
if (ast == null) return;
String filePath = ast.getFilePath();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
@ -154,24 +147,20 @@ public class CodanBuilder extends IncrementalProjectBuilder implements
resources = root.findFilesForLocationURI(uri);
if (resources != null && resources.length > 0) {
IFile resource = resources[0];
IProblemReporter problemReporter = CodanRuntime.getInstance()
.getProblemReporter();
IProblemReporter problemReporter = CodanRuntime.getInstance().getProblemReporter();
// TODO: this is wrong - should not delete all markers -
// only those that contributed by the checker that we run now
if (problemReporter instanceof CodanMarkerProblemReporter) {
((CodanMarkerProblemReporter) problemReporter)
.deleteMarkers(resource);
((CodanMarkerProblemReporter) problemReporter).deleteMarkers(resource);
}
for (IChecker checker : CheckersRegisry.getInstance()) {
try {
boolean run = false;
if (checker.enabledInContext(resource))
run = true;
if (checker.enabledInContext(resource)) run = true;
if (areProblemsForCheckerEnabled(checker, resource)) {
run = true;
}
if (run && checker instanceof ICAstChecker
&& checker.runInEditor())
if (run && checker instanceof ICAstChecker && checker.runInEditor())
((ICAstChecker) checker).processAst(ast);
} catch (Throwable e) {
CodanCorePlugin.log(e);
@ -185,35 +174,28 @@ public class CodanBuilder extends IncrementalProjectBuilder implements
* @param resource
* @return
*/
private boolean areProblemsForCheckerEnabled(IChecker checker,
IResource resource) {
IProblemProfile resourceProfile = CheckersRegisry.getInstance()
.getResourceProfile(resource);
Collection<IProblem> refProblems = CheckersRegisry.getInstance()
.getRefProblems(checker);
for (Iterator iterator = refProblems.iterator(); iterator.hasNext();) {
IProblem p = (IProblem) iterator.next();
private boolean areProblemsForCheckerEnabled(IChecker checker, IResource resource) {
IProblemProfile resourceProfile = CheckersRegisry.getInstance().getResourceProfile(resource);
Collection<IProblem> refProblems = CheckersRegisry.getInstance().getRefProblems(checker);
for (Iterator<IProblem> iterator = refProblems.iterator(); iterator.hasNext();) {
IProblem p = iterator.next();
// we need to check problem enablement in particular profile
IProblem problem = resourceProfile.findProblem(p.getId());
if (problem == null)
throw new IllegalArgumentException("Id is not registered");
if (problem.isEnabled())
return true;
if (problem == null) throw new IllegalArgumentException("Id is not registered"); //$NON-NLS-1$
if (problem.isEnabled()) return true;
}
// no problem is enabled for this checker, skip the checker
return false;
}
protected void fullBuild(final IProgressMonitor monitor)
throws CoreException {
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 {
protected void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor) throws CoreException {
// the visitor does the work.
delta.accept(new CodanDeltaVisitor());
}

View file

@ -54,11 +54,10 @@ public class CodanPreferencesLoader {
*/
public void setProperty(String id, String s) {
IProblem prob = baseModel.findProblem(id);
if (!(prob instanceof CodanProblem))
return;
if (!(prob instanceof CodanProblem)) return;
String sevs = s;
boolean enabled = true;
if (sevs.startsWith("-")) {
if (sevs.startsWith("-")) { //$NON-NLS-1$
sevs = sevs.substring(1);
enabled = false;
}
@ -95,8 +94,7 @@ public class CodanPreferencesLoader {
*/
public String getProperty(String id) {
IProblem prob = baseModel.findProblem(id);
if (!(prob instanceof CodanProblem))
return null;
if (!(prob instanceof CodanProblem)) return null;
String enabled = prob.isEnabled() ? "" : "-";
String severity = prob.getSeverity().toString();
String res = enabled + severity;

View file

@ -20,7 +20,7 @@ public class CodeAnlysisNature implements IProjectNature {
/**
* ID of this project nature
*/
public static final String NATURE_ID = "org.eclipse.cdt.codan.core.codanNature";
public static final String NATURE_ID = "org.eclipse.cdt.codan.core.codanNature"; //$NON-NLS-1$
private IProject project;
/*
@ -32,9 +32,7 @@ public class CodeAnlysisNature implements IProjectNature {
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;
}
if (commands[i].getBuilderName().equals(CodanBuilder.BUILDER_ID)) { return; }
}
ICommand[] newCommands = new ICommand[commands.length + 1];
System.arraycopy(commands, 0, newCommands, 0, commands.length);
@ -57,8 +55,7 @@ public class CodeAnlysisNature implements IProjectNature {
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);
System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1);
description.setBuildSpec(newCommands);
project.setDescription(description, null);
return;

View file

@ -24,7 +24,6 @@ import org.eclipse.core.runtime.CoreException;
public class CodanMarkerProblemReporter implements IProblemReporter {
/*
* (non-Javadoc)
*
@ -36,27 +35,20 @@ public class CodanMarkerProblemReporter implements IProblemReporter {
public void reportProblem(String id, IProblemLocation loc, Object... args) {
IFile file = loc.getFile();
int lineNumber = loc.getLineNumber();
if (file == null)
throw new NullPointerException("file");
if (id == null)
throw new NullPointerException("id");
IProblem problem = CheckersRegisry.getInstance().getResourceProfile(
file).findProblem(id);
if (problem == null)
throw new IllegalArgumentException("Id is not registered");
if (problem.isEnabled() == false)
return; // skip
if (file == null) throw new NullPointerException("file"); //$NON-NLS-1$
if (id == null) throw new NullPointerException("id"); //$NON-NLS-1$
IProblem problem = CheckersRegisry.getInstance().getResourceProfile(file).findProblem(id);
if (problem == null) throw new IllegalArgumentException("Id is not registered"); //$NON-NLS-1$
if (problem.isEnabled() == false) return; // skip
int severity = problem.getSeverity().intValue();
String messagePattern = problem.getMessagePattern();
String message = id;
if (messagePattern == null) {
if (args != null && args.length > 0 && args[0] instanceof String)
message = (String) args[0];
if (args != null && args.length > 0 && args[0] instanceof String) message = (String) args[0];
} else {
MessageFormat.format(messagePattern, args);
}
reportProblem(id, severity, file, lineNumber, loc.getStartingChar(),
loc.getEndingChar(), message);
reportProblem(id, severity, file, lineNumber, loc.getStartingChar(), loc.getEndingChar(), message);
}
/*
@ -66,28 +58,22 @@ public class CodanMarkerProblemReporter implements IProblemReporter {
* org.eclipse.cdt.codan.core.model.IProblemReporter#reportProblem(java.
* lang.String, org.eclipse.core.resources.IFile, int, java.lang.String)
*/
public void reportProblem(String id, int severity, IFile file,
int lineNumber, int startChar, int endChar, String message) {
public void reportProblem(String id, int severity, IFile file, int lineNumber, int startChar, int endChar,
String message) {
try {
// Do not put in duplicates
IMarker[] cur = file.findMarkers(GENERIC_CODE_ANALYSIS_MARKER_TYPE,
false, IResource.DEPTH_ZERO);
IMarker[] cur = file.findMarkers(GENERIC_CODE_ANALYSIS_MARKER_TYPE, false, IResource.DEPTH_ZERO);
if (cur != null) {
for (IMarker element : cur) {
int line = ((Integer) element
.getAttribute(IMarker.LINE_NUMBER)).intValue();
int line = ((Integer) element.getAttribute(IMarker.LINE_NUMBER)).intValue();
if (line == lineNumber) {
String mesg = (String) element
.getAttribute(IMarker.MESSAGE);
int sev = ((Integer) element
.getAttribute(IMarker.SEVERITY)).intValue();
if (sev == severity && mesg.equals(message))
return;
String mesg = (String) element.getAttribute(IMarker.MESSAGE);
int sev = ((Integer) element.getAttribute(IMarker.SEVERITY)).intValue();
if (sev == severity && mesg.equals(message)) return;
}
}
}
IMarker marker = file
.createMarker(GENERIC_CODE_ANALYSIS_MARKER_TYPE);
IMarker marker = file.createMarker(GENERIC_CODE_ANALYSIS_MARKER_TYPE);
marker.setAttribute(IMarker.MESSAGE, message);
marker.setAttribute(IMarker.SEVERITY, severity);
marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
@ -101,8 +87,7 @@ public class CodanMarkerProblemReporter implements IProblemReporter {
public void deleteMarkers(IResource file) {
try {
file.deleteMarkers(GENERIC_CODE_ANALYSIS_MARKER_TYPE, false,
IResource.DEPTH_ZERO);
file.deleteMarkers(GENERIC_CODE_ANALYSIS_MARKER_TYPE, false, IResource.DEPTH_ZERO);
} catch (CoreException ce) {
ce.printStackTrace();
}
@ -111,8 +96,7 @@ public class CodanMarkerProblemReporter implements IProblemReporter {
public void deleteAllMarkers() {
try {
// TODO delete contributed markers too
ResourcesPlugin.getWorkspace().getRoot().deleteMarkers(
GENERIC_CODE_ANALYSIS_MARKER_TYPE, false,
ResourcesPlugin.getWorkspace().getRoot().deleteMarkers(GENERIC_CODE_ANALYSIS_MARKER_TYPE, false,
IResource.DEPTH_INFINITE);
} catch (CoreException e) {
// TODO Auto-generated catch block

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.codan.internal.core.model;
import java.util.HashMap;
import org.eclipse.cdt.codan.core.model.CodanSeverity;
import org.eclipse.cdt.codan.core.model.IProblemCategory;
import org.eclipse.cdt.codan.core.model.IProblemParameterInfo;
@ -24,6 +25,7 @@ public class CodanProblem implements IProblemWorkingCopy {
private boolean enabled = true;
private HashMap<Object, Object> parameters = new HashMap<Object, Object>(0);
private IProblemParameterInfo parameterInfo;
private boolean frozen;
public CodanSeverity getSeverity() {
return severity;
@ -32,6 +34,7 @@ public class CodanProblem implements IProblemWorkingCopy {
public CodanProblem(String problemId, String name) {
this.id = problemId;
this.name = name;
this.frozen = false;
}
public String getName() {
@ -57,8 +60,7 @@ public class CodanProblem implements IProblemWorkingCopy {
}
public void setSeverity(CodanSeverity sev) {
if (sev == null)
throw new NullPointerException();
if (sev == null) throw new NullPointerException();
this.severity = sev;
}
@ -101,11 +103,20 @@ public class CodanProblem implements IProblemWorkingCopy {
return message;
}
protected void freeze() {
frozen = true;
}
/**
* @param message
* the message to set
*/
public void setMessagePattern(String message) {
checkSet();
this.message = message;
}
protected void checkSet() {
if (frozen) throw new IllegalStateException("Object is unmodifieble"); //$NON-NLS-1$
}
}

View file

@ -41,40 +41,36 @@ public class CodanProblemCategory implements IProblemCategory, Cloneable {
}
public IProblemElement[] getChildren() {
return (IProblemElement[]) list.toArray(new IProblemElement[list.size()]);
return list.toArray(new IProblemElement[list.size()]);
}
public void addChild(IProblemElement p) {
list.add(p);
}
public IProblem findProblem(String id) {
Object[] children = this.getChildren();
public static IProblem findProblem(IProblemCategory c, String id) {
Object[] children = c.getChildren();
for (Object object : children) {
if (object instanceof IProblemCategory) {
IProblemCategory cat = (IProblemCategory) object;
IProblem found = cat.findProblem(id);
if (found != null)
return found;
IProblem found = findProblem(cat, id);
if (found != null) return found;
} else if (object instanceof IProblem) {
IProblem p = (IProblem) object;
if (p.getId().equals(id))
return p;
if (p.getId().equals(id)) return p;
}
}
return null;
}
public IProblemCategory findCategory(String id) {
if (getId().equals(id))
return this;
Object[] children = getChildren();
public static IProblemCategory findCategory(IProblemCategory cat, String id) {
if (cat.getId().equals(id)) return cat;
Object[] children = cat.getChildren();
for (Object object : children) {
if (object instanceof IProblemCategory) {
IProblemCategory cat = (IProblemCategory) object;
IProblemCategory found = cat.findCategory(id);
if (found != null)
return found;
IProblemCategory cat2 = (IProblemCategory) object;
IProblemCategory found = findCategory(cat2, id);
if (found != null) return found;
}
}
return null;
@ -90,8 +86,7 @@ public class CodanProblemCategory implements IProblemCategory, Cloneable {
try {
CodanProblemCategory clone = (CodanProblemCategory) super.clone();
clone.list = new ArrayList<IProblemElement>();
for (Iterator<IProblemElement> iterator = this.list.iterator(); iterator
.hasNext();) {
for (Iterator<IProblemElement> iterator = this.list.iterator(); iterator.hasNext();) {
IProblemElement child = iterator.next();
clone.list.add((IProblemElement) child.clone());
}

View file

@ -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.internal.core.model;
import org.eclipse.cdt.codan.core.model.ProblemLocation;
import org.eclipse.core.resources.IFile;
/**
* Codan Problem Location, so far same as abstract class
*
*/
public class CodanProblemLocation extends ProblemLocation {
public CodanProblemLocation(IFile file, int startChar, int endChar) {
super(file, startChar, endChar);
}
protected CodanProblemLocation(IFile file, int line) {
super(file, line);
}
}

View file

@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2009 Alena Laskavaia
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Alena Laskavaia - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.codan.internal.core.model;
import org.eclipse.cdt.codan.core.model.IProblemLocation;
import org.eclipse.cdt.codan.core.model.IProblemLocationFactory;
import org.eclipse.core.resources.IFile;
/**
* Factory class that allows to create problem locations
*
*/
public class ProblemLocationFactory implements IProblemLocationFactory {
/* (non-Javadoc)
* @see org.eclipse.cdt.codan.core.model.IProblemLocationFactory#createProblemLocation(org.eclipse.core.resources.IFile, int)
*/
public IProblemLocation createProblemLocation(IFile file, int line) {
return new CodanProblemLocation(file, line);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.codan.core.model.IProblemLocationFactory#createProblemLocation(org.eclipse.core.resources.IFile, int, int)
*/
public IProblemLocation createProblemLocation(IFile file, int startChar, int endChar) {
return new CodanProblemLocation(file, startChar, endChar);
}
}

View file

@ -22,8 +22,7 @@ import org.eclipse.cdt.codan.core.model.IProblemProfile;
*
*/
public class ProblemProfile implements IProblemProfile, Cloneable {
private IProblemCategory rootCategory = new CodanProblemCategory("root",
"root");
private IProblemCategory rootCategory = new CodanProblemCategory("root", "root"); //$NON-NLS-1$ //$NON-NLS-2$
/*
* (non-Javadoc)
@ -33,7 +32,7 @@ public class ProblemProfile implements IProblemProfile, Cloneable {
* .String)
*/
public IProblem findProblem(String id) {
return getRoot().findProblem(id);
return CodanProblemCategory.findProblem(getRoot(), id);
}
/*
@ -51,8 +50,7 @@ public class ProblemProfile implements IProblemProfile, Cloneable {
* @param root
* @param problems
*/
protected void collectProblems(IProblemCategory parent,
Collection<IProblem> problems) {
protected void collectProblems(IProblemCategory parent, Collection<IProblem> problems) {
Object[] children = parent.getChildren();
for (Object object : children) {
if (object instanceof IProblemCategory) {
@ -69,13 +67,12 @@ public class ProblemProfile implements IProblemProfile, Cloneable {
}
public void addProblem(IProblem p, IProblemCategory cat) {
if (cat == null)
cat = getRoot();
if (cat == null) cat = getRoot();
((CodanProblemCategory) cat).addChild(p);
}
public IProblemCategory findCategory(String id) {
return getRoot().findCategory(id);
return CodanProblemCategory.findCategory(getRoot(), id);
}
/*
@ -87,8 +84,7 @@ public class ProblemProfile implements IProblemProfile, Cloneable {
public Object clone() {
try {
ProblemProfile clone = (ProblemProfile) super.clone();
clone.rootCategory = (IProblemCategory) ((CodanProblemCategory) this.rootCategory)
.clone();
clone.rootCategory = (IProblemCategory) ((CodanProblemCategory) this.rootCategory).clone();
return clone;
} catch (CloneNotSupportedException e) {
return this;

View file

@ -20,9 +20,15 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.cdt.codan.ui" version="2">
<resource path="src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java" type="org.eclipse.cdt.codan.internal.ui.preferences.CodanPreferencePage">
<filter id="640712815">
<message_arguments>
<message_argument value="ICheckersRegistry"/>
<message_argument value="CodanPreferencePage"/>
<message_argument value="updateProfile(IResource, IProblemProfile)"/>
</message_arguments>
</filter>
</resource>
</component>

View file

@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: Code Analyzers Framework
Bundle-SymbolicName: org.eclipse.cdt.codan.ui; singleton:=true
Bundle-Version: 1.0.0
Bundle-Activator: org.eclipse.cdt.codan.ui.CodanUIActivator
Bundle-Activator: org.eclipse.cdt.codan.internal.ui.CodanUIActivator
Bundle-Vendor: Eclipse
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,

View file

@ -3,7 +3,3 @@ output.. = bin/
bin.includes = plugin.xml,\
META-INF/,\
.
src.includes = src/,\
plugin.xml,\
build.properties,\
META-INF/

View file

@ -40,7 +40,7 @@ public class CodanCReconciler implements ICReconcilingListener {
*
*/
private void initialize() {
// TODO Auto-generated method stub
// nothing?
}
/*
@ -51,7 +51,7 @@ public class CodanCReconciler implements ICReconcilingListener {
* ()
*/
public void aboutToBeReconciled() {
// TODO Auto-generated method stub
// nothing
}
/*

View file

@ -1,4 +1,4 @@
package org.eclipse.cdt.codan.ui;
package org.eclipse.cdt.codan.internal.ui;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;

View file

@ -21,7 +21,7 @@ public class BuildPropertyPage extends FieldEditorPreferencePage implements
*
*/
public BuildPropertyPage() {
setPreferenceStore(org.eclipse.cdt.codan.ui.CodanUIActivator.getDefault()
setPreferenceStore(org.eclipse.cdt.codan.internal.ui.CodanUIActivator.getDefault()
.getPreferenceStore());
}

View file

@ -71,7 +71,7 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
protected String getPageId() {
return "org.eclipse.cdt.codan.internal.ui.preferences.CodanPreferencePage";
return "org.eclipse.cdt.codan.internal.ui.preferences.CodanPreferencePage"; //$NON-NLS-1$
}
/**
@ -153,7 +153,7 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
*/
@Override
public boolean performOk() {
if (isPropertyPage())
//if (isPropertyPage())
getRegistry().updateProfile((IResource) getElement(), null);
return super.performOk();
}

View file

@ -25,7 +25,7 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer {
* @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
*/
public void initializeDefaultPreferences() {
IPreferenceStore store = org.eclipse.cdt.codan.ui.CodanUIActivator
IPreferenceStore store = org.eclipse.cdt.codan.internal.ui.CodanUIActivator
.getDefault().getPreferenceStore();
store.setDefault(PreferenceConstants.P_RUN_ON_BUILD, false);
}