use of org.whole.lang.commons.model.Variable in project whole by wholeplatform.
the class MatcherTest method testRemoveVars.
@Test
public void testRemoveVars() {
IEntity pattern = new SimpleEntityPattern().create();
Matcher.removeVars(pattern, true);
GenericTraversalFactory.instance.topDown(new AbstractVariableVisitor() {
public void visitVariable(Variable variable) {
fail();
}
}, false).visit(pattern);
}
use of org.whole.lang.commons.model.Variable in project whole by wholeplatform.
the class MatcherTest method testRename.
@Test
public void testRename() {
Feature featurePattern = new FeaturePattern().create();
Variable var = (Variable) featurePattern.getType().wGetAdaptee(false);
assertEquals("featureType", var.getVarName().getValue());
Matcher.rename(featurePattern, "featureType", "fType", false);
assertEquals("fType", var.getVarName().getValue());
}
use of org.whole.lang.commons.model.Variable in project whole by wholeplatform.
the class GenericForwardSpecificBuilderTest method testMultiLanguage.
@Test
public void testMultiLanguage() throws Exception {
IEntity entity = XmlBuilderPersistenceKit.instance().readModel(new ClasspathPersistenceProvider("org/whole/lang/queries/util/BindVariablesInPathTemplates.xwl"));
ModelBuilderOperation mop = new ModelBuilderOperation();
ModelTemplate template = new ModelTemplate(entity);
template.apply(new GenericForwardSpecificBuilder(mop));
IEntity newEntity = mop.wGetResult();
// to match variables fill variables with defaults
IEntityIterator<IEntity> variableIterator = IteratorFactory.<IEntity>descendantOrSelfMatcherIterator().withPattern(GenericMatcherFactory.instance.isVariableMatcher());
variableIterator.reset(entity);
IEntityIterator<IEntity> newVariableIterator = IteratorFactory.<IEntity>descendantOrSelfMatcherIterator().withPattern(GenericMatcherFactory.instance.isVariableMatcher());
newVariableIterator.reset(newEntity);
while (variableIterator.hasNext()) {
assertTrue(newVariableIterator.hasNext());
Variable variable = (Variable) variableIterator.next().wGetAdaptee(false);
Variable newVariable = (Variable) newVariableIterator.next().wGetAdaptee(false);
EntityDescriptor<?> ed = variable.getVarType().getValue();
EntityDescriptor<?> newEd = newVariable.getVarType().getValue();
assertEquals(ed, newEd);
String name = variable.getVarName().getValue();
String newName = newVariable.getVarName().getValue();
assertEquals(name, newName);
IEntity replacement = GenericEntityFactory.instance.create(ed);
variableIterator.set(replacement);
newVariableIterator.set(EntityUtils.clone(replacement));
}
assertTrue(Matcher.match(entity, newEntity));
}
Aggregations