Search in sources :

Example 11 with ILanguageKit

use of org.whole.lang.reflect.ILanguageKit in project whole by wholeplatform.

the class QueriesContentAssistVisitor method visit.

@Override
public void visit(Name entity) {
    IEntity bindEntity = entity.wGetParent();
    if (!Matcher.match(Bind, bindEntity))
        return;
    IEntity bindingsEntity = bindEntity.wGetParent();
    if (!Matcher.match(Bindings, bindingsEntity))
        return;
    EntityType entityType;
    boolean allLanguageFeatures;
    IEntity entityCallOrTemplateEntity = bindingsEntity.wGetParent();
    switch(entityCallOrTemplateEntity.wGetEntityDescriptor().getOrdinal()) {
        case EntityCall_ord:
            entityType = ((EntityCall) entityCallOrTemplateEntity).getName();
            allLanguageFeatures = true;
            break;
        case EntityTemplate_ord:
            entityType = ((EntityTemplate) entityCallOrTemplateEntity).getName();
            allLanguageFeatures = false;
            break;
        default:
            return;
    }
    if (!DataTypeUtils.getDataKind(entityType).isString())
        return;
    String edUri = entityType.wStringValue();
    TreeSet<String> sortedNames = new TreeSet<String>();
    EntityDescriptor<?> ed = CommonsDataTypePersistenceParser.getEntityDescriptor(edUri, false, null);
    if (allLanguageFeatures || ed == null) {
        ILanguageKit lk = CommonsDataTypePersistenceParser.getLanguageKitPart(edUri);
        if (lk == null)
            return;
        Set<String> fNames = lk.getFeatureDescriptorEnum().names();
        sortedNames.addAll(fNames);
    } else
        for (FeatureDescriptor fd : ed.getEntityFeatureDescriptors()) sortedNames.add(fd.getName());
    allFeatureNames(sortedNames, entity.getValue());
}
Also used : EntityType(org.whole.lang.queries.model.EntityType) EntityType(org.whole.lang.queries.reflect.QueriesEntityDescriptorEnum.EntityType) IEntity(org.whole.lang.model.IEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) TreeSet(java.util.TreeSet) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 12 with ILanguageKit

use of org.whole.lang.reflect.ILanguageKit in project whole by wholeplatform.

the class QueriesContentAssistVisitor method allEntityTypes.

private boolean allEntityTypes(IEntity entity, EntityDescriptor<?> type) {
    if (!EntityUtils.hasParent(entity))
        return false;
    EntityDescriptor<?> featureED = entity.wGetParent().wGetEntityDescriptor(entity);
    if (!featureED.isPlatformSupertypeOf(EntityType) && !featureED.isPlatformSupertypeOf(TypeTest) && !featureED.isPlatformSupertypeOf(SubtypeTest) && !featureED.isPlatformSupertypeOf(SupertypeTest) && !featureED.isPlatformSupertypeOf(ExtendedSubtypeTest) && !featureED.isPlatformSupertypeOf(ExtendedSupertypeTest))
        return false;
    boolean alltypesTest = (type == SubtypeTest || type == SupertypeTest || type == ExtendedSubtypeTest || type == ExtendedSupertypeTest || type == AtTypeTest);
    ActionsUIEntityFactory aef = ActionsUIEntityFactory.instance;
    GroupAction languagesGroup = aef.createGroupAction();
    languagesGroup.setFillStrategy(aef.createHierarchical(aef.createDistinctPrefix(), aef.createSize(10)));
    languagesGroup.getText().setValue("queries.languages");
    Actions actions = aef.createActions(0);
    QueriesEntityFactory qef = QueriesEntityFactory.instance;
    String actualLanguageURI = "";
    String actualEntityName = "";
    EntityDescriptor<?> actualED = null;
    EntityDescriptor<?> targetED = type;
    try {
        actualED = CommonsDataTypePersistenceParser.parseEntityDescriptor(entity.wStringValue());
        actualLanguageURI = actualED.getLanguageKit().getURI();
        actualEntityName = actualED.getName();
    } catch (Exception e) {
        if (DataTypeUtils.getDataKind(entity).isString())
            actualEntityName = entity.wStringValue();
    }
    IResourceRegistry<ILanguageKit> registry = ReflectionFactory.getLanguageKitRegistry();
    for (ILanguageKit languageKit : registry.getResources(false, ResourceUtils.SIMPLE_COMPARATOR)) {
        if (languageKit.getURI().equals(actualLanguageURI))
            continue;
        EntityDescriptorEnum edEnum = languageKit.getEntityDescriptorEnum();
        EntityDescriptor<?> ed = null;
        if (actualEntityName.length() > 0)
            ed = edEnum.valueOf(actualEntityName);
        if (ed == null) {
            if (alltypesTest)
                ed = edEnum.valueOf(0);
            else {
                Iterator<EntityDescriptor<?>> iterator = edEnum.values().iterator();
                EntityDescriptor<?> nextED;
                while (ed == null && iterator.hasNext()) if (!(nextED = iterator.next()).isAbstract())
                    ed = nextED;
                if (ed == null)
                    continue;
            }
        }
        IEntity prototype = qef.create(targetED, CommonsDataTypePersistenceParser.unparseEntityDescriptor(ed));
        actions.wAdd(aef.createReplaceDifferentTemplateAction(prototype, ResourceUtils.SIMPLE_NAME_PROVIDER.toString(registry, languageKit), IActionConstants.SELECT_LANGUAGE_ICON));
    }
    languagesGroup.setActions(actions);
    boolean addedLanguages = EntityUtils.isResolver(entity) ? mergeResult(targetED, languagesGroup) : mergeResult(languagesGroup);
    if (actualED != null) {
        GroupAction typenamesGroup = aef.createGroupAction();
        typenamesGroup.setFillStrategy(aef.createHierarchical(aef.createDistinctPrefix(), aef.createSize(10)));
        typenamesGroup.getText().setValue(alltypesTest ? "queries.alltypenames" : "queries.typenames");
        actions = aef.createActions(0);
        EntityDescriptorEnum edEnum = actualED.getEntityDescriptorEnum();
        List<EntityDescriptor<?>> eds = new ArrayList<EntityDescriptor<?>>(edEnum.values());
        Collections.sort(eds, EnumValueImpl.getByNameComparator());
        for (EntityDescriptor<?> ed : eds) {
            if (ed.equals(actualED) || (!alltypesTest && ed.isAbstract()))
                continue;
            IEntity prototype = qef.create(targetED, CommonsDataTypePersistenceParser.unparseEntityDescriptor(ed));
            actions.wAdd(aef.createReplaceDifferentTemplateAction(prototype, ed.getName()));
        }
        typenamesGroup.setActions(actions);
        addedLanguages |= EntityUtils.isResolver(entity) ? mergeResult(targetED, typenamesGroup) : mergeResult(typenamesGroup);
    }
    return addedLanguages;
}
Also used : EntityDescriptorEnum(org.whole.lang.reflect.EntityDescriptorEnum) QueriesEntityDescriptorEnum(org.whole.lang.queries.reflect.QueriesEntityDescriptorEnum) Actions(org.whole.lang.actions.model.Actions) IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) ArrayList(java.util.ArrayList) ILanguageKit(org.whole.lang.reflect.ILanguageKit) GroupAction(org.whole.lang.actions.model.GroupAction) EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) ActionsUIEntityFactory(org.whole.lang.actions.ui.factories.ActionsUIEntityFactory)

Example 13 with ILanguageKit

use of org.whole.lang.reflect.ILanguageKit in project whole by wholeplatform.

the class QueriesContentAssistVisitor method allFeatureTypes.

private boolean allFeatureTypes(IEntity entity, EntityDescriptor<?> targetEd) {
    if (!EntityUtils.hasParent(entity) || !entity.wGetParent().wGetEntityDescriptor(entity).isPlatformSupertypeOf(targetEd))
        return false;
    ActionsUIEntityFactory aef = ActionsUIEntityFactory.instance;
    GroupAction languagesGroup = aef.createGroupAction();
    languagesGroup.setFillStrategy(aef.createHierarchical(aef.createDistinctPrefix(), aef.createSize(10)));
    languagesGroup.getText().setValue("queries.languages");
    Actions actions = aef.createActions(0);
    QueriesEntityFactory qef = QueriesEntityFactory.instance;
    String actualLanguageURI = "";
    String actualFeatureName = "";
    FeatureDescriptor actualFD = null;
    try {
        actualFD = CommonsDataTypePersistenceParser.parseFeatureDescriptor(entity.wStringValue());
        actualLanguageURI = actualFD.getLanguageKit().getURI();
        actualFeatureName = actualFD.getName();
    } catch (Exception e) {
        if (DataTypeUtils.getDataKind(entity).isString())
            actualFeatureName = entity.wStringValue();
    }
    IResourceRegistry<ILanguageKit> registry = ReflectionFactory.getLanguageKitRegistry();
    for (ILanguageKit languageKit : registry.getResources(false, ResourceUtils.SIMPLE_COMPARATOR)) {
        if (languageKit.getURI().equals(actualLanguageURI))
            continue;
        FeatureDescriptorEnum fdEnum = languageKit.getFeatureDescriptorEnum();
        if (fdEnum.values().isEmpty())
            continue;
        FeatureDescriptor fd = null;
        if (actualFeatureName.length() > 0)
            fd = fdEnum.valueOf(actualFeatureName);
        if (fd == null)
            fd = fdEnum.valueOf(0);
        IEntity prototype = qef.create(targetEd, CommonsDataTypePersistenceParser.unparseFeatureDescriptor(fd));
        actions.wAdd(aef.createReplaceDifferentTemplateAction(prototype, ResourceUtils.SIMPLE_NAME_PROVIDER.toString(registry, languageKit), IActionConstants.SELECT_LANGUAGE_ICON));
    }
    languagesGroup.setActions(actions);
    boolean addedLanguages = EntityUtils.isResolver(entity) ? mergeResult(targetEd, languagesGroup) : mergeResult(languagesGroup);
    if (actualFD != null) {
        GroupAction featurenamesGroup = aef.createGroupAction();
        featurenamesGroup.setFillStrategy(aef.createHierarchical(aef.createDistinctPrefix(), aef.createSize(10)));
        featurenamesGroup.getText().setValue("queries.featurenames");
        actions = aef.createActions(0);
        FeatureDescriptorEnum fdEnum = actualFD.getFeatureDescriptorEnum();
        List<FeatureDescriptor> fds = new ArrayList<FeatureDescriptor>(fdEnum.values());
        Collections.sort(fds, EnumValueImpl.getByNameComparator());
        for (FeatureDescriptor fd : fds) {
            if (fd.equals(actualFD))
                continue;
            IEntity prototype = qef.create(targetEd, CommonsDataTypePersistenceParser.unparseFeatureDescriptor(fd));
            actions.wAdd(aef.createReplaceDifferentTemplateAction(prototype, fd.getName()));
        }
        featurenamesGroup.setActions(actions);
        addedLanguages |= EntityUtils.isResolver(entity) ? mergeResult(targetEd, languagesGroup) : mergeResult(featurenamesGroup);
    }
    return addedLanguages;
}
Also used : FeatureDescriptorEnum(org.whole.lang.reflect.FeatureDescriptorEnum) Actions(org.whole.lang.actions.model.Actions) IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) ArrayList(java.util.ArrayList) ILanguageKit(org.whole.lang.reflect.ILanguageKit) GroupAction(org.whole.lang.actions.model.GroupAction) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) ActionsUIEntityFactory(org.whole.lang.actions.ui.factories.ActionsUIEntityFactory)

Example 14 with ILanguageKit

use of org.whole.lang.reflect.ILanguageKit in project whole by wholeplatform.

the class QueriesContentAssistVisitor method visit.

@Override
public void visit(LanguageTest entity) {
    String actualLanguageURI = entity.getValue();
    ActionsUIEntityFactory aef = ActionsUIEntityFactory.instance;
    GroupAction languagesGroup = aef.createGroupAction();
    languagesGroup.setFillStrategy(aef.createHierarchical(aef.createDistinctPrefix(), aef.createSize(10)));
    languagesGroup.getText().setValue("queries.languages");
    Actions actions = aef.createActions(0);
    QueriesEntityFactory qef = QueriesEntityFactory.instance;
    IResourceRegistry<ILanguageKit> registry = ReflectionFactory.getLanguageKitRegistry();
    for (ILanguageKit languageKit : registry.getResources(false, ResourceUtils.SIMPLE_COMPARATOR)) {
        String languageURI = languageKit.getURI();
        if (languageURI.equals(actualLanguageURI))
            continue;
        actions.wAdd(aef.createReplaceDifferentTemplateAction(qef.create(LanguageTest, languageURI), ResourceUtils.SIMPLE_NAME_PROVIDER.toString(registry, languageKit), IActionConstants.SELECT_LANGUAGE_ICON));
    }
    languagesGroup.setActions(actions);
    mergeResult(languagesGroup);
}
Also used : GroupAction(org.whole.lang.actions.model.GroupAction) Actions(org.whole.lang.actions.model.Actions) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) ActionsUIEntityFactory(org.whole.lang.actions.ui.factories.ActionsUIEntityFactory) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 15 with ILanguageKit

use of org.whole.lang.reflect.ILanguageKit in project whole by wholeplatform.

the class WorkflowsInterpreterVisitorTest method testInvokeOperation.

@Test
public void testInvokeOperation() throws Exception {
    IEntity invokeOperationTest = WorkflowsTestTemplateManager.instance().create("invokeOperationTest");
    IBindingManager args = BindingManagerFactory.instance.createArguments();
    TestDecorationManager dm = new TestDecorationManager();
    args.wDefValue("decorationManager", dm);
    StringWriter writer = new StringWriter();
    args.wDefValue("printWriter", new PrintWriter(writer));
    InterpreterOperation.interpret(invokeOperationTest, args);
    Assert.assertTrue(args.wIsSet("model"));
    Assert.assertTrue(args.wIsSet("modelCopy"));
    // validate assertions
    Assert.assertNotNull(dm.messages);
    Assert.assertFalse(dm.messages.isEmpty());
    Assert.assertEquals(1, dm.messages.size());
    Assert.assertTrue(dm.messages.contains("Reference to the undeclared type: IType"));
    // normalize assertions
    IEntity modelCopy = args.wGet("modelCopy");
    Assert.assertFalse(Matcher.match(args.wGet("model"), modelCopy));
    Assert.assertTrue(Matcher.match(args.wGet("model"), NormalizerOperation.normalize(EntityUtils.clone(modelCopy))));
    // pretty print assertions
    String ls = System.getProperty("line.separator");
    String TEXT_MODEL = "model SampleM" + ls + ls + ls + "entity Type types IType" + ls + "    feature DataStr data" + ls + ls + "entity DataStr" + ls + "    value <String>" + ls + ls + "abstract entity IType" + ls;
    Assert.assertEquals(TEXT_MODEL, writer.toString());
    // pretty print assertions
    ILanguageKit languageKit = ReflectionFactory.getLanguageKit("http://lang.whole.org/SampleM");
    Assert.assertNotNull(languageKit);
    EntityDescriptor<? extends IEntity> ed = languageKit.getEntityDescriptorEnum().valueOf("Type");
    Assert.assertNotNull(ed);
    Assert.assertEquals(1, ed.featureSize());
    // generate assertions
    File file = new File("./data/SampleM.xwl");
    Assert.assertTrue(file.exists());
    IEntity entity = XmlBuilderPersistenceKit.instance().readModel(new FilePersistenceProvider(file));
    Assert.assertTrue(Matcher.match(args.wGet("model"), entity));
    Assert.assertFalse(args.wIsSet("fileArtifact"));
}
Also used : StringWriter(java.io.StringWriter) IEntity(org.whole.lang.model.IEntity) FilePersistenceProvider(org.whole.lang.codebase.FilePersistenceProvider) IBindingManager(org.whole.lang.bindings.IBindingManager) File(java.io.File) ILanguageKit(org.whole.lang.reflect.ILanguageKit) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

ILanguageKit (org.whole.lang.reflect.ILanguageKit)41 IEntity (org.whole.lang.model.IEntity)12 EntityDescriptorEnum (org.whole.lang.reflect.EntityDescriptorEnum)8 Actions (org.whole.lang.actions.model.Actions)7 GroupAction (org.whole.lang.actions.model.GroupAction)7 EntityDescriptor (org.whole.lang.reflect.EntityDescriptor)7 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)6 ArrayList (java.util.ArrayList)5 ActionsUIEntityFactory (org.whole.lang.actions.ui.factories.ActionsUIEntityFactory)5 Test (org.junit.Test)4 QueriesEntityFactory (org.whole.lang.queries.factories.QueriesEntityFactory)4 IVisitor (org.whole.lang.visitors.IVisitor)4 HashMap (java.util.HashMap)3 IBindingManager (org.whole.lang.bindings.IBindingManager)3 Grammar (org.whole.lang.grammars.model.Grammar)3 IDataTypeParser (org.whole.lang.parsers.IDataTypeParser)3 HashSet (java.util.HashSet)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 IPersistenceKit (org.whole.lang.codebase.IPersistenceKit)2