use of com.github.javaparser.ast.comments.JavadocComment in project javaparser by javaparser.
the class NodeWithJavadocTest method removeJavaDocPositiveCase.
@Test
public void removeJavaDocPositiveCase() {
ClassOrInterfaceDeclaration decl = new ClassOrInterfaceDeclaration(EnumSet.noneOf(Modifier.class), false, "Foo");
decl.setComment(new JavadocComment("A comment"));
assertEquals(true, decl.removeJavaDocComment());
assertFalse(decl.getComment().isPresent());
}
use of com.github.javaparser.ast.comments.JavadocComment in project javaparser by javaparser.
the class DifferenceTest method annotationDeclarationExampleWithJavadocAdded.
@Test
public void annotationDeclarationExampleWithJavadocAdded() throws IOException {
considerExample("AnnotationDeclaration_Example3_original");
AnnotationDeclaration annotationDeclaration = (AnnotationDeclaration) cu.getType(0);
CsmElement element = ConcreteSyntaxModel.forClass(annotationDeclaration.getClass());
JavadocComment comment = new JavadocComment("Cool this annotation!");
LexicalDifferenceCalculator.CalculatedSyntaxModel csmOriginal = new LexicalDifferenceCalculator().calculatedSyntaxModelForNode(element, annotationDeclaration);
LexicalDifferenceCalculator.CalculatedSyntaxModel csmChanged = new LexicalDifferenceCalculator().calculatedSyntaxModelAfterPropertyChange(element, annotationDeclaration, ObservableProperty.COMMENT, null, comment);
Difference diff = Difference.calculate(csmOriginal, csmChanged);
diff.removeIndentationElements();
int i = 0;
assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.PUBLIC)), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(spaceTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.AT)), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.INTERFACE)), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(spaceTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmChild(annotationDeclaration.getName())), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(spaceTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.LBRACE)), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmChild(annotationDeclaration.getMember(0))), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmChild(annotationDeclaration.getMember(1))), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmChild(annotationDeclaration.getMember(2))), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmChild(annotationDeclaration.getMember(3))), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmChild(annotationDeclaration.getMember(4))), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmChild(annotationDeclaration.getMember(5))), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(kept(new CsmToken(GeneratedJavaParserConstants.RBRACE)), diff.getElements().get(i++));
assertEquals(i, diff.getElements().size());
}
use of com.github.javaparser.ast.comments.JavadocComment in project javaparser by javaparser.
the class LexicalDifferenceCalculatorTest method annotationDeclaratioJavadocExampleAddingJavadoc.
@Test
public void annotationDeclaratioJavadocExampleAddingJavadoc() throws IOException {
considerExample("AnnotationDeclaration_Example3_original");
AnnotationDeclaration annotationDeclaration = (AnnotationDeclaration) cu.getType(0);
CsmElement element = ConcreteSyntaxModel.forClass(annotationDeclaration.getClass());
JavadocComment comment = new JavadocComment("Cool this annotation!");
LexicalDifferenceCalculator.CalculatedSyntaxModel csm = new LexicalDifferenceCalculator().calculatedSyntaxModelAfterPropertyChange(element, annotationDeclaration, ObservableProperty.COMMENT, null, comment);
csm.removeIndentationElements();
int i = 0;
assertEquals(new CsmToken(GeneratedJavaParserConstants.PUBLIC), csm.elements.get(i++));
assertEquals(new CsmToken(spaceTokenKind()), csm.elements.get(i++));
assertEquals(new CsmToken(GeneratedJavaParserConstants.AT), csm.elements.get(i++));
assertEquals(new CsmToken(GeneratedJavaParserConstants.INTERFACE), csm.elements.get(i++));
assertEquals(new CsmToken(spaceTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getName()), csm.elements.get(i++));
assertEquals(new CsmToken(spaceTokenKind()), csm.elements.get(i++));
assertEquals(new CsmToken(GeneratedJavaParserConstants.LBRACE), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(0)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(1)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(2)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(3)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(4)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new LexicalDifferenceCalculator.CsmChild(annotationDeclaration.getMember(5)), csm.elements.get(i++));
assertEquals(new CsmToken(eolTokenKind()), csm.elements.get(i++));
assertEquals(new CsmToken(GeneratedJavaParserConstants.RBRACE), csm.elements.get(i++));
assertEquals(i, csm.elements.size());
}
use of com.github.javaparser.ast.comments.JavadocComment in project javaparser by javaparser.
the class JavadocExtractorTest method processFile.
private void processFile(File file) throws FileNotFoundException {
try {
CompilationUnit cu = JavaParser.parse(file, StandardCharsets.UTF_8);
new VoidVisitorAdapter<Object>() {
@Override
public void visit(JavadocComment n, Object arg) {
super.visit(n, arg);
n.parse();
}
}.visit(cu, null);
} catch (ParseProblemException e) {
System.err.println("ERROR PROCESSING " + file);
}
}
use of com.github.javaparser.ast.comments.JavadocComment in project javaparser by javaparser.
the class JavadocTest method toCommentorJavadocWithTwoLinesOfJustDescription.
@Test
public void toCommentorJavadocWithTwoLinesOfJustDescription() {
Javadoc javadoc = new Javadoc(JavadocDescription.parseText("first line" + EOL + "second line"));
assertEquals(new JavadocComment("" + EOL + "\t\t * first line" + EOL + "\t\t * second line" + EOL + "\t\t "), javadoc.toComment("\t\t"));
}
Aggregations