Search in sources :

Example 1 with TreeVisitor

use of com.sun.source.tree.TreeVisitor in project error-prone by google.

the class StringLiteralTest method notMatches.

@Test
public void notMatches() {
    // TODO(b/67738557): consolidate helpers for creating fake trees
    LiteralTree tree = new LiteralTree() {

        @Override
        public Kind getKind() {
            throw new UnsupportedOperationException();
        }

        @Override
        public <R, D> R accept(TreeVisitor<R, D> visitor, D data) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Object getValue() {
            return "a string literal";
        }
    };
    assertFalse(new StringLiteral("different string").matches(tree, null));
    IdentifierTree idTree = new IdentifierTree() {

        @Override
        public Name getName() {
            return null;
        }

        @Override
        public Kind getKind() {
            throw new UnsupportedOperationException();
        }

        @Override
        public <R, D> R accept(TreeVisitor<R, D> visitor, D data) {
            throw new UnsupportedOperationException();
        }
    };
    assertFalse(new StringLiteral("test").matches(idTree, null));
    // TODO(b/67738557): consolidate helpers for creating fake trees
    LiteralTree intTree = new LiteralTree() {

        @Override
        public Object getValue() {
            return 5;
        }

        @Override
        public Kind getKind() {
            throw new UnsupportedOperationException();
        }

        @Override
        public <R, D> R accept(TreeVisitor<R, D> visitor, D data) {
            throw new UnsupportedOperationException();
        }
    };
    assertFalse(new StringLiteral("test").matches(intTree, null));
}
Also used : TreeVisitor(com.sun.source.tree.TreeVisitor) IdentifierTree(com.sun.source.tree.IdentifierTree) LiteralTree(com.sun.source.tree.LiteralTree) Test(org.junit.Test)

Example 2 with TreeVisitor

use of com.sun.source.tree.TreeVisitor in project error-prone by google.

the class StringLiteralTest method matches.

@Test
public void matches() {
    // TODO(b/67738557): consolidate helpers for creating fake trees
    LiteralTree tree = new LiteralTree() {

        @Override
        public Kind getKind() {
            throw new UnsupportedOperationException();
        }

        @Override
        public <R, D> R accept(TreeVisitor<R, D> visitor, D data) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Object getValue() {
            return "a string literal";
        }
    };
    assertTrue(new StringLiteral("a string literal").matches(tree, null));
}
Also used : TreeVisitor(com.sun.source.tree.TreeVisitor) LiteralTree(com.sun.source.tree.LiteralTree) Test(org.junit.Test)

Aggregations

LiteralTree (com.sun.source.tree.LiteralTree)2 TreeVisitor (com.sun.source.tree.TreeVisitor)2 Test (org.junit.Test)2 IdentifierTree (com.sun.source.tree.IdentifierTree)1