use of org.eclipse.n4js.validation.IssueCodes.SYN_KW_EXTENDS_IMPLEMENTS_MIXED_UP 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);
}
}
}
Aggregations