Java Code Examples for spoon.processing.Processor

The following examples show how to use spoon.processing.Processor. These examples are extracted from open source projects. 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
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 Project: nopol   Source File: SpoonedFile.java    License: 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 3
Source Project: nopol   Source File: SpoonedFile.java    License: 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 4
Source Project: nopol   Source File: DelegatingProcessor.java    License: 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 5
Source Project: nopol   Source File: ConstraintModelBuilder.java    License: 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 6
Source Project: spoon-examples   Source File: TestSpooner.java    License: 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 7
Source Project: spoon-examples   Source File: TestSpooner.java    License: 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 8
Source Project: nopol   Source File: SpoonedProject.java    License: 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 Project: nopol   Source File: SpoonedProject.java    License: 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 10
Source Project: nopol   Source File: SpoonedProject.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void processClass(String qualifiedName, Processor<?> processor) {
    processClass(asList(qualifiedName), processor);
}
 
Example 11
Source Project: nopol   Source File: SpoonedProject.java    License: 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 12
Source Project: nopol   Source File: SpoonedProject.java    License: 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 13
Source Project: nopol   Source File: CompoundProcessor.java    License: 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 14
Source Project: nopol   Source File: CompoundProcessor.java    License: 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 15
Source Project: nopol   Source File: CompoundProcessor.java    License: 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 16
Source Project: nopol   Source File: CompoundProcessor.java    License: GNU General Public License v2.0 4 votes vote down vote up
private List<Processor<? super T>> subprocessors() {
    return subprocessors;
}
 
Example 17
Source Project: nopol   Source File: SpoonedFile.java    License: GNU General Public License v2.0 4 votes vote down vote up
public ClassLoader processedAndDumpedToClassLoader(Processor<?> processor) {
    return processedAndDumpedToClassLoader(asList(processor));
}
 
Example 18
Source Project: nopol   Source File: SpoonedFile.java    License: GNU General Public License v2.0 4 votes vote down vote up
public ClassLoader processedAndDumpedToClassLoader(Collection<? extends Processor<?>> processors) {
    process(processors);
    return dumpedToClassLoader();
}
 
Example 19
Source Project: nopol   Source File: SpoonedFile.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void process(Processor<?> processor) {
    process(asList(processor));
}
 
Example 20
Source Project: nopol   Source File: SpoonedFile.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void process(Collection<? extends Processor<?>> processors) {
    processModelledClasses(modelledClasses(), processors);
}
 
Example 21
Source Project: nopol   Source File: SpoonedFile.java    License: 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 22
Source Project: nopol   Source File: DelegatingProcessor.java    License: 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 23
public MutationTester(String src, TestDriver tester, Processor mutator) {
	this.sourceCodeToBeMutated = src;
	this.testDriver = tester;
	this.mutator = mutator;
}
 
Example 24
Source Project: astor   Source File: DynamothCollector.java    License: GNU General Public License v2.0 2 votes vote down vote up
private void setProcessor(Processor processor) {
	manager.getProcessors().clear();

	manager.addProcessor(processor);

}