简体   繁体   中英

Java annotations for code style with semantics like @Deprecated

Does anybody have some kind of "code style" annotations in the project, ex: @OverEngineered for over-complexed code or @Duplicated... etc.

Ideally I'd subclass @Deprecated for that (@OverEngineered extends @Deprecated) to get the IDE highlight it, but java annotations are not inherited .

So I wonder if there is some workaround to get the IDE to highlight such code-style custom annotations as deprecated? Or is this the wrong way or wrong task in general?

The workaround would be implemented with a plugin you develop for Eclipse. I would say, however, nothing is more semantically as a good written comment in the code.

After all it depends on the purpose. But I think a good comment is better than a plugin which anyone has to install.

You could write a family of these annotations, and then use them alongside @Deprecated . The latter gets you the warnings, the former supply the details to human readers. You could write a Checkstyle rule to require that every deprecated thing has an explanatory annotation, and/or that every explanation accompanies a deprecation.

Rather than writing several annotations, though, i'd write one, which takes an explanatory label as a parameter. I'd call it @BecauseItIs . So:

@Deprecated @BecauseItIs("overengineered")
public void calculateSumOfTwoIntegersUsingSurfaceIntegrals(int a, int b) {

It's not clear to me if you have another goal besides calling attention to the spot in the IDE. You mention @Deprecated which also shows up in the Javadoc, IDE documentation popups, and compiler output.

For simply the IDE highlighting without the other possibilities, you could leverage the FIXME / TODO sorts of comment tags that most IDEs support (at least those I've used). Just add your own tags for OVERENGINEERED: this is too ... etc.

Eclipse allows you to also specify if you want case matched, so it could be OverEngineered:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM