use of com.puppycrawl.tools.checkstyle.api.FullIdent in project checkstyle by checkstyle.
the class ImportOrderCheck method visitToken.
// -@cs[CyclomaticComplexity] SWITCH was transformed into IF-ELSE.
@Override
public void visitToken(DetailAST ast) {
final FullIdent ident;
final boolean isStatic;
if (ast.getType() == TokenTypes.IMPORT) {
ident = FullIdent.createFullIdentBelow(ast);
isStatic = false;
} else {
ident = FullIdent.createFullIdent(ast.getFirstChild().getNextSibling());
isStatic = true;
}
final boolean isStaticAndNotLastImport = isStatic && !lastImportStatic;
final boolean isLastImportAndNonStatic = lastImportStatic && !isStatic;
// https://github.com/checkstyle/checkstyle/issues/1387
if (option == ImportOrderOption.TOP) {
if (isLastImportAndNonStatic) {
lastGroup = Integer.MIN_VALUE;
lastImport = "";
}
doVisitToken(ident, isStatic, isStaticAndNotLastImport);
} else if (option == ImportOrderOption.BOTTOM) {
if (isStaticAndNotLastImport) {
lastGroup = Integer.MIN_VALUE;
lastImport = "";
}
doVisitToken(ident, isStatic, isLastImportAndNonStatic);
} else if (option == ImportOrderOption.ABOVE) {
// previous non-static but current is static
doVisitToken(ident, isStatic, isStaticAndNotLastImport);
} else if (option == ImportOrderOption.UNDER) {
doVisitToken(ident, isStatic, isLastImportAndNonStatic);
} else if (option == ImportOrderOption.INFLOW) {
// "previous" argument is useless here
doVisitToken(ident, isStatic, true);
} else {
throw new IllegalStateException("Unexpected option for static imports: " + option);
}
lastImportLine = ast.findFirstToken(TokenTypes.SEMI).getLineNo();
lastImportStatic = isStatic;
beforeFirstImport = false;
}
use of com.puppycrawl.tools.checkstyle.api.FullIdent in project checkstyle by checkstyle.
the class JavadocMethodCheck method getThrows.
/**
* Computes the exception nodes for a method.
*
* @param ast the method node.
* @return the list of exception nodes for ast.
*/
private List<ExceptionInfo> getThrows(DetailAST ast) {
final List<ExceptionInfo> returnValue = new ArrayList<>();
final DetailAST throwsAST = ast.findFirstToken(TokenTypes.LITERAL_THROWS);
if (throwsAST != null) {
DetailAST child = throwsAST.getFirstChild();
while (child != null) {
if (child.getType() == TokenTypes.IDENT || child.getType() == TokenTypes.DOT) {
final FullIdent ident = FullIdent.createFullIdent(child);
final ExceptionInfo exceptionInfo = new ExceptionInfo(createClassInfo(new Token(ident), getCurrentClassName()));
returnValue.add(exceptionInfo);
}
child = child.getNextSibling();
}
}
return returnValue;
}
use of com.puppycrawl.tools.checkstyle.api.FullIdent in project checkstyle by checkstyle.
the class AbstractClassCouplingCheck method visitPackageDef.
/**
* Stores package of current class we check.
* @param pkg package definition.
*/
private void visitPackageDef(DetailAST pkg) {
final FullIdent ident = FullIdent.createFullIdent(pkg.getLastChild().getPreviousSibling());
packageName = ident.getText();
}
use of com.puppycrawl.tools.checkstyle.api.FullIdent in project checkstyle by checkstyle.
the class PackageDeclarationCheck method visitToken.
@Override
public void visitToken(DetailAST ast) {
defined = true;
if (matchDirectoryStructure) {
final DetailAST packageNameAst = ast.getLastChild().getPreviousSibling();
final FullIdent fullIdent = FullIdent.createFullIdent(packageNameAst);
final String packageName = fullIdent.getText().replace('.', File.separatorChar);
final String directoryName = getDirectoryName();
if (!directoryName.endsWith(packageName)) {
log(fullIdent.getLineNo(), MSG_KEY_MISMATCH, packageName);
}
}
}
use of com.puppycrawl.tools.checkstyle.api.FullIdent in project checkstyle by checkstyle.
the class AbstractTypeAwareCheck method processImport.
/**
* Collects the details of imports.
* @param ast node containing the import details
*/
private void processImport(DetailAST ast) {
final FullIdent name = FullIdent.createFullIdentBelow(ast);
imports.add(name.getText());
}