Search in sources :

Example 6 with ILanguageKit

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();
}
Also used : FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) Production(org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum.Production) Production(org.whole.lang.grammars.model.Production) Grammar(org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum.Grammar) Grammar(org.whole.lang.grammars.model.Grammar) ILanguageKit(org.whole.lang.reflect.ILanguageKit) HashSet(java.util.HashSet)

Example 7 with ILanguageKit

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();
}
Also used : Path(org.whole.lang.queries.model.Path) IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) NonTerminal(org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum.NonTerminal) NonTerminal(org.whole.lang.grammars.model.NonTerminal) Grammar(org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum.Grammar) Grammar(org.whole.lang.grammars.model.Grammar) ILanguageKit(org.whole.lang.reflect.ILanguageKit) HashSet(java.util.HashSet)

Example 8 with ILanguageKit

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);
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 9 with ILanguageKit

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);
}
Also used : FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 10 with ILanguageKit

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();
                }
            });
        }
    });
}
Also used : IOperation(org.whole.lang.operations.IOperation) GrammarBasedDataTypeParser(org.whole.lang.grammars.parsers.GrammarBasedDataTypeParser) LanguageDescriptor(org.whole.lang.grammars.model.LanguageDescriptor) AbstractLanguageExtensionDeployer(org.whole.lang.reflect.AbstractLanguageExtensionDeployer) IVisitorFactory(org.whole.lang.visitors.IVisitorFactory) ILanguageKit(org.whole.lang.reflect.ILanguageKit) DynamicLanguageKit(org.whole.lang.reflect.DynamicLanguageKit) ReflectionFactory(org.whole.lang.reflect.ReflectionFactory) IBindingManager(org.whole.lang.bindings.IBindingManager) TargetLanguage(org.whole.lang.grammars.model.TargetLanguage)

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