### 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; + /** + *
Status constant indicating that the attached javadoc content cannot be retrieved due to multiple reasons: + * invalid url, timed-out,...
+ * + * @since 3.2 + */ + public static final int CANNOT_RETRIEVE_ATTACHED_JAVADOC = 1008; + /** + *Status constant indicating that the attached javadoc content format is unrecognized.
+ * + * @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); + + /** + *Returns the Javadoc as an html source if this element has an attached javadoc, + * null otherwise.
+ *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.
+ * + *The html is extracted from the attached javadoc and provided as is. No + * transformation or validation is done.
+ * + *If the default encoding is set to null, the platform encoding is used.
+ * + *NOTE: This API is subject to change before the 3.2 release.
+ * + * @param monitor the given progress monitor + * @param encoding the given default encoding + * @exception JavaModelException if: + *ClassFileReader
specific for this IClassFile, based
* on its underlying resource, or null
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("