Skip to content

Commit

Permalink
Merge pull request #1029 from reactiveui/more-source-generator
Browse files Browse the repository at this point in the history
Use Semantic model for generating sources
  • Loading branch information
clairernovotny authored Jan 23, 2021
2 parents a2c721c + b3c3e70 commit f6e30cf
Show file tree
Hide file tree
Showing 10 changed files with 384 additions and 816 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<NoWarn>$(NoWarn);1701;1702;CS1591;NU1701</NoWarn>
<NoPackageAnalysis>true</NoPackageAnalysis>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)Refit.ruleset</CodeAnalysisRuleSet>
<LangVersion>latest</LangVersion>
<LangVersion>preview</LangVersion>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)buildtask.snk</AssemblyOriginatorKeyFile>
Expand Down

This file was deleted.

45 changes: 45 additions & 0 deletions InterfaceStubGenerator.Core/ITypeSymbolExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.CodeAnalysis;

namespace Refit.Generator
{
static class ITypeSymbolExtensions
{
public static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(this ITypeSymbol? type)
{
var current = type;
while (current != null)
{
yield return current;
current = current.BaseType;
}
}

// Determine if "type" inherits from "baseType", ignoring constructed types, optionally including interfaces,
// dealing only with original types.
public static bool InheritsFromOrEquals(
this ITypeSymbol type, ITypeSymbol baseType, bool includeInterfaces)
{
if (!includeInterfaces)
{
return InheritsFromOrEquals(type, baseType);
}

return type.GetBaseTypesAndThis().Concat(type.AllInterfaces).Any(t => t.Equals(baseType, SymbolEqualityComparer.Default));
}


// Determine if "type" inherits from "baseType", ignoring constructed types and interfaces, dealing
// only with original types.
public static bool InheritsFromOrEquals(
this ITypeSymbol type, ITypeSymbol baseType)
{
return type.GetBaseTypesAndThis().Any(t => t.Equals(baseType, SymbolEqualityComparer.Default));
}

}
}
19 changes: 1 addition & 18 deletions InterfaceStubGenerator.Core/InterfaceStubGenerator.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,11 @@
<AssemblyOriginatorKeyFile>..\buildtask.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<IsRoslynComponent>true</IsRoslynComponent>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" />
<PackageReference Include="Nustache" Version="1.16.0.10" GeneratePathProperty="true" PrivateAssets="all" />
</ItemGroup>

<PropertyGroup>
<GetTargetPathDependsOn>$(GetTargetPathDependsOn);GetDependencyTargetPaths</GetTargetPathDependsOn>
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="GeneratedInterfaceStubTemplate.mustache">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>

<Target Name="SetBuildVer" AfterTargets="GetBuildVersion" BeforeTargets="SetCloudBuildVersionVars;SetCloudBuildNumberWithVersion">
Expand All @@ -32,10 +21,4 @@
</PropertyGroup>
</Target>

<Target Name="GetDependencyTargetPaths">
<ItemGroup>
<TargetPathWithTargetPlatformMoniker Include="$(PkgNustache)\lib\net20\Nustache.Core.dll" IncludeRuntimeDependency="false" />
</ItemGroup>
</Target>

</Project>
Loading

0 comments on commit f6e30cf

Please sign in to comment.