use of org.eclipse.n4js.ts.types.TInterface in project n4js by eclipse.
the class N4JSSyntaxValidator method checkInterfaceDeclaration.
/**
* Checks that no "with" or "role" 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.
* <p>
* "role" will be removed in grammar.
*/
@Check
public void checkInterfaceDeclaration(N4InterfaceDeclaration n4InterfaceDecl) {
ICompositeNode node = NodeModelUtils.findActualNodeFor(n4InterfaceDecl);
ILeafNode keywordNode;
keywordNode = findLeafWithKeyword(n4InterfaceDecl, "{", node, IMPLEMENTS_KEYWORD, false);
if (keywordNode != null) {
TInterface tinterface = n4InterfaceDecl.getDefinedTypeAsInterface();
if (tinterface == null) {
// avoid consequential errors
return;
}
if (tinterface.getSuperInterfaceRefs().isEmpty()) {
// ok
return;
}
if (tinterface.getSuperInterfaceRefs().stream().allMatch(superTypeRef -> superTypeRef.getDeclaredType() instanceof TInterface)) {
List<? extends IdentifiableElement> interfaces = tinterface.getSuperInterfaceRefs().stream().flatMap((ParameterizedTypeRef ref) -> {
Type declaredType = ref.getDeclaredType();
if (declaredType instanceof TInterface) {
return Stream.of((TInterface) declaredType);
}
return Stream.empty();
}).collect(Collectors.toList());
String message = getMessageForSYN_KW_EXTENDS_IMPLEMENTS_MIXED_UP(validatorMessageHelper.description(tinterface), "implement", "interface" + (interfaces.size() > 1 ? "s " : " ") + validatorMessageHelper.names(interfaces), EXTENDS_KEYWORD);
addIssue(message, n4InterfaceDecl, keywordNode.getTotalOffset(), keywordNode.getLength(), SYN_KW_EXTENDS_IMPLEMENTS_MIXED_UP);
}
}
}
Aggregations