README and SPECIFICATION updated
This commit is contained in:
@@ -105,31 +105,54 @@ public abstract class TypeDeclaration : JavaNode
|
|||||||
{
|
{
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public Modifiers Modifiers { get; set; }
|
public Modifiers Modifiers { get; set; }
|
||||||
public List<MemberDeclaration> Members { get; set; }
|
public List<Annotation> Annotations { get; set; }
|
||||||
|
public List<TypeParameter> TypeParameters { get; set; }
|
||||||
|
public JavaDoc? JavaDoc { get; set; }
|
||||||
|
|
||||||
|
// Gets the body/members of this type declaration
|
||||||
|
public abstract IEnumerable<JavaNode> Body { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ClassDeclaration : TypeDeclaration
|
public class ClassDeclaration : TypeDeclaration
|
||||||
{
|
{
|
||||||
public TypeNode? Superclass { get; set; }
|
public TypeReference? SuperClass { get; set; }
|
||||||
public List<TypeNode> Interfaces { get; set; }
|
public List<TypeReference> Interfaces { get; set; }
|
||||||
public List<TypeParameter> TypeParameters { get; set; }
|
public List<MemberDeclaration> Members { get; set; }
|
||||||
|
public List<TypeDeclaration> NestedTypes { get; set; }
|
||||||
|
public bool IsRecord { get; set; }
|
||||||
|
|
||||||
|
// Body includes both Members and NestedTypes
|
||||||
|
public override IEnumerable<JavaNode> Body => Members.Concat(NestedTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class InterfaceDeclaration : TypeDeclaration
|
public class InterfaceDeclaration : TypeDeclaration
|
||||||
{
|
{
|
||||||
public List<TypeNode> ExtendedInterfaces { get; set; }
|
public List<TypeReference> ExtendedInterfaces { get; set; }
|
||||||
public List<TypeParameter> TypeParameters { get; set; }
|
public List<MemberDeclaration> Members { get; set; }
|
||||||
|
public List<TypeDeclaration> NestedTypes { get; set; }
|
||||||
|
|
||||||
|
// Body includes both Members and NestedTypes
|
||||||
|
public override IEnumerable<JavaNode> Body => Members.Concat(NestedTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EnumDeclaration : TypeDeclaration
|
public class EnumDeclaration : TypeDeclaration
|
||||||
{
|
{
|
||||||
|
public List<TypeReference> Interfaces { get; set; }
|
||||||
public List<EnumConstant> Constants { get; set; }
|
public List<EnumConstant> Constants { get; set; }
|
||||||
public List<TypeNode> Interfaces { get; set; }
|
public List<MemberDeclaration> Members { get; set; }
|
||||||
|
public List<TypeDeclaration> NestedTypes { get; set; }
|
||||||
|
|
||||||
|
// Body includes Constants, Members and NestedTypes
|
||||||
|
public override IEnumerable<JavaNode> Body => Constants.Concat(Members).Concat(NestedTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AnnotationDeclaration : TypeDeclaration
|
public class AnnotationDeclaration : TypeDeclaration
|
||||||
{
|
{
|
||||||
public List<AnnotationMember> Members { get; set; }
|
public List<AnnotationMember> Members { get; set; }
|
||||||
|
public List<TypeDeclaration> NestedTypes { get; set; }
|
||||||
|
|
||||||
|
// Body includes both Members and NestedTypes
|
||||||
|
public override IEnumerable<JavaNode> Body => Members.Concat(NestedTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RecordDeclaration : TypeDeclaration
|
public class RecordDeclaration : TypeDeclaration
|
||||||
@@ -720,6 +743,18 @@ var mainMethod = AstQuery.FirstOrDefault<MethodDeclaration>(compilationUnit,
|
|||||||
var containingClass = AstQuery.GetAncestors(method, compilationUnit)
|
var containingClass = AstQuery.GetAncestors(method, compilationUnit)
|
||||||
.OfType<ClassDeclaration>()
|
.OfType<ClassDeclaration>()
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
// Find all nested types in a class
|
||||||
|
var outerClass = compilationUnit.Types.OfType<ClassDeclaration>().First();
|
||||||
|
var allNestedTypes = outerClass.NestedTypes;
|
||||||
|
|
||||||
|
// Find nested interfaces specifically
|
||||||
|
var nestedInterfaces = outerClass.NestedTypes
|
||||||
|
.OfType<InterfaceDeclaration>();
|
||||||
|
|
||||||
|
// Recursively find all nested types (including deeply nested)
|
||||||
|
var allNested = AstQuery.FindAll<TypeDeclaration>(outerClass)
|
||||||
|
.Where(t => t != outerClass);
|
||||||
```
|
```
|
||||||
|
|
||||||
## AST Transformation API
|
## AST Transformation API
|
||||||
|
|||||||
15
README.md
15
README.md
@@ -82,9 +82,17 @@ CompilationUnit
|
|||||||
├── ImportDeclaration[]
|
├── ImportDeclaration[]
|
||||||
└── TypeDeclaration[]
|
└── TypeDeclaration[]
|
||||||
├── ClassDeclaration
|
├── ClassDeclaration
|
||||||
|
│ ├── Members[]
|
||||||
|
│ └── NestedTypes[]
|
||||||
├── InterfaceDeclaration
|
├── InterfaceDeclaration
|
||||||
|
│ ├── Members[]
|
||||||
|
│ └── NestedTypes[]
|
||||||
├── EnumDeclaration
|
├── EnumDeclaration
|
||||||
|
│ ├── Constants[]
|
||||||
|
│ ├── Members[]
|
||||||
|
│ └── NestedTypes[]
|
||||||
└── AnnotationDeclaration
|
└── AnnotationDeclaration
|
||||||
|
└── Members[]
|
||||||
```
|
```
|
||||||
|
|
||||||
### Visitor Pattern
|
### Visitor Pattern
|
||||||
@@ -152,6 +160,13 @@ var serializableClasses = ast
|
|||||||
var getters = ast
|
var getters = ast
|
||||||
.FindAll<MethodDeclaration>()
|
.FindAll<MethodDeclaration>()
|
||||||
.Where(m => m.IsGetter());
|
.Where(m => m.IsGetter());
|
||||||
|
|
||||||
|
// Access nested types
|
||||||
|
var outerClass = ast.Types.OfType<ClassDeclaration>().First();
|
||||||
|
foreach (var nestedType in outerClass.NestedTypes)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Nested: {nestedType.Name} ({nestedType.GetType().Name})");
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### JSON Serialization
|
### JSON Serialization
|
||||||
|
|||||||
Reference in New Issue
Block a user