spoon.processing.AbstractProcessor Java Examples

The following examples show how to use spoon.processing.AbstractProcessor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DumbFaultLocalizerImpl.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Map<SourceLocation, List<TestResult>> getTestListPerStatement() {
	SpoonedProject spooner = new SpoonedProject(nopolContext.getProjectSources(), nopolContext);
	final List<SourcePosition> l = new ArrayList<>();
	spooner.process(new AbstractProcessor<CtIf>(){
		@Override
		public void process(CtIf ctIf) {
			l.add(ctIf.getCondition().getPosition());
		}
	});

	Map<SourceLocation, List<TestResult>> countPerSourceLocation = new HashMap<>();

	List<TestResult> res = new ArrayList<>();

	for (String testClass : nopolContext.getProjectTests()) {
		try {
			URLClassLoader urlClassLoader = new URLClassLoader(nopolContext.getProjectClasspath(), this.getClass().getClassLoader());
			Class klass = urlClassLoader.loadClass(testClass);

			// does not work, see https://stackoverflow.com/a/29865611
			//for (FrameworkMethod desc : new BlockJUnit4ClassRunner(klass).getChildren()) {

			// so we get the methods ourselves
			// only support basic Junit4
			for (String m : getTestMethods(klass)) {
				res.add(new TestResultImpl(TestCase.from(m), false));
			}
	} catch (Exception e) {
			System.out.println(testClass);
		}
	}
	for(SourcePosition pos : l) {
		SourceLocation loc = new SourceLocation(pos.getCompilationUnit().getMainType().getQualifiedName(), pos.getLine());
		countPerSourceLocation.put(loc, Collections.unmodifiableList(res));
	}
	return countPerSourceLocation;
}