Search in sources :

Example 1 with PrimitiveTypeTree

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);
}
Also used : MethodTree(org.sonar.plugins.java.api.tree.MethodTree) PrimitiveTypeTree(org.sonar.plugins.java.api.tree.PrimitiveTypeTree) Test(org.junit.Test)

Example 2 with PrimitiveTypeTree

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());
}
Also used : PrimitiveTypeTree(org.sonar.plugins.java.api.tree.PrimitiveTypeTree) Tree(org.sonar.plugins.java.api.tree.Tree) IdentifierTree(org.sonar.plugins.java.api.tree.IdentifierTree) MethodInvocationTree(org.sonar.plugins.java.api.tree.MethodInvocationTree) MethodTree(org.sonar.plugins.java.api.tree.MethodTree)

Example 3 with PrimitiveTypeTree

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;
}
Also used : TypeTree(org.sonar.plugins.java.api.tree.TypeTree) PrimitiveTypeTree(org.sonar.plugins.java.api.tree.PrimitiveTypeTree) BlockTree(org.sonar.plugins.java.api.tree.BlockTree)

Aggregations

PrimitiveTypeTree (org.sonar.plugins.java.api.tree.PrimitiveTypeTree)3 MethodTree (org.sonar.plugins.java.api.tree.MethodTree)2 Test (org.junit.Test)1 BlockTree (org.sonar.plugins.java.api.tree.BlockTree)1 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)1 MethodInvocationTree (org.sonar.plugins.java.api.tree.MethodInvocationTree)1 Tree (org.sonar.plugins.java.api.tree.Tree)1 TypeTree (org.sonar.plugins.java.api.tree.TypeTree)1