Bug 93741 - Javadoc of PackageDeclaration is null
Summary: Javadoc of PackageDeclaration is null
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 critical (vote)
Target Milestone: 3.1 M7   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-04 19:16 EDT by julien CLA
Modified: 2005-05-12 04:26 EDT (History)
1 user (show)

See Also:


Attachments
Snapshot of a sample (78.72 KB, image/gif)
2005-05-07 14:46 EDT, Frederic Fusier CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description julien CLA 2005-05-04 19:16:33 EDT
The javadoc of CompilationUnit PackageDeclaration is always null. Thru the JDK 
1.5 specification, we use the PackageDeclaration in the file package-info.java 
to store the Package's Java doc.
Comment 1 Frederic Fusier CLA 2005-05-07 07:01:19 EDT
Which build are you using?
If this is 3.1 M6, could you make a try with a more recent integration build
(I20050506-1600) or 3.1 M7 next week and confirm that your bug is a duplicate of
bug 83804?
Thanks
Comment 2 julien CLA 2005-05-07 14:11:52 EDT
I was 3.1M6. I just tested the build I20050506-1600. The javaDoc in 
PackageDeclaration of CompilationUnit is always null.
Comment 3 Frederic Fusier CLA 2005-05-07 14:44:46 EDT
I cannot reproduce your problem.

PackageDeclaration javadoc of package-info.java CompilationUnit is always not
null when there's a javadoc comment specified before package declaration:
/**
 * Javadoc for all package 
 * @see Object Root class
 */
 package test.packageInfo;

I'll add a snapshot to show this using ASTView...

Can you provide a detailed test case to help to understand what happen there?
Comment 4 Frederic Fusier CLA 2005-05-07 14:46:24 EDT
Created attachment 20802 [details]
Snapshot of a sample

Using ASTView, you can see that PackageDeclaration Javadoc is not null and that
its hierachy match comment contents...
Comment 5 julien CLA 2005-05-07 15:56:43 EDT
Here is my code:
		ASTParser parser = ASTParser.newParser(AST.JLS3); 
		parser.setSource("/**\n * test\n */package test;".toCharArray
());
		CompilationUnit unit = (CompilationUnit) parser.createAST
(null);
		PackageDeclaration packageDeclaration = unit.getPackage();
		System.out.println(packageDeclaration.getJavadoc());

I get null in starndard output
Comment 6 Frederic Fusier CLA 2005-05-07 17:09:55 EDT
Javadoc is only set for package-info.java compilation unit and if you compile it
 with 1.5 source level.

So, to make your example working, you need to modify your code as follow:
	ASTParser parser = ASTParser.newParser(AST.JLS3); 
	parser.setSource("/**\n * test\n */package test;".toCharArray());

	// CU need to have package-info name
	parser.setUnitName("package-info");

	// CU need to be parsed with 1.5 source level
	Hashtable options = JavaCore.getOptions();
	options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
	parser.setCompilerOptions(options);

	CompilationUnit unit = (CompilationUnit) parser.createAST(null);
	PackageDeclaration packageDeclaration = unit.getPackage();
	System.out.println(packageDeclaration.getJavadoc());
Comment 7 Markus Keller CLA 2005-05-12 03:37:13 EDT
> Javadoc is only set for package-info.java compilation unit and if you compile
> it with 1.5 source level.

That's not true. It it were so, it should have been documented in
PackageDeclaration#getJavadoc(). But the JLS3 AST for the example below contains
the Javadoc header in I20050509-2010.


/*******************************************************************************
 * Header
 ******************************************************************************/
package xy;
public class Try { }
Comment 8 Frederic Fusier CLA 2005-05-12 04:26:42 EDT
Yes, you're right. Only source level 1.5 is necessary to get javadoc in package
declaration. The difference is that references in javadoc are resolved only for
package-info.java compilation unit as javadoc.exe done.
I posted a message on news group to julien's thread but didn't update this bug.
Thanks to have done it :-)