use of com.github.javaparser.ast.comments.LineComment in project javaparser by javaparser.
the class NodeTest method removeOrphanCommentPositiveCase.
@Test
public void removeOrphanCommentPositiveCase() {
ClassOrInterfaceDeclaration decl = new ClassOrInterfaceDeclaration(EnumSet.noneOf(Modifier.class), false, "A");
Comment c = new LineComment("A comment");
decl.addOrphanComment(c);
assertEquals(1, decl.getOrphanComments().size());
assertTrue(decl == c.getParentNode().get());
assertTrue(decl.removeOrphanComment(c));
assertEquals(0, decl.getOrphanComments().size());
assertFalse(c.getParentNode().isPresent());
}
use of com.github.javaparser.ast.comments.LineComment in project javaparser by javaparser.
the class NodeTest method removeOrphanCommentNegativeCase.
@Test
public void removeOrphanCommentNegativeCase() {
ClassOrInterfaceDeclaration aClass = new ClassOrInterfaceDeclaration(EnumSet.noneOf(Modifier.class), false, "A");
FieldDeclaration aField = new FieldDeclaration(EnumSet.noneOf(Modifier.class), new VariableDeclarator(PrimitiveType.intType(), "f"));
aClass.getMembers().add(aField);
Comment c = new LineComment("A comment");
aField.addOrphanComment(c);
// the comment is an orphan comment of the field, so trying to remove it on the class should not work
assertFalse(aClass.removeOrphanComment(c));
assertEquals(1, aField.getOrphanComments().size());
assertTrue(c.getParentNode().isPresent());
}
use of com.github.javaparser.ast.comments.LineComment in project javaparser by javaparser.
the class PrettyPrintVisitorTest method singlelineCommentGetsFormatted.
@Test
public void singlelineCommentGetsFormatted() {
CompilationUnit cu = new CompilationUnit();
cu.addClass("X").addMethod("abc").setComment(new LineComment(" line1 \n "));
assertEqualsNoEol("public class X {\n" + "\n" + " // line1\n" + " void abc() {\n" + " }\n" + "}\n", cu.toString());
}
Aggregations