`
+* If a method has **no tags**, it prints `TAGS=-`
+
+Example:
+
+```text
+Feb 11, 2026 1:33:35 AM org.egothor.methodatlas.MethodAtlasApp scanRoot
+INFO: Scanning /tmp/junit-12139245189413750595 for JUnit files
+com.acme.tests.SampleOneTest, alpha, LOC=8, TAGS=fast;crypto
+com.acme.tests.SampleOneTest, beta, LOC=6, TAGS=param
+com.acme.tests.SampleOneTest, gamma, LOC=4, TAGS=nested1;nested2
+com.acme.other.AnotherTest, delta, LOC=3, TAGS=-
+```
+
+## Notes
+
+* The scanner looks for files ending with `*Test.java`.
+* JUnit methods are detected by annotations such as:
+ * `@Test`
+ * `@ParameterizedTest`
+ * `@RepeatedTest`
+* Tag extraction supports:
+ * `@Tag("x")` (including repeated `@Tag`)
+ * `@Tags({ @Tag("x"), @Tag("y") })`
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000..b2cdac2
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,68 @@
+plugins {
+ id 'java'
+ id 'application'
+}
+
+group = 'org.egothor.methodatlas'
+version = '0.1.0-SNAPSHOT'
+
+java {
+ toolchain {
+ languageVersion = JavaLanguageVersion.of(21)
+ }
+}
+
+repositories {
+ mavenCentral()
+}
+
+dependencies {
+ implementation 'com.github.javaparser:javaparser-core:3.28.0'
+
+ testImplementation(platform("org.junit:junit-bom:5.14.2"))
+ testImplementation 'org.junit.jupiter:junit-jupiter'
+ testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
+}
+
+application {
+ mainClass = 'org.egothor.methodatlas.MethodAtlasApp'
+}
+
+tasks.test {
+ useJUnitPlatform()
+}
+
+jar {
+ manifest {
+ attributes(
+ 'Main-Class': application.mainClass,
+ 'Implementation-Title': rootProject.name,
+ 'Implementation-Version': "${version}"
+ )
+ }
+
+ from sourceSets.main.output
+
+ dependsOn configurations.runtimeClasspath
+
+ // Include each JAR dependency
+ configurations.runtimeClasspath.findAll { it.exists() && it.name.endsWith('.jar') }.each { jarFile ->
+ def jarName = jarFile.name.replaceAll(/\.jar$/, '')
+
+ from(zipTree(jarFile)) {
+ // Exclude signature-related files
+ exclude 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA'
+
+ // Rename license/notice files to avoid conflicts
+ eachFile { file ->
+ if (file.path ==~ /META-INF\/(LICENSE|NOTICE)(\..*)?/) {
+ file.path = "META-INF/licenses-from-${jarName}/${file.name}"
+ }
+ }
+
+ includeEmptyDirs = false
+ }
+ }
+
+ duplicatesStrategy = DuplicatesStrategy.EXCLUDE
+}
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
new file mode 100644
index 0000000..cc61ce4
--- /dev/null
+++ b/gradle/libs.versions.toml
@@ -0,0 +1,12 @@
+# This file was generated by the Gradle 'init' task.
+# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format
+
+[versions]
+commons-math3 = "3.6.1"
+guava = "33.1.0-jre"
+junit-jupiter = "5.10.2"
+
+[libraries]
+commons-math3 = { module = "org.apache.commons:commons-math3", version.ref = "commons-math3" }
+guava = { module = "com.google.guava:guava", version.ref = "guava" }
+junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..2c35211
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..09523c0
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,7 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
+networkTimeout=10000
+validateDistributionUrl=true
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
new file mode 100755
index 0000000..f5feea6
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,252 @@
+#!/bin/sh
+
+#
+# Copyright © 2015-2021 the original authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+##############################################################################
+#
+# Gradle start up script for POSIX generated by Gradle.
+#
+# Important for running:
+#
+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+# noncompliant, but you have some other compliant shell such as ksh or
+# bash, then to run this script, type that shell name before the whole
+# command line, like:
+#
+# ksh Gradle
+#
+# Busybox and similar reduced shells will NOT work, because this script
+# requires all of these POSIX shell features:
+# * functions;
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
+#
+# Important for patching:
+#
+# (2) This script targets any POSIX shell, so it avoids extensions provided
+# by Bash, Ksh, etc; in particular arrays are avoided.
+#
+# The "traditional" practice of packing multiple parameters into a
+# space-separated string is a well documented source of bugs and security
+# problems, so this is (mostly) avoided, by progressively accumulating
+# options in "$@", and eventually passing that to Java.
+#
+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+# see the in-line comments for details.
+#
+# There are tweaks for specific operating systems such as AIX, CygWin,
+# Darwin, MinGW, and NonStop.
+#
+# (3) This script is generated from the Groovy template
+# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# within the Gradle project.
+#
+# You can find Gradle at https://github.com/gradle/gradle/.
+#
+##############################################################################
+
+# Attempt to set APP_HOME
+
+# Resolve links: $0 may be a link
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
+ [ -h "$app_path" ]
+do
+ ls=$( ls -ld "$app_path" )
+ link=${ls#*' -> '}
+ case $link in #(
+ /*) app_path=$link ;; #(
+ *) app_path=$APP_HOME$link ;;
+ esac
+done
+
+# This is normally unused
+# shellcheck disable=SC2034
+APP_BASE_NAME=${0##*/}
+# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
+APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
+' "$PWD" ) || exit
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD=maximum
+
+warn () {
+ echo "$*"
+} >&2
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+} >&2
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "$( uname )" in #(
+ CYGWIN* ) cygwin=true ;; #(
+ Darwin* ) darwin=true ;; #(
+ MSYS* | MINGW* ) msys=true ;; #(
+ NONSTOP* ) nonstop=true ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD=$JAVA_HOME/jre/sh/java
+ else
+ JAVACMD=$JAVA_HOME/bin/java
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD=java
+ if ! command -v java >/dev/null 2>&1
+ then
+ die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+fi
+
+# Increase the maximum file descriptors if we can.
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
+ esac
+fi
+
+# Collect all arguments for the java command, stacking in reverse order:
+# * args from the command line
+# * the main class name
+# * -classpath
+# * -D...appname settings
+# * --module-path (only if needed)
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
+
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ for arg do
+ if
+ case $arg in #(
+ -*) false ;; # don't mess with options #(
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
+ [ -e "$t" ] ;; #(
+ *) false ;;
+ esac
+ then
+ arg=$( cygpath --path --ignore --mixed "$arg" )
+ fi
+ # Roll the args list around exactly as many times as the number of
+ # args, so each arg winds up back in the position where it started, but
+ # possibly modified.
+ #
+ # NB: a `for` loop captures its iteration list before it begins, so
+ # changing the positional parameters here affects neither the number of
+ # iterations, nor the values presented in `arg`.
+ shift # remove old arg
+ set -- "$@" "$arg" # push replacement arg
+ done
+fi
+
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Collect all arguments for the java command:
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
+# and any embedded shellness will be escaped.
+# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
+# treated as '${Hostname}' itself on the command line.
+
+set -- \
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
+ -classpath "$CLASSPATH" \
+ org.gradle.wrapper.GradleWrapperMain \
+ "$@"
+
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+ die "xargs is not available"
+fi
+
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+# set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+ xargs -n1 |
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+ tr '\n' ' '
+ )" '"$@"'
+
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 0000000..9d21a21
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,94 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+@rem SPDX-License-Identifier: Apache-2.0
+@rem
+
+@if "%DEBUG%"=="" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%"=="" set DIRNAME=.
+@rem This is normally unused
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if %ERRORLEVEL% equ 0 goto execute
+
+echo. 1>&2
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo. 1>&2
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if %ERRORLEVEL% equ 0 goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+set EXIT_CODE=%ERRORLEVEL%
+if %EXIT_CODE% equ 0 set EXIT_CODE=1
+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
+exit /b %EXIT_CODE%
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/lib/.project b/lib/.project
new file mode 100644
index 0000000..674e601
--- /dev/null
+++ b/lib/.project
@@ -0,0 +1,23 @@
+
+
+ MethodAtlas-lib
+ Project MethodAtlas-lib created by Buildship.
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.buildship.core.gradleprojectbuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.eclipse.buildship.core.gradleprojectnature
+
+
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..7ba098e
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1 @@
+rootProject.name = 'methodatlas'
diff --git a/src/main/java/org/egothor/methodatlas/MethodAtlasApp.java b/src/main/java/org/egothor/methodatlas/MethodAtlasApp.java
new file mode 100644
index 0000000..25b6bf6
--- /dev/null
+++ b/src/main/java/org/egothor/methodatlas/MethodAtlasApp.java
@@ -0,0 +1,443 @@
+package org.egothor.methodatlas;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import com.github.javaparser.ParserConfiguration;
+import com.github.javaparser.ParserConfiguration.LanguageLevel;
+import com.github.javaparser.StaticJavaParser;
+import com.github.javaparser.ast.CompilationUnit;
+import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
+import com.github.javaparser.ast.body.MethodDeclaration;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.expr.ArrayInitializerExpr;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.expr.MemberValuePair;
+
+/**
+ * Command-line utility that scans Java source trees for JUnit test methods and
+ * reports per-method statistics.
+ *
+ *
+ * The tool walks one or more root directories, parses {@code *Test.java} files
+ * using JavaParser, and emits a record for each method annotated with one of
+ * the supported JUnit Jupiter test annotations.
+ *
+ *
+ * Detection
+ *
+ * - Test methods are detected by annotations {@code @Test},
+ * {@code @ParameterizedTest}, and {@code @RepeatedTest} (simple name
+ * match).
+ * - {@code @Tag} values are collected from repeated {@code @Tag("...")}
+ * annotations and from {@code @Tags({ @Tag("..."), ... })} containers.
+ * - Lines of code (LOC) is computed from the AST source range:
+ * {@code endLine - beginLine + 1}. If the range is unavailable, LOC is
+ * {@code 0}.
+ *
+ *
+ * Output
+ *
+ * By default, the tool prints CSV with a header line:
+ * {@code fqcn,method,loc,tags}. The {@code tags} field is a semicolon-separated
+ * list.
+ *
+ *
+ *
+ * If {@code -plain} is provided as the first argument, the tool prints a plain
+ * text format:
+ *
+ *
+ * fqcn, method, LOC=<n>, TAGS=<tag1;tag2>
+ *
+ *
+ * If no tags are present, {@code TAGS=-} is printed.
+ *
+ *
+ * Examples
+ * java -jar methodatlas.jar /path/to/repo
+ * java -jar methodatlas.jar -plain /path/to/repo /another/repo
+ *
+ */
+public class MethodAtlasApp {
+ /**
+ * Logging facility for scan progress and parse failures.
+ */
+ private static final Logger LOG = Logger.getLogger(MethodAtlasApp.class.getName());
+
+ /**
+ * Output formats supported by the application.
+ */
+ private enum OutputMode {
+ /**
+ * Comma-separated values with a header line and raw numeric LOC.
+ */
+ CSV,
+ /**
+ * Plain text lines including {@code LOC=} and {@code TAGS=} labels.
+ */
+ PLAIN
+ }
+
+ /**
+ * Program entry point.
+ *
+ *
+ * Usage:
+ *
+ *
+ * java -jar methodatlas.jar [ -plain ] <path1> [ <path2> ... ]
+ *
+ *
+ *
+ * - If {@code -plain} is provided as the first argument, the tool uses the
+ * plain-text output mode; otherwise CSV output is used.
+ * - If no paths are provided, the current directory {@code "."} is
+ * scanned.
+ *
+ *
+ *
+ * The JavaParser language level is configured before parsing to support modern
+ * Java syntax (for example, {@code record} declarations).
+ *
+ *
+ * @param args command-line arguments; see usage above
+ * @throws IOException if directory traversal fails while scanning input paths
+ */
+ public static void main(String[] args) throws IOException {
+ ParserConfiguration pc = new ParserConfiguration();
+ pc.setLanguageLevel(LanguageLevel.JAVA_21); // or JAVA_17, etc.
+ StaticJavaParser.setConfiguration(pc);
+
+ OutputMode mode = OutputMode.CSV;
+ int firstPathIndex = 0;
+
+ if (args.length > 0 && "-plain".equals(args[0])) {
+ mode = OutputMode.PLAIN;
+ firstPathIndex = 1;
+ }
+
+ if (mode == OutputMode.CSV) {
+ System.out.println("fqcn,method,loc,tags");
+ }
+
+ if (args.length <= firstPathIndex) {
+ scanRoot(Paths.get("."), mode);
+ return;
+ }
+
+ for (int i = firstPathIndex; i < args.length; i++) {
+ scanRoot(Paths.get(args[i]), mode);
+ }
+ }
+
+ /**
+ * Recursively scans the supplied root directory for Java test files and
+ * processes them.
+ *
+ *
+ * The current implementation matches files by suffix {@code "Test.java"}.
+ *
+ *
+ * @param root root directory to scan
+ * @param mode output mode to use for emitted records
+ * @throws IOException if the file tree walk fails
+ */
+ private static void scanRoot(Path root, OutputMode mode) throws IOException {
+ LOG.log(Level.INFO, "Scanning {0} for JUnit files", root);
+
+ Files.walk(root).filter(p -> p.toString().endsWith("Test.java")).forEach(p -> processFile(p, mode));
+ }
+
+ /**
+ * Parses a single Java source file and emits records for all detected JUnit
+ * test methods.
+ *
+ *
+ * Parse errors are logged. Files that cannot be parsed are skipped.
+ *
+ *
+ * @param path Java source file to parse
+ * @param mode output mode to use for emitted records
+ */
+ private static void processFile(Path path, OutputMode mode) {
+ try {
+ CompilationUnit cu = StaticJavaParser.parse(path);
+
+ String pkg = cu.getPackageDeclaration().map(p -> p.getNameAsString()).orElse("");
+
+ cu.findAll(ClassOrInterfaceDeclaration.class).forEach(clazz -> {
+ String className = clazz.getNameAsString();
+ String fqcn = pkg.isEmpty() ? className : pkg + "." + className;
+
+ clazz.findAll(MethodDeclaration.class).forEach(method -> {
+ if (isJUnitTest(method)) {
+ int loc = countLOC(method);
+ List tags = getTagValues(method);
+ emit(mode, fqcn, method.getNameAsString(), loc, tags);
+ }
+ });
+ });
+
+ } catch (Exception e) {
+ LOG.log(Level.WARNING, "Failed to parse: {0}", path);
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Emits a single output record representing one test method.
+ *
+ *
+ * For CSV output, values are printed as {@code fqcn,method,loc,tags} with CSV
+ * escaping applied to text fields. The {@code tags} field is a
+ * semicolon-separated list, or an empty field if no tags exist.
+ *
+ *
+ *
+ * For plain output, labels {@code LOC=} and {@code TAGS=} are included. If no
+ * tags exist, {@code TAGS=-} is printed.
+ *
+ *
+ * @param mode output mode to use
+ * @param fqcn fully-qualified class name
+ * @param method method name
+ * @param loc lines of code for the method declaration (inclusive range)
+ * @param tags list of tag values; may be empty
+ */
+ private static void emit(OutputMode mode, String fqcn, String method, int loc, List tags) {
+ if (mode == OutputMode.PLAIN) {
+ String tagText = tags.isEmpty() ? "-" : String.join(";", tags);
+ System.out.println(fqcn + ", " + method + ", LOC=" + loc + ", TAGS=" + tagText);
+ return;
+ }
+
+ String tagText = tags.isEmpty() ? "" : String.join(";", tags);
+ System.out.println(csvEscape(fqcn) + "," + csvEscape(method) + "," + loc + "," + csvEscape(tagText));
+ }
+
+ /**
+ * Escapes a value for safe inclusion in a CSV field.
+ *
+ *
+ * If the value contains a comma, quote, or line break, the value is quoted and
+ * internal quotes are doubled, per common CSV conventions.
+ *
+ *
+ * @param value input value; may be {@code null}
+ * @return escaped CSV field value (never {@code null})
+ */
+ private static String csvEscape(String value) {
+ if (value == null) {
+ return "";
+ }
+ boolean mustQuote = value.indexOf(',') >= 0 || value.indexOf('"') >= 0 || value.indexOf('\n') >= 0
+ || value.indexOf('\r') >= 0;
+
+ if (!mustQuote) {
+ return value;
+ }
+ return "\"" + value.replace("\"", "\"\"") + "\"";
+ }
+
+ /**
+ * Determines whether the given method declaration represents a JUnit Jupiter
+ * test method.
+ *
+ *
+ * The method is considered a test if it is annotated with one of the supported
+ * test annotations by simple name: {@code Test}, {@code ParameterizedTest}, or
+ * {@code RepeatedTest}.
+ *
+ *
+ * @param method method declaration to inspect
+ * @return {@code true} if the method is considered a test method; {@code false}
+ * otherwise
+ */
+ private static boolean isJUnitTest(MethodDeclaration method) {
+ for (AnnotationExpr ann : method.getAnnotations()) {
+ String name = ann.getNameAsString();
+ if ("Test".equals(name) || "ParameterizedTest".equals(name) || "RepeatedTest".equals(name)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Collects all {@code @Tag} values declared directly on a method.
+ *
+ *
+ * Supported forms:
+ *
+ *
+ * - Repeated {@code @Tag("...")} annotations
+ * - {@code @Tags({ @Tag("..."), @Tag("...") })} container annotation
+ *
+ *
+ * @param method method declaration to inspect
+ * @return list of tag values in encounter order; never {@code null}
+ */
+ private static List getTagValues(MethodDeclaration method) {
+ List tags = new ArrayList<>();
+
+ for (AnnotationExpr ann : method.getAnnotations()) {
+ String name = ann.getNameAsString();
+ if (isTagAnnotationName(name)) {
+ extractTagValue(ann).ifPresent(tags::add);
+ } else if (isTagsContainerAnnotationName(name)) {
+ tags.addAll(extractTagValuesFromContainer(ann));
+ }
+ }
+
+ return tags;
+ }
+
+ /**
+ * Checks whether an annotation name represents {@code @Tag}.
+ *
+ * @param name annotation name (simple or qualified)
+ * @return {@code true} if it matches {@code Tag}; {@code false} otherwise
+ */
+ private static boolean isTagAnnotationName(String name) {
+ return "Tag".equals(name) || name.endsWith(".Tag");
+ }
+
+ /**
+ * Checks whether an annotation name represents {@code @Tags} (the container for
+ * {@code @Tag}).
+ *
+ * @param name annotation name (simple or qualified)
+ * @return {@code true} if it matches {@code Tags}; {@code false} otherwise
+ */
+ private static boolean isTagsContainerAnnotationName(String name) {
+ return "Tags".equals(name) || name.endsWith(".Tags");
+ }
+
+ /**
+ * Extracts the tag value from a {@code @Tag} annotation expression.
+ *
+ *
+ * Both single-member and normal annotation syntaxes are supported:
+ *
+ *
+ * - {@code @Tag("fast")}
+ * - {@code @Tag(value = "fast")}
+ *
+ *
+ * @param ann annotation expression representing {@code @Tag}
+ * @return extracted tag value, or empty if it cannot be determined
+ */
+ private static Optional extractTagValue(AnnotationExpr ann) {
+ if (ann.isSingleMemberAnnotationExpr()) {
+ return Optional.of(expressionToTagText(ann.asSingleMemberAnnotationExpr().getMemberValue()));
+ }
+
+ if (ann.isNormalAnnotationExpr()) {
+ for (MemberValuePair pair : ann.asNormalAnnotationExpr().getPairs()) {
+ if ("value".equals(pair.getNameAsString())) {
+ return Optional.of(expressionToTagText(pair.getValue()));
+ }
+ }
+ }
+
+ return Optional.empty();
+ }
+
+ /**
+ * Extracts all contained {@code @Tag} values from a {@code @Tags} container
+ * annotation.
+ *
+ *
+ * Handles array initializers such as:
+ *
+ *
+ * @Tags({ @Tag("a"), @Tag("b") })
+ *
+ *
+ * @param ann annotation expression representing {@code @Tags}
+ * @return list of extracted tag values; never {@code null}
+ */
+ private static List extractTagValuesFromContainer(AnnotationExpr ann) {
+ List tags = new ArrayList<>();
+ Optional maybeValue = Optional.empty();
+
+ if (ann.isSingleMemberAnnotationExpr()) {
+ maybeValue = Optional.of(ann.asSingleMemberAnnotationExpr().getMemberValue());
+ } else if (ann.isNormalAnnotationExpr()) {
+ for (MemberValuePair pair : ann.asNormalAnnotationExpr().getPairs()) {
+ if ("value".equals(pair.getNameAsString())) {
+ maybeValue = Optional.of(pair.getValue());
+ break;
+ }
+ }
+ }
+
+ if (maybeValue.isEmpty()) {
+ return tags;
+ }
+
+ Expression value = maybeValue.get();
+ if (value.isArrayInitializerExpr()) {
+ ArrayInitializerExpr array = value.asArrayInitializerExpr();
+ for (Expression element : array.getValues()) {
+ if (element.isAnnotationExpr()) {
+ AnnotationExpr inner = element.asAnnotationExpr();
+ if (isTagAnnotationName(inner.getNameAsString())) {
+ extractTagValue(inner).ifPresent(tags::add);
+ }
+ }
+ }
+ } else if (value.isAnnotationExpr()) {
+ AnnotationExpr inner = value.asAnnotationExpr();
+ if (isTagAnnotationName(inner.getNameAsString())) {
+ extractTagValue(inner).ifPresent(tags::add);
+ }
+ }
+
+ return tags;
+ }
+
+ /**
+ * Converts an annotation value expression to tag text.
+ *
+ *
+ * String literals are returned as their unescaped string value. Other
+ * expressions are returned using {@link Expression#toString()}.
+ *
+ *
+ * @param expr expression to convert; may be {@code null}
+ * @return converted tag text (never {@code null})
+ */
+ private static String expressionToTagText(Expression expr) {
+ if (expr == null) {
+ return "";
+ }
+ if (expr.isStringLiteralExpr()) {
+ return expr.asStringLiteralExpr().asString();
+ }
+ return expr.toString();
+ }
+
+ /**
+ * Computes the lines of code (LOC) for a method declaration using its source
+ * range.
+ *
+ * @param method method declaration
+ * @return inclusive LOC computed from the source range; {@code 0} if range is
+ * not available
+ */
+ private static int countLOC(MethodDeclaration method) {
+ if (method.getRange().isPresent()) {
+ return method.getRange().get().end.line - method.getRange().get().begin.line + 1;
+ }
+ return 0;
+ }
+}
diff --git a/src/main/java/org/egothor/methodatlas/package-info.java b/src/main/java/org/egothor/methodatlas/package-info.java
new file mode 100644
index 0000000..01fe1fb
--- /dev/null
+++ b/src/main/java/org/egothor/methodatlas/package-info.java
@@ -0,0 +1,18 @@
+/**
+ * Provides the {@code MethodAtlasApp} command-line utility for scanning Java
+ * source trees for JUnit test methods and emitting per-method statistics.
+ *
+ *
+ * The primary entry point is {@link org.egothor.methodatlas.MethodAtlasApp}.
+ *
+ *
+ *
+ * Output modes:
+ *
+ *
+ * - CSV (default): {@code fqcn,method,loc,tags}
+ * - Plain text: enabled by {@code -plain} as the first command-line
+ * argument
+ *
+ */
+package org.egothor.methodatlas;
\ No newline at end of file
diff --git a/src/test/java/org/egothor/methodatlas/MethodAtlasAppTest.java b/src/test/java/org/egothor/methodatlas/MethodAtlasAppTest.java
new file mode 100644
index 0000000..5c4bda8
--- /dev/null
+++ b/src/test/java/org/egothor/methodatlas/MethodAtlasAppTest.java
@@ -0,0 +1,242 @@
+package org.egothor.methodatlas;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * End-to-end tests for {@link MethodAtlasApp} output formats (CSV default,
+ * -plain).
+ *
+ * These tests copy predefined Java fixture files from
+ * src/test/resources/fixtures into a temporary directory and run
+ * MethodAtlasApp.main(...) against that directory, asserting the detected
+ * methods, LOC, and extracted @Tag values.
+ */
+public class MethodAtlasAppTest {
+
+ @Test
+ public void csvMode_detectsMethodsLocAndTags(@TempDir Path tempDir) throws Exception {
+ copyFixture(tempDir, "SampleOneTest.java");
+ copyFixture(tempDir, "AnotherTest.java");
+
+ String output = runAppCapturingStdout(new String[] { tempDir.toString() });
+
+ List lines = nonEmptyLines(output);
+ assertTrue(lines.size() >= 3, "Expected header + at least 2 records, got: " + lines.size());
+
+ assertEquals("fqcn,method,loc,tags", lines.get(0));
+
+ Map rows = new HashMap<>();
+ for (int i = 1; i < lines.size(); i++) {
+ CsvRow row = parseCsvRow(lines.get(i));
+ rows.put(row.fqcn + "#" + row.method, row);
+ }
+
+ assertCsvRow(rows, "com.acme.tests.SampleOneTest", "alpha", 8, List.of("fast", "crypto"));
+ assertCsvRow(rows, "com.acme.tests.SampleOneTest", "beta", 6, List.of("param"));
+ assertCsvRow(rows, "com.acme.tests.SampleOneTest", "gamma", 4, List.of("nested1", "nested2"));
+ assertCsvRow(rows, "com.acme.other.AnotherTest", "delta", 3, List.of());
+ }
+
+ @Test
+ public void plainMode_detectsMethodsLocAndTags(@TempDir Path tempDir) throws Exception {
+ copyFixture(tempDir, "SampleOneTest.java");
+ copyFixture(tempDir, "AnotherTest.java");
+
+ String output = runAppCapturingStdout(new String[] { "-plain", tempDir.toString() });
+
+ List lines = nonEmptyLines(output);
+ assertTrue(lines.size() >= 4, "Expected at least 4 method lines, got: " + lines.size());
+
+ Map rows = new HashMap<>();
+ for (String line : lines) {
+ PlainRow row = parsePlainRow(line);
+ rows.put(row.fqcn + "#" + row.method, row);
+ }
+
+ assertPlainRow(rows, "com.acme.tests.SampleOneTest", "alpha", 8, "fast;crypto");
+ assertPlainRow(rows, "com.acme.tests.SampleOneTest", "beta", 6, "param");
+ assertPlainRow(rows, "com.acme.tests.SampleOneTest", "gamma", 4, "nested1;nested2");
+ assertPlainRow(rows, "com.acme.other.AnotherTest", "delta", 3, "-");
+ }
+
+ private static void assertCsvRow(Map rows, String fqcn, String method, int expectedLoc,
+ List expectedTags) {
+
+ CsvRow row = rows.get(fqcn + "#" + method);
+ assertNotNull(row, "Missing row for " + fqcn + "#" + method);
+
+ assertEquals(expectedLoc, row.loc, "LOC mismatch for " + fqcn + "#" + method);
+ assertEquals(expectedTags, row.tags, "Tags mismatch for " + fqcn + "#" + method);
+ }
+
+ private static void assertPlainRow(Map rows, String fqcn, String method, int expectedLoc,
+ String expectedTagsText) {
+
+ PlainRow row = rows.get(fqcn + "#" + method);
+ assertNotNull(row, "Missing row for " + fqcn + "#" + method);
+
+ assertEquals(expectedLoc, row.loc, "LOC mismatch for " + fqcn + "#" + method);
+ assertEquals(expectedTagsText, row.tagsText, "Tags mismatch for " + fqcn + "#" + method);
+ }
+
+ private static void copyFixture(Path destDir, String fixtureFileName) throws IOException {
+ String resourcePath = "/fixtures/" + fixtureFileName + ".txt";
+ try (InputStream in = MethodAtlasAppTest.class.getResourceAsStream(resourcePath)) {
+ assertNotNull(in, "Missing test resource: " + resourcePath);
+
+ Path out = destDir.resolve(fixtureFileName);
+ Files.copy(in, out);
+ }
+ }
+
+ private static String runAppCapturingStdout(String[] args) throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintStream previous = System.out;
+
+ try (PrintStream ps = new PrintStream(baos, true, StandardCharsets.UTF_8)) {
+ System.setOut(ps);
+ MethodAtlasApp.main(args);
+ } finally {
+ System.setOut(previous);
+ }
+
+ return baos.toString(StandardCharsets.UTF_8);
+ }
+
+ private static List nonEmptyLines(String text) {
+ String[] parts = text.split("\\R");
+ List lines = new ArrayList<>();
+ for (String p : parts) {
+ String trimmed = p.trim();
+ if (!trimmed.isEmpty()) {
+ lines.add(trimmed);
+ }
+ }
+ return lines;
+ }
+
+ private static CsvRow parseCsvRow(String line) {
+ List fields = parseCsvFields(line);
+ assertEquals(4, fields.size(), "Expected 4 CSV fields, got " + fields.size() + " from: " + line);
+
+ CsvRow row = new CsvRow();
+ row.fqcn = fields.get(0);
+ row.method = fields.get(1);
+ row.loc = Integer.parseInt(fields.get(2));
+
+ String tagsText = fields.get(3);
+ row.tags = splitTags(tagsText);
+
+ return row;
+ }
+
+ private static List splitTags(String tagsText) {
+ List tags = new ArrayList<>();
+ if (tagsText == null || tagsText.isEmpty()) {
+ return tags;
+ }
+ String[] parts = tagsText.split(";");
+ for (String p : parts) {
+ String t = p.trim();
+ if (!t.isEmpty()) {
+ tags.add(t);
+ }
+ }
+ return tags;
+ }
+
+ /**
+ * Minimal CSV parser that supports commas and quotes.
+ */
+ private static List parseCsvFields(String line) {
+ List out = new ArrayList<>();
+ StringBuilder current = new StringBuilder();
+
+ boolean inQuotes = false;
+ int i = 0;
+ while (i < line.length()) {
+ char ch = line.charAt(i);
+
+ if (inQuotes) {
+ if (ch == '\"') {
+ if (i + 1 < line.length() && line.charAt(i + 1) == '\"') {
+ current.append('\"');
+ i += 2;
+ continue;
+ }
+ inQuotes = false;
+ i++;
+ continue;
+ }
+ current.append(ch);
+ i++;
+ continue;
+ }
+
+ if (ch == '\"') {
+ inQuotes = true;
+ i++;
+ continue;
+ }
+
+ if (ch == ',') {
+ out.add(current.toString());
+ current.setLength(0);
+ i++;
+ continue;
+ }
+
+ current.append(ch);
+ i++;
+ }
+
+ out.add(current.toString());
+ return out;
+ }
+
+ private static PlainRow parsePlainRow(String line) {
+ Pattern p = Pattern.compile("^(.*),\\s+(.*),\\s+LOC=(\\d+),\\s+TAGS=(.*)$");
+ Matcher m = p.matcher(line);
+ assertTrue(m.matches(), "Unexpected plain output line: " + line);
+
+ PlainRow row = new PlainRow();
+ row.fqcn = m.group(1).trim();
+ row.method = m.group(2).trim();
+ row.loc = Integer.parseInt(m.group(3));
+ row.tagsText = m.group(4).trim();
+ return row;
+ }
+
+ private static final class CsvRow {
+ private String fqcn;
+ private String method;
+ private int loc;
+ private List tags;
+ }
+
+ private static final class PlainRow {
+ private String fqcn;
+ private String method;
+ private int loc;
+ private String tagsText;
+ }
+}
diff --git a/src/test/resources/fixtures/AnotherTest.java.txt b/src/test/resources/fixtures/AnotherTest.java.txt
new file mode 100644
index 0000000..8991a7e
--- /dev/null
+++ b/src/test/resources/fixtures/AnotherTest.java.txt
@@ -0,0 +1,10 @@
+package com.acme.other;
+
+import org.junit.jupiter.api.RepeatedTest;
+
+public class AnotherTest {
+
+ @RepeatedTest(2)
+ void delta() {
+ }
+}
diff --git a/src/test/resources/fixtures/SampleOneTest.java.txt b/src/test/resources/fixtures/SampleOneTest.java.txt
new file mode 100644
index 0000000..25b4f00
--- /dev/null
+++ b/src/test/resources/fixtures/SampleOneTest.java.txt
@@ -0,0 +1,31 @@
+package com.acme.tests;
+
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Tags;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+public class SampleOneTest {
+
+ @Test
+ @Tag("fast")
+ @Tag("crypto")
+ void alpha() {
+ int a = 1;
+ int b = 2;
+ int c = a + b;
+ }
+
+ @ParameterizedTest
+ @ValueSource(ints = { 1, 2 })
+ @Tag("param")
+ void beta(int x) {
+ // single line
+ }
+
+ @Test
+ @Tags({ @Tag("nested1"), @Tag("nested2") })
+ void gamma() {
+ }
+}