csharp

package
v0.6.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
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")
)
View Source
const (
	VisibilityPublic            = Visibility("public")
	VisibilityProtected         = Visibility("protected")
	VisibilityInternal          = Visibility("internal")
	VisibilityPrivate           = Visibility("private")
	VisibilityProtectedInternal = Visibility("protected_internal")
	VisibilityPrivateProtected  = Visibility("private_protected")
)
View Source
const (
	ImportTypeUsing       = ImportType("using")
	ImportTypeUsingAlias  = ImportType("using_alias")
	ImportTypeUsingStatic = ImportType("using_static")
)
View Source
const (
	ImportScopeGlobal          = ImportScope("global")
	ImportScopeCompilationUnit = ImportScope("compilation_unit")
	ImportScopeNamespace       = ImportScope("namespace")
)
View Source
const CSharp = core.LanguageId("csharp")

Variables

View Source
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 AddRuntimeFile(unit *core.ExecutionUnit, templateData any, path string, content []byte) error

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

func ContainingNamespaces(node *sitter.Node) map[string]struct{}

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 IsValidTypeName(nameNode *sitter.Node, expectedNamespace, expectedType string) bool

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.

func NewFile

func NewFile(path string, content io.Reader) (f *core.SourceFile, err error)

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

type Attribute struct {
	Name string
	Node *sitter.Node
}

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 AttributeArg struct {
	Name  string
	Value string
}

type Attributes added in v0.6.3

type Attributes map[string][]Attribute

Attributes is a mapping between an attribute name and its declarations in the current context.

func (Attributes) OfType added in v0.6.3

func (a Attributes) OfType(attrType string, additional ...string) []Attribute

OfType returns a []Attribute filtered by the supplied attribute types. The supplied attribute types should be qualified names.

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

type CSharpPlugins struct {
	Plugins []core.Plugin
}

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) Name added in v0.6.3

func (p *Expose) Name() string

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

func (p *Import) ImportedAs() string

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 Imports added in v0.6.3

type Imports map[string][]Import

Imports provides a mapping between import sources and the list of imports for each.

func FindImportsAtNode added in v0.6.3

func FindImportsAtNode(node *sitter.Node) Imports

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.

func (Imports) AsSlice added in v0.6.3

func (imports Imports) AsSlice() []Import

AsSlice converts an instance of Imports to []Import for simpler iteration over all Import values.

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 Parameter added in v0.6.3

type Parameter struct {
	Name     string
	TypeNode *sitter.Node
}

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

Directories

Path Synopsis
aws

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL