Wednesday, January 2, 2013

Built-in Dart Annotations: @deprecated

In the comments to yesterday's post on Dart annotations, Ladislav Thon pointed out that there is already a package in the Dart Pub using them: meta. I cannot resist the temptation to kick the tires, so I update my pubspec.yaml to include any version of meta:

Next, in my awesome Cookie class, I decide that cookie should not be responsible for mixing its own ingredients. I factor that functionality out into a Mixer class and deprecate the mix_it() method. Rather than raising an error or printing a warning that I will be sure to ignore, I use meta's @deprecated annotation:

I would very much like to adapt this kind of annotation for my own internal annotations. Specifically, I would like to make my @IntentionalError annotation suppress normal warnings from dart_analyzer. This is very specific to examples from Dart for Hipsters so I would not expect dart_analyzer to support it natively. But if I could adapt what the meta package does to influence dart_analyzer, I would be very happy.

Unfortunately, the meta package does nothing. It only includes a few constant constructor definitions. Internal code in dart_analyzer must look for these annotations in order to do its thing. Ah well, maybe someday.

Until then, I can be secure in the knowledge that dart_analyzer (and Dart Editor) are hard at work warning other developers of the danger of telling a cookie to mix itself.