Search in sources :

Example 1 with UnexpectedTokenTypeException

use of com.github.sevntu.checkstyle.common.UnexpectedTokenTypeException in project methods-distance by sevntu-checkstyle.

the class MethodDefinitionParser method getMethodParameterDefText.

private String getMethodParameterDefText(DetailAST parameterDef) {
    final DetailAST type = parameterDef.findFirstToken(TokenTypes.TYPE);
    final DetailAST typeFirstChild = type.getFirstChild();
    String typeName;
    switch(typeFirstChild.getType()) {
        case TokenTypes.IDENT:
            typeName = typeFirstChild.getText();
            break;
        case TokenTypes.DOT:
            typeName = typeFirstChild.getNextSibling().getText();
            break;
        case TokenTypes.ARRAY_DECLARATOR:
            typeName = typeFirstChild.getFirstChild().getText();
            break;
        default:
            if (PRIMITIVE_TOKEN_TYPES.contains(typeFirstChild.getType())) {
                typeName = typeFirstChild.getText();
            } else {
                throw new UnexpectedTokenTypeException(typeFirstChild);
            }
    }
    if (typeFirstChild.getType() == TokenTypes.ARRAY_DECLARATOR) {
        typeName += "[]";
    }
    if (parameterDef.findFirstToken(TokenTypes.ELLIPSIS) != null) {
        typeName += "...";
    }
    return typeName;
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) UnexpectedTokenTypeException(com.github.sevntu.checkstyle.common.UnexpectedTokenTypeException)

Aggregations

UnexpectedTokenTypeException (com.github.sevntu.checkstyle.common.UnexpectedTokenTypeException)1 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)1