Skip to content

Commit

Permalink
update issue message
Browse files Browse the repository at this point in the history
  • Loading branch information
erwan-serandour committed Dec 16, 2024
1 parent 76c87a6 commit 8cbf08d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class MismatchPackageDirectoryCheck extends BaseTreeVisitor implements JavaFileScanner {

private JavaFileScannerContext context;
private static final String MESSAGE = "This file \"{0}\" should be located in \"{1}\" directory, not in \"{2}\"";
private static final String MESSAGE = "File path \"{0}\" should match package name \"{1}\". Move file or change package name";

@Override
public void scanFile(JavaFileScannerContext context) {
Expand All @@ -47,7 +47,10 @@ public void visitCompilationUnit(CompilationUnitTree tree) {
String dir = javaFile.getParent();
if (!dir.endsWith(packageName)) {
String dirWithoutDots = dir.replace(".", File.separator);
String issueMessage = MessageFormat.format(MESSAGE, javaFile.getName(), packageName, dir);
int srcIndex = dir.indexOf("src");
String truncatedPath = "/" + dir.substring(srcIndex == -1 ? 0 : srcIndex);
String issueMessage = MessageFormat.format(MESSAGE, truncatedPath, packageName);

if (dirWithoutDots.endsWith(packageName)) {
context.reportIssue(this, packageDeclaration.packageName(), issueMessage + "(Do not use dots in directory names).");
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.foo.mismatchPackage; // Noncompliant
package org.foo.mismatchPackage; // Noncompliant {{File path "/src/test/files/checks/mismatchPackage" should match package name "org/foo/mismatchPackage". Move file or change package name.}}
// ^^^^^^^^^^^^^^^^^^^^^^^

class Mismatch {}

0 comments on commit 8cbf08d

Please sign in to comment.