Skip to content

Add keywords abstract and concrete #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 226 additions & 0 deletions docs/en-US/about_Type_Signatures.help.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Type signatures are a custom query language built into PowerShell type expressio
* [Generic Parameters (`T`, `TT`, and `TM`)](#generic-parameters-t-tt-and-tm)
* [`primitive`](#primitive)
* [`interface`](#interface)
* [`abstract`](#abstract)
* [`concrete`](#concrete)
* [`number`](#number)
* [`decoration`, `hasattr`](#decoration-hasattr)
* [`generic`](#generic)
Expand Down Expand Up @@ -2508,6 +2510,230 @@ void Example(int value);
</tr>
</table>

## `abstract`

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

Matches only abstract types.

<table>
<tr>
<td colspan="2" width="1000">

```powershell
Find-Member -ParameterType { [abstract] }
```

</td>
</tr>
<tr>
<th width="1">

</th>
<th>

Signature

</th>
</tr>
<tr>
<td width="1">

:x:

</td>
<td>

```csharp
void Example(IDisposable disposable);
```

</td>
</tr>
<tr>
<td width="1">

:x:

</td>
<td>

```csharp
void Example(object obj);
```

</td>
</tr>
<tr>
<td width="1">

:x:

</td>
<td>

```csharp
void Example(int value);
```

</td>
</tr>
<tr>
<td width="1">

:x:

</td>
<td>

```csharp
void Example(T value);
```

</td>
</tr>
<tr>
<td width="1">

:heavy_check_mark:

</td>
<td>

```csharp
void Example(FileSystemInfo value);
```

</td>
</tr>
<tr>
<td width="1">

:heavy_check_mark:

</td>
<td>

```csharp
void Example(FileInfo value);
```

</td>
</tr>
</table>

## `concrete`

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

Matches only concrete types. No abstract classes, interfaces, or generic parameters.

<table>
<tr>
<td colspan="2" width="1000">

```powershell
Find-Member -ParameterType { [abstract] }
```

</td>
</tr>
<tr>
<th width="1">

</th>
<th>

Signature

</th>
</tr>
<tr>
<td width="1">

:x:

</td>
<td>

```csharp
void Example(IDisposable disposable);
```

</td>
</tr>
<tr>
<td width="1">

:heavy_check_mark:

</td>
<td>

```csharp
void Example(object obj);
```

</td>
</tr>
<tr>
<td width="1">

:heavy_check_mark:

</td>
<td>

```csharp
void Example(int value);
```

</td>
</tr>
<tr>
<td width="1">

:x:

</td>
<td>

```csharp
void Example(T value);
```

</td>
</tr>
<tr>
<td width="1">

:x:

</td>
<td>

```csharp
void Example(FileSystemInfo value);
```

</td>
</tr>
<tr>
<td width="1">

:heavy_check_mark:

</td>
<td>

```csharp
void Example(FileInfo value);
```

</td>
</tr>
</table>

## `number`

<sup>([Back to Top](#keywords))</sup>
Expand Down
4 changes: 3 additions & 1 deletion src/ClassExplorer/Signatures/ClassificationKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ internal enum ClassificationKind

Primitive = 1 << 8,

Pointer = 1 << 9,
Abstract = 1 << 9,

Concrete = 1 << 10,
}
}
2 changes: 2 additions & 0 deletions src/ClassExplorer/Signatures/Keywords.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ internal static class Keywords
public const string @enum = "enum";
public const string referencetype = "referencetype";
public const string @interface = "interface";
public const string @abstract = "abstract";
public const string concrete = "concrete";
public const string primitive = "primitive";
public const string pointer = "pointer";
public const string any = "any";
Expand Down
2 changes: 2 additions & 0 deletions src/ClassExplorer/Signatures/SignatureParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ public ITypeSignature ParseDefinition(
Keywords.@enum => new TypeClassification(ClassificationKind.Enum),
Keywords.referencetype => new TypeClassification(ClassificationKind.ReferenceType),
Keywords.@interface => new TypeClassification(ClassificationKind.Interface),
Keywords.@abstract => new TypeClassification(ClassificationKind.Abstract),
Keywords.concrete => new TypeClassification(ClassificationKind.Concrete),
Keywords.primitive => new TypeClassification(ClassificationKind.Primitive),
Keywords.any => new AnySignature(),
Keywords.generic => Consume(ParseGeneric(args, typeName), out argsConsumed),
Expand Down
33 changes: 32 additions & 1 deletion src/ClassExplorer/Signatures/TypeClassification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,42 @@ public override bool IsMatch(Type type)
return false;
}

if ((Kind & ClassificationKind.Pointer) != 0 && !type.IsPointer)
if ((Kind & ClassificationKind.Abstract) != 0 && (!type.IsAbstract || type.IsInterface))
{
return false;
}

if ((Kind & ClassificationKind.Concrete) != 0 && !IsConcrete(type))
{
return false;
}

return true;
}

private static bool IsConcrete(Type type)
{
if (type is not { IsAbstract: false, IsInterface: false, IsGenericParameter: false })
{
return false;
}

if (type.IsGenericType)
{
foreach (Type genericArg in type.GetGenericArguments())
{
if (!IsConcrete(genericArg))
{
return false;
}
}
}

if (type.HasElementType)
{
return IsConcrete(type.GetElementType()!);
}

return true;
}

Expand Down
36 changes: 36 additions & 0 deletions tools/Signatures.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,42 @@ keywords:
- match: false
sig: void Example(int value);

- header: "`abstract`"
description: Matches only abstract types.
examples:
- syntax: Find-Member -ParameterType { [abstract] }
signatures:
- match: false
sig: void Example(IDisposable disposable);
- match: false
sig: void Example(object obj);
- match: false
sig: void Example(int value);
- match: false
sig: void Example(T value);
- match: true
sig: void Example(FileSystemInfo value);
- match: true
sig: void Example(FileInfo value);

- header: "`concrete`"
description: Matches only concrete types. No abstract classes, interfaces, or generic parameters.
examples:
- syntax: Find-Member -ParameterType { [abstract] }
signatures:
- match: false
sig: void Example(IDisposable disposable);
- match: true
sig: void Example(object obj);
- match: true
sig: void Example(int value);
- match: false
sig: void Example(T value);
- match: false
sig: void Example(FileSystemInfo value);
- match: true
sig: void Example(FileInfo value);

- header: "`number`"
description: Matches a hard coded list of types representing numbers.
examples:
Expand Down