mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
[279740] - Trying to separate public API and some clean-up
This commit is contained in:
parent
0888fe2ffe
commit
ac758f71fb
28 changed files with 655 additions and 121 deletions
|
@ -11,5 +11,4 @@ Require-Bundle: org.eclipse.core.runtime,
|
|||
Bundle-ActivationPolicy: lazy
|
||||
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
||||
Export-Package: org.eclipse.cdt.codan.core,
|
||||
org.eclipse.cdt.codan.core.builder,
|
||||
org.eclipse.cdt.codan.core.model
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<builder
|
||||
hasNature="true">
|
||||
<run
|
||||
class="org.eclipse.cdt.codan.core.builder.CodanBuilder">
|
||||
class="org.eclipse.cdt.codan.internal.core.CodanBuilder">
|
||||
</run>
|
||||
</builder>
|
||||
</extension>
|
||||
|
@ -20,7 +20,7 @@
|
|||
point="org.eclipse.core.resources.natures">
|
||||
<runtime>
|
||||
<run
|
||||
class="org.eclipse.cdt.codan.core.builder.CodeAnlysisNature">
|
||||
class="org.eclipse.cdt.codan.internal.core.CodeAnlysisNature">
|
||||
</run>
|
||||
</runtime>
|
||||
<builder
|
||||
|
|
|
@ -3,9 +3,8 @@ package org.eclipse.cdt.codan.core;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.cdt.codan.core.builder.CodanBuilder;
|
||||
import org.eclipse.cdt.codan.core.model.CodanProblemReporter;
|
||||
import org.eclipse.cdt.codan.core.model.CodanRuntime;
|
||||
import org.eclipse.cdt.codan.internal.core.CodanBuilder;
|
||||
import org.eclipse.cdt.codan.internal.core.model.CodanMarkerProblemReporter;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
|
@ -28,10 +27,10 @@ public class CodanApplication implements IApplication {
|
|||
extractArguments(args);
|
||||
CodanBuilder codanBuilder = new CodanBuilder();
|
||||
CodanRuntime runtime = CodanRuntime.getInstance();
|
||||
runtime.setProblemReporter(new CodanProblemReporter() {
|
||||
runtime.setProblemReporter(new CodanMarkerProblemReporter() {
|
||||
@Override
|
||||
public void reportProblem(String id, IFile file, int lineNumber,
|
||||
String 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);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.eclipse.cdt.codan.core;
|
||||
|
||||
import org.eclipse.cdt.codan.internal.core.CodeAnlysisNature;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Plugin;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
|
@ -13,6 +14,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 NATURE_ID = CodeAnlysisNature.NATURE_ID;
|
||||
// The shared instance
|
||||
private static CodanCorePlugin plugin;
|
||||
|
||||
|
|
|
@ -8,12 +8,12 @@
|
|||
* Contributors:
|
||||
* Alena Laskavaia - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.builder;
|
||||
package org.eclipse.cdt.codan.core;
|
||||
|
||||
import org.eclipse.cdt.codan.core.model.CodanProblem;
|
||||
import org.eclipse.cdt.codan.core.model.CodanSeverity;
|
||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemProfile;
|
||||
import org.eclipse.cdt.codan.internal.core.model.CodanProblem;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
|
||||
/**
|
|
@ -0,0 +1,54 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Alena Laskavaia
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Alena Laskavaia - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core;
|
||||
|
||||
import org.eclipse.cdt.codan.core.model.ICheckersRegistry;
|
||||
import org.eclipse.cdt.codan.core.model.ICodanAstReconciler;
|
||||
import org.eclipse.cdt.codan.core.model.ICodanBuilder;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemReporter;
|
||||
import org.eclipse.cdt.codan.internal.core.CheckersRegisry;
|
||||
import org.eclipse.cdt.codan.internal.core.CodanBuilder;
|
||||
import org.eclipse.cdt.codan.internal.core.model.CodanMarkerProblemReporter;
|
||||
|
||||
/**
|
||||
* Runtime singleton class to get access to Codan framework parts
|
||||
*
|
||||
*/
|
||||
public class CodanRuntime {
|
||||
private static CodanRuntime instance = new CodanRuntime();
|
||||
private IProblemReporter problemReporter = new CodanMarkerProblemReporter();
|
||||
private CodanBuilder builder = new CodanBuilder();
|
||||
private CheckersRegisry checkers = CheckersRegisry.getInstance();
|
||||
|
||||
public IProblemReporter getProblemReporter() {
|
||||
return problemReporter;
|
||||
}
|
||||
|
||||
public void setProblemReporter(IProblemReporter reporter) {
|
||||
problemReporter = reporter;
|
||||
}
|
||||
|
||||
public static CodanRuntime getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ICodanBuilder getBuilder() {
|
||||
return builder;
|
||||
}
|
||||
|
||||
public ICodanAstReconciler getAstQuickBuilder() {
|
||||
return builder;
|
||||
}
|
||||
|
||||
public ICheckersRegistry getChechersRegistry() {
|
||||
return checkers;
|
||||
}
|
||||
}
|
|
@ -10,22 +10,54 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.model;
|
||||
|
||||
import org.eclipse.cdt.codan.core.CodanRuntime;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
||||
public abstract class AbstractChecker implements IChecker {
|
||||
String name;
|
||||
protected String name;
|
||||
|
||||
public AbstractChecker() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if checker is enabled in context of resource, if returns false checker's "processResource"
|
||||
* method won't be called
|
||||
*/
|
||||
public boolean enabledInContext(IResource res) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports a simple problem for given file and line
|
||||
* @param id - problem id
|
||||
* @param file - file
|
||||
* @param lineNumber - line
|
||||
* @param arg - problem argument, if problem does not define error message it will be error message
|
||||
* (not recommended because of internationalization)
|
||||
*/
|
||||
public void reportProblem(String id, IFile file, int lineNumber,
|
||||
String message) {
|
||||
CodanRuntime.getInstance().getProblemReporter().reportProblem(id, file,
|
||||
lineNumber, message);
|
||||
String arg) {
|
||||
getProblemReporter().reportProblem(id, new ProblemLocation(file,
|
||||
lineNumber), arg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reports a simple problem for given file and line, error message comes from problem definition
|
||||
* @param id - problem id
|
||||
* @param file - file
|
||||
* @param lineNumber - line
|
||||
*/
|
||||
public void reportProblem(String id, IFile file, int lineNumber) {
|
||||
getProblemReporter().reportProblem(id, new ProblemLocation(file,
|
||||
lineNumber), new Object[]{});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return problem reporter for given checker
|
||||
*/
|
||||
protected IProblemReporter getProblemReporter() {
|
||||
return CodanRuntime.getInstance().getProblemReporter();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,13 +79,15 @@ public abstract class AbstractIndexAstChecker extends AbstractChecker implements
|
|||
|
||||
public void reportProblem(String id, IASTNode astNode, String message) {
|
||||
IASTFileLocation astLocation = astNode.getFileLocation();
|
||||
IFile astFile = file;
|
||||
if (astFile == null) {
|
||||
IPath location = new Path(astLocation.getFileName());
|
||||
astFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(location);
|
||||
IFile astFile = ResourcesPlugin.getWorkspace().getRoot()
|
||||
.getFileForLocation(location);
|
||||
if (astFile == null) {
|
||||
astFile = file;
|
||||
}
|
||||
|
||||
CodanRuntime.getInstance().getProblemReporter().reportProblem(id,
|
||||
astFile, astLocation.getStartingLineNumber(), message);
|
||||
getProblemReporter().reportProblem(
|
||||
id,
|
||||
new ProblemLocation(astFile, astLocation
|
||||
.getStartingLineNumber()), message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Alena Laskavaia
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Alena Laskavaia - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.model;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
||||
/**
|
||||
* @author Alena
|
||||
*
|
||||
*/
|
||||
public interface ICheckersRegistry {
|
||||
public abstract Iterator<IChecker> iterator();
|
||||
|
||||
public abstract void addChecker(IChecker checker);
|
||||
|
||||
public abstract void addProblem(IProblem p, String category);
|
||||
|
||||
public abstract void addCategory(IProblemCategory p, String category);
|
||||
|
||||
public abstract void addRefProblem(IChecker c, IProblem p);
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public abstract IProblemProfile getDefaultProfile();
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public abstract IProblemProfile getWorkspaceProfile();
|
||||
|
||||
/**
|
||||
* @param element
|
||||
* @return
|
||||
*/
|
||||
public abstract IProblemProfile getResourceProfile(IResource element);
|
||||
|
||||
/**
|
||||
* @param element
|
||||
* @return
|
||||
*/
|
||||
public abstract IProblemProfile getResourceProfileWorkingCopy(
|
||||
IResource element);
|
||||
|
||||
/**
|
||||
* Set profile for resource. This method is called by UI, and should not be
|
||||
* called by clients directly
|
||||
*
|
||||
* @param resource
|
||||
* - resource
|
||||
* @param profile
|
||||
* - problems profile
|
||||
*/
|
||||
public abstract void updateProfile(IResource resource,
|
||||
IProblemProfile profile);
|
||||
}
|
|
@ -10,23 +10,13 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.model;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
/**
|
||||
* Runtime singleton class to get access to Codan framework parts
|
||||
* @author Alena
|
||||
*
|
||||
*/
|
||||
public class CodanRuntime {
|
||||
private static CodanRuntime instance = new CodanRuntime();
|
||||
private CodanProblemReporter problemReporter = new CodanProblemReporter();
|
||||
|
||||
public CodanProblemReporter getProblemReporter() {
|
||||
return problemReporter;
|
||||
}
|
||||
|
||||
public void setProblemReporter(CodanProblemReporter reporter) {
|
||||
problemReporter = reporter;
|
||||
}
|
||||
|
||||
public static CodanRuntime getInstance() {
|
||||
return instance;
|
||||
}
|
||||
public interface ICodanAstReconciler {
|
||||
public void reconcileAst(IASTTranslationUnit ast, IProgressMonitor monitor);
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Alena Laskavaia
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Alena Laskavaia - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.model;
|
||||
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
/**
|
||||
* @author Alena
|
||||
*
|
||||
*/
|
||||
public interface ICodanBuilder {
|
||||
public void processResource(IResource resource, IProgressMonitor monitor);
|
||||
}
|
|
@ -10,6 +10,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.model;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface IProblem extends IProblemElement {
|
||||
String getName();
|
||||
|
||||
|
@ -19,5 +21,17 @@ public interface IProblem extends IProblemElement {
|
|||
|
||||
CodanSeverity getSeverity();
|
||||
|
||||
IProblemCategory getCategory();
|
||||
String getMessagePattern();
|
||||
|
||||
void setSeverity(CodanSeverity sev);
|
||||
|
||||
void setEnabled(boolean checked);
|
||||
|
||||
void setMessagePattern(String message);
|
||||
|
||||
public void setProperty(Object key, Object value);
|
||||
|
||||
public Object getProperty(Object key);
|
||||
|
||||
public Collection<Object> getPropertyKeys();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Alena Laskavaia
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Alena Laskavaia - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.model;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
||||
/**
|
||||
* Interface to describe problem location. Usually contains file and linenumber,
|
||||
* also supports character positions for sophisticated errors.
|
||||
*
|
||||
*/
|
||||
public interface IProblemLocation {
|
||||
/**
|
||||
*
|
||||
* @return File for the problem - absolute full paths
|
||||
*/
|
||||
IFile getFile();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Primary line for the problem, lines start with 1 for file. If -1
|
||||
* char position would be used.
|
||||
*/
|
||||
int getLineNumber();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return character position where problem starts within file, first char
|
||||
* is 0, inclusive, tab count as one. If unknown return -1.
|
||||
*/
|
||||
int getStartingChar();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return character position where problem ends within file, first char is
|
||||
* 0, exclusive, tab count as one. If unknown return -1.
|
||||
*/
|
||||
int getEndingChar();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return extra data for problem location, checker specific, can be
|
||||
* backtrace for example
|
||||
*/
|
||||
Object getData();
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Alena Laskavaia
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Alena Laskavaia - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.model;
|
||||
|
||||
|
||||
/**
|
||||
* IProblemReporter - interface to report problems
|
||||
*
|
||||
*/
|
||||
public interface IProblemReporter {
|
||||
/**
|
||||
* Report a problem with "problemId" id on location determined by "loc",
|
||||
* using problem specific error message customised by args.
|
||||
* @param problemId - id of the problem registers with checker
|
||||
* @param loc - location object
|
||||
* @param args - custom args, can be null, in this case default message is reported
|
||||
*/
|
||||
public void reportProblem(String problemId, IProblemLocation loc,
|
||||
Object ... args);
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Alena Laskavaia
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Alena Laskavaia - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.model;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
||||
/**
|
||||
* Implementation of IProblemLocation
|
||||
*
|
||||
*/
|
||||
public class ProblemLocation implements IProblemLocation {
|
||||
protected IFile file;
|
||||
protected int line;
|
||||
protected int posStart;
|
||||
protected int posEnd;
|
||||
protected Object extra;
|
||||
|
||||
/**
|
||||
* @param file
|
||||
* @param line
|
||||
* @param lineEnd
|
||||
* @param posStart
|
||||
* @param posEnd
|
||||
*/
|
||||
public ProblemLocation(IFile file, int line) {
|
||||
this.file = file;
|
||||
this.line = line;
|
||||
this.posStart = -1;
|
||||
this.posEnd = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param file
|
||||
* @param startingLineNumber
|
||||
* @param endingLineNumber
|
||||
*/
|
||||
public ProblemLocation(IFile file, int startChar, int endChar) {
|
||||
this.file = file;
|
||||
this.line = -1;
|
||||
this.posStart = startChar;
|
||||
this.posEnd = endChar;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.codan.core.model.IProblemLocation#getData()
|
||||
*/
|
||||
public Object getData() {
|
||||
return extra;
|
||||
}
|
||||
|
||||
public void setData(Object data) {
|
||||
this.extra = data;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.codan.core.model.IProblemLocation#getFile()
|
||||
*/
|
||||
public IFile getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.codan.core.model.IProblemLocation#getLine()
|
||||
*/
|
||||
public int getLineNumber() {
|
||||
return getStartingLineNumber();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.codan.core.model.IProblemLocation#getStartLine()
|
||||
*/
|
||||
public int getStartingLineNumber() {
|
||||
return line;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.codan.core.model.IProblemLocation#getStartPos()
|
||||
*/
|
||||
public int getStartingChar() {
|
||||
return posStart;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.codan.core.model.IProblemLocation#getEndingChar()
|
||||
*/
|
||||
public int getEndingChar() {
|
||||
return posEnd;
|
||||
}
|
||||
}
|
|
@ -13,6 +13,8 @@ package org.eclipse.cdt.codan.core.model;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.cdt.codan.internal.core.model.CodanProblemCategory;
|
||||
|
||||
/**
|
||||
* @author Alena
|
||||
*
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* Contributors:
|
||||
* Alena Laskavaia - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.model;
|
||||
package org.eclipse.cdt.codan.internal.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -16,8 +16,16 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
||||
import org.eclipse.cdt.codan.core.CodanPreferencesLoader;
|
||||
import org.eclipse.cdt.codan.core.PreferenceConstants;
|
||||
import org.eclipse.cdt.codan.core.builder.CodanPreferencesLoader;
|
||||
import org.eclipse.cdt.codan.core.model.IChecker;
|
||||
import org.eclipse.cdt.codan.core.model.ICheckersRegistry;
|
||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemCategory;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemProfile;
|
||||
import org.eclipse.cdt.codan.core.model.ProblemProfile;
|
||||
import org.eclipse.cdt.codan.internal.core.model.CodanProblem;
|
||||
import org.eclipse.cdt.codan.internal.core.model.CodanProblemCategory;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ProjectScope;
|
||||
|
@ -28,7 +36,7 @@ import org.eclipse.core.runtime.IExtensionPoint;
|
|||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
|
||||
public class CheckersRegisry implements Iterable<IChecker> {
|
||||
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";
|
||||
|
@ -176,6 +184,9 @@ public class CheckersRegisry implements Iterable<IChecker> {
|
|||
return elementValue;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#iterator()
|
||||
*/
|
||||
public Iterator<IChecker> iterator() {
|
||||
return checkers.iterator();
|
||||
}
|
||||
|
@ -186,10 +197,16 @@ public class CheckersRegisry implements Iterable<IChecker> {
|
|||
return instance;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#addChecker(org.eclipse.cdt.codan.core.model.IChecker)
|
||||
*/
|
||||
public void addChecker(IChecker checker) {
|
||||
checkers.add(checker);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#addProblem(org.eclipse.cdt.codan.core.model.IProblem, java.lang.String)
|
||||
*/
|
||||
public void addProblem(IProblem p, String category) {
|
||||
IProblemCategory cat = getDefaultProfile().findCategory(category);
|
||||
if (cat == null)
|
||||
|
@ -197,6 +214,9 @@ public class CheckersRegisry implements Iterable<IChecker> {
|
|||
((ProblemProfile) getDefaultProfile()).addProblem(p, cat);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#addCategory(org.eclipse.cdt.codan.core.model.IProblemCategory, java.lang.String)
|
||||
*/
|
||||
public void addCategory(IProblemCategory p, String category) {
|
||||
IProblemCategory cat = getDefaultProfile().findCategory(category);
|
||||
if (cat == null)
|
||||
|
@ -204,18 +224,21 @@ public class CheckersRegisry implements Iterable<IChecker> {
|
|||
((ProblemProfile) getDefaultProfile()).addCategory(p, cat);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#addRefProblem(org.eclipse.cdt.codan.core.model.IChecker, org.eclipse.cdt.codan.core.model.IProblem)
|
||||
*/
|
||||
public void addRefProblem(IChecker c, IProblem p) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#getDefaultProfile()
|
||||
*/
|
||||
public IProblemProfile getDefaultProfile() {
|
||||
return profiles.get(DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#getWorkspaceProfile()
|
||||
*/
|
||||
public IProblemProfile getWorkspaceProfile() {
|
||||
IProblemProfile wp = profiles.get(ResourcesPlugin.getWorkspace());
|
||||
|
@ -239,9 +262,8 @@ public class CheckersRegisry implements Iterable<IChecker> {
|
|||
profiles.put(element, profile);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param element
|
||||
* @return
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#getResourceProfile(org.eclipse.core.resources.IResource)
|
||||
*/
|
||||
public IProblemProfile getResourceProfile(IResource element) {
|
||||
IProblemProfile prof = profiles.get(element);
|
||||
|
@ -274,9 +296,8 @@ public class CheckersRegisry implements Iterable<IChecker> {
|
|||
return prof;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param element
|
||||
* @return
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#getResourceProfileWorkingCopy(org.eclipse.core.resources.IResource)
|
||||
*/
|
||||
public IProblemProfile getResourceProfileWorkingCopy(IResource element) {
|
||||
if (element instanceof IProject) {
|
|
@ -8,17 +8,20 @@
|
|||
* Contributors:
|
||||
* Alena Laskavaia - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.builder;
|
||||
package org.eclipse.cdt.codan.internal.core;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
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.CodanRuntime;
|
||||
import org.eclipse.cdt.codan.core.CodanRuntime;
|
||||
import org.eclipse.cdt.codan.core.model.ICAstChecker;
|
||||
import org.eclipse.cdt.codan.core.model.IChecker;
|
||||
import org.eclipse.cdt.codan.core.model.ICodanAstReconciler;
|
||||
import org.eclipse.cdt.codan.core.model.ICodanBuilder;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemReporter;
|
||||
import org.eclipse.cdt.codan.internal.core.model.CodanMarkerProblemReporter;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
@ -32,8 +35,10 @@ import org.eclipse.core.resources.IncrementalProjectBuilder;
|
|||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
|
||||
public class CodanBuilder extends IncrementalProjectBuilder {
|
||||
public class CodanBuilder extends IncrementalProjectBuilder implements
|
||||
ICodanBuilder, ICodanAstReconciler {
|
||||
public static final String BUILDER_ID = "org.eclipse.cdt.codan.core.codanBuilder";
|
||||
|
||||
public class CodanDeltaVisitor implements IResourceDeltaVisitor {
|
||||
|
@ -44,19 +49,26 @@ public class CodanBuilder extends IncrementalProjectBuilder {
|
|||
* org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse
|
||||
* .core.resources.IResourceDelta)
|
||||
*/
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.cdt.codan.internal.core.ICodanBuilder#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);
|
||||
processResource(resource, new NullProgressMonitor());
|
||||
break;
|
||||
case IResourceDelta.REMOVED:
|
||||
// handle removed resource
|
||||
break;
|
||||
case IResourceDelta.CHANGED:
|
||||
// handle changed resource
|
||||
processResource(resource);
|
||||
processResource(resource, new NullProgressMonitor());
|
||||
break;
|
||||
}
|
||||
// return true to continue visiting children.
|
||||
|
@ -66,7 +78,8 @@ public class CodanBuilder extends IncrementalProjectBuilder {
|
|||
|
||||
public class CodanResourceVisitor implements IResourceVisitor {
|
||||
public boolean visit(IResource resource) {
|
||||
processResource(resource);
|
||||
if (!(resource instanceof IProject))
|
||||
processResource(resource, new NullProgressMonitor());
|
||||
// return true to continue visiting children.
|
||||
return true;
|
||||
}
|
||||
|
@ -93,12 +106,17 @@ public class CodanBuilder extends IncrementalProjectBuilder {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void processResource(IResource resource) {
|
||||
public void processResource(IResource resource, IProgressMonitor monitor) {
|
||||
// String string = Platform.getPreferencesService().getString(
|
||||
// CodanCorePlugin.PLUGIN_ID, "problems", "", null);
|
||||
// System.err.println("set = " + string);
|
||||
// delete general markers
|
||||
CodanRuntime.getInstance().getProblemReporter().deleteMarkers(resource);
|
||||
IProblemReporter problemReporter = CodanRuntime.getInstance()
|
||||
.getProblemReporter();
|
||||
if (problemReporter instanceof CodanMarkerProblemReporter) {
|
||||
((CodanMarkerProblemReporter) problemReporter)
|
||||
.deleteMarkers(resource);
|
||||
}
|
||||
for (IChecker checker : CheckersRegisry.getInstance()) {
|
||||
try {
|
||||
boolean run = false;
|
||||
|
@ -110,12 +128,18 @@ public class CodanBuilder extends IncrementalProjectBuilder {
|
|||
CodanCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
if (resource instanceof IProject) {
|
||||
try {
|
||||
resource.accept(getResourceVisitor());
|
||||
} catch (CoreException e) {
|
||||
CodanCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void reconcileAst(IASTTranslationUnit ast, IProgressMonitor monitor) {
|
||||
if (ast == null)
|
||||
return;
|
||||
|
||||
String filePath = ast.getFilePath();
|
||||
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||
IWorkspaceRoot root = workspace.getRoot();
|
||||
|
@ -124,8 +148,12 @@ public class CodanBuilder extends IncrementalProjectBuilder {
|
|||
resources = root.findFilesForLocationURI(uri);
|
||||
if (resources != null && resources.length > 0) {
|
||||
IFile resource = resources[0];
|
||||
CodanRuntime.getInstance().getProblemReporter().deleteMarkers(
|
||||
resource);
|
||||
IProblemReporter problemReporter = CodanRuntime.getInstance()
|
||||
.getProblemReporter();
|
||||
if (problemReporter instanceof CodanMarkerProblemReporter) {
|
||||
((CodanMarkerProblemReporter) problemReporter)
|
||||
.deleteMarkers(resource);
|
||||
}
|
||||
for (IChecker checker : CheckersRegisry.getInstance()) {
|
||||
try {
|
||||
boolean run = false;
|
||||
|
@ -153,4 +181,13 @@ public class CodanBuilder extends IncrementalProjectBuilder {
|
|||
// the visitor does the work.
|
||||
delta.accept(new CodanDeltaVisitor());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.codan.core.model.ICodanBuilder#getResourceVisitor()
|
||||
*/
|
||||
public CodanResourceVisitor getResourceVisitor() {
|
||||
return new CodanResourceVisitor();
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@
|
|||
* Contributors:
|
||||
* Alena Laskavaia - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.builder;
|
||||
package org.eclipse.cdt.codan.internal.core;
|
||||
|
||||
import org.eclipse.core.resources.ICommand;
|
||||
import org.eclipse.core.resources.IProject;
|
|
@ -8,31 +8,67 @@
|
|||
* Contributors:
|
||||
* Alena Laskavaia - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.model;
|
||||
package org.eclipse.cdt.codan.internal.core.model;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemLocation;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemReporter;
|
||||
import org.eclipse.cdt.codan.internal.core.CheckersRegisry;
|
||||
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 CodanProblemReporter {
|
||||
public class CodanMarkerProblemReporter implements IProblemReporter {
|
||||
public static final String GENERIC_CODE_ANALYSIS_MARKER_TYPE = "org.eclipse.cdt.codan.core.codanProblem";
|
||||
|
||||
public void reportProblem(String id, IFile file, int lineNumber,
|
||||
String message) {
|
||||
try {
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.cdt.codan.core.model.IProblemReporter#reportProblem(java.
|
||||
* lang.String, org.eclipse.cdt.codan.core.model.IProblemLocation,
|
||||
* java.lang.Object[])
|
||||
*/
|
||||
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);
|
||||
IProblem problem = CheckersRegisry.getInstance().getResourceProfile(
|
||||
file).findProblem(id);
|
||||
if (problem == null)
|
||||
throw new IllegalArgumentException("Id is not registered");
|
||||
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];
|
||||
} else {
|
||||
MessageFormat.format(messagePattern, args);
|
||||
}
|
||||
reportProblem(id, severity, file, lineNumber, loc.getStartingChar(),
|
||||
loc.getEndingChar(), message);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* 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) {
|
||||
try {
|
||||
// Do not put in duplicates
|
||||
IMarker[] cur = file.findMarkers(GENERIC_CODE_ANALYSIS_MARKER_TYPE,
|
||||
false, IResource.DEPTH_ZERO);
|
||||
|
@ -54,10 +90,10 @@ public class CodanProblemReporter {
|
|||
.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);
|
||||
marker.setAttribute(IMarker.PROBLEM, id);
|
||||
marker.setAttribute(IMarker.CHAR_END, endChar);
|
||||
marker.setAttribute(IMarker.CHAR_START, startChar);
|
||||
} catch (CoreException e) {
|
||||
e.printStackTrace();
|
||||
}
|
|
@ -8,21 +8,30 @@
|
|||
* Contributors:
|
||||
* Alena Laskavaia - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.model;
|
||||
package org.eclipse.cdt.codan.internal.core.model;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.eclipse.cdt.codan.core.model.CodanSeverity;
|
||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemCategory;
|
||||
|
||||
public class CodanProblem implements IProblem {
|
||||
private String id;
|
||||
private String name;
|
||||
private String message;
|
||||
private CodanSeverity severity = CodanSeverity.Warning;
|
||||
private boolean enabled = true;
|
||||
private HashMap<Object, Object> properties = new HashMap<Object, Object>(0);
|
||||
|
||||
public CodanSeverity getSeverity() {
|
||||
return severity;
|
||||
}
|
||||
|
||||
public CodanProblem(String id2, String name2) {
|
||||
this.id = id2;
|
||||
this.name = name2;
|
||||
public CodanProblem(String problemId, String name) {
|
||||
this.id = problemId;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
@ -66,4 +75,32 @@ public class CodanProblem implements IProblem {
|
|||
public Object clone() throws CloneNotSupportedException {
|
||||
return super.clone();
|
||||
}
|
||||
|
||||
public void setProperty(Object key, Object value) {
|
||||
properties.put(key, value);
|
||||
}
|
||||
|
||||
public Object getProperty(Object key) {
|
||||
return properties.get(key);
|
||||
};
|
||||
|
||||
public Collection<Object> getPropertyKeys() {
|
||||
return properties.keySet();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.codan.core.model.IProblem#getMessagePattern()
|
||||
*/
|
||||
public String getMessagePattern() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message the message to set
|
||||
*/
|
||||
public void setMessagePattern(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
|
@ -8,11 +8,15 @@
|
|||
* Contributors:
|
||||
* Alena Laskavaia - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.model;
|
||||
package org.eclipse.cdt.codan.internal.core.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemCategory;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemElement;
|
||||
|
||||
public class CodanProblemCategory implements IProblemCategory, Cloneable {
|
||||
private String id;
|
||||
private String name;
|
|
@ -55,7 +55,7 @@ public class BuildPropertyPage extends FieldEditorPreferencePage implements
|
|||
// "Confirmation",
|
||||
// "Do you want to remove existing problems? If build is disabled they won't be updated anymore.");
|
||||
// if (openQuestion == true) {
|
||||
// CodanProblemReporter.deleteAllMarkers();
|
||||
// CodanMarkerProblemReporter.deleteAllMarkers();
|
||||
// }
|
||||
// }
|
||||
return true;
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
package org.eclipse.cdt.codan.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
||||
import org.eclipse.cdt.codan.core.model.CheckersRegisry;
|
||||
import org.eclipse.cdt.codan.core.CodanRuntime;
|
||||
import org.eclipse.cdt.codan.core.model.ICheckersRegistry;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemProfile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
|
@ -50,14 +51,21 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
|||
* editor knows how to save and restore itself.
|
||||
*/
|
||||
public void createFieldEditors() {
|
||||
profile = isPropertyPage() ? CheckersRegisry.getInstance()
|
||||
profile = isPropertyPage() ? getRegistry()
|
||||
.getResourceProfileWorkingCopy((IResource) getElement())
|
||||
: CheckersRegisry.getInstance().getWorkspaceProfile();
|
||||
: getRegistry().getWorkspaceProfile();
|
||||
CheckedTreeEditor checkedTreeEditor = new ProblemsTreeEditor(
|
||||
getFieldEditorParent(), profile);
|
||||
addField(checkedTreeEditor);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected ICheckersRegistry getRegistry() {
|
||||
return CodanRuntime.getInstance().getChechersRegistry();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
@ -66,8 +74,7 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements
|
|||
@Override
|
||||
public boolean performOk() {
|
||||
if (isPropertyPage())
|
||||
CheckersRegisry.getInstance().updateProfile(
|
||||
(IResource) getElement(), null);
|
||||
getRegistry().updateProfile((IResource) getElement(), null);
|
||||
return super.performOk();
|
||||
}
|
||||
|
||||
|
|
|
@ -10,9 +10,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.cdt.codan.core.CodanPreferencesLoader;
|
||||
import org.eclipse.cdt.codan.core.PreferenceConstants;
|
||||
import org.eclipse.cdt.codan.core.builder.CodanPreferencesLoader;
|
||||
import org.eclipse.cdt.codan.core.model.CodanProblem;
|
||||
import org.eclipse.cdt.codan.core.model.CodanSeverity;
|
||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemCategory;
|
||||
|
@ -139,8 +138,8 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
|
|||
|
||||
public void checkStateChanged(CheckStateChangedEvent event) {
|
||||
Object element = event.getElement();
|
||||
if (element instanceof CodanProblem) {
|
||||
((CodanProblem) element).setEnabled(event.getChecked());
|
||||
if (element instanceof IProblem) {
|
||||
((IProblem) element).setEnabled(event.getChecked());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -209,7 +208,7 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
|
|||
});
|
||||
column2.setEditingSupport(new EditingSupport(getTreeViewer()) {
|
||||
protected boolean canEdit(Object element) {
|
||||
return element instanceof CodanProblem;
|
||||
return element instanceof IProblem;
|
||||
}
|
||||
|
||||
protected CellEditor getCellEditor(Object element) {
|
||||
|
@ -218,13 +217,13 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
|
|||
}
|
||||
|
||||
protected Object getValue(Object element) {
|
||||
return ((CodanProblem) element).getSeverity().intValue();
|
||||
return ((IProblem) element).getSeverity().intValue();
|
||||
}
|
||||
|
||||
protected void setValue(Object element, Object value) {
|
||||
int index = ((Integer) value).intValue();
|
||||
CodanSeverity val = CodanSeverity.values()[index];
|
||||
((CodanProblem) element).setSeverity(val);
|
||||
((IProblem) element).setSeverity(val);
|
||||
getTreeViewer().update(element, null);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.ui;
|
||||
|
||||
import org.eclipse.cdt.codan.core.builder.CodanBuilder;
|
||||
import org.eclipse.cdt.codan.core.CodanRuntime;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.text.ICReconcilingListener;
|
||||
|
@ -64,7 +64,8 @@ public class CodanCReconciler implements ICReconcilingListener {
|
|||
*/
|
||||
public void reconciled(IASTTranslationUnit ast, boolean force,
|
||||
IProgressMonitor progressMonitor) {
|
||||
new CodanBuilder().reconcileAst(ast, progressMonitor);
|
||||
CodanRuntime.getInstance().getAstQuickBuilder().reconcileAst(ast,
|
||||
progressMonitor);
|
||||
// System.err.println("ast reconsiled");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,9 +12,13 @@ package org.eclipse.cdt.codan.ui.actions;
|
|||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.codan.core.builder.CodanBuilder;
|
||||
import org.eclipse.cdt.codan.core.CodanRuntime;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
|
@ -25,23 +29,38 @@ public class RunCodeAnalysis implements IObjectActionDelegate {
|
|||
private ISelection sel;
|
||||
|
||||
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
|
||||
// TODO Auto-generated method stub
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void run(IAction action) {
|
||||
for (Iterator iterator = ((IStructuredSelection) sel).iterator(); iterator
|
||||
.hasNext();) {
|
||||
Job job = new Job("Running Code Analysis") {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected IStatus run(final IProgressMonitor monitor) {
|
||||
IStructuredSelection ss = (IStructuredSelection) sel;
|
||||
int count = ss.size();
|
||||
monitor.beginTask(getName(), count * 100);
|
||||
if (monitor.isCanceled())
|
||||
return Status.CANCEL_STATUS;
|
||||
for (Iterator iterator = ss.iterator(); iterator.hasNext();) {
|
||||
Object o = iterator.next();
|
||||
if (o instanceof IResource) {
|
||||
IResource res = (IResource) o;
|
||||
try {
|
||||
res.accept(new CodanBuilder().new CodanResourceVisitor());
|
||||
} catch (CoreException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
SubProgressMonitor subMon = new SubProgressMonitor(
|
||||
monitor, 100);
|
||||
CodanRuntime.getInstance().getBuilder()
|
||||
.processResource(res, subMon);
|
||||
if (subMon.isCanceled())
|
||||
return Status.CANCEL_STATUS;
|
||||
}
|
||||
if (monitor.isCanceled())
|
||||
return Status.CANCEL_STATUS;
|
||||
}
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
};
|
||||
job.setUser(true);
|
||||
job.schedule();
|
||||
}
|
||||
|
||||
public void selectionChanged(IAction action, ISelection selection) {
|
||||
|
|
|
@ -12,7 +12,7 @@ package org.eclipse.cdt.codan.ui.actions;
|
|||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.codan.core.builder.CodeAnlysisNature;
|
||||
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -77,7 +77,7 @@ public class ToggleNatureAction implements IObjectActionDelegate {
|
|||
description = project.getDescription();
|
||||
String[] natures = description.getNatureIds();
|
||||
for (int i = 0; i < natures.length; ++i) {
|
||||
if (CodeAnlysisNature.NATURE_ID.equals(natures[i])) {
|
||||
if (CodanCorePlugin.NATURE_ID.equals(natures[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ public class ToggleNatureAction implements IObjectActionDelegate {
|
|||
IProjectDescription description = project.getDescription();
|
||||
String[] natures = description.getNatureIds();
|
||||
for (int i = 0; i < natures.length; ++i) {
|
||||
if (CodeAnlysisNature.NATURE_ID.equals(natures[i])) {
|
||||
if (CodanCorePlugin.NATURE_ID.equals(natures[i])) {
|
||||
if (add == false) {
|
||||
// Remove the nature
|
||||
String[] newNatures = new String[natures.length - 1];
|
||||
|
@ -120,7 +120,7 @@ public class ToggleNatureAction implements IObjectActionDelegate {
|
|||
// Add the nature
|
||||
String[] newNatures = new String[natures.length + 1];
|
||||
System.arraycopy(natures, 0, newNatures, 0, natures.length);
|
||||
newNatures[natures.length] = CodeAnlysisNature.NATURE_ID;
|
||||
newNatures[natures.length] = CodanCorePlugin.NATURE_ID;
|
||||
description.setNatureIds(newNatures);
|
||||
project.setDescription(description, null);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue