Provides SyntaxAnnotations and extension methods for marking generated and source code in syntax trees.
Namespace: Metalama.Framework.Engine.Formatting
Assembly: Metalama.Framework.Sdk.dll
Syntax
public static class FormattingAnnotationsRemarks
Aspect weavers must annotate their generated code so Metalama can properly format it and distinguish it from source code. Use these methods when transforming syntax trees in IAspectWeaver implementations.
Key methods:
- WithGeneratedCodeAnnotation<T>(T?, SyntaxAnnotation): Mark a node and all children as generated code.
- WithSourceCodeAnnotation<T>(T?): Mark a node as source code (within a generated tree).
- WithSimplifierAnnotation<T>(T): Mark a type name for simplification (e.g., remove namespace qualifications).
The GeneratedCodeAnnotation property provides the annotation specific to the current aspect.
Properties
| Name | Description |
|---|---|
| PossibleRedundantAnnotation | Annotation used to mark locals and 'return;' statement that may be redundant. Currently we are not doing anything with them, but we could. |
| SourceCodeAnnotation | Gets an annotation that means that the syntax stems from source code. This can be added to a child node of a node annotated
with the |
Methods
| Name | Description |
|---|---|
| WithFormattingAnnotationsFrom<T>(T, SyntaxNode) | |
| WithGeneratedCodeAnnotation(SyntaxToken, SyntaxAnnotation) | |
| WithGeneratedCodeAnnotation(in SyntaxTrivia, SyntaxAnnotation) | |
| WithGeneratedCodeAnnotation<T>(T?, SyntaxAnnotation) | |
| WithSimplifierAnnotation<T>(T) | Marks a syntax node for simplification (e.g., removing unnecessary namespace qualifications from type names). |
| WithSourceCodeAnnotationIfNotGenerated<T>(T) | Marks a syntax node as source code only if it is not already marked as generated code. |
| WithSourceCodeAnnotation<T>(T?) | Annotates a syntax node with an annotation meaning that the syntax node and all its children are user code. The annotation is typically obtained from GeneratedCodeAnnotation, but it can also be created from CreateGeneratedCodeAnnotation(string). |