use of com.python.pydev.analysis.visitors.Found 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);
}
}
}
}
use of com.python.pydev.analysis.visitors.Found in project Pydev by fabioz.
the class AbstractScopeAnalyzerVisitor method visitName.
/**
* Visiting some name
*
* @see org.python.pydev.parser.jython.ast.VisitorIF#visitName(org.python.pydev.parser.jython.ast.Name)
*/
@Override
public Object visitName(Name node) throws Exception {
unhandled_node(node);
// when visiting the global namespace, we don't go into any inner scope.
SourceToken token = AbstractVisitor.makeToken(node, moduleName, nature);
boolean found = true;
// on aug assign, it has to enter both, the load and the read (but first the load, because it can be undefined)
if (node.ctx == Name.Load || node.ctx == Name.Del || node.ctx == Name.AugStore) {
found = markRead(token);
}
if (node.ctx == Name.Store || node.ctx == Attribute.NamedStore || node.ctx == Name.Param || node.ctx == Name.KwOnlyParam || (node.ctx == Name.AugStore && found)) {
// if it was undefined on augstore, we do not go on to creating the token
String rep = token.getRepresentation();
if (checkCurrentScopeForAssignmentsToBuiltins()) {
if (builtinTokens.contains(rep)) {
// Overriding builtin...
onAddAssignmentToBuiltinMessage(token, rep);
}
}
org.python.pydev.shared_core.structure.Tuple<IToken, Found> foundInNamesToIgnore = findInNamesToIgnore(rep, token);
if (foundInNamesToIgnore == null) {
if (!rep.equals("self") && !rep.equals("cls")) {
scope.addToken(token, token);
if (node.ctx == Attribute.NamedStore) {
markRead(token);
}
} else {
// ignore self
addToNamesToIgnore(node, false, false);
}
}
}
return token;
}
use of com.python.pydev.analysis.visitors.Found in project Pydev by fabioz.
the class ScopeAnalyzerVisitor method visitImportFrom.
@Override
public Object visitImportFrom(ImportFrom node) throws Exception {
Object ret = super.visitImportFrom(node);
// the import from will generate the tokens that go into the module namespace, but still, it needs to
// create tokens that will not be used in code-analysis, but will be used in matching tokens
// regarding its module.
NameTok tokModName = (NameTok) node.module;
for (String m : new FullRepIterable(tokModName.id)) {
if (m.indexOf(".") == -1) {
aliasType[] names = new aliasType[1];
NameTok importNameTok = new NameTok(m, NameTok.ImportModule);
importNameTok.beginLine = tokModName.beginLine;
importNameTok.beginColumn = tokModName.beginColumn;
names[0] = new aliasType(importNameTok, null);
names[0].beginLine = tokModName.beginLine;
names[0].beginColumn = tokModName.beginColumn;
Import importTok = new Import(names);
importTok.beginLine = tokModName.beginLine;
importTok.beginColumn = tokModName.beginColumn;
List<IToken> createdTokens = AbstractVisitor.makeImportToken(importTok, null, this.current.getName(), true, this.current.getNature());
for (IToken token : createdTokens) {
ImportInfo info = this.scope.importChecker.visitImportToken(token, false, this.completionCache);
Found found = new Found(token, token, scope.getCurrScopeId(), scope.getCurrScopeItems());
found.importInfo = info;
// check if this is actually a match
checkFound(found, peekParent());
addFoundToImportsMap(found, importsFoundFromModuleName);
}
}
}
return ret;
}
use of com.python.pydev.analysis.visitors.Found in project Pydev by fabioz.
the class ScopeAnalyzerVisitor method addFoundToImportsMap.
/**
* Used to add some Found that is related to an import to a 'global import register'.
* This is needed because, unlike other regular tokens, we want to find imports that are
* in diferent contexts as being in the same context.
*
* @param found this is the Found that we want to add to the imports
* @param map this is the map that contains the imports Found occurrences (it has to be passed,
* as there is a map for the imports that are actually in the namespace and another for those
* that are 'artificially' generated).
*/
private void addFoundToImportsMap(Found found, Map<String, List<Tuple3<Found, Integer, ASTEntry>>> map) {
ImportInfo info = found.importInfo;
String modName = UNRESOLVED_MOD_NAME;
if (info != null && info.mod != null) {
modName = info.mod.getName();
}
List<Tuple3<Found, Integer, ASTEntry>> prev = map.get(modName);
if (prev == null) {
prev = new ArrayList<Tuple3<Found, Integer, ASTEntry>>();
map.put(modName, prev);
}
// col delta is undefined
prev.add(new Tuple3<Found, Integer, ASTEntry>(found, -1, peekParent()));
}
use of com.python.pydev.analysis.visitors.Found in project Pydev by fabioz.
the class ScopeAnalyzerVisitor method checkImportEntries.
/**
* Checks the import entries for imports that are the same as the one that should be already found.
*/
private void checkImportEntries(List<Tuple4<IToken, Integer, ASTEntry, Found>> ret, Set<IToken> f, List<Tuple3<Found, Integer, ASTEntry>> importEntries, int colDelta) {
if (importEntries != null) {
for (Tuple3<Found, Integer, ASTEntry> foundInFromModule : importEntries) {
IToken generator = foundInFromModule.o1.getSingle().generator;
Tuple4<IToken, Integer, ASTEntry, Found> tup3 = new Tuple4<IToken, Integer, ASTEntry, Found>(generator, colDelta > foundInFromModule.o2 ? colDelta : foundInFromModule.o2, foundInFromModule.o3, foundInFromModule.o1);
if (!f.contains(generator)) {
f.add(generator);
ret.add(tup3);
}
}
}
}
Aggregations