mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Cosmetics.
This commit is contained in:
parent
ba4c7c1e04
commit
e290bc4877
1 changed files with 27 additions and 28 deletions
|
@ -6,10 +6,9 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
* Andrew Ferguson (Symbian)
|
* Andrew Ferguson (Symbian)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.core.testplugin.util;
|
package org.eclipse.cdt.core.testplugin.util;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
@ -69,21 +68,22 @@ public class TestSourceReader {
|
||||||
* test in the source code.
|
* test in the source code.
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static StringBuilder[] getContentsForTest(Bundle bundle, String srcRoot, Class clazz, final String testName, int sections) throws IOException {
|
public static StringBuilder[] getContentsForTest(Bundle bundle, String srcRoot, Class clazz,
|
||||||
|
final String testName, int sections) throws IOException {
|
||||||
String fqn = clazz.getName().replace('.', '/');
|
String fqn = clazz.getName().replace('.', '/');
|
||||||
fqn = fqn.indexOf("$")==-1 ? fqn : fqn.substring(0,fqn.indexOf("$"));
|
fqn = fqn.indexOf("$") == -1 ? fqn : fqn.substring(0, fqn.indexOf("$"));
|
||||||
String classFile = fqn + ".java";
|
String classFile = fqn + ".java";
|
||||||
IPath filePath= new Path(srcRoot + '/' + classFile);
|
IPath filePath= new Path(srcRoot + '/' + classFile);
|
||||||
|
|
||||||
InputStream in;
|
InputStream in;
|
||||||
try {
|
try {
|
||||||
if (bundle != null)
|
if (bundle != null) {
|
||||||
in = FileLocator.openStream(bundle, filePath, false);
|
in = FileLocator.openStream(bundle, filePath, false);
|
||||||
else {
|
} else {
|
||||||
in = clazz.getResourceAsStream('/'+classFile);
|
in = clazz.getResourceAsStream('/' + classFile);
|
||||||
}
|
}
|
||||||
} catch(IOException e) {
|
} catch (IOException e) {
|
||||||
if(clazz.getSuperclass()!=null && !clazz.equals(TestCase.class)) {
|
if (clazz.getSuperclass() != null && !clazz.equals(TestCase.class)) {
|
||||||
return getContentsForTest(bundle, srcRoot, clazz.getSuperclass(), testName, sections);
|
return getContentsForTest(bundle, srcRoot, clazz.getSuperclass(), testName, sections);
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -91,30 +91,30 @@ public class TestSourceReader {
|
||||||
|
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
||||||
|
|
||||||
List contents = new ArrayList();
|
List<StringBuilder> contents = new ArrayList<StringBuilder>();
|
||||||
StringBuilder content = new StringBuilder();
|
StringBuilder content = new StringBuilder();
|
||||||
for(String line = br.readLine(); line!=null; line = br.readLine()) {
|
for (String line = br.readLine(); line != null; line = br.readLine()) {
|
||||||
line = line.replaceFirst("^\\s*", ""); // replace leading whitespace, preserve trailing
|
line = line.replaceFirst("^\\s*", ""); // replace leading whitespace, preserve trailing
|
||||||
if(line.startsWith("//")) {
|
if (line.startsWith("//")) {
|
||||||
content.append(line.substring(2)+"\n");
|
content.append(line.substring(2) + "\n");
|
||||||
} else {
|
} else {
|
||||||
if(content.length()>0) {
|
if (content.length() > 0) {
|
||||||
contents.add(content);
|
contents.add(content);
|
||||||
if(contents.size()==sections+1)
|
if (contents.size() == sections + 1)
|
||||||
contents.remove(0);
|
contents.remove(0);
|
||||||
content = new StringBuilder();
|
content = new StringBuilder();
|
||||||
}
|
}
|
||||||
int idx= line.indexOf(testName);
|
int idx= line.indexOf(testName);
|
||||||
if( idx != -1 && !Character.isJavaIdentifierPart(line.charAt(idx+testName.length()))) {
|
if (idx != -1 && !Character.isJavaIdentifierPart(line.charAt(idx + testName.length()))) {
|
||||||
return (StringBuilder[]) contents.toArray(new StringBuilder[contents.size()]);
|
return contents.toArray(new StringBuilder[contents.size()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(clazz.getSuperclass()!=null && !clazz.equals(TestCase.class)) {
|
if (clazz.getSuperclass() != null && !clazz.equals(TestCase.class)) {
|
||||||
return getContentsForTest(bundle, srcRoot, clazz.getSuperclass(), testName, sections);
|
return getContentsForTest(bundle, srcRoot, clazz.getSuperclass(), testName, sections);
|
||||||
}
|
}
|
||||||
throw new IOException("Test data not found for "+clazz+" "+testName);
|
throw new IOException("Test data not found for " + clazz + " " + testName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -139,15 +139,15 @@ public class TestSourceReader {
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
int idx= buf.indexOf(lookfor);
|
int idx= buf.indexOf(lookfor);
|
||||||
if (idx >= 0) {
|
if (idx >= 0) {
|
||||||
return idx+offset;
|
return idx + offset;
|
||||||
}
|
}
|
||||||
offset+=buf.length();
|
offset += buf.length();
|
||||||
buf.setLength(0);
|
buf.setLength(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int idx= buf.indexOf(lookfor);
|
int idx= buf.indexOf(lookfor);
|
||||||
if (idx >= 0) {
|
if (idx >= 0) {
|
||||||
return idx+offset;
|
return idx + offset;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -196,8 +196,8 @@ public class TestSourceReader {
|
||||||
} else {
|
} else {
|
||||||
line= line.trim();
|
line= line.trim();
|
||||||
if (line.startsWith("{" + tag)) {
|
if (line.startsWith("{" + tag)) {
|
||||||
if (line.length() == tag.length()+1 ||
|
if (line.length() == tag.length() + 1 ||
|
||||||
!Character.isJavaIdentifierPart(line.charAt(tag.length()+1))) {
|
!Character.isJavaIdentifierPart(line.charAt(tag.length() + 1))) {
|
||||||
found= true;
|
found= true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,8 +207,7 @@ public class TestSourceReader {
|
||||||
}
|
}
|
||||||
line= reader.readLine();
|
line= reader.readLine();
|
||||||
}
|
}
|
||||||
}
|
} finally {
|
||||||
finally {
|
|
||||||
reader.close();
|
reader.close();
|
||||||
}
|
}
|
||||||
Assert.assertTrue("Tag '" + tag + "' is not defined inside of '" + filePath + "'.", found);
|
Assert.assertTrue("Tag '" + tag + "' is not defined inside of '" + filePath + "'.", found);
|
||||||
|
@ -239,7 +238,7 @@ public class TestSourceReader {
|
||||||
long timestamp= file.getLocalTimeStamp();
|
long timestamp= file.getLocalTimeStamp();
|
||||||
file.setContents(stream, false, false, new NullProgressMonitor());
|
file.setContents(stream, false, false, new NullProgressMonitor());
|
||||||
if (file.getLocalTimeStamp() == timestamp) {
|
if (file.getLocalTimeStamp() == timestamp) {
|
||||||
file.setLocalTimeStamp(timestamp+1000);
|
file.setLocalTimeStamp(timestamp + 1000);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
createFolders(file);
|
createFolders(file);
|
||||||
|
|
Loading…
Add table
Reference in a new issue