use of com.cflint.BugInfo.BugInfoBuilder in project CFLint by cflint.
the class DefaultCFLintExceptionListener method exceptionOccurred.
@Override
public void exceptionOccurred(final Throwable exception, final String messageCode, final String filename, final Integer line, final Integer column, final String functionName, final String expression) {
final BugInfoBuilder bugInfoBuilder = new BugInfo.BugInfoBuilder();
bugInfoBuilder.setMessageCode(messageCode).setFilename(filename).setSeverity("ERROR");
if ("PARSE_ERROR".equals(messageCode)) {
bugInfoBuilder.setMessage("Unable to parse");
} else {
bugInfoBuilder.setMessage(exception.getMessage());
}
bugInfoBuilder.setExpression(expression);
bugInfoBuilder.setFunction(functionName);
if (line != null) {
bugInfoBuilder.setLine(line);
}
if (column != null) {
bugInfoBuilder.setColumn(column);
}
bugs.add(bugInfoBuilder.build());
}
use of com.cflint.BugInfo.BugInfoBuilder in project CFLint by cflint.
the class CFLint method reportRule.
protected void reportRule(final Element elem, final Object expression, final Context context, final CFLintScanner pluginParm, final ContextMessage msg) {
final String msgcode = msg.getMessageCode();
final String nameVar = msg.getVariable();
final CFLintScanner plugin = msg.getSource() == null ? pluginParm : msg.getSource();
if (checkForDisabled(elem, msgcode)) {
return;
}
if (configuration == null) {
throw new NullPointerException("Configuration is null");
}
PluginInfoRule ruleInfo;
if ("PLUGIN_ERROR".equals(msgcode)) {
ruleInfo = new PluginInfoRule();
final PluginMessage msgInfo = new PluginMessage("PLUGIN_ERROR");
msgInfo.setMessageText("Error in plugin: ${variable}");
msgInfo.setSeverity("ERROR");
ruleInfo.getMessages().add(msgInfo);
} else {
if (plugin == null) {
throw new NullPointerException("Plugin not set. Plugin should be using addMessage(messageCode,variable,source) to report messages in parent contexts");
}
ruleInfo = configuration.getRuleForPlugin(plugin);
}
if (ruleInfo == null) {
throw new NullPointerException("Rule not found for " + plugin.getClass().getSimpleName());
}
final PluginMessage msgInfo = ruleInfo.getMessageByCode(msgcode);
if (configuration == null) {
throw new NullPointerException("Message definition not found for [" + msgcode + "] in " + plugin.getClass().getSimpleName());
}
final BugInfoBuilder bldr = new BugInfo.BugInfoBuilder().setMessageCode(msgcode).setVariable(nameVar).setFunction(context.getFunctionName()).setFilename(context.getFilename()).setComponent(context.getComponentName());
if (msgInfo != null) {
bldr.setSeverity(msgInfo.getSeverity());
bldr.setMessage(msgInfo.getMessageText());
} else {
String errMessage = "Message code: " + msgcode + " is not configured correctly.";
fireCFLintException(new NullPointerException(errMessage), PLUGIN_ERROR, "", null, null, null, null);
bldr.setSeverity("WARNING");
bldr.setMessage(msgcode);
}
if (expression instanceof CFStatement) {
bldr.setExpression(((CFStatement) expression).Decompile(0));
} else if (expression instanceof CFScriptStatement) {
bldr.setExpression(((CFScriptStatement) expression).Decompile(0));
} else if (elem != null) {
bldr.setExpression(elem.toString());
}
bldr.setRuleParameters(ruleInfo.getParameters());
if (configuration.includes(ruleInfo.getMessageByCode(msgcode)) && !configuration.excludes(ruleInfo.getMessageByCode(msgcode))) {
if (expression instanceof CFExpression) {
BugInfo bugInfo = bldr.build((CFExpression) expression, elem);
final Token token = ((CFExpression) expression).getToken();
if (!suppressed(bugInfo, token, context)) {
bugs.add(bugInfo);
}
} else {
final BugInfo bug = bldr.build((CFParsedStatement) expression, elem);
if (msg.getLine() != null) {
bug.setLine(msg.getLine());
bug.setColumn(0);
}
bugs.add(bug);
}
}
}
Aggregations