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 |
} |