blob: fdadfe7d8a64e423afdf086bc851dea81eef97c4 [file] [log] [blame]
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +00001/*******************************************************************************
Stephan Herrmann28464e42013-02-02 16:25:14 +01002 * Copyright (c) 2000, 2013 IBM Corporation and others.
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +00003 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.jdt.core.tests.model;
12
13import java.io.IOException;
14import java.net.MalformedURLException;
15import java.net.URI;
16import java.net.URL;
17import java.util.Map;
18
19import junit.framework.Test;
Stephan Herrmann1057e9a2011-03-10 18:42:56 +000020import junit.framework.TestSuite;
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +000021
Stephan Herrmann918c05c2012-12-16 20:09:49 +010022import org.eclipse.core.resources.IFile;
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +000023import org.eclipse.core.resources.IResource;
24import org.eclipse.core.runtime.CoreException;
Stephan Herrmann0717d572010-04-21 22:04:13 +000025import org.eclipse.core.runtime.IPath;
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +000026import org.eclipse.core.runtime.NullProgressMonitor;
Stephan Herrmannebb81ec2010-12-11 19:33:12 +000027import org.eclipse.core.runtime.Path;
Stephan Herrmann918c05c2012-12-16 20:09:49 +010028import org.eclipse.jdt.core.IAccessRule;
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +000029import org.eclipse.jdt.core.IClassFile;
30import org.eclipse.jdt.core.IClasspathAttribute;
31import org.eclipse.jdt.core.IClasspathEntry;
32import org.eclipse.jdt.core.ICompilationUnit;
33import org.eclipse.jdt.core.IField;
34import org.eclipse.jdt.core.IJavaProject;
35import org.eclipse.jdt.core.IMethod;
36import org.eclipse.jdt.core.IPackageFragment;
37import org.eclipse.jdt.core.IPackageFragmentRoot;
38import org.eclipse.jdt.core.IType;
39import org.eclipse.jdt.core.JavaCore;
40import org.eclipse.jdt.core.JavaModelException;
Stephan Herrmann918c05c2012-12-16 20:09:49 +010041import org.eclipse.jdt.core.compiler.CharOperation;
Stephan Herrmannebb81ec2010-12-11 19:33:12 +000042import org.eclipse.jdt.internal.core.BinaryType;
43import org.eclipse.jdt.internal.core.JavaModelManager;
44import org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo;
Stephan Herrmann918c05c2012-12-16 20:09:49 +010045import org.eclipse.jdt.internal.core.util.Util;
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +000046
47public class AttachedJavadocTests extends ModifyingResourceTests {
48 private static final String DEFAULT_DOC_FOLDER = "doc";
49
50 static {
Stephan Herrmannfa0b16c2011-08-25 12:46:28 +000051// TESTS_NAMES = new String[] { "testBug354766" };
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +000052// TESTS_NUMBERS = new int[] { 24 };
53// TESTS_RANGE = new int[] { 169, 180 };
54 }
55
56 public static Test suite() {
Stephan Herrmann1057e9a2011-03-10 18:42:56 +000057 // hack to guarantee the test order
58 TestSuite suite = new Suite(AttachedJavadocTests.class.getName());
59 suite.addTest(new AttachedJavadocTests("test001"));
60 suite.addTest(new AttachedJavadocTests("test002"));
61 suite.addTest(new AttachedJavadocTests("test003"));
62 suite.addTest(new AttachedJavadocTests("test004"));
63 suite.addTest(new AttachedJavadocTests("test005"));
64 suite.addTest(new AttachedJavadocTests("test006"));
65 suite.addTest(new AttachedJavadocTests("test007"));
66 suite.addTest(new AttachedJavadocTests("test008"));
67 suite.addTest(new AttachedJavadocTests("test009"));
68 suite.addTest(new AttachedJavadocTests("test010"));
69 suite.addTest(new AttachedJavadocTests("test011"));
70 suite.addTest(new AttachedJavadocTests("test012"));
71 suite.addTest(new AttachedJavadocTests("test013"));
72 suite.addTest(new AttachedJavadocTests("test014"));
73 suite.addTest(new AttachedJavadocTests("test015"));
74 suite.addTest(new AttachedJavadocTests("test016"));
75 suite.addTest(new AttachedJavadocTests("test017"));
76 suite.addTest(new AttachedJavadocTests("test018"));
77 suite.addTest(new AttachedJavadocTests("test019"));
78 suite.addTest(new AttachedJavadocTests("test020"));
79 suite.addTest(new AttachedJavadocTests("test021"));
80 suite.addTest(new AttachedJavadocTests("test022"));
81 suite.addTest(new AttachedJavadocTests("test023"));
82 suite.addTest(new AttachedJavadocTests("test024"));
83 suite.addTest(new AttachedJavadocTests("test025"));
84 suite.addTest(new AttachedJavadocTests("testBug304394"));
85 suite.addTest(new AttachedJavadocTests("testBug304394a"));
86 suite.addTest(new AttachedJavadocTests("testBug320167"));
87 suite.addTest(new AttachedJavadocTests("testBug329671"));
88 suite.addTest(new AttachedJavadocTests("testBug334652"));
89 suite.addTest(new AttachedJavadocTests("testBug334652_2"));
90 suite.addTest(new AttachedJavadocTests("testBug334652_3"));
91 suite.addTest(new AttachedJavadocTests("testBug334652_4"));
Stephan Herrmannfa0b16c2011-08-25 12:46:28 +000092 suite.addTest(new AttachedJavadocTests("testBug354766"));
Stephan Herrmann92d73022011-11-10 09:47:45 +000093 suite.addTest(new AttachedJavadocTests("testBug354766_2"));
Stephan Herrmann918c05c2012-12-16 20:09:49 +010094 suite.addTest(new AttachedJavadocTests("testBug394967"));
95 suite.addTest(new AttachedJavadocTests("testBug394382"));
Stephan Herrmann28464e42013-02-02 16:25:14 +010096 suite.addTest(new AttachedJavadocTests("testBug398272"));
Stephan Herrmann1057e9a2011-03-10 18:42:56 +000097 return suite;
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +000098 }
99
100 private IJavaProject project;
101 private IPackageFragmentRoot root;
102
103 public AttachedJavadocTests(String name) {
104 super(name);
105 }
106
107 private void setJavadocLocationAttribute(String folderName) throws JavaModelException {
108 IClasspathEntry[] entries = this.project.getRawClasspath();
109 IResource resource = this.project.getProject().findMember("/"+folderName+"/"); //$NON-NLS-1$
110 assertNotNull("doc folder cannot be null", resource); //$NON-NLS-1$
111 URI locationURI = resource.getLocationURI();
112 assertNotNull("doc folder cannot be null", locationURI); //$NON-NLS-1$
113 URL docUrl = null;
114 try {
115 docUrl = locationURI.toURL();
116 } catch (MalformedURLException e) {
117 assertTrue("Should not happen", false); //$NON-NLS-1$
118 } catch(IllegalArgumentException e) {
119 assertTrue("Should not happen", false); //$NON-NLS-1$
120 }
121 IClasspathAttribute attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, docUrl.toExternalForm());
122 for (int i = 0, max = entries.length; i < max; i++) {
123 final IClasspathEntry entry = entries[i];
124 if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
125 && entry.getContentKind() == IPackageFragmentRoot.K_BINARY
126 && "/AttachedJavadocProject/lib/test6.jar".equals(entry.getPath().toString())) { //$NON-NLS-1$
127 entries[i] = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), new IClasspathAttribute[] { attribute}, entry.isExported());
128 }
129 }
130 this.project.setRawClasspath(entries, null);
131 }
132 /**
133 * Create project and set the jar placeholder.
134 */
135 public void setUpSuite() throws Exception {
136 super.setUpSuite();
137
138 this.project = setUpJavaProject("AttachedJavadocProject", "1.5"); //$NON-NLS-1$
139 Map options = this.project.getOptions(true);
140 options.put(JavaCore.TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC, "2000"); //$NON-NLS-1$
141 this.project.setOptions(options);
142 setJavadocLocationAttribute(DEFAULT_DOC_FOLDER);
143
144 IPackageFragmentRoot[] roots = this.project.getAllPackageFragmentRoots();
145 int count = 0;
146 for (int i = 0, max = roots.length; i < max; i++) {
147 final IPackageFragmentRoot packageFragmentRoot = roots[i];
148 switch(packageFragmentRoot.getKind()) {
149 case IPackageFragmentRoot.K_BINARY :
150 if (!packageFragmentRoot.isExternal()) {
151 count++;
152 if (this.root == null) {
153 this.root = packageFragmentRoot;
154 }
155 }
156 }
157 }
158 assertEquals("Wrong value", 1, count); //$NON-NLS-1$
159 assertNotNull("Should not be null", this.root); //$NON-NLS-1$
160 }
161
162 /**
163 * Reset the jar placeholder and delete project.
164 */
165 public void tearDownSuite() throws Exception {
166 this.deleteProject("AttachedJavadocProject"); //$NON-NLS-1$
167 this.root = null;
168 this.project = null;
169 super.tearDownSuite();
170 }
171
172 // test javadoc for a package fragment
173 public void test001() throws JavaModelException {
174 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
175 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
176 String javadoc = packageFragment.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
177 assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
178 }
179
180 // for a class file
181 public void test002() throws JavaModelException {
182 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
183 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
184 IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
185 assertNotNull(classFile);
186 String javadoc = classFile.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
187 assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
188 }
189
190 // for a field
191 public void test003() throws JavaModelException {
192 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
193 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
194 IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
195 assertNotNull(classFile);
196 IType type = classFile.getType();
197 IField field = type.getField("f"); //$NON-NLS-1$
198 assertNotNull(field);
199 String javadoc = field.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
200 assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
201 }
202
203 // for a method
204 public void test004() throws JavaModelException {
205 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
206 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
207 IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
208 assertNotNull(classFile);
209 IType type = classFile.getType();
210 IMethod method = type.getMethod("foo", new String[] {"I", "J", "Ljava.lang.String;"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
211 assertTrue(method.exists());
212 String javadoc = method.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
213 assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
214 String[] paramNames = method.getParameterNames();
215 assertNotNull(paramNames);
216 assertEquals("Wrong size", 3, paramNames.length); //$NON-NLS-1$
217 assertEquals("Wrong name for first param", "i", paramNames[0]); //$NON-NLS-1$ //$NON-NLS-2$
218 assertEquals("Wrong name for second param", "l", paramNames[1]); //$NON-NLS-1$ //$NON-NLS-2$
219 assertEquals("Wrong name for third param", "s", paramNames[2]); //$NON-NLS-1$ //$NON-NLS-2$
220 }
221
222 // for a constructor
223 public void test005() throws JavaModelException {
224 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
225 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
226 IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
227 assertNotNull(classFile);
228 IType type = classFile.getType();
229 IMethod method = type.getMethod("X", new String[] {"I"}); //$NON-NLS-1$ //$NON-NLS-2$
230 assertTrue(method.exists());
231 String javadoc = method.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
232 assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
233 String[] paramNames = method.getParameterNames();
234 assertNotNull(paramNames);
235 assertEquals("Wrong size", 1, paramNames.length); //$NON-NLS-1$
236 assertEquals("Wrong name for first param", "i", paramNames[0]); //$NON-NLS-1$ //$NON-NLS-2$
237 }
238
239 // for a member type
240 public void test006() throws JavaModelException {
241 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
242 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
243 IClassFile classFile = packageFragment.getClassFile("X$A.class"); //$NON-NLS-1$
244 assertNotNull(classFile);
245 String javadoc = classFile.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
246 assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
247 }
248
249 // for a constructor
250 public void test007() throws JavaModelException {
251 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
252 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
253 IClassFile classFile = packageFragment.getClassFile("X$A.class"); //$NON-NLS-1$
254 assertNotNull(classFile);
255 IType type = classFile.getType();
256 IMethod method = type.getMethod("A", new String[] {"Lp1.p2.X;", "F"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
257 assertTrue(method.exists());
258 String javadoc = method.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
259 assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
260 String[] paramNames = method.getParameterNames();
261 assertNotNull(paramNames);
262 assertEquals("Wrong size", 1, paramNames.length); //$NON-NLS-1$
263 assertEquals("Wrong name for first param", "f", paramNames[0]); //$NON-NLS-1$ //$NON-NLS-2$
264 }
265
266 // for a method foo2
267 public void test008() throws JavaModelException {
268 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
269 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
270 IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
271 assertNotNull(classFile);
272 IType type = classFile.getType();
273 IMethod method = type.getMethod("foo2", new String[0]); //$NON-NLS-1$
274 assertTrue(method.exists());
275 String javadoc = method.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
276 assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
277 String[] paramNames = method.getParameterNames();
278 assertNotNull(paramNames);
279 assertEquals("Wrong size", 0, paramNames.length); //$NON-NLS-1$
280 }
281
282 // for a field f2
283 public void test009() throws JavaModelException {
284 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
285 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
286 IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
287 assertNotNull(classFile);
288 IType type = classFile.getType();
289 IField field = type.getField("f2"); //$NON-NLS-1$
290 assertNotNull(field);
291 String javadoc = field.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
292 assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
293 }
294
295 // test archive doc
296 public void test010() throws JavaModelException {
297 IClasspathEntry[] savedEntries = null;
298 try {
299 IClasspathEntry[] entries = this.project.getRawClasspath();
300 savedEntries = (IClasspathEntry[]) entries.clone();
301 IResource resource = this.project.getProject().findMember("/doc.zip"); //$NON-NLS-1$
302 assertNotNull("doc folder cannot be null", resource); //$NON-NLS-1$
303 URI locationURI = resource.getLocationURI();
304 assertNotNull("doc folder cannot be null", locationURI); //$NON-NLS-1$
305 URL docUrl = null;
306 try {
307 docUrl = locationURI.toURL();
308 } catch (MalformedURLException e) {
309 assertTrue("Should not happen", false); //$NON-NLS-1$
310 } catch(IllegalArgumentException e) {
311 assertTrue("Should not happen", false); //$NON-NLS-1$
312 }
313 final String path = "jar:" + docUrl.toExternalForm() + "!/doc"; //$NON-NLS-1$ //$NON-NLS-2$
314 //final String path = "jar:" + "platform:/resource/AttachedJavadocProject/doc.zip" + "!/doc";
315 IClasspathAttribute attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, path);
316 for (int i = 0, max = entries.length; i < max; i++) {
317 final IClasspathEntry entry = entries[i];
318 if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
319 && entry.getContentKind() == IPackageFragmentRoot.K_BINARY
320 && "/AttachedJavadocProject/lib/test6.jar".equals(entry.getPath().toString())) { //$NON-NLS-1$
321 entries[i] = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), new IClasspathAttribute[] { attribute }, entry.isExported());
322 }
323 }
324 this.project.setRawClasspath(entries, null);
325 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
326 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
327 IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
328 assertNotNull(classFile);
329 IType type = classFile.getType();
330 IField field = type.getField("f"); //$NON-NLS-1$
331 assertNotNull(field);
332 String javadoc = field.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
333 assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
334 } finally {
335 // restore classpath
336 if (savedEntries != null) {
337 this.project.setRawClasspath(savedEntries, null);
338 }
339 }
340 }
341
342 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=120597
343 public void test011() throws JavaModelException {
344 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
345 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
346 IClassFile classFile = packageFragment.getClassFile("Z.class"); //$NON-NLS-1$
347 assertNotNull(classFile);
348 IType type = classFile.getType();
349 IField field = type.getField("out"); //$NON-NLS-1$
350 assertNotNull(field);
351 String javadoc = field.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
352 assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
353 }
354
355 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=120637
356 public void test012() throws JavaModelException {
357 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
358 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
359 IClassFile classFile = packageFragment.getClassFile("Z.class"); //$NON-NLS-1$
360 assertNotNull(classFile);
361 String javadoc = classFile.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
362 assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
363 assertTrue("Should not contain reference to out", javadoc.indexOf("out") == -1);
364 }
365
366 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=120559
367 public void test013() throws JavaModelException {
368 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
369 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
370 IClassFile classFile = packageFragment.getClassFile("W.class"); //$NON-NLS-1$
371 assertNotNull(classFile);
372 String javadoc = classFile.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
373 assertNull("Should not have a javadoc", javadoc); //$NON-NLS-1$
374 }
375
376 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=120637
377 public void test014() throws JavaModelException {
378 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
379 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
380 IClassFile classFile = packageFragment.getClassFile("E.class"); //$NON-NLS-1$
381 assertNotNull(classFile);
382 String javadoc = classFile.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
383 assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
384 assertTrue("Should not contain reference to Constant C", javadoc.indexOf("Constant C") == -1);
385 }
386
387 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=120637
388 public void test015() throws JavaModelException {
389 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
390 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
391 IClassFile classFile = packageFragment.getClassFile("Annot.class"); //$NON-NLS-1$
392 assertNotNull(classFile);
393 String javadoc = classFile.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
394 assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
395 assertTrue("Should not contain reference to name", javadoc.indexOf("name") == -1);
396 }
397
398 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=120847
399 public void test016() throws JavaModelException {
400 IClasspathEntry[] savedEntries = null;
401 try {
402 IClasspathEntry[] entries = this.project.getRawClasspath();
403 savedEntries = (IClasspathEntry[]) entries.clone();
404 IClasspathAttribute attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, "invalid_path");
405 for (int i = 0, max = entries.length; i < max; i++) {
406 final IClasspathEntry entry = entries[i];
407 if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
408 && entry.getContentKind() == IPackageFragmentRoot.K_BINARY
409 && "/AttachedJavadocProject/lib/test6.jar".equals(entry.getPath().toString())) { //$NON-NLS-1$
410 entries[i] = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), new IClasspathAttribute[] { attribute }, entry.isExported());
411 }
412 }
413 this.project.setRawClasspath(entries, null);
414 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
415 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
416 IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
417 assertNotNull(classFile);
418 IType type = classFile.getType();
419 IField field = type.getField("f"); //$NON-NLS-1$
420 assertNotNull(field);
421 field.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
422 assertFalse("Should be unreachable", true);
423 } catch(JavaModelException e) {
424 assertTrue("Must occur", true);
425 assertEquals("Wrong error message", "Cannot retrieve the attached javadoc for invalid_path", e.getMessage());
426 } finally {
427 // restore classpath
428 if (savedEntries != null) {
429 this.project.setRawClasspath(savedEntries, null);
430 }
431 }
432 }
433
434 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=120875
435 public void test017() throws JavaModelException {
436 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
437 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
438 IClassFile classFile = packageFragment.getClassFile("Annot2.class"); //$NON-NLS-1$
439 assertNotNull(classFile);
440 String javadoc = classFile.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
441 assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
442 assertTrue("Should not contain reference to name2", javadoc.indexOf("name2") == -1);
443 }
444
445 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=138167
446 public void test018() throws JavaModelException {
447 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2.p3"); //$NON-NLS-1$
448 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
449 IClassFile classFile = packageFragment.getClassFile("C.class"); //$NON-NLS-1$
450 assertNotNull(classFile);
451 IType type = classFile.getType();
452 IMethod[] methods = type.getMethods();
453 NullProgressMonitor monitor = new NullProgressMonitor();
454 for (int i = 0, max = methods.length; i < max; i++) {
455 IMethod method = methods[i];
456 String javadoc = method.getAttachedJavadoc(monitor);
457 assertNotNull("Should have a javadoc", javadoc);
458 final String selector = method.getElementName();
459 assertTrue("Wrong doc", javadoc.indexOf(selector) != -1);
460 }
461 }
462
463 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=138167
464 public void test019() throws JavaModelException {
465 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2.p3"); //$NON-NLS-1$
466 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
467 IClassFile classFile = packageFragment.getClassFile("C.class"); //$NON-NLS-1$
468 assertNotNull(classFile);
469 IType type = classFile.getType();
470 IMethod method = type.getMethod("bar5", new String[] {"Ljava.util.Map<TK;TV;>;", "I", "Ljava.util.Map<TK;TV;>;"}); //$NON-NLS-1$
471 assertTrue(method.exists());
472 String javadoc = method.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
473 assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
474 String[] names = method.getParameterNames();
475 assertNotNull("No names", names);
476 assertEquals("Wrong size", 3, names.length);
477 assertEquals("Wrong parameter name", "m", names[0]);
478 assertEquals("Wrong parameter name", "j", names[1]);
479 assertEquals("Wrong parameter name", "m2", names[2]);
480 }
481
482 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=139160
483 public void test020() throws JavaModelException {
484 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
485 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
486 IClassFile classFile = packageFragment.getClassFile("Z.class"); //$NON-NLS-1$
487 assertNotNull(classFile);
488 IType type = classFile.getType();
489 IMethod method = type.getMethod("foo", new String[] {"I", "I"}); //$NON-NLS-1$
490 assertTrue(method.exists());
491 String javadoc = null;
492 try {
493 javadoc = method.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
494 } catch(JavaModelException e) {
495 assertTrue("Should not happen", false);
496 }
497 assertNull("Should not have a javadoc", javadoc); //$NON-NLS-1$
498 String[] paramNames = method.getParameterNames();
499 assertNotNull(paramNames);
500 assertEquals("Wrong size", 2, paramNames.length); //$NON-NLS-1$
501 assertEquals("Wrong name", "i", paramNames[0]); //$NON-NLS-1$
502 assertEquals("Wrong name", "j", paramNames[1]); //$NON-NLS-1$
503 }
504
505 /*
506 * Ensures that calling getAttachedJavadoc(...) on a binary method
507 * has no side-effect on the underlying Java model cache.
508 * (regression test for bug 140879 Spontaneous error "java.util.Set cannot be resolved...")
509 */
510 public void test021() throws CoreException, IOException {
511 ICompilationUnit workingCopy = null;
512 try {
513 IPackageFragment p = this.root.getPackageFragment("p2");
514 IType type = p.getClassFile("X.class").getType();
515 IMethod method = type.getMethod("foo", new String[0]);
516
517 // the following call should have no side-effect
518 method.getAttachedJavadoc(null);
519
520 // ensure no side-effect
521 ProblemRequestor problemRequestor = new ProblemRequestor();
522 workingCopy = getWorkingCopy(
523 "/AttachedJavadocProject/src/Test.java",
524 "import p2.Y;\n" +
525 "public class Test extends Y { }",
526 newWorkingCopyOwner(problemRequestor)
527 );
528 assertProblems(
529 "Unexpected problems",
530 "----------\n" +
531 "----------\n",
532 problemRequestor);
533 } finally {
534 if (workingCopy != null)
535 workingCopy.discardWorkingCopy();
536 deleteProject("P");
537 }
538 }
539
540 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=149154
541 public void test022() throws JavaModelException {
542 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
543 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
544 IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
545 assertNotNull(classFile);
546 IType type = classFile.getType();
547 IMethod method = type.getMethod("access$1", new String[] {"Lp1.p2.X;", "I"}); //$NON-NLS-1$
548 assertTrue(method.exists());
549 String javadoc = null;
550 try {
551 javadoc = method.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
552 } catch(JavaModelException e) {
553 assertTrue("Should not happen", false);
554 }
555 assertNull("Should not have a javadoc", javadoc); //$NON-NLS-1$
556 String[] paramNames = method.getParameterNames();
557 assertNotNull(paramNames);
558 assertEquals("Wrong size", 2, paramNames.length); //$NON-NLS-1$
559 assertEquals("Wrong name", "arg0", paramNames[0]); //$NON-NLS-1$
560 assertEquals("Wrong name", "arg1", paramNames[1]); //$NON-NLS-1$
561 }
562
563 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=221723
564 // for a method
565 public void test023() throws JavaModelException {
566 try {
567 setJavadocLocationAttribute("specialDoc");
568
569 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
570 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
571 IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
572 assertNotNull(classFile);
573 IType type = classFile.getType();
574 IMethod method = type.getMethod("foo", new String[] {"I", "J", "Ljava.lang.String;"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
575 assertTrue(method.exists());
576 String javadoc = method.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
577 assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
578 String[] paramNames = method.getParameterNames();
579 assertNotNull(paramNames);
580 assertEquals("Wrong size", 3, paramNames.length); //$NON-NLS-1$
581 assertEquals("Wrong name for first param", "i", paramNames[0]); //$NON-NLS-1$ //$NON-NLS-2$
582 assertEquals("Wrong name for second param", "l", paramNames[1]); //$NON-NLS-1$ //$NON-NLS-2$
583 assertEquals("Wrong name for third param", "s", paramNames[2]); //$NON-NLS-1$ //$NON-NLS-2$
584 } finally {
585 setJavadocLocationAttribute(DEFAULT_DOC_FOLDER);
586 }
587 }
588 // for a private field
589 public void test024() throws JavaModelException {
590 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
591 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
592 IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
593 assertNotNull(classFile);
594 IType type = classFile.getType();
595 IField field = type.getField("f4"); //$NON-NLS-1$
596 assertNotNull(field);
597 String javadoc = field.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
598 assertNull("Should have no javadoc", javadoc); //$NON-NLS-1$
599 }
Stephan Herrmann13a070b2010-04-02 03:54:26 +0000600 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=304316
601 public void test025() throws JavaModelException {
602 IClasspathEntry[] savedEntries = null;
603 try {
604 IClasspathEntry[] entries = this.project.getRawClasspath();
605 savedEntries = (IClasspathEntry[]) entries.clone();
Stephan Herrmann618f6922012-08-10 22:00:05 +0200606 final String path = "http:/download.oracle.com/javase/6/docs/api/"; //$NON-NLS-1$
Stephan Herrmann13a070b2010-04-02 03:54:26 +0000607 IClasspathAttribute attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, path);
608 for (int i = 0, max = entries.length; i < max; i++) {
609 final IClasspathEntry entry = entries[i];
610 if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
611 && entry.getContentKind() == IPackageFragmentRoot.K_BINARY
612 && "/AttachedJavadocProject/lib/test6.jar".equals(entry.getPath().toString())) { //$NON-NLS-1$
613 entries[i] = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), new IClasspathAttribute[] { attribute }, entry.isExported());
614 }
615 }
616 this.project.setRawClasspath(entries, null);
617 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
618 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
619 IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
620 assertNotNull(classFile);
621 IType type = classFile.getType();
622 IField field = type.getField("f"); //$NON-NLS-1$
623 assertNotNull(field);
624 String javadoc = field.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
625 assertNull("Should not have a javadoc", javadoc); //$NON-NLS-1$
626 } finally {
627 // restore classpath
628 if (savedEntries != null) {
629 this.project.setRawClasspath(savedEntries, null);
630 }
631 }
632 }
Stephan Herrmann0717d572010-04-21 22:04:13 +0000633 /**
634 * @bug 304394: IJavaElement#getAttachedJavadoc(IProgressMonitor) should support referenced entries
635 * Test that javadoc is picked up from the referenced classpath entry when the javadoc location is added
636 * to that entry
637 *
638 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=304394"
639 * @throws Exception
640 */
641 public void testBug304394() throws Exception {
642 setJavadocLocationAttribute("specialDoc");
643 IClasspathEntry[] savedEntries = null;
644 try {
645 IClasspathEntry[] entries = this.project.getRawClasspath();
646 savedEntries = (IClasspathEntry[]) entries.clone();
647 IClasspathEntry chainedJar = null;
648 int max = entries.length;
649 for (int i = 0; i < max; i++) {
650 final IClasspathEntry entry = entries[i];
651 if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
652 && entry.getContentKind() == IPackageFragmentRoot.K_BINARY
653 && "/AttachedJavadocProject/lib/test6.jar".equals(entry.getPath().toString())) { //$NON-NLS-1$
654
655 chainedJar = entries[i];
656 addLibrary(this.project, "/lib/chaining.jar", null, new String[0],
657 new String[] {
658 "META-INF/MANIFEST.MF",
659 "Manifest-Version: 1.0\n" +
660 "Class-Path: test6.jar\n",
661 },
662 JavaCore.VERSION_1_4);
663 IPath jarPath = this.project.getPath().append("lib").append("chaining.jar");
664 entries[i] = JavaCore.newLibraryEntry(jarPath, entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath());
665 break;
666 }
667 }
668
669 this.project.setRawClasspath(entries, new IClasspathEntry[]{chainedJar}, this.project.getOutputLocation(), null);
670 waitForAutoBuild();
671
672 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
673 IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
674 IType type = classFile.getType();
675 IMethod method = type.getMethod("foo", new String[] {"I", "J", "Ljava.lang.String;"}); //$NON-NLS-1$
676 String javadoc = method.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
677 assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
678 } finally {
679 // restore classpath
680 if (savedEntries != null) {
681 this.project.setRawClasspath(savedEntries, null);
682 }
683 removeLibrary(this.project, "/lib/chaining.jar", null);
684 }
685 }
686 /**
687 * Additional test for bug 304394.
688 * Test that javadoc is picked up from the raw classpath entry when the referenced entry doesn't
689 * contain the javadoc location attrribute.
690 *
691 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=304394"
692 * @throws Exception
693 */
694 public void testBug304394a() throws Exception {
695 setJavadocLocationAttribute("specialDoc");
696 IClasspathEntry[] savedEntries = null;
697 try {
698 IClasspathEntry[] entries = this.project.getRawClasspath();
699 savedEntries = (IClasspathEntry[]) entries.clone();
700 IClasspathEntry chainedJar = null;
701 int max = entries.length;
702 for (int i = 0; i < max; i++) {
703 final IClasspathEntry entry = entries[i];
704 if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
705 && entry.getContentKind() == IPackageFragmentRoot.K_BINARY
706 && "/AttachedJavadocProject/lib/test6.jar".equals(entry.getPath().toString())) { //$NON-NLS-1$
707
708 chainedJar = entries[i];
709 addLibrary(this.project, "/lib/chaining.jar", null, new String[0],
710 new String[] {
711 "META-INF/MANIFEST.MF",
712 "Manifest-Version: 1.0\n" +
713 "Class-Path: test6.jar\n",
714 },
715 JavaCore.VERSION_1_4);
716 IPath jarPath = this.project.getPath().append("lib").append("chaining.jar");
717 entries[i] = JavaCore.newLibraryEntry(jarPath, entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported());
718 break;
719 }
720 }
721
722 chainedJar = JavaCore.newLibraryEntry(chainedJar.getPath(), null, null, null, null, chainedJar.isExported());
723 this.project.setRawClasspath(entries, new IClasspathEntry[]{chainedJar}, this.project.getOutputLocation(), null);
724 waitForAutoBuild();
725
726 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
727 IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
728 IType type = classFile.getType();
729 IMethod method = type.getMethod("foo", new String[] {"I", "J", "Ljava.lang.String;"}); //$NON-NLS-1$
730 String javadoc = method.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
731 assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
732 } finally {
733 // restore classpath
734 if (savedEntries != null) {
735 this.project.setRawClasspath(savedEntries, null);
736 }
737 removeLibrary(this.project, "/lib/chaining.jar", null);
738 }
Stephan Herrmannae5583a2010-09-26 16:41:40 +0000739 }
740 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=320167
741 // Test to verify that while trying to get javadoc contents from a malformed
742 // javadoc, CharOperation doesnt throw an IOOBE
743 public void testBug320167() throws JavaModelException {
744 try {
745 setJavadocLocationAttribute("malformedDoc");
746
747 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
748 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
749 IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
750 assertNotNull(classFile);
751 IType type = classFile.getType();
752 IMethod method = type.getMethod("foo", new String[] {"I", "J", "Ljava.lang.String;"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
753 assertTrue(method.exists());
754 String javadoc = method.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
755 assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
756 String[] paramNames = method.getParameterNames();
757 assertNotNull(paramNames);
758 assertEquals("Wrong size", 3, paramNames.length); //$NON-NLS-1$
759 assertEquals("Wrong name for first param", "i", paramNames[0]); //$NON-NLS-1$ //$NON-NLS-2$
760 assertEquals("Wrong name for second param", "l", paramNames[1]); //$NON-NLS-1$ //$NON-NLS-2$
761 assertEquals("Wrong name for third param", "s", paramNames[2]); //$NON-NLS-1$ //$NON-NLS-2$
762 } catch (IndexOutOfBoundsException e) {
763 assertTrue("Should not happen", false);
764 } catch (JavaModelException e) {
765 assertTrue("Should happen", true);
766 } finally {
767 setJavadocLocationAttribute(DEFAULT_DOC_FOLDER);
768 }
769 }
Stephan Herrmannebb81ec2010-12-11 19:33:12 +0000770 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=329671
771 public void testBug329671() throws CoreException, IOException {
772 Map options = this.project.getOptions(true);
773 Object timeout = options.get(JavaCore.TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC);
774 options.put(JavaCore.TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC, "0"); //$NON-NLS-1$
775 this.project.setOptions(options);
776 IClasspathEntry[] entries = this.project.getRawClasspath();
777
778 try {
779 IClasspathAttribute attribute =
780 JavaCore.newClasspathAttribute(
781 IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
782 "jar:platform:/resource/AttachedJavadocProject/bug329671_doc.zip!/");
783 IClasspathEntry newEntry = JavaCore.newLibraryEntry(new Path("/AttachedJavadocProject/bug329671.jar"), null, null, null, new IClasspathAttribute[] { attribute}, false);
784 this.project.setRawClasspath(new IClasspathEntry[]{newEntry}, null);
785 this.project.getResolvedClasspath(false);
786
787 IPackageFragmentRoot jarRoot = this.project.getPackageFragmentRoot(getFile("/AttachedJavadocProject/bug329671.jar"));
788 final IType type = jarRoot.getPackageFragment("bug").getClassFile("X.class").getType();
789 IMethod method = type.getMethod("foo", new String[]{"Ljava.lang.Object;"});
790 assertNotNull(method);
791
792 String[] paramNames = method.getParameterNames();
793 assertStringsEqual("Parameter names", new String[]{"arg0"}, paramNames);
794 final PerProjectInfo projectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(this.project.getProject());
795 final Object varThis = this;
796 Thread thread = new Thread(){
797 public void run() {
798 Object javadocContent = projectInfo.javadocCache.get(type);
799 while(javadocContent == null || javadocContent == BinaryType.EMPTY_JAVADOC) {
800 try {
801 Thread.sleep(50);
802 javadocContent = projectInfo.javadocCache.get(type);
803 } catch (InterruptedException e) {
804 }
805 synchronized (varThis) {
806 varThis.notify();
807 }
808 }
809 }
810 };
811 thread.start();
812 synchronized (varThis) {
813 try {
814 varThis.wait(5000);
815 } catch (InterruptedException e) {
816 e.printStackTrace();
817 }
818 }
819 projectInfo.javadocCache.flush();
820 options.put(JavaCore.TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC, "5000"); //$NON-NLS-1$
821 this.project.setOptions(options);
822 paramNames = method.getParameterNames();
823 assertStringsEqual("Parameter names", new String[]{"param"}, paramNames);
824 } finally {
825 this.project.setRawClasspath(entries, null);
826 if (timeout != null)
827 options.put(JavaCore.TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC, timeout);
828 this.project.setOptions(options);
829 }
830 }
Stephan Herrmann192b65f2011-01-27 12:07:40 +0000831 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=334652
832 public void testBug334652() throws CoreException, IOException {
833 IClasspathEntry[] entries = this.project.getRawClasspath();
834
835 try {
836 IClasspathAttribute attribute =
837 JavaCore.newClasspathAttribute(
838 IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
839 "jar:platform:/resource/AttachedJavadocProject/bug334652_doc.zip!/NoJavaDocForInnerClass/doc");
840 IClasspathEntry newEntry = JavaCore.newLibraryEntry(new Path("/AttachedJavadocProject/bug334652.jar"), null, null, null, new IClasspathAttribute[] { attribute}, false);
841 this.project.setRawClasspath(new IClasspathEntry[]{newEntry}, null);
842 this.project.getResolvedClasspath(false);
843
844 IPackageFragmentRoot jarRoot = this.project.getPackageFragmentRoot(getFile("/AttachedJavadocProject/bug334652.jar"));
845 final IType type = jarRoot.getPackageFragment("com.test").getClassFile("PublicAbstractClass$InnerFinalException.class").getType();
846 IMethod method = type.getMethod("InnerFinalException", new String[] { "Lcom.test.PublicAbstractClass;", "Ljava.lang.String;", "Ljava.lang.String;"});
847 assertNotNull(method);
848 assertTrue("Does not exist", method.exists());
849
850 String javadoc = method.getAttachedJavadoc(null);
851 assertNotNull(javadoc);
852 assertEquals("Wrong contents", "<H3>\r\n" +
853 "PublicAbstractClass.InnerFinalException</H3>\r\n" +
854 "<PRE>\r\n" +
855 "public <B>PublicAbstractClass.InnerFinalException</B>(java.lang.String&nbsp;property,\r\n" +
856 " java.lang.String&nbsp;msg)</PRE>\r\n" +
857 "<DL>\r\n" +
858 "<DD>javadoc for InnerFinalException(String property, String msg)\r\n" +
859 "<P>\r\n" +
860 "<DL>\r\n" +
861 "<DT><B>Parameters:</B><DD><CODE>property</CODE> - the property argument<DD><CODE>msg</CODE> - the message argument</DL>\r\n" +
862 "</DL>\r\n", javadoc);
863 } finally {
864 this.project.setRawClasspath(entries, null);
865 }
866 }
867 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=334652
868 public void testBug334652_2() throws CoreException, IOException {
869 IClasspathEntry[] entries = this.project.getRawClasspath();
870
871 try {
872 IClasspathAttribute attribute =
873 JavaCore.newClasspathAttribute(
874 IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
875 "jar:platform:/resource/AttachedJavadocProject/bug334652(2)_doc.zip!/doc");
876 IClasspathEntry newEntry = JavaCore.newLibraryEntry(new Path("/AttachedJavadocProject/bug334652(2).jar"), null, null, null, new IClasspathAttribute[] { attribute}, false);
877 this.project.setRawClasspath(new IClasspathEntry[]{newEntry}, null);
878 this.project.getResolvedClasspath(false);
879
880 IPackageFragmentRoot jarRoot = this.project.getPackageFragmentRoot(getFile("/AttachedJavadocProject/bug334652(2).jar"));
881 final IType type = jarRoot.getPackageFragment("com.test").getClassFile("PublicAbstractClass$InnerFinalException.class").getType();
882 IMethod method = type.getMethod("InnerFinalException", new String[] { "Ljava.lang.String;", "Ljava.lang.String;"});
883 assertNotNull(method);
884 assertTrue("Does not exist", method.exists());
885
886 String javadoc = method.getAttachedJavadoc(null);
887 assertNotNull(javadoc);
888 assertEquals("Wrong contents", "<H3>\r\n" +
889 "PublicAbstractClass.InnerFinalException</H3>\r\n" +
890 "<PRE>\r\n" +
891 "public <B>PublicAbstractClass.InnerFinalException</B>(java.lang.String&nbsp;property,\r\n" +
892 " java.lang.String&nbsp;msg)</PRE>\r\n" +
893 "<DL>\r\n" +
894 "<DD>javadoc for InnerFinalException(String property, String msg)\r\n" +
895 "<P>\r\n" +
896 "<DL>\r\n" +
897 "<DT><B>Parameters:</B><DD><CODE>property</CODE> - the property argument<DD><CODE>msg</CODE> - the message argument</DL>\r\n" +
898 "</DL>\r\n", javadoc);
899 } finally {
900 this.project.setRawClasspath(entries, null);
901 }
902 }
903 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=334652
904 public void testBug334652_3() throws CoreException, IOException {
905 IClasspathEntry[] entries = this.project.getRawClasspath();
906
907 try {
908 IClasspathAttribute attribute =
909 JavaCore.newClasspathAttribute(
910 IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
911 "jar:platform:/resource/AttachedJavadocProject/bug334652(3)_doc.zip!/doc");
912 IClasspathEntry newEntry = JavaCore.newLibraryEntry(new Path("/AttachedJavadocProject/bug334652(3).jar"), null, null, null, new IClasspathAttribute[] { attribute}, false);
913 this.project.setRawClasspath(new IClasspathEntry[]{newEntry}, null);
914 this.project.getResolvedClasspath(false);
915
916 IPackageFragmentRoot jarRoot = this.project.getPackageFragmentRoot(getFile("/AttachedJavadocProject/bug334652(3).jar"));
917 final IType type = jarRoot.getPackageFragment("com.test").getClassFile("PublicAbstractClass$A$InnerFinalException.class").getType();
918 IMethod method = type.getMethod("InnerFinalException", new String[] { "Lcom.test.PublicAbstractClass$A;", "Ljava.lang.String;", "Ljava.lang.String;"});
919 assertNotNull(method);
920 assertTrue("Does not exist", method.exists());
921
922 String javadoc = method.getAttachedJavadoc(null);
923 assertNotNull(javadoc);
924 assertEquals("Wrong contents",
925 "<H3>\r\n" +
926 "PublicAbstractClass.A.InnerFinalException</H3>\r\n" +
927 "<PRE>\r\n" +
928 "public <B>PublicAbstractClass.A.InnerFinalException</B>(java.lang.String&nbsp;property,\r\n" +
929 " java.lang.String&nbsp;msg)</PRE>\r\n" +
930 "<DL>\r\n" +
931 "<DD>javadoc for InnerFinalException(String property, String msg)\r\n" +
932 "<P>\r\n" +
933 "<DL>\r\n" +
934 "<DT><B>Parameters:</B><DD><CODE>property</CODE> - the property argument<DD><CODE>msg</CODE> - the message argument</DL>\r\n" +
935 "</DL>\r\n", javadoc);
936 } finally {
937 this.project.setRawClasspath(entries, null);
938 }
939 }
940 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=334652
941 public void testBug334652_4() throws CoreException, IOException {
942 IClasspathEntry[] entries = this.project.getRawClasspath();
943
944 try {
945 IClasspathAttribute attribute =
946 JavaCore.newClasspathAttribute(
947 IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
948 "jar:platform:/resource/AttachedJavadocProject/bug334652(4)_doc.zip!/doc");
949 IClasspathEntry newEntry = JavaCore.newLibraryEntry(new Path("/AttachedJavadocProject/bug334652(4).jar"), null, null, null, new IClasspathAttribute[] { attribute}, false);
950 this.project.setRawClasspath(new IClasspathEntry[]{newEntry}, null);
951 this.project.getResolvedClasspath(false);
952
953 IPackageFragmentRoot jarRoot = this.project.getPackageFragmentRoot(getFile("/AttachedJavadocProject/bug334652(4).jar"));
954 final IType type = jarRoot.getPackageFragment("com.test").getClassFile("PublicAbstractClass$A$InnerFinalException.class").getType();
955 IMethod method = type.getMethod("InnerFinalException", new String[] { "Lcom.test.PublicAbstractClass$A;", "Ljava.lang.String;", "Ljava.lang.String;"});
956 assertNotNull(method);
957 assertTrue("Does not exist", method.exists());
958
959 String javadoc = method.getAttachedJavadoc(null);
960 assertNotNull(javadoc);
961 assertEquals("Wrong contents", "<H3>\r\n" +
962 "PublicAbstractClass.A.InnerFinalException</H3>\r\n" +
963 "<PRE>\r\n" +
964 "public <B>PublicAbstractClass.A.InnerFinalException</B>(java.lang.String&nbsp;property,\r\n" +
965 " java.lang.String&nbsp;msg)</PRE>\r\n" +
966 "<DL>\r\n" +
967 "<DD>javadoc for InnerFinalException(String property, String msg)\r\n" +
968 "<P>\r\n" +
969 "<DL>\r\n" +
970 "<DT><B>Parameters:</B><DD><CODE>property</CODE> - the property argument<DD><CODE>msg</CODE> - the message argument</DL>\r\n" +
971 "</DL>\r\n", javadoc);
972 } finally {
973 this.project.setRawClasspath(entries, null);
974 }
975 }
Stephan Herrmannfa0b16c2011-08-25 12:46:28 +0000976 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=354766
977 public void testBug354766() throws CoreException, IOException {
978 IClasspathEntry[] entries = this.project.getRawClasspath();
979
980 try {
981 IClasspathAttribute attribute =
982 JavaCore.newClasspathAttribute(
983 IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
984 "jar:platform:/resource/AttachedJavadocProject/bug354766_doc.zip!/");
985 IClasspathEntry newEntry = JavaCore.newLibraryEntry(new Path("/AttachedJavadocProject/bug354766.jar"), null, null, null, new IClasspathAttribute[] { attribute}, false);
986 this.project.setRawClasspath(new IClasspathEntry[]{newEntry}, null);
987 this.project.getResolvedClasspath(false);
988
989 IPackageFragmentRoot jarRoot = this.project.getPackageFragmentRoot(getFile("/AttachedJavadocProject/bug354766.jar"));
990 final IType type = jarRoot.getPackageFragment("com.test").getClassFile("PublicAbstractClass$InnerFinalException.class").getType();
991 IMethod method = type.getMethod("foo", new String[0]);
992 assertNotNull(method);
993 assertTrue("Does not exist", method.exists());
994
995 String javadoc = method.getAttachedJavadoc(null);
996 assertNotNull(javadoc);
997 assertEquals(
998 "Wrong contents",
999 "<H3>\r\n" +
1000 "foo</H3>\r\n" +
1001 "<PRE>\r\n" +
1002 "public void <B>foo</B>()</PRE>\r\n" +
1003 "<DL>\r\n" +
1004 "<DD>Test method\r\n" +
1005 "<P>\r\n" +
1006 "<DD><DL>\r\n" +
1007 "</DL>\r\n" +
1008 "</DD>\r\n" +
1009 "</DL>\r\n",
1010 javadoc);
1011 } finally {
1012 this.project.setRawClasspath(entries, null);
1013 }
1014 }
Stephan Herrmann92d73022011-11-10 09:47:45 +00001015 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=354766
1016 public void testBug354766_2() throws CoreException, IOException {
1017 IClasspathEntry[] entries = this.project.getRawClasspath();
1018
1019 try {
1020 IClasspathAttribute attribute =
1021 JavaCore.newClasspathAttribute(
1022 IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
1023 "jar:platform:/resource/AttachedJavadocProject/bug354766_doc.zip!/");
1024 IClasspathEntry newEntry = JavaCore.newLibraryEntry(new Path("/AttachedJavadocProject/bug354766.jar"), null, null, null, new IClasspathAttribute[] { attribute}, false);
1025 this.project.setRawClasspath(new IClasspathEntry[]{newEntry}, null);
1026 this.project.getResolvedClasspath(false);
1027
1028 IPackageFragmentRoot jarRoot = this.project.getPackageFragmentRoot(getFile("/AttachedJavadocProject/bug354766.jar"));
1029 final IType type = jarRoot.getPackageFragment("com.test").getClassFile("PublicAbstractClass$InnerFinalException.class").getType();
1030 IMethod method = type.getMethod("InnerFinalException", new String[] { "Lcom.test.PublicAbstractClass;"});
1031 assertNotNull(method);
1032 assertTrue("Does not exist", method.exists());
1033
1034 String javadoc = method.getAttachedJavadoc(null);
1035 assertNotNull(javadoc);
1036 assertEquals(
1037 "Wrong contents",
1038 "<H3>\r\n" +
1039 "PublicAbstractClass.InnerFinalException</H3>\r\n" +
1040 "<PRE>\r\n" +
1041 "public <B>PublicAbstractClass.InnerFinalException</B>()</PRE>\r\n" +
1042 "<DL>\r\n" +
1043 "<DD>javadoc for InnerFinalException()\r\n" +
1044 "<P>\r\n" +
1045 "</DL>\r\n" +
1046 "\r\n" +
1047 "<!-- ============ METHOD DETAIL ========== -->\r\n" +
1048 "\r\n",
1049 javadoc);
1050 } finally {
1051 this.project.setRawClasspath(entries, null);
1052 }
1053 }
Stephan Herrmann918c05c2012-12-16 20:09:49 +01001054 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=394967
1055 public void testBug394967() throws JavaModelException {
1056 IClasspathEntry[] entries = this.project.getRawClasspath();
1057 try {
1058 IClasspathAttribute attribute =
1059 JavaCore.newClasspathAttribute(
1060 IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
1061 "jar:platform:/resource/AttachedJavadocProject/bug394967_doc.zip!/");
1062 IClasspathEntry newEntry = JavaCore.newLibraryEntry(new Path("/AttachedJavadocProject/bug394967.jar"), null, null, null, new IClasspathAttribute[] { attribute}, false);
1063 this.project.setRawClasspath(new IClasspathEntry[]{newEntry}, null);
1064 this.project.getResolvedClasspath(false);
1065
1066 IPackageFragmentRoot jarRoot = this.project.getPackageFragmentRoot(getFile("/AttachedJavadocProject/bug394967.jar"));
1067 final IPackageFragment packageFragment = jarRoot.getPackageFragment("java.io");
1068 assertNotNull(packageFragment);
1069 assertTrue("Does not exist", packageFragment.exists());
1070
1071 String javadoc = packageFragment.getAttachedJavadoc(null);
1072 assertNotNull(javadoc);
1073 assertEquals(
1074 "Wrong contents",
1075 "\r\n<div class=\"block\">Provides for system input and output through data streams, serialization and the file system.\r\n" +
1076 "<h2>\r\n" +
1077 "Package Specification</h2>\r\n" +
1078 "<p><br>Provides for system input and output through data streams, serialization and the file system. Unless otherwise noted, passing a null argument to a constructor or method in any class or interface in this package will cause a NullPointerException to be thrown.\r\n" +
1079 "<h2>Related Documentation</h2>\r\n" +
1080 "For overviews, tutorials, examples, guides, and tool documentation,\r\n" +
1081 "please see:\r\n" +
1082 "<ul>\r\n" +
1083 " <li><a href=\"../../../guide/serialization\">Serialization Enhancements</a>\r\n" +
1084 "</ul>\r\n" +
1085 "<DL>\r\n" +
1086 "<DT><B>Since:</B></DT>\r\n" +
1087 "<DD>JDK1.0</DD>\r\n" +
1088 "</DL></div>\r\n" +
1089 "</div>\r\n",
1090 javadoc);
1091 } finally {
1092 this.project.setRawClasspath(entries, null);
1093 }
1094 }
1095 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=394382
1096 public void testBug394382() throws JavaModelException {
1097 IClasspathEntry[] oldClasspath = this.project.getRawClasspath();
1098 try {
1099 String encoding = "UTF-8";
1100 IResource resource = this.project.getProject().findMember("/UTF8doc/"); //$NON-NLS-1$
1101 assertNotNull("doc folder cannot be null", resource); //$NON-NLS-1$
1102 URI locationURI = resource.getLocationURI();
1103 assertNotNull("doc folder cannot be null", locationURI); //$NON-NLS-1$
1104 URL docUrl = null;
1105 try {
1106 docUrl = locationURI.toURL();
1107 } catch (MalformedURLException e) {
1108 assertTrue("Should not happen", false); //$NON-NLS-1$
1109 } catch(IllegalArgumentException e) {
1110 assertTrue("Should not happen", false); //$NON-NLS-1$
1111 }
1112 IClasspathAttribute attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, docUrl.toExternalForm());
1113 IClasspathEntry newEntry = JavaCore.newLibraryEntry(new Path("/AttachedJavadocProject/lib/bug394382.jar"), null, null, new IAccessRule[]{}, new IClasspathAttribute[] { attribute }, false ); //$NON-NLS-1$
1114 IClasspathEntry[] newClasspath = new IClasspathEntry[oldClasspath.length + 1];
1115 System.arraycopy(oldClasspath, 0, newClasspath, 0, oldClasspath.length);
1116 newClasspath[oldClasspath.length] = newEntry;
1117 this.project.setRawClasspath(newClasspath, null);
1118 waitForAutoBuild();
1119
1120 IPackageFragmentRoot[] roots = this.project.getAllPackageFragmentRoots();
1121 IPackageFragmentRoot packageRoot = null;
1122 for(int i=0; i < roots.length; i++) {
1123 IPath path = roots[i].getPath();
1124 if (path.segment(path.segmentCount() - 1).equals("bug394382.jar")) {
1125 packageRoot = roots[i];
1126 }
1127 }
1128
1129 assertNotNull("Should not be null", packageRoot);
1130 IPackageFragment packageFragment = packageRoot.getPackageFragment("p"); //$NON-NLS-1$
1131 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
1132 IClassFile classFile = packageFragment.getClassFile("TestBug394382.class"); //$NON-NLS-1$
1133 assertNotNull(classFile);
1134 IType type = classFile.getType();
1135 IFile sourceFile = (IFile) this.project.getProject().findMember("UTF8doc/p/TestBug394382.txt");
1136 String javadoc = null;
1137 try {
1138 javadoc = type.getAttachedJavadoc(new NullProgressMonitor());
1139 } catch(JavaModelException e) {
1140 assertTrue("Should not happen", false);
1141 }
1142 assertNotNull("Shouldhave a javadoc", javadoc); //$NON-NLS-1$
1143 String encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding));
1144 char[] charArray = encodedContents.toCharArray();
1145 encodedContents = new String(CharOperation.remove(charArray, '\r'));
1146 charArray = javadoc.toCharArray();
1147 javadoc = new String(CharOperation.remove(charArray, '\r'));
1148 assertTrue("Sources should be decoded the same way", encodedContents.equals(javadoc));
1149 }
1150 finally {
1151 this.project.setRawClasspath(oldClasspath, null);
1152 }
1153 }
Stephan Herrmann28464e42013-02-02 16:25:14 +01001154 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=398272
1155 public void testBug398272() throws JavaModelException {
1156 IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2.p3.p4"); //$NON-NLS-1$
1157 assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
1158 try {
1159 String javadoc = packageFragment.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
1160 assertNull("Javadoc should be null", javadoc); //$NON-NLS-1$
1161 } catch(JavaModelException jme) {
1162 fail("Should not throw Java Model Exception");
1163 }
1164 }
Stephan Herrmannbe6c0ea2010-04-01 21:59:30 +00001165}