@Override protected boolean specificValidate(SymbolResolver resolver, ErrorCollector errorCollector) { if (baseType.isPresent()) { if (!baseType.get().isReferenceTypeUsage() || !baseType.get().asReferenceTypeUsage().isClass(resolver)) { errorCollector.recordSemanticError( baseType.get().getPosition(), "Only classes can be extended"); return false; } } for (TypeUsageNode typeUsage : interfaces) { if (!typeUsage.isReferenceTypeUsage() || !typeUsage.asReferenceTypeUsage().isInterface(resolver)) { errorCollector.recordSemanticError( typeUsage.getPosition(), "Only interfaces can be implemented"); return false; } } if (getExplicitConstructors().size() > 1) { for (TurinTypeContructorDefinitionNode contructorDefinition : getExplicitConstructors()) { errorCollector.recordSemanticError( contructorDefinition.getPosition(), "At most one explicit constructor can be defined"); } return false; } return super.specificValidate(resolver, errorCollector); }
@Override public Iterable<Node> getChildren() { List<Node> children = new LinkedList<>(); children.addAll(members); children.addAll(annotations); if (baseType.isPresent()) { children.add(baseType.get()); } children.addAll(interfaces); return children; }
@Override public JvmConstructorDefinition resolveConstructorCall(List<ActualParam> actualParams) { // all named parameters should be after the named ones if (!ParamUtils.verifyOrder(actualParams)) { throw new IllegalArgumentException( "Named params should all be grouped after the positional ones"); } ensureIsInitialized(symbolResolver()); Optional<InternalConstructorDefinition> constructor = constructors.stream().filter((c) -> c.match(symbolResolver(), actualParams)).findFirst(); if (!constructor.isPresent()) { throw new UnsolvedConstructorException(getQualifiedName(), actualParams); } return constructor.get().getJvmConstructorDefinition(); }