use of org.eclipse.n4js.n4JS.N4ClassDefinition in project n4js by eclipse.
the class N4JSMemberRedefinitionValidator method checkUnpairedAccessorFilling.
private void checkUnpairedAccessorFilling(MemberMatrix mm, N4ClassifierDefinition definition) {
if (definition.getDefinedType().isStaticPolyfill() && mm.hasMixedAccessorPair()) {
FieldAccessor ownedAccessor = (FieldAccessor) Iterables.getFirst(mm.owned(), null);
if (null == ownedAccessor) {
// Should not happen, a mixed accessor pair implies at least one owned member
return;
}
if (!(definition instanceof N4ClassDefinition)) {
// Non-class static polyfills aren't allowed. Validated somewhere else.
return;
}
TClass filledClass = MemberRedefinitionUtils.getFilledClass((N4ClassDefinition) definition);
if (null == filledClass) {
// Invalid static polyfill class. Validated somewhere else.
return;
}
// Iterate over all inherited members
SourceAwareIterator memberIterator = mm.actuallyInheritedAndMixedMembers();
while (memberIterator.hasNext()) {
TMember next = memberIterator.next();
ContainerType<?> containingType = next.getContainingType();
// Issue an error if the member isn't owned by the filled class
if (containingType != filledClass) {
messageMissingOwnedAccessor(ownedAccessor);
}
}
}
}
use of org.eclipse.n4js.n4JS.N4ClassDefinition in project n4js by eclipse.
the class N4JSSyntaxValidator method checkClassDefinition.
/**
* Checks that no "with" is used and that list of implemented interfaces is separated with commas and not with
* keywords. These checks (with some warnings created instead of errors) should help the transition from roles to
* interfaces. However, they may be useful later on as well, e.g., if an interface is manually refactored into a
* class or vice versa.
* <p>
* Note that "with" is used in Dart for roles, so maybe it is useful to have a user-friendly message instead of a
* parser error.
*/
@Check
public void checkClassDefinition(N4ClassDefinition n4ClassDefinition) {
holdsCorrectOrderOfExtendsImplements(n4ClassDefinition);
ICompositeNode node = NodeModelUtils.findActualNodeFor(n4ClassDefinition);
ILeafNode keywordNode = findSecondLeafWithKeyword(n4ClassDefinition, "{", node, EXTENDS_KEYWORD, false);
if (keywordNode != null) {
TClass tclass = n4ClassDefinition.getDefinedTypeAsClass();
if (tclass == null) {
// avoid consequential errors
return;
}
if (StreamSupport.stream(tclass.getImplementedInterfaceRefs().spliterator(), false).allMatch(superTypeRef -> superTypeRef.getDeclaredType() instanceof TInterface)) {
List<? extends IdentifiableElement> interfaces = StreamSupport.stream(tclass.getImplementedInterfaceRefs().spliterator(), false).map(ref -> (TInterface) (ref.getDeclaredType())).collect(Collectors.toList());
String message = getMessageForSYN_KW_EXTENDS_IMPLEMENTS_MIXED_UP(validatorMessageHelper.description(tclass), "extend", "interface" + (interfaces.size() > 1 ? "s " : " ") + validatorMessageHelper.names(interfaces), IMPLEMENTS_KEYWORD);
addIssue(message, n4ClassDefinition, keywordNode.getTotalOffset(), keywordNode.getLength(), SYN_KW_EXTENDS_IMPLEMENTS_MIXED_UP);
}
}
}
use of org.eclipse.n4js.n4JS.N4ClassDefinition in project n4js by eclipse.
the class FGUtils method isCFContainer.
/**
* @return true iff the given {@link ControlFlowElement} is a container such as a function's body.
*/
public static boolean isCFContainer(EObject cfe) {
boolean isScript = cfe instanceof Script;
boolean isBlock = cfe instanceof Block;
boolean isExpression = cfe instanceof Expression;
boolean isBindingPattern = cfe instanceof BindingPattern;
if (!isScript && !isBlock && !isExpression && !isBindingPattern) {
return false;
}
EObject cfeContainer = cfe.eContainer();
EObject cfeContainer2 = (cfeContainer == null) ? null : cfeContainer.eContainer();
boolean containerIsFunctionDeclaration = cfeContainer instanceof FunctionDeclaration;
boolean containerIsFunctionDefinition = cfeContainer instanceof FunctionDefinition;
boolean containerIsFieldAccessor = cfeContainer instanceof FieldAccessor;
boolean containerIsFormalParameter = cfeContainer instanceof FormalParameter;
boolean containerIsFieldDeclaration = cfeContainer instanceof N4FieldDeclaration;
boolean containerIsAnnotationArgument = cfeContainer instanceof AnnotationArgument;
boolean containerIsLiteralOrComputedPropertyName = cfeContainer instanceof LiteralOrComputedPropertyName;
boolean containerIsExportSpecifier = cfeContainer instanceof ExportSpecifier;
boolean containerIsExportDeclaration = cfeContainer instanceof ExportDeclaration;
boolean containerIsN4ClassDefinition = cfeContainer instanceof N4ClassDefinition;
boolean container2IsN4FieldDeclaration = cfeContainer2 instanceof N4FieldDeclaration;
boolean isCFContainer = false;
isCFContainer |= isScript;
isCFContainer |= isBlock && containerIsFunctionDeclaration;
isCFContainer |= isBlock && containerIsFunctionDefinition;
isCFContainer |= isBlock && containerIsFieldAccessor;
isCFContainer |= isBindingPattern && containerIsFormalParameter;
isCFContainer |= isExpression && containerIsFormalParameter;
isCFContainer |= isExpression && containerIsFieldDeclaration;
isCFContainer |= isExpression && containerIsAnnotationArgument;
isCFContainer |= isExpression && containerIsLiteralOrComputedPropertyName && container2IsN4FieldDeclaration;
isCFContainer |= isExpression && containerIsN4ClassDefinition;
isCFContainer |= isExpression && containerIsExportSpecifier;
isCFContainer |= isExpression && containerIsExportDeclaration;
return isCFContainer;
}
Aggregations