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