View | Details | Raw Unified | Return to bug 110173
Collapse All | Expand All

(-)codeassist/org/eclipse/jdt/internal/codeassist/InternalCompletionProposal.java (-6 / +1 lines)
Lines 96-107 Link Here
96
			// TODO (david) shouldn't it be NameLookup.ACCEPT_ALL ?
96
			// TODO (david) shouldn't it be NameLookup.ACCEPT_ALL ?
97
			type = this.nameLookup.findType(new String(tName), false, NameLookup.ACCEPT_CLASSES & NameLookup.ACCEPT_INTERFACES);
97
			type = this.nameLookup.findType(new String(tName), false, NameLookup.ACCEPT_CLASSES & NameLookup.ACCEPT_INTERFACES);
98
			if(type instanceof BinaryType){
98
			if(type instanceof BinaryType){
99
				if(((BinaryType)type).getSourceMapper() != null) {
99
				this.completionEngine.typeCache.put(tName, type);
100
					this.completionEngine.typeCache.put(tName, type);
101
				} else {
102
					this.completionEngine.typeCache.put(tName, NO_ATTACHED_SOURCE);
103
					type = null;
104
				}
105
			} else {
100
			} else {
106
				type = null;
101
				type = null;
107
			}
102
			}
(-)model/org/eclipse/jdt/core/IJavaModelStatusConstants.java (-1 / +14 lines)
Lines 306-310 Link Here
306
	 * Status constant indicating that a compiler option is invalid.
306
	 * Status constant indicating that a compiler option is invalid.
307
	 * @since 3.1
307
	 * @since 3.1
308
	 */
308
	 */
309
//	public static final int INVALID_COMPILER_OPTION = 1007;	
309
//	public static final int INVALID_COMPILER_OPTION = 1007;
310
	/**
311
	 * <p>Status constant indicating that the attached javadoc content cannot be retrieved due to multiple reasons:
312
	 * invalid url, timed-out,...</p>
313
	 * 
314
	 * @since 3.2
315
	 */
316
	public static final int CANNOT_RETRIEVE_ATTACHED_JAVADOC = 1008;
317
	/**
318
	 * <p>Status constant indicating that the attached javadoc content format is unrecognized.</p>
319
	 * 
320
	 * @since 3.2
321
	 */
322
	public static final int UNRECOGNIZED_JAVADOC_FORMAT = 1009;
310
}
323
}
(-)model/org/eclipse/jdt/core/IJavaElement.java (+28 lines)
Lines 13-18 Link Here
13
import org.eclipse.core.resources.IResource;
13
import org.eclipse.core.resources.IResource;
14
import org.eclipse.core.runtime.IAdaptable;
14
import org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.core.runtime.IPath;
15
import org.eclipse.core.runtime.IPath;
16
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.jobs.ISchedulingRule;
17
import org.eclipse.core.runtime.jobs.ISchedulingRule;
17
18
18
/**
19
/**
Lines 157-162 Link Here
157
	 * @since 2.0
158
	 * @since 2.0
158
	 */
159
	 */
159
	IJavaElement getAncestor(int ancestorType);
160
	IJavaElement getAncestor(int ancestorType);
161
	
162
	/**
163
	 * <p>Returns the Javadoc as an html source if this element has an attached javadoc,
164
	 * null otherwise.</p> 
165
	 * <p>This should be used only for binary elements. Source elements will always return null.
166
	 * The encoding used to read the javadoc is the one defined by the content type of the
167
	 * file. If none is defined, then the specified encoding will be used as the default encoding.</p>
168
	 * 
169
	 * <p>The html is extracted from the attached javadoc and provided as is. No
170
	 * transformation or validation is done.</p>
171
	 *
172
	 * <p>If the default encoding is set to null, the platform encoding is used.</p>
173
	 * 
174
	 * <p>NOTE: This API is subject to change before the 3.2 release.</p>
175
	 * 
176
	 * @param monitor the given progress monitor
177
	 * @param encoding the given default encoding
178
	 * @exception JavaModelException if:<u>
179
	 *  <li>this element does not exist</li>
180
	 *  <li>retrieving the attached javadoc fails (timed-out, invalid URL, ...)
181
	 *  <li>the format of the javadoc doesn't match expected standards (different anchors,...)</li>
182
	 *  </u>
183
	 * @return the extracted javadoc from the attached javadoc, null if none
184
	 * @see IClasspathAttribute#JAVADOC_LOCATION_ATTRIBUTE_NAME
185
	 * @since 3.2
186
	 */
187
	String getAttachedJavadoc(IProgressMonitor monitor, String encoding) throws JavaModelException;	
160
188
161
	/**
189
	/**
162
	 * Returns the resource that corresponds directly to this element,
190
	 * Returns the resource that corresponds directly to this element,
(-)model/org/eclipse/jdt/internal/core/JavaProject.java (-1 / +12 lines)
Lines 10-25 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.core;
11
package org.eclipse.jdt.internal.core;
12
12
13
import java.io.*;
13
import java.io.BufferedInputStream;
14
import java.io.ByteArrayInputStream;
15
import java.io.ByteArrayOutputStream;
16
import java.io.File;
17
import java.io.FileInputStream;
18
import java.io.IOException;
19
import java.io.InputStream;
20
import java.io.OutputStreamWriter;
21
import java.io.StringReader;
22
import java.io.UnsupportedEncodingException;
14
import java.util.ArrayList;
23
import java.util.ArrayList;
15
import java.util.HashMap;
24
import java.util.HashMap;
16
import java.util.HashSet;
25
import java.util.HashSet;
17
import java.util.Hashtable;
26
import java.util.Hashtable;
18
import java.util.Iterator;
27
import java.util.Iterator;
19
import java.util.Map;
28
import java.util.Map;
29
20
import javax.xml.parsers.DocumentBuilder;
30
import javax.xml.parsers.DocumentBuilder;
21
import javax.xml.parsers.DocumentBuilderFactory;
31
import javax.xml.parsers.DocumentBuilderFactory;
22
import javax.xml.parsers.ParserConfigurationException;
32
import javax.xml.parsers.ParserConfigurationException;
33
23
import org.eclipse.core.resources.ICommand;
34
import org.eclipse.core.resources.ICommand;
24
import org.eclipse.core.resources.IFile;
35
import org.eclipse.core.resources.IFile;
25
import org.eclipse.core.resources.IFolder;
36
import org.eclipse.core.resources.IFolder;
(-)model/org/eclipse/jdt/internal/core/BinaryField.java (+32 lines)
Lines 10-17 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
15
import org.eclipse.core.runtime.IProgressMonitor;
13
import org.eclipse.jdt.core.Flags;
16
import org.eclipse.jdt.core.Flags;
14
import org.eclipse.jdt.core.IField;
17
import org.eclipse.jdt.core.IField;
18
import org.eclipse.jdt.core.IJavaModelStatusConstants;
19
import org.eclipse.jdt.core.IPackageFragment;
20
import org.eclipse.jdt.core.IType;
15
import org.eclipse.jdt.core.JavaModelException;
21
import org.eclipse.jdt.core.JavaModelException;
16
import org.eclipse.jdt.core.Signature;
22
import org.eclipse.jdt.core.Signature;
17
import org.eclipse.jdt.internal.compiler.env.IBinaryField;
23
import org.eclipse.jdt.internal.compiler.env.IBinaryField;
Lines 105-108 Link Here
105
		}
111
		}
106
	}
112
	}
107
}
113
}
114
public String getAttachedJavadoc(IProgressMonitor monitor, String encoding) throws JavaModelException {
115
	URL baseLocation= getJavadocBaseLocation();
116
	if (baseLocation == null) {
117
		return null;
118
	}
119
	StringBuffer pathBuffer = new StringBuffer(baseLocation.toExternalForm());
120
121
	if (!(pathBuffer.charAt(pathBuffer.length() - 1) == '/')) {
122
		pathBuffer.append('/');
123
	}
124
	IType declaringType = this.getDeclaringType();
125
	IPackageFragment pack= declaringType.getPackageFragment();
126
	pathBuffer.append(pack.getElementName().replace('.', '/')).append('/').append(declaringType.getTypeQualifiedName('.')).append(JavadocConstants.HTML_EXTENSION);
127
	String contents = getURLContents(String.valueOf(pathBuffer), encoding);
128
	if (contents == null) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC, this));
129
	int indexAnchor = contents.indexOf(
130
			JavadocConstants.ANCHOR_PREFIX_START + this.getElementName() + JavadocConstants.ANCHOR_PREFIX_END);
131
	if (indexAnchor == -1) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNRECOGNIZED_JAVADOC_FORMAT, this));
132
	int indexOfEndLink = contents.indexOf(JavadocConstants.ANCHOR_SUFFIX, indexAnchor);
133
	if (indexOfEndLink == -1) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNRECOGNIZED_JAVADOC_FORMAT, this));
134
	int indexOfNextField = contents.indexOf(JavadocConstants.ANCHOR_PREFIX_START, indexOfEndLink);
135
	int indexOfBottom = contents.indexOf(JavadocConstants.CONSTRUCTOR_DETAIL, indexOfEndLink);
136
	indexOfNextField= Math.min(indexOfNextField, indexOfBottom);
137
	if (indexOfNextField == -1) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNRECOGNIZED_JAVADOC_FORMAT, this));
138
	return contents.substring(indexOfEndLink + JavadocConstants.ANCHOR_SUFFIX_LENGTH, indexOfNextField);
139
}
108
}
140
}
(-)model/org/eclipse/jdt/internal/core/ClassFile.java (-10 / +3 lines)
Lines 24-39 Link Here
24
import org.eclipse.core.runtime.IStatus;
24
import org.eclipse.core.runtime.IStatus;
25
import org.eclipse.core.runtime.Path;
25
import org.eclipse.core.runtime.Path;
26
import org.eclipse.jdt.core.*;
26
import org.eclipse.jdt.core.*;
27
import org.eclipse.jdt.core.IBuffer;
28
import org.eclipse.jdt.core.IClassFile;
29
import org.eclipse.jdt.core.ICompilationUnit;
30
import org.eclipse.jdt.core.IJavaElement;
31
import org.eclipse.jdt.core.IJavaModelStatusConstants;
32
import org.eclipse.jdt.core.IPackageFragmentRoot;
33
import org.eclipse.jdt.core.IParent;
34
import org.eclipse.jdt.core.ISourceRange;
35
import org.eclipse.jdt.core.IType;
36
import org.eclipse.jdt.core.JavaModelException;
37
import org.eclipse.jdt.core.compiler.IProblem;
27
import org.eclipse.jdt.core.compiler.IProblem;
38
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
28
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
39
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
29
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
Lines 213-218 Link Here
213
	}
203
	}
214
	return elt;
204
	return elt;
215
}
205
}
206
public String getAttachedJavadoc(IProgressMonitor monitor, String encoding) throws JavaModelException {
207
	return this.getType().getAttachedJavadoc(monitor, encoding);
208
}
216
/**
209
/**
217
 * Returns the <code>ClassFileReader</code>specific for this IClassFile, based
210
 * Returns the <code>ClassFileReader</code>specific for this IClassFile, based
218
 * on its underlying resource, or <code>null</code> if unable to create
211
 * on its underlying resource, or <code>null</code> if unable to create
(-)model/org/eclipse/jdt/internal/core/PackageFragment.java (-2 / +26 lines)
Lines 10-17 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.core;
11
package org.eclipse.jdt.internal.core;
12
12
13
import java.util.*;
13
import java.net.URL;
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.HashSet;
15
import java.util.Map;
16
import java.util.Map;
16
17
17
import org.eclipse.core.resources.IContainer;
18
import org.eclipse.core.resources.IContainer;
Lines 21-33 Link Here
21
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.core.runtime.Path;
24
import org.eclipse.jdt.core.*;
25
import org.eclipse.jdt.core.IClassFile;
25
import org.eclipse.jdt.core.IClassFile;
26
import org.eclipse.jdt.core.ICompilationUnit;
26
import org.eclipse.jdt.core.ICompilationUnit;
27
import org.eclipse.jdt.core.IJavaElement;
27
import org.eclipse.jdt.core.IJavaElement;
28
import org.eclipse.jdt.core.IJavaModelStatusConstants;
28
import org.eclipse.jdt.core.IPackageFragment;
29
import org.eclipse.jdt.core.IPackageFragment;
29
import org.eclipse.jdt.core.IPackageFragmentRoot;
30
import org.eclipse.jdt.core.IPackageFragmentRoot;
31
import org.eclipse.jdt.core.IParent;
32
import org.eclipse.jdt.core.ISourceManipulation;
30
import org.eclipse.jdt.core.JavaModelException;
33
import org.eclipse.jdt.core.JavaModelException;
34
import org.eclipse.jdt.core.WorkingCopyOwner;
31
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
35
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
32
import org.eclipse.jdt.internal.core.util.MementoTokenizer;
36
import org.eclipse.jdt.internal.core.util.MementoTokenizer;
33
import org.eclipse.jdt.internal.core.util.Messages;
37
import org.eclipse.jdt.internal.core.util.Messages;
Lines 430-433 Link Here
430
		}
434
		}
431
	}
435
	}
432
}
436
}
437
/*
438
 * @see IJavaElement#getAttachedJavadoc(IProgressMonitor)
439
 */
440
public String getAttachedJavadoc(IProgressMonitor monitor, String encoding) throws JavaModelException {
441
	URL baseLocation= getJavadocBaseLocation();
442
	if (baseLocation == null) {
443
		return null;
444
	}
445
	StringBuffer pathBuffer = new StringBuffer(baseLocation.toExternalForm());
446
447
	if (!(pathBuffer.charAt(pathBuffer.length() - 1) == '/')) {
448
		pathBuffer.append('/');
449
	}
450
	String packPath= this.getElementName().replace('.', '/');
451
	pathBuffer.append(packPath).append('/').append(JavadocConstants.PACKAGE_FILE_NAME);
452
	
453
	final String contents = getURLContents(String.valueOf(pathBuffer), encoding);
454
	if (contents == null) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC, this));
455
	return contents;
456
}
433
}
457
}
(-)model/org/eclipse/jdt/internal/core/BinaryMethod.java (-5 / +116 lines)
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
									"&nbsp;".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
}
(-)model/org/eclipse/jdt/internal/core/BinaryType.java (+38 lines)
Lines 11-16 Link Here
11
package org.eclipse.jdt.internal.core;
11
package org.eclipse.jdt.internal.core;
12
12
13
import java.io.InputStream;
13
import java.io.InputStream;
14
import java.net.URL;
14
import java.util.ArrayList;
15
import java.util.ArrayList;
15
import java.util.HashMap;
16
import java.util.HashMap;
16
17
Lines 982-985 Link Here
982
	else
983
	else
983
		buffer.append("<anonymous>"); //$NON-NLS-1$
984
		buffer.append("<anonymous>"); //$NON-NLS-1$
984
}
985
}
986
public String getAttachedJavadoc(IProgressMonitor monitor, String encoding) throws JavaModelException {
987
	URL baseLocation= getJavadocBaseLocation();
988
	if (baseLocation == null) {
989
		return null;
990
	}
991
	StringBuffer pathBuffer = new StringBuffer(baseLocation.toExternalForm());
992
993
	if (!(pathBuffer.charAt(pathBuffer.length() - 1) == '/')) {
994
		pathBuffer.append('/');
995
	}
996
	IPackageFragment pack= this.getPackageFragment();
997
	String typeQualifiedName = this.getTypeQualifiedName('.');
998
	typeQualifiedName = typeQualifiedName.replace('$', '.');
999
	pathBuffer.append(pack.getElementName().replace('.', '/')).append('/').append(typeQualifiedName).append(JavadocConstants.HTML_EXTENSION);
1000
	
1001
	final String contents = getURLContents(String.valueOf(pathBuffer), encoding);
1002
	if (contents == null) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC, this));
1003
	final int indexOfStartOfClassData = contents.indexOf(JavadocConstants.START_OF_CLASS_DATA);
1004
	if (indexOfStartOfClassData == -1) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNRECOGNIZED_JAVADOC_FORMAT, this));
1005
	int indexOfNextSummary = contents.indexOf(JavadocConstants.NESTED_CLASS_SUMMARY);
1006
	if (indexOfNextSummary == -1) {
1007
		// try to find constructor summary start
1008
		indexOfNextSummary = contents.indexOf(JavadocConstants.CONSTRUCTOR_SUMMARY);
1009
	}
1010
	if (indexOfNextSummary == -1) {
1011
		// try to find method summary start
1012
		indexOfNextSummary = contents.indexOf(JavadocConstants.METHOD_SUMMARY);
1013
	}
1014
	if (indexOfNextSummary == -1) {
1015
		// we take the end of class data
1016
		indexOfNextSummary = contents.indexOf(JavadocConstants.END_OF_CLASS_DATA);
1017
	}
1018
	if (indexOfNextSummary == -1) {
1019
		throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNRECOGNIZED_JAVADOC_FORMAT, this));
1020
	}
1021
	return contents.substring(indexOfStartOfClassData + JavadocConstants.START_OF_CLASS_DATA_LENGTH, indexOfNextSummary);
1022
}
985
}
1023
}
(-)model/org/eclipse/jdt/internal/core/JavaElement.java (+99 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.core;
11
package org.eclipse.jdt.internal.core;
12
12
13
import java.io.IOException;
14
import java.io.InputStream;
15
import java.net.MalformedURLException;
16
import java.net.URL;
17
import java.net.URLConnection;
13
import java.util.ArrayList;
18
import java.util.ArrayList;
14
import java.util.HashMap;
19
import java.util.HashMap;
15
20
Lines 29-34 Link Here
29
 * @see IJavaElement
34
 * @see IJavaElement
30
 */
35
 */
31
public abstract class JavaElement extends PlatformObject implements IJavaElement {
36
public abstract class JavaElement extends PlatformObject implements IJavaElement {
37
//	private static final QualifiedName PROJECT_JAVADOC= new QualifiedName(JavaCore.PLUGIN_ID, "project_javadoc_location"); //$NON-NLS-1$
32
38
33
	public static final char JEM_ESCAPE = '\\';
39
	public static final char JEM_ESCAPE = '\\';
34
	public static final char JEM_JAVAPROJECT = '=';
40
	public static final char JEM_JAVAPROJECT = '=';
Lines 155-160 Link Here
155
	 * Puts the newly created element info in the given map.
161
	 * Puts the newly created element info in the given map.
156
	 */
162
	 */
157
	protected abstract void generateInfos(Object info, HashMap newElements, IProgressMonitor pm) throws JavaModelException;
163
	protected abstract void generateInfos(Object info, HashMap newElements, IProgressMonitor pm) throws JavaModelException;
164
	
158
	/**
165
	/**
159
	 * @see IJavaElement
166
	 * @see IJavaElement
160
	 */
167
	 */
Lines 612-615 Link Here
612
	protected void toStringName(StringBuffer buffer) {
619
	protected void toStringName(StringBuffer buffer) {
613
		buffer.append(getElementName());
620
		buffer.append(getElementName());
614
	}
621
	}
622
	
623
	protected URL getJavadocBaseLocation() throws JavaModelException {
624
		IPackageFragmentRoot root= (IPackageFragmentRoot) this.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
625
		if (root == null) {
626
			return null;
627
		}
628
629
		if (root.getKind() == IPackageFragmentRoot.K_BINARY) {
630
			IClasspathEntry entry= root.getRawClasspathEntry();
631
			if (entry == null) {
632
				return null;
633
			}
634
			if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
635
				entry= getRealClasspathEntry(root.getJavaProject(), entry.getPath(), root.getPath());
636
				if (entry == null) {
637
					return null;
638
				}
639
			}
640
			return getLibraryJavadocLocation(entry);
641
		}
642
		return null;
643
	}
644
	
645
	private static IClasspathEntry getRealClasspathEntry(IJavaProject jproject, IPath containerPath, IPath libPath) throws JavaModelException {
646
		IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
647
		if (container != null) {
648
			IClasspathEntry[] entries= container.getClasspathEntries();
649
			for (int i= 0; i < entries.length; i++) {
650
				IClasspathEntry curr= entries[i];
651
				IClasspathEntry resolved= JavaCore.getResolvedClasspathEntry(curr);
652
				if (resolved != null && libPath.equals(resolved.getPath())) {
653
					return curr; // return the real entry
654
				}
655
			}
656
		}
657
		return null; // not found
658
	}
659
	
660
	public static URL getLibraryJavadocLocation(IClasspathEntry entry) throws JavaModelException {
661
		switch(entry.getEntryKind()) {
662
			case IClasspathEntry.CPE_LIBRARY :
663
			case IClasspathEntry.CPE_VARIABLE :
664
				break;
665
			default :
666
				throw new IllegalArgumentException("Entry must be of kind CPE_LIBRARY or CPE_VARIABLE"); //$NON-NLS-1$
667
		}
668
		
669
		IClasspathAttribute[] extraAttributes= entry.getExtraAttributes();
670
		for (int i= 0; i < extraAttributes.length; i++) {
671
			IClasspathAttribute attrib= extraAttributes[i];
672
			if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) {
673
				try {
674
					return new URL(attrib.getValue());
675
				} catch (MalformedURLException e) {
676
					throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC));
677
				}
678
			}
679
		}
680
		return null;
681
	}
682
	
683
	/*
684
	 * @see IJavaElement#getAttachedJavadoc(IProgressMonitor)
685
	 */
686
	public String getAttachedJavadoc(IProgressMonitor monitor, String encoding) throws JavaModelException {
687
		return null;
688
	}
689
	protected String getURLContents(String docUrlValue, String encoding) throws JavaModelException {
690
		try {
691
			URL docUrl = new URL(docUrlValue);
692
			URLConnection connection = docUrl.openConnection();
693
			String contentEncoding = connection.getContentEncoding();
694
			if (contentEncoding != null) {
695
				InputStream stream = docUrl.openStream();
696
				char[] contents = org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsCharArray(stream, -1, contentEncoding);
697
				if (contents != null) {
698
					return String.valueOf(contents);
699
				}
700
			} else {
701
				InputStream stream = docUrl.openStream();
702
				char[] contents = org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsCharArray(stream, -1, encoding);
703
				if (contents != null) {
704
					return String.valueOf(contents);
705
				}
706
			}
707
 		} catch (MalformedURLException e) {
708
 			// ignore
709
		} catch (IOException e) {
710
			// ignore
711
		}
712
		return null;
713
	}
615
}
714
}
(-)model/org/eclipse/jdt/internal/core/JavadocConstants.java (+20 lines)
Added Link Here
1
package org.eclipse.jdt.internal.core;
2
3
public interface JavadocConstants {
4
5
	String ANCHOR_PREFIX_END = "\""; //$NON-NLS-1$
6
	String ANCHOR_PREFIX_START = "<A NAME=\""; //$NON-NLS-1$
7
	String ANCHOR_SUFFIX = "</A>"; //$NON-NLS-1$
8
	int ANCHOR_SUFFIX_LENGTH = JavadocConstants.ANCHOR_SUFFIX.length();
9
	String CONSTRUCTOR_DETAIL = "<!-- ========= CONSTRUCTOR DETAIL ======== -->"; //$NON-NLS-1$
10
	String CONSTRUCTOR_SUMMARY = "<!-- ======== CONSTRUCTOR SUMMARY ======== -->"; //$NON-NLS-1$
11
	String END_OF_CLASS_DATA = "<!-- ========= END OF CLASS DATA ========= -->"; //$NON-NLS-1$
12
	String HTML_EXTENSION = ".html"; //$NON-NLS-1$
13
	String INDEX_FILE_NAME = "index.html"; //$NON-NLS-1$
14
	String METHOD_DETAIL = "<!-- ============ METHOD DETAIL ========== -->"; //$NON-NLS-1$
15
	String METHOD_SUMMARY = "<!-- ========== METHOD SUMMARY =========== -->"; //$NON-NLS-1$
16
	String NESTED_CLASS_SUMMARY = "<!-- ======== NESTED CLASS SUMMARY ======== -->"; //$NON-NLS-1$
17
	String PACKAGE_FILE_NAME = "package-summary.html"; //$NON-NLS-1$
18
	String START_OF_CLASS_DATA = "<!-- ======== START OF CLASS DATA ======== -->"; //$NON-NLS-1$
19
	int START_OF_CLASS_DATA_LENGTH = JavadocConstants.START_OF_CLASS_DATA.length();
20
}

Return to bug 110173