Search in sources :

Example 21 with JavadocComment

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());
}
Also used : JavadocComment(com.github.javaparser.ast.comments.JavadocComment) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) Modifier(com.github.javaparser.ast.Modifier) Test(org.junit.Test)

Example 22 with JavadocComment

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());
}
Also used : JavadocComment(com.github.javaparser.ast.comments.JavadocComment) CsmToken(com.github.javaparser.printer.concretesyntaxmodel.CsmToken) CsmChild(com.github.javaparser.printer.lexicalpreservation.LexicalDifferenceCalculator.CsmChild) CsmElement(com.github.javaparser.printer.concretesyntaxmodel.CsmElement) Test(org.junit.Test)

Example 23 with JavadocComment

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());
}
Also used : JavadocComment(com.github.javaparser.ast.comments.JavadocComment) CsmToken(com.github.javaparser.printer.concretesyntaxmodel.CsmToken) AnnotationDeclaration(com.github.javaparser.ast.body.AnnotationDeclaration) CsmElement(com.github.javaparser.printer.concretesyntaxmodel.CsmElement) Test(org.junit.Test)

Example 24 with JavadocComment

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);
    }
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) JavadocComment(com.github.javaparser.ast.comments.JavadocComment) ParseProblemException(com.github.javaparser.ParseProblemException)

Example 25 with JavadocComment

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"));
}
Also used : JavadocComment(com.github.javaparser.ast.comments.JavadocComment) Test(org.junit.Test)

Aggregations

JavadocComment (com.github.javaparser.ast.comments.JavadocComment)25 Comment (com.github.javaparser.ast.comments.Comment)16 BlockComment (com.github.javaparser.ast.comments.BlockComment)14 LineComment (com.github.javaparser.ast.comments.LineComment)14 Test (org.junit.Test)7 BodyDeclaration (com.github.javaparser.ast.body.BodyDeclaration)4 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)4 TypeParameter (com.github.javaparser.ast.TypeParameter)3 MultiTypeParameter (com.github.javaparser.ast.body.MultiTypeParameter)3 AnnotationDeclaration (com.github.javaparser.ast.body.AnnotationDeclaration)2 EnumConstantDeclaration (com.github.javaparser.ast.body.EnumConstantDeclaration)2 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)2 Parameter (com.github.javaparser.ast.body.Parameter)2 CsmElement (com.github.javaparser.printer.concretesyntaxmodel.CsmElement)2 CsmToken (com.github.javaparser.printer.concretesyntaxmodel.CsmToken)2 Javadoc (act.apidoc.javadoc.Javadoc)1 ParseProblemException (com.github.javaparser.ParseProblemException)1 com.github.javaparser.ast (com.github.javaparser.ast)1 CompilationUnit (com.github.javaparser.ast.CompilationUnit)1 Modifier (com.github.javaparser.ast.Modifier)1