Skip to content

Commit

Permalink
adding an additional test javaparser#866
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomassetti committed May 21, 2017
1 parent 7c051d8 commit e9796ac
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,7 @@ && matching(ne, pe)) {
for (CsmElement elementToAdd : elementsToBeAddedAtTheEnd) {
elements.add(diffElIterator++, new Added(elementToAdd));
}

} else {
throw new UnsupportedOperationException("" + diffEl + " vs " + nodeTextEl);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,47 @@ public void moveOverrideAnnotations() {
}
});
});
assertEquals("public class TestPage extends Page {" + EOL +
EOL +
" protected void test() {}" + EOL +
EOL +
" @Override" + EOL +
" protected void initializePage() {}" + EOL +
"}", result.b.print(cu));
}

// See issue #866
@Test
public void moveOrAddOverrideAnnotations() {
String code = "public class TestPage extends Page {" + EOL +
EOL +
" protected void test() {}" + EOL +
EOL +
" protected @Override void initializePage() {}" + EOL +
"}";

Pair<ParseResult<CompilationUnit>, LexicalPreservingPrinter> result = LexicalPreservingPrinter
.setup(ParseStart.COMPILATION_UNIT, Providers.provider(code));

CompilationUnit cu = result.a.getResult().get();

cu.getTypes().stream()
.forEach(type -> {
type.getMembers().stream()
.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 {" + EOL +
EOL +
" @Override" + EOL +
Expand Down

0 comments on commit e9796ac

Please sign in to comment.