com.puppycrawl.tools.checkstyle.api.FullIdent Java Examples

The following examples show how to use com.puppycrawl.tools.checkstyle.api.FullIdent. 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: SpringJUnit5Check.java    From spring-javaformat with Apache License 2.0 5 votes vote down vote up
private void check() {
	for (String bannedImport : BANNED_IMPORTS) {
		FullIdent ident = this.imports.get(bannedImport);
		if (ident != null) {
			log(ident.getLineNo(), ident.getColumnNo(), "junit5.bannedImport", bannedImport);
		}
	}
	for (DetailAST testMethod : this.testMethods) {
		if (AnnotationUtil.containsAnnotation(testMethod, JUNIT4_TEST_ANNOTATION)) {
			log(testMethod, "junit5.bannedTestAnnotation");
		}
	}
	checkMethodVisibility(this.testMethods, "junit5.testPublicMethod", "junit5.testPrivateMethod");
	checkMethodVisibility(this.lifecycleMethods, "junit5.lifecyclePublicMethod", "junit5.lifecyclePrivateMethod");
}
 
Example #2
Source File: SpringJUnit5Check.java    From spring-javaformat with Apache License 2.0 4 votes vote down vote up
private void visitImport(DetailAST ast) {
	FullIdent ident = FullIdent.createFullIdentBelow(ast);
	this.imports.put(ident.getText(), ident);
}
 
Example #3
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 #4
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 #5
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 writeReplace() or readResolve().
 * @param aAST method def to check
 * @return true if this is a writeReplace() definition
 */
private boolean isWriteReplaceOrReadResolve(DetailAST aAST)
{
    // name is writeReplace or readResolve...
    final DetailAST ident = aAST.findFirstToken(TokenTypes.IDENT);
    if (!"writeReplace".equals(ident.getText())
        && !"readResolve".equals(ident.getText()))
    {
        return false;
    }

    // returns Object...
    final DetailAST typeAST =
        (DetailAST) aAST.findFirstToken(TokenTypes.TYPE).getFirstChild();
    if (typeAST.getType() != TokenTypes.DOT
        && typeAST.getType() != TokenTypes.IDENT)
    {
        return false;
    }

    // should have no parameters...
    final DetailAST params = aAST.findFirstToken(TokenTypes.PARAMETERS);
    if (params != null && params.getChildCount() != 0) {
        return false;
    }

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

    return true;
}
 
Example #6
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 #7
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;
}
 
Example #8
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 writeReplace() or readResolve().
 * @param aAST method def to check
 * @return true if this is a writeReplace() definition
 */
private boolean isWriteReplaceOrReadResolve(DetailAST aAST)
{
    // name is writeReplace or readResolve...
    final DetailAST ident = aAST.findFirstToken(TokenTypes.IDENT);
    if (!"writeReplace".equals(ident.getText())
        && !"readResolve".equals(ident.getText()))
    {
        return false;
    }

    // returns Object...
    final DetailAST typeAST =
        (DetailAST) aAST.findFirstToken(TokenTypes.TYPE).getFirstChild();
    if (typeAST.getType() != TokenTypes.DOT
        && typeAST.getType() != TokenTypes.IDENT)
    {
        return false;
    }

    // should have no parameters...
    final DetailAST params = aAST.findFirstToken(TokenTypes.PARAMETERS);
    if (params != null && params.getChildCount() != 0) {
        return false;
    }

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

    return true;
}