spoon.processing.Processor Java Examples

The following examples show how to use spoon.processing.Processor. 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: CocoSpoonBasedSpectrumBasedFaultLocalizer.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
protected void runTests(String[] testClasses, NopolContext nopolContext, SpoonedProject spooner, Processor processor) {
	ClassLoader cl = spooner.processedAndDumpedToClassLoader(processor);
	TestCasesListener listener = new TestCasesListener();
	Map<String, Boolean> resultsPerNameOfTest = new HashMap<>();
	Map<String, Map<SourceLocation, Boolean>> linesExecutedPerTestNames = new HashMap<>();
	nbFailingTest = 0;
	nbSucceedTest = 0;
	for (int i = 0; i < testClasses.length; i++) {
		try {
			List<String> testMethods = new ArrayList<>();
			if (testClasses[i].contains("#")) {
				testMethods.add(testClasses[i]);
			} else {
				testMethods.addAll(getTestMethods(cl.loadClass(testClasses[i])));
			}
			for (String testMethod : testMethods) {
				TestSuiteExecution.runTest(testMethod, cl, listener, nopolContext);
				//Since we executed one test at the time, the listener contains one and only one TestCase
				boolean testSucceed = listener.numberOfFailedTests() == 0;
				resultsPerNameOfTest.put(testMethod, testSucceed);
				if (testSucceed) {
					nbSucceedTest++;
				} else {
					nbFailingTest++;
				}
				linesExecutedPerTestNames.put(testMethod, copyExecutedLinesAndReinit(_Instrumenting.lines));
			}
		} catch (ClassNotFoundException e) {
			throw new RuntimeException(e);
		}
	}
	this.buildTestResultPerSourceLocation(resultsPerNameOfTest, linesExecutedPerTestNames);
}
 
Example #2
Source File: TestSpooner.java    From spoon-examples with GNU General Public License v2.0 5 votes vote down vote up
public TestSpooner process(Class<? extends Processor>... processors) throws Exception {
	// Build spoon model
	compiler.build();
	
	List<Processor<?>> processorsNames = new ArrayList<>();
	for (Class<? extends Processor> processor : processors) {
		processorsNames.add(processor.newInstance());
	}
	compiler.process(processorsNames);

	return this;
}
 
Example #3
Source File: TestSpooner.java    From spoon-examples with GNU General Public License v2.0 5 votes vote down vote up
public TestSpooner process(CtElement element, Class<? extends Processor>... processors) throws Exception {
	// Build spoon model
	compiler.build();

	ProcessingManager processing = new QueueProcessingManager(compiler.getFactory());

	for (Class<? extends Processor> processorClz : processors) {
		processing.addProcessor(processorClz.getName());
	}
	processing.process(element);

	return this;
}
 
Example #4
Source File: ConstraintModelBuilder.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
public ConstraintModelBuilder(RuntimeValues<Boolean> runtimeValues, SourceLocation sourceLocation, Processor<?> processor, SpoonedProject spooner, NopolContext nopolContext) {
    this.sourceLocation = sourceLocation;
    this.nopolContext = nopolContext;
    String qualifiedName = sourceLocation.getRootClassName();
    SpoonedClass fork = spooner.forked(qualifiedName);
    try {
        classLoader = fork.processedAndDumpedToClassLoader(processor);
    } catch (DynamicCompilationException e) {
        logger.error("Unable to compile the change: \n" + fork.getSimpleType());
        throw e;
    }
    this.runtimeValues = runtimeValues;
}
 
Example #5
Source File: DelegatingProcessor.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void process(CtStatement element) {
    for (Processor processor : this.processors) {
        processor.process(element);
    }
    this.process = false;
}
 
Example #6
Source File: SpoonedFile.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
protected synchronized void processModelledClasses(Collection<? extends CtType<?>> modelledClasses, Collection<? extends Processor<?>> processors) {
    setProcessors(processors);
    for (CtType<?> modelledClass : modelledClasses) {
        String qualifiedName = modelledClass.getQualifiedName();
        //logDebug(logger(), format("[Spoon processing of %s]", qualifiedName));
        try {
            processingManager().process(modelledClass);
        } catch (ProcessInterruption e) {
            continue;
        }
    }
}
 
Example #7
Source File: SpoonedFile.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
public void generateOutputFile(File destinationFolder) {
    Environment env = factory.getEnvironment();
    env.setSourceOutputDirectory(destinationFolder);
    JavaOutputProcessor javaOutputProcessor = new JavaOutputProcessor(prettyPrinter);
    javaOutputProcessor.setFactory(factory);
    Processor<?> writer = javaOutputProcessor;
    process(writer);
}
 
Example #8
Source File: SpoonedProject.java    From nopol with GNU General Public License v2.0 4 votes vote down vote up
public ClassLoader processedAndDumpedToClassLoader(Collection<String> qualifiedNames, Processor<?> processor) {
    return processedAndDumpedToClassLoader(qualifiedNames, asList(processor));
}
 
Example #9
Source File: MutationTester.java    From spoon-examples with GNU General Public License v2.0 4 votes vote down vote up
public MutationTester(String src, TestDriver tester, Processor mutator) {
	this.sourceCodeToBeMutated = src;
	this.testDriver = tester;
	this.mutator = mutator;
}
 
Example #10
Source File: DelegatingProcessor.java    From nopol with GNU General Public License v2.0 4 votes vote down vote up
public DelegatingProcessor addProcessor(final Processor<CtElement> processor) {
    this.processors.add(processor);
    return this;
}
 
Example #11
Source File: SpoonedFile.java    From nopol with GNU General Public License v2.0 4 votes vote down vote up
private void setProcessors(Collection<? extends Processor<?>> processors) {
    processingManager().getProcessors().clear();
    for (Processor<?> processor : processors) {
        processingManager().addProcessor(processor);
    }
}
 
Example #12
Source File: SpoonedFile.java    From nopol with GNU General Public License v2.0 4 votes vote down vote up
public void process(Collection<? extends Processor<?>> processors) {
    processModelledClasses(modelledClasses(), processors);
}
 
Example #13
Source File: SpoonedFile.java    From nopol with GNU General Public License v2.0 4 votes vote down vote up
public void process(Processor<?> processor) {
    process(asList(processor));
}
 
Example #14
Source File: SpoonedFile.java    From nopol with GNU General Public License v2.0 4 votes vote down vote up
public ClassLoader processedAndDumpedToClassLoader(Collection<? extends Processor<?>> processors) {
    process(processors);
    return dumpedToClassLoader();
}
 
Example #15
Source File: SpoonedFile.java    From nopol with GNU General Public License v2.0 4 votes vote down vote up
public ClassLoader processedAndDumpedToClassLoader(Processor<?> processor) {
    return processedAndDumpedToClassLoader(asList(processor));
}
 
Example #16
Source File: CompoundProcessor.java    From nopol with GNU General Public License v2.0 4 votes vote down vote up
private List<Processor<? super T>> subprocessors() {
    return subprocessors;
}
 
Example #17
Source File: CompoundProcessor.java    From nopol with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void process(T element) {
    for (Processor<? super T> subprocessor : subprocessors()) {
        subprocessor.process(element);
    }
}
 
Example #18
Source File: CompoundProcessor.java    From nopol with GNU General Public License v2.0 4 votes vote down vote up
public CompoundProcessor(Class<T> targetClass, Collection<Processor<? super T>> processors) {
    this.targetCtClass = targetClass;
    subprocessors = MetaList.newLinkedList();
    subprocessors().addAll(processors);
}
 
Example #19
Source File: CompoundProcessor.java    From nopol with GNU General Public License v2.0 4 votes vote down vote up
public CompoundProcessor(Class<T> targetClass, Processor<? super T>... processors) {
    this(targetClass, asList(processors));
}
 
Example #20
Source File: SpoonedProject.java    From nopol with GNU General Public License v2.0 4 votes vote down vote up
public void processClasses(Collection<String> qualifiedNames, Collection<? extends Processor<?>> processors) {
    super.processModelledClasses(modelledClasses(qualifiedNames), processors);
}
 
Example #21
Source File: SpoonedProject.java    From nopol with GNU General Public License v2.0 4 votes vote down vote up
public void processClass(Collection<String> qualifiedNames, Processor<?> processor) {
    processClasses(qualifiedNames, asList(processor));
}
 
Example #22
Source File: SpoonedProject.java    From nopol with GNU General Public License v2.0 4 votes vote down vote up
public void processClass(String qualifiedName, Processor<?> processor) {
    processClass(asList(qualifiedName), processor);
}
 
Example #23
Source File: SpoonedProject.java    From nopol with GNU General Public License v2.0 4 votes vote down vote up
public ClassLoader processedAndDumpedToClassLoader(Collection<String> qualifiedNames, Collection<? extends Processor<?>> processors) {
    processClasses(qualifiedNames, processors);
    return super.newBytecodeClassloader(compiledClasses());
}
 
Example #24
Source File: DynamothCollector.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
private void setProcessor(Processor processor) {
	manager.getProcessors().clear();

	manager.addProcessor(processor);

}