use of com.python.pydev.analysis.visitors.GenAndTok in project Pydev by fabioz.
the class AbstractScopeAnalyzerVisitor method endScope.
/**
* finalizes the current scope
* @param reportUnused: defines whether we should report unused things found (we may not want to do that
* when we have an abstract method)
*/
protected void endScope(SimpleNode node) {
onBeforeEndScope(node);
// clear the last scope
ScopeItems m = scope.endScope();
for (Iterator<Found> it = probablyNotDefined.iterator(); it.hasNext(); ) {
Found n = it.next();
final GenAndTok probablyNotDefinedFirst = n.getSingle();
IToken tok = probablyNotDefinedFirst.tok;
String rep = tok.getRepresentation();
// we also get a last pass to the unused to see if they might have been defined later on the higher scope
List<Found> foundItems = find(m, rep);
boolean setUsed = false;
for (Found found : foundItems) {
// the scope where it is defined must be an outer scope so that we can say it was defined later...
final GenAndTok foundItemFirst = found.getSingle();
if ((probablyNotDefinedFirst.scopeFound.getScopeType() & Scope.ACCEPTED_METHOD_AND_LAMBDA) != 0 && m.getScopeType() != Scope.SCOPE_TYPE_CLASS) {
if (foundItemFirst.scopeId < probablyNotDefinedFirst.scopeId) {
found.setUsed(true);
setUsed = true;
}
}
}
if (setUsed) {
it.remove();
}
}
// point
if (scope.size() == 0) {
onLastScope(m);
}
onAfterEndScope(node, m);
}
use of com.python.pydev.analysis.visitors.GenAndTok in project Pydev by fabioz.
the class ScopeAnalyzerVisitorWithoutImports method getCompleteTokenOccurrences.
/**
* @return all the occurrences found in a 'complete' way (dotted name).
* The ASTEtries are decorated with the Found here...
*/
protected ArrayList<Tuple4<IToken, Integer, ASTEntry, Found>> getCompleteTokenOccurrences() {
// that's because we don't want duplicates
Set<IToken> f = new HashSet<IToken>();
ArrayList<Tuple4<IToken, Integer, ASTEntry, Found>> ret = new ArrayList<Tuple4<IToken, Integer, ASTEntry, Found>>();
for (Tuple3<Found, Integer, ASTEntry> found : foundOccurrences) {
List<GenAndTok> all = found.o1.getAll();
for (GenAndTok tok : all) {
Tuple4<IToken, Integer, ASTEntry, Found> tup4 = new Tuple4<IToken, Integer, ASTEntry, Found>(tok.generator, found.o2, found.o3, found.o1);
if (!f.contains(tok.generator)) {
f.add(tok.generator);
ret.add(tup4);
}
for (IToken t : tok.references) {
tup4 = new Tuple4<IToken, Integer, ASTEntry, Found>(t, found.o2, found.o3, found.o1);
if (!f.contains(t)) {
f.add(t);
ret.add(tup4);
}
}
}
onGetCompleteTokenOccurrences(found, f, ret);
}
return ret;
}
use of com.python.pydev.analysis.visitors.GenAndTok in project Pydev by fabioz.
the class AbstractScopeAnalyzerVisitor method addToNamesToIgnore.
/**
* used so that the token is added to the names to ignore...
*/
protected void addToNamesToIgnore(SimpleNode node, boolean finishClassScope, boolean checkBuiltins) {
SourceToken token = AbstractVisitor.makeToken(node, "", nature);
if (checkBuiltins) {
if (checkCurrentScopeForAssignmentsToBuiltins()) {
String rep = token.getRepresentation();
if (builtinTokens.contains(rep)) {
// Overriding builtin...
onAddAssignmentToBuiltinMessage(token, rep);
}
}
}
ScopeItems currScopeItems = scope.getCurrScopeItems();
Found found = new Found(token, token, scope.getCurrScopeId(), scope.getCurrScopeItems());
org.python.pydev.shared_core.structure.Tuple<IToken, Found> tup = new org.python.pydev.shared_core.structure.Tuple<IToken, Found>(token, found);
addToNamesToIgnore(token, currScopeItems, tup);
// in the 'probably not defined' stack.
for (Iterator<Found> it = probablyNotDefined.iterator(); it.hasNext(); ) {
Found n = it.next();
GenAndTok single = n.getSingle();
int foundScopeType = single.scopeFound.getScopeType();
// ok, if we are in a scope method, we may not get things that were defined in a class scope.
if (((foundScopeType & Scope.ACCEPTED_METHOD_AND_LAMBDA) != 0) && scope.getCurrScopeItems().getScopeType() == Scope.SCOPE_TYPE_CLASS) {
continue;
}
IToken tok = single.tok;
String firstPart = FullRepIterable.getFirstPart(tok.getRepresentation());
if (firstPart.equals(token.getRepresentation())) {
if (finishClassScope && scope.getCurrScopeId() < single.scopeFound.getScopeId() && (!futureAnnotationsImported && foundScopeType == Scope.SCOPE_TYPE_CLASS || (!futureAnnotationsImported && foundScopeType == Scope.SCOPE_TYPE_ANNOTATION))) {
it.remove();
onAddUndefinedMessage(tok, found);
} else {
it.remove();
onNotDefinedFoundLater(n, found);
}
}
}
}
Aggregations