Skip to content

Commit

Permalink
ThisExpr Optional classExpr
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepSnowNeeL committed Nov 30, 2016
1 parent aabc552 commit 9afad91
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
Expand Up @@ -21,6 +21,8 @@

package com.github.javaparser.ast.expr;

import java.util.Optional;

import com.github.javaparser.Range;
import com.github.javaparser.ast.observing.ObservableProperty;
import com.github.javaparser.ast.visitor.GenericVisitor;
Expand All @@ -31,7 +33,6 @@
*/
public final class ThisExpr extends Expression {

// TODO can be null
private Expression classExpr;

public ThisExpr() {
Expand All @@ -55,8 +56,8 @@ public ThisExpr(final Range range, final Expression classExpr) {
v.visit(this, arg);
}

public Expression getClassExpr() {
return classExpr;
public Optional<Expression> getClassExpr() {
return Optional.ofNullable(classExpr);
}

public ThisExpr setClassExpr(final Expression classExpr) {
Expand Down
Expand Up @@ -1108,7 +1108,7 @@ public Boolean visit(SimpleName n, Visitable arg) {
@Override public Boolean visit(final ThisExpr n1, final Visitable arg) {
final ThisExpr n2 = (ThisExpr) arg;

if (!nodeEquals(n1.getClassExpr(), n2.getClassExpr())) {
if (!nodeEquals(n1.getClassExpr().orElse(null), n2.getClassExpr().orElse(null))) {
return false;
}

Expand Down
Expand Up @@ -1460,9 +1460,9 @@ public R visit(final SynchronizedStmt n, final A arg) {
@Override
public R visit(final ThisExpr n, final A arg) {
visitComment(n, arg);
if (n.getClassExpr() != null) {
if (n.getClassExpr().isPresent()) {
{
R result = n.getClassExpr().accept(this, arg);
R result = n.getClassExpr().get().accept(this, arg);
if (result != null) {
return result;
}
Expand Down
Expand Up @@ -775,8 +775,8 @@ public Visitable visit(final SynchronizedStmt n, final A arg) {
@Override
public Visitable visit(final ThisExpr n, final A arg) {
visitComment(n, arg);
if (n.getClassExpr() != null) {
n.setClassExpr((Expression) n.getClassExpr().accept(this, arg));
if (n.getClassExpr().isPresent()) {
n.setClassExpr((Expression) n.getClassExpr().get().accept(this, arg));
}
return n;
}
Expand Down
Expand Up @@ -772,8 +772,8 @@ public void visit(final SynchronizedStmt n, final A arg) {
@Override
public void visit(final ThisExpr n, final A arg) {
visitComment(n.getComment(), arg);
if (n.getClassExpr() != null) {
n.getClassExpr().accept(this, arg);
if (n.getClassExpr().isPresent()) {
n.getClassExpr().get().accept(this, arg);
}
}

Expand Down
Expand Up @@ -718,8 +718,8 @@ public void visit(final NullLiteralExpr n, final Void arg) {
@Override
public void visit(final ThisExpr n, final Void arg) {
printJavaComment(n.getComment(), arg);
if (n.getClassExpr() != null) {
n.getClassExpr().accept(this, arg);
if (n.getClassExpr().isPresent()) {
n.getClassExpr().get().accept(this, arg);
printer.print(".");
}
printer.print("this");
Expand Down

0 comments on commit 9afad91

Please sign in to comment.