-
-
Notifications
You must be signed in to change notification settings - Fork 349
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
Adds comment support #554
Merged
Merged
Adds comment support #554
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
language: java | ||
|
||
sudo: required | ||
|
||
jdk: | ||
- oraclejdk8 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
title: Comments | ||
keywords: comments | ||
last_updated: Mars 22, 2016 | ||
--- | ||
|
||
### Comments in Spoon | ||
|
||
In Spoon there are different kinds of comments: | ||
|
||
* Line comments (from // to end line) | ||
* Block comments (from /* to */) | ||
* Javadoc comments (from /** to */) | ||
|
||
#### Javadoc Comments | ||
|
||
The Javadoc comments are available via the API ```CtElement.getDocComment()``` and return a ```String```. | ||
|
||
#### Other Comments | ||
|
||
The block and line comments are represented with a ```CtComment``` class ([javadoc](http://spoon.gforge.inria.fr/mvnsites/spoon-core/apidocs/spoon/reflect/declaration/CtComment.html)). | ||
This class exposes API to get the position and the content of the comment. | ||
|
||
We also try to understand to which element they are attached. | ||
We use simple heuristics that work well in nominal cases but it is not possible to address all specific cases. | ||
You can receive the comments of each ```CtElement``` via the API ```CtElement.getComments()``` that returns a ```List<CtComment>```. | ||
|
||
The reprint of the comments can be disable in the Environment. | ||
|
||
##### Comment Attribution | ||
|
||
* Each comment can have multiple comments | ||
* Comments in the same line of a statement is attached to the statement | ||
* Comments which are alone in one line (or more than one lines) are associated to the first element following them. | ||
* Comments cannot be associated to other comment | ||
* Comments at the end of a block are considered as orphans comment | ||
* Comments in a class level is attached to the class | ||
|
||
##### Comment Example | ||
Class comment | ||
```Java | ||
// class comment | ||
class A { | ||
// class comment | ||
} | ||
``` | ||
|
||
Statement comment | ||
```Java | ||
// Statement comment | ||
int a; // Statement comment | ||
``` | ||
|
||
Orphan comment | ||
```Java | ||
try { | ||
|
||
} exception (Exception e) { | ||
// Orphan comment | ||
} | ||
``` | ||
|
||
Multiple line comment | ||
```Java | ||
// Statement comment 1 | ||
// Statement comment 2 | ||
// Statement comment 3 | ||
int a; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright (C) 2006-2015 INRIA and contributors | ||
* Spoon - http://spoon.gforge.inria.fr/ | ||
* | ||
* This software is governed by the CeCILL-C License under French law and | ||
* abiding by the rules of distribution of free software. You can use, modify | ||
* and/or redistribute the software under the terms of the CeCILL-C license as | ||
* circulated by CEA, CNRS and INRIA at http://www.cecill.info. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. | ||
* | ||
* The fact that you are presently reading this means that you have had | ||
* knowledge of the CeCILL-C license and that you accept its terms. | ||
*/ | ||
package spoon.reflect.code; | ||
|
||
/** | ||
* This code element defines a comment | ||
* | ||
*/ | ||
public interface CtComment extends CtStatement { | ||
enum CommentType { | ||
/** | ||
* before the package line (typically the license) | ||
*/ | ||
FILE, | ||
/** | ||
* JavaDoc comment: before methods, fields, types | ||
*/ | ||
JAVADOC, | ||
/** | ||
* Inline comment (//) | ||
*/ | ||
INLINE, | ||
/** | ||
* Block comment (/* *\/) | ||
*/ | ||
BLOCK | ||
} | ||
|
||
/** | ||
* Get the content of the comment | ||
* @return the content of the comment | ||
*/ | ||
String getContent(); | ||
|
||
<E extends CtComment> E setContent(String content); | ||
|
||
/** | ||
* Get the type of the comment | ||
* @return the comment type | ||
*/ | ||
CommentType getCommentType(); | ||
|
||
<E extends CtComment> E setCommentType(CommentType commentType); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
package spoon.reflect.declaration; | ||
|
||
import spoon.processing.FactoryAccessor; | ||
import spoon.reflect.code.CtComment; | ||
import spoon.reflect.cu.SourcePosition; | ||
import spoon.reflect.reference.CtReference; | ||
import spoon.reflect.reference.CtTypeReference; | ||
|
@@ -74,7 +75,7 @@ <A extends Annotation> CtAnnotation<A> getAnnotation( | |
|
||
/** | ||
* Returns the text of the documentation ("javadoc") comment of this | ||
* element. | ||
* element. The documentation is also accessible via {@link #getComments()}. | ||
*/ | ||
String getDocComment(); | ||
|
||
|
@@ -119,7 +120,9 @@ <A extends Annotation> CtAnnotation<A> getAnnotation( | |
|
||
/** | ||
* Sets the text of the documentation ("javadoc") comment of this | ||
* declaration. | ||
* declaration. This API will set the content of the first javadoc | ||
* {@link CtComment} or create a new javadoc {@link CtComment} if | ||
* no javadoc {@link CtComment} is available on this object. | ||
*/ | ||
<E extends CtElement> E setDocComment(String docComment); | ||
|
||
|
@@ -253,4 +256,28 @@ <E extends CtElement> List<E> getAnnotatedChildren( | |
* Returns the metadata keys stored in an element. | ||
*/ | ||
Set<String> getMetadataKeys(); | ||
|
||
/** | ||
* Set the comment list | ||
*/ | ||
<E extends CtElement> E setComments(List<CtComment> comments); | ||
|
||
/** | ||
* The list of comments | ||
* @return the list of comment | ||
*/ | ||
List<CtComment> getComments(); | ||
|
||
/** | ||
* Add a comment to the current element | ||
* <code>element.addComment(element.getFactory().Code().createComment("comment", CtComment.CommentType.INLINE)</code> | ||
* @param comment the comment | ||
*/ | ||
<E extends CtElement> E addComment(CtComment comment); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. javadoc? |
||
|
||
/** | ||
* Remove a comment | ||
* @param comment the comment to remove | ||
*/ | ||
<E extends CtElement> E removeComment(CtComment comment); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
give examples?