Search in sources :

Example 16 with TField

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

the class N4JSResourceDescription method getCrossRefTypeAcceptor.

private IAcceptor<EObject> getCrossRefTypeAcceptor(final Set<EObject> crossRefTypesAddHere) {
    IAcceptor<EObject> acceptor = new IAcceptor<EObject>() {

        @Override
        public void accept(EObject to) {
            if (to instanceof Type || to instanceof TVariable || to instanceof TEnumLiteral) {
                crossRefTypesAddHere.add(to);
            }
            // Add declared type of a field to cross ref types
            if (to instanceof TFunction) {
                TypeRef returnTypeRef = ((TFunction) to).getReturnTypeRef();
                crossRefTypesAddHere.add(returnTypeRef.getDeclaredType());
            }
            if (to instanceof TField) {
                TypeRef typeRef = ((TField) to).getTypeRef();
                crossRefTypesAddHere.add(typeRef.getDeclaredType());
            }
            // In case of TMember, add the containing type as well
            if (to instanceof TMember) {
                TMember casted = (TMember) to;
                ContainerType<?> declaringType = casted.getContainingType();
                crossRefTypesAddHere.add(declaringType);
            }
        }
    };
    return acceptor;
}
Also used : ContainerType(org.eclipse.n4js.ts.types.ContainerType) Type(org.eclipse.n4js.ts.types.Type) TFunction(org.eclipse.n4js.ts.types.TFunction) TVariable(org.eclipse.n4js.ts.types.TVariable) TField(org.eclipse.n4js.ts.types.TField) TEnumLiteral(org.eclipse.n4js.ts.types.TEnumLiteral) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) EObject(org.eclipse.emf.ecore.EObject) IAcceptor(org.eclipse.xtext.util.IAcceptor) TMember(org.eclipse.n4js.ts.types.TMember)

Example 17 with TField

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

the class ComposedMemberInfo method handleReadOnlyField.

private void handleReadOnlyField(TMember member) {
    boolean isReadOnlyField = false;
    if (member instanceof TField) {
        TField tField = (TField) member;
        isReadOnlyField = !tField.isWriteable();
    }
    hasReadOnlyField |= isReadOnlyField;
    onlyReadOnlyFields &= isReadOnlyField;
}
Also used : TField(org.eclipse.n4js.ts.types.TField)

Example 18 with TField

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

the class AbstractMemberScope method getSingleLocalElementByName.

@Override
protected IEObjectDescription getSingleLocalElementByName(QualifiedName name) {
    if (name.getSegmentCount() != 1) {
        return null;
    }
    final String nameAsString = name.getFirstSegment();
    // both read/write required
    if (ExpressionExtensions.isBothReadFromAndWrittenTo(context)) {
        TMember reader = findMember(nameAsString, false, staticAccess);
        TMember writer = findMember(nameAsString, true, staticAccess);
        if (null == reader && null == writer) {
            // will be caught as error "Could not resolve reference"
            return null;
        }
        if (null == reader) {
            return new UnsatisfiedRWAccessDescription(EObjectDescription.create(writer.getName(), writer), true);
        }
        if (null == writer) {
            return new UnsatisfiedRWAccessDescription(EObjectDescription.create(reader.getName(), reader), false);
        }
        // pick arbitrarily the setter
        return createSingleElementDescription(writer);
    }
    // either read or write requirement that moreover is satisfied
    final boolean accessForWriteOperation = ExpressionExtensions.isLeftHandSide(context);
    TMember existingMember = findMember(nameAsString, accessForWriteOperation, staticAccess);
    if (existingMember != null) {
        return createSingleElementDescription(existingMember);
    }
    // wrong read/write
    existingMember = findMember(nameAsString, !accessForWriteOperation, staticAccess);
    if (existingMember != null) {
        // allowed special case: writing in the ctor to a final field that lacks init value
        final boolean isAssOfFinalInCtor = N4JSASTUtils.isSemiLegalAssignmentToFinalFieldInCtor(context.eContainer(), existingMember);
        final boolean isLegalAssOfFinalInCtor = isAssOfFinalInCtor && !((TField) existingMember).isHasExpression();
        if (isLegalAssOfFinalInCtor) {
            return createSingleElementDescription(existingMember);
        }
        // allowed special case: wrong read/write in a mode other than N4JS
        if (jsVariantHelper.allowWrongReadWrite(context)) {
            // cf. sec. 13.1
            return createSingleElementDescription(existingMember);
        }
        return new WrongWriteAccessDescription(EObjectDescription.create(existingMember.getName(), existingMember), accessForWriteOperation, isAssOfFinalInCtor);
    }
    // wrong static / non-static
    existingMember = findMember(nameAsString, accessForWriteOperation, !staticAccess);
    if (existingMember == null) {
        // if both read/write access and static access are wrong, we want to
        // complain (only) about "wrong static access" -> so include this case here
        existingMember = findMember(nameAsString, !accessForWriteOperation, !staticAccess);
    }
    if (existingMember != null) {
        return new WrongStaticAccessDescription(EObjectDescription.create(existingMember.getName(), existingMember), staticAccess);
    }
    return null;
}
Also used : WrongWriteAccessDescription(org.eclipse.n4js.scoping.utils.WrongWriteAccessDescription) TField(org.eclipse.n4js.ts.types.TField) TMember(org.eclipse.n4js.ts.types.TMember) WrongStaticAccessDescription(org.eclipse.n4js.scoping.utils.WrongStaticAccessDescription) UnsatisfiedRWAccessDescription(org.eclipse.n4js.scoping.utils.UnsatisfiedRWAccessDescription)

Aggregations

TField (org.eclipse.n4js.ts.types.TField)18 TMember (org.eclipse.n4js.ts.types.TMember)11 TSetter (org.eclipse.n4js.ts.types.TSetter)10 TGetter (org.eclipse.n4js.ts.types.TGetter)9 ArrayList (java.util.ArrayList)7 EObject (org.eclipse.emf.ecore.EObject)7 TInterface (org.eclipse.n4js.ts.types.TInterface)7 AccessorTuple (org.eclipse.n4js.ts.types.util.AccessorTuple)7 TClass (org.eclipse.n4js.ts.types.TClass)6 TClassifier (org.eclipse.n4js.ts.types.TClassifier)6 TMethod (org.eclipse.n4js.ts.types.TMethod)6 Type (org.eclipse.n4js.ts.types.Type)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 Script (org.eclipse.n4js.n4JS.Script)5 MemberList (org.eclipse.n4js.ts.types.util.MemberList)5 MemberCollector (org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector)5 Collections.emptyList (java.util.Collections.emptyList)4