use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class SerializableFieldInSerializableClassCheck method checkCollectionAssignments.
private void checkCollectionAssignments(List<IdentifierTree> usages) {
for (IdentifierTree usage : usages) {
Tree parentTree = usage.parent();
if (parentTree.is(Tree.Kind.ASSIGNMENT)) {
AssignmentExpressionTree assignment = (AssignmentExpressionTree) parentTree;
ExpressionTree expression = assignment.expression();
if (usage.equals(assignment.variable()) && !expression.is(Tree.Kind.NULL_LITERAL) && isUnserializableCollection(expression.symbolType())) {
reportIssue(usage);
}
}
}
}
use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class KeywordAsIdentifierCheck method visitVariable.
@Override
public void visitVariable(VariableTree tree) {
IdentifierTree simpleName = tree.simpleName();
if (FORBIDDEN_IDENTIFIERS.contains(simpleName.name())) {
context.reportIssue(this, simpleName, "Use a different name than \"" + simpleName.name() + "\".");
}
super.visitVariable(tree);
}
use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class BooleanMethodNameCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
MethodTree methodTree = (MethodTree) tree;
IdentifierTree simpleName = methodTree.simpleName();
if (returnsBoolean(methodTree) && isBooleanGetter(simpleName) && isNotOverriding(methodTree)) {
reportIssue(simpleName, "Rename this method to start with \"is\" or \"has\".");
}
}
use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class FieldNameMatchingTypeNameCheck method visitClass.
@Override
public void visitClass(ClassTree tree) {
IdentifierTree simpleName = tree.simpleName();
if (simpleName != null) {
Symbol.TypeSymbol classSymbol = tree.symbol();
Collection<Symbol> members = classSymbol.memberSymbols();
for (Symbol sym : members) {
if (sym.isVariableSymbol() && !staticFieldSameType(classSymbol, sym)) {
// Exclude static fields of the same type.
fields.add(((Symbol.VariableSymbol) sym).declaration());
}
}
currentClassName = simpleName.name();
}
super.visitClass(tree);
currentClassName = "";
fields.clear();
}
use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class MethodNameSameAsClassCheck method visitClass.
@Override
public void visitClass(ClassTree tree) {
super.visitClass(tree);
IdentifierTree classSimpleName = tree.simpleName();
if (classSimpleName == null) {
return;
}
String className = classSimpleName.name();
for (Tree member : tree.members()) {
if (member.is(Tree.Kind.METHOD)) {
IdentifierTree simpleName = ((MethodTree) member).simpleName();
if (className.equals(simpleName.name())) {
context.reportIssue(this, simpleName, "Rename this method to prevent any misunderstanding or make it a constructor.");
}
}
}
}
Aggregations