Skip to content

Commit

Permalink
Explicit mode (#88)
Browse files Browse the repository at this point in the history
* Introduce "Explicit" mode
* Duplicate and adapt tests for explicit mode
* Support inheritance and external annotations.
  • Loading branch information
tom-englert authored Nov 10, 2017
1 parent b6f36ea commit 25af7e5
Show file tree
Hide file tree
Showing 103 changed files with 6,852 additions and 33 deletions.
23 changes: 23 additions & 0 deletions AssemblyToProcessExplicit/AssemblyToProcessExplicit.csproj
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>
281 changes: 281 additions & 0 deletions AssemblyToProcessExplicit/BaseClassWithAttributes.cs
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;
}
}
}
18 changes: 18 additions & 0 deletions AssemblyToProcessExplicit/ClassToExclude.cs
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; }
}
11 changes: 11 additions & 0 deletions AssemblyToProcessExplicit/ClassWithBadAttributes.cs
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();
}
11 changes: 11 additions & 0 deletions AssemblyToProcessExplicit/ClassWithExplicitInterface.cs
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;
}
}
21 changes: 21 additions & 0 deletions AssemblyToProcessExplicit/ClassWithPrivateMethod.cs
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; }
}
4 changes: 4 additions & 0 deletions AssemblyToProcessExplicit/GenericClass.cs
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; }
}
4 changes: 4 additions & 0 deletions AssemblyToProcessExplicit/IXamlMetadataProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Windows.UI.Xaml.Markup
{
public interface IXamlMetadataProvider{}
}
Loading

0 comments on commit 25af7e5

Please sign in to comment.