Skip to content

Commit

Permalink
cflint#290 - Additional refactoring from fireCFLintException to repor…
Browse files Browse the repository at this point in the history
…tRule
  • Loading branch information
TheRealAgentK committed Jul 1, 2017
1 parent b402275 commit 938fc79
Showing 1 changed file with 40 additions and 14 deletions.
54 changes: 40 additions & 14 deletions src/main/java/com/cflint/CFLint.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,9 @@ private void process(final Element elem, final String space, final Context conte
}
} catch (final Exception npe) {
printException(npe, elem);
fireCFLintException(npe, PARSE_ERROR, context.getFilename(), null, null, null, null);
final ContextMessage cm = new ContextMessage("PARSE_ERROR", null,null,context.startLine());
reportRule(currentElement,null,context,null, cm);
//fireCFLintException(npe, PARSE_ERROR, context.getFilename(), null, null, null, null);
}
}
processStack(elem.getChildElements(), space + " ", context);
Expand Down Expand Up @@ -417,7 +419,9 @@ private void process(final Element elem, final String space, final Context conte
functionContext.getMessages().clear();
} catch (final Exception e) {
printException(e);
fireCFLintException(e, PARSE_ERROR, context.getFilename(), null, null, null, null);
final ContextMessage cm = new ContextMessage("PARSE_ERROR", null,null,context.startLine());
reportRule(currentElement,null,context,null, cm);
//fireCFLintException(e, PARSE_ERROR, context.getFilename(), null, null, null, null);
}
}
handler.pop();
Expand All @@ -439,7 +443,9 @@ private void process(final Element elem, final String space, final Context conte
componentContext.getMessages().clear();
} catch (final Exception e) {
printException(e);
fireCFLintException(e, PARSE_ERROR, context.getFilename(), null, null, null, null);
final ContextMessage cm = new ContextMessage("PARSE_ERROR", null,null,context.startLine());
reportRule(currentElement,null,context,null, cm);
//fireCFLintException(e, PARSE_ERROR, context.getFilename(), null, null, null, null);
}
}
handler.pop();
Expand Down Expand Up @@ -623,7 +629,9 @@ private void process(final CFScriptStatement expression, Context context) {
componentContext.getMessages().clear();
} catch (final Exception e) {
printException(e);
fireCFLintException(e, PARSE_ERROR, context.getFilename(), null, null, null, null);
final ContextMessage cm = new ContextMessage("PARSE_ERROR", null,null,context.startLine());
reportRule(currentElement,null,context,null, cm);
//fireCFLintException(e, PARSE_ERROR, context.getFilename(), null, null, null, null);
}
}
} else if (expression instanceof CFForStatement) {
Expand Down Expand Up @@ -695,7 +703,9 @@ private void process(final CFScriptStatement expression, Context context) {
functionContext.getMessages().clear();
} catch (final Exception e) {
printException(e);
fireCFLintException(e, PARSE_ERROR, context.getFilename(), null, null, null, null);
final ContextMessage cm = new ContextMessage("PARSE_ERROR", null,null,context.startLine());
reportRule(currentElement,null,context,null, cm);
//fireCFLintException(e, PARSE_ERROR, context.getFilename(), null, null, null, null);
}
}
handler.pop();
Expand All @@ -718,24 +728,32 @@ private void process(final CFScriptStatement expression, Context context) {
} catch (IOException ex) {
System.err.println("Invalid include file " + context.getFilename());
final int line = context.startLine();
fireCFLintException(ex, PARSE_ERROR, context.getFilename(), line, 1, "",
"Invalid include file " + expression.getClass());
final ContextMessage cm = new ContextMessage("PARSE_ERROR", null,null,line);
reportRule(currentElement,"Invalid include file " + expression.getClass(),context,null, cm);

//fireCFLintException(ex, PARSE_ERROR, context.getFilename(), line, 1, "",
// "Invalid include file " + expression.getClass());
}
}
} else if(strictInclude){
System.err.println("Unable to resolve template value " + context.getFilename());
final int line = context.startLine();
fireCFLintException(new Exception(), PARSE_ERROR, context.getFilename(), line, 1, "",
"Unable to resolve template value " + expression.getClass());
final ContextMessage cm = new ContextMessage("PARSE_ERROR", null,null,line);
reportRule(currentElement,"Unable to resolve template value " + expression.getClass(),context,null, cm);

//fireCFLintException(new Exception(), PARSE_ERROR, context.getFilename(), line, 1, "",
// "Unable to resolve template value " + expression.getClass());
}
} else {
scanExpression(expression, context, elem);
}
} catch (final StackOverflowError soe) {
System.err.println("Stack overflow in " + context.getFilename());
final int line = context.startLine();
fireCFLintException(soe, PARSE_ERROR, context.getFilename(), line, 1, "",
"Stack overflow on " + expression.getClass());
final ContextMessage cm = new ContextMessage("PARSE_ERROR", null,null,line);
reportRule(currentElement,"Stack overflow on " + expression.getClass(),context,null, cm);
//fireCFLintException(soe, PARSE_ERROR, context.getFilename(), line, 1, "",
// "Stack overflow on " + expression.getClass());
}
// Process any messages added by downstream parsing.
for (final ContextMessage message : context.getMessages()) {
Expand All @@ -760,7 +778,9 @@ protected void doStructureStart(final Element elem, final Context context,
context.getMessages().clear();
} catch (final Exception e) {
printException(e);
fireCFLintException(e, PARSE_ERROR, context.getFilename(), null, null, null, null);
final ContextMessage cm = new ContextMessage("PARSE_ERROR", null,null,context.startLine());
reportRule(currentElement,null,context,null, cm);
//fireCFLintException(e, PARSE_ERROR, context.getFilename(), null, null, null, null);
}
}
}
Expand Down Expand Up @@ -1160,7 +1180,10 @@ protected void fireStartedProcessing(final String srcidentifier) {
structurePlugin.startFile(srcidentifier, bugs);
} catch (final Exception e) {
printException(e);
fireCFLintException(e, PARSE_ERROR, srcidentifier, null, null, null, null);
final Context context = new Context(currentFile,currentElement,null,true,null,null);
final ContextMessage cm = new ContextMessage("PARSE_ERROR", null,null,context.startLine());
reportRule(currentElement,null,context,null, cm);
//fireCFLintException(e, PARSE_ERROR, srcidentifier, null, null, null, null);
}
}
for (final ScanProgressListener p : scanProgressListeners) {
Expand All @@ -1174,7 +1197,10 @@ protected void fireFinishedProcessing(final String srcidentifier) {
structurePlugin.endFile(srcidentifier, bugs);
} catch (final Exception e) {
printException(e);
fireCFLintException(e, PARSE_ERROR, srcidentifier, null, null, null, null);
final Context context = new Context(currentFile,currentElement,null,true,null,null);
final ContextMessage cm = new ContextMessage("PARSE_ERROR", null,null,context.startLine());
reportRule(currentElement,null,context,null, cm);
//fireCFLintException(e, PARSE_ERROR, srcidentifier, null, null, null, null);
}
}
for (final ScanProgressListener p : scanProgressListeners) {
Expand Down

0 comments on commit 938fc79

Please sign in to comment.