Skip to content

Commit

Permalink
Added a method resolveAccessedValue() to FieldAccessExpr
Browse files Browse the repository at this point in the history
  • Loading branch information
malteskoruppa committed May 24, 2018
1 parent 1626ba1 commit d6ba23f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import javax.annotation.Generated;
import com.github.javaparser.TokenRange;
import com.github.javaparser.metamodel.OptionalProperty;
import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration;

import java.util.function.Consumer;

/**
Expand Down Expand Up @@ -254,6 +256,10 @@ public void ifFieldAccessExpr(Consumer<FieldAccessExpr> action) {
action.accept(this);
}

public ResolvedValueDeclaration resolveAccessedValue() {
return getSymbolResolver().resolveDeclaration(this, ResolvedValueDeclaration.class);
}

@Override
@Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
public Optional<FieldAccessExpr> toFieldAccessExpr() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ public <T> T resolveDeclaration(Node node, Class<T> resultClass) {
throw new UnsolvedSymbolException("We are unable to find the value declaration corresponding to " + node);
}
}
if (node instanceof FieldAccessExpr) {
SymbolReference<? extends ResolvedValueDeclaration> result = JavaParserFacade.get(typeSolver).solve((FieldAccessExpr) node);
if (result.isSolved()) {
if (resultClass.isInstance(result.getCorrespondingDeclaration())) {
return resultClass.cast(result.getCorrespondingDeclaration());
}
} else {
throw new UnsolvedSymbolException("We are unable to find the value declaration corresponding to " + node);
}
}
if (node instanceof ThisExpr) {
SymbolReference<ResolvedTypeDeclaration> result = JavaParserFacade.get(typeSolver).solve((ThisExpr) node);
if (result.isSolved()) {
Expand Down

0 comments on commit d6ba23f

Please sign in to comment.