diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 19d729c..6746357 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,6 +1,6 @@  - 2.0.1-pre03 + 2.0.1-pre04 Copyright © JetBrains 2024 Apache-2.0 diff --git a/src/Refasmer/Importer/ImportLogic.cs b/src/Refasmer/Importer/ImportLogic.cs index 4ba9cfd..2ee152d 100644 --- a/src/Refasmer/Importer/ImportLogic.cs +++ b/src/Refasmer/Importer/ImportLogic.cs @@ -619,17 +619,23 @@ private IEnumerable CalculateInternalTypesToPreserve( var parentTypes = new List(); if (!type.BaseType.IsNil) parentTypes.Add(type.BaseType); - foreach (var interfaceImpl in type.GetInterfaceImplementations()) + foreach (var interfaceImplHandle in type.GetInterfaceImplementations()) { - var @interface = _reader.GetInterfaceImplementation(interfaceImpl); - parentTypes.Add(@interface.Interface); + var interfaceImpl = _reader.GetInterfaceImplementation(interfaceImplHandle); + parentTypes.Add(interfaceImpl.Interface); } foreach (var parentTypeHandle in parentTypes) { - if (parentTypeHandle.Kind == HandleKind.TypeDefinition) + switch (parentTypeHandle.Kind) { - candidateTypes.Add((TypeDefinitionHandle)parentTypeHandle); + case HandleKind.TypeDefinition: + candidateTypes.Add((TypeDefinitionHandle)parentTypeHandle); + break; + case HandleKind.TypeSpecification: + var specification = _reader.GetTypeSpecification((TypeSpecificationHandle)parentTypeHandle); + AcceptTypeSignature(specification.Signature, collector); + break; } } diff --git a/tests/Refasmer.Tests/IntegrationTests.cs b/tests/Refasmer.Tests/IntegrationTests.cs index 939b549..2256709 100644 --- a/tests/Refasmer.Tests/IntegrationTests.cs +++ b/tests/Refasmer.Tests/IntegrationTests.cs @@ -49,18 +49,19 @@ await VerifyTypeContents( [TestCase("PublicClassWithInternalTypeInApi", "Class1ToBeMarkedInternal")] [TestCase("PublicClassDerivingFromInternal", "Class2ToBeMarkedInternal")] - [TestCase("PublicClassImplementingInternal", "InterfaceToBeMarkedInternal")] - public async Task InternalTypeInPublicApi(string mainClassName, string auxiliaryClassName) + [TestCase("PublicClassImplementingInternal", "IInterface1ToBeMarkedInternal")] + [TestCase("PublicClassWithInternalInterfaceImpl", "Class3ToBeMarkedInternal,IInterface2ToBeMarkedInternal`1")] + public async Task InternalTypeInPublicApi(string mainClassName, string auxiliaryClassNames) { var assemblyPath = await BuildTestAssemblyWithInternalTypeInPublicApi(); var resultAssembly = RefasmTestAssembly(assemblyPath, omitNonApiMembers: true); var fullMainClassName = $"RefasmerTestAssembly.{mainClassName}"; - var fullAuxiliaryClassName = $"RefasmerTestAssembly.{auxiliaryClassName}"; + var fullAuxiliaryClassNames = auxiliaryClassNames.Split(',').Select(x => $"RefasmerTestAssembly.{x}"); await VerifyTypeContents( resultAssembly, - [fullMainClassName, fullAuxiliaryClassName], + [fullMainClassName, ..fullAuxiliaryClassNames], parameters: [mainClassName]); } } diff --git a/tests/Refasmer.Tests/Printer.cs b/tests/Refasmer.Tests/Printer.cs index 36a0a9c..d2ec172 100644 --- a/tests/Refasmer.Tests/Printer.cs +++ b/tests/Refasmer.Tests/Printer.cs @@ -8,7 +8,8 @@ public static class Printer public static void PrintType(TypeDefinition type, StringBuilder printout, string indent = "") { var access = GetAccessString(type); - printout.AppendLine($"{indent}{access} type: {type.FullName}"); + var typeKind = GetTypeKindString(type); + printout.AppendLine($"{indent}{access} {typeKind}: {type.FullName}"); if (type.HasFields) { printout.AppendLine($"{indent}fields:"); @@ -34,10 +35,15 @@ public static void PrintType(TypeDefinition type, StringBuilder printout, string } } - printout.AppendLine($"{indent}): {method.ReturnType}:"); - foreach (var instruction in method.Body.Instructions) + printout.AppendLine($"): {method.ReturnType}:"); + if (method.IsAbstract) + printout.AppendLine($"{indent} - "); + else { - printout.AppendLine($"{indent} - {instruction}"); + foreach (var instruction in method.Body.Instructions) + { + printout.AppendLine($"{indent} - {instruction}"); + } } } } @@ -62,4 +68,14 @@ private static string GetAccessString(TypeDefinition type) if (type.IsNestedFamilyAndAssembly) return "private protected"; return "internal"; } + + private static string GetTypeKindString(TypeDefinition typeDefinition) + { + var result = new StringBuilder(); + if (typeDefinition.IsInterface) result.Append("interface"); + else if (typeDefinition.IsAbstract) result.Append("abstract "); + if (typeDefinition.IsValueType) result.Append("struct"); + else if (typeDefinition.IsClass) result.Append("class"); + return result.ToString(); + } } diff --git a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.BlittableGraph.verified.txt b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.BlittableGraph.verified.txt index 5d625ae..1b156e7 100644 --- a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.BlittableGraph.verified.txt +++ b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.BlittableGraph.verified.txt @@ -1,3 +1,3 @@ -public type: RefasmerTestAssembly.BlittableGraph +public struct: RefasmerTestAssembly.BlittableGraph fields: - : System.Int32 diff --git a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.BlittableStructWithPrivateFields.verified.txt b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.BlittableStructWithPrivateFields.verified.txt index 2d4e000..f803a52 100644 --- a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.BlittableStructWithPrivateFields.verified.txt +++ b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.BlittableStructWithPrivateFields.verified.txt @@ -1,3 +1,3 @@ -public type: RefasmerTestAssembly.BlittableStructWithPrivateFields +public struct: RefasmerTestAssembly.BlittableStructWithPrivateFields fields: - : System.Int32 diff --git a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.EmptyStructWithStaticMember.verified.txt b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.EmptyStructWithStaticMember.verified.txt index cb9c757..fb20c2b 100644 --- a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.EmptyStructWithStaticMember.verified.txt +++ b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.EmptyStructWithStaticMember.verified.txt @@ -1 +1 @@ -public type: RefasmerTestAssembly.EmptyStructWithStaticMember +public struct: RefasmerTestAssembly.EmptyStructWithStaticMember diff --git a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.NonBlittableGraph.verified.txt b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.NonBlittableGraph.verified.txt index 2b70304..a9e6a31 100644 --- a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.NonBlittableGraph.verified.txt +++ b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.NonBlittableGraph.verified.txt @@ -1,3 +1,3 @@ -public type: RefasmerTestAssembly.NonBlittableGraph +public struct: RefasmerTestAssembly.NonBlittableGraph fields: - : System.Int32 diff --git a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.NonBlittableStructWithPrivateFields.verified.txt b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.NonBlittableStructWithPrivateFields.verified.txt index 3e5a629..dd46266 100644 --- a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.NonBlittableStructWithPrivateFields.verified.txt +++ b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.NonBlittableStructWithPrivateFields.verified.txt @@ -1,3 +1,3 @@ -public type: RefasmerTestAssembly.NonBlittableStructWithPrivateFields +public struct: RefasmerTestAssembly.NonBlittableStructWithPrivateFields fields: - : System.Int32 diff --git a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.NonEmptyStructWithStaticMember.verified.txt b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.NonEmptyStructWithStaticMember.verified.txt index a5eb51c..e62402a 100644 --- a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.NonEmptyStructWithStaticMember.verified.txt +++ b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.NonEmptyStructWithStaticMember.verified.txt @@ -1,3 +1,3 @@ -public type: RefasmerTestAssembly.NonEmptyStructWithStaticMember +public struct: RefasmerTestAssembly.NonEmptyStructWithStaticMember fields: - : System.Int32 diff --git a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.PublicClassWithPrivateFields.verified.txt b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.PublicClassWithPrivateFields.verified.txt index b3096b0..059e029 100644 --- a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.PublicClassWithPrivateFields.verified.txt +++ b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.PublicClassWithPrivateFields.verified.txt @@ -1,4 +1,4 @@ -public type: RefasmerTestAssembly.PublicClassWithPrivateFields +public class: RefasmerTestAssembly.PublicClassWithPrivateFields fields: - PublicInt: System.Int32 methods: diff --git a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.PublicStructWithPrivateFields.verified.txt b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.PublicStructWithPrivateFields.verified.txt index ed60ee4..999eb30 100644 --- a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.PublicStructWithPrivateFields.verified.txt +++ b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.PublicStructWithPrivateFields.verified.txt @@ -1,3 +1,3 @@ -public type: RefasmerTestAssembly.PublicStructWithPrivateFields +public struct: RefasmerTestAssembly.PublicStructWithPrivateFields fields: - PublicInt: System.Int32 diff --git a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.StructWithNestedPrivateTypes.verified.txt b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.StructWithNestedPrivateTypes.verified.txt index 08cefb4..768d907 100644 --- a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.StructWithNestedPrivateTypes.verified.txt +++ b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.StructWithNestedPrivateTypes.verified.txt @@ -1,7 +1,7 @@ -public type: RefasmerTestAssembly.StructWithNestedPrivateTypes +public struct: RefasmerTestAssembly.StructWithNestedPrivateTypes fields: - : System.Int32 types: - internal type: RefasmerTestAssembly.StructWithNestedPrivateTypes/UnusedPublicStruct + internal struct: RefasmerTestAssembly.StructWithNestedPrivateTypes/UnusedPublicStruct fields: - : System.Int32 diff --git a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.UnsafeClassWithFunctionPointer.verified.txt b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.UnsafeClassWithFunctionPointer.verified.txt index 679ec12..d81374a 100644 --- a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.UnsafeClassWithFunctionPointer.verified.txt +++ b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedTypeOmitNonApi_typeName=RefasmerTestAssembly.UnsafeClassWithFunctionPointer.verified.txt @@ -1,4 +1,4 @@ -public type: RefasmerTestAssembly.UnsafeClassWithFunctionPointer +public class: RefasmerTestAssembly.UnsafeClassWithFunctionPointer methods: - MethodWithFunctionPointer(method System.Void *() functionPointer): System.Void: - .ctor(): System.Void: diff --git a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedType_typeName=RefasmerTestAssembly.NonBlittableGraph.verified.txt b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedType_typeName=RefasmerTestAssembly.NonBlittableGraph.verified.txt index 940bc52..2cd2c1c 100644 --- a/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedType_typeName=RefasmerTestAssembly.NonBlittableGraph.verified.txt +++ b/tests/Refasmer.Tests/data/IntegrationTests.CheckRefasmedType_typeName=RefasmerTestAssembly.NonBlittableGraph.verified.txt @@ -1,11 +1,11 @@ -public type: RefasmerTestAssembly.NonBlittableGraph +public struct: RefasmerTestAssembly.NonBlittableGraph fields: - x: RefasmerTestAssembly.NonBlittableGraph/DubiouslyBlittableType types: - private type: RefasmerTestAssembly.NonBlittableGraph/DubiouslyBlittableType + private struct: RefasmerTestAssembly.NonBlittableGraph/DubiouslyBlittableType fields: - x: RefasmerTestAssembly.NonBlittableGraph/DubiouslyBlittableType/NonBlittableType types: - private type: RefasmerTestAssembly.NonBlittableGraph/DubiouslyBlittableType/NonBlittableType + private struct: RefasmerTestAssembly.NonBlittableGraph/DubiouslyBlittableType/NonBlittableType fields: - x: System.String diff --git a/tests/Refasmer.Tests/data/IntegrationTests.InternalTypeInPublicApi_mainClassName=PublicClassImplementingInternal.verified.txt b/tests/Refasmer.Tests/data/IntegrationTests.InternalTypeInPublicApi_mainClassName=PublicClassImplementingInternal.verified.txt index c287ddf..6beb1d5 100644 --- a/tests/Refasmer.Tests/data/IntegrationTests.InternalTypeInPublicApi_mainClassName=PublicClassImplementingInternal.verified.txt +++ b/tests/Refasmer.Tests/data/IntegrationTests.InternalTypeInPublicApi_mainClassName=PublicClassImplementingInternal.verified.txt @@ -1,4 +1,4 @@ -public type: RefasmerTestAssembly.PublicClassImplementingInternal +public class: RefasmerTestAssembly.PublicClassImplementingInternal methods: - .ctor(): System.Void: -internal type: RefasmerTestAssembly.InterfaceToBeMarkedInternal +internal interface: RefasmerTestAssembly.IInterface1ToBeMarkedInternal diff --git a/tests/Refasmer.Tests/data/IntegrationTests.InternalTypeInPublicApi_mainClassName=PublicClassWithInternalInterfaceImpl.verified.txt b/tests/Refasmer.Tests/data/IntegrationTests.InternalTypeInPublicApi_mainClassName=PublicClassWithInternalInterfaceImpl.verified.txt new file mode 100644 index 0000000..ce5a3ce --- /dev/null +++ b/tests/Refasmer.Tests/data/IntegrationTests.InternalTypeInPublicApi_mainClassName=PublicClassWithInternalInterfaceImpl.verified.txt @@ -0,0 +1,9 @@ +public class: RefasmerTestAssembly.PublicClassWithInternalInterfaceImpl +methods: +- RefasmerTestAssembly.IInterface2ToBeMarkedInternal.Foo(): RefasmerTestAssembly.Class3ToBeMarkedInternal: +- .ctor(): System.Void: +internal class: RefasmerTestAssembly.Class3ToBeMarkedInternal +public interface: RefasmerTestAssembly.IInterface2ToBeMarkedInternal`1 +methods: +- Foo(): T: + - diff --git a/tests/RefasmerTestAssembly/InternalClassInApi.cs b/tests/RefasmerTestAssembly/InternalClassInApi.cs index ee17961..67e6d92 100644 --- a/tests/RefasmerTestAssembly/InternalClassInApi.cs +++ b/tests/RefasmerTestAssembly/InternalClassInApi.cs @@ -1,9 +1,16 @@ +using System; + namespace RefasmerTestAssembly; // Post-processed and converted to internal by tests: public class Class1ToBeMarkedInternal; public class Class2ToBeMarkedInternal; -public class InterfaceToBeMarkedInternal; +public class Class3ToBeMarkedInternal; +public interface IInterface1ToBeMarkedInternal; +public interface IInterface2ToBeMarkedInternal +{ + T Foo(); +} public class PublicClassWithInternalTypeInApi { @@ -11,4 +18,9 @@ public void Accept(Class1ToBeMarkedInternal argument) {} } public class PublicClassDerivingFromInternal : Class2ToBeMarkedInternal; -public class PublicClassImplementingInternal : InterfaceToBeMarkedInternal; +public class PublicClassImplementingInternal : IInterface1ToBeMarkedInternal; + +public class PublicClassWithInternalInterfaceImpl : IInterface2ToBeMarkedInternal +{ + Class3ToBeMarkedInternal IInterface2ToBeMarkedInternal.Foo() => throw new Exception("123"); +} \ No newline at end of file