use of org.sonar.plugins.java.api.tree.AssignmentExpressionTree 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);
}
}
use of org.sonar.plugins.java.api.tree.AssignmentExpressionTree in project sonar-java by SonarSource.
the class TypeAndReferenceSolver method completeMetadata.
private static void completeMetadata(JavaSymbol symbol, List<AnnotationTree> annotations) {
for (AnnotationTree tree : annotations) {
AnnotationInstanceResolve annotationInstance = new AnnotationInstanceResolve((JavaSymbol.TypeJavaSymbol) tree.symbolType().symbol());
symbol.metadata().addAnnotation(annotationInstance);
Arguments arguments = tree.arguments();
if (arguments.size() > 1 || (!arguments.isEmpty() && arguments.get(0).is(Tree.Kind.ASSIGNMENT))) {
for (ExpressionTree expressionTree : arguments) {
AssignmentExpressionTree aet = (AssignmentExpressionTree) expressionTree;
// TODO: Store more precise value than the expression (real value in case of literal, symbol for enums, array of values, solve constants?)
annotationInstance.addValue(new AnnotationValueResolve(((IdentifierTree) aet.variable()).name(), aet.expression()));
}
} else {
// Constant
addConstantValue(tree, annotationInstance);
}
}
}
use of org.sonar.plugins.java.api.tree.AssignmentExpressionTree in project sonar-java by SonarSource.
the class TypeAndReferenceSolver method visitAnnotation.
@Override
public void visitAnnotation(AnnotationTree tree) {
if (((AbstractTypedTree) tree.annotationType()).isTypeSet()) {
// This handle the case where type and its annotation is shared between two variables.
return;
}
resolveAs(tree.annotationType(), JavaSymbol.TYP);
Arguments arguments = tree.arguments();
if (arguments.size() > 1 || (!arguments.isEmpty() && arguments.get(0).is(Tree.Kind.ASSIGNMENT))) {
// resolve by identifying correct identifier in assignment.
for (ExpressionTree expressionTree : arguments) {
AssignmentExpressionTree aet = (AssignmentExpressionTree) expressionTree;
IdentifierTree variable = (IdentifierTree) aet.variable();
JavaSymbol identInType = resolve.findMethod(semanticModel.getEnv(tree), getType(tree.annotationType()), variable.name(), ImmutableList.<JavaType>of()).symbol();
associateReference(variable, identInType);
JavaType type = identInType.type;
if (type == null) {
type = Symbols.unknownType;
}
registerType(variable, type);
resolveAs(aet.expression(), JavaSymbol.VAR);
}
} else {
for (ExpressionTree expressionTree : arguments) {
resolveAs(expressionTree, JavaSymbol.VAR);
}
}
registerType(tree, getType(tree.annotationType()));
}
use of org.sonar.plugins.java.api.tree.AssignmentExpressionTree in project sonar-java by SonarSource.
the class PublicStaticMutableMembersCheck method checkAssignment.
private void checkAssignment(AssignmentExpressionTree node) {
ExpressionTree variable = ExpressionUtils.skipParentheses(node.variable());
if (variable.is(Tree.Kind.MEMBER_SELECT)) {
variable = ((MemberSelectExpressionTree) variable).identifier();
}
if (variable.is(Tree.Kind.IDENTIFIER)) {
IdentifierTree identifierTree = (IdentifierTree) variable;
Symbol symbol = identifierTree.symbol();
if (IMMUTABLE_CANDIDATES.contains(symbol) && isMutable(node.expression(), symbol)) {
reportIssue(identifierTree, "Make member \"" + symbol.name() + "\" \"protected\".");
IMMUTABLE_CANDIDATES.remove(symbol);
}
}
}
use of org.sonar.plugins.java.api.tree.AssignmentExpressionTree in project sonar-java by SonarSource.
the class MutableMembersUsageCheck method visitAssignmentExpression.
@Override
public void visitAssignmentExpression(AssignmentExpressionTree tree) {
super.visitAssignmentExpression(tree);
if (!isMutableType(tree.expression())) {
return;
}
ExpressionTree variable = tree.variable();
Symbol leftSymbol = null;
if (variable.is(Tree.Kind.IDENTIFIER)) {
IdentifierTree identifierTree = (IdentifierTree) variable;
leftSymbol = identifierTree.symbol();
} else if (variable.is(Tree.Kind.MEMBER_SELECT)) {
MemberSelectExpressionTree mit = (MemberSelectExpressionTree) variable;
leftSymbol = mit.identifier().symbol();
}
if (leftSymbol != null && leftSymbol.isPrivate()) {
checkStore(tree.expression());
}
}
Aggregations