Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 29674 Details for
Bug 110173
[plan] API to extract the Javadoc as HTML from attached HTML
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix
patch_110173.txt (text/plain), 29.06 KB, created by
Olivier Thomann
on 2005-11-09 21:41:21 EST
(
hide
)
Description:
Proposed fix
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2005-11-09 21:41:21 EST
Size:
29.06 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: codeassist/org/eclipse/jdt/internal/codeassist/InternalCompletionProposal.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/InternalCompletionProposal.java,v >retrieving revision 1.6 >diff -u -r1.6 InternalCompletionProposal.java >--- codeassist/org/eclipse/jdt/internal/codeassist/InternalCompletionProposal.java 22 Jun 2005 13:18:35 -0000 1.6 >+++ codeassist/org/eclipse/jdt/internal/codeassist/InternalCompletionProposal.java 10 Nov 2005 02:41:04 -0000 >@@ -96,12 +96,7 @@ > // TODO (david) shouldn't it be NameLookup.ACCEPT_ALL ? > type = this.nameLookup.findType(new String(tName), false, NameLookup.ACCEPT_CLASSES & NameLookup.ACCEPT_INTERFACES); > if(type instanceof BinaryType){ >- if(((BinaryType)type).getSourceMapper() != null) { >- this.completionEngine.typeCache.put(tName, type); >- } else { >- this.completionEngine.typeCache.put(tName, NO_ATTACHED_SOURCE); >- type = null; >- } >+ this.completionEngine.typeCache.put(tName, type); > } else { > type = null; > } >Index: model/org/eclipse/jdt/core/IJavaModelStatusConstants.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaModelStatusConstants.java,v >retrieving revision 1.33 >diff -u -r1.33 IJavaModelStatusConstants.java >--- model/org/eclipse/jdt/core/IJavaModelStatusConstants.java 23 Feb 2005 02:47:28 -0000 1.33 >+++ model/org/eclipse/jdt/core/IJavaModelStatusConstants.java 10 Nov 2005 02:41:04 -0000 >@@ -306,5 +306,18 @@ > * Status constant indicating that a compiler option is invalid. > * @since 3.1 > */ >-// public static final int INVALID_COMPILER_OPTION = 1007; >+// public static final int INVALID_COMPILER_OPTION = 1007; >+ /** >+ * <p>Status constant indicating that the attached javadoc content cannot be retrieved due to multiple reasons: >+ * invalid url, timed-out,...</p> >+ * >+ * @since 3.2 >+ */ >+ public static final int CANNOT_RETRIEVE_ATTACHED_JAVADOC = 1008; >+ /** >+ * <p>Status constant indicating that the attached javadoc content format is unrecognized.</p> >+ * >+ * @since 3.2 >+ */ >+ public static final int UNRECOGNIZED_JAVADOC_FORMAT = 1009; > } >Index: model/org/eclipse/jdt/core/IJavaElement.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaElement.java,v >retrieving revision 1.27 >diff -u -r1.27 IJavaElement.java >--- model/org/eclipse/jdt/core/IJavaElement.java 23 Feb 2005 02:47:28 -0000 1.27 >+++ model/org/eclipse/jdt/core/IJavaElement.java 10 Nov 2005 02:41:04 -0000 >@@ -13,6 +13,7 @@ > import org.eclipse.core.resources.IResource; > import org.eclipse.core.runtime.IAdaptable; > import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.jobs.ISchedulingRule; > > /** >@@ -157,6 +158,33 @@ > * @since 2.0 > */ > IJavaElement getAncestor(int ancestorType); >+ >+ /** >+ * <p>Returns the Javadoc as an html source if this element has an attached javadoc, >+ * null otherwise.</p> >+ * <p>This should be used only for binary elements. Source elements will always return null. >+ * The encoding used to read the javadoc is the one defined by the content type of the >+ * file. If none is defined, then the specified encoding will be used as the default encoding.</p> >+ * >+ * <p>The html is extracted from the attached javadoc and provided as is. No >+ * transformation or validation is done.</p> >+ * >+ * <p>If the default encoding is set to null, the platform encoding is used.</p> >+ * >+ * <p>NOTE: This API is subject to change before the 3.2 release.</p> >+ * >+ * @param monitor the given progress monitor >+ * @param encoding the given default encoding >+ * @exception JavaModelException if:<u> >+ * <li>this element does not exist</li> >+ * <li>retrieving the attached javadoc fails (timed-out, invalid URL, ...) >+ * <li>the format of the javadoc doesn't match expected standards (different anchors,...)</li> >+ * </u> >+ * @return the extracted javadoc from the attached javadoc, null if none >+ * @see IClasspathAttribute#JAVADOC_LOCATION_ATTRIBUTE_NAME >+ * @since 3.2 >+ */ >+ String getAttachedJavadoc(IProgressMonitor monitor, String encoding) throws JavaModelException; > > /** > * Returns the resource that corresponds directly to this element, >Index: model/org/eclipse/jdt/internal/core/JavaProject.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java,v >retrieving revision 1.351 >diff -u -r1.351 JavaProject.java >--- model/org/eclipse/jdt/internal/core/JavaProject.java 5 Oct 2005 09:20:16 -0000 1.351 >+++ model/org/eclipse/jdt/internal/core/JavaProject.java 10 Nov 2005 02:41:07 -0000 >@@ -10,16 +10,27 @@ > *******************************************************************************/ > package org.eclipse.jdt.internal.core; > >-import java.io.*; >+import java.io.BufferedInputStream; >+import java.io.ByteArrayInputStream; >+import java.io.ByteArrayOutputStream; >+import java.io.File; >+import java.io.FileInputStream; >+import java.io.IOException; >+import java.io.InputStream; >+import java.io.OutputStreamWriter; >+import java.io.StringReader; >+import java.io.UnsupportedEncodingException; > import java.util.ArrayList; > import java.util.HashMap; > import java.util.HashSet; > import java.util.Hashtable; > import java.util.Iterator; > import java.util.Map; >+ > import javax.xml.parsers.DocumentBuilder; > import javax.xml.parsers.DocumentBuilderFactory; > import javax.xml.parsers.ParserConfigurationException; >+ > import org.eclipse.core.resources.ICommand; > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IFolder; >Index: model/org/eclipse/jdt/internal/core/BinaryField.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryField.java,v >retrieving revision 1.26 >diff -u -r1.26 BinaryField.java >--- model/org/eclipse/jdt/internal/core/BinaryField.java 3 May 2005 10:49:21 -0000 1.26 >+++ model/org/eclipse/jdt/internal/core/BinaryField.java 10 Nov 2005 02:41:04 -0000 >@@ -10,8 +10,14 @@ > *******************************************************************************/ > package org.eclipse.jdt.internal.core; > >+import java.net.URL; >+ >+import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.jdt.core.Flags; > import org.eclipse.jdt.core.IField; >+import org.eclipse.jdt.core.IJavaModelStatusConstants; >+import org.eclipse.jdt.core.IPackageFragment; >+import org.eclipse.jdt.core.IType; > import org.eclipse.jdt.core.JavaModelException; > import org.eclipse.jdt.core.Signature; > import org.eclipse.jdt.internal.compiler.env.IBinaryField; >@@ -105,4 +111,30 @@ > } > } > } >+public String getAttachedJavadoc(IProgressMonitor monitor, String encoding) throws JavaModelException { >+ URL baseLocation= getJavadocBaseLocation(); >+ if (baseLocation == null) { >+ return null; >+ } >+ StringBuffer pathBuffer = new StringBuffer(baseLocation.toExternalForm()); >+ >+ if (!(pathBuffer.charAt(pathBuffer.length() - 1) == '/')) { >+ pathBuffer.append('/'); >+ } >+ IType declaringType = this.getDeclaringType(); >+ IPackageFragment pack= declaringType.getPackageFragment(); >+ pathBuffer.append(pack.getElementName().replace('.', '/')).append('/').append(declaringType.getTypeQualifiedName('.')).append(JavadocConstants.HTML_EXTENSION); >+ String contents = getURLContents(String.valueOf(pathBuffer), encoding); >+ if (contents == null) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC, this)); >+ int indexAnchor = contents.indexOf( >+ JavadocConstants.ANCHOR_PREFIX_START + this.getElementName() + JavadocConstants.ANCHOR_PREFIX_END); >+ if (indexAnchor == -1) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNRECOGNIZED_JAVADOC_FORMAT, this)); >+ int indexOfEndLink = contents.indexOf(JavadocConstants.ANCHOR_SUFFIX, indexAnchor); >+ if (indexOfEndLink == -1) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNRECOGNIZED_JAVADOC_FORMAT, this)); >+ int indexOfNextField = contents.indexOf(JavadocConstants.ANCHOR_PREFIX_START, indexOfEndLink); >+ int indexOfBottom = contents.indexOf(JavadocConstants.CONSTRUCTOR_DETAIL, indexOfEndLink); >+ indexOfNextField= Math.min(indexOfNextField, indexOfBottom); >+ if (indexOfNextField == -1) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNRECOGNIZED_JAVADOC_FORMAT, this)); >+ return contents.substring(indexOfEndLink + JavadocConstants.ANCHOR_SUFFIX_LENGTH, indexOfNextField); >+} > } >Index: model/org/eclipse/jdt/internal/core/ClassFile.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java,v >retrieving revision 1.111 >diff -u -r1.111 ClassFile.java >--- model/org/eclipse/jdt/internal/core/ClassFile.java 10 Oct 2005 15:57:19 -0000 1.111 >+++ model/org/eclipse/jdt/internal/core/ClassFile.java 10 Nov 2005 02:41:05 -0000 >@@ -24,16 +24,6 @@ > import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.Path; > import org.eclipse.jdt.core.*; >-import org.eclipse.jdt.core.IBuffer; >-import org.eclipse.jdt.core.IClassFile; >-import org.eclipse.jdt.core.ICompilationUnit; >-import org.eclipse.jdt.core.IJavaElement; >-import org.eclipse.jdt.core.IJavaModelStatusConstants; >-import org.eclipse.jdt.core.IPackageFragmentRoot; >-import org.eclipse.jdt.core.IParent; >-import org.eclipse.jdt.core.ISourceRange; >-import org.eclipse.jdt.core.IType; >-import org.eclipse.jdt.core.JavaModelException; > import org.eclipse.jdt.core.compiler.IProblem; > import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; > import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; >@@ -213,6 +203,9 @@ > } > return elt; > } >+public String getAttachedJavadoc(IProgressMonitor monitor, String encoding) throws JavaModelException { >+ return this.getType().getAttachedJavadoc(monitor, encoding); >+} > /** > * Returns the <code>ClassFileReader</code>specific for this IClassFile, based > * on its underlying resource, or <code>null</code> if unable to create >Index: model/org/eclipse/jdt/internal/core/PackageFragment.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragment.java,v >retrieving revision 1.68 >diff -u -r1.68 PackageFragment.java >--- model/org/eclipse/jdt/internal/core/PackageFragment.java 22 Apr 2005 16:25:34 -0000 1.68 >+++ model/org/eclipse/jdt/internal/core/PackageFragment.java 10 Nov 2005 02:41:07 -0000 >@@ -10,8 +10,9 @@ > *******************************************************************************/ > package org.eclipse.jdt.internal.core; > >-import java.util.*; >+import java.net.URL; > import java.util.ArrayList; >+import java.util.HashSet; > import java.util.Map; > > import org.eclipse.core.resources.IContainer; >@@ -21,13 +22,16 @@ > import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.Path; >-import org.eclipse.jdt.core.*; > import org.eclipse.jdt.core.IClassFile; > import org.eclipse.jdt.core.ICompilationUnit; > import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.IJavaModelStatusConstants; > import org.eclipse.jdt.core.IPackageFragment; > import org.eclipse.jdt.core.IPackageFragmentRoot; >+import org.eclipse.jdt.core.IParent; >+import org.eclipse.jdt.core.ISourceManipulation; > import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.jdt.core.WorkingCopyOwner; > import org.eclipse.jdt.internal.compiler.util.SuffixConstants; > import org.eclipse.jdt.internal.core.util.MementoTokenizer; > import org.eclipse.jdt.internal.core.util.Messages; >@@ -430,4 +434,24 @@ > } > } > } >+/* >+ * @see IJavaElement#getAttachedJavadoc(IProgressMonitor) >+ */ >+public String getAttachedJavadoc(IProgressMonitor monitor, String encoding) throws JavaModelException { >+ URL baseLocation= getJavadocBaseLocation(); >+ if (baseLocation == null) { >+ return null; >+ } >+ StringBuffer pathBuffer = new StringBuffer(baseLocation.toExternalForm()); >+ >+ if (!(pathBuffer.charAt(pathBuffer.length() - 1) == '/')) { >+ pathBuffer.append('/'); >+ } >+ String packPath= this.getElementName().replace('.', '/'); >+ pathBuffer.append(packPath).append('/').append(JavadocConstants.PACKAGE_FILE_NAME); >+ >+ final String contents = getURLContents(String.valueOf(pathBuffer), encoding); >+ if (contents == null) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC, this)); >+ return contents; >+} > } >Index: model/org/eclipse/jdt/internal/core/BinaryMethod.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryMethod.java,v >retrieving revision 1.63 >diff -u -r1.63 BinaryMethod.java >--- model/org/eclipse/jdt/internal/core/BinaryMethod.java 3 May 2005 10:49:21 -0000 1.63 >+++ model/org/eclipse/jdt/internal/core/BinaryMethod.java 10 Nov 2005 02:41:04 -0000 >@@ -10,12 +10,13 @@ > *******************************************************************************/ > package org.eclipse.jdt.internal.core; > >+import java.net.URL; >+import java.util.ArrayList; >+import java.util.StringTokenizer; >+ >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.NullProgressMonitor; > import org.eclipse.jdt.core.*; >-import org.eclipse.jdt.core.Flags; >-import org.eclipse.jdt.core.IMethod; >-import org.eclipse.jdt.core.IType; >-import org.eclipse.jdt.core.JavaModelException; >-import org.eclipse.jdt.core.Signature; > import org.eclipse.jdt.core.compiler.CharOperation; > import org.eclipse.jdt.internal.compiler.SourceElementRequestorAdapter; > import org.eclipse.jdt.internal.compiler.env.IBinaryMethod; >@@ -193,6 +194,42 @@ > } > } > } >+ if (this.parameterNames == null) { >+ // try to see if we can retrieve the names from the attached javadoc >+ IBinaryMethod info = (IBinaryMethod) getElementInfo(); >+ final int paramCount = Signature.getParameterCount(new String(info.getMethodDescriptor())); >+ if (paramCount != 0) { >+ String javadoc = this.getAttachedJavadoc(new NullProgressMonitor(), "UTF-8"); //$NON-NLS-1$ >+ if (javadoc != null) { >+ final int indexOfOpenParen = javadoc.indexOf('('); >+ if (indexOfOpenParen != -1) { >+ final int indexOfClosingParen = javadoc.indexOf(')', indexOfOpenParen); >+ if (indexOfClosingParen != -1) { >+ final char[] paramsSource = >+ CharOperation.replace( >+ javadoc.substring(indexOfOpenParen + 1, indexOfClosingParen).toCharArray(), >+ " ".toCharArray(), //$NON-NLS-1$ >+ new char[] {' '}); >+ final StringTokenizer tokenizer = new StringTokenizer(String.valueOf(paramsSource), ", \n\r"); //$NON-NLS-1$ >+ int index = 0; >+ final ArrayList paramNames = new ArrayList(paramCount); >+ while (tokenizer.hasMoreTokens()) { >+ final String token = tokenizer.nextToken(); >+ if ((index & 1) != 0) { >+ // if odd then this is a parameter name >+ paramNames.add(token); >+ } >+ index++; >+ } >+ if (!paramNames.isEmpty()) { >+ this.parameterNames = new String[paramNames.size()]; >+ paramNames.toArray(this.parameterNames); >+ } >+ } >+ } >+ } >+ } >+ } > // if still no parameter names, produce fake ones > if (this.parameterNames == null) { > IBinaryMethod info = (IBinaryMethod) getElementInfo(); >@@ -387,4 +424,78 @@ > buffer.append(this.occurrenceCount); > } > } >+public String getAttachedJavadoc(IProgressMonitor monitor, String encoding) throws JavaModelException { >+ URL baseLocation= getJavadocBaseLocation(); >+ if (baseLocation == null) { >+ return null; >+ } >+ StringBuffer pathBuffer = new StringBuffer(baseLocation.toExternalForm()); >+ >+ if (!(pathBuffer.charAt(pathBuffer.length() - 1) == '/')) { >+ pathBuffer.append('/'); >+ } >+ IType declaringType = this.getDeclaringType(); >+ IPackageFragment pack= declaringType.getPackageFragment(); >+ String typeQualifiedName = declaringType.getTypeQualifiedName('.'); >+ typeQualifiedName = typeQualifiedName.replace('$', '.'); >+ pathBuffer.append(pack.getElementName().replace('.', '/')).append('/').append(typeQualifiedName).append(JavadocConstants.HTML_EXTENSION); >+ >+ String methodName = this.getElementName(); >+ if (this.isConstructor()) { >+ methodName = typeQualifiedName; >+ } >+ String anchor = Signature.toString(this.getSignature().replace('/', '.'), methodName, null, true, false); >+ if (declaringType.isMember()) { >+ int depth = 0; >+ final String packageFragmentName = declaringType.getPackageFragment().getElementName(); >+ // might need to remove a part of the signature corresponding to the synthetic argument >+ final IJavaProject javaProject = declaringType.getJavaProject(); >+ char[][] typeNames = CharOperation.splitOn('.', typeQualifiedName.toCharArray()); >+ if (!Flags.isStatic(declaringType.getFlags())) depth++; >+ StringBuffer typeName = new StringBuffer(); >+ for (int i = 0, max = typeNames.length; i < max; i++) { >+ if (typeName.length() == 0) { >+ typeName.append(typeNames[i]); >+ } else { >+ typeName.append('.').append(typeNames[i]); >+ } >+ IType resolvedType = javaProject.findType(packageFragmentName, String.valueOf(typeName)); >+ if (resolvedType != null && resolvedType.isMember() && !Flags.isStatic(resolvedType.getFlags())) depth++; >+ } >+ if (depth != 0) { >+ int indexOfOpeningParen = anchor.indexOf('('); >+ if (indexOfOpeningParen == -1) return null; >+ int index = indexOfOpeningParen; >+ indexOfOpeningParen++; >+ for (int i = 0; i < depth; i++) { >+ int indexOfComma = anchor.indexOf(',', index); >+ if (indexOfComma != -1) { >+ index = indexOfComma + 2; >+ } >+ } >+ anchor = anchor.substring(0, indexOfOpeningParen) + anchor.substring(index); >+ } >+ } >+ final String contents = getURLContents(String.valueOf(pathBuffer), encoding); >+ if (contents == null) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC, this)); >+ int indexAnchor = contents.indexOf(JavadocConstants.ANCHOR_PREFIX_START + anchor + JavadocConstants.ANCHOR_PREFIX_END); >+ if (indexAnchor == -1) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNRECOGNIZED_JAVADOC_FORMAT, this)); >+ int indexOfEndLink = contents.indexOf(JavadocConstants.ANCHOR_SUFFIX, indexAnchor); >+ if (indexOfEndLink == -1) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNRECOGNIZED_JAVADOC_FORMAT, this)); >+ int indexOfNextMethod = contents.indexOf(JavadocConstants.ANCHOR_PREFIX_START, indexOfEndLink); >+ // find bottom >+ int indexOfBottom = -1; >+ if (this.isConstructor()) { >+ indexOfBottom = contents.indexOf(JavadocConstants.METHOD_DETAIL, indexOfEndLink); >+ if (indexOfBottom == -1) { >+ indexOfBottom = contents.indexOf(JavadocConstants.END_OF_CLASS_DATA, indexOfEndLink); >+ } >+ } else { >+ indexOfBottom = contents.indexOf(JavadocConstants.END_OF_CLASS_DATA, indexOfEndLink); >+ } >+ if (indexOfBottom == -1) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNRECOGNIZED_JAVADOC_FORMAT, this)); >+ indexOfNextMethod = Math.min(indexOfNextMethod, indexOfBottom); >+ if (indexOfNextMethod == -1) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNRECOGNIZED_JAVADOC_FORMAT, this)); >+ return contents.substring(indexOfEndLink + JavadocConstants.ANCHOR_SUFFIX_LENGTH, indexOfNextMethod); >+} > } >Index: model/org/eclipse/jdt/internal/core/BinaryType.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryType.java,v >retrieving revision 1.123 >diff -u -r1.123 BinaryType.java >--- model/org/eclipse/jdt/internal/core/BinaryType.java 13 Oct 2005 09:09:52 -0000 1.123 >+++ model/org/eclipse/jdt/internal/core/BinaryType.java 10 Nov 2005 02:41:05 -0000 >@@ -11,6 +11,7 @@ > package org.eclipse.jdt.internal.core; > > import java.io.InputStream; >+import java.net.URL; > import java.util.ArrayList; > import java.util.HashMap; > >@@ -982,4 +983,41 @@ > else > buffer.append("<anonymous>"); //$NON-NLS-1$ > } >+public String getAttachedJavadoc(IProgressMonitor monitor, String encoding) throws JavaModelException { >+ URL baseLocation= getJavadocBaseLocation(); >+ if (baseLocation == null) { >+ return null; >+ } >+ StringBuffer pathBuffer = new StringBuffer(baseLocation.toExternalForm()); >+ >+ if (!(pathBuffer.charAt(pathBuffer.length() - 1) == '/')) { >+ pathBuffer.append('/'); >+ } >+ IPackageFragment pack= this.getPackageFragment(); >+ String typeQualifiedName = this.getTypeQualifiedName('.'); >+ typeQualifiedName = typeQualifiedName.replace('$', '.'); >+ pathBuffer.append(pack.getElementName().replace('.', '/')).append('/').append(typeQualifiedName).append(JavadocConstants.HTML_EXTENSION); >+ >+ final String contents = getURLContents(String.valueOf(pathBuffer), encoding); >+ if (contents == null) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC, this)); >+ final int indexOfStartOfClassData = contents.indexOf(JavadocConstants.START_OF_CLASS_DATA); >+ if (indexOfStartOfClassData == -1) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNRECOGNIZED_JAVADOC_FORMAT, this)); >+ int indexOfNextSummary = contents.indexOf(JavadocConstants.NESTED_CLASS_SUMMARY); >+ if (indexOfNextSummary == -1) { >+ // try to find constructor summary start >+ indexOfNextSummary = contents.indexOf(JavadocConstants.CONSTRUCTOR_SUMMARY); >+ } >+ if (indexOfNextSummary == -1) { >+ // try to find method summary start >+ indexOfNextSummary = contents.indexOf(JavadocConstants.METHOD_SUMMARY); >+ } >+ if (indexOfNextSummary == -1) { >+ // we take the end of class data >+ indexOfNextSummary = contents.indexOf(JavadocConstants.END_OF_CLASS_DATA); >+ } >+ if (indexOfNextSummary == -1) { >+ throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNRECOGNIZED_JAVADOC_FORMAT, this)); >+ } >+ return contents.substring(indexOfStartOfClassData + JavadocConstants.START_OF_CLASS_DATA_LENGTH, indexOfNextSummary); >+} > } >Index: model/org/eclipse/jdt/internal/core/JavaElement.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElement.java,v >retrieving revision 1.103 >diff -u -r1.103 JavaElement.java >--- model/org/eclipse/jdt/internal/core/JavaElement.java 6 Sep 2005 13:55:44 -0000 1.103 >+++ model/org/eclipse/jdt/internal/core/JavaElement.java 10 Nov 2005 02:41:05 -0000 >@@ -10,6 +10,11 @@ > *******************************************************************************/ > package org.eclipse.jdt.internal.core; > >+import java.io.IOException; >+import java.io.InputStream; >+import java.net.MalformedURLException; >+import java.net.URL; >+import java.net.URLConnection; > import java.util.ArrayList; > import java.util.HashMap; > >@@ -29,6 +34,7 @@ > * @see IJavaElement > */ > public abstract class JavaElement extends PlatformObject implements IJavaElement { >+// private static final QualifiedName PROJECT_JAVADOC= new QualifiedName(JavaCore.PLUGIN_ID, "project_javadoc_location"); //$NON-NLS-1$ > > public static final char JEM_ESCAPE = '\\'; > public static final char JEM_JAVAPROJECT = '='; >@@ -155,6 +161,7 @@ > * Puts the newly created element info in the given map. > */ > protected abstract void generateInfos(Object info, HashMap newElements, IProgressMonitor pm) throws JavaModelException; >+ > /** > * @see IJavaElement > */ >@@ -612,4 +619,96 @@ > protected void toStringName(StringBuffer buffer) { > buffer.append(getElementName()); > } >+ >+ protected URL getJavadocBaseLocation() throws JavaModelException { >+ IPackageFragmentRoot root= (IPackageFragmentRoot) this.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); >+ if (root == null) { >+ return null; >+ } >+ >+ if (root.getKind() == IPackageFragmentRoot.K_BINARY) { >+ IClasspathEntry entry= root.getRawClasspathEntry(); >+ if (entry == null) { >+ return null; >+ } >+ if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { >+ entry= getRealClasspathEntry(root.getJavaProject(), entry.getPath(), root.getPath()); >+ if (entry == null) { >+ return null; >+ } >+ } >+ return getLibraryJavadocLocation(entry); >+ } >+ return null; >+ } >+ >+ private static IClasspathEntry getRealClasspathEntry(IJavaProject jproject, IPath containerPath, IPath libPath) throws JavaModelException { >+ IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject); >+ if (container != null) { >+ IClasspathEntry[] entries= container.getClasspathEntries(); >+ for (int i= 0; i < entries.length; i++) { >+ IClasspathEntry curr= entries[i]; >+ IClasspathEntry resolved= JavaCore.getResolvedClasspathEntry(curr); >+ if (resolved != null && libPath.equals(resolved.getPath())) { >+ return curr; // return the real entry >+ } >+ } >+ } >+ return null; // not found >+ } >+ >+ public static URL getLibraryJavadocLocation(IClasspathEntry entry) throws JavaModelException { >+ switch(entry.getEntryKind()) { >+ case IClasspathEntry.CPE_LIBRARY : >+ case IClasspathEntry.CPE_VARIABLE : >+ break; >+ default : >+ throw new IllegalArgumentException("Entry must be of kind CPE_LIBRARY or CPE_VARIABLE"); //$NON-NLS-1$ >+ } >+ >+ IClasspathAttribute[] extraAttributes= entry.getExtraAttributes(); >+ for (int i= 0; i < extraAttributes.length; i++) { >+ IClasspathAttribute attrib= extraAttributes[i]; >+ if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) { >+ try { >+ return new URL(attrib.getValue()); >+ } catch (MalformedURLException e) { >+ throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC)); >+ } >+ } >+ } >+ return null; >+ } >+ >+ /* >+ * @see IJavaElement#getAttachedJavadoc(IProgressMonitor) >+ */ >+ public String getAttachedJavadoc(IProgressMonitor monitor, String encoding) throws JavaModelException { >+ return null; >+ } >+ protected String getURLContents(String docUrlValue, String encoding) throws JavaModelException { >+ try { >+ URL docUrl = new URL(docUrlValue); >+ URLConnection connection = docUrl.openConnection(); >+ String contentEncoding = connection.getContentEncoding(); >+ if (contentEncoding != null) { >+ InputStream stream = docUrl.openStream(); >+ char[] contents = org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsCharArray(stream, -1, contentEncoding); >+ if (contents != null) { >+ return String.valueOf(contents); >+ } >+ } else { >+ InputStream stream = docUrl.openStream(); >+ char[] contents = org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsCharArray(stream, -1, encoding); >+ if (contents != null) { >+ return String.valueOf(contents); >+ } >+ } >+ } catch (MalformedURLException e) { >+ // ignore >+ } catch (IOException e) { >+ // ignore >+ } >+ return null; >+ } > } >Index: model/org/eclipse/jdt/internal/core/JavadocConstants.java >=================================================================== >RCS file: model/org/eclipse/jdt/internal/core/JavadocConstants.java >diff -N model/org/eclipse/jdt/internal/core/JavadocConstants.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ model/org/eclipse/jdt/internal/core/JavadocConstants.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,20 @@ >+package org.eclipse.jdt.internal.core; >+ >+public interface JavadocConstants { >+ >+ String ANCHOR_PREFIX_END = "\""; //$NON-NLS-1$ >+ String ANCHOR_PREFIX_START = "<A NAME=\""; //$NON-NLS-1$ >+ String ANCHOR_SUFFIX = "</A>"; //$NON-NLS-1$ >+ int ANCHOR_SUFFIX_LENGTH = JavadocConstants.ANCHOR_SUFFIX.length(); >+ String CONSTRUCTOR_DETAIL = "<!-- ========= CONSTRUCTOR DETAIL ======== -->"; //$NON-NLS-1$ >+ String CONSTRUCTOR_SUMMARY = "<!-- ======== CONSTRUCTOR SUMMARY ======== -->"; //$NON-NLS-1$ >+ String END_OF_CLASS_DATA = "<!-- ========= END OF CLASS DATA ========= -->"; //$NON-NLS-1$ >+ String HTML_EXTENSION = ".html"; //$NON-NLS-1$ >+ String INDEX_FILE_NAME = "index.html"; //$NON-NLS-1$ >+ String METHOD_DETAIL = "<!-- ============ METHOD DETAIL ========== -->"; //$NON-NLS-1$ >+ String METHOD_SUMMARY = "<!-- ========== METHOD SUMMARY =========== -->"; //$NON-NLS-1$ >+ String NESTED_CLASS_SUMMARY = "<!-- ======== NESTED CLASS SUMMARY ======== -->"; //$NON-NLS-1$ >+ String PACKAGE_FILE_NAME = "package-summary.html"; //$NON-NLS-1$ >+ String START_OF_CLASS_DATA = "<!-- ======== START OF CLASS DATA ======== -->"; //$NON-NLS-1$ >+ int START_OF_CLASS_DATA_LENGTH = JavadocConstants.START_OF_CLASS_DATA.length(); >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 110173
: 29674