View | Details | Raw Unified | Return to bug 304394 | Differences between
and this patch

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/JavaElement.java (-31 / +19 lines)
Lines 649-690 Link Here
649
		}
649
		}
650
650
651
		if (root.getKind() == IPackageFragmentRoot.K_BINARY) {
651
		if (root.getKind() == IPackageFragmentRoot.K_BINARY) {
652
			IClasspathEntry entry= root.getRawClasspathEntry();
652
			IClasspathEntry entry= null;
653
			if (entry == null) {
653
			try {
654
				return null;
654
				entry= root.getResolvedClasspathEntry();
655
			}
655
				URL url = getLibraryJavadocLocation(entry);
656
			if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
656
				if (url != null) {
657
				entry= getRealClasspathEntry(root.getJavaProject(), entry.getPath(), root.getPath());
657
					return url;
658
				if (entry == null) {
658
				}
659
			}
660
			catch(JavaModelException jme) {
661
				// Proceed with raw classpath
662
			}
663
			
664
			entry= root.getRawClasspathEntry();
665
			switch (entry.getEntryKind()) {
666
				case IClasspathEntry.CPE_LIBRARY:
667
				case IClasspathEntry.CPE_VARIABLE:
668
					return getLibraryJavadocLocation(entry);
669
				default:
659
					return null;
670
					return null;
660
				}
671
			}			
661
			}
662
			return getLibraryJavadocLocation(entry);
663
		}
672
		}
664
		return null;
673
		return null;
665
	}
674
	}
666
675
667
	private static IClasspathEntry getRealClasspathEntry(IJavaProject jproject, IPath containerPath, IPath libPath) throws JavaModelException {
668
		IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
669
		if (container != null) {
670
			IClasspathEntry[] entries= container.getClasspathEntries();
671
			for (int i= 0; i < entries.length; i++) {
672
				IClasspathEntry curr = entries[i];
673
				if (curr == null) {
674
					if (JavaModelManager.CP_RESOLVE_VERBOSE || JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE) {
675
						JavaModelManager.getJavaModelManager().verbose_missbehaving_container(jproject, containerPath, entries);
676
					}
677
					break;
678
				}
679
				IClasspathEntry resolved= JavaCore.getResolvedClasspathEntry(curr);
680
				if (resolved != null && libPath.equals(resolved.getPath())) {
681
					return curr; // return the real entry
682
				}
683
			}
684
		}
685
		return null; // not found
686
	}
687
688
	protected static URL getLibraryJavadocLocation(IClasspathEntry entry) throws JavaModelException {
676
	protected static URL getLibraryJavadocLocation(IClasspathEntry entry) throws JavaModelException {
689
		switch(entry.getEntryKind()) {
677
		switch(entry.getEntryKind()) {
690
			case IClasspathEntry.CPE_LIBRARY :
678
			case IClasspathEntry.CPE_LIBRARY :
(-)src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java (+107 lines)
Lines 20-25 Link Here
20
20
21
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.NullProgressMonitor;
24
import org.eclipse.core.runtime.NullProgressMonitor;
24
import org.eclipse.jdt.core.IClassFile;
25
import org.eclipse.jdt.core.IClassFile;
25
import org.eclipse.jdt.core.IClasspathAttribute;
26
import org.eclipse.jdt.core.IClasspathAttribute;
Lines 580-583 Link Here
580
			}
581
			}
581
		}
582
		}
582
	}
583
	}
584
	/**
585
	 * @bug 304394: IJavaElement#getAttachedJavadoc(IProgressMonitor) should support referenced entries
586
	 * Test that javadoc is picked up from the referenced classpath entry if present
587
	 * 
588
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=139160"
589
	 * @throws Exception
590
	 */
591
	public void testBug304394() throws Exception {
592
		setJavadocLocationAttribute("specialDoc");
593
		IClasspathEntry[] savedEntries = null;
594
		try {
595
			IClasspathEntry[] entries = this.project.getRawClasspath();
596
			savedEntries = (IClasspathEntry[]) entries.clone();
597
			IClasspathEntry chainedJar = null;
598
			int max = entries.length;
599
			for (int i = 0; i < max; i++) {
600
				final IClasspathEntry entry = entries[i];
601
				if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
602
						&& entry.getContentKind() == IPackageFragmentRoot.K_BINARY
603
						&& "/AttachedJavadocProject/lib/test6.jar".equals(entry.getPath().toString())) { //$NON-NLS-1$
604
605
					chainedJar = entries[i];
606
					addLibrary(this.project, "/lib/chaining.jar", null, new String[0], 
607
							new String[] {
608
								"META-INF/MANIFEST.MF",
609
								"Manifest-Version: 1.0\n" +
610
								"Class-Path: test6.jar\n",
611
							},
612
							JavaCore.VERSION_1_4);
613
					IPath jarPath = this.project.getPath().append("lib").append("chaining.jar");
614
					entries[i] = JavaCore.newLibraryEntry(jarPath, entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath());
615
					break;
616
				}
617
			}
618
			
619
			this.project.setRawClasspath(entries, new IClasspathEntry[]{chainedJar}, this.project.getOutputLocation(), null);
620
			waitForAutoBuild();
621
			
622
			IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
623
			IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
624
			IType type = classFile.getType();
625
			IMethod method = type.getMethod("foo", new String[] {"I", "J", "Ljava.lang.String;"}); //$NON-NLS-1$
626
			String javadoc = method.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
627
			assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
628
		} finally {
629
			// restore classpath
630
			if (savedEntries != null) {
631
				this.project.setRawClasspath(savedEntries, null);
632
			}
633
			removeLibrary(this.project, "/lib/chaining.jar", null);
634
		}
635
	}
636
	/**
637
	 * Additional test for bug 304394.
638
	 * Test that javadoc is picked up from the raw classpath entry when the referenced entry doesn't 
639
	 * contain the javadoc location.
640
	 * 
641
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=139160"
642
	 * @throws Exception
643
	 */
644
	public void testBug304394a() throws Exception {
645
		setJavadocLocationAttribute("specialDoc");
646
		IClasspathEntry[] savedEntries = null;
647
		try {
648
			IClasspathEntry[] entries = this.project.getRawClasspath();
649
			savedEntries = (IClasspathEntry[]) entries.clone();
650
			IClasspathEntry chainedJar = null;
651
			int max = entries.length;
652
			for (int i = 0; i < max; i++) {
653
				final IClasspathEntry entry = entries[i];
654
				if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
655
						&& entry.getContentKind() == IPackageFragmentRoot.K_BINARY
656
						&& "/AttachedJavadocProject/lib/test6.jar".equals(entry.getPath().toString())) { //$NON-NLS-1$
657
658
					chainedJar = entries[i];
659
					addLibrary(this.project, "/lib/chaining.jar", null, new String[0], 
660
							new String[] {
661
								"META-INF/MANIFEST.MF",
662
								"Manifest-Version: 1.0\n" +
663
								"Class-Path: test6.jar\n",
664
							},
665
							JavaCore.VERSION_1_4);
666
					IPath jarPath = this.project.getPath().append("lib").append("chaining.jar");
667
					entries[i] = JavaCore.newLibraryEntry(jarPath, entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported());
668
					break;
669
				}
670
			}
671
			
672
			chainedJar = JavaCore.newLibraryEntry(chainedJar.getPath(), null, null, null, null, chainedJar.isExported());
673
			this.project.setRawClasspath(entries, new IClasspathEntry[]{chainedJar}, this.project.getOutputLocation(), null);
674
			waitForAutoBuild();
675
			
676
			IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
677
			IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
678
			IType type = classFile.getType();
679
			IMethod method = type.getMethod("foo", new String[] {"I", "J", "Ljava.lang.String;"}); //$NON-NLS-1$
680
			String javadoc = method.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
681
			assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
682
		} finally {
683
			// restore classpath
684
			if (savedEntries != null) {
685
				this.project.setRawClasspath(savedEntries, null);
686
			}
687
			removeLibrary(this.project, "/lib/chaining.jar", null);
688
		}
689
	}	
583
}
690
}

Return to bug 304394