/
AbstractScopeNode.java
80 lines (66 loc) · 2.84 KB
/
AbstractScopeNode.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* Copyright (C) 2006, 2007 Dennis Hunziker, Ueli Kistler
* Copyright (C) 2007 Reto Schuettel, Robin Stocker
*
* IFS Institute for Software, HSR Rapperswil, Switzerland
*
*/
package org.python.pydev.refactoring.ast.adapters;
import java.util.List;
import org.python.pydev.parser.jython.SimpleNode;
import org.python.pydev.refactoring.ast.visitors.VisitorFactory;
import org.python.pydev.refactoring.ast.visitors.context.ClassDefVisitor;
import org.python.pydev.refactoring.ast.visitors.context.LocalFunctionDefVisitor;
import org.python.pydev.refactoring.ast.visitors.context.ScopeAssignedVisitor;
import org.python.pydev.refactoring.ast.visitors.context.ScopeVariablesVisitor;
public abstract class AbstractScopeNode<T extends SimpleNode> extends AbstractNodeAdapter<T> {
private List<SimpleAdapter> usedVariables;
private List<SimpleAdapter> assignedVariables;
private List<FunctionDefAdapter> functions;
private List<IClassDefAdapter> classes;
protected AbstractScopeNode() {
}
public AbstractScopeNode(ModuleAdapter module, AbstractScopeNode<? extends SimpleNode> parent, T node, AdapterPrefs adapterPrefs) {
super(module, parent, node, adapterPrefs);
}
public List<FunctionDefAdapter> getFunctions() {
if(functions == null){
T node = getASTNode();
ModuleAdapter module = getModule();
assert (node != null);
assert (module != null);
LocalFunctionDefVisitor visitor = VisitorFactory.createContextVisitor(LocalFunctionDefVisitor.class, node, module, this);
functions = visitor.getAll();
}
return functions;
}
public List<IClassDefAdapter> getClasses() {
if(this.classes == null){
ClassDefVisitor visitor = VisitorFactory.createContextVisitor(ClassDefVisitor.class, this.getASTNode(), getModule(), this);
this.classes = visitor.getAll();
}
return this.classes;
}
public List<SimpleAdapter> getAssignedVariables() {
if(assignedVariables == null){
ScopeAssignedVisitor visitor = VisitorFactory.createContextVisitor(ScopeAssignedVisitor.class, getASTNode(), this.getModule(), this);
assignedVariables = visitor.getAll();
}
return assignedVariables;
}
public List<SimpleAdapter> getUsedVariables() {
if(usedVariables == null){
ScopeVariablesVisitor visitor = VisitorFactory.createContextVisitor(ScopeVariablesVisitor.class, getASTNode(), this.getModule(), this);
usedVariables = visitor.getAll();
}
return usedVariables;
}
public boolean alreadyUsedName(String newName) {
for(SimpleAdapter adapter:this.getUsedVariables()){
if(adapter.getName().compareTo(newName) == 0){
return true;
}
}
return false;
}
}