use of org.sonar.plugins.java.api.tree.LabeledStatementTree in project sonar-java by SonarSource.
the class JavaTreeModelTest method labeled_statement.
/**
* 14.7. Labeled Statements
*/
@Test
public void labeled_statement() {
LabeledStatementTree tree = (LabeledStatementTree) firstMethodFirstStatement("class T { void m() { label: ; } }");
assertThat(tree.is(Tree.Kind.LABELED_STATEMENT)).isTrue();
assertThat(tree.label().name()).isEqualTo("label");
assertThat(tree.statement()).isNotNull();
assertThat(tree.colonToken().text()).isEqualTo(":");
assertThatChildrenIteratorHasSize(tree, 3);
}
use of org.sonar.plugins.java.api.tree.LabeledStatementTree in project sonar-java by SonarSource.
the class SwitchWithLabelsCheck method visitNode.
@Override
public void visitNode(Tree tree) {
CaseGroupTree cgt = (CaseGroupTree) tree;
for (StatementTree statementTree : cgt.body()) {
if (statementTree.is(LABELED_STATEMENT)) {
IdentifierTree label = ((LabeledStatementTree) statementTree).label();
reportIssue(label, "Remove this misleading \"" + label.name() + "\" label.");
}
}
}
use of org.sonar.plugins.java.api.tree.LabeledStatementTree in project sonar-java by SonarSource.
the class LabelsVisitor method associateLabel.
private void associateLabel(@Nullable IdentifierTree label) {
if (label == null) {
return;
}
LabeledStatementTree labelTree = labelTrees.get(label.name());
if (labelTree != null) {
JavaSymbol symbol = (JavaSymbol) labelTree.symbol();
((IdentifierTreeImpl) label).setSymbol(symbol);
symbol.addUsage(label);
}
}
Aggregations