Search in sources :

Example 1 with SimpleTraitUsageNode

use of st.gravel.support.compiler.ast.SimpleTraitUsageNode in project gravel by gravel-st.

the class CompositeTraitUsageNode method flattenClassDescriptionNode_in_.

@Override
public ClassDescriptionNode flattenClassDescriptionNode_in_(final ClassDescriptionNode _aClassDescriptionNode, final SystemNode _aSystemNode) {
    final ClassDescriptionNode[] _n;
    final Map<String, MethodNode>[] _definitionInOtherTraits;
    final List<MethodNode>[] _requirements;
    _n = new ClassDescriptionNode[1];
    _definitionInOtherTraits = new Map[1];
    _requirements = new List[1];
    _n[0] = _aClassDescriptionNode;
    _definitionInOtherTraits[0] = new java.util.HashMap<String, MethodNode>();
    _requirements[0] = new java.util.ArrayList();
    for (final SimpleTraitUsageNode _component : _components) {
        _component.allMethodsIn_do_(_aSystemNode, new st.gravel.support.jvm.Block1<Object, MethodNode>() {

            @Override
            public Object value_(final MethodNode _method) {
                final boolean _canUnderstand;
                final String _selector;
                _selector = _method.selector();
                _canUnderstand = _aClassDescriptionNode.canUnderstand_in_(_selector, _aSystemNode);
                if (_method.isTraitRequirement()) {
                    if (!_canUnderstand) {
                        return _requirements[0].add(_method.ofTrait_(_component.reference()));
                    }
                } else {
                    if (!_aClassDescriptionNode.includesSelector_(_selector)) {
                        final MethodNode _other;
                        MethodNode _temp1 = _definitionInOtherTraits[0].get(_selector);
                        _other = ((MethodNode) _temp1);
                        if (_other != null) {
                            if (CompositeTraitUsageNode.this.conflicts_with_(_other, _method)) {
                                _n[0] = _n[0].copyReplaceMethodNode_(_method.withBody_(SequenceNode.factory.statement_(GlobalReadNode.factory.namespace_name_(AbsoluteReference.factory.object(), "TraitConflict").send_with_("raiseSignal:", StringLiteralNode.factory.value_(CompositeTraitUsageNode.this.traitConflictStringFor_in_(_selector, _aSystemNode))))));
                            }
                        } else {
                            _n[0] = _n[0].withMethodNode_ofTrait_(_method, _component.reference());
                        }
                    }
                    return _definitionInOtherTraits[0].put(_method.selector(), _method);
                }
                return CompositeTraitUsageNode.this;
            }
        });
    }
    for (final MethodNode _method : _requirements[0]) {
        if (!(_definitionInOtherTraits[0].containsKey(_method.selector()) || _n[0].includesSelector_(_method.selector()))) {
            _n[0] = _n[0].withMethodNode_(CompositeTraitUsageNode.this.newTraitRequirementNotDefinedFor_(_method));
        }
    }
    return _n[0];
}
Also used : ClassDescriptionNode(st.gravel.support.compiler.ast.ClassDescriptionNode) ArrayList(java.util.ArrayList) MethodNode(st.gravel.support.compiler.ast.MethodNode) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) SimpleTraitUsageNode(st.gravel.support.compiler.ast.SimpleTraitUsageNode)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ClassDescriptionNode (st.gravel.support.compiler.ast.ClassDescriptionNode)1 MethodNode (st.gravel.support.compiler.ast.MethodNode)1 SimpleTraitUsageNode (st.gravel.support.compiler.ast.SimpleTraitUsageNode)1