Skip to content

Commit

Permalink
Let FieldAccessExpr implement NodeWithSimpleName interface like Metho…
Browse files Browse the repository at this point in the history
…dCallExpr etc
  • Loading branch information
arturbosch committed Jan 9, 2017
1 parent 1705b11 commit b333220
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
Expand Up @@ -23,6 +23,7 @@

import com.github.javaparser.Range;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName;
import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments;
import com.github.javaparser.ast.observer.ObservableProperty;
import com.github.javaparser.ast.type.Type;
Expand All @@ -39,28 +40,28 @@
*
* @author Julio Vilmar Gesser
*/
public final class FieldAccessExpr extends Expression implements NodeWithTypeArguments<FieldAccessExpr> {
public final class FieldAccessExpr extends Expression implements NodeWithSimpleName<FieldAccessExpr>, NodeWithTypeArguments<FieldAccessExpr> {

private Expression scope;

private NodeList<Type> typeArguments;

private SimpleName field;
private SimpleName name;

public FieldAccessExpr() {
this(null, new ThisExpr(), new NodeList<>(), new SimpleName());
}

public FieldAccessExpr(final Expression scope, final String field) {
this(null, scope, new NodeList<>(), new SimpleName(field));
public FieldAccessExpr(final Expression scope, final String name) {
this(null, scope, new NodeList<>(), new SimpleName(name));
}

public FieldAccessExpr(final Range range, final Expression scope, final NodeList<Type> typeArguments,
final SimpleName field) {
final SimpleName name) {
super(range);
setScope(scope);
setTypeArguments(typeArguments);
setFieldExpr(field);
setName(name);
}

@Override
Expand All @@ -73,24 +74,46 @@ public <A> void accept(final VoidVisitor<A> v, final A arg) {
v.visit(this, arg);
}

@Override
public SimpleName getName() {
return name;
}

@Override
public FieldAccessExpr setName(SimpleName name) {
notifyPropertyChange(ObservableProperty.NAME, this.name, name);
this.name = assertNotNull(name);
setAsParentNodeOf(this.name);
return this;
}

/**
* Use {@link #getName} instead.
*/
@Deprecated
public SimpleName getField() {
return field;
return name;
}

public Optional<Expression> getScope() {
return Optional.ofNullable(scope);
}

/**
* Use {@link #setName} with new SimpleName(field) instead.
*/
@Deprecated
public FieldAccessExpr setField(final String field) {
setFieldExpr(new SimpleName(field));
setName(new SimpleName(field));
return this;
}

/**
* Use {@link #setName} instead.
*/
@Deprecated
public FieldAccessExpr setFieldExpr(SimpleName inner) {
notifyPropertyChange(ObservableProperty.FIELD, this.field, inner);
this.field = assertNotNull(inner);
setAsParentNodeOf(this.field);
return this;
return setName(inner);
}

/**
Expand Down
Expand Up @@ -537,7 +537,7 @@ public Visitable visit(EnclosedExpr _n, Object _arg) {
public Visitable visit(FieldAccessExpr _n, Object _arg) {
Expression scope_ = cloneNode(_n.getScope(), _arg);
NodeList<Type> typeArguments_ = cloneList(_n.getTypeArguments().orElse(null), _arg);
SimpleName fieldExpr_ = cloneNode(_n.getField(), _arg);
SimpleName fieldExpr_ = cloneNode(_n.getName(), _arg);
Comment comment = cloneNode(_n.getComment(), _arg);

FieldAccessExpr r = new FieldAccessExpr(
Expand Down
Expand Up @@ -837,7 +837,7 @@ public Boolean visit(final FieldAccessExpr n1, final Visitable arg) {
return false;
}

if (!objEquals(n1.getField(), n2.getField())) {
if (!objEquals(n1.getName(), n2.getName())) {
return false;
}

Expand Down
Expand Up @@ -345,7 +345,7 @@ public void visit(final FieldAccessExpr n, final A arg) {
visitComment(n.getComment(), arg);
if (n.getScope().isPresent())
n.getScope().get().accept(this, arg);
n.getField().accept(this, arg);
n.getName().accept(this, arg);
}

@Override
Expand Down
Expand Up @@ -551,7 +551,7 @@ public void visit(final FieldAccessExpr n, final Void arg) {
if (n.getScope().isPresent())
n.getScope().get().accept(this, arg);
printer.print(".");
n.getField().accept(this, arg);
n.getName().accept(this, arg);
}

@Override
Expand Down

0 comments on commit b333220

Please sign in to comment.