Java Code Examples for spoon.reflect.declaration.CtType#accept()

The following examples show how to use spoon.reflect.declaration.CtType#accept() . 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: TreeTest.java    From gumtree-spoon-ast-diff with Apache License 2.0 6 votes vote down vote up
@Test
public void test_Path_ScannerWithSpoon_left() throws Exception {

	Launcher spoon = new Launcher();
	Factory factory = spoon.createFactory();
	spoon.createCompiler(factory,
			SpoonResourceHelper.resources("src/test/resources/examples/roots/test8/left_QuickNotepad_1.13.java"))
			.build();

	CtType<?> astLeft = factory.Type().get("QuickNotepad");
	assertNotNull(astLeft.getPath());
	assertNotNull(astLeft);
	PathScanner pscanner = new PathScanner();
	astLeft.accept(pscanner);

}
 
Example 2
Source File: TreeTest.java    From gumtree-spoon-ast-diff with Apache License 2.0 6 votes vote down vote up
@Test
public void test_Path_ScannerWithSpoon_Right() throws Exception {

	Launcher spoon = new Launcher();
	Factory factory = spoon.createFactory();
	spoon.createCompiler(factory,
			SpoonResourceHelper.resources("src/test/resources/examples/roots/test8/right_QuickNotepad_1.14.java"))
			.build();

	CtType<?> astLeft = factory.Type().get("QuickNotepad");
	assertNotNull(astLeft.getPath());
	assertNotNull(astLeft);
	PathScanner pscanner = new PathScanner();
	astLeft.accept(pscanner);

}
 
Example 3
Source File: PatchGenerator.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
private CtElement getTarget() {
	CtType type = factory.Type().get(patch.getSourceLocation().getRootClassName());
	EarlyTerminatingScanner<CtElement> targetFinder = new EarlyTerminatingScanner<CtElement>() {
		@Override
		protected void enter(CtElement e) {
			if (e.getPosition() instanceof NoSourcePosition) {
				return;
			}
			if (e.getPosition().getSourceStart() == patch.getSourceLocation().getBeginSource()
					&& e.getPosition().getSourceEnd() == patch.getSourceLocation().getEndSource() && e.isImplicit() == false) {
				if (patch.getType() == RepairType.CONDITIONAL && e instanceof CtIf) {
					setResult(((CtIf) e).getCondition());
				} else {
					setResult(e);
				}
				terminate();
				return;
			}
			if (e.getPosition().getSourceStart() <= patch.getSourceLocation().getBeginSource()
					&& e.getPosition().getSourceEnd() >= patch.getSourceLocation().getEndSource()) {
				super.enter(e);
			}
		}
	};
	type.accept(targetFinder);
	return targetFinder.getResult();
}
 
Example 4
Source File: AstorCoreEngine.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void initModel() throws Exception {

		if (!MutationSupporter.getFactory().Type().getAll().isEmpty()) {
			if (ConfigurationProperties.getPropertyBool("resetmodel")) {
				Factory fcurrent = MutationSupporter.getFactory();
				log.debug("The Spoon Model was already built.");
				Factory fnew = MutationSupporter.cleanFactory();
				log.debug("New factory created? " + !fnew.equals(fcurrent));
			} else {
				log.debug("we keep previous factory");
				// we do not generate a new model
				return;
			}
		}

		this.mutatorSupporter.buildSpoonModel(this.projectFacade);

		log.info("Number of CtTypes created: " + mutatorSupporter.getFactory().Type().getAll().size());

		///// ONCE ASTOR HAS BUILT THE MODEL,
		///// We apply different processes and manipulation over it.

		// We process the model to add blocks as parent of statement which are
		// not contained in a block
		BlockReificationScanner visitor = new BlockReificationScanner();
		for (CtType c : mutatorSupporter.getFactory().Type().getAll()) {
			c.accept(visitor);
		}

	}
 
Example 5
Source File: TreeTest.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
@Test
public void test_Path_Scanner_failing_tofix() throws Exception {
	AstComparator diff = new AstComparator();
	File fl = new File("src/test/resources/examples/roots/test8/left_QuickNotepad_1.13.java");
	File fr = new File("src/test/resources/examples/roots/test8/right_QuickNotepad_1.14.java");

	CtType<?> astLeft = diff.getCtType(fl);

	assertNotNull(astLeft);
	assertEquals("QuickNotepad", astLeft.getSimpleName());

	CtPath pathLeft = astLeft.getPath();
	assertNotNull(pathLeft);

	CtType<?> astRight = diff.getCtType(fr);

	assertNotNull(astRight);
	assertEquals("QuickNotepad", astRight.getSimpleName());
	// No package in that file
	assertEquals("QuickNotepad", astRight.getQualifiedName());

	CtPath pathRight = astRight.getPath();
	assertNotNull(pathRight);

	PathScanner pscanner = new PathScanner();
	astLeft.accept(pscanner);
	astRight.accept(pscanner);

}
 
Example 6
Source File: TreeTest.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
@Test
public void test_Path_ScannerWithSpoon_both() throws Exception {

	Launcher spoon = new Launcher();
	Factory factory = spoon.createFactory();
	spoon.createCompiler(factory,
			SpoonResourceHelper.resources("src/test/resources/examples/roots/test8/left_QuickNotepad_1.13.java"))
			.build();

	CtType<?> astLeft = factory.Type().get("QuickNotepad");

	// So, if we create a new factory, it works.
	// Reusing the same factory, the path fails.
	factory = spoon.createFactory();
	spoon.createCompiler(factory,
			SpoonResourceHelper.resources("src/test/resources/examples/roots/test8/left_QuickNotepad_1.13.java"))
			.build();

	CtType<?> astRight = factory.Type().get("QuickNotepad");

	PathScanner pscanner = new PathScanner();

	assertNotNull(astLeft.getPath());
	assertNotNull(astLeft);
	astLeft.accept(pscanner);

	assertNotNull(astRight.getPath());
	assertNotNull(astRight);
	astRight.accept(pscanner);

}
 
Example 7
Source File: TreeTest.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
@Test
public void test_Path_ScannerWithGTFailing_right() throws Exception {

	AstComparator diff = new AstComparator();

	File fr = new File("src/test/resources/examples/roots/test8/right_QuickNotepad_1.14.java");

	CtType<?> astRight = diff.getCtType(fr);

	PathScanner pscanner = new PathScanner();

	assertNotNull(astRight.getPath());
	assertNotNull(astRight);
	astRight.accept(pscanner);

}
 
Example 8
Source File: TreeTest.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
@Test
public void test_Path_ScannerWithGTFailing_both() throws Exception {

	AstComparator diff = new AstComparator();
	File fl = new File("src/test/resources/examples/roots/test8/left_QuickNotepad_1.13.java");

	CtType<?> astLeft = diff.getCtType(fl);

	File fr = new File("src/test/resources/examples/roots/test8/right_QuickNotepad_1.14.java");

	CtType<?> astRight = diff.getCtType(fr);

	PathScanner pscanner = new PathScanner();

	assertNotNull(astLeft.getPath());
	assertNotNull(astLeft);
	astLeft.accept(pscanner);

	assertNotNull(astRight.getPath());
	assertNotNull(astRight);
	astRight.accept(pscanner);

}
 
Example 9
Source File: TreeTest.java    From gumtree-spoon-ast-diff with Apache License 2.0 3 votes vote down vote up
@Test
public void test_Path_ScannerWithGTFailing_left() throws Exception {

	AstComparator diff = new AstComparator();
	File fl = new File("src/test/resources/examples/roots/test8/left_QuickNotepad_1.13.java");

	CtType<?> astLeft = diff.getCtType(fl);

	PathScanner pscanner = new PathScanner();

	assertNotNull(astLeft.getPath());
	assertNotNull(astLeft);
	astLeft.accept(pscanner);

}