Search in sources :

Example 21 with TypeTree

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

the class TypeAndReferenceSolver method visitUnionType.

@Override
public void visitUnionType(UnionTypeTree tree) {
    resolveAs((List<TypeTree>) tree.typeAlternatives(), JavaSymbol.TYP);
    ImmutableSet.Builder<Type> uniontype = ImmutableSet.builder();
    for (TypeTree typeTree : tree.typeAlternatives()) {
        uniontype.add(typeTree.symbolType());
    }
    registerType(tree, (JavaType) resolve.leastUpperBound(uniontype.build()));
}
Also used : UnionTypeTree(org.sonar.plugins.java.api.tree.UnionTypeTree) ArrayTypeTree(org.sonar.plugins.java.api.tree.ArrayTypeTree) TypeTree(org.sonar.plugins.java.api.tree.TypeTree) ParameterizedTypeTree(org.sonar.plugins.java.api.tree.ParameterizedTypeTree) PrimitiveTypeTree(org.sonar.plugins.java.api.tree.PrimitiveTypeTree) Type(org.sonar.plugins.java.api.semantic.Type) ImmutableSet(com.google.common.collect.ImmutableSet)

Example 22 with TypeTree

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

the class ArrayDesignatorOnVariableCheck method visitNode.

@Override
public void visitNode(Tree tree) {
    VariableTree variableTree = (VariableTree) tree;
    TypeTree type = variableTree.type();
    SyntaxToken identifierToken = variableTree.simpleName().identifierToken();
    while (type.is(Tree.Kind.ARRAY_TYPE)) {
        ArrayTypeTree arrayTypeTree = (ArrayTypeTree) type;
        SyntaxToken arrayDesignatorToken = arrayTypeTree.ellipsisToken();
        if (arrayDesignatorToken == null) {
            arrayDesignatorToken = arrayTypeTree.openBracketToken();
        }
        if (isInvalidPosition(arrayDesignatorToken, identifierToken)) {
            reportIssue(arrayDesignatorToken, "Move the array designator from the variable to the type.");
            break;
        }
        type = arrayTypeTree.type();
    }
}
Also used : TypeTree(org.sonar.plugins.java.api.tree.TypeTree) ArrayTypeTree(org.sonar.plugins.java.api.tree.ArrayTypeTree) SyntaxToken(org.sonar.plugins.java.api.tree.SyntaxToken) VariableTree(org.sonar.plugins.java.api.tree.VariableTree) ArrayTypeTree(org.sonar.plugins.java.api.tree.ArrayTypeTree)

Example 23 with TypeTree

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

the class NPEThrowCheck method visitNode.

@Override
public void visitNode(Tree tree) {
    if (hasSemantic()) {
        if (tree.is(Kind.THROW_STATEMENT)) {
            ExpressionTree expressionTree = ((ThrowStatementTree) tree).expression();
            raiseIssueOnNpe(expressionTree, expressionTree.symbolType());
        } else {
            for (TypeTree throwClause : ((MethodTree) tree).throwsClauses()) {
                raiseIssueOnNpe(throwClause, throwClause.symbolType());
            }
        }
    }
}
Also used : TypeTree(org.sonar.plugins.java.api.tree.TypeTree) MethodTree(org.sonar.plugins.java.api.tree.MethodTree) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) ThrowStatementTree(org.sonar.plugins.java.api.tree.ThrowStatementTree)

Example 24 with TypeTree

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

the class OptionalAsParameterCheck method visitNode.

@Override
public void visitNode(Tree tree) {
    if (!hasSemantic()) {
        return;
    }
    for (VariableTree parameter : ((MethodTree) tree).parameters()) {
        TypeTree typeTree = parameter.type();
        Optional<String> msg = expectedTypeInsteadOfOptional(typeTree.symbolType());
        if (msg.isPresent()) {
            reportIssue(typeTree, msg.get());
        }
    }
}
Also used : TypeTree(org.sonar.plugins.java.api.tree.TypeTree) MethodTree(org.sonar.plugins.java.api.tree.MethodTree) VariableTree(org.sonar.plugins.java.api.tree.VariableTree)

Example 25 with TypeTree

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

the class VariableTreeImpl method completeType.

public VariableTreeImpl completeType(TypeTree type) {
    TypeTree actualType = type;
    if (nestedDimensions != null) {
        nestedDimensions.setLastChildType(type);
        actualType = nestedDimensions;
    }
    this.type = actualType;
    return this;
}
Also used : TypeTree(org.sonar.plugins.java.api.tree.TypeTree) InferedTypeTree(org.sonar.plugins.java.api.tree.InferedTypeTree)

Aggregations

TypeTree (org.sonar.plugins.java.api.tree.TypeTree)31 ParameterizedTypeTree (org.sonar.plugins.java.api.tree.ParameterizedTypeTree)11 Type (org.sonar.plugins.java.api.semantic.Type)8 ArrayTypeTree (org.sonar.plugins.java.api.tree.ArrayTypeTree)6 MethodTree (org.sonar.plugins.java.api.tree.MethodTree)6 NewClassTree (org.sonar.plugins.java.api.tree.NewClassTree)6 VariableTree (org.sonar.plugins.java.api.tree.VariableTree)6 ClassTree (org.sonar.plugins.java.api.tree.ClassTree)5 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)5 MemberSelectExpressionTree (org.sonar.plugins.java.api.tree.MemberSelectExpressionTree)4 PrimitiveTypeTree (org.sonar.plugins.java.api.tree.PrimitiveTypeTree)4 UnionTypeTree (org.sonar.plugins.java.api.tree.UnionTypeTree)4 Test (org.junit.Test)3 IdentifierTreeImpl (org.sonar.java.model.expression.IdentifierTreeImpl)3 Symbol (org.sonar.plugins.java.api.semantic.Symbol)3 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 HashSet (java.util.HashSet)2 CheckForNull (javax.annotation.CheckForNull)2