use of fr.inria.spoon.dataflow.warning.Warning in project spoon by INRIA.
the class AlwaysTrueFalseChecker method check.
private void check(CtExpression<?> expression, boolean isLoopCondition) {
Expr conditionExpr = (Expr) expression.getMetadata("value");
CtTypeReference<?> expressionType = getActualType(expression);
// Unboxing conversion
if (!expressionType.isPrimitive() && isCalculable(expressionType)) {
conditionExpr = getMemory().read(expressionType.unbox(), (IntExpr) conditionExpr);
}
ConditionStatus conditionStatus = checkCond((BoolExpr) conditionExpr);
if (conditionStatus == ConditionStatus.ALWAYS_TRUE && !isLoopCondition) {
addWarning(new Warning(expression, WarningKind.ALWAYS_TRUE));
} else if (conditionStatus == ConditionStatus.ALWAYS_FALSE) {
addWarning(new Warning(expression, WarningKind.ALWAYS_FALSE));
}
}
use of fr.inria.spoon.dataflow.warning.Warning in project spoon by INRIA.
the class TestRunner method test.
public void test(File file) throws IOException {
Launcher launcher = new Launcher();
launcher.getEnvironment().setNoClasspath(false);
launcher.getEnvironment().setCommentEnabled(false);
launcher.getEnvironment().setComplianceLevel(10);
launcher.addInputResource(file.getAbsolutePath());
CtModel model = launcher.buildModel();
List<String> lines = Files.readAllLines(file.toPath(), Charset.defaultCharset());
CheckersScanner scanner = new CheckersScanner(launcher.getFactory());
model.getAllTypes().forEach(scanner::scan);
List<Warning> warnings = scanner.getWarnings();
for (Warning warn : warnings) {
if (!lines.get(warn.position.getLine() - 1).contains("//@" + warn.kind.name())) {
fail(String.format("ADDITIONAL WARNING '%s' AT (%s:%d)", warn.kind.name(), warn.position.getFile().getAbsolutePath(), warn.position.getLine()));
}
}
for (int i = 0; i < lines.size(); i++) {
String line = lines.get(i);
List<String> commentWarnings = getCommentWarnings(line);
int lineNumber = i + 1;
for (String commentWarning : commentWarnings) {
boolean isMissing = warnings.stream().noneMatch(w -> w.position.getLine() == lineNumber && w.kind.name().equals(commentWarning));
if (isMissing) {
fail(String.format("MISSING WARNING '%s' AT (%s:%d)", commentWarning, file.getAbsolutePath(), lineNumber));
}
}
}
}
Aggregations