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()));
}
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();
}
}
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());
}
}
}
}
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());
}
}
}
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;
}
Aggregations