Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Target and MinimumVersion to SourceTemplateAttribute #22

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/Annotations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ public PathReferenceAttribute([NotNull, PathReference] string basePath)
/// Text inside these comments is added as source code when the template is applied. Template parameters
/// can be used either as additional method parameters or as identifiers wrapped in two '$' signs.
/// Use the <see cref="MacroAttribute"/> attribute to specify macros for parameters.
/// The expression to be used in the expansion can be adjusted by the <see cref="SourceTemplateAttribute.Target"/> parameter.
/// </remarks>
/// <example>
/// In this example, the 'forEach' method is a source template available over all values
Expand All @@ -783,7 +784,27 @@ public PathReferenceAttribute([NotNull, PathReference] string basePath)
/// </example>
[AttributeUsage(AttributeTargets.Method)]
[Conditional("JETBRAINS_ANNOTATIONS")]
public sealed class SourceTemplateAttribute : Attribute { }
public sealed class SourceTemplateAttribute : Attribute
{
/// <summary>
/// Allows specifying which expression to capture for template execution if more than one present on the expansion.
/// If not specified, Inner is assumed.
/// </summary>
public SourceTemplateTargetExpression Target { get; set; }
}
/// <summary>
/// Provides a value for the <see cref="SourceTemplateAttribute"/> to define how to capture
/// the expression at the point of expansion
/// </summary>
public enum SourceTemplateTargetExpression
{
/// <summary>Selects inner expression</summary>
/// <example><c>_args = args.{caret}</c> captures <c>args</c></example>
Inner = 0,
/// <summary>Selects outer expression</summary>
/// <example><c>_args = args.{caret}</c> captures whole assignment</example>
Outer = 1
}

/// <summary>
/// Allows specifying a macro for a parameter of a <see cref="SourceTemplateAttribute">source template</see>.
Expand Down