Search in sources :

Example 6 with EntityDescriptor

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

the class GenericGrammarBasedValidatorVisitor method calculateDataTerminals.

private void calculateDataTerminals(Grammar grammar) {
    this.dataTerminals = new HashMap<EntityDescriptor<?>, DataTerminal>();
    // TODO ensure grammar normalized
    Map<String, Rule> productions = new HashMap<String, Rule>();
    IEntityIterator<Production> pi = IteratorFactory.<Production>childIterator();
    pi.reset(grammar.getPhraseStructure());
    for (Production p : pi) productions.put(p.getName().getValue(), p.getRule());
    Map<String, Rule> lexicon = new HashMap<String, Rule>();
    IEntityIterator<Production> li = IteratorFactory.<Production>childIterator();
    li.reset(grammar.getLexicalStructure());
    for (Production p : li) lexicon.put(p.getName().getValue(), p.getRule());
    ILanguageKit languageKit = ReflectionFactory.getLanguageKit(GrammarsUtils.getLanguageURI(grammar), false, null);
    EntityDescriptorEnum edEnum = languageKit.getEntityDescriptorEnum();
    for (EntityDescriptor<?> ed : edEnum) if (EntityUtils.isData(ed)) {
        Rule production = productions.get(ed.getName());
        if (!ed.getDataKind().isEnumValue()) {
            DataTerminal dataTerminal = Matcher.find(GrammarsEntityDescriptorEnum.DataTerminal, production, false);
            if (dataTerminal == null) {
                NonTerminal nonTerminal = Matcher.find(GrammarsEntityDescriptorEnum.NonTerminal, production, false);
                dataTerminal = Matcher.find(GrammarsEntityDescriptorEnum.DataTerminal, lexicon.get(nonTerminal.getValue()), false);
            }
            dataTerminals.put(ed, EntityUtils.clone(dataTerminal));
        }
    }
}
Also used : EntityDescriptorEnum(org.whole.lang.reflect.EntityDescriptorEnum) GrammarsEntityDescriptorEnum(org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum) HashMap(java.util.HashMap) NonTerminal(org.whole.lang.grammars.model.NonTerminal) ILanguageKit(org.whole.lang.reflect.ILanguageKit) EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) Production(org.whole.lang.grammars.model.Production) DataTerminal(org.whole.lang.grammars.model.DataTerminal) Rule(org.whole.lang.grammars.model.Rule)

Example 7 with EntityDescriptor

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

the class PojoUtils method getEntityDescriptor.

@SuppressWarnings("unchecked")
private static <E extends IEntity> EntityDescriptor<E> getEntityDescriptor(ProductDeclaration declaration, Library library) {
    String entityTypeName = declaration.getTemplate().wStringValue();
    ;
    ILanguageKit languageKit = ReflectionFactory.getLanguageKit(library.getLanguageURI().wStringValue());
    return (EntityDescriptor<E>) languageKit.getEntityDescriptorEnum().valueOf(entityTypeName);
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 8 with EntityDescriptor

use of org.whole.lang.reflect.EntityDescriptor 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 9 with EntityDescriptor

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

the class DBSchemaTemplateFactoryTest method testRDBUtils.

@Category(KnownFailingTests.class)
@Test
public void testRDBUtils() throws Exception {
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    bm.wDefValue("connection", connection);
    bm.wDefValue("generateDropStatements", false);
    Database database = new SampleDatabase().create();
    InterpreterOperation.interpret(database, bm);
    DBSchemaTemplateFactory dbSchemaTemplateFactory = new DBSchemaTemplateFactory(connection, "DBNAME", null);
    Database generatedDatabase = dbSchemaTemplateFactory.create();
    HashMap<EntityDescriptor<?>, Comparator<IEntity>> comparatorsMap = new HashMap<EntityDescriptor<?>, Comparator<IEntity>>();
    comparatorsMap.put(RDBEntityDescriptorEnum.Tables, new OrderedMatcher.SimpleFeatureComparator(RDBFeatureDescriptorEnum.name));
    Assert.assertTrue(OrderedMatcher.match(database, generatedDatabase, comparatorsMap));
    Assert.fail();
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) HashMap(java.util.HashMap) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Database(org.whole.lang.rdb.model.Database) Comparator(java.util.Comparator) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 10 with EntityDescriptor

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

the class EntityAssistCompositeContributionItem method createWrapActions.

protected List<IAction> createWrapActions(ILanguageKit lk, IEntity targetEntity) {
    List<IAction> wrapActions = new ArrayList<IAction>();
    Set<EntityDescriptor<?>> wrapTypes = new HashSet<EntityDescriptor<?>>();
    IGEFEditorKit editorKit = (IGEFEditorKit) (targetEntity.wGetLanguageKit().equals(lk) ? ReflectionFactory.getEditorKit(targetEntity) : lk.getDefaultEditorKit());
    for (Object[] wrapAction : editorKit.getActionFactory().wrapActions()) {
        EntityDescriptor<?> ed = (EntityDescriptor<?>) wrapAction[1];
        if (isWrappable(targetEntity, ed, (IEnablerPredicate) wrapAction[0])) {
            String label = (String) wrapAction[2];
            IEntityTransformer transformer = (IEntityTransformer) wrapAction[3];
            wrapActions.add(contextProvider.getActionRegistry().getActionFactory().createPerformAction(label, WRAP_ICON_URI, QueriesEntityFactory.instance.createBooleanLiteral(true), getBehavior(ed, transformer)));
            wrapTypes.add(ed);
        }
    }
    for (EntityDescriptor<?> ed : lk.getEntityDescriptorEnum()) if (EntityUtils.isComposite(ed) && !wrapTypes.contains(ed) && isWrappable(targetEntity, ed, EnablerPredicateFactory.instance.assignableTo(ed.getEntityDescriptor(0)))) {
        String label = StringUtils.camelCaseToSpacedWords(ed.getName());
        wrapActions.add(contextProvider.getActionRegistry().getActionFactory().createPerformAction(label, WRAP_ICON_URI, QueriesEntityFactory.instance.createBooleanLiteral(true), getBehavior(ed, DefaultWrapInTransformer.instance)));
    }
    return wrapActions;
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) IAction(org.eclipse.jface.action.IAction) ArrayList(java.util.ArrayList) IGEFEditorKit(org.whole.lang.ui.editor.IGEFEditorKit) IEntityTransformer(org.whole.lang.util.IEntityTransformer) HashSet(java.util.HashSet)

Aggregations

EntityDescriptor (org.whole.lang.reflect.EntityDescriptor)29 IEntity (org.whole.lang.model.IEntity)13 ArrayList (java.util.ArrayList)9 ILanguageKit (org.whole.lang.reflect.ILanguageKit)7 HashMap (java.util.HashMap)5 EntityDescriptorEnum (org.whole.lang.reflect.EntityDescriptorEnum)5 ExpressionStatement (org.eclipse.jdt.core.dom.ExpressionStatement)4 FieldDeclaration (org.eclipse.jdt.core.dom.FieldDeclaration)4 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)4 Actions (org.whole.lang.actions.model.Actions)3 GroupAction (org.whole.lang.actions.model.GroupAction)3 ActionsUIEntityFactory (org.whole.lang.actions.ui.factories.ActionsUIEntityFactory)3 IBindingManager (org.whole.lang.bindings.IBindingManager)3 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)3 Comparator (java.util.Comparator)2 HashSet (java.util.HashSet)2 List (java.util.List)2 IAction (org.eclipse.jface.action.IAction)2 Test (org.junit.Test)2 Database (org.whole.lang.rdb.model.Database)2