use of org.whole.lang.factories.IEntityFactory in project whole by wholeplatform.
the class ArtifactsUtils method cloneArtifact.
public static IEntity cloneArtifact(IEntity artifact, IEntity appendChild) {
IEntityFactory ef = GenericEntityFactory.instance(RegistryConfigurations.RESOLVER);
EntityDescriptor<?> ed = artifact.wGetEntityDescriptor();
IEntity newArtifact = ef.create(ed);
for (FeatureDescriptor fd : ed.getEntityFeatureDescriptors()) {
if (artifacts.equals(fd) || projects.equals(fd)) {
IEntity composite = newArtifact.wGet(fd);
if (appendChild != null)
composite.wAdd(appendChild);
else
composite.wResolveWith(fd.getEntityDescriptor());
} else
newArtifact.wSet(fd, EntityUtils.clone(artifact.wGet(fd)));
}
return newArtifact;
}
use of org.whole.lang.factories.IEntityFactory in project whole by wholeplatform.
the class BindingManagerFactory method createFlatBindingsModel.
public IEntity createFlatBindingsModel(IBindingManager bm) {
IEntityFactory ef = GenericEntityFactory.instance;
IEntity bindings = ef.create(getEdEnum().valueOf("Bindings"));
Set<String> names = bm.wNames();
for (String name : new TreeSet<String>(names)) bindings.wAdd(createBinding(name, bm.wGet(name)));
return bindings;
}
use of org.whole.lang.factories.IEntityFactory in project whole by wholeplatform.
the class BindingManagerFactory method createFlatScopedBindingsModel.
public IEntity createFlatScopedBindingsModel(IBindingManager bm) {
IEntityFactory ef = GenericEntityFactory.instance;
IEntity scopedBindings = ef.create(getEdEnum().valueOf("ScopedBindings"));
IBindingScope scope = bm;
Map<String, IEntity> bindingsMap = new TreeMap<String, IEntity>();
do {
for (String name : scope.wLocalNames()) {
IEntity value = scope.wGet(name);
if (value == null)
continue;
if (!bindingsMap.containsKey(name))
bindingsMap.put(name, value);
}
IEntity sourceEntity = scope.getSourceEntity();
if (sourceEntity != null || scope.wEnclosingScope() == NullScope.instance) {
int i = 0;
for (Map.Entry<String, IEntity> entry : bindingsMap.entrySet()) scopedBindings.wAdd(i++, createBinding(entry.getKey(), entry.getValue()));
bindingsMap.clear();
scopedBindings.wAdd(0, ef.create(getEdEnum().valueOf("Scope"), ef.create(getEdEnum().valueOf("BindingScope"), (Object) scope), ef.create(getEdEnum().valueOf("Value"), (Object) scope.getSourceEntity())));
}
} while ((scope = scope.wEnclosingScope()) != NullScope.instance);
return scopedBindings;
}
use of org.whole.lang.factories.IEntityFactory in project whole by wholeplatform.
the class DynamicModelDefinitionTest method testLanguageKitDefinition.
@Test
public void testLanguageKitDefinition() {
DynamicLanguageKit lk = new DynamicLanguageKit();
lk.setURI("http://lang.whole.org/DynamicImpl");
lk.setNamespace("org.whole.lang.reflect");
lk.setName("DynamicImp");
FeatureDescriptorEnum fds = lk.getFeatureDescriptorEnum();
fds.addFeatureDescriptors("value", "type", "name", "parameters", "body", "initializer", "exp", "exp1", "exp2", "condition", "trueBody", "falseBody", "arguments", "updater");
EntityDescriptorEnum eds = lk.getEntityDescriptorEnum();
final EntityDescriptor<?> ExpressionDesc = eds.addSimpleEntity("Expression", "Expression", true);
final EntityDescriptor<?> StatementDesc = eds.addSimpleEntity("Statement", "Statement", true);
EntityDescriptor<?> bs = eds.addCompositeEntity("BlockStatement", "BlockStatement", false, true, false);
bs.withFeature(CommonsFeatureDescriptorEnum.composite_element, StatementDesc.getOrdinal());
EntityDescriptor<?> ifs = eds.addSimpleEntity("IfStatement", "IfStatement", false).withFeature(fds.valueOf("condition"), ExpressionDesc.getOrdinal()).withFeature(fds.valueOf("trueBody"), StatementDesc.getOrdinal());
EntityDescriptor<?> ifes = eds.addSimpleEntity("IfElseStatement", "IfElseStatement", false).withFeature(fds.valueOf("condition"), ExpressionDesc.getOrdinal()).withFeature(fds.valueOf("trueBody"), StatementDesc.getOrdinal()).withFeature(fds.valueOf("falseBody"), StatementDesc.getOrdinal());
EntityDescriptor<?> ws = eds.addSimpleEntity("WhileStatement", "WhileStatement", false).withFeature(fds.valueOf("condition"), ExpressionDesc.getOrdinal()).withFeature(fds.valueOf("body"), StatementDesc.getOrdinal());
EntityDescriptor<?> es = eds.addSimpleEntity("ExpressionStatement", "ExpressionStatement", false).withFeature(fds.valueOf("exp"), ExpressionDesc.getOrdinal());
StatementDesc.setLanguageSubtypes(true, bs.getOrdinal(), ifs.getOrdinal(), ifes.getOrdinal(), ws.getOrdinal(), es.getOrdinal());
final EntityDescriptor<?> LiteralDesc = eds.addSimpleEntity("Literal", "Literal", true);
LiteralDesc.setLanguageSubtypes(true, eds.addDataEntity("BooleanLiteral", "BooleanLiteral", false, Boolean.TYPE).getOrdinal(), eds.addDataEntity("IntLiteral", "IntLiteral", false, Integer.TYPE).getOrdinal(), eds.addDataEntity("StringLiteral", "StringLiteral", false, String.class).getOrdinal());
EntityDescriptor<?> ne = eds.addDataEntity("Name", "Name", false, String.class);
eds.addSimpleEntity("AssignmentExpression", "AssignmentExpression", false).withFeature(fds.valueOf("name"), ne.getOrdinal()).withFeature(fds.valueOf("exp"), ExpressionDesc.getOrdinal());
for (String edName : new String[] { "And", "Or", "Addition", "Division", "Multiplication", "Remainder", "Subtraction", "Equals", "GreaterOrEquals", "GreaterThan", "LessOrEquals", "LessThan", "NotEquals" }) {
eds.addSimpleEntity(edName, edName, false).withFeature(fds.valueOf("exp1"), ExpressionDesc.getOrdinal()).withFeature(fds.valueOf("exp1"), ExpressionDesc.getOrdinal());
}
// TODO configure entity registry
ReflectionFactory.deploy(DynamicLanguageKit.getDeployer(lk));
assertEquals(lk, ReflectionFactory.getLanguageKit(lk.getURI()));
IEntityFactory ef = GenericEntityFactory.instance;
IEntity p = ef.create(eds.valueOf("WhileStatement"), ef.create(eds.valueOf("GreaterThan"), ef.create(eds.valueOf("Name"), "n"), ef.create(eds.valueOf("IntLiteral"), 0)), ef.create(eds.valueOf("ExpressionStatement"), ef.create(eds.valueOf("AssignmentExpression"), ef.create(eds.valueOf("Name"), "n"), ef.create(eds.valueOf("Subtraction"), ef.create(eds.valueOf("Name"), "n"), ef.create(eds.valueOf("IntLiteral"), 1)))));
assertEquals(lk, p.wGetLanguageKit());
}
use of org.whole.lang.factories.IEntityFactory in project whole by wholeplatform.
the class DynamicModelDefinitionTest method testTupleDefinition.
@Test
public void testTupleDefinition() {
DynamicLanguageKit lk = new DynamicLanguageKit();
lk.setURI("http://lang.whole.org/QueriesTupleResultLanguage");
lk.setNamespace("org.whole.lang.reflect");
lk.setName("QueriesTupleResultLanguage");
EntityDescriptorEnum eds = lk.getEntityDescriptorEnum();
EntityDescriptor<?> any = eds.addSimpleEntity("Any", "Any", true);
EntityDescriptor<?> gtd = eds.addCompositeEntity("GenericTuple", "GenericTuple", false, true, false);
gtd.withFeature(CommonsFeatureDescriptorEnum.composite_element, any.getOrdinal());
eds.setAssignableFromAll(true, any.getOrdinal());
ReflectionFactory.deploy(DynamicLanguageKit.getDeployer(lk));
assertEquals(lk, ReflectionFactory.getLanguageKit(lk.getURI()));
IEntityFactory ef = GenericEntityFactory.instance;
IEntity p = ef.create(eds.valueOf("GenericTuple"));
IEntity[] e = new IEntity[2];
p.wAdd(e[0] = QueriesEntityFactory.instance.createSelfStep());
p.wAdd(e[1] = GrammarsEntityFactory.instance.createNonTerminal("myNt"));
assertEquals(2, p.wSize());
assertSame(e[0], p.wGet(0));
assertSame(e[1], p.wGet(1));
}
Aggregations