-
-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
review: feature: SourcePosition#isValidPosition(), throw exception when accessing invalid position #1964
Conversation
5499b65
to
5be54bc
Compare
Returning null is a bad and dangerous practice. I would prefer not to go in this direction.
That's good!
What would be the difference with |
Sidenote: when it is no backward-compatible, please avoid prefixing the PR with |
What do you suggest? Note that existing approach with NoSourcePosition and PartialSourcePosition has some problem - see problems discussed in #1963 |
I do not understand, the question. But let's discuss first the alternative for getPosition returns null. It is the main point of this PR, so any change here will completely change whole solution ;-) |
nobody really knows how to correctly ask whether value returned by With this PR it is clear But what is correct without this PR??? |
What you proposed sounds good to me
One method, clear responsibility, encapsulates implementation detail, no null value |
I have two questions, before I can change this PR:
I prefer |
|
Thanks Thomas for your opinion, I agree with you. |
agree with @tdurieux. |
7ea6fcf
to
e23b9de
Compare
d0e231c
to
606d132
Compare
@@ -269,6 +273,16 @@ public void setAutoImport(boolean autoImport) { | |||
this.autoImport = autoImport; | |||
} | |||
|
|||
private PartialSourcePositionImpl myPartialSourcePosition; | |||
/** | |||
* @return a {@link Source} which points to this {@link CompilationUnit}. It always returns same value to safe memory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the path to Source is not found during the javadoc generation
Looking forward to it, it should fix the regression identified in Casper: https://travis-ci.org/Spirals-Team/casper/builds/367789415 |
So we are three in this cinema ... looking at yellow circle ... and waiting for happy end :-)) |
API changes: 1 (Detected by Revapi) Old API: fr.inria.gforge.spoon:spoon-core:jar:6.3.0-20180417.183645-43 / New API: fr.inria.gforge.spoon:spoon-core:jar:6.3.0-SNAPSHOT
|
thanks for the comprehensive refactoring |
I confirm that the regression has been fixed |
This is alternative to #1963
Source
SourcePosition extends Source
CtElement#getPosition()
returns null if source position is not known. It is DerivedProperty now.CtElement#getSource()
andsetSource(Source)
CtElement#getCompilationUnit()
which return not null even for cases when NoSourcePosition was used before.SourceImpl
(before each had own instance ofPartialSourcePositionImpl
) - less memory neededNoSourcePosition
andPartialSourcePosition
.It is not backward compatible for the code which expected NoSourcePosition or asked getSourceStart() >= 0, ... , but:
PartialSourcePosition
, ...WDYT?