Skip to content

Commit

Permalink
Merge pull request cnescatlab#86 from WaldoFR/V3-dev
Browse files Browse the repository at this point in the history
JFlexException improvement and lexer's lists verification
  • Loading branch information
dupuisa authored Aug 28, 2017
2 parents 6b99a2c + 9d6790c commit b02ea49
Show file tree
Hide file tree
Showing 189 changed files with 2,228 additions and 581 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,19 @@ public List<CheckResult> check(List<File> pInputFiles, List<String> pLanguageIds
Runtime.getRuntime().gc();
}
analyzers.add(service.submit(callableAnalysis));

}
}
}
for (Future<List<CheckResult>> analysis : analyzers) {
analysisResultCheckResult.addAll(analysis.get());
}
} catch (NullContributionException | ExecutionException | InterruptedException
| CoreException e) {
} catch (NullContributionException | InterruptedException | CoreException e) {

LOGGER.throwing(this.getClass().getName(), methodName, e);
} catch (ExecutionException exception) {
if (exception.getCause() instanceof JFlexException) {
throw (JFlexException) exception.getCause();
}
}
return analysisResultCheckResult;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,17 @@ public File getInputFile() {
return inputFile;
}

/**
* @param str
* to set to ASCII decimal
* @return
* @return ASCII decimal of <code>str</code>
*/
public static final String toASCII(final String str) {
String code = "";
for (char character : str.toCharArray()) {
code += (int) character;
}
return code;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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.exception;

/**
Expand All @@ -12,25 +12,129 @@
*/
public class JFlexException extends Exception {

/**
* Serial Version UID.
*/
private static final long serialVersionUID = 4198004753881804823L;

/**
* Default constructor.
*/
public JFlexException() {
super();
}

/**
* Constructor with original exception.
*
* @param exception
* the original exception.
*/
public JFlexException(final Exception exception) {
super(exception);
}
/**
* Serial Version UID.
*/
private static final long serialVersionUID = 4198004753881804823L;
/** fileName causing the exception */
private String fileName;
/** Line location of the exception */
private int line;
/** Column location of the exception */
private int column;
/** Last word scanned during the analysis */
private String lastScan;
/** Error message defined by the analyzer */
private String message;
/** Rules causing the exception */
private String ruleName;

/**
* Default constructor.
*/
public JFlexException() {
super();
}

/**
* @param pRuleName
* Rules causing the exception
* @param pFileName
* fileName causing the exception
* @param pMessage
* Error message defined by the analyzer
* @param pLastScan
* Last word scanned during the analysis
* @param pLine
* Line location of the exception
* @param pColumn
* Column location of the exception
*/
public JFlexException(final String pRuleName, final String pFileName, final String pMessage,
final String pLastScan, final int pLine, final int pColumn) {
super(errorMessage(pRuleName, pFileName, pMessage, pLastScan, pLine, pColumn));
this.ruleName = pRuleName;
this.fileName = pFileName;
this.message = pMessage;
this.line = pLine;
this.column = pColumn;
}

/**
* @param pRuleName
* Rules causing the exception
* @param pFileName
* fileName causing the exception
* @param pMessage
* Error message defined by the analyzer
* @param pLastScan
* Last word scanned during the analysis
* @param pLine
* Line location of the exception
* @param pColumn
* Column location of the exception
* @return Exception message related to the parameters.
*/
private static String errorMessage(String pRuleName, String pFileName, String pMessage,
String pLastScan, int pLine, int pColumn) {
final String message = "i-Code CNES analysis encountered a problem.\n\n" + pMessage + "\n"
+ "CheckerId : " + pRuleName + "\n" + "File : " + pFileName + "\n" + "Line:"
+ pLine + "\n" + "Column:" + pColumn + "\n"

+ "Last word scanned :" + pLastScan + "\n"
+ "You can report this issue on : https://github.com/dupuisa/i-CodeCNES/issues/";
return message;
}

/**
* Constructor with original exception.
*
* @param exception
* the original exception.
*/
public JFlexException(final Exception exception) {
super(exception);
}

/**
* @return the fileName
*/
public final String getFileName() {
return fileName;
}

/**
* @return the line
*/
public final int getLine() {
return line;
}

/**
* @return the column
*/
public final int getColumn() {
return column;
}

/**
* @return the lastScan
*/
public final String getLastScan() {
return lastScan;
}

/**
* @return the message
*/
public final String getErrorMessage() {
return message;
}

/**
* @return the ruleName
*/
public final String getRuleName() {
return ruleName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import fr.cnes.analysis.tools.analyzer.metrics.FunctionMetricValue;
%class GeneratedMetricName
%extends AbstractChecker
%public
%column
%line

/* This three lines are not meant to be modified. */
Expand Down Expand Up @@ -84,6 +85,7 @@ STRING = \'[^\']*\' | \"[^\"]*\"
/* in this section. */
%{
String location = "MAIN PROGRAM";
private String parsedFileName;
FileMetricValue fileValue;

public GeneratedMetricName(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ import fr.cnes.analysis.tools.analyzer.exception.JFlexException;
%extends AbstractChecker
%public
%ignorecase
%line
%column
%line


%function run
%yylexthrow JFlexException
Expand Down Expand Up @@ -77,10 +78,11 @@ STRING = \'[^\']*\' | \"[^\"]*\"


String location = "MAIN PROGRAM";
private String parsedFileName;
float numCiclomatic = 0;
float numCiclomaticTotal = 0;
int functionLine = 0;
String parsedFileName;


public F77METComplexitySimplified() {

Expand All @@ -90,7 +92,8 @@ STRING = \'[^\']*\' | \"[^\"]*\"
public void setInputFile(File file) throws FileNotFoundException {
super.setInputFile(file);
LOGGER.finest("begin method setInputFile");
this.zzReader = new FileReader(new Path(file.getAbsolutePath()).toOSString());
this.parsedFileName = file.toString();
this.zzReader = new FileReader(new Path(file.getAbsolutePath()).toOSString());
this.parsedFileName = file.toString();
LOGGER.finest("end method setInputFile");
}
Expand Down Expand Up @@ -228,6 +231,8 @@ STRING = \'[^\']*\' | \"[^\"]*\"


[^] {
String errorMessage = "Class"+this.getClass().getName()+"\nIllegal character <" + yytext() + ">\nFile :"+ this.parsedFileName+"\nat line:"+yyline+" column:"+yycolumn;
throw new JFlexException(new Exception(errorMessage));
}
String parsedWord = "Word ["+yytext()+"], code [" + toASCII(yytext()) + "]";
final String errorMessage = "Analysis failure : Your file could not be analyzed. Please verify that it was encoded in an UNIX format.";
throw new JFlexException(this.getClass().getName(), parsedFileName,
errorMessage, parsedWord, yyline, yycolumn);
}
17 changes: 11 additions & 6 deletions fr.cnes.analysis.tools.fortran77.metrics/lex/F77METLineOfCode.lex
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ import fr.cnes.analysis.tools.analyzer.exception.JFlexException;
%extends AbstractChecker
%public
%ignorecase
%line
%column
%line


%function run
%yylexthrow JFlexException
Expand Down Expand Up @@ -66,10 +67,11 @@ SPACE = [\ \r\f\t]
private static final Logger LOGGER = Logger.getLogger(F77METLineOfCode.class.getName());

String location = "MAIN PROGRAM";
private String parsedFileName;
float numLines = 0;
float numTotal = 0;
int functionLine = 0;
String parsedFileName;



public F77METLineOfCode(){
Expand All @@ -79,7 +81,8 @@ SPACE = [\ \r\f\t]
public void setInputFile(File file) throws FileNotFoundException {
super.setInputFile(file);
LOGGER.finest("begin method setInputFile");
this.zzReader = new FileReader(new Path(file.getAbsolutePath()).toOSString());
this.parsedFileName = file.toString();
this.zzReader = new FileReader(new Path(file.getAbsolutePath()).toOSString());
this.parsedFileName = file.toString();
LOGGER.finest("end method setInputFile");
}
Expand Down Expand Up @@ -260,6 +263,8 @@ SPACE = [\ \r\f\t]
/* DEFAULT STATE */
/********************/
[^] {
String errorMessage = "Class"+this.getClass().getName()+"\nIllegal character <" + yytext() + ">\nFile :"+ this.parsedFileName+"\nat line:"+yyline+" column:"+yycolumn;
throw new JFlexException(new Exception(errorMessage));
}
String parsedWord = "Word ["+yytext()+"], code [" + toASCII(yytext()) + "]";
final String errorMessage = "Analysis failure : Your file could not be analyzed. Please verify that it was encoded in an UNIX format.";
throw new JFlexException(this.getClass().getName(), parsedFileName,
errorMessage, parsedWord, yyline, yycolumn);
}
17 changes: 11 additions & 6 deletions fr.cnes.analysis.tools.fortran77.metrics/lex/F77METNesting.lex
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ import fr.cnes.analysis.tools.analyzer.exception.JFlexException;
%extends AbstractChecker
%public
%ignorecase
%line
%column
%line


%function run
%yylexthrow JFlexException
Expand Down Expand Up @@ -73,13 +74,14 @@ SMBL = \& | \+ | \$


String location = "MAIN PROGRAM";
private String parsedFileName;
List<String> identifiers = new LinkedList<String>();
float numImbrics = 0;
float numMaxImbrics = 0;
float numImbricsTotal = 0;
boolean end = true;
int functionLine = 0;
String parsedFileName;


public F77METNesting(){
}
Expand All @@ -88,7 +90,8 @@ SMBL = \& | \+ | \$
public void setInputFile(File file) throws FileNotFoundException {
super.setInputFile(file);
LOGGER.finest("begin method setInputFile");
this.zzReader = new FileReader(new Path(file.getAbsolutePath()).toOSString());
this.parsedFileName = file.toString();
this.zzReader = new FileReader(new Path(file.getAbsolutePath()).toOSString());
this.parsedFileName = file.toString();
LOGGER.finest("end method setInputFile");
}
Expand Down Expand Up @@ -260,6 +263,8 @@ SMBL = \& | \+ | \$


[^] {
String errorMessage = "Class"+this.getClass().getName()+"\nIllegal character <" + yytext() + ">\nFile :"+ this.parsedFileName+"\nat line:"+yyline+" column:"+yycolumn;
throw new JFlexException(new Exception(errorMessage));
}
String parsedWord = "Word ["+yytext()+"], code [" + toASCII(yytext()) + "]";
final String errorMessage = "Analysis failure : Your file could not be analyzed. Please verify that it was encoded in an UNIX format.";
throw new JFlexException(this.getClass().getName(), parsedFileName,
errorMessage, parsedWord, yyline, yycolumn);
}
Loading

0 comments on commit b02ea49

Please sign in to comment.