Search in sources :

Example 81 with ClassTree

use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.

the class NonNullSetToNullCheck method checkEndOfExecutionPath.

@Override
public void checkEndOfExecutionPath(CheckerContext context, ConstraintManager constraintManager) {
    if (methodTree.is(Tree.Kind.CONSTRUCTOR) && !isDefaultConstructorForJpa(methodTree) && !callsThisConstructor(methodTree) && !exitingWithException(context)) {
        ClassTree classTree = (ClassTree) methodTree.parent();
        classTree.members().stream().filter(m -> m.is(Tree.Kind.VARIABLE)).map(m -> (VariableTree) m).filter(v -> v.initializer() == null).forEach(v -> checkVariable(context, methodTree, v.symbol()));
    }
}
Also used : ObjectConstraint(org.sonar.java.se.constraint.ObjectConstraint) JavaSymbol(org.sonar.java.resolve.JavaSymbol) ProgramState(org.sonar.java.se.ProgramState) ExpressionUtils(org.sonar.java.model.ExpressionUtils) NullableAnnotationUtils.nonNullAnnotation(org.sonar.java.se.NullableAnnotationUtils.nonNullAnnotation) MessageFormat(java.text.MessageFormat) CheckerContext(org.sonar.java.se.CheckerContext) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) VariableTree(org.sonar.plugins.java.api.tree.VariableTree) ConstraintManager(org.sonar.java.se.constraint.ConstraintManager) Lists(com.google.common.collect.Lists) SymbolMetadata(org.sonar.plugins.java.api.semantic.SymbolMetadata) MemberSelectExpressionTree(org.sonar.plugins.java.api.tree.MemberSelectExpressionTree) SymbolicValue(org.sonar.java.se.symbolicvalues.SymbolicValue) Nullable(javax.annotation.Nullable) Arguments(org.sonar.plugins.java.api.tree.Arguments) ReturnStatementTree(org.sonar.plugins.java.api.tree.ReturnStatementTree) ExpressionStatementTree(org.sonar.plugins.java.api.tree.ExpressionStatementTree) StatementTree(org.sonar.plugins.java.api.tree.StatementTree) Tree(org.sonar.plugins.java.api.tree.Tree) MethodInvocationTree(org.sonar.plugins.java.api.tree.MethodInvocationTree) NewClassTree(org.sonar.plugins.java.api.tree.NewClassTree) List(java.util.List) Stream(java.util.stream.Stream) CFG(org.sonar.java.cfg.CFG) AssignmentExpressionTree(org.sonar.plugins.java.api.tree.AssignmentExpressionTree) ClassTree(org.sonar.plugins.java.api.tree.ClassTree) Rule(org.sonar.check.Rule) IdentifierTree(org.sonar.plugins.java.api.tree.IdentifierTree) Symbol(org.sonar.plugins.java.api.semantic.Symbol) MethodTree(org.sonar.plugins.java.api.tree.MethodTree) NewClassTree(org.sonar.plugins.java.api.tree.NewClassTree) ClassTree(org.sonar.plugins.java.api.tree.ClassTree)

Example 82 with ClassTree

use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.

the class CallSuperMethodFromInnerClassCheck method visitNode.

@Override
public void visitNode(Tree tree) {
    ClassTree classTree = (ClassTree) tree;
    Symbol.TypeSymbol classSymbol = classTree.symbol();
    if (classSymbol != null && isInnerClass(classSymbol) && !extendsOuterClass(classSymbol)) {
        classTree.accept(new MethodInvocationVisitor(classSymbol));
    }
}
Also used : Symbol(org.sonar.plugins.java.api.semantic.Symbol) ClassTree(org.sonar.plugins.java.api.tree.ClassTree)

Example 83 with ClassTree

use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.

the class LeftCurlyBraceBaseTreeVisitor method visitNewClass.

@Override
public void visitNewClass(NewClassTree tree) {
    ClassTree classBody = tree.classBody();
    if (classBody != null && tree.arguments().closeParenToken() != null) {
        checkTokens(tree.arguments().closeParenToken(), classBody.openBraceToken());
    }
    super.visitNewClass(tree);
}
Also used : NewClassTree(org.sonar.plugins.java.api.tree.NewClassTree) ClassTree(org.sonar.plugins.java.api.tree.ClassTree)

Example 84 with ClassTree

use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.

the class LeftCurlyBraceBaseTreeVisitor method visitEnumConstant.

@Override
public void visitEnumConstant(EnumConstantTree tree) {
    NewClassTree initializer = tree.initializer();
    ClassTree classBody = initializer.classBody();
    if (classBody != null) {
        SyntaxToken openBraceToken = classBody.openBraceToken();
        if (initializer.arguments().closeParenToken() != null) {
            checkTokens(initializer.arguments().closeParenToken(), openBraceToken);
        } else {
            checkTokens(tree.simpleName().identifierToken(), openBraceToken);
        }
    }
    super.visitEnumConstant(tree);
}
Also used : SyntaxToken(org.sonar.plugins.java.api.tree.SyntaxToken) NewClassTree(org.sonar.plugins.java.api.tree.NewClassTree) ClassTree(org.sonar.plugins.java.api.tree.ClassTree) NewClassTree(org.sonar.plugins.java.api.tree.NewClassTree)

Example 85 with ClassTree

use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.

the class MembersDifferOnlyByCapitalizationCheck method visitNode.

@Override
public void visitNode(Tree tree) {
    if (!hasSemantic()) {
        return;
    }
    ClassTree classTree = (ClassTree) tree;
    List<Symbol> allMembers = retrieveMembers(classTree.symbol());
    Multimap<String, Symbol> membersByName = sortByName(allMembers);
    for (Tree member : classTree.members()) {
        if (member.is(Tree.Kind.METHOD)) {
            MethodTree methodTree = (MethodTree) member;
            checkForIssue(methodTree.symbol(), methodTree.simpleName(), membersByName);
        } else if (member.is(Tree.Kind.VARIABLE)) {
            VariableTree variableTree = (VariableTree) member;
            checkForIssue(variableTree.symbol(), variableTree.simpleName(), membersByName);
        }
    }
}
Also used : MethodTree(org.sonar.plugins.java.api.tree.MethodTree) Symbol(org.sonar.plugins.java.api.semantic.Symbol) NewClassTree(org.sonar.plugins.java.api.tree.NewClassTree) ClassTree(org.sonar.plugins.java.api.tree.ClassTree) VariableTree(org.sonar.plugins.java.api.tree.VariableTree) Tree(org.sonar.plugins.java.api.tree.Tree) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) NewClassTree(org.sonar.plugins.java.api.tree.NewClassTree) LambdaExpressionTree(org.sonar.plugins.java.api.tree.LambdaExpressionTree) VariableTree(org.sonar.plugins.java.api.tree.VariableTree) ClassTree(org.sonar.plugins.java.api.tree.ClassTree) IdentifierTree(org.sonar.plugins.java.api.tree.IdentifierTree) MethodTree(org.sonar.plugins.java.api.tree.MethodTree) ReturnStatementTree(org.sonar.plugins.java.api.tree.ReturnStatementTree)

Aggregations

ClassTree (org.sonar.plugins.java.api.tree.ClassTree)116 Tree (org.sonar.plugins.java.api.tree.Tree)53 MethodTree (org.sonar.plugins.java.api.tree.MethodTree)47 CompilationUnitTree (org.sonar.plugins.java.api.tree.CompilationUnitTree)45 Test (org.junit.Test)41 VariableTree (org.sonar.plugins.java.api.tree.VariableTree)37 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)32 Symbol (org.sonar.plugins.java.api.semantic.Symbol)31 NewClassTree (org.sonar.plugins.java.api.tree.NewClassTree)23 List (java.util.List)19 Type (org.sonar.plugins.java.api.semantic.Type)18 File (java.io.File)14 MethodInvocationTree (org.sonar.plugins.java.api.tree.MethodInvocationTree)13 Rule (org.sonar.check.Rule)12 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)12 Collectors (java.util.stream.Collectors)10 SquidClassLoader (org.sonar.java.bytecode.loader.SquidClassLoader)10 IssuableSubscriptionVisitor (org.sonar.plugins.java.api.IssuableSubscriptionVisitor)10 ImmutableList (com.google.common.collect.ImmutableList)9 MemberSelectExpressionTree (org.sonar.plugins.java.api.tree.MemberSelectExpressionTree)9