Open sandboxFocus

Class FormattingAnnotations

Provides SyntaxAnnotations and extension methods for marking generated and source code in syntax trees.

Inheritance
FormattingAnnotations
Namespace: Metalama.Framework.Engine.Formatting
Assembly: Metalama.Framework.Sdk.dll
Syntax
public static class FormattingAnnotations
Remarks

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:

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 WithGeneratedCodeAnnotation method. This is a synonym for SourceCodeAnnotation.

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).

See Also