desruisseaux commented on code in PR #1162:
URL: 
https://github.com/apache/maven-compiler-plugin/pull/1162#discussion_r4732223929


##########
src/main/java/org/apache/maven/plugin/compiler/incremental/BytecodeAnalyzer.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ *
+ *   http://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.
+ */
+package org.apache.maven.plugin.compiler.incremental;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.Set;
+
+/**
+ * Facade for analyzing compiled {@code .class} files to extract type 
references.
+ *
+ * <p>This class is part of a multi-release JAR. The root implementation 
(loaded on
+ * JDK &lt; 24) always throws {@link UnsupportedOperationException} from
+ * {@link #analyze} — bytecode analysis is not supported on JDK 17–23.
+ * The {@code META-INF/versions/24/} override (loaded automatically by the JVM
+ * on JDK 24+) provides the real implementation backed by the standard
+ * {@code java.lang.classfile} API.
+ *
+ * <p>The {@link ClassAnalysis} record carries the class name and two 
classified
+ * sets of type references: {@link ClassAnalysis#signatureTypes()} (API 
surface)
+ * and {@link ClassAnalysis#implementationTypes()} (method body instructions 
only).
+ */
+public final class BytecodeAnalyzer {
+
+    /**
+     * Prefix used to distinguish module-info qualified names from regular 
class names.
+     * A type name starting with this prefix is a module name, not a class 
name.
+     */
+    public static final String MODULE_PREFIX = "module:";
+
+    /**
+     * Analysis result for a single {@code .class} file.
+     *
+     * @param className           fully-qualified class name (dot-separated)
+     * @param signatureTypes      types appearing in public API surface 
(method/field descriptors,
+     *                            supertype, interfaces, exception types, 
annotation types)
+     * @param implementationTypes types appearing only in method body bytecode 
instructions
+     *                            (INVOKEVIRTUAL, NEW, CHECKCAST, field 
owners, etc.)
+     * @param annotationTypes     fully-qualified names of annotation types 
present on the class
+     *                            or its members, used for annotation 
processor cascade decisions
+     * @param moduleName          Java module name, or empty string if unnamed 
or non-modular
+     * @param isModuleInfo        {@code true} if this represents {@code 
module-info.class}
+     * @param sourceFileName      simple source file name from the {@code 
SourceFile} class file
+     *                            attribute (e.g. {@code "Foo.java"}); empty 
string if absent
+     */
+    public record ClassAnalysis(
+            String className,
+            Set<String> signatureTypes,
+            Set<String> implementationTypes,
+            Set<String> annotationTypes,
+            String moduleName,
+            boolean isModuleInfo,
+            String sourceFileName) {}
+
+    private BytecodeAnalyzer() {}
+
+    /**
+     * Analyzes the class file at {@code classFile}.
+     *
+     * @param classFile path to the {@code .class} file
+     * @return analysis result
+     * @throws IOException if reading the file fails
+     * @throws UnsupportedOperationException if called on JDK &lt; 24
+     */
+    public static ClassAnalysis analyze(Path classFile) throws IOException {
+        throw new UnsupportedOperationException("Bytecode analysis requires 
JDK 24 or later (running JDK "
+                + Runtime.version().feature()
+                + ").");
+    }

Review Comment:
   This method is defined in `java24` as simply reading all bytes from the file 
then delegating to `analyze(byte[])`. Since it does not depend on the JDK 
version, move that method to `GraphIncrementalBuild` (which is the class that 
needs it) for keeping in `BytecodeAnalyzer` the minimum number of methods that 
depend on the JDK version.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to