Lines 21-28
Link Here
|
21 |
import org.eclipse.core.runtime.Path; |
21 |
import org.eclipse.core.runtime.Path; |
22 |
import org.eclipse.jdt.core.*; |
22 |
import org.eclipse.jdt.core.*; |
23 |
import org.eclipse.jdt.core.dom.*; |
23 |
import org.eclipse.jdt.core.dom.*; |
24 |
import org.eclipse.jdt.core.dom.AST; |
|
|
25 |
import org.eclipse.jdt.core.dom.ASTNode; |
26 |
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; |
24 |
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; |
27 |
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot; |
25 |
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot; |
28 |
import org.eclipse.jdt.internal.core.util.Util; |
26 |
import org.eclipse.jdt.internal.core.util.Util; |
Lines 34-39
Link Here
|
34 |
* - don't hardcode positions |
32 |
* - don't hardcode positions |
35 |
*/ |
33 |
*/ |
36 |
public class AttachSourceTests extends ModifyingResourceTests { |
34 |
public class AttachSourceTests extends ModifyingResourceTests { |
|
|
35 |
static { |
36 |
// TESTS_NAMES = new String[] { "testRootPath13" }; |
37 |
// TESTS_NUMBERS = new int[] { 5 }; |
38 |
// TESTS_RANGE = new int[] { 169, 180 }; |
39 |
} |
40 |
|
41 |
public static Test suite() { |
42 |
return buildTestSuite(AttachSourceTests.class); |
43 |
} |
37 |
|
44 |
|
38 |
/** @deprecated using deprecated code */ |
45 |
/** @deprecated using deprecated code */ |
39 |
private static final int AST_INTERNAL_JLS2 = AST.JLS2; |
46 |
private static final int AST_INTERNAL_JLS2 = AST.JLS2; |
Lines 45-53
Link Here
|
45 |
public AttachSourceTests(String name) { |
52 |
public AttachSourceTests(String name) { |
46 |
super(name); |
53 |
super(name); |
47 |
} |
54 |
} |
48 |
public static Test suite() { |
|
|
49 |
return new Suite(AttachSourceTests.class); |
50 |
} |
51 |
public ASTNode runConversion(IClassFile classFile, boolean resolveBindings) { |
55 |
public ASTNode runConversion(IClassFile classFile, boolean resolveBindings) { |
52 |
ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS2); |
56 |
ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS2); |
53 |
parser.setSource(classFile); |
57 |
parser.setSource(classFile); |
Lines 868-872
Link Here
|
868 |
attachSource(root, null, null); // detach source |
872 |
attachSource(root, null, null); // detach source |
869 |
root.close(); |
873 |
root.close(); |
870 |
} |
874 |
} |
871 |
|
875 |
/** |
|
|
876 |
* http://bugs.eclipse.org/bugs/show_bug.cgi?id=110172 |
877 |
*/ |
878 |
public void testRootPath13() throws JavaModelException { |
879 |
IJavaProject project = this.getJavaProject("/AttachSourceTests"); |
880 |
IPackageFragmentRoot root = project.getPackageFragmentRoot(this.getFile("/AttachSourceTests/test6.jar")); |
881 |
assertTrue("Root doesn't exist", root.exists()); |
882 |
attachSource(root, "/AttachSourceTests/test6src.zip", null); |
883 |
|
884 |
try { |
885 |
// check the javadoc source range in a class file |
886 |
IClassFile cf = root.getPackageFragment("p1.p2").getClassFile("X.class"); |
887 |
assertNotNull(cf); |
888 |
final String source = cf.getSource(); |
889 |
assertNotNull("No source", source); |
890 |
IJavaElement[] children = cf.getChildren(); |
891 |
assertEquals("Wrong number of children", 1, children.length); |
892 |
IJavaElement element = children[0]; |
893 |
assertTrue("Not a type", element instanceof IType); |
894 |
IType type = (IType) element; |
895 |
IJavaElement[] members = type.getChildren(); |
896 |
final int length = members.length; |
897 |
assertEquals("Wrong number", 9, length); |
898 |
for (int i = 0; i < length; i++) { |
899 |
element = members[i]; |
900 |
assertTrue(element instanceof IMember); |
901 |
final ISourceRange javadocRange = ((IMember) element).getJavadocRange(); |
902 |
final String elementName = element.getElementName(); |
903 |
if ("f".equals(elementName)) { |
904 |
assertNotNull("No javadoc source range", javadocRange); |
905 |
final int start = javadocRange.getOffset(); |
906 |
final int end = javadocRange.getLength() + start - 1; |
907 |
String javadocSource = source.substring(start, end); |
908 |
assertTrue("Wrong javadoc", javadocSource.indexOf("field f") != -1); |
909 |
} else if ("foo".equals(elementName)) { |
910 |
assertNotNull("No javadoc source range", javadocRange); |
911 |
final int start = javadocRange.getOffset(); |
912 |
final int end = javadocRange.getLength() + start - 1; |
913 |
String javadocSource = source.substring(start, end); |
914 |
assertTrue("Wrong javadoc", javadocSource.indexOf("method foo") != -1); |
915 |
} else if ("A".equals(elementName)) { |
916 |
assertNotNull("No javadoc source range", javadocRange); |
917 |
final int start = javadocRange.getOffset(); |
918 |
final int end = javadocRange.getLength() + start - 1; |
919 |
String javadocSource = source.substring(start, end); |
920 |
assertTrue("Wrong javadoc", javadocSource.indexOf("member type A") != -1); |
921 |
} else if ("X".equals(elementName)) { |
922 |
// need treatment for the two constructors |
923 |
assertTrue("Not an IMethod", element instanceof IMethod); |
924 |
IMethod method = (IMethod) element; |
925 |
switch(method.getNumberOfParameters()) { |
926 |
case 0 : |
927 |
assertNull("Has a javadoc source range", javadocRange); |
928 |
break; |
929 |
case 1: |
930 |
assertNotNull("No javadoc source range", javadocRange); |
931 |
final int start = javadocRange.getOffset(); |
932 |
final int end = javadocRange.getLength() + start - 1; |
933 |
String javadocSource = source.substring(start, end); |
934 |
assertTrue("Wrong javadoc", javadocSource.indexOf("constructor") != -1); |
935 |
} |
936 |
} else if ("f3".equals(elementName)) { |
937 |
assertNotNull("No javadoc source range", javadocRange); |
938 |
final int start = javadocRange.getOffset(); |
939 |
final int end = javadocRange.getLength() + start - 1; |
940 |
String javadocSource = source.substring(start, end); |
941 |
assertTrue("Wrong javadoc", javadocSource.indexOf("Real") != -1); |
942 |
} else if ("f2".equals(elementName)) { |
943 |
assertNull("Has a javadoc source range", javadocRange); |
944 |
} else if ("foo2".equals(elementName)) { |
945 |
assertNull("Has a javadoc source range", javadocRange); |
946 |
} else if ("B".equals(elementName)) { |
947 |
assertNull("Has a javadoc source range", javadocRange); |
948 |
} |
949 |
} |
950 |
} finally { |
951 |
attachSource(root, null, null); // detach source |
952 |
root.close(); |
953 |
} |
954 |
} |
872 |
} |
955 |
} |