Java Code Examples for org.sonar.plugins.java.api.tree.MethodTree#accept()

The following examples show how to use org.sonar.plugins.java.api.tree.MethodTree#accept() . 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: FindSessionDeclarationVisitor.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Override
public void visitMethod(MethodTree tree) {
    FindDeclarationOfReturnedVariable visitor = new FindDeclarationOfReturnedVariable();
    tree.accept(visitor);
    declarationOfReturnedVariable = visitor.getDeclarationOfReturnedVariable();
    super.visitMethod(tree);
}
 
Example 2
Source File: ModifiableValueMapUsageCheck.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
private void visitMethodWithMVM(IdentifierTree modifiableValueMapUsageIdentifier, Tree usageOfMVM) {
    int argumentNumber = ((Arguments) usageOfMVM).indexOf(modifiableValueMapUsageIdentifier);
    MethodInvocationTree methodInvocationWithMVM = (MethodInvocationTree) usageOfMVM.parent();
    if (methodInvocationWithMVM != null) {
        MethodTree methodWithMVM = (MethodTree) methodInvocationWithMVM.symbol().declaration();
        if (methodWithMVM != null && methodWithMVM.is(Tree.Kind.METHOD)) {
            MethodWithMVMVisitor methodWithMVMVisitor = new MethodWithMVMVisitor(this, argumentNumber);
            methodWithMVM.accept(methodWithMVMVisitor);
        }
    }
}
 
Example 3
Source File: SessionShouldBeLoggedOut.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
protected boolean checkIfLoggedOut(MethodTree method, VariableTree injector) {
    Set<IdentifierTree> usagesOfSession = new HashSet<>(injector.symbol().usages());
    CheckLoggedOutVisitor checkLoggedOutVisitor = new CheckLoggedOutVisitor(usagesOfSession);
    FinallyBlockVisitor finallyBlockVisitor = new FinallyBlockVisitor(checkLoggedOutVisitor);
    method.accept(finallyBlockVisitor);
    return checkLoggedOutVisitor.isLoggedOut();
}
 
Example 4
Source File: ResourceResolverShouldBeClosed.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
protected boolean checkIfResourceResolverIsClosed(MethodTree method, VariableTree injector) {
    Set<IdentifierTree> usagesOfRR = new HashSet<>(injector.symbol().usages());
    CheckClosedVisitor checkClosedVisitor = new CheckClosedVisitor(usagesOfRR);
    FinallyBlockVisitor finallyBlockVisitor = new FinallyBlockVisitor(checkClosedVisitor);
    method.accept(finallyBlockVisitor);
    return checkClosedVisitor.isClosed();
}
 
Example 5
Source File: FindRRDeclarationVisitor.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Override
public void visitMethod(MethodTree tree) {
    FindDeclarationOfReturnedVariable visitor = new FindDeclarationOfReturnedVariable();
    tree.accept(visitor);
    declarationOfReturnedVariable = visitor.getDeclarationOfReturnedVariable();
    super.visitMethod(tree);
}
 
Example 6
Source File: FindSessionDeclarationVisitor.java    From AEM-Rules-for-SonarQube with Apache License 2.0 4 votes vote down vote up
private boolean isManuallyCreatedSession(MethodTree methodDeclaration) {
    CheckIfSessionCreatedManually sessionCreatedManually = new CheckIfSessionCreatedManually();
    methodDeclaration.accept(sessionCreatedManually);
    return sessionCreatedManually.isCreatedManually();
}
 
Example 7
Source File: SessionShouldBeLoggedOut.java    From AEM-Rules-for-SonarQube with Apache License 2.0 4 votes vote down vote up
protected Collection<VariableTree> findSessionsInMethod(MethodTree methodTree) {
    FindSessionDeclarationVisitor findSessionDeclarationVisitor = new FindSessionDeclarationVisitor();
    methodTree.accept(findSessionDeclarationVisitor);
    return findSessionDeclarationVisitor.getDeclarations();
}
 
Example 8
Source File: ResourceResolverShouldBeClosed.java    From AEM-Rules-for-SonarQube with Apache License 2.0 4 votes vote down vote up
protected Collection<VariableTree> findResolversInMethod(MethodTree methodTree) {
    FindRRDeclarationVisitor findVariableDeclarationVisitor = new FindRRDeclarationVisitor();
    methodTree.accept(findVariableDeclarationVisitor);
    return findVariableDeclarationVisitor.getDeclarations();
}
 
Example 9
Source File: FindRRDeclarationVisitor.java    From AEM-Rules-for-SonarQube with Apache License 2.0 4 votes vote down vote up
private boolean isManuallyCreatedResourceResolver(MethodTree methodDeclaration) {
    CheckIfRRCreatedManually rrCreatedManually = new CheckIfRRCreatedManually();
    methodDeclaration.accept(rrCreatedManually);
    return rrCreatedManually.isCreatedManually();
}