use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class StaticMultithreadedUnsafeFieldsCheck method visitNode.
@Override
public void visitNode(Tree tree) {
VariableTree variableTree = (VariableTree) tree;
Type type = variableTree.type().symbolType();
if (ModifiersUtils.hasModifier(variableTree.modifiers(), Modifier.STATIC) && isForbiddenType(variableTree)) {
if (type.isSubtypeOf(JAVA_TEXT_SIMPLE_DATE_FORMAT) && onlySynchronizedUsages((Symbol.VariableSymbol) variableTree.symbol())) {
return;
}
IdentifierTree identifierTree = variableTree.simpleName();
reportIssue(identifierTree, String.format("Make \"%s\" an instance variable.", identifierTree.name()));
}
}
use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class UndocumentedApiCheck method className.
private String className() {
String className = packageName;
IdentifierTree identifierTree = classTrees.peek().simpleName();
if (identifierTree != null) {
className += "." + identifierTree.name();
}
return className;
}
use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class StaticMethodCheck method visitMemberSelectExpression.
@Override
public void visitMemberSelectExpression(MemberSelectExpressionTree tree) {
if (tree.expression().is(Tree.Kind.IDENTIFIER)) {
IdentifierTree identifier = (IdentifierTree) tree.expression();
Symbol owner = identifier.symbol().owner();
if (owner != null && owner.isMethodSymbol()) {
// No need to investigate selection on local symbols
return;
}
}
super.visitMemberSelectExpression(tree);
}
use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class EnumConstantTest method test_annotation.
@Test
public void test_annotation() {
LexerlessGrammarBuilder b = JavaLexer.createGrammarBuilder();
ActionParser<Tree> parser = new ActionParser<>(StandardCharsets.UTF_8, b, JavaGrammar.class, new TreeFactory(), new JavaNodeBuilder(), JavaLexer.ENUM_CONSTANT);
EnumConstantTreeImpl node = (EnumConstantTreeImpl) parser.parse("@Foo CONSTANT");
assertThat(node.modifiers().size()).isEqualTo(1);
assertThat(((IdentifierTree) ((AnnotationTreeImpl) node.modifiers().get(0)).annotationType()).identifierToken().text()).isEqualTo("Foo");
}
use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class MethodMatcherTest method does_not_match_without_callSite_enclosingClass.
@Test
public void does_not_match_without_callSite_enclosingClass() throws Exception {
MethodMatcher matcher = MethodMatcher.create().name(NameCriteria.any()).withAnyParameters().callSite(TypeCriteria.anyType());
Symbol symbol = mock(Symbol.class);
when(symbol.enclosingClass()).thenReturn(null);
IdentifierTree id = mock(IdentifierTree.class);
when(id.is(Tree.Kind.IDENTIFIER)).thenReturn(true);
when(id.symbol()).thenReturn(symbol);
MethodInvocationTree tree = mock(MethodInvocationTree.class);
when(tree.methodSelect()).thenReturn(id);
assertThat(matcher.matches(tree)).isFalse();
}
Aggregations