Search in sources :

Example 11 with Variable

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);
}
Also used : Variable(org.whole.lang.commons.model.Variable) IEntity(org.whole.lang.model.IEntity) AbstractVariableVisitor(org.whole.lang.matchers.GenericMatcherFactory.AbstractVariableVisitor) Test(org.junit.Test)

Example 12 with Variable

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());
}
Also used : Variable(org.whole.lang.commons.model.Variable) Feature(org.whole.lang.models.model.Feature) Test(org.junit.Test)

Example 13 with Variable

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));
}
Also used : ModelTemplate(org.whole.lang.templates.ModelTemplate) Variable(org.whole.lang.commons.model.Variable) IEntity(org.whole.lang.model.IEntity) ClasspathPersistenceProvider(org.whole.lang.codebase.ClasspathPersistenceProvider) Test(org.junit.Test)

Aggregations

Variable (org.whole.lang.commons.model.Variable)13 IEntity (org.whole.lang.model.IEntity)10 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 QuantifierEnum (org.whole.lang.commons.model.QuantifierEnum)2 Feature (org.whole.lang.models.model.Feature)2 HashMap (java.util.HashMap)1 Set (java.util.Set)1 ITransactionScope (org.whole.lang.bindings.ITransactionScope)1 ClasspathPersistenceProvider (org.whole.lang.codebase.ClasspathPersistenceProvider)1 AbstractVariableVisitor (org.whole.lang.matchers.GenericMatcherFactory.AbstractVariableVisitor)1 SubstituteException (org.whole.lang.matchers.SubstituteException)1 InternalIEntity (org.whole.lang.model.InternalIEntity)1 Model (org.whole.lang.models.model.Model)1 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)1 ModelTemplate (org.whole.lang.templates.ModelTemplate)1 TestingModel (org.whole.lang.testentities.codebase.TestingModel)1 MissingVariableException (org.whole.lang.visitors.MissingVariableException)1