Skip to content

Commit d1a45fd

Browse files
committed
Fix printer compatibility
1 parent f0c0704 commit d1a45fd

3 files changed

Lines changed: 17 additions & 20 deletions

File tree

libs/printer/src/PrettyPrinter.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace TypeLang\Printer;
66

77
use TypeLang\Node\Node;
8-
use TypeLang\Node\Statement;
98
use TypeLang\Node\Type\Attribute\AttributeGroupNode;
109
use TypeLang\Node\Type\Attribute\AttributeGroupsListNode;
1110
use TypeLang\Node\Type\Callable\CallableParameterNode;
@@ -25,6 +24,7 @@
2524
use TypeLang\Node\Type\LogicalTypeNode;
2625
use TypeLang\Node\Type\NamedTypeNode;
2726
use TypeLang\Node\Type\NullableTypeNode;
27+
use TypeLang\Node\Type\Shape\ClassConstFieldNode;
2828
use TypeLang\Node\Type\Shape\ClassConstMaskFieldNode;
2929
use TypeLang\Node\Type\Shape\ConstMaskFieldNode;
3030
use TypeLang\Node\Type\Shape\FieldNode;
@@ -123,7 +123,7 @@ public function __construct(
123123
/**
124124
* @throws NonPrintableNodeException
125125
*/
126-
protected function make(Statement $stmt): string
126+
protected function make(TypeNode $stmt): string
127127
{
128128
return match (true) {
129129
$stmt instanceof LiteralNode => $this->printLiteralNode($stmt),
@@ -282,6 +282,7 @@ protected function printShapeFieldName(FieldNode $field): string
282282
$field instanceof NamedFieldNode => $this->printNamedShapeFieldName($field),
283283
$field instanceof ConstMaskFieldNode => $this->printConstMaskShapeFieldName($field),
284284
$field instanceof ClassConstMaskFieldNode => $this->printClassConstMaskShapeFieldName($field),
285+
$field instanceof ClassConstFieldNode => $this->printClassConstShapeFieldName($field),
285286
default => $this->printUnknownShapeFieldName($field),
286287
};
287288
}
@@ -306,20 +307,20 @@ protected function printConstMaskShapeFieldName(ConstMaskFieldNode $field): stri
306307
return $field->key->name->toString() . '*';
307308
}
308309

310+
protected function printClassConstShapeFieldName(ClassConstFieldNode $field): string
311+
{
312+
return \sprintf('%s::%s', $field->key->class, $field->key->constant);
313+
}
314+
309315
protected function printClassConstMaskShapeFieldName(ClassConstMaskFieldNode $field): string
310316
{
311-
$class = $field->key->class;
312317
$constant = $field->key->constant;
313318

314-
if ($field->key instanceof ClassConstNode) {
315-
return $class . '::' . $constant;
316-
}
317-
318319
if ($constant === null) {
319-
return $class . '::*';
320+
return \sprintf('%s::*', $field->key->class);
320321
}
321322

322-
return $class . '::' . $constant . '*';
323+
return \sprintf('%s::%s*', $field->key->class, $constant);
323324
}
324325

325326
protected function printUnknownShapeFieldName(FieldNode $field): string

libs/printer/src/Printer.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace TypeLang\Printer;
66

7-
use TypeLang\Node\Statement;
87
use TypeLang\Node\Type\LogicalTypeNode;
98
use TypeLang\Node\Type\TypeNode;
109

@@ -13,12 +12,12 @@ abstract class Printer implements PrinterInterface
1312
/**
1413
* @var non-empty-string
1514
*/
16-
protected const DEFAULT_NEW_LINE_DELIMITER = "\n";
15+
protected const string DEFAULT_NEW_LINE_DELIMITER = "\n";
1716

1817
/**
1918
* @var non-empty-string
2019
*/
21-
protected const DEFAULT_INDENTION = ' ';
20+
protected const string DEFAULT_INDENTION = ' ';
2221

2322
/**
2423
* @var int<0, max>
@@ -41,7 +40,7 @@ public function __construct(
4140
public readonly string $indention = self::DEFAULT_INDENTION,
4241
) {}
4342

44-
public function print(Statement $stmt): string
43+
public function print(TypeNode $stmt): string
4544
{
4645
$this->nesting = $this->depth = 0;
4746

@@ -51,7 +50,7 @@ public function print(Statement $stmt): string
5150
/**
5251
* @return non-empty-string
5352
*/
54-
abstract protected function make(Statement $stmt): string;
53+
abstract protected function make(TypeNode $stmt): string;
5554

5655
/**
5756
* @param int<0, max>|null $depth
@@ -96,7 +95,7 @@ protected function unwrapAndPrint(LogicalTypeNode $stmt): iterable
9695
}
9796

9897
/**
99-
* @param iterable<mixed, Statement> $stmts
98+
* @param iterable<mixed, TypeNode> $stmts
10099
*
101100
* @return list<non-empty-string>
102101
*/

libs/printer/src/PrinterInterface.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44

55
namespace TypeLang\Printer;
66

7-
use TypeLang\Node\Statement;
7+
use TypeLang\Node\Type\TypeNode;
88

99
interface PrinterInterface
1010
{
11-
/**
12-
* @return non-empty-string
13-
*/
14-
public function print(Statement $stmt): string;
11+
public function print(TypeNode $stmt): string;
1512
}

0 commit comments

Comments
 (0)