use of spoon.reflect.code.CtJavaDoc 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.CtJavaDoc in project spoon by INRIA.
the class DefaultCoreFactory method createJavaDoc.
@Override
public CtJavaDoc createJavaDoc() {
CtJavaDoc e = new CtJavaDocImpl();
e.setFactory(getMainFactory());
return e;
}
use of spoon.reflect.code.CtJavaDoc in project spoon by INRIA.
the class CommentTest method testJavaDocEmptyCommentAndTag.
@Test
public void testJavaDocEmptyCommentAndTag() {
// the sources are checked out with \n even on Windows.
String EOL = "\n";
Factory f = getSpoonFactory();
CtClass<?> type = (CtClass<?>) f.Type().get(JavaDocEmptyCommentAndTags.class);
CtJavaDoc classJavaDoc = (CtJavaDoc) type.getComments().get(0);
// contract: content is never null
assertNotNull(classJavaDoc.getContent());
// contract: empty content is ""
assertEquals("", classJavaDoc.getContent());
CtJavaDoc methodJavaDoc = (CtJavaDoc) type.getMethodsByName("m").get(0).getComments().get(1);
// contract: content is never null
assertNotNull(methodJavaDoc.getContent());
// contract: empty content is ""
assertEquals("", methodJavaDoc.getContent());
}
use of spoon.reflect.code.CtJavaDoc in project spoon by INRIA.
the class CommentTest method testCommentsInResourcesWithWindowsEOL.
@Test
public void testCommentsInResourcesWithWindowsEOL() throws IOException {
// contract: the WindowsEOL.java contains MS Windows \r\n as EOL
try (InputStream is = new FileInputStream(new File("./src/test/java/spoon/test/comment/testclasses/WindowsEOL.java"))) {
int b;
boolean lastWasCR = false;
while ((b = is.read()) != -1) {
if (lastWasCR) {
// next must be LF
assertTrue(b == '\n');
lastWasCR = false;
}
if (b == '\r') {
lastWasCR = true;
}
}
}
final Launcher launcher = new Launcher();
launcher.run(new String[] { "-i", "./src/test/java/spoon/test/comment/testclasses/WindowsEOL.java", "-o", "./target/spooned/", "-c" });
Factory f = launcher.getFactory();
CtClass<?> type = (CtClass<?>) f.Type().get(WindowsEOL.class);
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));
}
}
}
// This test passes on MS Windows too - why spoon uses `\n` on MS Windows too?
assertEquals("This file contains MS Windows EOL.\n" + "It is here to test whether comments are printed well\n" + "in this case", classJavaDoc.getContent());
}
use of spoon.reflect.code.CtJavaDoc 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);
}
Aggregations