summaryrefslogtreecommitdiffstats
authorManju Mathew2012-11-20 05:49:37 (EST)
committer Dani Megert2012-11-20 05:49:37 (EST)
commit2c254e24e4d69c3ff229adad1160425d3a40ab8c (patch) (side-by-side diff)
tree7eae4b3d0622574a5491e07030a6aafcba3b7f2c
parent5da79b4c8ac238ea93a663adbb34f58a089ffb5b (diff)
downloadeclipse.jdt.ui-2c254e24e4d69c3ff229adad1160425d3a40ab8c.zip
eclipse.jdt.ui-2c254e24e4d69c3ff229adad1160425d3a40ab8c.tar.gz
eclipse.jdt.ui-2c254e24e4d69c3ff229adad1160425d3a40ab8c.tar.bz2
First cut of package doc support
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/javadoc/JavaDocLocations.java20
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java82
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavadocHover.java79
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/javadoc/JavaDocMessages.java4
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/javadoc/JavaDocMessages.properties3
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/javadoc/JavadocContentAccess2.java219
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/JavaElementLabelComposer.java2
7 files changed, 346 insertions, 63 deletions
diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/javadoc/JavaDocLocations.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/javadoc/JavaDocLocations.java
index 4c820c6..ead10f6 100644
--- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/javadoc/JavaDocLocations.java
+++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/javadoc/JavaDocLocations.java
@@ -590,10 +590,17 @@ public class JavaDocLocations {
}
public static String getBaseURL(IMember member) throws JavaModelException {
- if (member.isBinary()) {
+ return getBaseURL(member, member.isBinary());
+ }
+
+
+
+ public static String getBaseURL(IJavaElement element, boolean isBinary) throws JavaModelException {
+ String baseUrl= null;
+ if (isBinary) {
// Source attachment usually does not include Javadoc resources
// => Always use the Javadoc location as base:
- URL baseURL= JavaUI.getJavadocLocation(member, false);
+ URL baseURL= JavaUI.getJavadocLocation(element, false);
if (baseURL != null) {
if (baseURL.getProtocol().equals(JAR_PROTOCOL)) {
// It's a JarURLConnection, which is not known to the browser widget.
@@ -603,10 +610,10 @@ public class JavaDocLocations {
baseURL= baseURL2;
}
}
- return baseURL.toExternalForm();
+ baseUrl= baseURL.toExternalForm();
}
} else {
- IResource resource= member.getResource();
+ IResource resource= element.getResource();
if (resource != null) {
/*
* Too bad: Browser widget knows nothing about EFS and custom URL handlers,
@@ -616,10 +623,11 @@ public class JavaDocLocations {
*/
IPath location= resource.getLocation();
if (location != null)
- return location.toFile().toURI().toString();
+ baseUrl= location.toFile().toURI().toString();
}
}
- return null;
+ return baseUrl;
+
}
/**
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java
index 08fbc8e..5efed7f 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java
@@ -107,6 +107,7 @@ import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.ILocalVariable;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IOpenable;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.ITypeRoot;
@@ -1074,7 +1075,7 @@ public class JavadocView extends AbstractInfoView {
for (int i= 0; i < result.length; i++) {
HTMLPrinter.startBulletList(buffer);
IJavaElement curr= result[i];
- if (curr instanceof IMember || curr.getElementType() == IJavaElement.LOCAL_VARIABLE)
+ if (curr instanceof IMember || curr instanceof IPackageFragment || curr.getElementType() == IJavaElement.LOCAL_VARIABLE)
HTMLPrinter.addBullet(buffer, getInfoText(curr, null, false));
HTMLPrinter.endBulletList(buffer);
}
@@ -1082,7 +1083,28 @@ public class JavadocView extends AbstractInfoView {
} else {
IJavaElement curr= result[0];
- if (curr instanceof IMember) {
+ if(curr instanceof IPackageFragment){
+ HTMLPrinter.addSmallHeader(buffer, getInfoText(curr, null, true));
+ buffer.append("<br>"); //$NON-NLS-1$
+ IPackageFragment packge = (IPackageFragment)curr;
+ Reader reader;
+ String content= JavadocContentAccess2.getPackageDocumentation(packge);
+ reader= content == null ? null : new StringReader(content);
+ IPackageFragmentRoot root= (IPackageFragmentRoot) packge.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
+
+ // Provide hint why there's no Java doc
+ try {
+ base= getInfoTextForNoJavadoc(reader, packge, root, root.getKind() == IPackageFragmentRoot.K_BINARY);
+ } catch (JavaModelException e) {
+ reader= new StringReader(InfoViewMessages.JavadocView_error_gettingJavadoc);
+ JavaPlugin.log(e);
+ }
+
+
+ if (reader != null) {
+ HTMLPrinter.addParagraph(buffer, reader);
+ }
+ }else if (curr instanceof IMember) {
final IMember member= (IMember)curr;
String constantValue= null;
@@ -1112,26 +1134,8 @@ public class JavadocView extends AbstractInfoView {
reader= content == null ? null : new StringReader(content);
// Provide hint why there's no Javadoc
- if (reader == null && member.isBinary()) {
- boolean hasAttachedJavadoc= JavaDocLocations.getJavadocBaseLocation(member) != null;
- IPackageFragmentRoot root= (IPackageFragmentRoot)member.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
- boolean hasAttachedSource= root != null && root.getSourceAttachmentPath() != null;
- IOpenable openable= member.getOpenable();
- boolean hasSource= openable.getBuffer() != null;
-
- if (!hasAttachedSource && !hasAttachedJavadoc)
- reader= new StringReader(InfoViewMessages.JavadocView_noAttachments);
- else if (!hasAttachedJavadoc && !hasSource)
- reader= new StringReader(InfoViewMessages.JavadocView_noAttachedJavadoc);
- else if (!hasAttachedSource)
- reader= new StringReader(InfoViewMessages.JavadocView_noAttachedSource);
- else if (!hasSource)
- reader= new StringReader(InfoViewMessages.JavadocView_noInformation);
-
- } else {
- base= JavaDocLocations.getBaseURL(member);
- }
-
+ IPackageFragmentRoot root= (IPackageFragmentRoot) member.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
+ base= getInfoTextForNoJavadoc(reader, member, root, member.isBinary());
} catch (JavaModelException ex) {
reader= new StringReader(InfoViewMessages.JavadocView_error_gettingJavadoc);
JavaPlugin.log(ex.getStatus());
@@ -1165,6 +1169,40 @@ public class JavadocView extends AbstractInfoView {
}
/**
+ * The reader will store the reason for why there is no valid java doc associated with the
+ * selected IJavaElement
+ *
+ * @param reader - the StringReader
+ * @param element - IJavaElement
+ * @param root - IPackageFragmentRoot
+ * @param isBinary - whether the content is coming from jar
+ * @return - baseURL of the JavaDoc, null if there is no associated javadoc
+ * @throws JavaModelException -
+ */
+ private static String getInfoTextForNoJavadoc(Reader reader, IJavaElement element, IPackageFragmentRoot root, boolean isBinary) throws JavaModelException {
+ String baseURL= null;
+ if (reader == null && isBinary) {
+ boolean hasAttachedJavadoc= JavaDocLocations.getJavadocBaseLocation(element) != null;
+ boolean hasAttachedSource= root != null && root.getSourceAttachmentPath() != null;
+ IOpenable openable= element.getOpenable();
+ boolean hasSource= openable.getBuffer() != null;
+
+ if (!hasAttachedSource && !hasAttachedJavadoc)
+ reader= new StringReader(InfoViewMessages.JavadocView_noAttachments);
+ else if (!hasAttachedJavadoc && !hasSource)
+ reader= new StringReader(InfoViewMessages.JavadocView_noAttachedJavadoc);
+ else if (!hasAttachedSource)
+ reader= new StringReader(InfoViewMessages.JavadocView_noAttachedSource);
+ else if (!hasSource)
+ reader= new StringReader(InfoViewMessages.JavadocView_noInformation);
+
+ } else {
+ baseURL= JavaDocLocations.getBaseURL(element, isBinary);
+ }
+
+ return baseURL;
+ }
+ /**
* Gets the label for the given member.
*
* @param member the Java member
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavadocHover.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavadocHover.java
index dd436f8..9636b3b 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavadocHover.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavadocHover.java
@@ -62,6 +62,7 @@ import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IOpenable;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.ITypeRoot;
import org.eclipse.jdt.core.JavaCore;
@@ -575,7 +576,7 @@ public class JavadocHover extends AbstractJavaEditorTextHover {
* @return the HTML hover info for the given element(s) or <code>null</code> if no information is available
* @since 3.4
*/
- private static JavadocBrowserInformationControlInput getHoverInfo(IJavaElement[] elements, ITypeRoot editorInputElement, IRegion hoverRegion, JavadocBrowserInformationControlInput previousInput) {
+ public static JavadocBrowserInformationControlInput getHoverInfo(IJavaElement[] elements, ITypeRoot editorInputElement, IRegion hoverRegion, JavadocBrowserInformationControlInput previousInput) {
int nResults= elements.length;
StringBuffer buffer= new StringBuffer();
boolean hasContents= false;
@@ -589,7 +590,7 @@ public class JavadocHover extends AbstractJavaEditorTextHover {
for (int i= 0; i < elements.length; i++) {
HTMLPrinter.startBulletList(buffer);
IJavaElement curr= elements[i];
- if (curr instanceof IMember || curr.getElementType() == IJavaElement.LOCAL_VARIABLE) {
+ if (curr instanceof IMember || curr instanceof IPackageFragment || curr.getElementType() == IJavaElement.LOCAL_VARIABLE) {
String label= JavaElementLabels.getElementLabel(curr, getHeaderFlags(curr));
String link;
try {
@@ -608,38 +609,40 @@ public class JavadocHover extends AbstractJavaEditorTextHover {
} else {
element= elements[0];
- if (element instanceof IMember) {
+ if(element instanceof IPackageFragment){
+ HTMLPrinter.addSmallHeader(buffer, getInfoText(element, editorInputElement, hoverRegion, true));
+ buffer.append("<br>"); //$NON-NLS-1$
+ IPackageFragment packge = (IPackageFragment)element;
+ Reader reader;
+ String content= JavadocContentAccess2.getPackageDocumentation(packge);
+ reader = content == null ? null : new StringReader(content);
+ IPackageFragmentRoot root= (IPackageFragmentRoot) packge.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
+
+ // Provide hint why there's no Java doc
+ try {
+ base = getInfoTextForNoJavadoc(reader, packge, root, root.getKind() == IPackageFragmentRoot.K_BINARY);
+ } catch (JavaModelException e) {
+ reader = new StringReader(JavaHoverMessages.JavadocHover_error_gettingJavadoc);
+ JavaPlugin.log(e);
+ }
+
+
+ if (reader != null) {
+ HTMLPrinter.addParagraph(buffer, reader);
+ }
+ hasContents = true;
+ }else if (element instanceof IMember) {
HTMLPrinter.addSmallHeader(buffer, getInfoText(element, editorInputElement, hoverRegion, true));
buffer.append("<br>"); //$NON-NLS-1$
addAnnotations(buffer, element, editorInputElement, hoverRegion);
IMember member= (IMember) element;
Reader reader;
try {
-// reader= JavadocContentAccess.getHTMLContentReader(member, true, true);
+ IPackageFragmentRoot root = (IPackageFragmentRoot) member.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
String content= JavadocContentAccess2.getHTMLContent(member, true);
reader= content == null ? null : new StringReader(content);
-
- // Provide hint why there's no Javadoc
- if (reader == null && member.isBinary()) {
- boolean hasAttachedJavadoc= JavaDocLocations.getJavadocBaseLocation(member) != null;
- IPackageFragmentRoot root= (IPackageFragmentRoot)member.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
- boolean hasAttachedSource= root != null && root.getSourceAttachmentPath() != null;
- IOpenable openable= member.getOpenable();
- boolean hasSource= openable.getBuffer() != null;
-
- if (!hasAttachedSource && !hasAttachedJavadoc)
- reader= new StringReader(JavaHoverMessages.JavadocHover_noAttachments);
- else if (!hasAttachedJavadoc && !hasSource)
- reader= new StringReader(JavaHoverMessages.JavadocHover_noAttachedJavadoc);
- else if (!hasAttachedSource)
- reader= new StringReader(JavaHoverMessages.JavadocHover_noAttachedSource);
- else if (!hasSource)
- reader= new StringReader(JavaHoverMessages.JavadocHover_noInformation);
-
- } else {
- base= JavaDocLocations.getBaseURL(member);
- }
-
+ // Provide hint why there's no Java doc
+ base= getInfoTextForNoJavadoc(reader, member, root, member.isBinary());
} catch (JavaModelException ex) {
reader= new StringReader(JavaHoverMessages.JavadocHover_error_gettingJavadoc);
JavaPlugin.log(ex);
@@ -674,6 +677,30 @@ public class JavadocHover extends AbstractJavaEditorTextHover {
return null;
}
+ private static String getInfoTextForNoJavadoc(Reader reader, IJavaElement element, IPackageFragmentRoot root, boolean isBinary) throws JavaModelException {
+ String baseURL= null;
+ if (reader == null && isBinary) {
+ boolean hasAttachedJavadoc= JavaDocLocations.getJavadocBaseLocation(element) != null;
+ boolean hasAttachedSource= root != null && root.getSourceAttachmentPath() != null;
+ IOpenable openable= element.getOpenable();
+ boolean hasSource= openable.getBuffer() != null;
+
+ if (!hasAttachedSource && !hasAttachedJavadoc)
+ reader= new StringReader(JavaHoverMessages.JavadocHover_noAttachments);
+ else if (!hasAttachedJavadoc && !hasSource)
+ reader= new StringReader(JavaHoverMessages.JavadocHover_noAttachedJavadoc);
+ else if (!hasAttachedSource)
+ reader= new StringReader(JavaHoverMessages.JavadocHover_noAttachedSource);
+ else if (!hasSource)
+ reader= new StringReader(JavaHoverMessages.JavadocHover_noInformation);
+
+ } else {
+ baseURL= JavaDocLocations.getBaseURL(element, isBinary);
+ }
+
+ return baseURL;
+ }
+
private static String getInfoText(IJavaElement element, ITypeRoot editorInputElement, IRegion hoverRegion, boolean allowImage) {
long flags= getHeaderFlags(element);
StringBuffer label= new StringBuffer(JavaElementLinks.getElementLabel(element, flags));
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/javadoc/JavaDocMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/javadoc/JavaDocMessages.java
index 47d4f32..6aa0c17 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/javadoc/JavaDocMessages.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/javadoc/JavaDocMessages.java
@@ -35,6 +35,10 @@ final class JavaDocMessages extends NLS {
public static String JavaDoc2HTMLTextReader_specified_by_section;
public static String JavaDoc2HTMLTextReader_version_section;
+ public static String JavadocContentAccess2_PACKAGE_HTML;
+ public static String JavadocContentAccess2_PACKAGE_INFO_CLASS;
+ public static String JavadocContentAccess2_PACKAGE_INFO_JAVA;
+
static {
NLS.initializeMessages(BUNDLE_NAME, JavaDocMessages.class);
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/javadoc/JavaDocMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/javadoc/JavaDocMessages.properties
index e957e8e..3c91bf9 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/javadoc/JavaDocMessages.properties
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/javadoc/JavaDocMessages.properties
@@ -20,3 +20,6 @@ JavaDoc2HTMLTextReader_see_section=See Also:
JavaDoc2HTMLTextReader_since_section=Since:
JavaDoc2HTMLTextReader_specified_by_section=Specified by:
JavaDoc2HTMLTextReader_version_section=Version:
+JavadocContentAccess2_PACKAGE_HTML=package.html
+JavadocContentAccess2_PACKAGE_INFO_CLASS=package-info.class
+JavadocContentAccess2_PACKAGE_INFO_JAVA=package-info.java
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/javadoc/JavadocContentAccess2.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/javadoc/JavadocContentAccess2.java
index 45d7273..13b2338 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/javadoc/JavadocContentAccess2.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/javadoc/JavadocContentAccess2.java
@@ -11,8 +11,12 @@
*******************************************************************************/
package org.eclipse.jdt.internal.ui.text.javadoc;
+import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.Reader;
+import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.net.URL;
import java.text.MessageFormat;
@@ -23,18 +27,36 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.filebuffers.ITextFileBufferManager;
+import org.eclipse.core.filebuffers.LocationKind;
import org.eclipse.jface.internal.text.html.HTMLPrinter;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+
import org.eclipse.jdt.core.IBuffer;
+import org.eclipse.jdt.core.IClassFile;
+import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJarEntryResource;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
@@ -576,11 +598,22 @@ public class JavadocContentAccess2 {
return javadoc2HTML(member, rawJavadoc);
}
- private static Javadoc getJavadocNode(IMember member, String rawJavadoc) {
+ private static Javadoc getJavadocNode(IJavaElement member, String rawJavadoc) {
//FIXME: take from SharedASTProvider if available
//Caveat: Javadoc nodes are not available when Javadoc processing has been disabled!
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=212207
+ CompilationUnit root= createAST(member, rawJavadoc);
+ if (root == null)
+ return null;
+ List<AbstractTypeDeclaration> types= root.types();
+ if (types.size() != 1)
+ return null;
+ AbstractTypeDeclaration type= types.get(0);
+ return type.getJavadoc();
+ }
+
+ private static CompilationUnit createAST(IJavaElement member, String rawJavadoc) {
ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
IJavaProject javaProject= member.getJavaProject();
@@ -593,13 +626,7 @@ public class JavadocContentAccess2 {
parser.setSource(source.toCharArray());
CompilationUnit root= (CompilationUnit) parser.createAST(null);
- if (root == null)
- return null;
- List<AbstractTypeDeclaration> types= root.types();
- if (types.size() != 1)
- return null;
- AbstractTypeDeclaration type= types.get(0);
- return type.getJavadoc();
+ return root;
}
private static String javadoc2HTML(IMember member, String rawJavadoc) {
@@ -1597,4 +1624,180 @@ public class JavadocContentAccess2 {
return true;
}
+ /**
+ * Java doc for a package can be found in package.html or package-info.java file. Depending on
+ * the availability of the document pick the correct content
+ *
+ * @param packageFragment - The package which is requesting for the document
+ * @return - the document content in HTML formal
+ */
+ public static String getPackageDocumentation(IPackageFragment packageFragment) {
+
+ String contents= null;
+ IJavaElement javaElement= null;
+ CompilationUnit astNode= null;
+ IPackageFragmentRoot root= (IPackageFragmentRoot) packageFragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
+
+ try {
+
+// 1==> Handle the case when the documentation is present in package-info.java or package-info.class file
+ if (root.getKind() == IPackageFragmentRoot.K_BINARY) {
+ javaElement= packageFragment.getClassFile(JavaDocMessages.JavadocContentAccess2_PACKAGE_INFO_CLASS);
+ } else if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
+ javaElement= packageFragment.getCompilationUnit(JavaDocMessages.JavadocContentAccess2_PACKAGE_INFO_JAVA);
+ }
+
+ if (javaElement != null && javaElement.exists()) {
+ astNode= parse(javaElement);
+ if (astNode != null) {
+ List<?> commentList= astNode.getCommentList();
+ if (commentList != null && !commentList.isEmpty()) {
+ Javadoc javadoc= getJavadocNode(javaElement, commentList.toString());
+ JavadocContentAccess2 docacc= new JavadocContentAccess2(null, javadoc, commentList.toString());
+ contents= docacc.toHTML();
+ }
+ }
+ }
+ // 2==> Handle the case when the documentation is done in package.html file. The file can be either in normal source folder or coming from a jar file
+ else {
+ Object[] nonJavaResources= packageFragment.getNonJavaResources();
+ if (root.getKind() == IPackageFragmentRoot.K_BINARY) {
+ for (Object object : nonJavaResources) {
+ if (object instanceof IJarEntryResource && ((IJarEntryResource) object).isFile()
+ && ((IJarEntryResource) object).getName().endsWith(JavaDocMessages.JavadocContentAccess2_PACKAGE_HTML)) {
+ InputStream in;
+ try {
+ in= ((IJarEntryResource) object).getContents();
+ contents= getContentsFromInputStream(in);
+ break;
+ } catch (CoreException e) {
+ JavaPlugin.log(e.getStatus());
+ }
+ }
+ }
+ //if content is null then it means the package.html file is not part of the binary jar and it could be retrieved from the source jar
+ if (contents == null) {
+ IPath sourceAttachmentPath= root.getSourceAttachmentPath();
+// IPath sourceAttachmentRootPath= root.getSourceAttachmentRootPath(); TODO : not sure the implication of this one
+ if (sourceAttachmentPath != null) {
+ try {
+ ZipFile zipFile= new ZipFile(sourceAttachmentPath.toFile(), ZipFile.OPEN_READ);
+ String elementName= packageFragment.getElementName();
+ String packagePath= elementName.replace(".", "/") + "/" + JavaDocMessages.JavadocContentAccess2_PACKAGE_HTML; //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
+
+ ZipEntry packageHtml= zipFile.getEntry(packagePath);
+ if (packageHtml != null) {
+ InputStream in= zipFile.getInputStream(packageHtml);
+ contents= getContentsFromInputStream(in);
+ }
+
+ } catch (IOException e) {
+ JavaPlugin.log(e.getCause());
+ }
+
+ }
+ }
+ } else {
+ for (Object nonJavaResource : nonJavaResources) {
+ if (nonJavaResource instanceof IFile && ((IResource) nonJavaResource).exists()
+ && ((IFile) nonJavaResource).getName().endsWith(JavaDocMessages.JavadocContentAccess2_PACKAGE_HTML)) {
+ contents= getIFileContent((IFile) nonJavaResource);
+ break;
+ }
+ }
+ }
+ }
+
+
+ //3==> Handle the case when the documentation is coming from AttachedJavaDoc
+ if (contents == null && (root.isArchive() || root.isExternal())) {
+ contents= packageFragment.getAttachedJavadoc(null);
+ }
+
+
+ } catch (JavaModelException e) {
+ JavaPlugin.log(e.getStatus());
+ }
+
+ return contents;
+ }
+
+ private static String getContentsFromInputStream(InputStream in) {
+ final int DEFAULT_FILE_SIZE= 15 * 1024;
+ StringBuffer buffer= new StringBuffer(DEFAULT_FILE_SIZE);
+
+ try {
+ Reader reader= new BufferedReader(new InputStreamReader(in, ResourcesPlugin.getEncoding()), DEFAULT_FILE_SIZE);
+
+ char[] readBuffer= new char[2048];
+ int n;
+ n= reader.read(readBuffer);
+
+ while (n > 0) {
+ buffer.append(readBuffer, 0, n);
+ n= reader.read(readBuffer);
+ }
+ } catch (UnsupportedEncodingException e) {
+ JavaPlugin.log(e.getCause());
+ } catch (IOException e) {
+ JavaPlugin.log(e.getCause());
+ }
+ return buffer.toString();
+ }
+
+
+ /**
+ * * Reads a ICompilationUnit and creates the AST DOM for manipulating the Java source file
+ *
+ * @param javaElement - The compilation unit
+ * @return parsed compilation unit
+ */
+
+ private static CompilationUnit parse(IJavaElement javaElement) {
+ ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
+ IJavaProject javaProject= javaElement.getJavaProject();
+ parser.setProject(javaProject);
+ Map<String, String> options= javaProject.getOptions(true);
+ options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
+ parser.setCompilerOptions(options);
+ parser.setKind(ASTParser.K_COMPILATION_UNIT);
+ if (javaElement instanceof ICompilationUnit) {
+ parser.setSource((ICompilationUnit) javaElement);
+ } else if (javaElement instanceof IClassFile) {
+ parser.setSource((IClassFile) javaElement);
+ }
+ parser.setResolveBindings(true);
+ return (CompilationUnit) parser.createAST(null);
+
+ }
+
+ /**
+ * Read the content of the IFile
+ *
+ * @param resource The resource whose content has to be read
+ * @return the content of the file
+ */
+ private static String getIFileContent(IFile resource) {
+ String content= null;
+ ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
+ try {
+ manager.connect(resource.getFullPath(), LocationKind.NORMALIZE, null);
+ try {
+ ITextFileBuffer buffer= manager.getTextFileBuffer(resource.getFullPath(), LocationKind.NORMALIZE);
+ IDocument document= buffer.getDocument();
+ if (document != null) {
+ content= document.get(0, document.getLength());
+
+ }
+ } finally {
+ manager.disconnect(resource.getFullPath(), LocationKind.NORMALIZE, null);
+ }
+ } catch (CoreException e) {
+ JavaPlugin.log(e.getStatus());
+ } catch (BadLocationException e) {
+ JavaPlugin.log(e);
+ }
+ return content;
+ }
+
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/JavaElementLabelComposer.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/JavaElementLabelComposer.java
index b6e68eb..f915f98 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/JavaElementLabelComposer.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/JavaElementLabelComposer.java
@@ -291,7 +291,7 @@ public class JavaElementLabelComposer {
appendCompilationUnitLabel((ICompilationUnit) element, flags);
break;
case IJavaElement.PACKAGE_FRAGMENT:
- appendPackageFragmentLabel((IPackageFragment) element, flags);
+ appendPackageFragmentLabel((IPackageFragment) element, flags & QUALIFIER_FLAGS);
break;
case IJavaElement.PACKAGE_FRAGMENT_ROOT:
appendPackageFragmentRootLabel((IPackageFragmentRoot) element, flags);