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

The following examples show how to use com.puppycrawl.tools.checkstyle.api.TokenTypes#CTOR_DEF . 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: MonitoringRecordFactoryConventionCheck.java    From kieker with Apache License 2.0 6 votes vote down vote up
/**
 * This method checks the constructors of the record.
 *
 * @param ast
 *            The record class.
 */
private void checkConstructors(final DetailAST ast) {
	DetailAST child = ast.findFirstToken(TokenTypes.OBJBLOCK).findFirstToken(TokenTypes.CTOR_DEF);
	while (child != null) {
		if ((child.getType() == TokenTypes.CTOR_DEF)
				&& MonitoringRecordFactoryConventionCheck.isValidConstructor(child)) {
			// We found a valid constructor
			return;
		}

		child = child.getNextSibling();
	}

	// Seems like there is no valid constructor
	this.log(ast.getLineNo(), "invalid factory constructor");
}
 
Example 2
Source File: AnalysisComponentConstructorCheck.java    From kieker with Apache License 2.0 6 votes vote down vote up
@Override
public void visitToken(final DetailAST ast) {
	// Check whether we are interested in the class (whether it is an
	// analysis component or not)
	if (!(this.ignoreAbstractClasses && CSUtility.isAbstract(ast))
			&& AnalysisComponentConstructorCheck.isAnalysisComponent(ast)) {
		// Now check the constructors
		DetailAST child = ast.findFirstToken(TokenTypes.OBJBLOCK).findFirstToken(TokenTypes.CTOR_DEF);
		while (child != null) {
			if ((child.getType() == TokenTypes.CTOR_DEF)
					&& AnalysisComponentConstructorCheck.isValidConstructor(child)) {
				// We found a valid constructor
				return;
			}

			child = child.getNextSibling();
		}

		// Seems like there is no valid constructor
		this.log(ast.getLineNo(), "invalid analysis component constructor");
	}
}
 
Example 3
Source File: UnusedParameterCheck.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Determines whether an AST is a method definition with a body, or is
 * a constructor definition.
 * @param aAST the AST to check.
 * @return if AST has a body.
 */
private boolean hasBody(DetailAST aAST)
{
    if (aAST.getType() == TokenTypes.METHOD_DEF) {
        return aAST.branchContains(TokenTypes.SLIST);
    }
    else if (aAST.getType() == TokenTypes.CTOR_DEF) {
        return true;
    }
    return false;
}
 
Example 4
Source File: UnusedParameterCheck.java    From contribution with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Determines whether an AST is a method definition with a body, or is
 * a constructor definition.
 * @param aAST the AST to check.
 * @return if AST has a body.
 */
private boolean hasBody(DetailAST aAST)
{
    if (aAST.getType() == TokenTypes.METHOD_DEF) {
        return aAST.branchContains(TokenTypes.SLIST);
    }
    else if (aAST.getType() == TokenTypes.CTOR_DEF) {
        return true;
    }
    return false;
}
 
Example 5
Source File: SpringJavadocCheck.java    From spring-javaformat with Apache License 2.0 4 votes vote down vote up
@Override
public int[] getDefaultTokens() {
	return new int[] { TokenTypes.INTERFACE_DEF, TokenTypes.CLASS_DEF, TokenTypes.ENUM_DEF,
			TokenTypes.ANNOTATION_DEF, TokenTypes.METHOD_DEF, TokenTypes.CTOR_DEF };
}
 
Example 6
Source File: SpringJavadocCheck.java    From spring-javaformat with Apache License 2.0 4 votes vote down vote up
@Override
public int[] getAcceptableTokens() {
	return new int[] { TokenTypes.INTERFACE_DEF, TokenTypes.CLASS_DEF, TokenTypes.ENUM_DEF,
			TokenTypes.ANNOTATION_DEF, TokenTypes.METHOD_DEF, TokenTypes.CTOR_DEF, TokenTypes.ENUM_CONSTANT_DEF,
			TokenTypes.ANNOTATION_FIELD_DEF };
}
 
Example 7
Source File: OneMethodPrivateFieldCheck.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/** @see com.puppycrawl.tools.checkstyle.checks.usage.AbstractUsageCheck */
public void applyTo(Set aNodes)
{
    // apply the check to each private field
    final Set methods = new HashSet();
    final Iterator it = aNodes.iterator();
    while (it.hasNext()) {
        methods.clear();
        final DetailAST nameAST = (DetailAST) it.next();
        // find methods using the field
        final Iterator refIt = getReferences(nameAST);
        while (refIt.hasNext()) {
            final Reference ref = (Reference) refIt.next();
            final SymTabAST refNode = ref.getTreeNode();
            final DetailAST refDetail = refNode.getDetailNode();
            // don't need to check a self-reference
            if (refDetail == nameAST) {
                continue;
            }
            DetailAST parent = refDetail.getParent();
            while (parent != null) {
                final int type = parent.getType();
                if ((type == TokenTypes.METHOD_DEF)
                    || (type == TokenTypes.CTOR_DEF)
                    || (type == TokenTypes.INSTANCE_INIT)
                    || (type == TokenTypes.STATIC_INIT))
                {
                    methods.add(parent);
                    break;
                }
                // initializer for inner class?
                else if (type == TokenTypes.CLASS_DEF) {
                    break;
                }
                parent = parent.getParent();
            }
        }
        if (methods.size() == 1) {
            log(
                nameAST.getLineNo(),
                nameAST.getColumnNo(),
                getErrorKey(),
                nameAST.getText());
        }
    }
}
 
Example 8
Source File: OneMethodPrivateFieldCheck.java    From contribution with GNU Lesser General Public License v2.1 4 votes vote down vote up
/** @see com.puppycrawl.tools.checkstyle.checks.usage.AbstractUsageCheck */
public void applyTo(Set aNodes)
{
    // apply the check to each private field
    final Set methods = new HashSet();
    final Iterator it = aNodes.iterator();
    while (it.hasNext()) {
        methods.clear();
        final DetailAST nameAST = (DetailAST) it.next();
        // find methods using the field
        final Iterator refIt = getReferences(nameAST);
        while (refIt.hasNext()) {
            final Reference ref = (Reference) refIt.next();
            final SymTabAST refNode = ref.getTreeNode();
            final DetailAST refDetail = refNode.getDetailNode();
            // don't need to check a self-reference
            if (refDetail == nameAST) {
                continue;
            }
            DetailAST parent = refDetail.getParent();
            while (parent != null) {
                final int type = parent.getType();
                if ((type == TokenTypes.METHOD_DEF)
                    || (type == TokenTypes.CTOR_DEF)
                    || (type == TokenTypes.INSTANCE_INIT)
                    || (type == TokenTypes.STATIC_INIT))
                {
                    methods.add(parent);
                    break;
                }
                // initializer for inner class?
                else if (type == TokenTypes.CLASS_DEF) {
                    break;
                }
                parent = parent.getParent();
            }
        }
        if (methods.size() == 1) {
            log(
                nameAST.getLineNo(),
                nameAST.getColumnNo(),
                getErrorKey(),
                nameAST.getText());
        }
    }
}