use of org.eclipse.n4js.scoping.utils.WrongStaticAccessDescription 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