Search in sources :

Example 26 with FeatureDescriptor

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

the class GenericTemplateInterpreterVisitor method visit.

public void visit(IEntity entity) {
    IEntity adaptee = entity.wGetAdaptee(false);
    EntityDescriptor<?> ed = adaptee.wGetEntityDescriptor();
    // TODO workaround move into a separate visitor
    if (ed.getLanguageKit().getURI().equals(CommonsLanguageKit.URI)) {
        switch(ed.getOrdinal()) {
            case CommonsEntityDescriptorEnum.Resolver_ord:
                break;
            case CommonsEntityDescriptorEnum.SameStageFragment_ord:
                stagedVisit(adaptee.wGetRoot());
                if (getStage() > 0)
                    setResult(GenericEntityFactory.instance.create(CommonsEntityDescriptorEnum.SameStageFragment, // CommonsEntityFactory.instance.createSameStageFragment(
                    EntityUtils.cloneIfParented(getResult())));
                return;
            case CommonsEntityDescriptorEnum.RootFragment_ord:
            case CommonsEntityDescriptorEnum.StageDownFragment_ord:
                setResult(null);
                IEntity oldSelfEntity = getBindings().wGet("self");
                final int stageShift0 = -1;
                stagedVisit(adaptee.wGetRoot(), stageShift0);
                if (getBindings().wGet("self") != oldSelfEntity)
                    getBindings().wDef("self", oldSelfEntity);
                if (getStage() + stageShift0 > 0 && !isResultIterator())
                    setResult(GenericEntityFactory.instance.create(CommonsEntityDescriptorEnum.StageDownFragment, // CommonsEntityFactory.instance.createStageDownFragment(
                    EntityUtils.cloneIfParented(getResult())));
                return;
            case CommonsEntityDescriptorEnum.StageUpFragment_ord:
                final int stageShift = +1;
                stagedVisit(adaptee.wGetRoot(), stageShift);
                if (getStage() > 0) {
                    setResult(GenericEntityFactory.instance.create(CommonsEntityDescriptorEnum.StageUpFragment, // CommonsEntityFactory.instance.createStageUpFragment(
                    EntityUtils.cloneIfParented(BehaviorUtils.evaluateResult(getBindings()))));
                }
                return;
            case CommonsEntityDescriptorEnum.Variable_ord:
            case CommonsEntityDescriptorEnum.InlineVariable_ord:
                Variable variable = (Variable) adaptee;
                String varName = variable.getVarName().getValue();
                IEntity value = getBindings().wGet(varName);
                if (value != null) {
                    if (BindingManagerFactory.instance.isVoid(value))
                        setResult(value);
                    else {
                        QuantifierEnum.Value quantifierValue = variable.getQuantifier().getValue();
                        if (quantifierValue.isComposite()) {
                            Variable newVariable = EntityUtils.clone(variable);
                            newVariable.getQuantifier().setValue(quantifierValue.toOptional());
                            if (EntityUtils.isInlineVariable(variable)) {
                                // TODO constantChildIterator should call EntityUtils.convert(childValue, varType)
                                setResultIterator(IteratorFactory.sequenceIterator(IteratorFactory.constantChildIterator(value), IteratorFactory.constantIterator(newVariable, true)));
                            } else {
                                EntityDescriptor<?> varType = variable.getVarType().getValue();
                                try {
                                    setResultIterator(IteratorFactory.sequenceIterator(IteratorFactory.constantIterator(EntityUtils.convertCloneIfParented(value, varType), true), IteratorFactory.constantIterator(newVariable, true)));
                                } catch (IllegalArgumentException e) {
                                    throw new SubstituteException(variable, value.wGetEntityDescriptor());
                                }
                            }
                        } else {
                            if (EntityUtils.isInlineVariable(variable)) {
                                // TODO constantChildIterator should call EntityUtils.convert(childValue, varType)
                                setResultIterator(IteratorFactory.constantChildIterator(value));
                            } else {
                                EntityDescriptor<?> varType = variable.getVarType().getValue();
                                try {
                                    setResult(EntityUtils.convertCloneIfParented(value, varType));
                                } catch (IllegalArgumentException e) {
                                    throw new SubstituteException(variable, value.wGetEntityDescriptor());
                                }
                            }
                        }
                    }
                    return;
                }
        }
    }
    IEntity result = ((InternalIEntity) adaptee).wShallowClone();
    IEntity oldSelfEntity2 = getBindings().wGet("self");
    for (int i = 0; i < result.wSize(); i++) {
        int resultSize = result.wSize();
        visit(result.wGet(i));
        int nextResultSize = result.wSize();
        i += (nextResultSize - resultSize);
        if (isResultIterator()) {
            IEntityIterator<?> iterator = getResultIterator();
            setResultIterator(null);
            IEntity selfEntity = getBindings().wGet("self");
            if (selfEntity != oldSelfEntity2)
                getBindings().wDef("self", selfEntity = oldSelfEntity2);
            iterator.reset(selfEntity);
            FeatureDescriptor resultChildDescriptor = result.wGetFeatureDescriptor(i);
            if (EntityUtils.isComposite(result)) {
                result.wRemove(i--);
                if (iterator.hasNext()) {
                    ITransactionScope resettableScope = BindingManagerFactory.instance.createTransactionScope();
                    getBindings().wEnterScope(resettableScope);
                    resultSize = result.wSize();
                    for (IEntity e : iterator) {
                        nextResultSize = result.wSize();
                        i += (nextResultSize - resultSize);
                        if (BindingManagerFactory.instance.isVoid(e))
                            resultSize = nextResultSize;
                        else {
                            result.wAdd(++i, EntityUtils.convertCloneIfReparenting(e, resultChildDescriptor));
                            resultSize = result.wSize();
                        }
                        resettableScope.commit();
                    }
                    resettableScope.rollback();
                    getBindings().wExitScope();
                }
            } else {
                IEntity e = null;
                if (iterator.hasNext()) {
                    ITransactionScope resettableScope = BindingManagerFactory.instance.createTransactionScope();
                    getBindings().wEnterScope(resettableScope);
                    for (IEntity r : iterator) {
                        if (!BindingManagerFactory.instance.isVoid(r))
                            e = r;
                        resettableScope.commit();
                    }
                    resettableScope.rollback();
                    getBindings().wExitScope();
                }
                if (e != null)
                    result.wSet(i, EntityUtils.convertCloneIfReparenting(e, resultChildDescriptor));
                else
                    result.wRemove(i);
            }
        } else {
            IEntity child = getResult();
            if (child != null && !BindingManagerFactory.instance.isVoid(child)) {
                FeatureDescriptor resultChildDescriptor = result.wGetAdaptee(false).wGetFeatureDescriptor(i);
                result.wSet(i, EntityUtils.convertCloneIfReparenting(child, resultChildDescriptor));
            } else
                result.wRemove(i);
        }
        IEntity selfEntity = getBindings().wGet("self");
        if (selfEntity != oldSelfEntity2)
            getBindings().wDef("self", selfEntity = oldSelfEntity2);
    }
    setResult(result);
}
Also used : Variable(org.whole.lang.commons.model.Variable) ITransactionScope(org.whole.lang.bindings.ITransactionScope) IEntity(org.whole.lang.model.IEntity) InternalIEntity(org.whole.lang.model.InternalIEntity) SubstituteException(org.whole.lang.matchers.SubstituteException) QuantifierEnum(org.whole.lang.commons.model.QuantifierEnum) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) InternalIEntity(org.whole.lang.model.InternalIEntity)

Example 27 with FeatureDescriptor

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

the class GenericCloneVisitor method updateAdjacencyGraph.

public void updateAdjacencyGraph() {
    for (Map.Entry<IEntity, IEntity> entry : entityCloneMap.entrySet()) {
        IEntity entity = entry.getKey();
        IEntity entityClone = entry.getValue();
        for (int i = entity.wSize(), size = i + entity.wAdjacentSize(); i < size; i++) {
            IEntity adjacentEntity = entity.wGet(i);
            IEntity adjacentClone = entityCloneMap.get(adjacentEntity);
            if (adjacentClone != null)
                entityClone.wSet(i, adjacentClone);
            else
                // TODO enforce shallow copy removal semantics
                entityClone.wRemove(i);
        }
        for (FeatureDescriptor fd : entity.wGetAspectualFeatureDescriptors()) if (fd.isReference()) {
            IEntity adjacentEntity = entity.wGet(fd);
            IEntity adjacentClone = entityCloneMap.get(adjacentEntity);
            if (adjacentClone != null)
                entityClone.wSet(fd, adjacentClone);
            else
                // TODO enforce shallow copy removal semantics
                entityClone.wRemove(fd);
        }
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) InternalIEntity(org.whole.lang.model.InternalIEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) Map(java.util.Map) HashMap(java.util.HashMap)

Example 28 with FeatureDescriptor

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

the class QueriesContentAssistVisitor method visit.

@Override
public void visit(Name entity) {
    IEntity bindEntity = entity.wGetParent();
    if (!Matcher.match(Bind, bindEntity))
        return;
    IEntity bindingsEntity = bindEntity.wGetParent();
    if (!Matcher.match(Bindings, bindingsEntity))
        return;
    EntityType entityType;
    boolean allLanguageFeatures;
    IEntity entityCallOrTemplateEntity = bindingsEntity.wGetParent();
    switch(entityCallOrTemplateEntity.wGetEntityDescriptor().getOrdinal()) {
        case EntityCall_ord:
            entityType = ((EntityCall) entityCallOrTemplateEntity).getName();
            allLanguageFeatures = true;
            break;
        case EntityTemplate_ord:
            entityType = ((EntityTemplate) entityCallOrTemplateEntity).getName();
            allLanguageFeatures = false;
            break;
        default:
            return;
    }
    if (!DataTypeUtils.getDataKind(entityType).isString())
        return;
    String edUri = entityType.wStringValue();
    TreeSet<String> sortedNames = new TreeSet<String>();
    EntityDescriptor<?> ed = CommonsDataTypePersistenceParser.getEntityDescriptor(edUri, false, null);
    if (allLanguageFeatures || ed == null) {
        ILanguageKit lk = CommonsDataTypePersistenceParser.getLanguageKitPart(edUri);
        if (lk == null)
            return;
        Set<String> fNames = lk.getFeatureDescriptorEnum().names();
        sortedNames.addAll(fNames);
    } else
        for (FeatureDescriptor fd : ed.getEntityFeatureDescriptors()) sortedNames.add(fd.getName());
    allFeatureNames(sortedNames, entity.getValue());
}
Also used : EntityType(org.whole.lang.queries.model.EntityType) EntityType(org.whole.lang.queries.reflect.QueriesEntityDescriptorEnum.EntityType) IEntity(org.whole.lang.model.IEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) TreeSet(java.util.TreeSet) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 29 with FeatureDescriptor

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

the class QueriesContentAssistVisitor method allFeatureTypes.

private boolean allFeatureTypes(IEntity entity, EntityDescriptor<?> targetEd) {
    if (!EntityUtils.hasParent(entity) || !entity.wGetParent().wGetEntityDescriptor(entity).isPlatformSupertypeOf(targetEd))
        return false;
    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 actualFeatureName = "";
    FeatureDescriptor actualFD = null;
    try {
        actualFD = CommonsDataTypePersistenceParser.parseFeatureDescriptor(entity.wStringValue());
        actualLanguageURI = actualFD.getLanguageKit().getURI();
        actualFeatureName = actualFD.getName();
    } catch (Exception e) {
        if (DataTypeUtils.getDataKind(entity).isString())
            actualFeatureName = entity.wStringValue();
    }
    IResourceRegistry<ILanguageKit> registry = ReflectionFactory.getLanguageKitRegistry();
    for (ILanguageKit languageKit : registry.getResources(false, ResourceUtils.SIMPLE_COMPARATOR)) {
        if (languageKit.getURI().equals(actualLanguageURI))
            continue;
        FeatureDescriptorEnum fdEnum = languageKit.getFeatureDescriptorEnum();
        if (fdEnum.values().isEmpty())
            continue;
        FeatureDescriptor fd = null;
        if (actualFeatureName.length() > 0)
            fd = fdEnum.valueOf(actualFeatureName);
        if (fd == null)
            fd = fdEnum.valueOf(0);
        IEntity prototype = qef.create(targetEd, CommonsDataTypePersistenceParser.unparseFeatureDescriptor(fd));
        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 (actualFD != null) {
        GroupAction featurenamesGroup = aef.createGroupAction();
        featurenamesGroup.setFillStrategy(aef.createHierarchical(aef.createDistinctPrefix(), aef.createSize(10)));
        featurenamesGroup.getText().setValue("queries.featurenames");
        actions = aef.createActions(0);
        FeatureDescriptorEnum fdEnum = actualFD.getFeatureDescriptorEnum();
        List<FeatureDescriptor> fds = new ArrayList<FeatureDescriptor>(fdEnum.values());
        Collections.sort(fds, EnumValueImpl.getByNameComparator());
        for (FeatureDescriptor fd : fds) {
            if (fd.equals(actualFD))
                continue;
            IEntity prototype = qef.create(targetEd, CommonsDataTypePersistenceParser.unparseFeatureDescriptor(fd));
            actions.wAdd(aef.createReplaceDifferentTemplateAction(prototype, fd.getName()));
        }
        featurenamesGroup.setActions(actions);
        addedLanguages |= EntityUtils.isResolver(entity) ? mergeResult(targetEd, languagesGroup) : mergeResult(featurenamesGroup);
    }
    return addedLanguages;
}
Also used : FeatureDescriptorEnum(org.whole.lang.reflect.FeatureDescriptorEnum) Actions(org.whole.lang.actions.model.Actions) IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) ArrayList(java.util.ArrayList) ILanguageKit(org.whole.lang.reflect.ILanguageKit) GroupAction(org.whole.lang.actions.model.GroupAction) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) ActionsUIEntityFactory(org.whole.lang.actions.ui.factories.ActionsUIEntityFactory)

Example 30 with FeatureDescriptor

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

the class FlowchartDefaultEntityRegistryConfiguration method apply.

public void apply(IEntityRegistry er) {
    super.apply(er);
    FlowchartEntityFactory ef = FlowchartEntityFactory.instance(er);
    er.put(ef.create(FlowchartEntityDescriptorEnum.Entry, ef.createPixels(0), ef.createPixels(0), ef.createPixels(16), ef.createPixels(16), ef.createText("entry")));
    er.put(ef.create(FlowchartEntityDescriptorEnum.Exit, ef.createPixels(0), ef.createPixels(0), ef.createPixels(16), ef.createPixels(16), ef.createText("exit")));
    er.put(ef.create(FlowchartEntityDescriptorEnum.Block, ef.createPixels(0), ef.createPixels(0), ef.createPixels(50), ef.createPixels(40), ef.createText("block")));
    er.put(ef.create(FlowchartEntityDescriptorEnum.Choice, ef.createPixels(0), ef.createPixels(0), ef.createPixels(40), ef.createPixels(30), ef.createText("choice")));
    Transitions joinTransitions = ef.createTransitions(0);
    er.put(ef.create(FlowchartEntityDescriptorEnum.Join, ef.createPixels(0), ef.createPixels(0), ef.createPixels(50), ef.createPixels(16), ef.createText("join"), joinTransitions));
    Flowchart flowchart = ef.create(FlowchartEntityDescriptorEnum.Flowchart, ef.createNodes(0), ef.createTransitions(0));
    er.put(flowchart);
    flowchart.wAddChangeEventHandler(new IdentityChangeEventHandler() {

        private static final long serialVersionUID = 1L;

        public void notifyChanged(IEntity source, FeatureDescriptor fd, IEntity oldValue, IEntity newValue) {
            if (FlowchartFeatureDescriptorEnum.transitions.equals(fd)) {
                newValue.wAddChangeEventHandler(new IdentityChangeEventHandler() {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void notifyRemoved(IEntity source, FeatureDescriptor featureDesc, int index, IEntity oldValue) {
                        super.notifyRemoved(source, featureDesc, index, oldValue);
                        if (Matcher.match(FlowchartEntityDescriptorEnum.Flowchart, source.wGetParent()) && EntityUtils.isNotResolver(oldValue)) {
                            removeCrossReferences(oldValue, FlowchartFeatureDescriptorEnum.target);
                            removeCrossReferences(oldValue, FlowchartFeatureDescriptorEnum.source);
                        }
                    }

                    private void removeCrossReferences(IEntity transition, FeatureDescriptor fd) {
                        IEntity referrer = transition.wGet(fd);
                        for (int i = referrer.wSize(), size = i + referrer.wAdjacentSize(); i < size; i++) {
                            IEntity adjacent = referrer.wGet(i);
                            if (EntityUtils.isComposite(adjacent) && adjacent.wContains(transition))
                                referrer.wGet(i).wRemove(transition);
                            else if (// referece modifier check not needed
                            adjacent == transition)
                                referrer.wSet(i, CommonsEntityAdapterFactory.createResolver(adjacent.wGetEntityDescriptor()));
                        }
                    }
                });
            }
        }
    });
    // FIXME workaround for misbehaving event handling on composite entities with relationship modifier.
    // AbstractEntity.notifyAdded() should have notified the composite owner's event handler (Join),
    // consequently we redirect any change event of the composite to the owner entity.
    joinTransitions.wAddChangeEventHandler(new IdentityChangeEventHandler() {

        private static final long serialVersionUID = 1L;

        @Override
        public void notifyAdded(IEntity source, FeatureDescriptor featureDesc, int index, IEntity newValue) {
            IEntity targetJoin = newValue.wGet(FlowchartFeatureDescriptorEnum.target);
            IChangeEventHandler changeEventHandler = targetJoin.wGetModel().getCompoundModel().getChangeEventHandler();
            changeEventHandler.notifyChanged(targetJoin, FlowchartFeatureDescriptorEnum.targetTransitions, source, source);
        }

        @Override
        public void notifyRemoved(IEntity source, FeatureDescriptor featureDesc, int index, IEntity newValue) {
            IEntity targetJoin = newValue.wGet(FlowchartFeatureDescriptorEnum.target);
            IChangeEventHandler changeEventHandler = targetJoin.wGetModel().getCompoundModel().getChangeEventHandler();
            changeEventHandler.notifyChanged(targetJoin, FlowchartFeatureDescriptorEnum.targetTransitions, source, source);
        }
    });
}
Also used : IChangeEventHandler(org.whole.lang.events.IChangeEventHandler) IdentityChangeEventHandler(org.whole.lang.events.IdentityChangeEventHandler) Transitions(org.whole.lang.flowchart.model.Transitions) IEntity(org.whole.lang.model.IEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) Flowchart(org.whole.lang.flowchart.model.Flowchart)

Aggregations

FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)100 IEntity (org.whole.lang.model.IEntity)43 InternalIEntity (org.whole.lang.model.InternalIEntity)6 ILanguageKit (org.whole.lang.reflect.ILanguageKit)6 HashSet (java.util.HashSet)5 IContributionItem (org.eclipse.jface.action.IContributionItem)5 ActionsVisibleWhen (org.whole.lang.e4.ui.expressions.ActionsVisibleWhen)5 VisibilityExpression (org.whole.lang.e4.ui.expressions.VisibilityExpression)5 ActionsCompositeContributionItem (org.whole.lang.e4.ui.menu.ActionsCompositeContributionItem)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 HashMap (java.util.HashMap)3 IBindingManager (org.whole.lang.bindings.IBindingManager)3 ITransactionScope (org.whole.lang.bindings.ITransactionScope)3 IdentityRequestEventHandler (org.whole.lang.events.IdentityRequestEventHandler)3 IMappingStrategy (org.whole.lang.xsd.codebase.IMappingStrategy)3 IEntityFactory (org.whole.lang.factories.IEntityFactory)2 ArrayType (org.whole.lang.pojo.model.ArrayType)2 CollectionType (org.whole.lang.pojo.model.CollectionType)2 MapType (org.whole.lang.pojo.model.MapType)2