From 1e15e90d32959844cb876fa66f8c969f9c2dc18f Mon Sep 17 00:00:00 2001 From: Dave Friedel Date: Wed, 23 Jul 2025 06:27:48 -0400 Subject: [PATCH] README and SPECIFICATION updated --- API_SPECIFICATION.md | 49 +++++++++++++++++++++++++++++++++++++------- README.md | 15 ++++++++++++++ 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/API_SPECIFICATION.md b/API_SPECIFICATION.md index 29bacfc..5cd8b37 100644 --- a/API_SPECIFICATION.md +++ b/API_SPECIFICATION.md @@ -105,31 +105,54 @@ public abstract class TypeDeclaration : JavaNode { public string Name { get; set; } public Modifiers Modifiers { get; set; } - public List Members { get; set; } + public List Annotations { get; set; } + public List TypeParameters { get; set; } + public JavaDoc? JavaDoc { get; set; } + + // Gets the body/members of this type declaration + public abstract IEnumerable Body { get; } } public class ClassDeclaration : TypeDeclaration { - public TypeNode? Superclass { get; set; } - public List Interfaces { get; set; } - public List TypeParameters { get; set; } + public TypeReference? SuperClass { get; set; } + public List Interfaces { get; set; } + public List Members { get; set; } + public List NestedTypes { get; set; } + public bool IsRecord { get; set; } + + // Body includes both Members and NestedTypes + public override IEnumerable Body => Members.Concat(NestedTypes); } public class InterfaceDeclaration : TypeDeclaration { - public List ExtendedInterfaces { get; set; } - public List TypeParameters { get; set; } + public List ExtendedInterfaces { get; set; } + public List Members { get; set; } + public List NestedTypes { get; set; } + + // Body includes both Members and NestedTypes + public override IEnumerable Body => Members.Concat(NestedTypes); } public class EnumDeclaration : TypeDeclaration { + public List Interfaces { get; set; } public List Constants { get; set; } - public List Interfaces { get; set; } + public List Members { get; set; } + public List NestedTypes { get; set; } + + // Body includes Constants, Members and NestedTypes + public override IEnumerable Body => Constants.Concat(Members).Concat(NestedTypes); } public class AnnotationDeclaration : TypeDeclaration { public List Members { get; set; } + public List NestedTypes { get; set; } + + // Body includes both Members and NestedTypes + public override IEnumerable Body => Members.Concat(NestedTypes); } public class RecordDeclaration : TypeDeclaration @@ -720,6 +743,18 @@ var mainMethod = AstQuery.FirstOrDefault(compilationUnit, var containingClass = AstQuery.GetAncestors(method, compilationUnit) .OfType() .FirstOrDefault(); + +// Find all nested types in a class +var outerClass = compilationUnit.Types.OfType().First(); +var allNestedTypes = outerClass.NestedTypes; + +// Find nested interfaces specifically +var nestedInterfaces = outerClass.NestedTypes + .OfType(); + +// Recursively find all nested types (including deeply nested) +var allNested = AstQuery.FindAll(outerClass) + .Where(t => t != outerClass); ``` ## AST Transformation API diff --git a/README.md b/README.md index a51b549..1e426a7 100644 --- a/README.md +++ b/README.md @@ -82,9 +82,17 @@ CompilationUnit ├── ImportDeclaration[] └── TypeDeclaration[] ├── ClassDeclaration + │ ├── Members[] + │ └── NestedTypes[] ├── InterfaceDeclaration + │ ├── Members[] + │ └── NestedTypes[] ├── EnumDeclaration + │ ├── Constants[] + │ ├── Members[] + │ └── NestedTypes[] └── AnnotationDeclaration + └── Members[] ``` ### Visitor Pattern @@ -152,6 +160,13 @@ var serializableClasses = ast var getters = ast .FindAll() .Where(m => m.IsGetter()); + +// Access nested types +var outerClass = ast.Types.OfType().First(); +foreach (var nestedType in outerClass.NestedTypes) +{ + Console.WriteLine($"Nested: {nestedType.Name} ({nestedType.GetType().Name})"); +} ``` ### JSON Serialization