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;
}
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;
}
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];
}
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));
}
}
}
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;
}
Aggregations