Search in sources :

Example 1 with EntityDescriptorEnum

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

the class XmlStoreConsumerVisitor method visit.

public void visit(QualifiedName entity) {
    String nameSpace = entity.getNameSpace().wStringValue();
    String qualifiedString = entity.getName().wStringValue();
    EntityDescriptorEnum edEnum = (EntityDescriptorEnum) entityDescriptorEnumMap.get(nameSpace);
    entityDescriptor = getEntityDescriptor(edEnum, qualifiedString);
}
Also used : XmlEntityDescriptorEnum(org.whole.lang.xml.reflect.XmlEntityDescriptorEnum) EntityDescriptorEnum(org.whole.lang.reflect.EntityDescriptorEnum)

Example 2 with EntityDescriptorEnum

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

the class OutlineUIProvider method getPartDataProvider.

public IOutlineUIProvider getPartDataProvider(IEntity entity) {
    ILanguageKit languageKit = entity.wGetLanguageKit();
    IUITemplate pt = ((IGEFEditorKit) entity.wGetEditorKit()).getUITemplate(languageKit);
    String id = pt.getId();
    IOutlineUIProvider[] data = idPartDataMap.get(id);
    if (data == null) {
        EntityDescriptorEnum types = languageKit.getEntityDescriptorEnum();
        int size = types.size();
        idPartDataMap.put(id, data = new IOutlineUIProvider[size]);
        for (int i = 0; i < data.length; i++) data[i] = DefaultOutlineUIProvider.instance;
        pt.applyOutline(createOutlineBuilder(data));
    }
    int entityOrd = entity.wGetEntityOrd();
    if (data.length <= entityOrd)
        return DefaultOutlineUIProvider.instance;
    return data[entityOrd];
}
Also used : EntityDescriptorEnum(org.whole.lang.reflect.EntityDescriptorEnum) IGEFEditorKit(org.whole.lang.ui.editor.IGEFEditorKit) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 3 with EntityDescriptorEnum

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

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

the class GrammarBasedUnparserVisitor method visit.

@Override
public void visit(Choose entity) {
    if (!appendModelEntityAsFragment()) {
        if (Matcher.match(GrammarsEntityDescriptorEnum.As, entity.wGet(0)))
            append(getAsString(model));
        else {
            // get rule using model entity
            EntityDescriptorEnum edEnum = model.wGetLanguageKit().getEntityDescriptorEnum();
            Rule rule = null;
            for (int size = entity.wSize(), i = 0; rule == null && i < size; i++) {
                Rule child = (Rule) entity.wGet(i);
                NonTerminal nt = (NonTerminal) Matcher.find(phraseNonTerminal, child, false);
                if (// TODO test was isAssignableFrom
                Matcher.isAssignableAsIsFrom(edEnum.valueOf(nt.getValue()), model))
                    rule = child;
            }
            if (rule != null)
                rule.accept(this);
            else
                throw new IllegalStateException("missing choose rule for model entity");
        }
    }
}
Also used : EntityDescriptorEnum(org.whole.lang.reflect.EntityDescriptorEnum) GrammarsEntityDescriptorEnum(org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum) NonTerminal(org.whole.lang.grammars.model.NonTerminal) Rule(org.whole.lang.grammars.model.Rule)

Example 5 with EntityDescriptorEnum

use of org.whole.lang.reflect.EntityDescriptorEnum 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)

Aggregations

EntityDescriptorEnum (org.whole.lang.reflect.EntityDescriptorEnum)13 ILanguageKit (org.whole.lang.reflect.ILanguageKit)8 IEntity (org.whole.lang.model.IEntity)6 EntityDescriptor (org.whole.lang.reflect.EntityDescriptor)5 ArrayList (java.util.ArrayList)3 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 Test (org.junit.Test)2 NonTerminal (org.whole.lang.grammars.model.NonTerminal)2 Rule (org.whole.lang.grammars.model.Rule)2 GrammarsEntityDescriptorEnum (org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 DateTime (org.joda.time.DateTime)1 FramesEntityFactory (org.whole.lang.frames.factories.FramesEntityFactory)1 DataTerminal (org.whole.lang.grammars.model.DataTerminal)1 Production (org.whole.lang.grammars.model.Production)1 JavaEntityDescriptorEnum (org.whole.lang.java.reflect.JavaEntityDescriptorEnum)1 ModelsModel (org.whole.lang.models.codebase.ModelsModel)1