Skip to content

Commit

Permalink
Update #23 Constructors and attributes #16 function name
Browse files Browse the repository at this point in the history
Checker attributes are now set on new instance. Javadoc added and the
function applyRules was renamed to check.
  • Loading branch information
Omar WALDMANN committed May 30, 2017
1 parent bd6202d commit 8b8deb1
Show file tree
Hide file tree
Showing 17 changed files with 403 additions and 332 deletions.
1 change: 1 addition & 0 deletions fr.cnes.analysis.tools.analyzer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.checkstyle
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* i-Code CNES is a static code analyser.
* This software is a free software, under the terms of the Eclipse Public License version 1.0.
* http://www.eclipse.org/legal/epl-v10.html
*
*/
package fr.cnes.analysis.tools.analyzer;

import fr.cnes.analysis.tools.analyzer.datas.AbstractMetric;
Expand Down Expand Up @@ -28,7 +34,7 @@
* </p>
* <p>
* <h2>Available methods</h2> The service method to call to run an analysis are
* {@link #applyRules(List, List, List)} and
* {@link #check(List, List, List)} and
* {@link #computeMetrics(List, List, List)}. Once, it returns after a moment
* the results thanks to {@link CallableMetricAnalyzer} &
* {@link CallableRuleAnalyzer}.
Expand Down Expand Up @@ -77,7 +83,7 @@ public class Analyzer {
private static int THREAD_NB = 1;

/**
* <h1>{@link #applyRules(List, List, List)}</h1>
* <h1>{@link #check(List, List, List)}</h1>
* <p>
* This method apply all rules of the different contributions set in
* parameter except the one excluded. File in parameters are being analyzed
Expand All @@ -101,9 +107,9 @@ public class Analyzer {
* @throws JFlexException
* when the syntax analysis failed.
*/
public List<CheckResult> applyRules(List<File> pInputFiles, List<String> pLanguageIds,
public List<CheckResult> check(List<File> pInputFiles, List<String> pLanguageIds,
List<String> pExcludedCheckIds) throws IOException, JFlexException {
final String methodName = "applyRules";
final String methodName = "check";
LOGGER.entering(this.getClass().getName(), methodName);
List<String> languageIds = pLanguageIds;
if (languageIds == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* i-Code CNES is a static code analyser.
* This software is a free software, under the terms of the Eclipse Public License version 1.0.
* http://www.eclipse.org/legal/epl-v10.html
*
*/
package fr.cnes.analysis.tools.analyzer;

import fr.cnes.analysis.tools.analyzer.datas.AbstractMetric;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* i-Code CNES is a static code analyser.
* This software is a free software, under the terms of the Eclipse Public License version 1.0.
* http://www.eclipse.org/legal/epl-v10.html
*
*/
package fr.cnes.analysis.tools.analyzer;

import fr.cnes.analysis.tools.analyzer.datas.AbstractRule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,142 +6,143 @@
*/
package fr.cnes.analysis.tools.analyzer.datas;

import fr.cnes.analysis.tools.analyzer.exception.JFlexException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

import fr.cnes.analysis.tools.analyzer.exception.JFlexException;

/**
* Abstract class implementing the generic application of a rule over a file.
* For each rule and file, an instance is made.
*
*/
public abstract class AbstractRule extends AbstractEvaluation {
/** Analysed file. */
private File file;

/** List of violations found during analysis. **/
private List<CheckResult> checkResults;

private CheckResult checkResult;// TODO à voir pour l'enlever

/**
* Getter for the list of violations.
*
* @return the violations
*/
public List<CheckResult> getCheckResults() {
return this.checkResults;
}

/**
* Setter for the list of violations.
*
* @param pCheckResults
* the violations to set
*/
public void setViolations(final List<CheckResult> pCheckResults) {
this.checkResults = pCheckResults;
}

/**
* Run analysis for considering file and rule.
*
* @return list of {@link fr.cnes.analysis.tools.analyzer.datas.Violation}
* found during analysis
* @throws IOException
* IO problem occurred
* @throws JFlexException
* JFlex error during analysis
*/
public abstract List<CheckResult> run() throws IOException, JFlexException;

/**
* Method to add a violation, knowing its location and line.
*
* @param pLocation
* the location
*
* @param pMessage
* result's message
* @param pLine
* the line
* @throws JFlexException
* exception thrown when cloning error appears
*/
protected void setError(final String pLocation, final String pMessage, final int pLine) throws JFlexException {

// TODO set the langage id
CheckResult checkResult = new CheckResult(this.getContribution().getAttribute("name"),
this.getContribution().getAttribute("id"), "");
checkResult.setLine(pLine);
checkResult.setLocation(pLocation);
checkResult.setMessage(pMessage);
checkResult.setFile(file);
this.checkResults.add(checkResult);

}

/**
* Method to add a violation, knowing its location and line.
*
* @param pLocation
* the location
*
* @param pValue
* result's message
* @param pLine
* the line
* @throws JFlexException
* exception thrown when cloning error appears
*/
protected void setError(final String pLocation, final float pValue, final int pLine) throws JFlexException {

// TODO set the langage id
CheckResult checkResult = new CheckResult(this.getContribution().getAttribute("name"),
this.getContribution().getAttribute("id"), "");
checkResult.setLine(pLine);
checkResult.setLocation(pLocation);
checkResult.setValue(pValue);
checkResult.setFile(file);
this.checkResults.add(checkResult);

}

/*
* (non-Javadoc)
*
* @see
* fr.cnes.analysis.tools.analyzer.datas.AbstractEvaluation#setInputFile
* (org.eclipse.core.runtime.IPath)
*/
@Override
public void setInputFile(final File file) throws FileNotFoundException {
this.checkResults = new LinkedList<CheckResult>();
this.checkResult = new CheckResult(this.getContribution().getAttribute("name"),
this.getContribution().getAttribute("id"), ""); // TODO si on
// garde,
// remplir le
// langage id
this.checkResult.setFile(file);
this.file = file;
}

/**
* @return the checkResult
*/
public CheckResult getCheckResult() {
return checkResult;
}

/**
* @param checkResult
* the checkResult to set
*/
public void setCheckResult(CheckResult checkResult) {
this.checkResult = checkResult;
}
/** Analysed file. */
private File file;

/** List of violations found during analysis. **/
private List<CheckResult> checkResults;

private CheckResult checkResult;// TODO à voir pour l'enlever

/**
* Getter for the list of violations.
*
* @return the violations
*/
public List<CheckResult> getCheckResults() {
return this.checkResults;
}

/**
* Setter for the list of violations.
*
* @param pCheckResults
* the violations to set
*/
public void setViolations(final List<CheckResult> pCheckResults) {
this.checkResults = pCheckResults;
}

/**
* Run analysis for considering file and rule.
*
* @return list of {@link fr.cnes.analysis.tools.analyzer.datas.Violation}
* found during analysis
* @throws IOException
* IO problem occurred
* @throws JFlexException
* JFlex error during analysis
*/
public abstract List<CheckResult> run() throws IOException, JFlexException;

/**
* Method to add a violation, knowing its location and line.
*
* @param pLocation
* the location
*
* @param pMessage
* result's message
* @param pLine
* the line
* @throws JFlexException
* exception thrown when cloning error appears
*/
protected void setError(final String pLocation, final String pMessage, final int pLine)
throws JFlexException {
// TODO Improve how is set the language id
CheckResult checkResult = new CheckResult(this.getContribution().getAttribute("name"),
this.getContribution().getAttribute("id"),
this.getContribution().getDeclaringExtension().getExtensionPointUniqueIdentifier());
checkResult.setLine(pLine);
checkResult.setLocation(pLocation);
checkResult.setMessage(pMessage);
checkResult.setFile(file);
this.checkResults.add(checkResult);

}

/**
* Method to add a violation, knowing its location and line.
*
* @param pLocation
* the location
*
* @param pValue
* result's message
* @param pLine
* the line
* @throws JFlexException
* exception thrown when cloning error appears
*/
protected void setError(final String pLocation, final float pValue, final int pLine)
throws JFlexException {

// TODO Improve how is set the language id
CheckResult checkResult = new CheckResult(this.getContribution().getAttribute("name"),
this.getContribution().getAttribute("id"),
this.getContribution().getDeclaringExtension().getExtensionPointUniqueIdentifier());
checkResult.setLine(pLine);
checkResult.setLocation(pLocation);
checkResult.setValue(pValue);
checkResult.setFile(file);
this.checkResults.add(checkResult);

}

/*
* (non-Javadoc)
*
* @see
* fr.cnes.analysis.tools.analyzer.datas.AbstractEvaluation#setInputFile
* (org.eclipse.core.runtime.IPath)
*/
@Override
public void setInputFile(final File pInputFile) throws FileNotFoundException {
this.checkResults = new LinkedList<CheckResult>();
// TODO improve language identifier retrieval
this.checkResult = new CheckResult(this.getContribution().getAttribute("name"),
this.getContribution().getAttribute("id"),
this.getContribution().getDeclaringExtension().getExtensionPointUniqueIdentifier());
this.checkResult.setFile(pInputFile);
this.file = pInputFile;
}

/**
* @return the checkResult
*/
public CheckResult getCheckResult() {
return checkResult;
}

/**
* @param pCheckResult
* the checkResult to set
*/
public void setCheckResult(CheckResult pCheckResult) {
this.checkResult = pCheckResult;
}
}
Loading

0 comments on commit 8b8deb1

Please sign in to comment.