-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Introduce "Explicit" mode * Duplicate and adapt tests for explicit mode * Support inheritance and external annotations.
- Loading branch information
1 parent
b6f36ea
commit 25af7e5
Showing
103 changed files
with
6,852 additions
and
33 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
AssemblyToProcessExplicit/AssemblyToProcessExplicit.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net452</TargetFramework> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<Optimize>true</Optimize> | ||
<DebugType>full</DebugType> | ||
<DebugSymbols>true</DebugSymbols> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<DefineConstants>TRACE;DEBUG;JETBRAINS_ANNOTATIONS</DefineConstants> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<DefineConstants>TRACE;JETBRAINS_ANNOTATIONS</DefineConstants> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="JetBrains.Annotations" Version="11.1.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\AssemblyWithAnnotations\AssemblyWithAnnotations.csproj" /> | ||
<ProjectReference Include="..\AssemblyWithExternalAnnotations\AssemblyWithExternalAnnotations.csproj" /> | ||
<ProjectReference Include="..\ReferenceAssembly\ReferenceAssembly.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,281 @@ | ||
using JetBrains.Annotations; | ||
|
||
using NullGuard; | ||
|
||
public abstract class BaseClassWithAttributes | ||
{ | ||
public abstract void MethodWithNotNullParameter(string canBeNull, [NotNull] string arg); | ||
|
||
[NotNull] | ||
public abstract string MethodWithNotNullReturnValue(string arg); | ||
|
||
[NotNull] | ||
public abstract string NotNullProperty { get; set; } | ||
} | ||
|
||
public interface BaseInterfaceWithAttributes | ||
{ | ||
void MethodWithNotNullParameter(string canBeNull, [NotNull] string arg); | ||
|
||
[NotNull] | ||
string MethodWithNotNullReturnValue(string arg); | ||
|
||
[NotNull] | ||
string NotNullProperty { get; set; } | ||
} | ||
|
||
public interface InheritedInterface : BaseInterfaceWithAttributes | ||
{ | ||
|
||
} | ||
|
||
public interface InterfaceWithAttributes | ||
{ | ||
void MethodWithNotNullParameter(string canBeNull, [NotNull] string arg); | ||
|
||
[NotNull] | ||
string MethodWithNotNullReturnValue(string arg); | ||
|
||
[NotNull] | ||
string NotNullProperty { get; set; } | ||
} | ||
|
||
namespace InternalBase | ||
{ | ||
public class DerivedClass : BaseClassWithAttributes | ||
{ | ||
public override void MethodWithNotNullParameter(string canBeNull, string arg) | ||
{ | ||
} | ||
|
||
public override string MethodWithNotNullReturnValue(string arg) | ||
{ | ||
return arg; | ||
} | ||
|
||
public override string NotNullProperty { get; set; } | ||
} | ||
|
||
public class ImplementsInterface : InterfaceWithAttributes | ||
{ | ||
public void MethodWithNotNullParameter(string canBeNull, string arg) | ||
{ | ||
} | ||
|
||
public string MethodWithNotNullReturnValue(string arg) | ||
{ | ||
return arg; | ||
} | ||
|
||
public string NotNullProperty { get; set; } | ||
} | ||
|
||
public class ImplementsInheritedInterface : InheritedInterface | ||
{ | ||
public void MethodWithNotNullParameter(string canBeNull, string arg) | ||
{ | ||
} | ||
|
||
public string MethodWithNotNullReturnValue(string arg) | ||
{ | ||
return arg; | ||
} | ||
|
||
public string NotNullProperty { get; set; } | ||
} | ||
|
||
[NullGuard(ValidationFlags.All)] // TODO: need this due to https://github.com/Fody/NullGuard/issues/37 https://github.com/Fody/NullGuard/issues/60, remove after fix of #60 | ||
public class ImplementsInterfaceExplicit : InterfaceWithAttributes | ||
{ | ||
public void MethodWithNotNullParameter(string canBeNull, string arg) | ||
{ | ||
((InterfaceWithAttributes)this).MethodWithNotNullParameter(canBeNull, arg); | ||
} | ||
|
||
public string MethodWithNotNullReturnValue(string arg) | ||
{ | ||
return ((InterfaceWithAttributes)this).MethodWithNotNullReturnValue(arg); | ||
} | ||
|
||
public string NotNullProperty | ||
{ | ||
get => ((InterfaceWithAttributes)this).NotNullProperty; | ||
set => ((InterfaceWithAttributes)this).NotNullProperty = value; | ||
} | ||
|
||
void InterfaceWithAttributes.MethodWithNotNullParameter(string canBeNull, string arg) | ||
{ | ||
} | ||
|
||
string InterfaceWithAttributes.MethodWithNotNullReturnValue(string arg) | ||
{ | ||
return arg; | ||
} | ||
|
||
string InterfaceWithAttributes.NotNullProperty | ||
{ | ||
get; | ||
set; | ||
} | ||
} | ||
} | ||
|
||
namespace AssemblyBase | ||
{ | ||
public class DerivedClass : AssemblyWithAnnotations.BaseClassWithAttributes | ||
{ | ||
public override void MethodWithNotNullParameter(string canBeNull, string arg) | ||
{ | ||
} | ||
|
||
public override string MethodWithNotNullReturnValue(string arg) | ||
{ | ||
return arg; | ||
} | ||
|
||
public override string NotNullProperty { get; set; } | ||
} | ||
|
||
public class ImplementsInterface : AssemblyWithAnnotations.InterfaceWithAttributes | ||
{ | ||
public void MethodWithNotNullParameter(string canBeNull, string arg) | ||
{ | ||
} | ||
|
||
public string MethodWithNotNullReturnValue(string arg) | ||
{ | ||
return arg; | ||
} | ||
|
||
public string NotNullProperty { get; set; } | ||
} | ||
|
||
public class ImplementsInheritedInterface : AssemblyWithAnnotations.InheritedInterface | ||
{ | ||
public void MethodWithNotNullParameter(string canBeNull, string arg) | ||
{ | ||
} | ||
|
||
public string MethodWithNotNullReturnValue(string arg) | ||
{ | ||
return arg; | ||
} | ||
|
||
public string NotNullProperty { get; set; } | ||
} | ||
|
||
[NullGuard(ValidationFlags.All)] // TODO: need this due to https://github.com/Fody/NullGuard/issues/37 https://github.com/Fody/NullGuard/issues/60, remove after fix of #60 | ||
public class ImplementsInterfaceExplicit : AssemblyWithAnnotations.InterfaceWithAttributes | ||
{ | ||
public void MethodWithNotNullParameter(string canBeNull, string arg) | ||
{ | ||
((AssemblyWithAnnotations.InterfaceWithAttributes)this).MethodWithNotNullParameter(canBeNull, arg); | ||
} | ||
|
||
public string MethodWithNotNullReturnValue(string arg) | ||
{ | ||
return ((AssemblyWithAnnotations.InterfaceWithAttributes)this).MethodWithNotNullReturnValue(arg); | ||
} | ||
|
||
public string NotNullProperty | ||
{ | ||
get => ((AssemblyWithAnnotations.InterfaceWithAttributes)this).NotNullProperty; | ||
set => ((AssemblyWithAnnotations.InterfaceWithAttributes)this).NotNullProperty = value; | ||
} | ||
|
||
void AssemblyWithAnnotations.InterfaceWithAttributes.MethodWithNotNullParameter(string canBeNull, string arg) | ||
{ | ||
} | ||
|
||
string AssemblyWithAnnotations.InterfaceWithAttributes.MethodWithNotNullReturnValue(string arg) | ||
{ | ||
return arg; | ||
} | ||
|
||
string AssemblyWithAnnotations.InterfaceWithAttributes.NotNullProperty | ||
{ | ||
get; | ||
set; | ||
} | ||
} | ||
} | ||
|
||
namespace ExternalBase | ||
{ | ||
public class DerivedClass : AssemblyWithExternalAnnotations.BaseClassWithAttributes | ||
{ | ||
public override void MethodWithNotNullParameter(string canBeNull, string arg) | ||
{ | ||
} | ||
|
||
public override string MethodWithNotNullReturnValue(string arg) | ||
{ | ||
return arg; | ||
} | ||
|
||
public override string NotNullProperty { get; set; } | ||
} | ||
|
||
public class ImplementsInterface : AssemblyWithExternalAnnotations.InterfaceWithAttributes | ||
{ | ||
public void MethodWithNotNullParameter(string canBeNull, string arg) | ||
{ | ||
} | ||
|
||
public string MethodWithNotNullReturnValue(string arg) | ||
{ | ||
return arg; | ||
} | ||
|
||
public string NotNullProperty { get; set; } | ||
} | ||
|
||
public class ImplementsInheritedInterface : AssemblyWithExternalAnnotations.InheritedInterface | ||
{ | ||
public void MethodWithNotNullParameter(string canBeNull, string arg) | ||
{ | ||
} | ||
|
||
public string MethodWithNotNullReturnValue(string arg) | ||
{ | ||
return arg; | ||
} | ||
|
||
public string NotNullProperty { get; set; } | ||
} | ||
|
||
[NullGuard(ValidationFlags.All)] // TODO: need this due to https://github.com/Fody/NullGuard/issues/37 https://github.com/Fody/NullGuard/issues/60, remove after fix of #60 | ||
public class ImplementsInterfaceExplicit : AssemblyWithExternalAnnotations.InterfaceWithAttributes | ||
{ | ||
public void MethodWithNotNullParameter(string canBeNull, string arg) | ||
{ | ||
((AssemblyWithExternalAnnotations.InterfaceWithAttributes)this).MethodWithNotNullParameter(canBeNull, arg); | ||
} | ||
|
||
public string MethodWithNotNullReturnValue(string arg) | ||
{ | ||
return ((AssemblyWithExternalAnnotations.InterfaceWithAttributes)this).MethodWithNotNullReturnValue(arg); | ||
} | ||
|
||
public string NotNullProperty | ||
{ | ||
get => ((AssemblyWithExternalAnnotations.InterfaceWithAttributes)this).NotNullProperty; | ||
set => ((AssemblyWithExternalAnnotations.InterfaceWithAttributes)this).NotNullProperty = value; | ||
} | ||
|
||
void AssemblyWithExternalAnnotations.InterfaceWithAttributes.MethodWithNotNullParameter(string canBeNull, string arg) | ||
{ | ||
} | ||
|
||
string AssemblyWithExternalAnnotations.InterfaceWithAttributes.MethodWithNotNullReturnValue(string arg) | ||
{ | ||
return arg; | ||
} | ||
|
||
string AssemblyWithExternalAnnotations.InterfaceWithAttributes.NotNullProperty | ||
{ | ||
get; | ||
set; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using JetBrains.Annotations; | ||
|
||
public class ClassToExclude | ||
{ | ||
// ReSharper disable once UnusedParameter.Local | ||
public ClassToExclude([NotNull] string test) | ||
{ | ||
} | ||
|
||
[NotNull] | ||
public string Test([NotNull] string text) | ||
{ | ||
return text; | ||
} | ||
|
||
[NotNull] | ||
public string Property { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using NullGuard; | ||
|
||
public abstract class ClassWithBadAttributes | ||
{ | ||
public abstract void MethodWithNoNullCheckOnParam([AllowNull] string arg); | ||
public abstract string PropertyWithNoNullCheckOnSet { get; [param: AllowNull] set; } | ||
public abstract string PropertyAllowsNullGetButDoesNotAllowNullSet { [return: AllowNull] get; set; } | ||
|
||
[return: AllowNull] | ||
public abstract string MethodAllowsNullReturnValue(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
using JetBrains.Annotations; | ||
|
||
public class ClassWithExplicitInterface : IComparable<string> | ||
{ | ||
int IComparable<string>.CompareTo([NotNull] string other) | ||
{ | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using JetBrains.Annotations; | ||
|
||
using NullGuard; | ||
|
||
[NullGuard(ValidationFlags.NonPublic | ValidationFlags.Arguments)] | ||
public class ClassWithPrivateMethod | ||
{ | ||
public void PublicWrapperOfPrivateMethod() | ||
{ | ||
SomePrivateMethod(null); | ||
} | ||
|
||
// ReSharper disable UnusedParameter.Local | ||
void SomePrivateMethod([NotNull] string x) | ||
// ReSharper restore UnusedParameter.Local | ||
{ | ||
} | ||
|
||
[NotNull] | ||
public string SomeProperty { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public class GenericClass<T> { | ||
[JetBrains.Annotations.NotNull] | ||
public T NonNullProperty { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace Windows.UI.Xaml.Markup | ||
{ | ||
public interface IXamlMetadataProvider{} | ||
} |
Oops, something went wrong.