Search in sources :

Example 66 with DetailAstImpl

use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.

the class JavadocTagInfoTest method testParam.

@Test
public void testParam() {
    final DetailAstImpl ast = new DetailAstImpl();
    final int[] validTypes = { TokenTypes.CLASS_DEF, TokenTypes.INTERFACE_DEF, TokenTypes.METHOD_DEF, TokenTypes.CTOR_DEF };
    for (int type : validTypes) {
        ast.setType(type);
        assertWithMessage("Invalid ast type for current tag: " + ast.getType()).that(JavadocTagInfo.PARAM.isValidOn(ast)).isTrue();
    }
    ast.setType(TokenTypes.LAMBDA);
    assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.PARAM.isValidOn(ast)).isFalse();
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) Test(org.junit.jupiter.api.Test)

Example 67 with DetailAstImpl

use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.

the class JavadocTagInfoTest method testThrows.

@Test
public void testThrows() {
    final DetailAstImpl ast = new DetailAstImpl();
    final int[] validTypes = { TokenTypes.METHOD_DEF, TokenTypes.CTOR_DEF };
    for (int type : validTypes) {
        ast.setType(type);
        assertWithMessage("Invalid ast type for current tag: " + ast.getType()).that(JavadocTagInfo.THROWS.isValidOn(ast)).isTrue();
    }
    ast.setType(TokenTypes.LAMBDA);
    assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.THROWS.isValidOn(ast)).isFalse();
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) Test(org.junit.jupiter.api.Test)

Example 68 with DetailAstImpl

use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.

the class JavadocTagInfoTest method testReturn.

@Test
public void testReturn() {
    final DetailAstImpl ast = new DetailAstImpl();
    final DetailAstImpl astChild = new DetailAstImpl();
    astChild.setType(TokenTypes.TYPE);
    ast.setFirstChild(astChild);
    final DetailAstImpl astChild2 = new DetailAstImpl();
    astChild2.setType(TokenTypes.LITERAL_INT);
    astChild.setFirstChild(astChild2);
    final int[] validTypes = { TokenTypes.METHOD_DEF };
    for (int type : validTypes) {
        ast.setType(type);
        assertWithMessage("Invalid ast type for current tag: " + ast.getType()).that(JavadocTagInfo.RETURN.isValidOn(ast)).isTrue();
    }
    astChild2.setType(TokenTypes.LITERAL_VOID);
    assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.RETURN.isValidOn(ast)).isFalse();
    ast.setType(TokenTypes.LAMBDA);
    assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.RETURN.isValidOn(ast)).isFalse();
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) Test(org.junit.jupiter.api.Test)

Example 69 with DetailAstImpl

use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.

the class JavadocTagInfoTest method testSerial.

@Test
public void testSerial() throws ReflectiveOperationException {
    final DetailAstImpl ast = new DetailAstImpl();
    final DetailAstImpl astParent = new DetailAstImpl();
    astParent.setType(TokenTypes.LITERAL_CATCH);
    final Method setParent = ast.getClass().getDeclaredMethod("setParent", DetailAstImpl.class);
    setParent.setAccessible(true);
    setParent.invoke(ast, astParent);
    final int[] validTypes = { TokenTypes.VARIABLE_DEF };
    for (int type : validTypes) {
        ast.setType(type);
        assertWithMessage("Invalid ast type for current tag: " + ast.getType()).that(JavadocTagInfo.SERIAL.isValidOn(ast)).isTrue();
    }
    astParent.setType(TokenTypes.SLIST);
    ast.setType(TokenTypes.VARIABLE_DEF);
    assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.SERIAL.isValidOn(ast)).isFalse();
    ast.setType(TokenTypes.PARAMETER_DEF);
    assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.SERIAL.isValidOn(ast)).isFalse();
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 70 with DetailAstImpl

use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.

the class JavadocTagInfoTest method testSerialData.

@Test
public void testSerialData() {
    final DetailAstImpl ast = new DetailAstImpl();
    ast.setType(TokenTypes.METHOD_DEF);
    final DetailAstImpl astChild = new DetailAstImpl();
    astChild.setType(TokenTypes.IDENT);
    astChild.setText("writeObject");
    ast.setFirstChild(astChild);
    final String[] validNames = { "writeObject", "readObject", "writeExternal", "readExternal", "writeReplace", "readResolve" };
    for (String name : validNames) {
        astChild.setText(name);
        assertWithMessage("Invalid ast type for current tag: " + ast.getType()).that(JavadocTagInfo.SERIAL_DATA.isValidOn(ast)).isTrue();
    }
    astChild.setText("1111");
    assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.SERIAL_DATA.isValidOn(ast)).isFalse();
    ast.setType(TokenTypes.LAMBDA);
    assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.SERIAL_DATA.isValidOn(ast)).isFalse();
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) Test(org.junit.jupiter.api.Test)

Aggregations

DetailAstImpl (com.puppycrawl.tools.checkstyle.DetailAstImpl)106 Test (org.junit.jupiter.api.Test)90 CommonToken (org.antlr.v4.runtime.CommonToken)14 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)8 Method (java.lang.reflect.Method)6 Violation (com.puppycrawl.tools.checkstyle.api.Violation)5 AxisIterator (net.sf.saxon.tree.iter.AxisIterator)4 Context (com.puppycrawl.tools.checkstyle.api.Context)3 ArrayList (java.util.ArrayList)2 EmptyIterator (net.sf.saxon.tree.iter.EmptyIterator)2 DefaultConfiguration (com.puppycrawl.tools.checkstyle.DefaultConfiguration)1 AbstractNode (com.puppycrawl.tools.checkstyle.xpath.AbstractNode)1 RootNode (com.puppycrawl.tools.checkstyle.xpath.RootNode)1 DescendantIterator (com.puppycrawl.tools.checkstyle.xpath.iterators.DescendantIterator)1 File (java.io.File)1 AbstractMap (java.util.AbstractMap)1 Map (java.util.Map)1 ArrayIterator (net.sf.saxon.tree.iter.ArrayIterator)1