use of com.github.javaparser.utils.Utils.SYSTEM_EOL in project javaparser by javaparser.
the class LexicalPreservingPrinterTest method moveOverrideAnnotations.
// See issue #866
@Test
void moveOverrideAnnotations() {
String code = "public class TestPage extends Page {" + SYSTEM_EOL + SYSTEM_EOL + " protected void test() {}" + SYSTEM_EOL + SYSTEM_EOL + " protected @Override void initializePage() {}" + SYSTEM_EOL + "}";
CompilationUnit cu = parse(code);
LexicalPreservingPrinter.setup(cu);
cu.getTypes().forEach(type -> type.getMembers().forEach(member -> member.ifMethodDeclaration(methodDeclaration -> {
if (methodDeclaration.getAnnotationByName("Override").isPresent()) {
while (methodDeclaration.getAnnotations().isNonEmpty()) {
AnnotationExpr annotationExpr = methodDeclaration.getAnnotations().get(0);
annotationExpr.remove();
}
methodDeclaration.addMarkerAnnotation("Override");
}
})));
assertEquals("public class TestPage extends Page {" + SYSTEM_EOL + SYSTEM_EOL + " protected void test() {}" + SYSTEM_EOL + SYSTEM_EOL + " @Override" + SYSTEM_EOL + " protected void initializePage() {}" + SYSTEM_EOL + "}", LexicalPreservingPrinter.print(cu));
}
use of com.github.javaparser.utils.Utils.SYSTEM_EOL in project javaparser by javaparser.
the class LexicalPreservingPrinterTest method handleAddingMarkerAnnotation.
// See issue #865
@Test
void handleAddingMarkerAnnotation() {
String code = "public class TestPage extends Page {" + SYSTEM_EOL + SYSTEM_EOL + " protected void test() {}" + SYSTEM_EOL + SYSTEM_EOL + " @Override" + SYSTEM_EOL + " protected void initializePage() {}" + SYSTEM_EOL + "}";
CompilationUnit cu = parse(code);
LexicalPreservingPrinter.setup(cu);
cu.getTypes().forEach(type -> type.getMembers().forEach(member -> {
if (member instanceof MethodDeclaration) {
MethodDeclaration methodDeclaration = (MethodDeclaration) member;
if (!methodDeclaration.getAnnotationByName("Override").isPresent()) {
methodDeclaration.addMarkerAnnotation("Override");
}
}
}));
assertEquals("public class TestPage extends Page {" + SYSTEM_EOL + SYSTEM_EOL + " @Override" + SYSTEM_EOL + " protected void test() {}" + SYSTEM_EOL + SYSTEM_EOL + " @Override" + SYSTEM_EOL + " protected void initializePage() {}" + SYSTEM_EOL + "}", LexicalPreservingPrinter.print(cu));
}
use of com.github.javaparser.utils.Utils.SYSTEM_EOL in project javaparser by javaparser.
the class LexicalPreservingPrinterTest method handleOverrideAnnotationAlternative.
// See issue #865
@Test
void handleOverrideAnnotationAlternative() {
String code = "public class TestPage extends Page {" + SYSTEM_EOL + SYSTEM_EOL + " protected void test() {}" + SYSTEM_EOL + SYSTEM_EOL + " protected void initializePage() {}" + SYSTEM_EOL + "}";
CompilationUnit cu = parse(code);
LexicalPreservingPrinter.setup(cu);
cu.getTypes().forEach(type -> type.getMembers().forEach(member -> member.ifMethodDeclaration(methodDeclaration -> methodDeclaration.addAnnotation("Override"))));
assertEquals("public class TestPage extends Page {" + SYSTEM_EOL + SYSTEM_EOL + " @Override()" + SYSTEM_EOL + " protected void test() {}" + SYSTEM_EOL + SYSTEM_EOL + " @Override()" + SYSTEM_EOL + " protected void initializePage() {}" + SYSTEM_EOL + "}", LexicalPreservingPrinter.print(cu));
}
use of com.github.javaparser.utils.Utils.SYSTEM_EOL in project javaparser by javaparser.
the class LexicalPreservingPrinterTest method moveOrAddOverrideAnnotations.
// See issue #866
@Test
void moveOrAddOverrideAnnotations() {
String code = "public class TestPage extends Page {" + SYSTEM_EOL + SYSTEM_EOL + " protected void test() {}" + SYSTEM_EOL + SYSTEM_EOL + " protected @Override void initializePage() {}" + SYSTEM_EOL + "}";
CompilationUnit cu = parse(code);
LexicalPreservingPrinter.setup(cu);
cu.getTypes().forEach(type -> type.getMembers().forEach(member -> {
if (member instanceof MethodDeclaration) {
MethodDeclaration methodDeclaration = (MethodDeclaration) member;
if (methodDeclaration.getAnnotationByName("Override").isPresent()) {
while (methodDeclaration.getAnnotations().isNonEmpty()) {
AnnotationExpr annotationExpr = methodDeclaration.getAnnotations().get(0);
annotationExpr.remove();
}
}
methodDeclaration.addMarkerAnnotation("Override");
}
}));
assertEquals("public class TestPage extends Page {" + SYSTEM_EOL + SYSTEM_EOL + " @Override" + SYSTEM_EOL + " protected void test() {}" + SYSTEM_EOL + SYSTEM_EOL + " @Override" + SYSTEM_EOL + " protected void initializePage() {}" + SYSTEM_EOL + "}", LexicalPreservingPrinter.print(cu));
}
use of com.github.javaparser.utils.Utils.SYSTEM_EOL in project javaparser by javaparser.
the class JavadocTest method inlineTagsAreParsable.
@Test
void inlineTagsAreParsable() {
String docText = "Returns the {@link TOFilename}s of all files that existed during the requested" + SYSTEM_EOL + "{@link TOVersion}. Set {@systemProperty JAVA_HOME} correctly." + SYSTEM_EOL + "" + SYSTEM_EOL + "@param versionID the id of the {@link TOVersion}." + SYSTEM_EOL + "@return the filenames" + SYSTEM_EOL + "@throws InvalidIDException if the {@link IPersistence} doesn't recognize the given versionID." + SYSTEM_EOL;
Javadoc javadoc = parseJavadoc(docText);
List<JavadocInlineTag> inlineTags = javadoc.getDescription().getElements().stream().filter(element -> element instanceof JavadocInlineTag).map(element -> (JavadocInlineTag) element).collect(toList());
assertEquals("link", inlineTags.get(0).getName());
assertEquals(" TOFilename", inlineTags.get(0).getContent());
assertEquals(LINK, inlineTags.get(0).getType());
assertEquals("link", inlineTags.get(1).getName());
assertEquals(" TOVersion", inlineTags.get(1).getContent());
assertEquals(LINK, inlineTags.get(1).getType());
assertEquals("systemProperty", inlineTags.get(2).getName());
assertEquals(" JAVA_HOME", inlineTags.get(2).getContent());
assertEquals(SYSTEM_PROPERTY, inlineTags.get(2).getType());
String javadocText = javadoc.toText();
assertTrue(javadocText.contains("{@link TOVersion}"));
}
Aggregations