Skip to content

Commit

Permalink
Put receiver parameter only in method declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
matozoid committed Oct 17, 2017
1 parent 255d264 commit 27a1a23
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 105 deletions.
Expand Up @@ -43,7 +43,6 @@
import static com.github.javaparser.utils.Utils.assertNotNull; import static com.github.javaparser.utils.Utils.assertNotNull;
import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList;
import java.util.Optional;
import java.util.function.Consumer; import java.util.function.Consumer;


/** /**
Expand All @@ -61,23 +60,20 @@ public abstract class CallableDeclaration<T extends CallableDeclaration<?>> exte


private NodeList<ReferenceType> thrownExceptions; private NodeList<ReferenceType> thrownExceptions;


private ReceiverParameter receiverParameter;

@AllFieldsConstructor @AllFieldsConstructor
public CallableDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, ReceiverParameter receiverParameter) { public CallableDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions) {
this(null, modifiers, annotations, typeParameters, name, parameters, thrownExceptions, receiverParameter); this(null, modifiers, annotations, typeParameters, name, parameters, thrownExceptions);
} }


/**This constructor is used by the parser and is considered private.*/ /**This constructor is used by the parser and is considered private.*/
@Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
public CallableDeclaration(TokenRange tokenRange, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, ReceiverParameter receiverParameter) { public CallableDeclaration(TokenRange tokenRange, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions) {
super(tokenRange, annotations); super(tokenRange, annotations);
setModifiers(modifiers); setModifiers(modifiers);
setTypeParameters(typeParameters); setTypeParameters(typeParameters);
setName(name); setName(name);
setParameters(parameters); setParameters(parameters);
setThrownExceptions(thrownExceptions); setThrownExceptions(thrownExceptions);
setReceiverParameter(receiverParameter);
customInitialization(); customInitialization();
} }


Expand Down Expand Up @@ -222,12 +218,6 @@ public boolean remove(Node node) {
return true; return true;
} }
} }
if (receiverParameter != null) {
if (node == receiverParameter) {
removeReceiverParameter();
return true;
}
}
for (int i = 0; i < thrownExceptions.size(); i++) { for (int i = 0; i < thrownExceptions.size(); i++) {
if (thrownExceptions.get(i) == node) { if (thrownExceptions.get(i) == node) {
thrownExceptions.remove(i); thrownExceptions.remove(i);
Expand Down Expand Up @@ -354,12 +344,6 @@ public boolean replace(Node node, Node replacementNode) {
return true; return true;
} }
} }
if (receiverParameter != null) {
if (node == receiverParameter) {
setReceiverParameter((ReceiverParameter) replacementNode);
return true;
}
}
for (int i = 0; i < thrownExceptions.size(); i++) { for (int i = 0; i < thrownExceptions.size(); i++) {
if (thrownExceptions.get(i) == node) { if (thrownExceptions.get(i) == node) {
thrownExceptions.set(i, (ReferenceType) replacementNode); thrownExceptions.set(i, (ReferenceType) replacementNode);
Expand Down Expand Up @@ -391,28 +375,4 @@ public CallableDeclaration asCallableDeclaration() {
public void ifCallableDeclaration(Consumer<CallableDeclaration> action) { public void ifCallableDeclaration(Consumer<CallableDeclaration> action) {
action.accept(this); action.accept(this);
} }

@Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
public Optional<ReceiverParameter> getReceiverParameter() {
return Optional.ofNullable(receiverParameter);
}

@SuppressWarnings("unchecked")
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
public T setReceiverParameter(final ReceiverParameter receiverParameter) {
if (receiverParameter == this.receiverParameter) {
return (T) this;
}
notifyPropertyChange(ObservableProperty.RECEIVER_PARAMETER, this.receiverParameter, receiverParameter);
if (this.receiverParameter != null)
this.receiverParameter.setParentNode(null);
this.receiverParameter = receiverParameter;
setAsParentNodeOf(receiverParameter);
return (T) this;
}

@Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
public CallableDeclaration removeReceiverParameter() {
return setReceiverParameter((ReceiverParameter) null);
}
} }
Expand Up @@ -51,34 +51,34 @@
* *
* <br/>All annotations preceding the name will be set on this object, not on the class. * <br/>All annotations preceding the name will be set on this object, not on the class.
* JavaParser doesn't know if it they are applicable to the method or the class. * JavaParser doesn't know if it they are applicable to the method or the class.
* *
* @author Julio Vilmar Gesser * @author Julio Vilmar Gesser
*/ */
public final class ConstructorDeclaration extends CallableDeclaration<ConstructorDeclaration> implements NodeWithBlockStmt<ConstructorDeclaration>, NodeWithAccessModifiers<ConstructorDeclaration>, NodeWithJavadoc<ConstructorDeclaration>, NodeWithDeclaration, NodeWithSimpleName<ConstructorDeclaration>, NodeWithParameters<ConstructorDeclaration>, NodeWithThrownExceptions<ConstructorDeclaration>, NodeWithTypeParameters<ConstructorDeclaration> { public final class ConstructorDeclaration extends CallableDeclaration<ConstructorDeclaration> implements NodeWithBlockStmt<ConstructorDeclaration>, NodeWithAccessModifiers<ConstructorDeclaration>, NodeWithJavadoc<ConstructorDeclaration>, NodeWithDeclaration, NodeWithSimpleName<ConstructorDeclaration>, NodeWithParameters<ConstructorDeclaration>, NodeWithThrownExceptions<ConstructorDeclaration>, NodeWithTypeParameters<ConstructorDeclaration> {


private BlockStmt body; private BlockStmt body;


public ConstructorDeclaration() { public ConstructorDeclaration() {
this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new NodeList<>(), new SimpleName(), new NodeList<>(), new NodeList<>(), new BlockStmt(), null); this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new NodeList<>(), new SimpleName(), new NodeList<>(), new NodeList<>(), new BlockStmt());
} }


public ConstructorDeclaration(String name) { public ConstructorDeclaration(String name) {
this(null, EnumSet.of(Modifier.PUBLIC), new NodeList<>(), new NodeList<>(), new SimpleName(name), new NodeList<>(), new NodeList<>(), new BlockStmt(), null); this(null, EnumSet.of(Modifier.PUBLIC), new NodeList<>(), new NodeList<>(), new SimpleName(name), new NodeList<>(), new NodeList<>(), new BlockStmt());
} }


public ConstructorDeclaration(EnumSet<Modifier> modifiers, String name) { public ConstructorDeclaration(EnumSet<Modifier> modifiers, String name) {
this(null, modifiers, new NodeList<>(), new NodeList<>(), new SimpleName(name), new NodeList<>(), new NodeList<>(), new BlockStmt(), null); this(null, modifiers, new NodeList<>(), new NodeList<>(), new SimpleName(name), new NodeList<>(), new NodeList<>(), new BlockStmt());
} }


@AllFieldsConstructor @AllFieldsConstructor
public ConstructorDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body, ReceiverParameter receiverParameter) { public ConstructorDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body) {
this(null, modifiers, annotations, typeParameters, name, parameters, thrownExceptions, body, receiverParameter); this(null, modifiers, annotations, typeParameters, name, parameters, thrownExceptions, body);
} }


/**This constructor is used by the parser and is considered private.*/ /**This constructor is used by the parser and is considered private.*/
@Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
public ConstructorDeclaration(TokenRange tokenRange, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body, ReceiverParameter receiverParameter) { public ConstructorDeclaration(TokenRange tokenRange, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body) {
super(tokenRange, modifiers, annotations, typeParameters, name, parameters, thrownExceptions, receiverParameter); super(tokenRange, modifiers, annotations, typeParameters, name, parameters, thrownExceptions);
setBody(body); setBody(body);
customInitialization(); customInitialization();
} }
Expand Down
Expand Up @@ -67,6 +67,8 @@ public final class MethodDeclaration extends CallableDeclaration<MethodDeclarati


private BlockStmt body; private BlockStmt body;


private ReceiverParameter receiverParameter;

public MethodDeclaration() { public MethodDeclaration() {
this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new NodeList<>(), new ClassOrInterfaceType(), new SimpleName(), new NodeList<>(), new NodeList<>(), new BlockStmt(), null); this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new NodeList<>(), new ClassOrInterfaceType(), new SimpleName(), new NodeList<>(), new NodeList<>(), new BlockStmt(), null);
} }
Expand Down Expand Up @@ -94,9 +96,10 @@ public MethodDeclaration(final EnumSet<Modifier> modifiers, final NodeList<Annot
/**This constructor is used by the parser and is considered private.*/ /**This constructor is used by the parser and is considered private.*/
@Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
public MethodDeclaration(TokenRange tokenRange, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, Type type, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body, ReceiverParameter receiverParameter) { public MethodDeclaration(TokenRange tokenRange, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, Type type, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body, ReceiverParameter receiverParameter) {
super(tokenRange, modifiers, annotations, typeParameters, name, parameters, thrownExceptions, receiverParameter); super(tokenRange, modifiers, annotations, typeParameters, name, parameters, thrownExceptions);
setType(type); setType(type);
setBody(body); setBody(body);
setReceiverParameter(receiverParameter);
customInitialization(); customInitialization();
} }


Expand Down Expand Up @@ -271,6 +274,12 @@ public boolean remove(Node node) {
return true; return true;
} }
} }
if (receiverParameter != null) {
if (node == receiverParameter) {
removeReceiverParameter();
return true;
}
}
return super.remove(node); return super.remove(node);
} }


Expand Down Expand Up @@ -302,6 +311,12 @@ public boolean replace(Node node, Node replacementNode) {
return true; return true;
} }
} }
if (receiverParameter != null) {
if (node == receiverParameter) {
setReceiverParameter((ReceiverParameter) replacementNode);
return true;
}
}
if (node == type) { if (node == type) {
setType((Type) replacementNode); setType((Type) replacementNode);
return true; return true;
Expand Down Expand Up @@ -330,4 +345,27 @@ public void ifMethodDeclaration(Consumer<MethodDeclaration> action) {
public ResolvedMethodDeclaration resolve() { public ResolvedMethodDeclaration resolve() {
return getSymbolResolver().resolve(this, ResolvedMethodDeclaration.class); return getSymbolResolver().resolve(this, ResolvedMethodDeclaration.class);
} }

@Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
public Optional<ReceiverParameter> getReceiverParameter() {
return Optional.ofNullable(receiverParameter);
}

@Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
public MethodDeclaration setReceiverParameter(final ReceiverParameter receiverParameter) {
if (receiverParameter == this.receiverParameter) {
return (MethodDeclaration) this;
}
notifyPropertyChange(ObservableProperty.RECEIVER_PARAMETER, this.receiverParameter, receiverParameter);
if (this.receiverParameter != null)
this.receiverParameter.setParentNode(null);
this.receiverParameter = receiverParameter;
setAsParentNodeOf(receiverParameter);
return this;
}

@Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
public MethodDeclaration removeReceiverParameter() {
return setReceiverParameter((ReceiverParameter) null);
}
} }
Expand Up @@ -185,12 +185,11 @@ public Visitable visit(final ConstructorDeclaration n, final Object arg) {
BlockStmt body = cloneNode(n.getBody(), arg); BlockStmt body = cloneNode(n.getBody(), arg);
SimpleName name = cloneNode(n.getName(), arg); SimpleName name = cloneNode(n.getName(), arg);
NodeList<Parameter> parameters = cloneList(n.getParameters(), arg); NodeList<Parameter> parameters = cloneList(n.getParameters(), arg);
ReceiverParameter receiverParameter = cloneNode(n.getReceiverParameter(), arg);
NodeList<ReferenceType> thrownExceptions = cloneList(n.getThrownExceptions(), arg); NodeList<ReferenceType> thrownExceptions = cloneList(n.getThrownExceptions(), arg);
NodeList<TypeParameter> typeParameters = cloneList(n.getTypeParameters(), arg); NodeList<TypeParameter> typeParameters = cloneList(n.getTypeParameters(), arg);
NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
Comment comment = cloneNode(n.getComment(), arg); Comment comment = cloneNode(n.getComment(), arg);
ConstructorDeclaration r = new ConstructorDeclaration(n.getTokenRange().orElse(null), n.getModifiers(), annotations, typeParameters, name, parameters, thrownExceptions, body, receiverParameter); ConstructorDeclaration r = new ConstructorDeclaration(n.getTokenRange().orElse(null), n.getModifiers(), annotations, typeParameters, name, parameters, thrownExceptions, body);
r.setComment(comment); r.setComment(comment);
return r; return r;
} }
Expand All @@ -199,10 +198,10 @@ public Visitable visit(final ConstructorDeclaration n, final Object arg) {
@Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator") @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
public Visitable visit(final MethodDeclaration n, final Object arg) { public Visitable visit(final MethodDeclaration n, final Object arg) {
BlockStmt body = cloneNode(n.getBody(), arg); BlockStmt body = cloneNode(n.getBody(), arg);
ReceiverParameter receiverParameter = cloneNode(n.getReceiverParameter(), arg);
Type type = cloneNode(n.getType(), arg); Type type = cloneNode(n.getType(), arg);
SimpleName name = cloneNode(n.getName(), arg); SimpleName name = cloneNode(n.getName(), arg);
NodeList<Parameter> parameters = cloneList(n.getParameters(), arg); NodeList<Parameter> parameters = cloneList(n.getParameters(), arg);
ReceiverParameter receiverParameter = cloneNode(n.getReceiverParameter(), arg);
NodeList<ReferenceType> thrownExceptions = cloneList(n.getThrownExceptions(), arg); NodeList<ReferenceType> thrownExceptions = cloneList(n.getThrownExceptions(), arg);
NodeList<TypeParameter> typeParameters = cloneList(n.getTypeParameters(), arg); NodeList<TypeParameter> typeParameters = cloneList(n.getTypeParameters(), arg);
NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg); NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
Expand Down
Expand Up @@ -338,8 +338,6 @@ public Boolean visit(final ConstructorDeclaration n, final Visitable arg) {
return false; return false;
if (!nodesEquals(n.getParameters(), n2.getParameters())) if (!nodesEquals(n.getParameters(), n2.getParameters()))
return false; return false;
if (!nodeEquals(n.getReceiverParameter(), n2.getReceiverParameter()))
return false;
if (!nodesEquals(n.getThrownExceptions(), n2.getThrownExceptions())) if (!nodesEquals(n.getThrownExceptions(), n2.getThrownExceptions()))
return false; return false;
if (!nodesEquals(n.getTypeParameters(), n2.getTypeParameters())) if (!nodesEquals(n.getTypeParameters(), n2.getTypeParameters()))
Expand All @@ -357,6 +355,8 @@ public Boolean visit(final MethodDeclaration n, final Visitable arg) {
final MethodDeclaration n2 = (MethodDeclaration) arg; final MethodDeclaration n2 = (MethodDeclaration) arg;
if (!nodeEquals(n.getBody(), n2.getBody())) if (!nodeEquals(n.getBody(), n2.getBody()))
return false; return false;
if (!nodeEquals(n.getReceiverParameter(), n2.getReceiverParameter()))
return false;
if (!nodeEquals(n.getType(), n2.getType())) if (!nodeEquals(n.getType(), n2.getType()))
return false; return false;
if (!objEquals(n.getModifiers(), n2.getModifiers())) if (!objEquals(n.getModifiers(), n2.getModifiers()))
Expand All @@ -365,8 +365,6 @@ public Boolean visit(final MethodDeclaration n, final Visitable arg) {
return false; return false;
if (!nodesEquals(n.getParameters(), n2.getParameters())) if (!nodesEquals(n.getParameters(), n2.getParameters()))
return false; return false;
if (!nodeEquals(n.getReceiverParameter(), n2.getReceiverParameter()))
return false;
if (!nodesEquals(n.getThrownExceptions(), n2.getThrownExceptions())) if (!nodesEquals(n.getThrownExceptions(), n2.getThrownExceptions()))
return false; return false;
if (!nodesEquals(n.getTypeParameters(), n2.getTypeParameters())) if (!nodesEquals(n.getTypeParameters(), n2.getTypeParameters()))
Expand Down
Expand Up @@ -562,11 +562,6 @@ public List<R> visit(final ConstructorDeclaration n, final A arg) {
if (tmp != null) if (tmp != null)
result.addAll(tmp); result.addAll(tmp);
} }
if (n.getReceiverParameter().isPresent()) {
tmp = n.getReceiverParameter().get().accept(this, arg);
if (tmp != null)
result.addAll(tmp);
}
{ {
tmp = n.getThrownExceptions().accept(this, arg); tmp = n.getThrownExceptions().accept(this, arg);
if (tmp != null) if (tmp != null)
Expand Down Expand Up @@ -1190,6 +1185,11 @@ public List<R> visit(final MethodDeclaration n, final A arg) {
if (tmp != null) if (tmp != null)
result.addAll(tmp); result.addAll(tmp);
} }
if (n.getReceiverParameter().isPresent()) {
tmp = n.getReceiverParameter().get().accept(this, arg);
if (tmp != null)
result.addAll(tmp);
}
{ {
tmp = n.getType().accept(this, arg); tmp = n.getType().accept(this, arg);
if (tmp != null) if (tmp != null)
Expand All @@ -1205,11 +1205,6 @@ public List<R> visit(final MethodDeclaration n, final A arg) {
if (tmp != null) if (tmp != null)
result.addAll(tmp); result.addAll(tmp);
} }
if (n.getReceiverParameter().isPresent()) {
tmp = n.getReceiverParameter().get().accept(this, arg);
if (tmp != null)
result.addAll(tmp);
}
{ {
tmp = n.getThrownExceptions().accept(this, arg); tmp = n.getThrownExceptions().accept(this, arg);
if (tmp != null) if (tmp != null)
Expand Down
Expand Up @@ -502,11 +502,6 @@ public R visit(final ConstructorDeclaration n, final A arg) {
if (result != null) if (result != null)
return result; return result;
} }
if (n.getReceiverParameter().isPresent()) {
result = n.getReceiverParameter().get().accept(this, arg);
if (result != null)
return result;
}
{ {
result = n.getThrownExceptions().accept(this, arg); result = n.getThrownExceptions().accept(this, arg);
if (result != null) if (result != null)
Expand Down Expand Up @@ -1040,6 +1035,11 @@ public R visit(final MethodDeclaration n, final A arg) {
if (result != null) if (result != null)
return result; return result;
} }
if (n.getReceiverParameter().isPresent()) {
result = n.getReceiverParameter().get().accept(this, arg);
if (result != null)
return result;
}
{ {
result = n.getType().accept(this, arg); result = n.getType().accept(this, arg);
if (result != null) if (result != null)
Expand All @@ -1055,11 +1055,6 @@ public R visit(final MethodDeclaration n, final A arg) {
if (result != null) if (result != null)
return result; return result;
} }
if (n.getReceiverParameter().isPresent()) {
result = n.getReceiverParameter().get().accept(this, arg);
if (result != null)
return result;
}
{ {
result = n.getThrownExceptions().accept(this, arg); result = n.getThrownExceptions().accept(this, arg);
if (result != null) if (result != null)
Expand Down

0 comments on commit 27a1a23

Please sign in to comment.