private void initializeExplicitConstructor( TurinTypeContructorDefinitionNode constructor, SymbolResolver resolver) { List<? extends FormalParameter> allParams = constructor.getParameters(); List<FormalParameter> paramsWithoutDefaultValues = allParams .stream() .filter((p) -> !p.hasDefaultValue()) .collect(Collectors.<FormalParameter>toList()); List<String> paramSignatures = paramsWithoutDefaultValues .stream() .map((p) -> p.getType().jvmType().getSignature()) .collect(Collectors.toList()); boolean hasDefaultParameters = allParams.stream().filter((p) -> p.hasDefaultValue()).findFirst().isPresent(); if (hasDefaultParameters) { paramSignatures.add("Ljava/util/Map;"); } JvmConstructorDefinition constructorDefinition = new JvmConstructorDefinition( jvmType().getInternalName(), "(" + String.join("", paramSignatures) + ")V"); constructors.add( new InternalConstructorDefinition( new ReferenceTypeUsage(this), allParams, constructorDefinition)); }
@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); }
public void add(TurinTypeContructorDefinitionNode contructorDefinition) { members.add(contructorDefinition); contructorDefinition.parent = this; }