Skip to content
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

Merged
merged 1 commit into from
Jun 24, 2015

Conversation

leventov
Copy link
Contributor

See #249

@leventov leventov force-pushed the master branch 2 times, most recently from cbed20e to 73b21f7 Compare June 15, 2015 16:03
Factory factory = build(Foo.class);
CtClass<Object> fooClass = factory.Class().get(Foo.class);
CtField<?> iField = fooClass.getField("i");
CtVariableAccess<?> iRead =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused.

@GerardPaligot
Copy link
Contributor

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.

@leventov leventov force-pushed the master branch 2 times, most recently from cbed20e to 14119a5 Compare June 17, 2015 13:31
@leventov
Copy link
Contributor Author

@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);
Copy link
Contributor

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?

Copy link
Contributor Author

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;

@GerardPaligot
Copy link
Contributor

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?

@leventov
Copy link
Contributor Author

Ok

@leventov leventov force-pushed the master branch 2 times, most recently from 3f36d37 to 447dd5d Compare June 19, 2015 18:32
@leventov
Copy link
Contributor Author

@GerardPaligot please look why CI build is failing. I don't understand. Locally it is ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants