Lines 10-21
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.internal.core; |
11 |
package org.eclipse.jdt.internal.core; |
12 |
|
12 |
|
|
|
13 |
import java.net.URL; |
14 |
import java.util.ArrayList; |
15 |
import java.util.StringTokenizer; |
16 |
|
17 |
import org.eclipse.core.runtime.IProgressMonitor; |
18 |
import org.eclipse.core.runtime.NullProgressMonitor; |
13 |
import org.eclipse.jdt.core.*; |
19 |
import org.eclipse.jdt.core.*; |
14 |
import org.eclipse.jdt.core.Flags; |
|
|
15 |
import org.eclipse.jdt.core.IMethod; |
16 |
import org.eclipse.jdt.core.IType; |
17 |
import org.eclipse.jdt.core.JavaModelException; |
18 |
import org.eclipse.jdt.core.Signature; |
19 |
import org.eclipse.jdt.core.compiler.CharOperation; |
20 |
import org.eclipse.jdt.core.compiler.CharOperation; |
20 |
import org.eclipse.jdt.internal.compiler.SourceElementRequestorAdapter; |
21 |
import org.eclipse.jdt.internal.compiler.SourceElementRequestorAdapter; |
21 |
import org.eclipse.jdt.internal.compiler.env.IBinaryMethod; |
22 |
import org.eclipse.jdt.internal.compiler.env.IBinaryMethod; |
Lines 193-198
Link Here
|
193 |
} |
194 |
} |
194 |
} |
195 |
} |
195 |
} |
196 |
} |
|
|
197 |
if (this.parameterNames == null) { |
198 |
// try to see if we can retrieve the names from the attached javadoc |
199 |
IBinaryMethod info = (IBinaryMethod) getElementInfo(); |
200 |
final int paramCount = Signature.getParameterCount(new String(info.getMethodDescriptor())); |
201 |
if (paramCount != 0) { |
202 |
String javadoc = this.getAttachedJavadoc(new NullProgressMonitor(), "UTF-8"); //$NON-NLS-1$ |
203 |
if (javadoc != null) { |
204 |
final int indexOfOpenParen = javadoc.indexOf('('); |
205 |
if (indexOfOpenParen != -1) { |
206 |
final int indexOfClosingParen = javadoc.indexOf(')', indexOfOpenParen); |
207 |
if (indexOfClosingParen != -1) { |
208 |
final char[] paramsSource = |
209 |
CharOperation.replace( |
210 |
javadoc.substring(indexOfOpenParen + 1, indexOfClosingParen).toCharArray(), |
211 |
" ".toCharArray(), //$NON-NLS-1$ |
212 |
new char[] {' '}); |
213 |
final StringTokenizer tokenizer = new StringTokenizer(String.valueOf(paramsSource), ", \n\r"); //$NON-NLS-1$ |
214 |
int index = 0; |
215 |
final ArrayList paramNames = new ArrayList(paramCount); |
216 |
while (tokenizer.hasMoreTokens()) { |
217 |
final String token = tokenizer.nextToken(); |
218 |
if ((index & 1) != 0) { |
219 |
// if odd then this is a parameter name |
220 |
paramNames.add(token); |
221 |
} |
222 |
index++; |
223 |
} |
224 |
if (!paramNames.isEmpty()) { |
225 |
this.parameterNames = new String[paramNames.size()]; |
226 |
paramNames.toArray(this.parameterNames); |
227 |
} |
228 |
} |
229 |
} |
230 |
} |
231 |
} |
232 |
} |
196 |
// if still no parameter names, produce fake ones |
233 |
// if still no parameter names, produce fake ones |
197 |
if (this.parameterNames == null) { |
234 |
if (this.parameterNames == null) { |
198 |
IBinaryMethod info = (IBinaryMethod) getElementInfo(); |
235 |
IBinaryMethod info = (IBinaryMethod) getElementInfo(); |
Lines 387-390
Link Here
|
387 |
buffer.append(this.occurrenceCount); |
424 |
buffer.append(this.occurrenceCount); |
388 |
} |
425 |
} |
389 |
} |
426 |
} |
|
|
427 |
public String getAttachedJavadoc(IProgressMonitor monitor, String encoding) throws JavaModelException { |
428 |
URL baseLocation= getJavadocBaseLocation(); |
429 |
if (baseLocation == null) { |
430 |
return null; |
431 |
} |
432 |
StringBuffer pathBuffer = new StringBuffer(baseLocation.toExternalForm()); |
433 |
|
434 |
if (!(pathBuffer.charAt(pathBuffer.length() - 1) == '/')) { |
435 |
pathBuffer.append('/'); |
436 |
} |
437 |
IType declaringType = this.getDeclaringType(); |
438 |
IPackageFragment pack= declaringType.getPackageFragment(); |
439 |
String typeQualifiedName = declaringType.getTypeQualifiedName('.'); |
440 |
typeQualifiedName = typeQualifiedName.replace('$', '.'); |
441 |
pathBuffer.append(pack.getElementName().replace('.', '/')).append('/').append(typeQualifiedName).append(JavadocConstants.HTML_EXTENSION); |
442 |
|
443 |
String methodName = this.getElementName(); |
444 |
if (this.isConstructor()) { |
445 |
methodName = typeQualifiedName; |
446 |
} |
447 |
String anchor = Signature.toString(this.getSignature().replace('/', '.'), methodName, null, true, false); |
448 |
if (declaringType.isMember()) { |
449 |
int depth = 0; |
450 |
final String packageFragmentName = declaringType.getPackageFragment().getElementName(); |
451 |
// might need to remove a part of the signature corresponding to the synthetic argument |
452 |
final IJavaProject javaProject = declaringType.getJavaProject(); |
453 |
char[][] typeNames = CharOperation.splitOn('.', typeQualifiedName.toCharArray()); |
454 |
if (!Flags.isStatic(declaringType.getFlags())) depth++; |
455 |
StringBuffer typeName = new StringBuffer(); |
456 |
for (int i = 0, max = typeNames.length; i < max; i++) { |
457 |
if (typeName.length() == 0) { |
458 |
typeName.append(typeNames[i]); |
459 |
} else { |
460 |
typeName.append('.').append(typeNames[i]); |
461 |
} |
462 |
IType resolvedType = javaProject.findType(packageFragmentName, String.valueOf(typeName)); |
463 |
if (resolvedType != null && resolvedType.isMember() && !Flags.isStatic(resolvedType.getFlags())) depth++; |
464 |
} |
465 |
if (depth != 0) { |
466 |
int indexOfOpeningParen = anchor.indexOf('('); |
467 |
if (indexOfOpeningParen == -1) return null; |
468 |
int index = indexOfOpeningParen; |
469 |
indexOfOpeningParen++; |
470 |
for (int i = 0; i < depth; i++) { |
471 |
int indexOfComma = anchor.indexOf(',', index); |
472 |
if (indexOfComma != -1) { |
473 |
index = indexOfComma + 2; |
474 |
} |
475 |
} |
476 |
anchor = anchor.substring(0, indexOfOpeningParen) + anchor.substring(index); |
477 |
} |
478 |
} |
479 |
final String contents = getURLContents(String.valueOf(pathBuffer), encoding); |
480 |
if (contents == null) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC, this)); |
481 |
int indexAnchor = contents.indexOf(JavadocConstants.ANCHOR_PREFIX_START + anchor + JavadocConstants.ANCHOR_PREFIX_END); |
482 |
if (indexAnchor == -1) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNRECOGNIZED_JAVADOC_FORMAT, this)); |
483 |
int indexOfEndLink = contents.indexOf(JavadocConstants.ANCHOR_SUFFIX, indexAnchor); |
484 |
if (indexOfEndLink == -1) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNRECOGNIZED_JAVADOC_FORMAT, this)); |
485 |
int indexOfNextMethod = contents.indexOf(JavadocConstants.ANCHOR_PREFIX_START, indexOfEndLink); |
486 |
// find bottom |
487 |
int indexOfBottom = -1; |
488 |
if (this.isConstructor()) { |
489 |
indexOfBottom = contents.indexOf(JavadocConstants.METHOD_DETAIL, indexOfEndLink); |
490 |
if (indexOfBottom == -1) { |
491 |
indexOfBottom = contents.indexOf(JavadocConstants.END_OF_CLASS_DATA, indexOfEndLink); |
492 |
} |
493 |
} else { |
494 |
indexOfBottom = contents.indexOf(JavadocConstants.END_OF_CLASS_DATA, indexOfEndLink); |
495 |
} |
496 |
if (indexOfBottom == -1) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNRECOGNIZED_JAVADOC_FORMAT, this)); |
497 |
indexOfNextMethod = Math.min(indexOfNextMethod, indexOfBottom); |
498 |
if (indexOfNextMethod == -1) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNRECOGNIZED_JAVADOC_FORMAT, this)); |
499 |
return contents.substring(indexOfEndLink + JavadocConstants.ANCHOR_SUFFIX_LENGTH, indexOfNextMethod); |
500 |
} |
390 |
} |
501 |
} |