-
-
Notifications
You must be signed in to change notification settings - Fork 351
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
Allow to assign null AST childs after non-null #259
Conversation
cbed20e
to
73b21f7
Compare
Factory factory = build(Foo.class); | ||
CtClass<Object> fooClass = factory.Class().get(Foo.class); | ||
CtField<?> iField = fooClass.getField("i"); | ||
CtVariableAccess<?> iRead = |
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.
unused.
This feature seems necessary. We shouldn't have a NPE when we set a target with null. But my first reaction was that it is awful to check everywhere if the parameter is null. After reflection, if we want to keep the setters of parents and/or target on the AST, we don't have any choices. So, I'm ok with this PR. |
cbed20e
to
14119a5
Compare
@GerardPaligot fixed |
@@ -46,7 +46,8 @@ public void accept(CtVisitor visitor) { | |||
} | |||
|
|||
public void setExpression(CtExpression<T> value) { | |||
value.setParent(this); | |||
if (value != null) | |||
value.setParent(this); |
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.
An expression of an assertion can be null? For me, an assertion must have an expression so I propose to change for something like:
public void setExpression(CtExpression<T> value) {
if (value == null) {
throw new SpoonException("An assertion must have an expression.");
}
value.setParent(this);
this.value = value;
}
What do you think?
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.
There is an "assertionExpression" and just "expression". Null expression corresponds to the statement assert assertionExpression;
. Or it might be assert assertionExpression : expression;
For now, you have only one test in your PR to test a target null but there aren't tests for other checks. It could be interesting to add new tests for all others cases. We know now why we add these check but not necessarily in a few years. So, can you add tests? |
Ok |
3f36d37
to
447dd5d
Compare
@GerardPaligot please look why CI build is failing. I don't understand. Locally it is ok. |
21d4aec
to
d2f2701
Compare
See #249