Search in sources :

Example 21 with ILanguageKit

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

the class ReflectLibraryDeployer method getFeatureDescriptor.

public static FeatureDescriptor getFeatureDescriptor(IEntity selfEntity, IBindingManager bm) {
    FeatureDescriptor fd = null;
    if (DataTypeUtils.getDataKind(selfEntity).isString()) {
        String uri = selfEntity.wStringValue();
        if (ResourceUtils.hasFragmentPart(uri)) {
            String languageUri = ResourceUtils.stripFragmentPart(uri);
            String descriptorName = ResourceUtils.getFragmentPart(uri);
            ILanguageKit languageKit = ReflectionFactory.safeGetLanguageKit(languageUri, true, bm);
            if (languageKit != null)
                fd = languageKit.getFeatureDescriptorEnum().valueOf(descriptorName);
        }
    } else if (DataTypeUtils.getDataKind(selfEntity).isEnumValue() && selfEntity.wEnumValue() instanceof FeatureDescriptor)
        fd = (FeatureDescriptor) selfEntity.wEnumValue();
    else if (DataTypeUtils.getDataKind(selfEntity).isObject() && selfEntity.wGetValue() instanceof FeatureDescriptor)
        fd = (FeatureDescriptor) selfEntity.wGetValue();
    return fd;
}
Also used : FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 22 with ILanguageKit

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

the class QueriesDynamicCompilerVisitor method visit.

@Override
public void visit(Choose entity) {
    int size = entity.wSize();
    if (size == 1)
        entity.get(0).accept(this);
    else {
        boolean canOptimize = true;
        ILanguageKit languageKit = null;
        Map<EntityDescriptor<?>, Expression> typeMap = new HashMap<EntityDescriptor<?>, Expression>();
        If ifWithTemplate = new IfWithTemplate().create();
        If ifWithTypeTest = new IfWithTypeTest().create();
        ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
        getBindings().wEnterScope(ts);
        for (int i = 0; i < size; i++) {
            Expression child = entity.get(i);
            try {
                if (!Matcher.match(ifWithTemplate, child, getBindings()) && !Matcher.match(ifWithTypeTest, child, getBindings())) {
                    canOptimize = false;
                    break;
                }
                EntityDescriptor<?> ed = getBindings().wIsSet("typeTest") && getBindings().wGet("typeTest").wGetEntityDescriptor().getDataKind().isString() ? CommonsDataTypePersistenceParser.getEntityDescriptor(getBindings().wStringValue("typeTest")) : getBindings().wIsSet("pattern") ? getBindings().wGet("pattern").wGetEntityDescriptor() : null;
                if (ed == null) {
                    canOptimize = false;
                    break;
                }
                if (typeMap.containsKey(ed)) {
                    Expression behavior = typeMap.get(ed);
                    boolean isPattern = behavior.wGetParent() == entity;
                    if (isPattern) {
                        canOptimize = false;
                        break;
                    }
                } else {
                    if (languageKit == null)
                        languageKit = ed.getLanguageKit();
                    else if (!languageKit.equals(ed.getLanguageKit())) {
                        // ||
                        // !languageKit.getURI().equals("whole:org.whole.lang.javascript:JavaScript"))
                        // {
                        canOptimize = false;
                        break;
                    }
                    typeMap.put(ed, getBindings().wIsSet("pattern") ? child : getBindings().wGet("expression").wGetAdapter(QueriesEntityDescriptorEnum.Expression));
                }
            } finally {
                ts.rollback();
            }
        }
        getBindings().wExitScope();
        if (canOptimize && languageKit != null) {
            ChooseByTypeIterator<IEntity> chooseIterator = IteratorFactory.chooseIterator(languageKit);
            for (Entry<EntityDescriptor<?>, Expression> entry : typeMap.entrySet()) {
                Set<String> oldDeclaredNames = declaredNames;
                entry.getValue().accept(this);
                chooseIterator.setCase(entry.getKey(), getResultIterator());
                declaredNames = oldDeclaredNames;
            }
            setResultIterator(chooseIterator.withSourceEntity(entity));
        } else {
            IEntityIterator<? extends IEntity>[] iteratorChain = new IEntityIterator<?>[size];
            for (int i = 0; i < size; i++) {
                entity.get(i).accept(this);
                iteratorChain[i] = getResultIterator();
            }
            setResultIterator(IteratorFactory.chooseIterator(iteratorChain).withSourceEntity(entity));
        }
    }
}
Also used : ITransactionScope(org.whole.lang.bindings.ITransactionScope) HashMap(java.util.HashMap) IEntity(org.whole.lang.model.IEntity) ILanguageKit(org.whole.lang.reflect.ILanguageKit) EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) IfWithTypeTest(org.whole.lang.queries.codebase.IfWithTypeTest) IfWithTemplate(org.whole.lang.queries.codebase.IfWithTemplate) IEntityIterator(org.whole.lang.iterators.IEntityIterator)

Example 23 with ILanguageKit

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

the class JavaStoreProducerBuilder method ensureBuilder.

protected void ensureBuilder(EntityDescriptor<?> ed) {
    ensureMethodSizeLimit();
    ILanguageKit languageKit = ed.getLanguageKit();
    ILanguageKit builderLanguageKit = languageKit;
    if (languageKit.isDynamic()) {
        builderLanguageKit = ReflectionFactory.getLanguageKit(CommonsLanguageKit.URI);
        if (STRATEGY_FOR_DYNAMIC == null)
            STRATEGY_FOR_DYNAMIC = new SymbolicStrategy();
        strategy = STRATEGY_FOR_DYNAMIC;
    } else
        strategy = STRATEGY_FOR_STATIC;
    builderName = builderNameMap.get(builderLanguageKit);
    if (builderName == null) {
        builderName = builderPrefix + builderIndex++;
        builderNameMap.put(builderLanguageKit, builderName);
        buildGetBuilder(builderLanguageKit);
    }
    if (languageKit.isDynamic()) {
        edEnumName = edEnumNameMap.get(languageKit);
        if (edEnumName == null) {
            edEnumName = edEnumPrefix + builderIndex++;
            edEnumNameMap.put(languageKit, edEnumName);
            buildGetEntityDescriptorEnum(languageKit);
        }
    }
}
Also used : ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 24 with ILanguageKit

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

the class CommonsDataTypePresentationParser method parseEntityDescriptor.

public static EntityDescriptor<? extends IEntity> parseEntityDescriptor(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);
        EntityDescriptor<?> ed = lk.getEntityDescriptorEnum().valueOf(value.substring(index + 1));
        if (ed != null)
            return ed;
    }
    throw new WholeIllegalArgumentException(WholeMessages.no_data_type);
}
Also used : WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 25 with ILanguageKit

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

the class ActionsUIContentAssistVisitor method allLanguages.

protected boolean allLanguages(IEntity entity) {
    if (!Matcher.match(ActionsEntityDescriptorEnum.URI, entity))
        return false;
    ActionsEntityFactory aef = ActionsEntityFactory.instance;
    GroupAction languagesGroup = aef.createGroupAction();
    Actions actions = aef.createActions(0);
    String actualLanguageURI = DataTypeUtils.getAsPersistenceString(entity);
    IResourceRegistry<ILanguageKit> registry = ReflectionFactory.getLanguageKitRegistry();
    for (ILanguageKit languageKit : registry.getResources(false, ResourceUtils.SIMPLE_COMPARATOR)) {
        String uri = languageKit.getURI();
        if (uri.equals(actualLanguageURI))
            continue;
        URI prototype = aef.createURI(uri);
        actions.wAdd(createReplaceTemplateAction(prototype, ResourceUtils.SIMPLE_NAME_PROVIDER.toString(registry, languageKit), IActionConstants.SELECT_LANGUAGE_ICON));
    }
    languagesGroup.setActions(actions);
    return mergeResult(languagesGroup);
}
Also used : GroupAction(org.whole.lang.actions.model.GroupAction) Actions(org.whole.lang.actions.model.Actions) URI(org.whole.lang.actions.model.URI) ActionsEntityFactory(org.whole.lang.actions.factories.ActionsEntityFactory) 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