Java Code Examples for org.sonar.plugins.java.api.tree.AssignmentExpressionTree#expression()

The following examples show how to use org.sonar.plugins.java.api.tree.AssignmentExpressionTree#expression() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FindRRDeclarationVisitor.java    From AEM-Rules-for-SonarQube with Apache License 2.0 6 votes vote down vote up
@Override
public void visitAssignmentExpression(AssignmentExpressionTree tree) {
    if (isExpressionAMethodInvocation(tree) && isVariableAnIdentifier(tree)) {
        final MethodInvocationTree methodInvocation = (MethodInvocationTree) tree.expression();
        final IdentifierTree identifier = (IdentifierTree) tree.variable();
        if (isManuallyCreatedResourceResolver(methodInvocation)) {
            resourceResolvers.add((VariableTree) identifier.symbol().declaration());
        } else if (isResourceResolver(methodInvocation) && methodInvocation.methodSelect().is(Kind.IDENTIFIER)) {
            MethodTree methodDeclaration = getMethodTree(methodInvocation);
            // variable 'methodDeclaration' can be null in case when method declaration isn't within the same file.
            if (methodDeclaration != null && isManuallyCreatedResourceResolver(methodDeclaration)) {
                resourceResolvers.add((VariableTree) getDeclaration(identifier));
            }
        }
    }
    super.visitAssignmentExpression(tree);
}
 
Example 2
Source File: FindSessionDeclarationVisitor.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Override
public void visitAssignmentExpression(AssignmentExpressionTree tree) {
    if (isMethodInvocation(tree)) {
        MethodInvocationTree methodInvocation = (MethodInvocationTree) tree.expression();
        if (isManuallyCreatedSession(methodInvocation)) {
            IdentifierTree variable = (IdentifierTree) tree.variable();
            sessions.add((VariableTree) getDeclaration(variable));
        } else if (isSession(methodInvocation) && methodInvocation.methodSelect().is(Kind.IDENTIFIER)) {
            findSessionsCreatedInMethods(tree, methodInvocation);
        }
    }
    super.visitAssignmentExpression(tree);
}
 
Example 3
Source File: FindSessionDeclarationVisitor.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Override
public void visitAssignmentExpression(AssignmentExpressionTree tree) {
    if (isMethodInvocation(tree) && getDeclaration((IdentifierTree) tree.variable()).equals(declarationOfReturnedVariable)) {
        MethodInvocationTree methodInvocation = (MethodInvocationTree) tree.expression();
        if (isManuallyCreatedSession(methodInvocation)) {
            this.createdManually = true;
        } else {
            CheckIfSessionCreatedManually sessionCreatedManually = new CheckIfSessionCreatedManually();
            getMethodTree(methodInvocation).accept(sessionCreatedManually);
            this.createdManually = sessionCreatedManually.isCreatedManually();
        }
    }
    super.visitAssignmentExpression(tree);
}
 
Example 4
Source File: FindRRDeclarationVisitor.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Override
public void visitAssignmentExpression(AssignmentExpressionTree tree) {
    if (isExpressionAMethodInvocation(tree) && variableIsEqualToReturnedVariableIn(tree)) {
        MethodInvocationTree methodInvocation = (MethodInvocationTree) tree.expression();
        if (isManuallyCreatedResourceResolver(methodInvocation)) {
            this.createdManually = true;
        } else {
            CheckIfRRCreatedManually rrCreatedManually = new CheckIfRRCreatedManually();
            getMethodTree(methodInvocation).accept(rrCreatedManually);
            this.createdManually = rrCreatedManually.isCreatedManually();
        }
    }
    super.visitAssignmentExpression(tree);
}
 
Example 5
Source File: ContentResourceShouldBeNullCheckedCheck.java    From AEM-Rules-for-SonarQube with Apache License 2.0 4 votes vote down vote up
private boolean isGetContentResourceUsedOnResource(AssignmentExpressionTree tree) {
    return isResource(tree) &&
        tree.expression() instanceof MethodInvocationTree &&
        GET_CONTENT_RESOURCE_METHOD.equals(((MethodInvocationTree) tree.expression()).symbol().name());
}