use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class UnusedPrivateFieldCheck method checkIfUnused.
public void checkIfUnused(VariableTree tree) {
if (hasNoAnnotation(tree)) {
Symbol symbol = tree.symbol();
String name = symbol.name();
if (symbol.isPrivate() && onlyUsedInVariableAssignment(symbol) && !"serialVersionUID".equals(name) && !unknownIdentifiers.contains(name)) {
reportIssue(tree.simpleName(), "Remove this unused \"" + name + "\" private field.");
}
}
}
use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class UnusedTypeParameterCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (hasSemantic()) {
TypeParameters typeParameters;
String messageEnd;
if (tree.is(Tree.Kind.METHOD)) {
typeParameters = ((MethodTree) tree).typeParameters();
messageEnd = "method.";
} else {
typeParameters = ((ClassTree) tree).typeParameters();
messageEnd = "class.";
if (tree.is(Tree.Kind.INTERFACE)) {
messageEnd = "interface.";
}
}
for (TypeParameterTree typeParameter : typeParameters) {
Symbol symbol = semanticModel.getSymbol(typeParameter);
if (symbol.usages().isEmpty()) {
String message = new StringBuilder(typeParameter.identifier().name()).append(" is not used in the ").append(messageEnd).toString();
reportIssue(typeParameter.identifier(), message);
}
}
}
}
use of org.sonar.plugins.java.api.semantic.Symbol 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.semantic.Symbol in project sonar-java by SonarSource.
the class ExplodedGraphWalker method executeAssignment.
private void executeAssignment(AssignmentExpressionTree tree) {
ProgramState.Pop unstack;
SymbolicValue value;
if (tree.is(Tree.Kind.ASSIGNMENT)) {
unstack = ExpressionUtils.isSimpleAssignment(tree) ? programState.unstackValue(1) : programState.unstackValue(2);
value = unstack.values.get(0);
} else {
unstack = programState.unstackValue(2);
value = constraintManager.createSymbolicValue(tree);
}
programState = unstack.state;
Symbol symbol = null;
if (tree.variable().is(Tree.Kind.IDENTIFIER) || ExpressionUtils.isSelectOnThisOrSuper(tree)) {
symbol = ExpressionUtils.extractIdentifier(tree).symbol();
programState = programState.put(symbol, value);
}
programState = programState.stackValue(value, symbol);
}
use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class ExplodedGraphWalker method executeLogicalAssignment.
private void executeLogicalAssignment(AssignmentExpressionTree tree) {
ExpressionTree variable = tree.variable();
// FIXME handle also assignments with this SONARJAVA-2242
if (variable.is(Tree.Kind.IDENTIFIER)) {
ProgramState.Pop unstack = programState.unstackValue(2);
ProgramState.SymbolicValueSymbol assignedTo = unstack.valuesAndSymbols.get(1);
ProgramState.SymbolicValueSymbol value = unstack.valuesAndSymbols.get(0);
programState = unstack.state;
SymbolicValue symbolicValue = constraintManager.createBinarySymbolicValue(tree, ImmutableList.of(assignedTo, value));
Symbol symbol = ((IdentifierTree) variable).symbol();
programState = programState.stackValue(symbolicValue, symbol);
programState = programState.put(symbol, symbolicValue);
}
}
Aggregations