Skip to content

Commit

Permalink
[Xamarin.Android.Tools.AndroidSdk] Nullable Reference Type support (#84)
Browse files Browse the repository at this point in the history
Annotate `Xamarin.Android.Tools.AndroidSdk.dll` to support C#8
[Nullable Reference Types][0]

Additionally, add Visual Studio Code support and fix the
Azure Pipelines build.

[0]: https://docs.microsoft.com/en-us/dotnet/csharp/nullable-references
  • Loading branch information
jonpryor authored Jun 2, 2020
1 parent 2020b20 commit 2d3690e
Show file tree
Hide file tree
Showing 25 changed files with 668 additions and 175 deletions.
199 changes: 199 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
###############################
# Core EditorConfig Options #
###############################

root = true

# All files
[*]
charset = utf-8
trim_trailing_whitespace = true

# MSBuild
[*.{csproj,proj,projitems,shproj,fsproj,targets,props}]
indent_style = space
indent_size = 2

# XML config files
[*.{xml,axml,xaml,config,nuspec,resx}]
indent_style = space
indent_size = 2

# JSON files
[*.json]
indent_style = space
indent_size = 2

# F# files
[*.{fs, fsx, fsi}]
indent_style = space
indent_size = 4

# Code files
[*.{cs,csx,vb,vbx}]
insert_final_newline = true
indent_style = tab
tab_width = 8
indent_size = 8
max_line_length = 180

###############################
# .NET Coding Conventions #
###############################

[*.{cs,vb}]
# Organize usings
dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = false

# Avoid "this." and "Me." if not necessary
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion

# Use language keywords instead of framework type names for type references
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion

# Suggest more modern language features when available
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion

# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent

# Avoid redundant accessibility modifiers when they're default
dotnet_style_require_accessibility_modifiers = omit_if_default:suggestion
dotnet_style_readonly_field = true:suggestion

# Expression-level preferences
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent

###############################
# Naming Conventions #
###############################

# Style Definitions
dotnet_naming_style.pascal_case_style.capitalization = pascal_case

dotnet_naming_style.underline_separator.word_separator = _
dotnet_naming_style.underline_separator.capitalization = all_lower

# Symbol Definitions
dotnet_naming_symbols.parameters.applicable_kinds = parameter
dotnet_naming_symbols.parameters.applicable_accessibilities = *

dotnet_naming_symbols.fields.applicable_kinds = field

dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
dotnet_naming_symbols.constant_fields.required_modifiers = const

# Use CamelCase for parameters
dotnet_naming_rule.method_parameters_should_be_camel_case.severity = suggestion
dotnet_naming_rule.method_parameters_should_be_camel_case.symbols = parameters
dotnet_naming_rule.method_parameters_should_be_camel_case.style = camel_case

# Use PascalCase for constant fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style

# Use underline separator for instance fields
dotnet_naming_rule.fields_should_be_underline_separator.severity = suggestion
dotnet_naming_rule.fields_should_be_underline_separator.symbols = fields
dotnet_naming_rule.fields_should_be_underline_separator.style = underline_separator


###############################
# C# Code Style Rules #
###############################

[*.cs]
# var preferences
csharp_style_var_for_built_in_types = true:silent
csharp_style_var_when_type_is_apparent = true:silent
csharp_style_var_elsewhere = true:silent

# Expression-bodied members
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent

# Pattern-matching preferences
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion

# Null-checking preferences
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion

# Modifier preferences
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion

# Expression-level preferences
csharp_prefer_braces = true:silent
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_pattern_local_over_anonymous_function = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion

###############################
# C# Formatting Rules #
###############################

# Newline settings
csharp_new_line_before_open_brace = methods,types
csharp_new_line_before_else = false
csharp_new_line_before_catch = false
csharp_new_line_before_finally = false
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true

# Indentation preferences
csharp_indent_switch_labels = false
csharp_indent_case_contents = true
csharp_indent_switch_labels = true

# Space preferences
csharp_space_after_cast = true
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_around_binary_operators = before_and_after
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = true
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = true
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_before_open_square_brackets = true

# Wrapping preferences
csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true

##################################
# Visual Basic Code Style Rules #
##################################

[*.vb]
# Modifier preferences
visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async:suggestion
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"ms-vscode.csharp",
"ms-vscode.mono-debug",
"wghats.vscode-nxunit-test-adapter",
"visualstudioexptteam.vscodeintellicode",
]
}
22 changes: 22 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "mono",
"request": "launch",
"program": "${workspaceRoot}/packages/NUnit.ConsoleRunner.3.9.0/tools/nunit3-console.exe ${workspaceRoot}/bin/TestDebug/generator-Tests.dll",
"cwd": "${workspaceRoot}bin/TestDebug/"
},
{
"name": "Attach",
"type": "mono",
"request": "attach",
"address": "localhost",
"port": 55555
}
]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"nxunitExplorer.nunit": "packages/NUnit.ConsoleRunner.3.9.0/tools/nunit3-console.exe",
"nxunitExplorer.modules": [
"bin/TestDebug/Xamarin.Android.Tools.AndroidSdk-Tests.dll"
]
}
43 changes: 43 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build Xamarin.Android.Tools",
"type": "shell",
"command": "msbuild Xamarin.Android.Tools.sln /restore",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$msCompile"
]
},
{
"label": "Clean Xamarin.Android.Tools",
"type": "shell",
"command": "msbuild Xamarin.Android.Tools.sln /restore /t:Clean",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$msCompile"
]
},
{
"label": "Run Unit Tests",
"type": "shell",
"command": "make run-all-tests",
"group": {
"kind": "test",
"isDefault": true
},
"problemMatcher": [
"$msCompile"
]
}
]
}
25 changes: 25 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Note: MUST be imported *after* $(Configuration) is set! -->
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
</PropertyGroup>
<PropertyGroup>
<BaseIntermediateOutputPath Condition=" '$(BaseIntermediateOutputPath)' == '' ">obj\</BaseIntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' != '' And $(TargetFramework.StartsWith ('netcoreapp')) ">
<XATBuildingForNetCoreApp>True</XATBuildingForNetCoreApp>
</PropertyGroup>
<PropertyGroup Condition=" '$(XATBuildingForNetCoreApp)' == 'True' ">
<IntermediateOutputPath>$(BaseIntermediateOutputPath)\$(Configuration)-$(TargetFramework.ToLowerInvariant())</IntermediateOutputPath>
<BuildToolOutputFullPath>$(MSBuildThisFileDirectory)bin\Build$(Configuration)\$(TargetFramework.ToLowerInvariant())\</BuildToolOutputFullPath>
<ToolOutputFullPath>$(MSBuildThisFileDirectory)bin\$(Configuration)\$(TargetFramework.ToLowerInvariant())\</ToolOutputFullPath>
<TestOutputFullPath>$(MSBuildThisFileDirectory)bin\Test$(Configuration)-$(TargetFramework.ToLowerInvariant())\</TestOutputFullPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(XATBuildingForNetCoreApp)' != 'True' ">
<IntermediateOutputPath>$(BaseIntermediateOutputPath)\$(Configuration)</IntermediateOutputPath>
<BuildToolOutputFullPath>$(MSBuildThisFileDirectory)bin\Build$(Configuration)\</BuildToolOutputFullPath>
<ToolOutputFullPath>$(MSBuildThisFileDirectory)bin\$(Configuration)\</ToolOutputFullPath>
<TestOutputFullPath>$(MSBuildThisFileDirectory)bin\Test$(Configuration)\</TestOutputFullPath>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ V ?= 0
include build-tools/scripts/msbuild.mk

all:
$(MSBUILD) $(MSBUILD_FLAGS) Xamarin.Android.Tools.sln
$(MSBUILD) /restore $(MSBUILD_FLAGS) Xamarin.Android.Tools.sln

clean:
-$(MSBUILD) $(MSBUILD_FLAGS) /t:Clean Xamarin.Android.Tools.sln
Expand Down
11 changes: 11 additions & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Our testing infrastructure depends on a known location for:
- NUnit.Console
- csc.exe
-->
<configuration>
<config>
<add key="globalPackagesFolder" value="$\..\packages" />
</config>
</configuration>
4 changes: 4 additions & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Our testing infrastructure depends on a known location for:
- nunit3-console.exe
-->
<configuration>
<packageSources>
<clear />
Expand Down
9 changes: 9 additions & 0 deletions Xamarin.Android.Tools.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"folders": [
{
"path": "."
}
],
"settings": {
}
}
Loading

0 comments on commit 2d3690e

Please sign in to comment.