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

Always allow null parameter for setters. #694

Merged
merged 1 commit into from
Jun 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public <C extends CtExpression<T>> C setTypeCasts(List<CtTypeReference<?>> casts

@Override
public <C extends CtExpression<T>> C addTypeCast(CtTypeReference<?> type) {
if (type == null) {
return (C) this;
}
if (typeCasts == CtElementImpl.<CtTypeReference<?>>emptyList()) {
typeCasts = new ArrayList<CtTypeReference<?>>(CASTS_CONTAINER_DEFAULT_CAPACITY);
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/spoon/support/reflect/code/CtBlockImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ public <T extends CtBlock<R>> T insertEnd(CtStatementList statements) {
}

@Override
public <T extends CtBlock<R>> T insertAfter(Filter<? extends CtStatement> insertionPoints,
CtStatement statement) {
public <T extends CtBlock<R>> T insertAfter(Filter<? extends CtStatement> insertionPoints, CtStatement statement) {
for (CtStatement e : Query.getElements(this, insertionPoints)) {
e.insertAfter(statement);
}
Expand Down Expand Up @@ -178,6 +177,9 @@ public <T extends CtStatementList> T setStatements(List<CtStatement> statements)

@Override
public <T extends CtStatementList> T addStatement(CtStatement statement) {
if (statement == null) {
return (T) this;
}
ensureModifiableStatementsList();
statement.setParent(this);
this.statements.add(statement);
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/spoon/support/reflect/code/CtCaseImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public List<CtStatement> getStatements() {

@Override
public <T extends CtCase<E>> T setCaseExpression(CtExpression<E> caseExpression) {
caseExpression.setParent(this);
if (caseExpression != null) {
caseExpression.setParent(this);
}
this.caseExpression = caseExpression;
return (T) this;
}
Expand All @@ -69,6 +71,9 @@ public <T extends CtStatementList> T setStatements(List<CtStatement> statements)

@Override
public <T extends CtStatementList> T addStatement(CtStatement statement) {
if (statement == null) {
return (T) this;
}
if (statements == CtElementImpl.<CtStatement>emptyList()) {
statements = new ArrayList<CtStatement>(CASE_STATEMENTS_CONTAINER_DEFAULT_CAPACITY);
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/spoon/support/reflect/code/CtCatchImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@ public CtCatchVariable<? extends Throwable> getParameter() {

@Override
public <T extends CtCatch> T setBody(CtBlock<?> body) {
body.setParent(this);
if (body != null) {
body.setParent(this);
}
this.body = body;
return (T) this;
}

@Override
public <T extends CtCatch> T setParameter(CtCatchVariable<? extends Throwable> parameter) {
parameter.setParent(this);
if (parameter != null) {
parameter.setParent(this);
}
this.parameter = parameter;
return (T) this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public <C extends CtTypedElement> C setType(CtTypeReference<T> type) {

@Override
public <T extends CtMultiTypedElement> T addMultiType(CtTypeReference<?> ref) {
if (ref == null) {
return (T) this;
}
if (types == CtElementImpl.<CtTypeReference<?>>emptyList()) {
types = new ArrayList<CtTypeReference<?>>(
CATCH_VARIABLE_MULTI_TYPES_CONTAINER_DEFAULT_CAPACITY);
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/spoon/support/reflect/code/CtConditionalImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,27 @@ public CtExpression<T> getThenExpression() {

@Override
public <C extends CtConditional<T>> C setElseExpression(CtExpression<T> elseExpression) {
elseExpression.setParent(this);
if (elseExpression != null) {
elseExpression.setParent(this);
}
this.elseExpression = elseExpression;
return (C) this;
}

@Override
public <C extends CtConditional<T>> C setCondition(CtExpression<Boolean> condition) {
condition.setParent(this);
if (condition != null) {
condition.setParent(this);
}
this.condition = condition;
return (C) this;
}

@Override
public <C extends CtConditional<T>> C setThenExpression(CtExpression<T> thenExpression) {
thenExpression.setParent(this);
if (thenExpression != null) {
thenExpression.setParent(this);
}
this.thenExpression = thenExpression;
return (C) this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public <C extends CtAbstractInvocation<T>> C setArguments(List<CtExpression<?>>

@Override
public <C extends CtAbstractInvocation<T>> C addArgument(CtExpression<?> argument) {
if (argument == null) {
return (C) this;
}
if (arguments == CtElementImpl.<CtExpression<?>>emptyList()) {
arguments = new ArrayList<CtExpression<?>>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/spoon/support/reflect/code/CtDoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public CtExpression<Boolean> getLoopingExpression() {

@Override
public <T extends CtDo> T setLoopingExpression(CtExpression<Boolean> expression) {
expression.setParent(this);
if (expression != null) {
expression.setParent(this);
}
this.expression = expression;
return (T) this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public <C extends CtExpression<T>> C setTypeCasts(List<CtTypeReference<?>> casts

@Override
public <C extends CtExpression<T>> C addTypeCast(CtTypeReference<?> type) {
if (type == null) {
return (C) this;
}
if (typeCasts == CtElementImpl.<CtTypeReference<?>>emptyList()) {
typeCasts = new ArrayList<CtTypeReference<?>>(
CASTS_CONTAINER_DEFAULT_CAPACITY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
import spoon.reflect.code.CtExpression;
import spoon.reflect.code.CtFieldAccess;
import spoon.reflect.code.CtTargetedExpression;
import spoon.reflect.code.CtVariableAccess;
import spoon.reflect.reference.CtFieldReference;
import spoon.reflect.reference.CtTypeReference;
import spoon.reflect.reference.CtVariableReference;

public abstract class CtFieldAccessImpl<T> extends CtVariableReadImpl<T> implements CtFieldAccess<T> {
private static final long serialVersionUID = 1L;
Expand All @@ -49,11 +47,6 @@ public CtFieldReference<T> getVariable() {
return (CtFieldReference<T>) super.getVariable();
}

@Override
public <C extends CtVariableAccess<T>> C setVariable(CtVariableReference<T> variable) {
return super.setVariable(variable);
}

@Override
public CtTypeReference<T> getType() {
return getVariable() == null ? null : getVariable().getType();
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/spoon/support/reflect/code/CtForEachImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@ public CtLocalVariable<?> getVariable() {

@Override
public <T extends CtForEach> T setExpression(CtExpression<?> expression) {
expression.setParent(this);
if (expression != null) {
expression.setParent(this);
}
this.expression = expression;
return (T) this;
}

@Override
public <T extends CtForEach> T setVariable(CtLocalVariable<?> variable) {
variable.setParent(this);
if (variable != null) {
variable.setParent(this);
}
this.variable = variable;
return (T) this;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/spoon/support/reflect/code/CtForImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public List<CtStatement> getForInit() {

@Override
public <T extends CtFor> T addForInit(CtStatement statement) {
if (statement == null) {
return (T) this;
}
if (forInit == CtElementImpl.<CtStatement>emptyList()) {
forInit = new ArrayList<CtStatement>(FOR_INIT_STATEMENTS_CONTAINER_DEFAULT_CAPACITY);
}
Expand Down Expand Up @@ -92,6 +95,9 @@ public List<CtStatement> getForUpdate() {

@Override
public <T extends CtFor> T addForUpdate(CtStatement statement) {
if (statement == null) {
return (T) this;
}
if (forUpdate == CtElementImpl.<CtStatement>emptyList()) {
forUpdate = new ArrayList<CtStatement>(
FOR_UPDATE_STATEMENTS_CONTAINER_DEFAULT_CAPACITY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public List<CtExpression<?>> getArguments() {

@Override
public <C extends CtAbstractInvocation<T>> C addArgument(CtExpression<?> argument) {
if (argument == null) {
return (C) this;
}
if (arguments == CtElementImpl.<CtExpression<?>>emptyList()) {
arguments = new ArrayList<CtExpression<?>>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY);
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/spoon/support/reflect/code/CtLambdaImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ public <C extends CtExecutable<T>> C setParameters(List<CtParameter<?>> params)

@Override
public <C extends CtExecutable<T>> C addParameter(CtParameter<?> parameter) {
if (parameter == null) {
return (C) this;
}
if (parameters == CtElementImpl.<CtParameter<?>>emptyList()) {
parameters = new ArrayList<CtParameter<?>>(
PARAMETERS_CONTAINER_DEFAULT_CAPACITY);
Expand Down Expand Up @@ -130,6 +133,9 @@ public <C extends CtExecutable<T>> C setThrownTypes(Set<CtTypeReference<? extend

@Override
public <C extends CtExecutable<T>> C addThrownType(CtTypeReference<? extends Throwable> throwType) {
if (throwType == null) {
return (C) this;
}
if (thrownTypes == CtElementImpl.<CtTypeReference<? extends Throwable>>emptySet()) {
thrownTypes = new TreeSet<CtTypeReference<? extends Throwable>>();
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/spoon/support/reflect/code/CtNewArrayImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public <C extends CtNewArray<T>> C setDimensionExpressions(List<CtExpression<Int

@Override
public <C extends CtNewArray<T>> C addDimensionExpression(CtExpression<Integer> dimension) {
if (dimension == null) {
return (C) this;
}
if (dimensionExpressions == CtElementImpl.<CtExpression<Integer>>emptyList()) {
dimensionExpressions = new ArrayList<CtExpression<Integer>>(
NEW_ARRAY_DEFAULT_EXPRESSIONS_CONTAINER_DEFAULT_CAPACITY);
Expand Down Expand Up @@ -86,6 +89,9 @@ public <C extends CtNewArray<T>> C setElements(List<CtExpression<?>> expressions

@Override
public <C extends CtNewArray<T>> C addElement(CtExpression<?> expression) {
if (expression == null) {
return (C) this;
}
if (expressions == CtElementImpl.<CtExpression<?>>emptyList()) {
this.expressions = new ArrayList<CtExpression<?>>();
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/spoon/support/reflect/code/CtNewClassImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public CtClass<?> getAnonymousClass() {

@Override
public <N extends CtNewClass> N setAnonymousClass(CtClass<?> anonymousClass) {
anonymousClass.setParent(this);
if (anonymousClass != null) {
anonymousClass.setParent(this);
}
this.anonymousClass = anonymousClass;
return (N) this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public <T extends CtStatementList> T setStatements(List<CtStatement> stmts) {

@Override
public <T extends CtStatementList> T addStatement(CtStatement statement) {
if (statement == null) {
return (T) this;
}
if (this.statements == CtElementImpl.<CtStatement>emptyList()) {
this.statements = new ArrayList<CtStatement>(BLOCK_STATEMENTS_CONTAINER_DEFAULT_CAPACITY);
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/spoon/support/reflect/code/CtSwitchImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,18 @@ public <T extends CtSwitch<S>> T setCases(List<CtCase<? super S>> cases) {

@Override
public <T extends CtSwitch<S>> T setSelector(CtExpression<S> selector) {
selector.setParent(this);
if (selector != null) {
selector.setParent(this);
}
this.expression = selector;
return (T) this;
}

@Override
public <T extends CtSwitch<S>> T addCase(CtCase<? super S> c) {
if (c == null) {
return (T) this;
}
if (cases == CtElementImpl.<CtCase<? super S>>emptyList()) {
cases = new ArrayList<CtCase<? super S>>(SWITCH_CASES_CONTAINER_DEFAULT_CAPACITY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@ public CtExpression<?> getExpression() {

@Override
public <T extends CtSynchronized> T setBlock(CtBlock<?> block) {
block.setParent(this);
if (block != null) {
block.setParent(this);
}
this.block = block;
return (T) this;
}

@Override
public <T extends CtSynchronized> T setExpression(CtExpression<?> expression) {
expression.setParent(this);
if (expression != null) {
expression.setParent(this);
}
this.expression = expression;
return (T) this;
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/spoon/support/reflect/code/CtTryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public <T extends CtTry> T setCatchers(List<CtCatch> catchers) {

@Override
public <T extends CtTry> T addCatcher(CtCatch catcher) {
if (catcher == null) {
return (T) this;
}
if (catchers == CtElementImpl.<CtCatch>emptyList()) {
catchers = new ArrayList<CtCatch>(CATCH_CASES_CONTAINER_DEFAULT_CAPACITY);
}
Expand All @@ -79,7 +82,9 @@ public CtBlock<?> getFinalizer() {

@Override
public <T extends CtTry> T setFinalizer(CtBlock<?> finalizer) {
finalizer.setParent(this);
if (finalizer != null) {
finalizer.setParent(this);
}
this.finalizer = finalizer;
return (T) this;
}
Expand All @@ -91,7 +96,9 @@ public CtBlock<?> getBody() {

@Override
public <T extends CtTry> T setBody(CtBlock<?> body) {
body.setParent(this);
if (body != null) {
body.setParent(this);
}
this.body = body;
return (T) this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public <T extends CtTryWithResource> T setResources(List<CtLocalVariable<?>> res

@Override
public <T extends CtTryWithResource> T addResource(CtLocalVariable<?> resource) {
if (resource == null) {
return (T) this;
}
if (resources == CtElementImpl.<CtLocalVariable<?>>emptyList()) {
resources = new ArrayList<CtLocalVariable<?>>(RESOURCES_CONTAINER_DEFAULT_CAPACITY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ public void replace(CtElement element) {

@Override
public <C extends CtUnaryOperator> C setOperand(CtExpression<T> expression) {
expression.setParent(this);
if (expression != null) {
expression.setParent(this);
}
this.operand = expression;
return (C) this;
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/spoon/support/reflect/code/CtWhileImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public CtExpression<Boolean> getLoopingExpression() {

@Override
public <T extends CtWhile> T setLoopingExpression(CtExpression<Boolean> expression) {
expression.setParent(this);
if (expression != null) {
expression.setParent(this);
}
this.expression = expression;
return (T) this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public void accept(CtVisitor v) {
}

private <R> CtMethod<R> createGhostMethod(CtField<R> field) {
if (field == null) {
return null;
}
final CtMethod<R> method = factory.Core().createMethod();
method.setImplicit(true);
method.setSimpleName(field.getSimpleName());
Expand Down
Loading