use of spoon.reflect.declaration.CtClass in project spoon by INRIA.
the class CommentTest method testRemoveComment.
@Test
public void testRemoveComment() {
Factory f = getSpoonFactory();
CtClass<?> type = (CtClass<?>) f.Type().get(InlineComment.class);
List<CtComment> comments = type.getComments();
assertEquals(3, comments.size());
type.removeComment(comments.get(0));
assertEquals(2, type.getComments().size());
}
use of spoon.reflect.declaration.CtClass in project spoon by INRIA.
the class CommentTest method testWildComments.
@Test
public void testWildComments() {
// contract: tests that value of comment is correct even for wild combinations of characters. See WildComments class for details
Factory f = getSpoonFactory();
CtClass<?> type = (CtClass<?>) f.Type().get(WildComments.class);
List<CtLiteral<String>> literals = (List) ((CtNewArray<?>) type.getField("comments").getDefaultExpression()).getElements();
assertTrue(literals.size() > 10);
/*
* each string literal has a comment and string value, which defines expected value of it's comment
*/
for (CtLiteral<String> literal : literals) {
assertEquals(1, literal.getComments().size());
CtComment comment = literal.getComments().get(0);
String expected = literal.getValue();
assertEquals(literal.getPosition().toString(), expected, comment.getContent());
}
}
use of spoon.reflect.declaration.CtClass 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.declaration.CtClass 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.declaration.CtClass in project spoon by INRIA.
the class CommentTest method testJavadocShortAndLongComment.
@Test
public void testJavadocShortAndLongComment() {
// contract: in case we cannot determine if it is a short comment, we take the whole content
Factory f = getSpoonFactory();
CtClass<?> type = (CtClass<?>) f.Type().get(OtherJavaDoc.class);
CtJavaDoc classJavaDoc = (CtJavaDoc) type.getComments().get(0);
assertEquals("A short description without a proper end", classJavaDoc.getShortDescription());
assertEquals("A short description without a proper end", classJavaDoc.getLongDescription());
}
Aggregations