Search in sources :

Example 1 with ILanguageKit

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

the class AbstractOperation method setVisitor.

// TODO test and change into liftVisitor
public IVisitor setVisitor(IEntity entity, int absoluteStage, IVisitor visitor) {
    ILanguageKit languageKit = ReflectionFactory.getLanguageKit(entity);
    IVisitor oldVisitor = languageKit.hasVisitor(this) ? getVisitor(entity, absoluteStage) : null;
    int normalizedStage = absoluteStage <= 0 ? 0 : 1;
    String uri = ReflectionFactory.getLanguageKit(entity).getURI();
    IVisitor[] stagedVisitors = stagedVisitorsMap.get(uri);
    if (stagedVisitors == null)
        stagedVisitorsMap.put(uri, stagedVisitors = new IVisitor[2]);
    stagedVisitors[normalizedStage] = visitor;
    return oldVisitor;
}
Also used : IVisitor(org.whole.lang.visitors.IVisitor) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 2 with ILanguageKit

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

the class AbstractOperation method initVisitor.

protected IVisitor initVisitor(IEntity entity, int normalizedStage) {
    ILanguageKit languageKit = ReflectionFactory.getLanguageKit(entity);
    IVisitor visitor = null;
    if (languageKit.hasVisitor(this))
        visitor = languageKit.getVisitor(this, normalizedStage);
    if (visitor == null)
        visitor = getDefaultVisitor(entity, normalizedStage);
    return visitor;
}
Also used : IVisitor(org.whole.lang.visitors.IVisitor) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 3 with ILanguageKit

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

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

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

the class ActionsUIEntityFactory method createLanguagesGroupAction.

public GroupAction createLanguagesGroupAction(ActionKindEnum.Value kind, Set<String> excludeSet, EntityDescriptor<?> resultEd) {
    GroupAction groupAction = createHierarchicalGroupAction(resultEd.getLanguageKit().getName() + ".languages");
    Actions actions = createActions(0);
    IResourceRegistry<ILanguageKit> registry = ReflectionFactory.getLanguageKitRegistry();
    for (ILanguageKit languageKit : registry.getResources(false, ResourceUtils.SIMPLE_COMPARATOR)) {
        String uri = languageKit.getURI();
        if (excludeSet.contains(uri))
            continue;
        actions.wAdd(createTemplateAction(kind, create(resultEd, uri), ResourceUtils.SIMPLE_NAME_PROVIDER.toString(registry, languageKit), IActionConstants.SELECT_LANGUAGE_ICON, kind == ActionKindEnum.REPLACE));
    }
    groupAction.setActions(actions);
    return groupAction;
}
Also used : GroupAction(org.whole.lang.actions.model.GroupAction) Actions(org.whole.lang.actions.model.Actions) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

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