Skip to content

Commit

Permalink
make ContextTest pass
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomassetti committed Aug 12, 2018
1 parent 0c5eb7e commit a33639c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Expand Up @@ -34,6 +34,7 @@
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors;


import static com.github.javaparser.symbolsolver.javaparser.Navigator.getParentNode; import static com.github.javaparser.symbolsolver.javaparser.Navigator.getParentNode;
import static com.github.javaparser.symbolsolver.javaparser.Navigator.requireParentNode; import static com.github.javaparser.symbolsolver.javaparser.Navigator.requireParentNode;
Expand Down Expand Up @@ -91,6 +92,14 @@ public SymbolReference<ResolvedMethodDeclaration> solveMethod(String name, List<


@Override @Override
public List<VariableDeclarator> localVariablesExposedToChild(Node child) { public List<VariableDeclarator> localVariablesExposedToChild(Node child) {
for (int i=0;i<wrappedNode.getResources().size();i++) {
if (child == wrappedNode.getResources().get(i)) {
return wrappedNode.getResources().subList(0, i).stream()
.map(e -> e instanceof VariableDeclarationExpr ? ((VariableDeclarationExpr) e).getVariables() : Collections.<VariableDeclarator>emptyList())
.flatMap(List::stream)
.collect(Collectors.toList());
}
}
if (child == wrappedNode.getTryBlock()) { if (child == wrappedNode.getTryBlock()) {
List<VariableDeclarator> res = new LinkedList<>(); List<VariableDeclarator> res = new LinkedList<>();
for (Expression expr : wrappedNode.getResources()) { for (Expression expr : wrappedNode.getResources()) {
Expand Down
Expand Up @@ -644,12 +644,12 @@ public void parametersExposedToChildWithinTryStatement() {
// associated with the try-with-resources statement. // associated with the try-with-resources statement.


@Test @Test
public void parametersExposedToChildWithinTryWithResourcesStatement() { public void localVariablesExposedToChildWithinTryWithResourcesStatement() {
TryStmt stmt = parse("try (Object res1 = foo(); Object res2 = foo()) { body(); }", TryStmt stmt = parse("try (Object res1 = foo(); Object res2 = foo()) { body(); }",
ParseStart.STATEMENT).asTryStmt(); ParseStart.STATEMENT).asTryStmt();
assertOneParamExposedToChildInContextNamed(stmt, stmt.getResources().get(1), "res1"); assertOneVarExposedToChildInContextNamed(stmt, stmt.getResources().get(1), "res1");
assertNoParamsExposedToChildInContextNamed(stmt, stmt.getResources().get(0), "res1"); assertNoVarsExposedToChildInContextNamed(stmt, stmt.getResources().get(0), "res1");
assertOneParamExposedToChildInContextNamed(stmt, stmt.getTryBlock(), "res1"); assertOneVarExposedToChildInContextNamed(stmt, stmt.getTryBlock(), "res1");
} }


} }

0 comments on commit a33639c

Please sign in to comment.