Summary: | [javadoc] MethodDeclaration.getJavadoc() returns null | ||||||
---|---|---|---|---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Vedran Lerenc <vedran.lerenc> | ||||
Component: | Core | Assignee: | Frederic Fusier <frederic_fusier> | ||||
Status: | CLOSED INVALID | QA Contact: | |||||
Severity: | normal | ||||||
Priority: | P3 | ||||||
Version: | 3.0.1 | ||||||
Target Milestone: | 3.1 M4 | ||||||
Hardware: | PC | ||||||
OS: | Windows XP | ||||||
Whiteboard: | |||||||
Attachments: |
|
Description
Vedran Lerenc
2004-11-24 07:38:14 EST
Unfortunately I cannot reproduce this bug... Here's the simpler test case I use: b79373/Test.java package b79373; import b79373.p.q.r.s.IUser; public class Test extends IUser { // C comment public b79373.a.b.c.d.IUser methodInNoneOutOld(IUser user) { return null; } /** * Print a String and then terminate the line. This method behaves as though * it invokes <code>{@link #print(String)}</code> and then * <code>{@link #println()}</code>. * * @param user * The <code>String</code> to be printed. */ public b79373.a.b.c.d.IUser methodInNoneOutOld(b79373.a.b.c.d.IUser user) { return null; } } b79373/p/q/r/s/IUser.java: package b79373.p.q.r.s; public class IUser {} b79373/a/b/c/d/IUser.java: package b79373.a.b.c.d; public class IUser {} For first method declaration getJavadoc() returns null but second one does not! Could you try this simple example and let me know whether the second method javadic is null or not, thx Hello, I tried the example, i.e. I tried my code on Test.java and I got in both cases null. I have not created the two other files (IUser), because I use your libraries stand-alone without a running Eclipse environment and I am not interested in bindings (as stated in my initial bug report - can this be a problem? - do you have tried this?). For that purpose neither the file path must match the package nor full qualified names must be resolvable. All other calls to your parser API work correctly in stand-alone mode, except for MethodDeclaration.getJavaDoc(), although MethodDeclaration.getStartPosition () returns the correct position at the beginning of the JavaDoc for the second method. Regards, Vedran With or without bindings I always get a non null javadoc on second method... Here's the code I used to test it in a JUnit plugin test: // Get compilation unit IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IFile file = root.getFile(new Path("/Converter/src/b79373/SourceImportingNew.java")); ICompilationUnit cu = (ICompilationUnit)JavaCore.create(file); // Parse complation unit ASTParser parser = ASTParser.newParser(AST.JLS2); parser.setSource(cu); parser.setResolveBindings(false); ASTNode result = parser.createAST(null); CompilationUnit unit = (CompilationUnit) result; // First method javadoc comment should be null MethodDeclaration firstMethod = (MethodDeclaration) ((TypeDeclaration)unit.types().get(0)).bodyDeclarations().get(0); if (firstMethod.getJavadoc() == null) { System.out.println("First method javadoc is null: OK"); } else { System.err.println("First method javadoc is not null: KO"); } // Second method javadoc comment should NOT be null MethodDeclaration secondMethod = (MethodDeclaration) ((TypeDeclaration)unit.types().get(0)).bodyDeclarations().get(1); if (secondMethod.getJavadoc() != null) { System.out.println("Second method javadoc is not null: OK"); } else { System.err.println("Second method javadoc is null: KO"); } Running this, I get: First method javadoc is null: OK Second method javadoc is not null: OK Of course, this is executed inside Eclipse (in Headleass mode) where DOM AST is only designed to work. I cannot figure out how you can get an ICompilationUnit outside eclipse in a standard Java application. May be can you attach the code you run to let me test it?... Created attachment 16129 [details]
Full project - attached note with code snippet concerning stand-alone usage of the parser
No problem, here some code snippets:
import org.eclipse.jdt.core.*;
import org.eclipse.jdt.core.dom.*;
public class Transformer
{
private ASTParser parser;
public Transformer()
{
// Create parser
Map options = new HashMap();
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
parser = ASTParser.newParser(AST.JLS2);
parser.setCompilerOptions(options);
}
public CompilationUnit parse(String content)
{
// Parse source
parser.setSource(content.toCharArray());
CompilationUnit unitDecl = (CompilationUnit) parser.createAST(null);
return unitDecl;
}
public List analyze(CompilationUnit unitDecl, String originalContent)
{
// Do analysis
// e.g.
for (Iterator iter = unitDecl.imports().iterator(); iter.hasNext();)
{
ImportDeclaration importDecl = (ImportDeclaration) iter.next();
analyze(importDecl, originalContent, modifications, typeResolver);
}
for (Iterator iter = unitDecl.types().iterator(); iter.hasNext();)
{
TypeDeclaration typeDecl = (TypeDeclaration) iter.next();
analyze(typeDecl, originalContent, modifications, typeResolver);
}
// ...
}
}
This stuff works stand-alone just perfectly - navigating from compilation units
to imports, types, sub types, methods or fields works as expected, except for
this MethodDeclaration.getJavadoc() method.
Regards,
Vedran
OK, thanks for the input. I see what's wrong in your code, you're missing following compiler option in Transformer default constructor: options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); With this option enabled, javadoc will be parsed and built, then assigned in method declaration... Thanks, that solved the problem! :-) I am sorry for the inconvenience. One last question: Are the other available settings described somewhere in more detail? Regards, Vedran Look at JavaCore.getDefaultOptions() |