if (ASTHelpers.hasAnnotation(tree.getPackage(), SuppressPackageLocation.class, state)) { return Description.NO_MATCH;
@Override public Tree visitCompilationUnit(CompilationUnitTree tree, Void p) { CompilationUnitTree n = make.CompilationUnit(tree.getPackage(), tree.getImports(), tree.getTypeDecls(), tree.getSourceFile()); model.setElement(n, model.getElement(tree)); comments.copyComments(tree, n); model.setPos(n, model.getPos(tree)); return n; }
@Override public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState state) { if (tree.getPackageName() == null) { return Description.NO_MATCH; } // package-info annotations are special // TODO(cushon): fix the core suppression logic to handle this if (ASTHelpers.hasAnnotation(tree.getPackage(), SuppressPackageLocation.class, state)) { return Description.NO_MATCH; } String packageName = tree.getPackageName().toString(); String actualFileName = ASTHelpers.getFileNameFromUri(tree.getSourceFile().toUri()); if (actualFileName == null) { return Description.NO_MATCH; } String actualPath = actualFileName.substring(0, actualFileName.lastIndexOf('/')); String expectedSuffix = "/" + DOT_MATCHER.replaceFrom(packageName, '/'); if (actualPath.endsWith(expectedSuffix)) { return Description.NO_MATCH; } String message = String.format( "Expected package %s to be declared in a directory ending with %s, instead found %s", packageName, expectedSuffix, actualPath); return buildDescription(tree.getPackageName()).setMessage(message).build(); } }
return make.CompilationUnit(cut.getPackage(), imports, cut.getTypeDecls(), cut.getSourceFile());