Documentation ¶
Index ¶
- Constants
- Variables
- func AddRuntimeFile(unit *core.ExecutionUnit, templateData any, path string, content []byte) error
- func AllMatches(c *sitter.Node, q string) []query.MatchNodes
- func ContainingNamespaces(node *sitter.Node) map[string]struct{}
- func DoQuery(c *sitter.Node, q string) query.NextMatchFunc
- func FindDeclarationAtNode[T Declarable](node *sitter.Node) (T, bool)
- func HasAttribute[T Declarable](attribute string) predicate.Predicate[T]
- func HasBase(namespace, typeName string, using Imports) predicate.Predicate[*TypeDeclaration]
- func HasBaseWithSuffix(suffix string) predicate.Predicate[*TypeDeclaration]
- func HasName[T Declarable](name string) predicate.Predicate[T]
- func IsInNamespace[T Declarable](namespace string) predicate.Predicate[T]
- func IsValidTypeName(nameNode *sitter.Node, expectedNamespace, expectedType string) bool
- func NameHasSuffix[T Declarable](suffix string) predicate.Predicate[T]
- func NewFile(path string, content io.Reader) (f *core.SourceFile, err error)
- type ASPDotNetCoreStartupClass
- type AddExecRuntimeFiles
- type Attribute
- type AttributeArg
- type Attributes
- type CSharpExecutable
- type CSharpPlugins
- type Declarable
- type Declaration
- func (d *Declaration) AsDeclaration() Declaration
- func (d *Declaration) Attributes() Attributes
- func (d *Declaration) HasAnyModifier(modifier string, additional ...string) bool
- func (d *Declaration) HasModifiers(modifier string, additional ...string) bool
- func (d *Declaration) IsSealed() bool
- func (d *Declaration) SetDeclaringFile(filepath string)
- type DeclarationKind
- type Expose
- type FieldDeclaration
- type Import
- type ImportScope
- type ImportType
- type Imports
- type MethodDeclaration
- type NamespaceDeclarations
- type Parameter
- type Runtime
- type TypeDeclaration
- type Visibility
Constants ¶
const ( // Implemented DeclarationKindClass = DeclarationKind("class") DeclarationKindInterface = DeclarationKind("interface") DeclarationKindRecord = DeclarationKind("record") DeclarationKindStruct = DeclarationKind("struct") DeclarationKindField = DeclarationKind("field") DeclarationKindMethod = DeclarationKind("method") // TODO: implement parsing for remaining unimplemented declaration kinds // Unimplemented DeclarationKindProperty = DeclarationKind("property") DeclarationKindEnum = DeclarationKind("enum") DeclarationKindIndexer = DeclarationKind("indexer") DeclarationKindDelegate = DeclarationKind("delegate") DeclarationKindLocalVariable = DeclarationKind("local_variable") DeclarationKindLocalFunction = DeclarationKind("local_function") DeclarationKindEvent = DeclarationKind("event") )
const ( VisibilityPublic = Visibility("public") VisibilityProtected = Visibility("protected") VisibilityInternal = Visibility("internal") VisibilityPrivate = Visibility("private") VisibilityProtectedInternal = Visibility("protected_internal") VisibilityPrivateProtected = Visibility("private_protected") )
const ( ImportTypeUsing = ImportType("using") ImportTypeUsingAlias = ImportType("using_alias") ImportTypeUsingStatic = ImportType("using_static") )
const ( ImportScopeGlobal = ImportScope("global") ImportScopeCompilationUnit = ImportScope("compilation_unit") ImportScopeNamespace = ImportScope("namespace") )
const CSharp = core.LanguageId("csharp")
Variables ¶
var Language = core.SourceLanguage{ ID: CSharp, Sitter: csharp.GetLanguage(), CapabilityFinder: lang.NewCapabilityFinder("comment", lang.CompositePreprocessor( lang.RegexpRemovePreprocessor(`//\s*`), func(comment string) string { if !strings.HasPrefix(comment, "/*") { return comment } comment = comment[1 : len(comment)-1] comment = multilineCommentMarginRegexp.ReplaceAllString(comment, "") return comment }, )), TurnIntoComment: lang.MakeLineCommenter("// "), }
Functions ¶
func AddRuntimeFile ¶ added in v0.6.3
func AllMatches ¶ added in v0.6.3
func AllMatches(c *sitter.Node, q string) []query.MatchNodes
AllMatches completes processes all query matches immediately and returns a []query.MatchNodes.
func ContainingNamespaces ¶ added in v0.6.3
ContainingNamespaces returns the set of namespaces surrounding the current node.
func DoQuery ¶
func DoQuery(c *sitter.Node, q string) query.NextMatchFunc
DoQuery is a thin wrapper around `query.Exec` to use C# as the Language.
func FindDeclarationAtNode ¶ added in v0.6.3
func FindDeclarationAtNode[T Declarable](node *sitter.Node) (T, bool)
FindDeclarationAtNode finds the next declaration of the supplied Declarable implementation starting from the supplied node.
func HasAttribute ¶ added in v0.6.3
func HasAttribute[T Declarable](attribute string) predicate.Predicate[T]
HasAttribute is a predicate that evaluates if a Declarable is annotated with the given attribute.
func HasBase ¶ added in v0.6.3
func HasBase(namespace, typeName string, using Imports) predicate.Predicate[*TypeDeclaration]
HasBase is a predicate that evaluates whether a *TypeDeclaration's has a specific base.
func HasBaseWithSuffix ¶ added in v0.6.3
func HasBaseWithSuffix(suffix string) predicate.Predicate[*TypeDeclaration]
HasBaseWithSuffix is a predicate that evaluates whether any of a *TypeDeclaration's bases has the supplied suffix.
func HasName ¶ added in v0.6.3
func HasName[T Declarable](name string) predicate.Predicate[T]
HasName is a predicate that evaluates if a Declarable has the supplied name.
func IsInNamespace ¶ added in v0.6.3
func IsInNamespace[T Declarable](namespace string) predicate.Predicate[T]
IsInNamespace is a predicate that evaluates if a Declarable is declared in the supplied namespace.
func IsValidTypeName ¶ added in v0.6.3
func NameHasSuffix ¶ added in v0.6.3
func NameHasSuffix[T Declarable](suffix string) predicate.Predicate[T]
NameHasSuffix is a predicate that evaluates if a Declarable's name matches the supplied suffix.
Types ¶
type ASPDotNetCoreStartupClass ¶ added in v0.6.3
type ASPDotNetCoreStartupClass struct { Class TypeDeclaration ConfigureMethod MethodDeclaration ConfigureServicesMethod MethodDeclaration }
func FindASPDotnetCoreStartupClass ¶ added in v0.6.3
func FindASPDotnetCoreStartupClass(unit *core.ExecutionUnit) (*ASPDotNetCoreStartupClass, error)
type AddExecRuntimeFiles ¶ added in v0.6.3
type AddExecRuntimeFiles struct {
// contains filtered or unexported fields
}
func (*AddExecRuntimeFiles) Name ¶ added in v0.6.3
func (p *AddExecRuntimeFiles) Name() string
func (*AddExecRuntimeFiles) Transform ¶ added in v0.6.3
func (p *AddExecRuntimeFiles) Transform(result *core.CompilationResult, deps *core.Dependencies) error
type Attribute ¶ added in v0.6.3
func (*Attribute) Args ¶ added in v0.6.3
func (a *Attribute) Args() []AttributeArg
Args returns a slice containing an Attribute's arguments.
type AttributeArg ¶ added in v0.6.3
type Attributes ¶ added in v0.6.3
Attributes is a mapping between an attribute name and its declarations in the current context.
type CSharpExecutable ¶ added in v0.6.3
type CSharpExecutable struct {
Config *config.Application
}
func (CSharpExecutable) Name ¶ added in v0.6.3
func (l CSharpExecutable) Name() string
func (CSharpExecutable) Transform ¶ added in v0.6.3
func (l CSharpExecutable) Transform(result *core.CompilationResult, dependencies *core.Dependencies) error
type CSharpPlugins ¶
func NewCSharpPlugins ¶
func NewCSharpPlugins(cfg *config.Application, runtime Runtime) *CSharpPlugins
func (CSharpPlugins) Name ¶
func (c CSharpPlugins) Name() string
func (CSharpPlugins) Transform ¶
func (c CSharpPlugins) Transform(result *core.CompilationResult, deps *core.Dependencies) error
type Declarable ¶ added in v0.6.3
type Declarable interface { // AsDeclaration returns the Declarable's underlying Declaration. AsDeclaration() Declaration // SetDeclaringFile sets the value of the underlying Declaration's DeclaringFile field. SetDeclaringFile(string) }
Declarable simplifies the process of working with various typeName kinds simultaneously.
type Declaration ¶ added in v0.6.3
type Declaration struct { Node *sitter.Node Name string Namespace string DeclaringFile string Kind DeclarationKind Visibility Visibility QualifiedName string IsGeneric bool IsNested bool DeclaringClass string }
Declaration is the base struct for all C# declarations.
Specific declaration kinds can embed Declaration in kind-specific structs that match their more specific needs.
func (*Declaration) AsDeclaration ¶ added in v0.6.3
func (d *Declaration) AsDeclaration() Declaration
AsDeclaration returns the Declaration itself to comply with the Declarable interface.
func (*Declaration) Attributes ¶ added in v0.6.3
func (d *Declaration) Attributes() Attributes
Attributes gets the attributes a declaration is annotated with.
func (*Declaration) HasAnyModifier ¶ added in v0.6.3
func (d *Declaration) HasAnyModifier(modifier string, additional ...string) bool
HasAnyModifier evaluates if a declaration is modified with any of the supplied modifiers.
func (*Declaration) HasModifiers ¶ added in v0.6.3
func (d *Declaration) HasModifiers(modifier string, additional ...string) bool
HasModifiers evaluates if a declaration is modified with all the supplied modifiers.
func (*Declaration) IsSealed ¶ added in v0.6.3
func (d *Declaration) IsSealed() bool
IsSealed Evaluates if a declaration is functionally sealed (i.e. has either the "static" or "sealed" modifier).
func (*Declaration) SetDeclaringFile ¶ added in v0.6.3
func (d *Declaration) SetDeclaringFile(filepath string)
SetDeclaringFile sets the Declaration.DeclaringFile file field to the supplied filepath to comply with the Declarable interface.
type DeclarationKind ¶ added in v0.6.3
type DeclarationKind string
DeclarationKind is the kind of declaration represented by a given Declaration.
type Expose ¶ added in v0.6.3
type Expose struct{}
func (*Expose) Transform ¶ added in v0.6.3
func (p *Expose) Transform(result *core.CompilationResult, deps *core.Dependencies) error
type FieldDeclaration ¶ added in v0.6.3
type FieldDeclaration struct { Declaration HasInitialValue bool Type string Declarator *sitter.Node }
type Import ¶ added in v0.6.3
type Import struct { // Name is the exported name of the Import Name string // Node is the *sitter.Node associated with the Import's using directive Node *sitter.Node // Alias is the name with which this import is referred to in its enclosing Scope (i.e. module or local) Alias string Scope ImportScope Type ImportType Namespace string }
func (*Import) ImportedAs ¶ added in v0.6.3
ImportedAs returns the name of the import as it will be used locally (either the exported name or local alias).
type ImportScope ¶ added in v0.6.3
type ImportScope string
type ImportType ¶ added in v0.6.3
type ImportType string
C# using directive spec: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/namespaces#135-using-directives TODO: add support for "extern alias" imports: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/extern-alias
type Imports ¶ added in v0.6.3
Imports provides a mapping between import sources and the list of imports for each.
func FindImportsAtNode ¶ added in v0.6.3
FindImportsAtNode returns a map containing a list of imports for each import source starting from the supplied node.
func FindImportsInFile ¶ added in v0.6.3
func FindImportsInFile(file *core.SourceFile) Imports
FindImportsInFile returns a map containing a list of imports for each import source referenced within the file.
type MethodDeclaration ¶ added in v0.6.3
type MethodDeclaration struct { Declaration Parameters []Parameter ReturnType string }
type NamespaceDeclarations ¶ added in v0.6.3
type NamespaceDeclarations[T Declarable] map[string][]T
NamespaceDeclarations represents the relationship between a namespace and its declarations in the current context.
func FindDeclarationsAtNode ¶ added in v0.6.3
func FindDeclarationsAtNode[T Declarable](node *sitter.Node) NamespaceDeclarations[T]
FindDeclarationsAtNode returns a map containing a list of declarations of the supplied generic type "T" for each namespace starting from the supplied node.
func FindDeclarationsInFile ¶ added in v0.6.3
func FindDeclarationsInFile[T Declarable](file *core.SourceFile) NamespaceDeclarations[T]
FindDeclarationsInFile returns a map containing a list of declarations for each namespace in the supplied file.
func (NamespaceDeclarations[T]) Declarations ¶ added in v0.6.3
func (nsd NamespaceDeclarations[T]) Declarations() []T
Declarations converts NamespaceDeclarations[T] to []T to simplify iteration.
type Runtime ¶
type Runtime interface {
AddExecRuntimeFiles(unit *core.ExecutionUnit, result *core.CompilationResult, deps *core.Dependencies) error
}
type TypeDeclaration ¶ added in v0.6.3
type TypeDeclaration struct { Declaration Bases map[string]*sitter.Node }
TypeDeclaration represents a type declaration. Type declarations include classes, interfaces, records, and structs.
func FindSubtypes ¶ added in v0.6.3
func FindSubtypes(unit *core.ExecutionUnit, baseNamespace, baseType string) []*TypeDeclaration
type Visibility ¶ added in v0.6.3
type Visibility string
Visibility represents C#'s declaration visibility matrix