use of org.sonar.plugins.java.api.tree.PrimitiveTypeTree in project sonar-java by SonarSource.
the class JavaTreeModelTest method basic_type.
@Test
public void basic_type() {
PrimitiveTypeTree tree = (PrimitiveTypeTree) ((MethodTree) firstTypeMember("class T { int m() { return null; } }")).returnType();
assertThat(tree.keyword().text()).isEqualTo("int");
assertThatChildrenIteratorHasSize(tree, 1);
tree = (PrimitiveTypeTree) ((MethodTree) firstTypeMember("class T { void m() { return null; } }")).returnType();
assertThat(tree.keyword().text()).isEqualTo("void");
assertThatChildrenIteratorHasSize(tree, 1);
}
use of org.sonar.plugins.java.api.tree.PrimitiveTypeTree in project sonar-java by SonarSource.
the class ObjectFinalizeCheck method isFinalizeMethodMember.
private static boolean isFinalizeMethodMember(MethodTree methodTree) {
Tree returnType = methodTree.returnType();
boolean returnVoid = returnType != null && returnType.is(Tree.Kind.PRIMITIVE_TYPE) && "void".equals(((PrimitiveTypeTree) returnType).keyword().text());
return returnVoid && "finalize".equals(methodTree.simpleName().name());
}
use of org.sonar.plugins.java.api.tree.PrimitiveTypeTree in project sonar-java by SonarSource.
the class EnumMutableFieldCheck method isSetter.
private static boolean isSetter(MethodTree methodTree) {
TypeTree returnType = methodTree.returnType();
BlockTree block = methodTree.block();
boolean returnsVoid = returnType.is(Tree.Kind.PRIMITIVE_TYPE) && "void".equals(((PrimitiveTypeTree) returnType).keyword().text());
boolean hasAtLeastOneStatement = block == null || !block.body().isEmpty();
return methodTree.simpleName().name().startsWith("set") && methodTree.parameters().size() == 1 && returnsVoid && hasAtLeastOneStatement;
}
Aggregations