/** * Whether the type is java.lang.String. * @param typeAst the type to check. * @return true, if the type is java.lang.String. */ private static boolean isStringType(DetailAST typeAst) { final FullIdent type = FullIdent.createFullIdent(typeAst); return "String".equals(type.getText()) || "java.lang.String".equals(type.getText()); }
/** * Get name of class (with qualified package if specified) in {@code ast}. * @param ast ast to extract class name from * @return qualified name */ private static String extractQualifiedName(DetailAST ast) { return FullIdent.createFullIdent(ast).getText(); }
/** * 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()); }
/** * Collects the details of imports. * @param ast node containing the import details */ private void processImport(DetailAST ast) { final FullIdent name = FullIdent.createFullIdentBelow(ast); if (!name.getText().endsWith(STAR_IMPORT_SUFFIX)) { imports.add(name); } }
/** * Determines if an AST is a formal param of type Object. * @param paramNode the AST to check * @return true if firstChild is a parameter of an Object type. */ private static boolean isObjectParam(DetailAST paramNode) { final DetailAST typeNode = paramNode.findFirstToken(TokenTypes.TYPE); final FullIdent fullIdent = FullIdent.createFullIdentBelow(typeNode); final String name = fullIdent.getText(); return "Object".equals(name) || "java.lang.Object".equals(name); }
/** * Registers given import. This allows us to track imported classes. * @param imp import definition. */ public void registerImport(DetailAST imp) { final FullIdent ident = FullIdent.createFullIdent( imp.getLastChild().getPreviousSibling()); final String fullName = ident.getText(); final int lastDot = fullName.lastIndexOf(DOT); importedClassPackage.put(fullName.substring(lastDot + 1), fullName); }
/** * Converts FullIdent to Token. * @param fullIdent full ident to convert. */ public Token(FullIdent fullIdent) { text = fullIdent.getText(); lineNo = fullIdent.getLineNo(); columnNo = fullIdent.getColumnNo(); }
/** * Gets the full import identifier. If the import is a starred import and * it's not excluded then a violation is logged. * @param startingDot the starting dot for the import statement */ private void logsStarredImportViolation(DetailAST startingDot) { final FullIdent name = FullIdent.createFullIdent(startingDot); final String importText = name.getText(); if (importText.endsWith(STAR_IMPORT_SUFFIX) && !excludes.contains(importText)) { log(startingDot.getLineNo(), MSG_KEY, importText); } }
/** * Visits type. * @param ast type to process. */ public void visitType(DetailAST ast) { final String fullTypeName = CheckUtil.createFullType(ast).getText(); addReferencedClassName(fullTypeName); }
/** * Collects the details of static imports. * @param ast node containing the static import details */ private void processStaticImport(DetailAST ast) { final FullIdent name = FullIdent.createFullIdent( ast.getFirstChild().getNextSibling()); if (!name.getText().endsWith(STAR_IMPORT_SUFFIX)) { imports.add(name); } }
/** * Adds new referenced class. * @param ast a node which represents referenced class. */ private void addReferencedClassName(DetailAST ast) { final String fullIdentName = FullIdent.createFullIdent(ast).getText(); addReferencedClassName(fullIdentName); }
/** * Forms import full path. * @param token * current token. * @return full path or null. */ private static String getFullImportIdent(DetailAST token) { String ident = ""; if (token != null) { ident = FullIdent.createFullIdent(token.findFirstToken(TokenTypes.DOT)).getText(); } return ident; }
/** * Returns the current tree's ClassResolver. * @return {@code ClassResolver} for current tree. */ private ClassResolver getClassResolver() { if (classResolver == null) { classResolver = new ClassResolver(getClassLoader(), packageFullIdent.getText(), imports); } return classResolver; }
/** * Perform processing for an package token. * @param ast the package token */ private void processPackageDef(DetailAST ast) { final DetailAST packageNameAST = ast.getLastChild() .getPreviousSibling(); final FullIdent packageIdent = FullIdent.createFullIdent(packageNameAST); pkgName = packageIdent.getText(); }
/** * Returns package text. * @param ast PACKAGE_DEF ast node * @return String that represents full package name */ private static String getPackageText(DetailAST ast) { final DetailAST nameAST = ast.getLastChild().getPreviousSibling(); return FullIdent.createFullIdent(nameAST).getText(); }
/** * Stores package of current class we check. * @param pkg package definition. */ private void visitPackageDef(DetailAST pkg) { final FullIdent ident = FullIdent.createFullIdent(pkg.getLastChild().getPreviousSibling()); fileContext.setPackageName(ident.getText()); }