diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java index e4bffbbbc57..2869a337ba4 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java @@ -70,7 +70,19 @@ public class TestSourceReader { */ public static StringBuilder[] getContentsForTest(Bundle bundle, String srcRoot, Class clazz, final String testName, int sections) throws IOException { + // Walk up the class inheritance chain until we find the test method. + try { + while (clazz.getMethod(testName).getDeclaringClass() != clazz) { + clazz = clazz.getSuperclass(); + } + } catch (SecurityException e) { + Assert.fail(e.getMessage()); + } catch (NoSuchMethodException e) { + Assert.fail(e.getMessage()); + } + while (true) { + // Find and open the .java file for the class clazz. String fqn = clazz.getName().replace('.', '/'); fqn = fqn.indexOf("$") == -1 ? fqn : fqn.substring(0, fqn.indexOf("$")); String classFile = fqn + ".java"; @@ -94,6 +106,7 @@ public class TestSourceReader { BufferedReader br = new BufferedReader(new InputStreamReader(in)); try { + // Read the java file collecting comments until we encounter the test method. List contents = new ArrayList(); StringBuilder content = new StringBuilder(); for (String line = br.readLine(); line != null; line = br.readLine()) {