Break field initialization region into multiple regions
Version: 0.10.1.
Currently any error or fix object instantiated while visiting a node in the field initialization region, the enclosing method is "null" as they are not enclosed by any method. However, we can generalize the concept of method to member and consider the enclosing member instead. Below, the equivalent for enclosing member is described:
The enclosing member for fix or error is:
- If it is triggered inside a method, the enclosing member will be the enclosing method.
- If it is enclosed by a field declaration statement, the enclosing member will be the declared field.
- If none of the above, the enclosing member will be
"null"(used for static initialization region).
With the current approach the following errors will have the values below:
class C {
Field foo1 = Field(null); // Passing nullable, enclMethod = "null"
Field foo2 = null; // assigning nullable, enclMethod = "null"
static Field foo3 3 = null; // assigning nullable, enclMethod = "null"
{
foo3 = null; // assigning nullable, enclMethod = "null"
}
void bar(){
this.foo1 = null; // assigning nullable, enclMethod = "bar()"
}
}
From the point of view of Annotator, that is 4 conflicts in regions as they all have enclMethod = "null".
This can be greatly improved with the new approach suggested and changed to below:
class C {
Field foo1 = Field(null); // Passing nullable, enclMember = "foo1"
Field foo2 = null; // assigning nullable, enclMember = "foo2"
static Field foo3 = null; // assigning nullable, enclMember = "foo3"
{
Field3 = null; // assigning nullable, enclMember = "null"
}
void bar(){
this.foo1 = null; // assigning nullable, enclMember = "bar()"
}
}
None of the error reported above have any conflicts and can be allocated to separate regions.