Java Code Examples for com.puppycrawl.tools.checkstyle.api.TokenTypes#LITERAL_VOID

The following examples show how to use com.puppycrawl.tools.checkstyle.api.TokenTypes#LITERAL_VOID . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UnusedPrivateMethodCheck.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Checks if a given method is writeObject().
 * @param aAST method def to check
 * @return true if this is a writeObject() definition
 */
private boolean isWriteObject(DetailAST aAST)
{
    // name is writeObject...
    final DetailAST ident = aAST.findFirstToken(TokenTypes.IDENT);
    if (!"writeObject".equals(ident.getText())) {
        return false;
    }

    // returns void...
    final DetailAST typeAST =
        (DetailAST) aAST.findFirstToken(TokenTypes.TYPE).getFirstChild();
    if (typeAST.getType() != TokenTypes.LITERAL_VOID) {
        return false;
    }

    // should have one parameter...
    final DetailAST params = aAST.findFirstToken(TokenTypes.PARAMETERS);
    if (params == null || params.getChildCount() != 1) {
        return false;
    }
    // and paramter's type should be java.io.ObjectOutputStream
    final DetailAST type =
        (DetailAST) ((DetailAST) params.getFirstChild())
            .findFirstToken(TokenTypes.TYPE).getFirstChild();
    final String typeName = FullIdent.createFullIdent(type).getText();
    if (!"java.io.ObjectOutputStream".equals(typeName)
        && !"ObjectOutputStream".equals(typeName))
    {
        return false;
    }

    // and, finally, it should throws java.io.IOException
    final DetailAST throwsAST =
        aAST.findFirstToken(TokenTypes.LITERAL_THROWS);
    if (throwsAST == null || throwsAST.getChildCount() != 1) {
        return false;
    }
    final DetailAST expt = (DetailAST) throwsAST.getFirstChild();
    final String exceptionName = FullIdent.createFullIdent(expt).getText();
    if (!"java.io.IOException".equals(exceptionName)
        && !"IOException".equals(exceptionName))
    {
        return false;
    }

    return true;
}
 
Example 2
Source File: UnusedPrivateMethodCheck.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Checks if a given method is readObject().
 * @param aAST method def to check
 * @return true if this is a readObject() definition
 */
private boolean isReadObject(DetailAST aAST)
{
    // name is readObject...
    final DetailAST ident = aAST.findFirstToken(TokenTypes.IDENT);
    if (!"readObject".equals(ident.getText())) {
        return false;
    }

    // returns void...
    final DetailAST typeAST =
        (DetailAST) aAST.findFirstToken(TokenTypes.TYPE).getFirstChild();
    if (typeAST.getType() != TokenTypes.LITERAL_VOID) {
        return false;
    }

    // should have one parameter...
    final DetailAST params = aAST.findFirstToken(TokenTypes.PARAMETERS);
    if (params == null || params.getChildCount() != 1) {
        return false;
    }
    // and paramter's type should be java.io.ObjectInputStream
    final DetailAST type =
        (DetailAST) ((DetailAST) params.getFirstChild())
            .findFirstToken(TokenTypes.TYPE).getFirstChild();
    final String typeName = FullIdent.createFullIdent(type).getText();
    if (!"java.io.ObjectInputStream".equals(typeName)
        && !"ObjectInputStream".equals(typeName))
    {
        return false;
    }

    // and, finally, it should throws java.io.IOException
    // and java.lang.ClassNotFoundException
    final DetailAST throwsAST =
        aAST.findFirstToken(TokenTypes.LITERAL_THROWS);
    if (throwsAST == null || throwsAST.getChildCount() != 3) {
        return false;
    }
    final DetailAST excpt1 = (DetailAST) throwsAST.getFirstChild();
    final String exception1 = FullIdent.createFullIdent(excpt1).getText();
    final String exception2 =
        FullIdent.createFullIdent(throwsAST.getLastChild()).getText();
    if (!"java.io.IOException".equals(exception1)
        && !"IOException".equals(exception1)
        && !"java.io.IOException".equals(exception2)
        && !"IOException".equals(exception2)
        || !"java.lang.ClassNotFoundException".equals(exception1)
        && !"ClassNotFoundException".equals(exception1)
        && !"java.lang.ClassNotFoundException".equals(exception2)
        && !"ClassNotFoundException".equals(exception2))
    {
        return false;
    }

    return true;
}
 
Example 3
Source File: UnusedPrivateMethodCheck.java    From contribution with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Checks if a given method is writeObject().
 * @param aAST method def to check
 * @return true if this is a writeObject() definition
 */
private boolean isWriteObject(DetailAST aAST)
{
    // name is writeObject...
    final DetailAST ident = aAST.findFirstToken(TokenTypes.IDENT);
    if (!"writeObject".equals(ident.getText())) {
        return false;
    }

    // returns void...
    final DetailAST typeAST =
        (DetailAST) aAST.findFirstToken(TokenTypes.TYPE).getFirstChild();
    if (typeAST.getType() != TokenTypes.LITERAL_VOID) {
        return false;
    }

    // should have one parameter...
    final DetailAST params = aAST.findFirstToken(TokenTypes.PARAMETERS);
    if (params == null || params.getChildCount() != 1) {
        return false;
    }
    // and paramter's type should be java.io.ObjectOutputStream
    final DetailAST type =
        (DetailAST) ((DetailAST) params.getFirstChild())
            .findFirstToken(TokenTypes.TYPE).getFirstChild();
    final String typeName = FullIdent.createFullIdent(type).getText();
    if (!"java.io.ObjectOutputStream".equals(typeName)
        && !"ObjectOutputStream".equals(typeName))
    {
        return false;
    }

    // and, finally, it should throws java.io.IOException
    final DetailAST throwsAST =
        aAST.findFirstToken(TokenTypes.LITERAL_THROWS);
    if (throwsAST == null || throwsAST.getChildCount() != 1) {
        return false;
    }
    final DetailAST expt = (DetailAST) throwsAST.getFirstChild();
    final String exceptionName = FullIdent.createFullIdent(expt).getText();
    if (!"java.io.IOException".equals(exceptionName)
        && !"IOException".equals(exceptionName))
    {
        return false;
    }

    return true;
}
 
Example 4
Source File: UnusedPrivateMethodCheck.java    From contribution with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Checks if a given method is readObject().
 * @param aAST method def to check
 * @return true if this is a readObject() definition
 */
private boolean isReadObject(DetailAST aAST)
{
    // name is readObject...
    final DetailAST ident = aAST.findFirstToken(TokenTypes.IDENT);
    if (!"readObject".equals(ident.getText())) {
        return false;
    }

    // returns void...
    final DetailAST typeAST =
        (DetailAST) aAST.findFirstToken(TokenTypes.TYPE).getFirstChild();
    if (typeAST.getType() != TokenTypes.LITERAL_VOID) {
        return false;
    }

    // should have one parameter...
    final DetailAST params = aAST.findFirstToken(TokenTypes.PARAMETERS);
    if (params == null || params.getChildCount() != 1) {
        return false;
    }
    // and paramter's type should be java.io.ObjectInputStream
    final DetailAST type =
        (DetailAST) ((DetailAST) params.getFirstChild())
            .findFirstToken(TokenTypes.TYPE).getFirstChild();
    final String typeName = FullIdent.createFullIdent(type).getText();
    if (!"java.io.ObjectInputStream".equals(typeName)
        && !"ObjectInputStream".equals(typeName))
    {
        return false;
    }

    // and, finally, it should throws java.io.IOException
    // and java.lang.ClassNotFoundException
    final DetailAST throwsAST =
        aAST.findFirstToken(TokenTypes.LITERAL_THROWS);
    if (throwsAST == null || throwsAST.getChildCount() != 3) {
        return false;
    }
    final DetailAST excpt1 = (DetailAST) throwsAST.getFirstChild();
    final String exception1 = FullIdent.createFullIdent(excpt1).getText();
    final String exception2 =
        FullIdent.createFullIdent(throwsAST.getLastChild()).getText();
    if (!"java.io.IOException".equals(exception1)
        && !"IOException".equals(exception1)
        && !"java.io.IOException".equals(exception2)
        && !"IOException".equals(exception2)
        || !"java.lang.ClassNotFoundException".equals(exception1)
        && !"ClassNotFoundException".equals(exception1)
        && !"java.lang.ClassNotFoundException".equals(exception2)
        && !"ClassNotFoundException".equals(exception2))
    {
        return false;
    }

    return true;
}