*/
public static List<ASTEntry> getLocalOccurrences(final String occurencesFor, SimpleNode simpleNode,
final boolean onlyFirstAttribPart) {
List<ASTEntry> ret = new ArrayList<ASTEntry>();
SequencialASTIteratorVisitor visitor = new SequencialASTIteratorVisitor() {
@Override
public Object visitAttribute(Attribute node) throws Exception {
if (onlyFirstAttribPart) {
//this will visit the attribute parts if call, subscript, etc.
AbstractScopeAnalyzerVisitor.visitNeededAttributeParts(node, this);
List<SimpleNode> attributeParts = NodeUtils.getAttributeParts(node);
atomic(attributeParts.get(0)); //an attribute should always have many parts
traverse(attributeParts.get(0));
return null;
} else {
return super.visitAttribute(node);
}
}
};
if (simpleNode instanceof FunctionDef) {
//all that because we don't want to visit the name of the function if we've started in a function scope
FunctionDef d = (FunctionDef) simpleNode;
try {
//decorators
if (d.decs != null) {
for (decoratorsType dec : d.decs) {
if (dec != null) {
dec.accept(visitor);
}
}
}
//don't do d.args directly because we don't want to check the 'defaults'
if (d.args != null) {
if (d.args.args != null) {
for (exprType arg : d.args.args) {
arg.accept(visitor);
}
}
if (d.args.vararg != null) {
d.args.vararg.accept(visitor);
}
if (d.args.kwarg != null) {
d.args.kwarg.accept(visitor);
}
//visit keyword only args
if (d.args.kwonlyargs != null) {
for (exprType expr : d.args.kwonlyargs) {
expr.accept(visitor);
}
}
}
//and at last... the body
if (d.body != null) {
for (stmtType exp : d.body) {
if (exp != null) {
exp.accept(visitor);
}
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
try {
simpleNode.accept(visitor);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Iterator<ASTEntry> iterator = visitor.getNamesIterator();
while (iterator.hasNext()) {
ASTEntry entry = iterator.next();
//SimpleNode nameNode = entry.getNameNode();
//if(!occurencesFor.isParamRename){
// if(nameNode instanceof NameTok){