Skip to content

Commit

Permalink
Update #50 JFlexException improvement
Browse files Browse the repository at this point in the history
+ JFlexException can raise filename, line, columns, error message, last
parsed word and rule causing failure
+ Lexers now raise more details on encoding failure
+ JFlexException messages are now shown in i-Code UI
+ JFlexException contains a function to display the information message
with raised elements.
+ Shell rules (except the COMFLOWRecusion, COMNAMEHomonymy,
COMDATAInitialisation) do throw JFlexException when reaching error
state.
+ i-Code UI warning messageDialog was improved.
+ AbstractChecker contains a function to translate string into decimal
values of each character in it. This is useful to display information
when form feed or carriage return from non-Unix encoding files are
causing analysis failures.
+ Analyzer was edited to rethrow JFlexExceptions thrown from
CallableCheckers using ExecutionException from java.util.concurrent
  • Loading branch information
Omar Waldmann committed Aug 25, 2017
1 parent 0cb06cb commit c37b105
Show file tree
Hide file tree
Showing 189 changed files with 1,900 additions and 530 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 @@ -77,9 +77,9 @@ public JFlexException(final String pRuleName, final String pFileName, final Stri
*/
private static String errorMessage(String pRuleName, String pFileName, String pMessage,
String pLastScan, int pLine, int pColumn) {
final String message = "i-Code CNES Exception during analysis.\n" + "CheckerId : "
+ pRuleName + "\n" + "File : " + pFileName + "\n" + "ErrorMessage : "
+ pMessage + "\n" + "Line:" + pLine + "\n" + "Column:" + pColumn + "\n"
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/";
Expand Down Expand Up @@ -127,7 +127,7 @@ public final String getLastScan() {
/**
* @return the message
*/
public final String getMessage() {
public final String getErrorMessage() {
return message;
}

Expand Down
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ import fr.cnes.analysis.tools.analyzer.exception.JFlexException;
%extends AbstractChecker
%public
%ignorecase
%line
%column
%line


%function run
%yylexthrow JFlexException
Expand All @@ -60,11 +61,12 @@ END = END | end


String location = "MAIN PROGRAM";
private String parsedFileName;
Float numLines = 0.0f;
Float numComments = 0.0f;
boolean endLine = true;
int functionLine = 0;
String parsedFileName;



public F77METRatioComment() {
Expand All @@ -74,7 +76,8 @@ END = END | end
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 @@ -299,7 +302,9 @@ END = END | end
/*********************/
/* ERROR THROWN */
/*********************/
[^] {
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ STRING = \'[^\']*\' | \"[^\"]*\"
public void setInputFile(final File file) throws FileNotFoundException {
super.setInputFile(file);
LOGGER.finest("begin method setInputFile");
this.parsedFileName = file.toString();
this.zzReader = new FileReader(new Path(file.getAbsolutePath()).toOSString());

this.parsedFileName = file.toString();
this.zzReader = new FileReader(new Path(file.getAbsolutePath()).toOSString());
LOGGER.finest("end method setInputFile");
}

Expand Down Expand Up @@ -520,6 +521,8 @@ FUNCTION = {VAR}{SPACE}*"("
/* ERROR THROWN */
/*********************/
[^] {
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ SEE_FUNC = ([^a-zA-Z0-9\_])?("if" | "elseif" | "forall" | "while" | "where" | "
public void setInputFile(final File file) throws FileNotFoundException {
super.setInputFile(file);
LOGGER.finest("begin method setInputFile");
this.parsedFileName = file.toString();
this.zzReader = new FileReader(new Path(file.getAbsolutePath()).toOSString());

this.parsedFileName = file.toString();
this.zzReader = new FileReader(new Path(file.getAbsolutePath()).toOSString());
LOGGER.finest("end method setInputFile");
}

Expand Down Expand Up @@ -766,6 +767,8 @@ return getCheckResults();
/* ERROR 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);
}
11 changes: 7 additions & 4 deletions fr.cnes.analysis.tools.fortran77.rules/lex/COMDATAInvariant.lex
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ STRING = \'[^\']*\' | \"[^\"]*\"
public void setInputFile(final File file) throws FileNotFoundException {
super.setInputFile(file);
LOGGER.finest("begin method setInputFile");
this.parsedFileName = file.toString();
this.zzReader = new FileReader(new Path(file.getAbsolutePath()).toOSString());

this.parsedFileName = file.toString();
this.zzReader = new FileReader(new Path(file.getAbsolutePath()).toOSString());
LOGGER.finest("end method setInputFile");
}

Expand Down Expand Up @@ -326,6 +327,8 @@ return getCheckResults();
/* ERROR 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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ STRING = \'[^\']*\' | \"[^\"]*\"
public void setInputFile(final File file) throws FileNotFoundException {
super.setInputFile(file);
LOGGER.finest("begin method setInputFile");
this.parsedFileName = file.toString();
this.zzReader = new FileReader(new Path(file.getAbsolutePath()).toOSString());

this.parsedFileName = file.toString();
this.zzReader = new FileReader(new Path(file.getAbsolutePath()).toOSString());
LOGGER.finest("end method setInputFile");
}

Expand Down Expand Up @@ -408,6 +409,8 @@ WHILE = "while"
<LINE> . {}

[^] {
String errorMessage = "Class"+this.getClass().getName()+"\nIllegal character <" + yytext() + ">\nFile :"+ this.parsedFileName+"\nat line:"+(yyline+1)+" 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);
}
11 changes: 7 additions & 4 deletions fr.cnes.analysis.tools.fortran77.rules/lex/COMDATANotUsed.lex
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ EQUAL = \= [^\,\n\"\']*
public void setInputFile(final File file) throws FileNotFoundException {
super.setInputFile(file);
LOGGER.finest("begin method setInputFile");
this.parsedFileName = file.toString();
this.zzReader = new FileReader(new Path(file.getAbsolutePath()).toOSString());

this.parsedFileName = file.toString();
this.zzReader = new FileReader(new Path(file.getAbsolutePath()).toOSString());
LOGGER.finest("end method setInputFile");
}

Expand Down Expand Up @@ -271,6 +272,8 @@ return getCheckResults();
/* ERROR STATE */
/************************/
[^] {
String errorMessage = "Class"+this.getClass().getName()+"\nIllegal character <" + yytext() + ">\nFile :"+ this.parsedFileName+"\nat line:"+(yyline+1)+" 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 c37b105

Please sign in to comment.