Search in sources :

Example 1 with Variable

use of org.whole.lang.commons.model.Variable in project whole by wholeplatform.

the class Matcher method removeVars.

public static boolean removeVars(IEntity pattern, boolean force) {
    boolean allVarsAreOptional = true;
    AbstractPatternFilterIterator<IEntity> variableIterator = IteratorFactory.descendantOrSelfMatcherIterator().withPattern(GenericMatcherFactory.instance.isVariableMatcher());
    variableIterator.reset(pattern);
    for (IEntity variableAdapter : variableIterator) {
        Variable variable = (Variable) variableAdapter.wGetAdaptee(false);
        boolean isOptional = variable.getQuantifier().getValue().isOptional();
        allVarsAreOptional &= isOptional;
        if (force || isOptional)
            variableIterator.remove();
    }
    return allVarsAreOptional;
}
Also used : Variable(org.whole.lang.commons.model.Variable) IEntity(org.whole.lang.model.IEntity)

Example 2 with Variable

use of org.whole.lang.commons.model.Variable in project whole by wholeplatform.

the class InlineVariablePart method getModelSpecificChildren.

protected List<IEntity> getModelSpecificChildren() {
    Variable entity = getModelEntity();
    List<IEntity> children = new ArrayList<IEntity>(3);
    children.add(entity.getVarType());
    children.add(entity.getVarName());
    children.add(entity.getQuantifier());
    return children;
}
Also used : Variable(org.whole.lang.commons.model.Variable) IEntity(org.whole.lang.model.IEntity) ArrayList(java.util.ArrayList)

Example 3 with Variable

use of org.whole.lang.commons.model.Variable in project whole by wholeplatform.

the class VariablePart method getModelSpecificChildren.

protected List<IEntity> getModelSpecificChildren() {
    Variable entity = getModelEntity();
    List<IEntity> children = new ArrayList<IEntity>(3);
    children.add(entity.getVarType());
    children.add(entity.getVarName());
    children.add(entity.getQuantifier());
    return children;
}
Also used : Variable(org.whole.lang.commons.model.Variable) IEntity(org.whole.lang.model.IEntity) ArrayList(java.util.ArrayList)

Example 4 with Variable

use of org.whole.lang.commons.model.Variable in project whole by wholeplatform.

the class MatcherTest method testMultipleRename.

@Test
public void testMultipleRename() {
    Model modelPattern = new ModelPattern().create();
    Variable var1 = (Variable) modelPattern.getDeclarations().wGet(0).wGet(ModelsFeatureDescriptorEnum.features).wGet(0).wGet(ModelsFeatureDescriptorEnum.type).wGetAdaptee(false);
    Variable var2 = (Variable) modelPattern.getDeclarations().wGet(1).wGet(ModelsFeatureDescriptorEnum.name).wGetAdaptee(false);
    assertEquals("dataEntity", var1.getVarName().getValue());
    assertEquals("dataEntity", var2.getVarName().getValue());
    Matcher.rename(modelPattern, "dataEntity", "DE", false);
    assertEquals("DE", var1.getVarName().getValue());
    assertEquals("DE", var2.getVarName().getValue());
}
Also used : Variable(org.whole.lang.commons.model.Variable) TestingModel(org.whole.lang.testentities.codebase.TestingModel) Model(org.whole.lang.models.model.Model) Test(org.junit.Test)

Example 5 with Variable

use of org.whole.lang.commons.model.Variable in project whole by wholeplatform.

the class MatcherTest method testRenameMap.

@Test
public void testRenameMap() {
    Feature featurePattern = new FeaturePattern().create();
    Variable var1 = (Variable) featurePattern.getType().wGetAdaptee(false);
    Variable var2 = (Variable) featurePattern.getName().wGetAdaptee(false);
    assertEquals("featureType", var1.getVarName().getValue());
    assertEquals("featureName", var2.getVarName().getValue());
    Map<String, String> map = new HashMap<String, String>();
    map.put("featureType", "fType");
    map.put("featureName", "fName");
    Matcher.rename(featurePattern, map, false);
    assertEquals("fType", var1.getVarName().getValue());
    assertEquals("fName", var2.getVarName().getValue());
}
Also used : Variable(org.whole.lang.commons.model.Variable) HashMap(java.util.HashMap) Feature(org.whole.lang.models.model.Feature) 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