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;
}
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;
}
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;
}
Aggregations