Search in sources :

Example 1 with NameAndAccess

use of org.eclipse.n4js.ts.types.NameAndAccess in project n4js by eclipse.

the class MemberByNameAndAccessMap method get.

@Override
public TMember get(Object key) {
    if (key instanceof NameAndAccess) {
        for (int i = 0, size = members.size(); i < size; i++) {
            final TMember result = members.get(i);
            final NameAndAccess nameAndAccess = (NameAndAccess) key;
            if (nameAndAccess.getName().equals(result.getName())) {
                if (nameAndAccess.isStaticAccess() == result.isStatic()) {
                    if ((nameAndAccess.isWriteAccess() && result.isWriteable()) || (!nameAndAccess.isWriteAccess() && result.isReadable())) {
                        return result;
                    }
                }
            }
        }
    }
    return null;
}
Also used : NameAndAccess(org.eclipse.n4js.ts.types.NameAndAccess) TMember(org.eclipse.n4js.ts.types.TMember)

Example 2 with NameAndAccess

use of org.eclipse.n4js.ts.types.NameAndAccess in project n4js by eclipse.

the class TypingStrategyFilter method apply.

@Override
public boolean apply(IEObjectDescription description) {
    if (typingStrategy == TypingStrategy.DEFAULT || typingStrategy == TypingStrategy.NOMINAL) {
        return true;
    }
    EObject proxyOrInstance = description.getEObjectOrProxy();
    if (proxyOrInstance == null || proxyOrInstance.eIsProxy()) {
        return true;
    }
    if (!(proxyOrInstance instanceof TMember)) {
        return true;
    }
    TMember member = (TMember) proxyOrInstance;
    if (member.isStatic() || member.getMemberAccessModifier() != MemberAccessModifier.PUBLIC) {
        return false;
    }
    if (member instanceof TMethod) {
        switch(typingStrategy) {
            case NOMINAL:
            case DEFAULT:
                return true;
            case STRUCTURAL_FIELDS:
            case STRUCTURAL_READ_ONLY_FIELDS:
            case STRUCTURAL_WRITE_ONLY_FIELDS:
            case STRUCTURAL_FIELD_INITIALIZER:
                return false;
            case STRUCTURAL:
                // including constructors
                return true;
        }
    }
    if (member instanceof TGetter) {
        switch(typingStrategy) {
            case NOMINAL:
            case DEFAULT:
            case STRUCTURAL:
            case STRUCTURAL_FIELDS:
            case STRUCTURAL_READ_ONLY_FIELDS:
                return true;
            case STRUCTURAL_WRITE_ONLY_FIELDS:
                return false;
            case STRUCTURAL_FIELD_INITIALIZER:
                ContainerType<?> type = member.getContainingType();
                NameAndAccess naa = new NameAndAccess(member.getName(), true, false);
                Map<NameAndAccess, ? extends TMember> members = type.getOwnedMembersByNameAndAccess();
                boolean hasSetter = members.containsKey(naa);
                return hasSetter;
        }
    }
    if (member instanceof TSetter) {
        switch(typingStrategy) {
            case NOMINAL:
            case DEFAULT:
            case STRUCTURAL:
            case STRUCTURAL_FIELDS:
            case STRUCTURAL_WRITE_ONLY_FIELDS:
                return true;
            case STRUCTURAL_READ_ONLY_FIELDS:
            case STRUCTURAL_FIELD_INITIALIZER:
                return false;
        }
    }
    if (member instanceof TField) {
        TField field = (TField) member;
        switch(typingStrategy) {
            case NOMINAL:
            case DEFAULT:
            case STRUCTURAL:
            case STRUCTURAL_FIELDS:
                return true;
            case STRUCTURAL_READ_ONLY_FIELDS:
                return !isWriteAccess;
            case STRUCTURAL_WRITE_ONLY_FIELDS:
                return isWriteAccess;
            case STRUCTURAL_FIELD_INITIALIZER:
                boolean isAccessable = !isWriteAccess && (!field.isFinal() || !field.isHasExpression());
                return isAccessable;
        }
    }
    return true;
}
Also used : TSetter(org.eclipse.n4js.ts.types.TSetter) NameAndAccess(org.eclipse.n4js.ts.types.NameAndAccess) TMethod(org.eclipse.n4js.ts.types.TMethod) TField(org.eclipse.n4js.ts.types.TField) TGetter(org.eclipse.n4js.ts.types.TGetter) EObject(org.eclipse.emf.ecore.EObject) TMember(org.eclipse.n4js.ts.types.TMember)

Example 3 with NameAndAccess

use of org.eclipse.n4js.ts.types.NameAndAccess in project n4js by eclipse.

the class ContainerTypeImpl method getOrCreateOwnedMembersByNameAndAccess.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public Map<NameAndAccess, ? extends TMember> getOrCreateOwnedMembersByNameAndAccess() {
    Map<NameAndAccess, ? extends TMember> _ownedMembersByNameAndAccess = this.getOwnedMembersByNameAndAccess();
    boolean _tripleEquals = (_ownedMembersByNameAndAccess == null);
    if (_tripleEquals) {
        Map<NameAndAccess, ? extends TMember> _switchResult = null;
        int _size = this.getOwnedMembers().size();
        switch(_size) {
            case 0:
                _switchResult = Collections.<NameAndAccess, TMember>emptyMap();
                break;
            case 1:
                Map<NameAndAccess, ? extends TMember> _xblockexpression = null;
                {
                    final MT singleMember = this.getOwnedMembers().get(0);
                    final NameAndAccess[] nameAndAccess = NameAndAccess.of(singleMember);
                    Map<NameAndAccess, ? extends TMember> _xifexpression = null;
                    int _length = nameAndAccess.length;
                    boolean _greaterThan = (_length > 1);
                    if (_greaterThan) {
                        Map<NameAndAccess, TMember> _xblockexpression_1 = null;
                        {
                            final HashMap<NameAndAccess, TMember> map = new HashMap<NameAndAccess, TMember>();
                            map.put(nameAndAccess[0], singleMember);
                            map.put(nameAndAccess[1], singleMember);
                            _xblockexpression_1 = Collections.<NameAndAccess, TMember>unmodifiableMap(map);
                        }
                        _xifexpression = _xblockexpression_1;
                    } else {
                        _xifexpression = Collections.<NameAndAccess, MT>singletonMap(nameAndAccess[0], singleMember);
                    }
                    _xblockexpression = _xifexpression;
                }
                _switchResult = _xblockexpression;
                break;
            default:
                EList<MT> _ownedMembers = this.getOwnedMembers();
                MemberByNameAndAccessMap _memberByNameAndAccessMap = new MemberByNameAndAccessMap(_ownedMembers);
                _switchResult = Collections.<NameAndAccess, TMember>unmodifiableMap(_memberByNameAndAccessMap);
                break;
        }
        final Map<NameAndAccess, ? extends TMember> newRegistry = _switchResult;
        final Procedure0 _function = new Procedure0() {

            public void apply() {
                ContainerTypeImpl.this.setOwnedMembersByNameAndAccess(newRegistry);
            }
        };
        EcoreUtilN4.doWithDeliver(false, _function, this);
    }
    return this.getOwnedMembersByNameAndAccess();
}
Also used : MemberByNameAndAccessMap(org.eclipse.n4js.ts.types.internal.MemberByNameAndAccessMap) NameAndAccess(org.eclipse.n4js.ts.types.NameAndAccess) Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) HashMap(java.util.HashMap) TMember(org.eclipse.n4js.ts.types.TMember) HashMap(java.util.HashMap) Map(java.util.Map) MemberByNameAndAccessMap(org.eclipse.n4js.ts.types.internal.MemberByNameAndAccessMap)

Aggregations

NameAndAccess (org.eclipse.n4js.ts.types.NameAndAccess)3 TMember (org.eclipse.n4js.ts.types.TMember)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 EObject (org.eclipse.emf.ecore.EObject)1 TField (org.eclipse.n4js.ts.types.TField)1 TGetter (org.eclipse.n4js.ts.types.TGetter)1 TMethod (org.eclipse.n4js.ts.types.TMethod)1 TSetter (org.eclipse.n4js.ts.types.TSetter)1 MemberByNameAndAccessMap (org.eclipse.n4js.ts.types.internal.MemberByNameAndAccessMap)1 Procedure0 (org.eclipse.xtext.xbase.lib.Procedures.Procedure0)1