use of org.whole.lang.reflect.ILanguageKit in project whole by wholeplatform.
the class GrammarsContentAssistVisitor method calculateAsNameValues.
public static Set<String> calculateAsNameValues(IEntity e) {
Grammar grammar = Matcher.findAncestor(Grammar, e);
if (grammar != null) {
Production production = Matcher.findAncestor(Production, e);
String entityName = production.getName().getValue();
ILanguageKit languageKit = getLanguageKitIfExists(grammar);
if (languageKit != null) {
EntityDescriptor<?> ed = languageKit.getEntityDescriptorEnum().valueOf(entityName);
if (ed != null) {
Set<String> names = new HashSet<String>();
for (FeatureDescriptor fd : ed.getEntityFeatureDescriptors()) names.add(fd.getName());
return names;
}
}
}
return Collections.emptySet();
}
use of org.whole.lang.reflect.ILanguageKit in project whole by wholeplatform.
the class GrammarsContentAssistVisitor method calculateNonTerminalValues.
public static Set<String> calculateNonTerminalValues(IEntity e) {
Grammar grammar = Matcher.findAncestor(Grammar, e);
if (grammar != null) {
Set<String> names = new HashSet<String>();
IEntity parent = e.wGetParent();
ILanguageKit languageKit = getLanguageKitIfExists(grammar);
if (languageKit != null) {
if (!grammar.getLexicalStructure().equals(parent.wGetParent()))
names.addAll(languageKit.getEntityDescriptorEnum().names());
if (!parent.wGetFeatureDescriptor(e).equals(name)) {
QueriesEntityFactory qef = QueriesEntityFactory.instance;
Path allTokenNames = qef.createPath(qef.createSequence(qef.createFeatureStep("lexicalStructure"), qef.createFeatureStep("phraseStructure")), qef.createChildStep(), qef.createFilter(qef.createFeatureStep("name"), qef.createKindTest(KindTestEnum.IMPL)));
for (NonTerminal nt : BehaviorUtils.<NonTerminal>compileAndLazyEvaluate(allTokenNames, grammar)) names.add(nt.getValue());
}
} else {
AbstractPatternFilterIterator<NonTerminal> i = IteratorFactory.<NonTerminal>descendantOrSelfMatcherIterator().withPattern(NonTerminal);
i.reset(grammar);
for (NonTerminal nt : i) if (EntityUtils.isNotResolver(nt))
names.add(nt.getValue());
}
return names;
}
return Collections.emptySet();
}
use of org.whole.lang.reflect.ILanguageKit 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);
}
use of org.whole.lang.reflect.ILanguageKit in project whole by wholeplatform.
the class CommonsDataTypePresentationParser method parseFeatureDescriptor.
public static FeatureDescriptor parseFeatureDescriptor(String value) {
int index = value.indexOf('#');
if (index > 0) {
String languageUri = value.substring(0, index);
ILanguageKit lk = /*= null;
if (ReflectionFactory.hasLanguageKit(languageUri)) {
for (ILanguageKit lk2 : ReflectionFactory.getLanguageKits(true))
if (lk2.getName().equalsIgnoreCase(languageUri)) {
lk = lk2;
break;
}
}
if (lk == null)
lk*/
ReflectionFactory.getLanguageKit(languageUri);
FeatureDescriptor fd = lk.getFeatureDescriptorEnum().valueOf(value.substring(index + 1));
if (fd != null)
return fd;
}
throw new WholeIllegalArgumentException(WholeMessages.no_data_type);
}
use of org.whole.lang.reflect.ILanguageKit in project whole by wholeplatform.
the class GrammarsInterpreterVisitor method visit.
@Override
public void visit(Grammar grammar) {
grammar = normalize(grammar);
GrammarsRegistry.instance().putGrammar(grammar);
TargetLanguage targetLanguage = grammar.getTargetLanguage();
ILanguageKit languageKit = null;
final String languageUri;
IBindingManager bm = getBindings();
if (Matcher.match(GrammarsEntityDescriptorEnum.URI, targetLanguage)) {
languageUri = targetLanguage.wStringValue();
languageKit = ReflectionFactory.getLanguageKit(languageUri, true, bm);
} else {
languageUri = ((LanguageDescriptor) targetLanguage).getUri().getValue();
stagedVisit(GrammarsUtils.deriveModel(grammar, false));
languageKit = (ILanguageKit) bm.getResult().wGetValue();
}
if (languageKit.isDynamic()) {
DynamicLanguageKit dynamicLanguageKit = (DynamicLanguageKit) languageKit;
GrammarBasedDataTypeParser dataTypeParser = new GrammarBasedDataTypeParser(grammar.getUri().getValue());
dynamicLanguageKit.setDataTypeParser(DataTypeParsers.PERSISTENCE, dataTypeParser);
dynamicLanguageKit.setDataTypeParser(DataTypeParsers.PRESENTATION, dataTypeParser);
}
ReflectionFactory.updatePersistenceAndEditorKits(languageKit);
ReflectionFactory.deploy(new AbstractLanguageExtensionDeployer() {
public void deploy(ReflectionFactory platform) {
platform.addOperationFactory(languageUri, PrettyPrinterOperation.ID, new IVisitorFactory() {
public IVisitor create(IOperation operation, int stage) {
return new GenericGrammarBasedPrettyPrinterVisitor((PrettyPrinterOperation) operation);
}
});
platform.addOperationFactory(languageUri, ValidatorOperation.ID, new IVisitorFactory() {
public IVisitor create(IOperation operation, int stage) {
return new GenericGrammarBasedValidatorVisitor();
}
});
}
});
}
Aggregations