开发者

How to Interpret /***/ in java? [closed]

开发者 https://www.devze.com 2023-04-08 15:15 出处:网络
Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing th
Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 5 years ago.

Improve this question

What I am Doing?

I am now constructing a comments segregator as a part of my simple IDE stimulator (Which will detect all the comments in the java code).

In that my task is to note down all the starting and ending positions of comments and documentations of all forms...

1. //
2. /*......*/
3. /**.......*/

(I am doing this using Deterministic Finite Automata.)

And I will give separate colors for comments and documentation.

Where my doubt is?

Though it is uncommon开发者_如何学编程, When code has a statement like this /***/, how should I interpret that code? Whether I must treat it as comment or documentation?


Treat it as a comment since obviously there is no documentation to be communicated to anyone.

Edit:

Eclipse, for example, will treat /***/ as documentation. Taking cue from this site where Java grammar is explained, /**"documentation"*/ also formally specifies that documentation is between /** and */, even when length of its content is zero.

Practically, I'd say: treat it as comments. Formally, treat it as documentation. Pick one.


Color it however you want. As a line by itself, you cannot determine if it should be interpreted as /** */ (documentation) or /* * */ (a single commented asterisk) or /* **/ (oddball comment). You could try and infer if it's documentation or not by looking at the previous and next lines. If either of those are documentation, then most likely this little /***/ is documentation as well.


The javadoc comment style was not an extension of the language; it is not part of the actual Java syntax. So essentially every javadoc comment is a comment first, and javadoc second. For that reason, I would use "normal comment" as the default.


If you are treating /** */ as documentation then you should also treat /***/ as documentation - there isn't much practical difference between zero-length documentation and only-whitespace documentation.

I think it's also easier to implement - otherwise you have to treat /***/ as a special case (probably involves some-kind of look-ahead).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号