spoon.reflect.path.CtRole Java Examples

The following examples show how to use spoon.reflect.path.CtRole. 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: Nopol.java    From coming with MIT License 5 votes vote down vote up
private CtElement getWrapperIfConditoin(CtElement node) {
	List<CtElement> pathToRoot = ASTInfoResolver.getPathToRootNode(node);

	for (int i = pathToRoot.size() - 1; i >= 0; i--) {
		if (pathToRoot.get(i).getRoleInParent().equals(CtRole.CONDITION) && pathToRoot.get(i - 1) instanceof CtIf) {
			return pathToRoot.get(i);
		}
	}

	return null;
}
 
Example #2
Source File: PatternMatchingTest.java    From coming with MIT License 5 votes vote down vote up
@Test
public void testMatchingRoleIssue36_2_matching_inv() throws Exception {
	File fl = new File(getClass().getResource("/pattern_specification/pattern_modif_if2.xml").getFile());

	ChangePatternSpecification pattern = PatternXMLParser.parseFile(fl.getAbsolutePath());
	// add role
	assertEquals(2, pattern.getAbstractChanges().get(0).getAffectedEntity().getId());
	PatternEntity parent = pattern.getAbstractChanges().get(0).getAffectedEntity().getParentPatternEntity()
			.getParent();
	assertEquals(3, parent.getId());

	assertEquals(1, parent.getParentPatternEntity().getParent().getId());

	//
	parent.setRoleInParent(CtRole.THEN.name());
	// parent.setEntityType(PatternEntity.ANY);

	File s = getFile("diffcases/diffroleinparent1/1205753_EmbedPooledConnection_0_s.java");
	File t = getFile("diffcases/diffroleinparent1/1205753_EmbedPooledConnection_0_t.java");

	FineGrainDifftAnalyzer r = new FineGrainDifftAnalyzer();
	Diff diff = r.getDiff(s, t);

	System.out.println("Test result " + diff.getRootOperations());

	Assert.assertTrue(diff.getRootOperations().size() > 0);

	assertPattern(diff, pattern);

	DetectorChangePatternInstanceEngine detector = new DetectorChangePatternInstanceEngine();
	ResultMapping mappings = detector.mappingActions(pattern, diff);
	assertTrue(mappings.getMappings().size() > 0);

	List<ChangePatternInstance> instances = detector.findPatternInstances(pattern, diff);
	System.out.println("nr instances: " + instances.size());
	System.out.println(instances);

	assertEquals(1, instances.size());

}
 
Example #3
Source File: NodeCreator.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
@Override
public void scanCtReference(CtReference reference) {


    if (reference instanceof CtTypeReference && reference.getRoleInParent() == CtRole.SUPER_TYPE) {
        ITree superType = builder.createNode("SUPER_TYPE", reference.toString());
        CtWrapper<CtReference> k = new CtWrapper<CtReference>(reference, reference.getParent());
        superType.setMetadata(SpoonGumTreeBuilder.SPOON_OBJECT, k);
        reference.putMetadata(SpoonGumTreeBuilder.GUMTREE_NODE, superType);
        builder.addSiblingNode(superType);
    } else {
        super.scanCtReference(reference);
    }
}
 
Example #4
Source File: CtWrapper.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
public CtWrapper(L wrapped, CtElement parent, CtRole roleInParent) {
	super();
	this.value = wrapped;
	this.parent = parent;
	this.roleInParent = roleInParent;
	setFactory(parent.getFactory());
}
 
Example #5
Source File: LabelFinder.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
@Override
public <R> void visitCtBlock(CtBlock<R> e) {
	if (e.getRoleInParent() == CtRole.ELSE) {
		label = "ELSE";
	} else if (e.getRoleInParent() == CtRole.THEN) {
		label = "THEN";
	} else {
		label = "{";
	}
}
 
Example #6
Source File: TreeScanner.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
/**
 * Ignore some element from the AST
 * 
 * @param element
 * @return
 */
private boolean isToIgnore(CtElement element) {
	if (element instanceof CtStatementList && !(element instanceof CtCase)) {
		if (element.getRoleInParent() == CtRole.ELSE || element.getRoleInParent() == CtRole.THEN) {
			return false;
		}
		return true;
	}

	if (element instanceof CtReference && element.getRoleInParent() == CtRole.SUPER_TYPE) {
		return false;
	}

	return element.isImplicit() || element instanceof CtReference;
}
 
Example #7
Source File: CtWrapper.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
@Override
public CtRole getRoleInParent() {
	if (this.roleInParent != null)
		return this.roleInParent;
	return parent.getRoleInParent();
}
 
Example #8
Source File: CtVirtualElement.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
public CtVirtualElement(String wrapped, CtElement parent, Collection<?> children, CtRole roleInParent) {
	super(wrapped, parent, roleInParent);
	this.children = children;
}
 
Example #9
Source File: PatternMatchingTest.java    From coming with MIT License 3 votes vote down vote up
@Test
public void testMatchingRoleIssue36_1_matching_binop() throws Exception {
	File fl = new File(getClass().getResource("/pattern_specification/pattern_modif_if.xml").getFile());

	ChangePatternSpecification pattern = PatternXMLParser.parseFile(fl.getAbsolutePath());
	// add role
	assertEquals(2, pattern.getAbstractChanges().get(0).getAffectedEntity().getId());

	assertEquals(1,
			pattern.getAbstractChanges().get(0).getAffectedEntity().getParentPatternEntity().getParent().getId());

	pattern.getAbstractChanges().get(0).getAffectedEntity()// .getParentPatternEntity().getParent()
			.setRoleInParent(CtRole.CONDITION.name());

	File s = getFile("diffcases/diffroleinparent1/1205753_EmbedPooledConnection_0_s.java");
	File t = getFile("diffcases/diffroleinparent1/1205753_EmbedPooledConnection_0_t.java");

	FineGrainDifftAnalyzer r = new FineGrainDifftAnalyzer();
	Diff diff = r.getDiff(s, t);

	System.out.println("Test result " + diff.getRootOperations());

	Assert.assertTrue(diff.getRootOperations().size() > 0);

	assertPattern(diff, pattern);

	DetectorChangePatternInstanceEngine detector = new DetectorChangePatternInstanceEngine();
	ResultMapping mappings = detector.mappingActions(pattern, diff);
	assertTrue(mappings.getMappings().size() > 0);

	List<ChangePatternInstance> instances = detector.findPatternInstances(pattern, diff);
	System.out.println("nr instances: " + instances.size());
	System.out.println(instances);

	assertEquals(1, instances.size());

	ChangePatternInstance instancefound = instances.get(0);

}
 
Example #10
Source File: ExpressionReplaceOperator.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
public boolean isStatement(CtElement toModif) {

		if (!(toModif instanceof CtStatement))
			return false;

		if (toModif.getParent() instanceof CtBlock)
			return true;

		CtRole roleInParent = toModif.getRoleInParent();

		if (CtRole.BODY.equals(roleInParent) || CtRole.THEN.equals(roleInParent) || CtRole.ELSE.equals(roleInParent))
			return true;

		return false;
	}