Skip to content

Commit

Permalink
reduce calls to wrappedNode.getResources in localVariablesExposedToChild
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomassetti committed Aug 14, 2018
1 parent 6dfd044 commit 295f99b
Showing 1 changed file with 8 additions and 5 deletions.
Expand Up @@ -17,6 +17,7 @@
package com.github.javaparser.symbolsolver.javaparsermodel.contexts;

import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.body.VariableDeclarator;
import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.expr.VariableDeclarationExpr;
Expand Down Expand Up @@ -92,17 +93,19 @@ public SymbolReference<ResolvedMethodDeclaration> solveMethod(String name, List<

@Override
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())
NodeList<Expression> resources = wrappedNode.getResources();
for (int i=0;i<resources.size();i++) {
if (child == resources.get(i)) {
return resources.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()) {
List<VariableDeclarator> res = new LinkedList<>();
for (Expression expr : wrappedNode.getResources()) {
for (Expression expr : resources) {
if (expr instanceof VariableDeclarationExpr) {
res.addAll(((VariableDeclarationExpr)expr).getVariables());
}
Expand Down

0 comments on commit 295f99b

Please sign in to comment.