Commit 1a086ff
authored
[Java.Interop.Tools.JavaCallableWrappers] Fix IsValidIdentifier() (#610)
Context: dotnet/android#4431
Commit e7c5f54 added `IdentifierValidator.IsValidIdentifier()`,
replacing use of `CSharpCodeProvider.IsValidIdentifier()`, and this
change caused a unit test failure within xamarin-android:
// Xamarin.Android.Build.Tests.BuildTest.GeneratorValidateEventName
obj/Debug/generated/src/Com.Xamarin.Testing.Test.cs(350,29,350,32): error CS1001: Identifier expected
The line in question?
public event EventHandler 123 {
Oops.
It Turns Out™ that `IdentifierValidator.IsValidIdentifier("123")`
returned True, so we attempted to create an event named `123`, which
the C# compiler Does Not Like.
Fix `IdentifierValidator.IsValidIdentifier()` by using a new
`IsValidIdentifierRegex` regex to match against identifiers, instead
of attempting to reuse the `validIdentifier` regex, which matches for
*invalid* characters (it negates the match via `[^...]`), and thus
cannot differentiate between "starting" characters and everything
else, which is fine for `IdentifierValidator.CreateValidIdentifier()`,
but not for `IdentifierValidator.IsValidIdentifier()`.
Add unit tests for `IdentifierValidator.IsValidIdentifier()`.
Update `make run-test-generator-core` tests so that we add a
`View.setOn123Listener()` method, which prior to this commit would add
a `View.123` event:
partial class View {
public event EventHandler 123 {
add { … }
remove { … }
}
}
With a corrected `IdentifierValidator.IsValidIdentifier()`, this event
is no longer generated.1 parent f7ea4ed commit 1a086ff
File tree
5 files changed
+86
-1
lines changed- src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers
- tests
- Java.Interop.Tools.JavaCallableWrappers-Tests/Java.Interop.Tools.JavaCallableWrappers
- generator-Tests/Tests-Core
- expected.ji
- expected
5 files changed
+86
-1
lines changedLines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
46 | | - | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| |||
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
27 | 40 | | |
28 | 41 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
9 | 13 | | |
10 | 14 | | |
11 | 15 | | |
| |||
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
182 | 212 | | |
183 | 213 | | |
184 | 214 | | |
| |||
Lines changed: 36 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
175 | 211 | | |
176 | 212 | | |
177 | 213 | | |
| |||
0 commit comments