use of spoon.reflect.code.CtJavaDocTag in project spoon by INRIA.
the class JDTCommentBuilder method defineCommentContent.
/**
* Define the content of the comment
* @param comment the comment
* @param tagContent the tagContent of the tag
* @param tagType the tag type
*/
private void defineCommentContent(CtComment comment, String tagContent, CtJavaDocTag.TagType tagType) {
if (tagType != null) {
CtJavaDocTag docTag = comment.getFactory().Code().createJavaDocTag(tagContent, tagType);
((CtJavaDoc) comment).addTag(docTag);
} else if (!tagContent.isEmpty()) {
comment.setContent(tagContent.trim());
}
}
use of spoon.reflect.code.CtJavaDocTag in project spoon by INRIA.
the class DefaultCoreFactory method createJavaDocTag.
@Override
public CtJavaDocTag createJavaDocTag() {
CtJavaDocTag e = new CtJavaDocTagImpl();
e.setFactory(getMainFactory());
return e;
}
use of spoon.reflect.code.CtJavaDocTag in project spoon by INRIA.
the class CtJavaDocImpl method setTags.
@Override
public <E extends CtJavaDoc> E setTags(List<CtJavaDocTag> tags) {
if (tags == null) {
return (E) this;
}
getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, COMMENT_TAG, this.tags, new ArrayList<>(this.tags));
this.tags = new ArrayList<>();
for (CtJavaDocTag tag : tags) {
this.addTag(tag);
}
return (E) this;
}
use of spoon.reflect.code.CtJavaDocTag in project spoon by INRIA.
the class CommentTest method testJavaDocComment.
private void testJavaDocComment(CtClass type, String EOL) {
CtJavaDoc classJavaDoc = (CtJavaDoc) type.getComments().get(0);
// contract: test that java doc is printed correctly
String str = classJavaDoc.toString();
StringTokenizer st = new StringTokenizer(str, System.getProperty("line.separator"));
boolean first = true;
while (st.hasMoreTokens()) {
String line = st.nextToken();
if (first) {
// first
first = false;
assertTrue(line.length() == 3);
assertEquals("/**", line);
} else {
if (st.hasMoreTokens()) {
// in the middle
assertTrue(line.length() >= 2);
assertEquals(" *", line.substring(0, 2));
} else {
// last
assertTrue(line.length() == 3);
assertEquals(" */", line.substring(0, 3));
}
}
}
assertEquals("JavaDoc test class." + EOL + EOL + "Long description", classJavaDoc.getContent());
List<CtJavaDocTag> elements = type.getElements(new TypeFilter<>(CtJavaDocTag.class));
assertEquals(8, elements.size());
List<CtJavaDocTag> authorTags = getTagByType(elements, CtJavaDocTag.TagType.AUTHOR);
assertEquals(1, authorTags.size());
assertEquals("Thomas Durieux", authorTags.get(0).getContent());
List<CtJavaDocTag> deprecatedTags = getTagByType(elements, CtJavaDocTag.TagType.DEPRECATED);
assertEquals(1, deprecatedTags.size());
assertEquals("", deprecatedTags.get(0).getContent());
List<CtJavaDocTag> sinceTags = getTagByType(elements, CtJavaDocTag.TagType.SINCE);
assertEquals(2, sinceTags.size());
assertEquals("1.3", sinceTags.get(0).getContent());
assertEquals("1.3", sinceTags.get(1).getContent());
List<CtJavaDocTag> paramTags = getTagByType(elements, CtJavaDocTag.TagType.PARAM);
assertEquals(1, paramTags.size());
assertEquals("the parameters", paramTags.get(0).getContent());
assertEquals("i", paramTags.get(0).getParam());
CtJavaDocTag tagClone = paramTags.get(0).clone();
assertEquals("the parameters", tagClone.getContent());
assertEquals("i", tagClone.getParam());
List<CtJavaDocTag> throwsTags = getTagByType(elements, CtJavaDocTag.TagType.THROWS);
assertEquals(1, throwsTags.size());
assertEquals("an exception", throwsTags.get(0).getContent());
assertEquals("RuntimeException", throwsTags.get(0).getParam());
assertEquals("JavaDoc test class.", classJavaDoc.getShortDescription());
assertEquals("Long description", classJavaDoc.getLongDescription());
CtJavaDocTag deprecatedTag = classJavaDoc.getTags().get(0);
assertTrue(classJavaDoc.toString().indexOf("@deprecated") >= 0);
classJavaDoc.removeTag(0);
assertEquals(-1, classJavaDoc.toString().indexOf("@deprecated"));
classJavaDoc.addTag(deprecatedTag);
assertTrue(classJavaDoc.toString().indexOf("@deprecated") >= 0);
}
use of spoon.reflect.code.CtJavaDocTag in project spoon by INRIA.
the class CtElementImpl method getDocComment.
public String getDocComment() {
for (CtComment ctComment : comments) {
if (ctComment.getCommentType() == CtComment.CommentType.JAVADOC) {
StringBuffer result = new StringBuffer();
result.append(ctComment.getContent() + System.lineSeparator());
for (CtJavaDocTag tag : ((CtJavaDoc) ctComment).getTags()) {
// the tag already contains a new line
result.append(tag.toString());
}
return result.toString();
}
}
return "";
}
Aggregations