use of org.sonar.plugins.java.api.tree.TryStatementTree in project sonar-java by SonarSource.
the class TryWithResourcesCheck method leaveNode.
@Override
public void leaveNode(Tree tree) {
if (tree.is(Tree.Kind.TRY_STATEMENT)) {
TryStatementTree tryStatementTree = withinTry.pop();
List<Tree> secondaryTrees = toReport.pop();
if (!secondaryTrees.isEmpty()) {
List<JavaFileScannerContext.Location> secondary = new ArrayList<>();
for (Tree autoCloseable : secondaryTrees) {
secondary.add(new JavaFileScannerContext.Location("AutoCloseable resource", autoCloseable));
}
reportIssue(tryStatementTree.tryKeyword(), "Change this \"try\" to a try-with-resources." + context.getJavaVersion().java7CompatibilityMessage(), secondary, null);
}
}
}
Aggregations