Open sandboxFocusImprove this doc

LAMA5207: No naming convention matches the target

Severity Error
Reported by Metalama.Patterns.Wpf
Message No <ArtifactKind> naming convention matched '<Target>'. Add a naming convention that matches this name, or do not remove the default naming convention.

Cause

The [Command] and [DependencyProperty] aspects evaluate their naming conventions in order of priority. A naming convention that doesn't recognize the name of the target is skipped, and the next one is tried. For example, a CommandNamingConvention whose CommandNamePattern is ^Vykonat(?<CommandName>.+)$ skips a method named ExecuteSave. The same applies to PropertyNamePattern.

The default naming convention is evaluated last and accepts any name. Therefore, Metalama reports LAMA5207 only when the default naming convention has been removed, with RemoveNamingConvention or RemoveNamingConvention in a fabric, and none of the remaining naming conventions matches the target. The aspect isn't applied.

In the message, <ArtifactKind> is command or dependency property, and <Target> is the aspect's target.

In the following example, a fabric removes the default naming convention and adds a convention that recognizes only methods named RunXxx. The ExecuteSave method doesn't match it.

1using Metalama.Framework.Fabrics;
2using Metalama.Patterns.Wpf.Configuration;
3
4namespace Doc.LAMA5207.Error;
5
6internal class Fabric : NamespaceFabric
7{
8    public override void AmendNamespace( INamespaceAmender amender )
9    {
10        amender.ConfigureCommand(
11            b =>
12            {
13                b.RemoveNamingConvention( CommandOptionsBuilder.DefaultNamingConventionName );
14
15                // Only methods named RunXxx are recognized as commands.
16                b.AddNamingConvention( new CommandNamingConvention( "run" ) { CommandNamePattern = "^Run(?<CommandName>.+)$" } );
17            } );
18    }
19}
20
1using Metalama.Patterns.Wpf;
2
3namespace Doc.LAMA5207.Error;
4
5public class Document
6{
7    // Error: the name doesn't match the pattern ^Run(?<CommandName>.+)$ and the default naming convention was removed.
8    [Command]
    Error LAMA5207: No command naming convention matched 'Document.ExecuteSave()'. Add a naming convention that matches this name, or do not remove the default naming convention.

9    private void ExecuteSave() { }
10}
11

Resolution

  • Rename the target so that it matches one of your naming conventions, for example VykonatSave instead of ExecuteSave in the preceding example.
  • Add a naming convention that matches this name, for example a catch-all convention without CommandNamePattern, which uses the default algorithm to find the command name.
  • Don't remove the default naming convention: keep it as a fallback after your custom conventions.

In the following example, the method is renamed RunSave so that it matches the naming convention.

1using Metalama.Framework.Fabrics;
2using Metalama.Patterns.Wpf.Configuration;
3
4namespace Doc.LAMA5207.Fixed;
5
6internal class Fabric : NamespaceFabric
7{
8    public override void AmendNamespace( INamespaceAmender amender )
9    {
10        amender.ConfigureCommand(
11            b =>
12            {
13                b.RemoveNamingConvention( CommandOptionsBuilder.DefaultNamingConventionName );
14
15                // Only methods named RunXxx are recognized as commands.
16                b.AddNamingConvention( new CommandNamingConvention( "run" ) { CommandNamePattern = "^Run(?<CommandName>.+)$" } );
17            } );
18    }
19}
20
Source Code
1using Metalama.Patterns.Wpf;
2
3namespace Doc.LAMA5207.Fixed;
4
5public class Document
6{
7    // Fixed: the name matches the pattern of the naming convention.
8    [Command]
9    private void RunSave() { }
10}
11
Transformed Code
1using Metalama.Patterns.Wpf;
2
3namespace Doc.LAMA5207.Fixed;
4
5public class Document
6{
7    // Fixed: the name matches the pattern of the naming convention.
8    [Command]
9    private void RunSave() { }
10
11    public Document()
12    {
13        SaveCommand = DelegateCommandFactory.CreateDelegateCommand(RunSave, null);
14    }
15
16    public DelegateCommand SaveCommand { get; }
17}
18

See also