wu-sheng commented on code in PR #13723:
URL: https://github.com/apache/skywalking/pull/13723#discussion_r2883887909


##########
oap-server/analyzer/hierarchy/CLAUDE.md:
##########
@@ -0,0 +1,118 @@
+# Hierarchy Rule Compiler
+
+Compiles hierarchy matching rule expressions into `BiFunction<Service, 
Service, Boolean>` implementation classes at runtime using ANTLR4 parsing and 
Javassist bytecode generation.
+
+## Compilation Workflow
+
+```
+Rule expression string  (e.g., "{ (u, l) -> u.name == l.name }")
+  → HierarchyRuleScriptParser.parse(expression)   [ANTLR4 lexer/parser → 
visitor]
+  → HierarchyRuleModel (immutable AST)
+  → HierarchyRuleClassGenerator.compile(ruleName, expression)
+      1. classPool.makeClass()         — create class implementing BiFunction
+      2. generateApplyMethod(model)    — emit Java source for apply(Object, 
Object)
+      3. ctClass.toClass(HierarchyRulePackageHolder.class) — load via package 
anchor
+  → BiFunction<Service, Service, Boolean> instance
+```
+
+The generated class implements:
+```java
+Object apply(Object arg0, Object arg1)
+  // cast internally to Service and returns Boolean
+```
+
+No separate consumer/closure classes are needed — hierarchy rules are simple 
enough to compile into a single method body.
+
+## File Structure
+
+```
+oap-server/analyzer/hierarchy/
+  src/main/antlr4/.../HierarchyRuleLexer.g4     — ANTLR4 lexer grammar
+  src/main/antlr4/.../HierarchyRuleParser.g4    — ANTLR4 parser grammar
+
+  src/main/java/.../compiler/
+    HierarchyRuleScriptParser.java              — ANTLR4 facade: expression → 
AST
+    HierarchyRuleModel.java                     — Immutable AST model classes
+    HierarchyRuleClassGenerator.java            — Javassist code generator
+    CompiledHierarchyRuleProvider.java          — SPI provider: compiles rule 
expressions
+    hierarchy/rule/rt/
+      HierarchyRulePackageHolder.java           — Class loading anchor (empty 
marker)
+
+  src/main/resources/META-INF/services/
+    ...HierarchyDefinitionService$HierarchyRuleProvider — SPI registration
+
+  src/test/java/.../compiler/
+    HierarchyRuleScriptParserTest.java          — 5 parser tests
+    HierarchyRuleClassGeneratorTest.java        — 4 generator tests
+```
+
+## Package & Class Naming
+
+| Component | Package / Name |
+|-----------|---------------|
+| Parser/Model/Generator | 
`org.apache.skywalking.oap.server.core.config.compiler` |
+| Generated classes | 
`org.apache.skywalking.oap.server.core.config.compiler.hierarchy.rule.rt.HierarchyRule_<N>`
 |
+| Package holder | 
`org.apache.skywalking.oap.server.core.config.compiler.hierarchy.rule.rt.HierarchyRulePackageHolder`
 |
+| SPI provider | 
`org.apache.skywalking.oap.server.core.config.compiler.CompiledHierarchyRuleProvider`
 |

Review Comment:
   Fixed. Updated all four paths to include the `.v2.` segment.



-- 
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