-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor ReferenceType #237
Comments
@ftomassetti - how would you suggest to refactor this? Is this what's in the patch @ptitjes did somewhere else that we cannot see without breaking the law? ;) |
@matozoid Well, I think having respect for someone's beliefs (and work) should not be felt by anyone sane as adhering to the law... |
It's about licenses - that's the law. Also, smiley :) |
Calling mr. @ftomassetti! Mr. @ftomassetti are you there? |
Yes, but it is less than a year that I am thinking about this subject. It is better to not rush this thing too much :) I think that we should move arrayCount out of ReferenceType to ArrayType Now, if I am correct, ReferenceType specifies:
About the last point:
(see http://docs.oracle.com/javase/specs/jls/se8/html/jls-4.html#jls-4.3) Currently we have this field:
So that for example for:
To me it seems that this class is doing too much. If we instead move the array decoration to a different class it would means that the annotations associated to that array dimension could stay in that other class, which is a much simpler solution of what we have now. For the same example we would have a class ArrayType containing just its own annotations (c and d). It would wrap another ArrayType with the annotations b and it would wrap the ReferenceType that at this point would care just about the annotation a. |
Now that's a description :) It looks a lot like the suggestion in #112 - is that correct? |
Yes, it is definitely similar. I just do not know if ArrayType should extend ReferenceType and if ArrayType should wrap a Type or just a ReferenceType (probably yes, I just do not have enough coffee in me to confirm this). |
Also you should take care about the order of the array dimensions w.r.t. to their annotations. It seems to me that the wrapping you describe in your example is incorrect. See JLS8 section 9.7.4. |
I looked up all places where the grammar has the [ character and reverse engineered what's being produced there:
Is all of this correct? |
Or should that be... |
Okay, that is step one. |
I think this should be solved in a fundamentally different way. The main issue is that in Therefore I propose to...
(array creation is a fundamentally different construct and not part of this.) Pro: this is the most consistent way to do this that I can think of. Therefore it is the easiest to explain. I can't explain |
This would affect...
|
"int arrayCount" is no longer the way to store information about arrays. It has been replaced by two things:
This gives us the following API:
Here is an overview: int[] a, b[], c;
- VariableDeclarationExpr
- Type elementType
- List<ArrayBracketPair> bracketsOnElement
- List<VariableDeclarator> vars
- Type getType() { makeArrayType(elementType, bracketsOnElement, bracketsOnId) }
- VariableDeclaratorId id
- List<ArrayBracketPair> bracketsOnId
class X {
int[] a, b[], c;
}
- FieldDeclaration
- Type elementType
- List<ArrayBracketPair> bracketsOnElement
- List<VariableDeclarator> variables
- Type getType() { makeArrayType(elementType, bracketsOnElement, bracketsOnId) }
- VariableDeclaratorId id
- List<ArrayBracketPair> bracketsOnId
class X {
int[] a()[] {
...
}
}
- MethodDeclaration
- Type elementType
- List<ArrayBracketPair> bracketsOnElement
- List<ArrayBracketPair> bracketsAfterParameters
- Type getType() { makeArrayType(elementType, bracketsOnElement, bracketsAfterParameters) }
void a(int[] b[]) {
...
}
- Parameter
- Type elementType
- List<ArrayBracketPair> bracketsOnElement
- VariableDeclaratorId id
- List<ArrayBracketPair> bracketsOnId
- Type getType() { makeArrayType(elementType, bracketsOnElement, bracketsOnId) } Also...
|
Refactor ReferenceType to do one thing (contains annotations) instead of two (containg annotations and array modifiers).
This is a follow-up of #187
The text was updated successfully, but these errors were encountered: