Skip to content

Commit cf3e638

Browse files
Add keywords abstract and concrete (#27)
1 parent 7eeb273 commit cf3e638

File tree

6 files changed

+301
-2
lines changed

6 files changed

+301
-2
lines changed

docs/en-US/about_Type_Signatures.help.md

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Type signatures are a custom query language built into PowerShell type expressio
2626
* [Generic Parameters (`T`, `TT`, and `TM`)](#generic-parameters-t-tt-and-tm)
2727
* [`primitive`](#primitive)
2828
* [`interface`](#interface)
29+
* [`abstract`](#abstract)
30+
* [`concrete`](#concrete)
2931
* [`number`](#number)
3032
* [`decoration`, `hasattr`](#decoration-hasattr)
3133
* [`generic`](#generic)
@@ -2508,6 +2510,230 @@ void Example(int value);
25082510
</tr>
25092511
</table>
25102512

2513+
## `abstract`
2514+
2515+
<sup>([Back to Top](#keywords))</sup>
2516+
2517+
Matches only abstract types.
2518+
2519+
<table>
2520+
<tr>
2521+
<td colspan="2" width="1000">
2522+
2523+
```powershell
2524+
Find-Member -ParameterType { [abstract] }
2525+
```
2526+
2527+
</td>
2528+
</tr>
2529+
<tr>
2530+
<th width="1">
2531+
2532+
</th>
2533+
<th>
2534+
2535+
Signature
2536+
2537+
</th>
2538+
</tr>
2539+
<tr>
2540+
<td width="1">
2541+
2542+
:x:
2543+
2544+
</td>
2545+
<td>
2546+
2547+
```csharp
2548+
void Example(IDisposable disposable);
2549+
```
2550+
2551+
</td>
2552+
</tr>
2553+
<tr>
2554+
<td width="1">
2555+
2556+
:x:
2557+
2558+
</td>
2559+
<td>
2560+
2561+
```csharp
2562+
void Example(object obj);
2563+
```
2564+
2565+
</td>
2566+
</tr>
2567+
<tr>
2568+
<td width="1">
2569+
2570+
:x:
2571+
2572+
</td>
2573+
<td>
2574+
2575+
```csharp
2576+
void Example(int value);
2577+
```
2578+
2579+
</td>
2580+
</tr>
2581+
<tr>
2582+
<td width="1">
2583+
2584+
:x:
2585+
2586+
</td>
2587+
<td>
2588+
2589+
```csharp
2590+
void Example(T value);
2591+
```
2592+
2593+
</td>
2594+
</tr>
2595+
<tr>
2596+
<td width="1">
2597+
2598+
:heavy_check_mark:
2599+
2600+
</td>
2601+
<td>
2602+
2603+
```csharp
2604+
void Example(FileSystemInfo value);
2605+
```
2606+
2607+
</td>
2608+
</tr>
2609+
<tr>
2610+
<td width="1">
2611+
2612+
:heavy_check_mark:
2613+
2614+
</td>
2615+
<td>
2616+
2617+
```csharp
2618+
void Example(FileInfo value);
2619+
```
2620+
2621+
</td>
2622+
</tr>
2623+
</table>
2624+
2625+
## `concrete`
2626+
2627+
<sup>([Back to Top](#keywords))</sup>
2628+
2629+
Matches only concrete types. No abstract classes, interfaces, or generic parameters.
2630+
2631+
<table>
2632+
<tr>
2633+
<td colspan="2" width="1000">
2634+
2635+
```powershell
2636+
Find-Member -ParameterType { [abstract] }
2637+
```
2638+
2639+
</td>
2640+
</tr>
2641+
<tr>
2642+
<th width="1">
2643+
2644+
</th>
2645+
<th>
2646+
2647+
Signature
2648+
2649+
</th>
2650+
</tr>
2651+
<tr>
2652+
<td width="1">
2653+
2654+
:x:
2655+
2656+
</td>
2657+
<td>
2658+
2659+
```csharp
2660+
void Example(IDisposable disposable);
2661+
```
2662+
2663+
</td>
2664+
</tr>
2665+
<tr>
2666+
<td width="1">
2667+
2668+
:heavy_check_mark:
2669+
2670+
</td>
2671+
<td>
2672+
2673+
```csharp
2674+
void Example(object obj);
2675+
```
2676+
2677+
</td>
2678+
</tr>
2679+
<tr>
2680+
<td width="1">
2681+
2682+
:heavy_check_mark:
2683+
2684+
</td>
2685+
<td>
2686+
2687+
```csharp
2688+
void Example(int value);
2689+
```
2690+
2691+
</td>
2692+
</tr>
2693+
<tr>
2694+
<td width="1">
2695+
2696+
:x:
2697+
2698+
</td>
2699+
<td>
2700+
2701+
```csharp
2702+
void Example(T value);
2703+
```
2704+
2705+
</td>
2706+
</tr>
2707+
<tr>
2708+
<td width="1">
2709+
2710+
:x:
2711+
2712+
</td>
2713+
<td>
2714+
2715+
```csharp
2716+
void Example(FileSystemInfo value);
2717+
```
2718+
2719+
</td>
2720+
</tr>
2721+
<tr>
2722+
<td width="1">
2723+
2724+
:heavy_check_mark:
2725+
2726+
</td>
2727+
<td>
2728+
2729+
```csharp
2730+
void Example(FileInfo value);
2731+
```
2732+
2733+
</td>
2734+
</tr>
2735+
</table>
2736+
25112737
## `number`
25122738

25132739
<sup>([Back to Top](#keywords))</sup>

src/ClassExplorer/Signatures/ClassificationKind.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ internal enum ClassificationKind
2525

2626
Primitive = 1 << 8,
2727

28-
Pointer = 1 << 9,
28+
Abstract = 1 << 9,
29+
30+
Concrete = 1 << 10,
2931
}
3032
}

src/ClassExplorer/Signatures/Keywords.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ internal static class Keywords
2727
public const string @enum = "enum";
2828
public const string referencetype = "referencetype";
2929
public const string @interface = "interface";
30+
public const string @abstract = "abstract";
31+
public const string concrete = "concrete";
3032
public const string primitive = "primitive";
3133
public const string pointer = "pointer";
3234
public const string any = "any";

src/ClassExplorer/Signatures/SignatureParser.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ public ITypeSignature ParseDefinition(
220220
Keywords.@enum => new TypeClassification(ClassificationKind.Enum),
221221
Keywords.referencetype => new TypeClassification(ClassificationKind.ReferenceType),
222222
Keywords.@interface => new TypeClassification(ClassificationKind.Interface),
223+
Keywords.@abstract => new TypeClassification(ClassificationKind.Abstract),
224+
Keywords.concrete => new TypeClassification(ClassificationKind.Concrete),
223225
Keywords.primitive => new TypeClassification(ClassificationKind.Primitive),
224226
Keywords.any => new AnySignature(),
225227
Keywords.generic => Consume(ParseGeneric(args, typeName), out argsConsumed),

src/ClassExplorer/Signatures/TypeClassification.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,42 @@ public override bool IsMatch(Type type)
5555
return false;
5656
}
5757

58-
if ((Kind & ClassificationKind.Pointer) != 0 && !type.IsPointer)
58+
if ((Kind & ClassificationKind.Abstract) != 0 && (!type.IsAbstract || type.IsInterface))
5959
{
6060
return false;
6161
}
6262

63+
if ((Kind & ClassificationKind.Concrete) != 0 && !IsConcrete(type))
64+
{
65+
return false;
66+
}
67+
68+
return true;
69+
}
70+
71+
private static bool IsConcrete(Type type)
72+
{
73+
if (type is not { IsAbstract: false, IsInterface: false, IsGenericParameter: false })
74+
{
75+
return false;
76+
}
77+
78+
if (type.IsGenericType)
79+
{
80+
foreach (Type genericArg in type.GetGenericArguments())
81+
{
82+
if (!IsConcrete(genericArg))
83+
{
84+
return false;
85+
}
86+
}
87+
}
88+
89+
if (type.HasElementType)
90+
{
91+
return IsConcrete(type.GetElementType()!);
92+
}
93+
6394
return true;
6495
}
6596

tools/Signatures.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,42 @@ keywords:
434434
- match: false
435435
sig: void Example(int value);
436436

437+
- header: "`abstract`"
438+
description: Matches only abstract types.
439+
examples:
440+
- syntax: Find-Member -ParameterType { [abstract] }
441+
signatures:
442+
- match: false
443+
sig: void Example(IDisposable disposable);
444+
- match: false
445+
sig: void Example(object obj);
446+
- match: false
447+
sig: void Example(int value);
448+
- match: false
449+
sig: void Example(T value);
450+
- match: true
451+
sig: void Example(FileSystemInfo value);
452+
- match: true
453+
sig: void Example(FileInfo value);
454+
455+
- header: "`concrete`"
456+
description: Matches only concrete types. No abstract classes, interfaces, or generic parameters.
457+
examples:
458+
- syntax: Find-Member -ParameterType { [abstract] }
459+
signatures:
460+
- match: false
461+
sig: void Example(IDisposable disposable);
462+
- match: true
463+
sig: void Example(object obj);
464+
- match: true
465+
sig: void Example(int value);
466+
- match: false
467+
sig: void Example(T value);
468+
- match: false
469+
sig: void Example(FileSystemInfo value);
470+
- match: true
471+
sig: void Example(FileInfo value);
472+
437473
- header: "`number`"
438474
description: Matches a hard coded list of types representing numbers.
439475
examples:

0 commit comments

Comments
 (0)