-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[XAT.Bytecode] Add support for reading NotNull metadata into api.xml.
- Loading branch information
Showing
11 changed files
with
276 additions
and
17 deletions.
There are no files selected for viewing
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
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
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
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
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
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
68 changes: 68 additions & 0 deletions
68
tests/Xamarin.Android.Tools.Bytecode-Tests/NullableAnnotationTests.cs
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,68 @@ | ||
using System; | ||
|
||
using Xamarin.Android.Tools.Bytecode; | ||
|
||
using NUnit.Framework; | ||
using System.Linq; | ||
|
||
namespace Xamarin.Android.Tools.BytecodeTests | ||
{ | ||
[TestFixture] | ||
public class NullableAnnotationTests : ClassFileFixture | ||
{ | ||
[Test] | ||
public void RuntimeInvisibleAnnotations () | ||
{ | ||
var c = LoadClassFile ("NotNullClass.class"); | ||
|
||
// Method with no annotations | ||
var null_method = c.Methods.First (m => m.Name == "nullFunc"); | ||
|
||
Assert.AreEqual (0, null_method.Attributes.OfType<RuntimeInvisibleAnnotationsAttribute> ().Count ()); | ||
Assert.AreEqual (0, null_method.Attributes.OfType<RuntimeInvisibleParameterAnnotationsAttribute> ().Count ()); | ||
|
||
// Method with not-null parameter and return value annotations | ||
var notnull_method = c.Methods.First (m => m.Name == "notNullFunc"); | ||
var return_ann = notnull_method.Attributes.OfType<RuntimeInvisibleAnnotationsAttribute> ().FirstOrDefault ()?.Annotations; | ||
var param_ann = notnull_method.Attributes.OfType<RuntimeInvisibleParameterAnnotationsAttribute> ().FirstOrDefault ()?.Annotations; | ||
|
||
Assert.NotNull (return_ann); | ||
Assert.IsTrue (return_ann.Any (a => a.Type == "Landroid/annotation/NonNull;")); | ||
|
||
Assert.NotNull (param_ann); | ||
Assert.IsTrue (param_ann.Any (a => a.ParameterIndex == 0 && a.Annotations[0].Type == "Landroid/annotation/NonNull;")); | ||
|
||
// Field with no annotations | ||
var null_field = c.Fields.First (f => f.Name == "nullField"); | ||
|
||
Assert.AreEqual (0, null_field.Attributes.OfType<RuntimeInvisibleAnnotationsAttribute> ().Count ()); | ||
Assert.AreEqual (0, null_field.Attributes.OfType<RuntimeInvisibleParameterAnnotationsAttribute> ().Count ()); | ||
|
||
// Field with not-null annotation | ||
var notnull_field = c.Fields.First (f => f.Name == "notNullField"); | ||
|
||
var field_ann = notnull_method.Attributes.OfType<RuntimeInvisibleAnnotationsAttribute> ().FirstOrDefault ()?.Annotations; | ||
|
||
Assert.NotNull (field_ann); | ||
Assert.IsTrue (field_ann.Any (a => a.Type == "Landroid/annotation/NonNull;")); | ||
} | ||
|
||
[Test] | ||
public void NullableAnnotationOutput () | ||
{ | ||
var c = LoadClassFile ("NotNullClass.class"); | ||
var builder = new XmlClassDeclarationBuilder (c); | ||
var xml = builder.ToXElement (); | ||
|
||
var method = xml.Elements ("method").First (m => m.Attribute ("name").Value == "notNullFunc"); | ||
Assert.AreEqual ("true", method.Attribute ("return-not-null").Value); | ||
|
||
var parameter = method.Element ("parameter"); | ||
Assert.AreEqual ("true", parameter.Attribute ("not-null").Value); | ||
|
||
var field = xml.Elements ("field").First (f => f.Attribute ("name").Value == "notNullField"); | ||
Assert.AreEqual ("true", field.Attribute ("not-null").Value); | ||
} | ||
} | ||
} | ||
|
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
7 changes: 7 additions & 0 deletions
7
tests/Xamarin.Android.Tools.Bytecode-Tests/java/android/annotation/NonNull.java
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,7 @@ | ||
package android.annotation; | ||
|
||
import java.lang.annotation.*; | ||
import java.lang.reflect.*; | ||
|
||
public @interface NonNull { | ||
} |
Oops, something went wrong.