Search in sources :

Example 1 with EntityKinds

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

the class ModelLabelProvider method getText.

public String getText(Object element) {
    if (element instanceof IEntity) {
        IEntity entity = (IEntity) element;
        StringBuilder sb = new StringBuilder(entity.wGetEntityDescriptor().getName());
        EntityKinds kind = entity.wGetEntityKind();
        if (kind.isComposite()) {
            sb.append('[');
            sb.append(entity.wSize());
            sb.append(']');
        } else if (kind.isData()) {
            sb.append(": ");
            sb.append(entity.wGetValue());
        }
        return sb.toString();
    } else
        return super.getText(element);
}
Also used : IEntity(org.whole.lang.model.IEntity) EntityKinds(org.whole.lang.reflect.EntityKinds)

Example 2 with EntityKinds

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

the class DefaultCopyTransformer method transform.

public void transform(IEntity oldEntity, IEntity newEntity) {
    // if (newEntity.wGetEntityDescriptor().equals(oldEntity.wGetEntityDescriptor()))
    // return;
    EntityKinds oldKind = oldEntity.wGetEntityKind();
    EntityKinds newKind = newEntity.wGetEntityKind();
    if ((oldKind.isSimple() && newKind.isSimple()) || (EntityUtils.isVariable(oldEntity) && EntityUtils.isVariable(newEntity))) {
        // TODO workaround
        List<FeatureDescriptor> oldFeatures = oldEntity.wGetEntityDescriptor().getEntityFeatureDescriptors();
        Set<FeatureDescriptor> commonFeatures = new HashSet<FeatureDescriptor>();
        for (FeatureDescriptor fd : newEntity.wGetEntityDescriptor().getEntityFeatureDescriptors()) if (oldFeatures.contains(fd.getFeatureDescriptor()))
            commonFeatures.add(fd);
        for (FeatureDescriptor fd : commonFeatures) {
            IEntity oldChild = oldEntity.wGet(fd.getFeatureDescriptor());
            if (fd.getEntityDescriptor().isPlatformSupertypeOf(oldChild.wGetEntityDescriptor()))
                newEntity.wSet(fd, EntityUtils.clone(oldChild));
        }
    } else if (oldKind.isComposite() && newKind.isComposite()) {
        EntityDescriptor<?> newComponentDescriptor = newEntity.wGetEntityDescriptor(0);
        for (int i = 0, size = oldEntity.wSize(); i < size; i++) {
            IEntity oldChild = oldEntity.wGet(i);
            if (newComponentDescriptor.isPlatformSupertypeOf(oldChild.wGetEntityDescriptor()))
                newEntity.wSet(i, EntityUtils.clone(oldChild));
        }
    } else if (EntityUtils.isFragment(oldEntity) && EntityUtils.isFragment(newEntity)) {
        // TODO workaround
        newEntity.wSet(0, EntityUtils.clone(oldEntity.wGet(0)));
    }
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) IEntity(org.whole.lang.model.IEntity) EntityKinds(org.whole.lang.reflect.EntityKinds) HashSet(java.util.HashSet)

Example 3 with EntityKinds

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

the class DefaultWrapWithinTransformer method transform.

public void transform(IEntity oldEntity, IEntity newEntity) {
    EntityKinds newKind = newEntity.wGetEntityKind();
    if (newKind.isData())
        return;
    IEntity containerEntity;
    if (featureDescriptor != null)
        containerEntity = newEntity.wGet(featureDescriptor);
    else
        containerEntity = newEntity;
    if (!EntityUtils.isComposite(containerEntity))
        return;
    if (containerEntity.wGetEntityDescriptor(0).isPlatformSupertypeOf(oldEntity.wGetEntityDescriptor())) {
        IEntity clone = EntityUtils.clone(oldEntity);
        containerEntity.wSet(0, clone);
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) EntityKinds(org.whole.lang.reflect.EntityKinds)

Example 4 with EntityKinds

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

the class TestsInterpreterVisitor method visit.

@Override
public void visit(HasKind entity) {
    EntityKinds kind = EntityKinds.valueOf(entity.getKind().getValue().getName());
    setResultVisitor(GenericMatcherFactory.instance.hasKindMatcher(kind).withSourceEntity(entity));
}
Also used : EntityKinds(org.whole.lang.reflect.EntityKinds)

Example 5 with EntityKinds

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

the class QueriesDynamicCompilerVisitor method visit.

@Override
public void visit(KindTest entity) {
    Value kind = entity.getValue();
    switch(kind.getOrdinal()) {
        case KindTestEnum.IMPL_ord:
            setResultIterator(IteratorFactory.isImplIterator().withSourceEntity(entity));
            break;
        case KindTestEnum.FRAGMENT_ord:
            setResultIterator(IteratorFactory.isFragmentIterator().withSourceEntity(entity));
            break;
        case KindTestEnum.VARIABLE_ord:
            setResultIterator(IteratorFactory.isVariableIterator().withSourceEntity(entity));
            break;
        case KindTestEnum.RESOLVER_ord:
            setResultIterator(IteratorFactory.isResolverIterator().withSourceEntity(entity));
            break;
        default:
            EntityKinds ekind = EntityKinds.valueOf(kind.getName());
            setResultIterator(IteratorFactory.hasKindIterator(ekind).withSourceEntity(entity));
    }
}
Also used : Value(org.whole.lang.queries.model.KindTestEnum.Value) EntityKinds(org.whole.lang.reflect.EntityKinds)

Aggregations

EntityKinds (org.whole.lang.reflect.EntityKinds)9 IEntity (org.whole.lang.model.IEntity)4 HashSet (java.util.HashSet)1 Value (org.whole.lang.queries.model.KindTestEnum.Value)1 EntityDescriptor (org.whole.lang.reflect.EntityDescriptor)1 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)1 HasKind (org.whole.lang.tests.model.HasKind)1 Kind (org.whole.lang.tests.model.Kind)1 Value (org.whole.lang.tests.model.KindEnum.Value)1 EntityStyling (org.whole.lang.ui.notations.styledtree.styling.EntityStyling)1 LayoutStyle (org.whole.lang.ui.notations.styledtree.styling.EntityStyling.LayoutStyle)1 IEntityStyling (org.whole.lang.ui.notations.styledtree.styling.IEntityStyling)1