ASTParser does not parse javadoc comments [message #916821] |
Wed, 19 September 2012 14:08 |
Michael Doswald Messages: 2 Registered: September 2012 |
Junior Member |
|
|
Hi eclipse community,
I am using the eclipse java source code parser in jdt.core to parse some source files in our internal development tool. It's a maven plugin, so I use the jdt libraries in a standalone fashion (without eclipse).
I need to check the javadoc comments in the class, interface and enum declarations for some specific tags. Unfortunately, the ASTParser doesn't seem to parse the javadoc comments.
The following code shows a test method I implemented to narrow down the problem. Am I doing something wrong here?
@Test
public void testJavaDocParseFailure()
{
StringWriter classWriter = new StringWriter();
PrintWriter classStream = new PrintWriter( classWriter );
classStream.println("package test; ");
classStream.println(" ");
classStream.println("/** ");
classStream.println(" * This is a test comment ");
classStream.println(" */ ");
classStream.println("public class TestClass {} ");
ASTParser javaParser = ASTParser.newParser(AST.JLS4);
javaParser.setEnvironment(null, null, null, true);
javaParser.setStatementsRecovery(true);
Map<String,String> compilerOptions = JavaCore.getDefaultOptions();
compilerOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7);
compilerOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_7);
compilerOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_7);
javaParser.setCompilerOptions(compilerOptions);
javaParser.setSource( classWriter.toString().toCharArray() );
javaParser.createAST(null).accept( new ASTVisitor(true) {
@Override
public boolean visit(Javadoc node)
{
System.out.println( "Found javadoc: " + node );
return true;
}
@Override
public boolean visit(TypeDeclaration node)
{
System.out.println( "Found Type " + node.getName().getFullyQualifiedName() + " -> javadoc: " + node.getJavadoc() );
return super.visit(node);
}
});
}
The only output from this code is:
Found Type TestClass -> javadoc: null
I use the following libraries (copied from an eclipse 3.8 install):
org.eclipse.jdt.core_3.8.1.v20120531-0637
org.eclipse.equinox.common_3.6.100.v20120522-1841
org.eclipse.core.resources_3.8.0.v20120522-2034
org.eclipse.core.jobs_3.5.200.v20120521-2346
org.eclipse.core.runtime_3.8.0.v20120521-2346
org.eclipse.osgi_3.8.0.v20120529-1548
org.eclipse.core.contenttype_3.4.200.v20120523-2004
org.eclipse.equinox.preferences_3.5.0.v20120522-1841
Does anybody know what I am doing wrong here?
Regards,
Michael
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03186 seconds