diff --git a/IronJava.Core/AST/Nodes/Annotations.cs b/IronJava.Core/AST/Nodes/Annotations.cs index 6db000f..cfb5e20 100644 --- a/IronJava.Core/AST/Nodes/Annotations.cs +++ b/IronJava.Core/AST/Nodes/Annotations.cs @@ -10,6 +10,11 @@ namespace MarketAlly.IronJava.Core.AST.Nodes { public TypeReference Type { get; } public IReadOnlyList Arguments { get; } + + /// + /// Gets the name of the annotation (e.g., "Override" for @Override). + /// + public string Name => Type.Name; public Annotation( SourceRange location, diff --git a/IronJava.Core/AST/Nodes/CompilationUnit.cs b/IronJava.Core/AST/Nodes/CompilationUnit.cs index a176265..c5cfcfc 100644 --- a/IronJava.Core/AST/Nodes/CompilationUnit.cs +++ b/IronJava.Core/AST/Nodes/CompilationUnit.cs @@ -38,6 +38,11 @@ namespace MarketAlly.IronJava.Core.AST.Nodes { public string PackageName { get; } public IReadOnlyList Annotations { get; } + + /// + /// Gets the package name. Alias for PackageName for consistency. + /// + public string Name => PackageName; public PackageDeclaration( SourceRange location, @@ -61,6 +66,13 @@ namespace MarketAlly.IronJava.Core.AST.Nodes public string ImportPath { get; } public bool IsStatic { get; } public bool IsWildcard { get; } + + /// + /// Gets the name of the imported type or package. + /// For "import java.util.List", returns "java.util.List" + /// For "import java.util.*", returns "java.util.*" + /// + public string Name => ImportPath; public ImportDeclaration( SourceRange location, diff --git a/IronJava.Core/AST/Nodes/TypeDeclarations.cs b/IronJava.Core/AST/Nodes/TypeDeclarations.cs index 4459f51..db2b0cc 100644 --- a/IronJava.Core/AST/Nodes/TypeDeclarations.cs +++ b/IronJava.Core/AST/Nodes/TypeDeclarations.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using MarketAlly.IronJava.Core.AST.Visitors; namespace MarketAlly.IronJava.Core.AST.Nodes @@ -13,6 +14,11 @@ namespace MarketAlly.IronJava.Core.AST.Nodes public IReadOnlyList Annotations { get; } public IReadOnlyList TypeParameters { get; } public JavaDoc? JavaDoc { get; } + + /// + /// Gets the body/members of this type declaration. + /// + public abstract IEnumerable Body { get; } protected TypeDeclaration( SourceRange location, @@ -67,6 +73,8 @@ namespace MarketAlly.IronJava.Core.AST.Nodes AddChildren(members); } + public override IEnumerable Body => Members; + public override T Accept(IJavaVisitor visitor) => visitor.VisitClassDeclaration(this); public override void Accept(IJavaVisitor visitor) => visitor.VisitClassDeclaration(this); } @@ -97,6 +105,8 @@ namespace MarketAlly.IronJava.Core.AST.Nodes AddChildren(members); } + public override IEnumerable Body => Members; + public override T Accept(IJavaVisitor visitor) => visitor.VisitInterfaceDeclaration(this); public override void Accept(IJavaVisitor visitor) => visitor.VisitInterfaceDeclaration(this); } @@ -130,6 +140,8 @@ namespace MarketAlly.IronJava.Core.AST.Nodes AddChildren(members); } + public override IEnumerable Body => Constants.Cast().Concat(Members); + public override T Accept(IJavaVisitor visitor) => visitor.VisitEnumDeclaration(this); public override void Accept(IJavaVisitor visitor) => visitor.VisitEnumDeclaration(this); } @@ -154,6 +166,8 @@ namespace MarketAlly.IronJava.Core.AST.Nodes AddChildren(members); } + public override IEnumerable Body => Members; + public override T Accept(IJavaVisitor visitor) => visitor.VisitAnnotationDeclaration(this); public override void Accept(IJavaVisitor visitor) => visitor.VisitAnnotationDeclaration(this); } diff --git a/IronJava.Core/AST/Nodes/Types.cs b/IronJava.Core/AST/Nodes/Types.cs index 34aa485..2134654 100644 --- a/IronJava.Core/AST/Nodes/Types.cs +++ b/IronJava.Core/AST/Nodes/Types.cs @@ -9,6 +9,16 @@ namespace MarketAlly.IronJava.Core.AST.Nodes public abstract class TypeReference : JavaNode { protected TypeReference(SourceRange location) : base(location) { } + + /// + /// Gets the simple name of the type. + /// + public abstract string Name { get; } + + /// + /// Gets the fully qualified name of the type. + /// + public virtual string QualifiedName => Name; } /// @@ -17,6 +27,8 @@ namespace MarketAlly.IronJava.Core.AST.Nodes public class PrimitiveType : TypeReference { public PrimitiveTypeKind Kind { get; } + + public override string Name => Kind.ToString().ToLower(); public PrimitiveType(SourceRange location, PrimitiveTypeKind kind) : base(location) { @@ -45,7 +57,9 @@ namespace MarketAlly.IronJava.Core.AST.Nodes /// public class ClassOrInterfaceType : TypeReference { - public string Name { get; } + private readonly string _name; + + public override string Name => _name; public ClassOrInterfaceType? Scope { get; } public IReadOnlyList TypeArguments { get; } public IReadOnlyList Annotations { get; } @@ -57,7 +71,7 @@ namespace MarketAlly.IronJava.Core.AST.Nodes IReadOnlyList typeArguments, IReadOnlyList annotations) : base(location) { - Name = name; + _name = name; Scope = scope; TypeArguments = typeArguments; Annotations = annotations; @@ -68,6 +82,8 @@ namespace MarketAlly.IronJava.Core.AST.Nodes } public string FullName => Scope != null ? $"{Scope.FullName}.{Name}" : Name; + + public override string QualifiedName => FullName; public override T Accept(IJavaVisitor visitor) => visitor.VisitClassOrInterfaceType(this); public override void Accept(IJavaVisitor visitor) => visitor.VisitClassOrInterfaceType(this); @@ -80,6 +96,10 @@ namespace MarketAlly.IronJava.Core.AST.Nodes { public TypeReference ElementType { get; } public int Dimensions { get; } + + public override string Name => ElementType.Name + new string('[', Dimensions) + new string(']', Dimensions); + + public override string QualifiedName => ElementType.QualifiedName + new string('[', Dimensions) + new string(']', Dimensions); public ArrayType( SourceRange location,