| author | Manju Mathew | 2012-12-05 07:44:17 (EST) |
|---|---|---|
| committer | Dani Megert | 2012-12-05 07:44:17 (EST) |
| commit | 76f75e1a1282097d3de3fa1446dd7f7756c1dca5 (patch) (side-by-side diff) | |
| tree | 68176f56424990e5945bcfb4381051f36fb21d3a | |
| parent | 0ca71554e07b36bd8666dfc5e988cb0b05f52686 (diff) | |
| download | eclipse.jdt.ui-76f75e1a1282097d3de3fa1446dd7f7756c1dca5.zip eclipse.jdt.ui-76f75e1a1282097d3de3fa1446dd7f7756c1dca5.tar.gz eclipse.jdt.ui-76f75e1a1282097d3de3fa1446dd7f7756c1dca5.tar.bz2 | |
Patch 4 for review
16 files changed, 264 insertions, 279 deletions
diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/CorextMessages.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/CorextMessages.java index d884318..9e74475 100644 --- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/CorextMessages.java +++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/CorextMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -26,9 +26,13 @@ public final class CorextMessages extends NLS { public static String Resources_fileModified; public static String JavaDocLocations_migrate_operation; + public static String JavaDocLocations_error_gettingJavadoc; public static String JavaDocLocations_error_readXML; public static String JavaDocLocations_migratejob_name; - + public static String JavaDocLocations_noAttachedJavadoc; + public static String JavaDocLocations_noAttachedSource; + public static String JavaDocLocations_noAttachments; + public static String JavaDocLocations_noInformation; public static String History_error_serialize; public static String History_error_read; public static String TypeInfoHistory_consistency_check; diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/CorextMessages.properties b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/CorextMessages.properties index 084c316..7801e94 100644 --- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/CorextMessages.properties +++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/CorextMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2009 IBM Corporation and others. +# Copyright (c) 2000, 2012 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -14,8 +14,13 @@ Resources_modifiedResources= There are modified resources Resources_fileModified= File ''{0}'' has been modified since the beginning of the operation JavaDocLocations_migrate_operation=Migrate Javadoc locations to build path attributes... +JavaDocLocations_error_gettingJavadoc=<em>Note: An exception occurred while getting the Javadoc. See log for details.</em> JavaDocLocations_error_readXML=Problems while reading the Javadoc locations from XML JavaDocLocations_migratejob_name=Migrate Javadoc locations to build path attributes +JavaDocLocations_noAttachedJavadoc=<em>Note: This element has no attached Javadoc and the Javadoc could not be found in the attached source.</em> +JavaDocLocations_noAttachedSource=<em>Note: This element has no attached source and the Javadoc could not be found in the attached Javadoc.</em> +JavaDocLocations_noAttachments=<em>Note: This element neither has attached source nor attached Javadoc and hence no Javadoc could be found.</em> +JavaDocLocations_noInformation=<em>Note: The Javadoc for this element could neither be found in the attached source nor the attached Javadoc.</em> JavaModelUtil_applyedit_operation=Applying changes History_error_serialize= Problems serializing information to XML ''{0}'' diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/ImportReferencesCollector.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/ImportReferencesCollector.java index fe5a65b..63fe565 100644 --- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/ImportReferencesCollector.java +++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/ImportReferencesCollector.java @@ -86,7 +86,7 @@ public class ImportReferencesCollector extends GenericVisitor { private static boolean processJavadocComments(CompilationUnit astRoot) { // don't visit Javadoc for 'package-info' (bug 216432) if (astRoot != null && astRoot.getTypeRoot() != null) { - return !"package-info.java".equals(astRoot.getTypeRoot().getElementName()); //$NON-NLS-1$ + return !JavaModelUtil.PACKAGE_INFO_JAVA.equals(astRoot.getTypeRoot().getElementName()); } return true; } 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 66f0ea4..4a68993 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 @@ -70,6 +70,7 @@ 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.IOpenable; import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IPackageFragmentRoot; import org.eclipse.jdt.core.IType; @@ -590,12 +591,12 @@ public class JavaDocLocations { } /** - * Fetch the location of the javadoc. - * - * @param element an object of type JavaElement. - * @param isBinary true if the JavaElement is from a a Binary container. - * @return the location URL of the Javadoc or <code>null</code> if the location cannot be - * retrieved. + * Fetch the location of the Javadoc. + * + * @param element an object of type JavaElement + * @param isBinary <code>true</code> if the JavaElement is from a a Binary container + * @return the location URL of the Javadoc or <code>null</code> if the location can not be + * retrieved * @throws JavaModelException thrown when the element can not be accessed * @since 3.9 */ @@ -633,6 +634,43 @@ public class JavaDocLocations { } /** + * Give an explanation as to why the Javadoc of the element could not be retrieved. + * + * @param element an object of type Java Element + * @param root the root of the java element, can be <code>null</code> + * @param isBinary <code>true</code> if the element is coming from a binary container + * @return the reader object with the explanation for why the Javadoc for the element could not + * be fetched + * @since 3.9 + */ + public static Reader getExplanationForMissingJavadoc(IJavaElement element, IPackageFragmentRoot root, boolean isBinary) { + Reader reader= null; + try { + if (isBinary) { + boolean hasAttachedJavadoc= JavaDocLocations.getJavadocBaseLocation(element) != null; + boolean hasAttachedSource= root != null && root.getSourceAttachmentPath() != null; + IOpenable openable= element.getOpenable(); + boolean hasSource= openable.getBuffer() != null; + + // Provide hint why there's no Java doc + if (!hasAttachedSource && !hasAttachedJavadoc) + reader= new StringReader(CorextMessages.JavaDocLocations_noAttachments); + else if (!hasAttachedJavadoc && !hasSource) + reader= new StringReader(CorextMessages.JavaDocLocations_noAttachedJavadoc); + else if (!hasAttachedSource) + reader= new StringReader(CorextMessages.JavaDocLocations_noAttachedSource); + else if (!hasSource) + reader= new StringReader(CorextMessages.JavaDocLocations_noInformation); + + } + } catch (JavaModelException e) { + reader= new StringReader(CorextMessages.JavaDocLocations_error_gettingJavadoc); + JavaPlugin.log(e); + } + return reader; + } + + /** * Parse a URL from a String. This method first tries to treat <code>url</code> as a valid, encoded URL. * If that didn't work, it tries to recover from bad URLs, e.g. the unencoded form we used to use in persistent storage. * diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java index 4957b34..6399e3e 100644 --- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java +++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java @@ -95,14 +95,12 @@ public final class JavaModelUtil { /** * The name of the package-info.class file. - * * @since 3.9 */ public static final String PACKAGE_INFO_CLASS= "package-info.class"; //$NON-NLS-1$ /** * The name of the package.html file. - * * @since 3.9 */ public static final String PACKAGE_HTML= "package.html"; //$NON-NLS-1$ diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/InfoViewMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/InfoViewMessages.java index fa96bd2..d77313e 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/InfoViewMessages.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/InfoViewMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -35,7 +35,7 @@ final class InfoViewMessages extends NLS { public static String GotoInputAction_label; public static String GotoInputAction_tooltip; public static String GotoInputAction_description; - + public static String OpenInBrowserAction_url_label; public static String OpenInBrowserAction_url_toolTip; @@ -53,10 +53,6 @@ final class InfoViewMessages extends NLS { public static String JavadocView_error_noBrowser_title; public static String JavadocView_error_noBrowser_message; public static String JavadocView_error_noBrowser_doNotWarn; - public static String JavadocView_noAttachments; - public static String JavadocView_noAttachedSource; - public static String JavadocView_noAttachedJavadoc; - public static String JavadocView_noInformation; public static String JavadocView_error_gettingJavadoc; public static String JavadocView_constantValue_hexValue; diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/InfoViewMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/InfoViewMessages.properties index 6d7b5c7..11f492d 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/InfoViewMessages.properties +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/InfoViewMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2009 IBM Corporation and others. +# Copyright (c) 2000, 2012 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -39,10 +39,6 @@ JavadocView_action_toogleLinking_text=Link with Selection JavadocView_error_noBrowser_title= Javadoc view JavadocView_error_noBrowser_message= The HTML Browser widget could not be created. The standard text widget will be used instead. JavadocView_error_noBrowser_doNotWarn= Do not show this message again. -JavadocView_noAttachments= <em>Note: This element neither has attached source nor attached Javadoc and hence no Javadoc could be found.</em> -JavadocView_noAttachedSource= <em>Note: This element has no attached source and the Javadoc could not be found in the attached Javadoc.</em> -JavadocView_noAttachedJavadoc= <em>Note: This element has no attached Javadoc and the Javadoc could not be found in the attached source.</em> -JavadocView_noInformation= <em>Note: The Javadoc for this element could neither be found in the attached source nor the attached Javadoc.</em> JavadocView_error_gettingJavadoc= <em>Note: An exception occurred while getting the Javadoc. See log for details.</em> # The first parameter is the constant value string and the second is its hex representation JavadocView_constantValue_hexValue= {0} [{1}] 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 11e606f..7132181 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 @@ -113,7 +113,6 @@ import org.eclipse.jdt.core.IJavaElement; 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.IPackageDeclaration; import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IPackageFragmentRoot; @@ -476,8 +475,7 @@ public class JavadocView extends AbstractInfoView { private LinkAction fToggleLinkAction; /** - * Action to open the attached Javadoc. - * + * Action to open the attached Javadoc. * @since 3.4 */ private OpenInBrowserAction fOpenBrowserAction; @@ -1069,7 +1067,7 @@ public class JavadocView extends AbstractInfoView { } /** - * Returns the Javadoc in HTML format. + * Returns the Javadoc of the Java Element in HTML format. * * @param result the Java elements for which to get the Javadoc * @param activePart the active part if any @@ -1108,11 +1106,13 @@ public class JavadocView extends AbstractInfoView { } else if (curr instanceof IPackageFragment) { content= JavadocContentAccess2.getHTMLContent((IPackageFragment) curr); } - reader= content == null ? null : new StringReader(content); IPackageFragmentRoot root= (IPackageFragmentRoot) curr.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); - try { - base= getBaseURL(reader, curr, root, root.getKind() == IPackageFragmentRoot.K_BINARY); + boolean isBinary= root.getKind() == IPackageFragmentRoot.K_BINARY; + reader= (content == null ? JavaDocLocations.getExplanationForMissingJavadoc(curr, root, isBinary) : new StringReader(content)); + if (content != null) { + base= JavaDocLocations.getBaseURL(curr, isBinary); + } } catch (JavaModelException e) { reader= new StringReader(InfoViewMessages.JavadocView_error_gettingJavadoc); JavaPlugin.log(e); @@ -1149,10 +1149,12 @@ public class JavadocView extends AbstractInfoView { Reader reader; try { String content= JavadocContentAccess2.getHTMLContent(member, true); - reader= content == null ? null : new StringReader(content); - IPackageFragmentRoot root= (IPackageFragmentRoot) member.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); - base= getBaseURL(reader, member, root, member.isBinary()); + boolean isBinary= member.isBinary(); + reader= (content == null ? JavaDocLocations.getExplanationForMissingJavadoc(member, root, isBinary) : new StringReader(content)); + if (content != null) { + base= JavaDocLocations.getBaseURL(member, isBinary); + } } catch (JavaModelException ex) { reader= new StringReader(InfoViewMessages.JavadocView_error_gettingJavadoc); JavaPlugin.log(ex.getStatus()); @@ -1186,53 +1188,15 @@ public class JavadocView extends AbstractInfoView { } /** - * The reader will store the reason for why there is no valid java doc associated with the - * selected IJavaElement and also return the location URL where the Javadoc is present or - * <code>null</code> if no location is specified. - * - * @param reader the StringReader or <code>null</code> - * @param element an object of type IJavaElement - * @param root the IPackageFragmentRoot of the java element or <code>null</code> - * @param isBinary is true if the content is coming from a jar - * @return baseURL of the JavaDoc, <code>null</code> if there is no associated javadoc - * @throws JavaModelException if this element does not exist or if an exception occurs while - * accessing its corresponding resource. - * @since 3.9 - */ - private static String getBaseURL(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; - - // Provide hint why there's no Java doc - 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 * @param constantValue the constant value if any - * @param allowImage true if the java element image should be shown + * @param allowImage <code>true</code> if the java element image should be shown * @return a string containing the member's label */ private String getInfoText(IJavaElement member, String constantValue, boolean allowImage) { - StringBuffer label= new StringBuffer(JavaElementLinks.getElementLabel(member, getHeaderFlag(member))); + StringBuffer label= new StringBuffer(JavaElementLinks.getElementLabel(member, getHeaderFlags(member))); if (member.getElementType() == IJavaElement.FIELD && constantValue != null) { label.append(constantValue); } @@ -1251,11 +1215,11 @@ public class JavadocView extends AbstractInfoView { } - private long getHeaderFlag(IJavaElement element) { + private long getHeaderFlags(IJavaElement element) { switch (element.getElementType()) { case IJavaElement.PACKAGE_FRAGMENT: case IJavaElement.PACKAGE_DECLARATION: - return JavaElementLabels.P_COMPRESSED; + return LABEL_FLAGS ^ JavaElementLabels.ALL_FULLY_QUALIFIED; default: return LABEL_FLAGS; } @@ -1306,16 +1270,18 @@ public class JavadocView extends AbstractInfoView { try { element= super.findSelectedJavaElement(part, selection); - //update the javadoc view when package.html is selected in project explorer view + //update the Javadoc view when package.html is selected in project explorer view if (element == null && selection instanceof IStructuredSelection) { Object selectedElement= ((IStructuredSelection) selection).getFirstElement(); - if (selectedElement instanceof IFile && ((IFile) selectedElement).getName().endsWith(JavaModelUtil.PACKAGE_HTML)) { - IContainer parent= ((IFile) selectedElement).getParent(); - element= (IJavaElement) ((IAdaptable) parent).getAdapter(IJavaElement.class); + if (selectedElement instanceof IFile) { + IFile selectedFile= (IFile) selectedElement; + if (selectedFile.getName().equals(JavaModelUtil.PACKAGE_HTML)) { + IContainer parent= selectedFile.getParent(); + element= (IJavaElement) ((IAdaptable) parent).getAdapter(IJavaElement.class); + } } } - //update the javadoc view when the content of the package.* is modified in the editor if (element == null && selection instanceof ITextSelection) { ITextSelection textSelection= (ITextSelection) selection; if (part instanceof AbstractDecoratedTextEditor) { @@ -1332,8 +1298,11 @@ public class JavadocView extends AbstractInfoView { } else if (editorInput instanceof IFileEditorInput) { IFile file= ((IFileEditorInput) editorInput).getFile(); - IContainer parent= file.getParent(); - element= (IJavaElement) ((IAdaptable) parent).getAdapter(IJavaElement.class); + //update the Javadoc view when the content of the package.html is modified in the editor + if (file.getName().equals(JavaModelUtil.PACKAGE_HTML)) { + IContainer parent= file.getParent(); + element= (IJavaElement) ((IAdaptable) parent).getAdapter(IJavaElement.class); + } } } } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/LazyPackageCompletionProposal.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/LazyPackageCompletionProposal.java index aa9f3e0..f90e054 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/LazyPackageCompletionProposal.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/LazyPackageCompletionProposal.java @@ -14,7 +14,6 @@ package org.eclipse.jdt.internal.ui.text.java; import org.eclipse.jdt.core.CompletionProposal; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.Signature; import org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext; @@ -24,7 +23,6 @@ public class LazyPackageCompletionProposal extends LazyJavaCompletionProposal { public LazyPackageCompletionProposal(CompletionProposal proposal, JavaContentAssistInvocationContext context) { super(proposal, context); - proposal.setSignature(Signature.createCharArrayTypeSignature(getDisplayString().toCharArray(), true)); fCompilationUnit= context.getCompilationUnit(); } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/PackageProposalInfo.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/PackageProposalInfo.java index 7b24d1a..cc96f62 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/PackageProposalInfo.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/PackageProposalInfo.java @@ -20,8 +20,6 @@ import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.internal.corext.template.java.SignatureUtil; - public class PackageProposalInfo extends ProposalInfo { private boolean fJavaElementResolved= false; @@ -49,14 +47,17 @@ public class PackageProposalInfo extends ProposalInfo { /** * Resolve to a PackageFragment. * - * @return the <code>IPackageFragment</code> or <code>null</code> if no element can be found. - * @throws JavaModelException thrown if the path to the element is null or absolute. + * @return the <code>IPackageFragment</code> or <code>null</code> if no element can be found + * @throws JavaModelException thrown if the path to the element is null or absolute * @since 3.9 */ private IJavaElement resolvePackage() throws JavaModelException { - char[] signature= fProposal.getSignature(); - String typeName= SignatureUtil.stripSignatureToFQN(String.valueOf(signature)); - typeName= typeName.replace(".*", "").replace('.', IPath.SEPARATOR); //$NON-NLS-1$ //$NON-NLS-2$ - return fJavaProject.findElement(new Path(typeName)); + char[] signature= fProposal.getDeclarationSignature(); + if (signature != null) { + String typeName= String.valueOf(signature); + typeName= typeName.replace('.', IPath.SEPARATOR); + return fJavaProject.findElement(new Path(typeName)); + } + return null; } } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ProposalInfo.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ProposalInfo.java index b6afb9d..0199aad 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ProposalInfo.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ProposalInfo.java @@ -80,13 +80,13 @@ public class ProposalInfo { } /** - * Extracts the javadoc for the given <code>IJavaElement</code> and returns it + * Extracts the Javadoc for the given <code>IJavaElement</code> and returns it * as HTML. * - * @param element the IJavaElement to get the documentation for - * @return the javadoc for <code>member</code> or <code>null</code> if + * @param element the JavaElement to get the documentation for + * @return the Javadoc for Java Element or <code>null</code> if * it is not available - * @throws JavaModelException if accessing the javadoc fails + * @throws JavaModelException if accessing the Javadoc fails */ private String extractJavadoc(IJavaElement element) throws JavaModelException { if (element instanceof IMember) { diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.java index 49cf608..c118849 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.java @@ -31,10 +31,6 @@ final class JavaHoverMessages extends NLS { public static String JavadocHover_back; public static String JavadocHover_back_toElement_toolTip; - public static String JavadocHover_noAttachments; - public static String JavadocHover_noAttachedJavadoc; - public static String JavadocHover_noAttachedSource; - public static String JavadocHover_noInformation; public static String JavadocHover_constantValue_hexValue; public static String JavadocHover_error_gettingJavadoc; public static String JavadocHover_forward; diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.properties index e73ed43..606c21f 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.properties +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.properties @@ -23,10 +23,6 @@ NLSStringHover_NLSStringHover_PropertiesFileCouldNotBeReadWarning=<b>Warning:</b NLSStringHover_open_in_properties_file=Open in Properties File JavadocHover_back= Back JavadocHover_back_toElement_toolTip=Back to {0} -JavadocHover_noAttachments= <em>Note: This element neither has attached source nor attached Javadoc and hence no Javadoc could be found.</em> -JavadocHover_noAttachedSource= <em>Note: This element has no attached source and the Javadoc could not be found in the attached Javadoc.</em> -JavadocHover_noAttachedJavadoc= <em>Note: This element has no attached Javadoc and the Javadoc could not be found in the attached source.</em> -JavadocHover_noInformation= <em>Note: The Javadoc for this element could neither be found in the attached source nor the attached Javadoc.</em> # The first parameter is the constant value string and the second is its hex representation JavadocHover_constantValue_hexValue={0} [{1}] JavadocHover_error_gettingJavadoc= <em>Note: An exception occurred while getting the Javadoc. See log for details.</em> 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 cfb2ba9..f8381bd 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 @@ -61,7 +61,6 @@ import org.eclipse.jdt.core.IField; 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; @@ -577,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 */ - public static JavadocBrowserInformationControlInput getHoverInfo(IJavaElement[] elements, ITypeRoot editorInputElement, IRegion hoverRegion, JavadocBrowserInformationControlInput previousInput) { + private static JavadocBrowserInformationControlInput getHoverInfo(IJavaElement[] elements, ITypeRoot editorInputElement, IRegion hoverRegion, JavadocBrowserInformationControlInput previousInput) { int nResults= elements.length; StringBuffer buffer= new StringBuffer(); boolean hasContents= false; @@ -616,13 +615,16 @@ public class JavadocHover extends AbstractJavaEditorTextHover { IPackageFragment packge = (IPackageFragment)element; Reader reader; String content= JavadocContentAccess2.getHTMLContent(packge); - reader = content == null ? null : new StringReader(content); IPackageFragmentRoot root= (IPackageFragmentRoot) packge.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); - try { - base= getBaseURL(reader, packge, root, root.getKind() == IPackageFragmentRoot.K_BINARY); + boolean isBinary= root.getKind() == IPackageFragmentRoot.K_BINARY; + reader= (content == null ? JavaDocLocations.getExplanationForMissingJavadoc(element, root, isBinary) : new StringReader(content)); + + if (content != null) { + base= JavaDocLocations.getBaseURL(element, isBinary); + } } catch (JavaModelException e) { - reader = new StringReader(JavaHoverMessages.JavadocHover_error_gettingJavadoc); + reader= new StringReader(JavaHoverMessages.JavadocHover_error_gettingJavadoc); JavaPlugin.log(e); } @@ -630,18 +632,21 @@ public class JavadocHover extends AbstractJavaEditorTextHover { if (reader != null) { HTMLPrinter.addParagraph(buffer, reader); } - hasContents = true; - }else if (element instanceof IMember) { + 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 { - IPackageFragmentRoot root = (IPackageFragmentRoot) member.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); + IPackageFragmentRoot root= (IPackageFragmentRoot) member.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); String content= JavadocContentAccess2.getHTMLContent(member, true); - reader= content == null ? null : new StringReader(content); - base= getBaseURL(reader, member, root, member.isBinary()); + boolean isBinary= member.isBinary(); + reader= (content == null ? JavaDocLocations.getExplanationForMissingJavadoc(element, root, isBinary) : new StringReader(content)); + if (content != null) { + base= JavaDocLocations.getBaseURL(element, isBinary); + } } catch (JavaModelException ex) { reader= new StringReader(JavaHoverMessages.JavadocHover_error_gettingJavadoc); JavaPlugin.log(ex); @@ -676,43 +681,6 @@ public class JavadocHover extends AbstractJavaEditorTextHover { return null; } - /** - * Retrieve the URL for the Javadoc location or provide an hint why there is no javadoc. - * - * @param reader the StringReader or <code>null</code> - * @param element an object of type IJavaElement. - * @param root the PackageFragmentRoot of the element or <code>null</code> - * @param isBinary true if the element is from a binary container. - * @return the location URL or <code>null</code> if there is no javadoc associated with the - * element. - * @throws JavaModelException if this element does not exist or if an exception occurs while - * accessing its corresponding resource. - * @since 3.9 - */ - private static String getBaseURL(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; - - // Provide hint why there's no Java doc - 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) { @@ -758,7 +726,7 @@ public class JavadocHover extends AbstractJavaEditorTextHover { case IJavaElement.TYPE_PARAMETER: return TYPE_PARAMETER_FLAGS; case IJavaElement.PACKAGE_FRAGMENT: - return JavaElementLabels.P_COMPRESSED; + return LABEL_FLAGS ^ JavaElementLabels.ALL_FULLY_QUALIFIED; default: return LABEL_FLAGS; } 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 d728380..fa9a946 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 @@ -32,7 +32,6 @@ import java.util.zip.ZipFile; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; @@ -45,12 +44,10 @@ 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.ICodeAssist; +import org.eclipse.jdt.core.IClasspathAttribute; +import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.IJarEntryResource; @@ -62,9 +59,9 @@ import org.eclipse.jdt.core.IPackageDeclaration; import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IPackageFragmentRoot; import org.eclipse.jdt.core.ISourceRange; -import org.eclipse.jdt.core.ISourceReference; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.ITypeHierarchy; +import org.eclipse.jdt.core.ITypeRoot; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.Signature; @@ -72,6 +69,7 @@ import org.eclipse.jdt.core.SourceRange; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ASTParser; import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; +import org.eclipse.jdt.core.dom.Comment; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.IBinding; import org.eclipse.jdt.core.dom.IVariableBinding; @@ -602,12 +600,12 @@ public class JavadocContentAccess2 { return javadoc2HTML(member, rawJavadoc); } - private static Javadoc getJavadocNode(IJavaElement member, String rawJavadoc) { + private static Javadoc getJavadocNode(IJavaElement element, 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); + CompilationUnit root= createAST(element, rawJavadoc); if (root == null) return null; List<AbstractTypeDeclaration> types= root.types(); @@ -617,21 +615,6 @@ public class JavadocContentAccess2 { return type.getJavadoc(); } - private static CompilationUnit createAST(IJavaElement member, String rawJavadoc) { - ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL); - - IJavaProject javaProject= member.getJavaProject(); - parser.setProject(javaProject); - Map<String, String> options= javaProject.getOptions(true); - options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=212207 - parser.setCompilerOptions(options); - - String source= rawJavadoc + "class C{}"; //$NON-NLS-1$ - parser.setSource(source.toCharArray()); - - CompilationUnit root= (CompilationUnit) parser.createAST(null); - return root; - } private static String javadoc2HTML(IMember member, String rawJavadoc) { Javadoc javadoc= getJavadocNode(member, rawJavadoc); @@ -1629,44 +1612,28 @@ public class JavadocContentAccess2 { } /** - * When user select the package declaration in the outline view, the Javadoc View has to be - * updated with the corresponding package documentation. - * - * @param packageDeclaraion an element of type IPackageDeclaration. + * Retrieve the Javadoc for a PackageDeclaration. + * + * @param packageDeclaration an element of type IPackageDeclaration * @return Package documentation in HTML format or <code>null</code> if there is no associated - * javadoc. + * Javadoc * @since 3.9 */ - public static String getHTMLContent(IPackageDeclaration packageDeclaraion) { - String contents= null; - IJavaElement parent= packageDeclaraion.getParent(); - String packageName= packageDeclaraion.getElementName(); - - if (parent instanceof ISourceReference) { - try { - int offset= ((ISourceReference) parent).getSource().indexOf(packageName); - if (parent instanceof ICodeAssist) { - IJavaElement[] codeSelect= ((ICodeAssist) parent).codeSelect(offset, packageName.length()); - if (codeSelect != null && codeSelect[0] instanceof IPackageFragment) { - contents= getHTMLContent((IPackageFragment) codeSelect[0]); - } - } - } catch (JavaModelException e) { - JavaPlugin.log(e.getStatus()); - } + public static String getHTMLContent(IPackageDeclaration packageDeclaration) { + IJavaElement element= packageDeclaration.getAncestor(IJavaElement.PACKAGE_FRAGMENT); + if (element instanceof IPackageFragment) { + return getHTMLContent((IPackageFragment) element); } - - - return contents; + return null; } /** - * Java doc for a package can be found in package.html, package-info.java or from an attached javadoc. Depending on - * the availability of the document, pick the correct content. - * - * @param packageFragment the package which is requesting for the document. + * Javadoc for a package can be found in package.html, package-info.java or from an attached + * Javadoc. 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 format or <code>null</code> if there is no associated - * javadoc. + * Javadoc * @since 3.9 */ public static String getHTMLContent(IPackageFragment packageFragment) { @@ -1685,55 +1652,68 @@ public class JavadocContentAccess2 { javaElement= packageFragment.getCompilationUnit(JavaModelUtil.PACKAGE_INFO_JAVA); } - if (javaElement != null && javaElement.exists()) { - astNode= parse(javaElement); + if (javaElement != null && javaElement.exists() && javaElement instanceof ITypeRoot) { + String source= ((ITypeRoot) javaElement).getSource(); + //the source can be null for some of the class files + if (source != null) { + astNode= createAST(javaElement); if (astNode != null) { - List<?> commentList= astNode.getCommentList(); + List<Comment> 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(); + Comment comment= commentList.get(commentList.size() - 1); + if (comment instanceof Javadoc) { + JavadocContentAccess2 docacc= new JavadocContentAccess2(null, (Javadoc) comment, source); + 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) { - try { - //if the content is from an external class folder - if (object instanceof IJarEntryResource && ((IJarEntryResource) object).isFile() - && ((IJarEntryResource) object).getName().endsWith(JavaModelUtil.PACKAGE_HTML)) { - InputStream in= ((IJarEntryResource) object).getContents(); - contents= getContentsFromInputStream(in); - break; + try { + Object[] nonJavaResources= packageFragment.getNonJavaResources(); + if (root.getKind() == IPackageFragmentRoot.K_BINARY) { + for (Object object : nonJavaResources) { + try { + //if the content is from an external class folder + if (object instanceof IJarEntryResource && ((IJarEntryResource) object).isFile() + && ((IJarEntryResource) object).getName().equals(JavaModelUtil.PACKAGE_HTML)) { + InputStream in= ((IJarEntryResource) object).getContents(); + contents= getContentsFromInputStream(in, root); + break; + } + //if the content is in an internal class folder + else if (object instanceof IFile && ((IFile) object).getName().equals(JavaModelUtil.PACKAGE_HTML)) { + contents= getIFileContent((IFile) object); + break; + } + } catch (CoreException e) { + JavaPlugin.log(e.getStatus()); } - //if the content is in an internal class folder - else if (object instanceof IFile && ((IFile) object).getName().endsWith(JavaModelUtil.PACKAGE_HTML)) { - InputStream in= ((IFile) 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(".", "/") + "/" + JavaModelUtil.PACKAGE_HTML; //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ + //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(); + String elementName= packageFragment.getElementName(); + String packagePath= elementName.replace(".", "/") + "/" + JavaModelUtil.PACKAGE_HTML; //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ - ZipEntry packageHtml= zipFile.getEntry(packagePath); + try { + ZipFile zipFile= null; + ZipEntry packageHtml= null; + if (sourceAttachmentPath != null) { + zipFile= new ZipFile(sourceAttachmentPath.toFile(), ZipFile.OPEN_READ); + packageHtml= zipFile.getEntry(packagePath); + } + if (packageHtml == null && sourceAttachmentRootPath != null) { + zipFile= new ZipFile(sourceAttachmentRootPath.toFile(), ZipFile.OPEN_READ); + packageHtml= zipFile.getEntry(packagePath); + } if (packageHtml != null) { InputStream in= zipFile.getInputStream(packageHtml); - contents= getContentsFromInputStream(in); + contents= getContentsFromInputStream(in, root); } } catch (IOException e) { @@ -1741,22 +1721,26 @@ public class JavadocContentAccess2 { } } - } - } else { - for (Object nonJavaResource : nonJavaResources) { - if (nonJavaResource instanceof IFile && ((IResource) nonJavaResource).exists() - && ((IFile) nonJavaResource).getName().endsWith(JavaModelUtil.PACKAGE_HTML)) { - contents= getIFileContent((IFile) nonJavaResource); - break; + } else { + for (Object nonJavaResource : nonJavaResources) { + if (nonJavaResource instanceof IFile) { + IFile iFile= (IFile) nonJavaResource; + if (iFile.exists() && iFile.getName().equals(JavaModelUtil.PACKAGE_HTML)) { + contents= getIFileContent(iFile); + break; + } + } } } + } catch (JavaModelException e) { + JavaPlugin.log(e.getStatus()); } } //3==> Handle the case when the documentation is coming from AttachedJavaDoc if (contents == null && (root.isArchive() || root.isExternal())) { - contents= packageFragment.getAttachedJavadoc(new NullProgressMonitor()); + contents= packageFragment.getAttachedJavadoc(null); } @@ -1768,19 +1752,20 @@ public class JavadocContentAccess2 { } - private static String getContentsFromInputStream(InputStream in) { + private static String getContentsFromInputStream(InputStream in, IPackageFragmentRoot root) { 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); + String sourceAttachmentEncoding= getSourceAttachmentEncoding(root); + Reader reader= new BufferedReader(new InputStreamReader(in, sourceAttachmentEncoding), DEFAULT_FILE_SIZE); - char[] readBuffer= new char[2048]; + char[] readBuffer= new char[2048]; int charCount= reader.read(readBuffer); - while (charCount > 0) { - buffer.append(readBuffer, 0, charCount); - charCount= reader.read(readBuffer); + while (charCount > 0) { + buffer.append(readBuffer, 0, charCount); + charCount= reader.read(readBuffer); } } catch (UnsupportedEncodingException e) { JavaPlugin.log(e.getCause()); @@ -1791,20 +1776,40 @@ public class JavadocContentAccess2 { } + private static String getSourceAttachmentEncoding(IPackageFragmentRoot root) { + String encoding= ResourcesPlugin.getEncoding(); + IClasspathEntry entry; + try { + entry= root.getRawClasspathEntry(); + + if (entry != null) { + int kind= entry.getEntryKind(); + if (kind == IClasspathEntry.CPE_LIBRARY || kind == IClasspathEntry.CPE_VARIABLE) { + IClasspathAttribute[] extraAttributes= entry.getExtraAttributes(); + for (int i= 0; i < extraAttributes.length; i++) { + IClasspathAttribute attrib= extraAttributes[i]; + if (IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING.equals(attrib.getName())) { + encoding= attrib.getValue(); + break; + } + } + } + } + } catch (JavaModelException e) { + JavaPlugin.log(e.getStatus()); + } + return encoding; + } + /** * * Reads a ICompilationUnit and creates the AST DOM for manipulating the Java source file * - * @param javaElement an object of IJavaElement + * @param javaElement an object of JavaElement * @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); + private static CompilationUnit createAST(IJavaElement javaElement) { + ASTParser parser= initializeASTParser(javaElement); parser.setKind(ASTParser.K_COMPILATION_UNIT); if (javaElement instanceof ICompilationUnit) { parser.setSource((ICompilationUnit) javaElement); @@ -1816,31 +1821,46 @@ public class JavadocContentAccess2 { } + + private static CompilationUnit createAST(IJavaElement element, String rawJavadoc) { + ASTParser parser= initializeASTParser(element); + String source= rawJavadoc + "class C{}"; //$NON-NLS-1$ + parser.setSource(source.toCharArray()); + return (CompilationUnit) parser.createAST(null); + } + + private static ASTParser initializeASTParser(IJavaElement element) { + ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL); + IJavaProject javaProject= element.getJavaProject(); + parser.setProject(javaProject); + Map<String, String> options= javaProject.getOptions(true); + options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=212207 + parser.setCompilerOptions(options); + return parser; + } + /** - * Read the content of the IFile - * - * @param resource the IFile whose content has to be read + * Read the content of the IFile. + * + * @param file the IFile whose content has to be read * @return the content of the IFile */ - private static String getIFileContent(IFile resource) { + private static String getIFileContent(IFile file) { String content= null; ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager(); try { - manager.connect(resource.getFullPath(), LocationKind.NORMALIZE, null); + IPath fullPath= file.getFullPath(); + manager.connect(fullPath, LocationKind.IFILE, null); try { - ITextFileBuffer buffer= manager.getTextFileBuffer(resource.getFullPath(), LocationKind.NORMALIZE); - IDocument document= buffer.getDocument(); - if (document != null) { - content= document.get(0, document.getLength()); - + ITextFileBuffer buffer= manager.getTextFileBuffer(fullPath, LocationKind.IFILE); + if (buffer != null) { + content= buffer.getDocument().get(); } } finally { - manager.disconnect(resource.getFullPath(), LocationKind.NORMALIZE, null); + manager.disconnect(fullPath, LocationKind.IFILE, 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/ui/wizards/NewPackageWizardPage.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewPackageWizardPage.java index c74f410..537df59 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewPackageWizardPage.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewPackageWizardPage.java @@ -102,7 +102,7 @@ public class NewPackageWizardPage extends NewContainerWizardPage { private static final String PACKAGE_INFO_JAVA_FILENAME= JavaModelUtil.PACKAGE_INFO_JAVA; - private static final String PACKAGE_HTML_FILENAME= "package.html"; //$NON-NLS-1$ + private static final String PACKAGE_HTML_FILENAME= JavaModelUtil.PACKAGE_HTML; private static final String PAGE_NAME= "NewPackageWizardPage"; //$NON-NLS-1$ |

