use of org.python.pydev.ast.codecompletion.revisited.modules.SourceToken in project Pydev by fabioz.
the class OccurrencesVisitor method onFoundTokenAs.
@Override
protected void onFoundTokenAs(IToken token, Found foundAs) {
if (analyzeArgumentsMismatch) {
boolean reportFound = true;
try {
if (foundAs.importInfo != null) {
IDefinition[] definition = foundAs.importInfo.getDefinitions(nature, completionCache);
for (IDefinition iDefinition : definition) {
Definition d = (Definition) iDefinition;
if (d.ast instanceof FunctionDef || d.ast instanceof ClassDef) {
SourceToken tok = AbstractVisitor.makeToken(d.ast, token.getRepresentation(), d.module != null ? d.module.getName() : "", d.module != null ? d.module.getNature() : null);
tok.setDefinition(d);
onPushToRecordedFounds(tok);
reportFound = false;
break;
}
}
}
} catch (Exception e) {
Log.log(e);
}
if (reportFound) {
onPushToRecordedFounds(token);
}
}
}
use of org.python.pydev.ast.codecompletion.revisited.modules.SourceToken in project Pydev by fabioz.
the class AbstractScopeAnalyzerVisitor method visitAttribute.
/**
* visiting some attribute, as os.path or math().val or (10,10).__class__
*
* @see org.python.pydev.parser.jython.ast.VisitorIF#visitAttribute(org.python.pydev.parser.jython.ast.Attribute)
*/
@Override
public Object visitAttribute(Attribute node) throws Exception {
SourceToken token = AbstractVisitor.makeFullNameToken(node, moduleName, nature);
unhandled_node(node);
visitingAttributeStackI += 1;
if (visitingAttributeStackI == 1) {
// Mostly a cache helper so that we don't incur the cost of creating a new one every time we find
// an attribute, as only one will be active at any time when we start checking an attribute.
visitingAttributeStack = visitingAttributeStackCache;
}
String representation = token.getRepresentation();
int curr = visitingAttributeStack.increment(representation);
try {
boolean doReturn = visitNeededAttributeParts(node, this);
if (representation.length() == 0) {
return null;
}
if (doReturn) {
return null;
}
String fullRep = representation;
if (node.ctx == Attribute.Store || node.ctx == Attribute.NamedStore || node.ctx == Attribute.Param || node.ctx == Attribute.KwOnlyParam || node.ctx == Attribute.AugStore) {
// in a store attribute, the first part is always a load
int i = fullRep.indexOf('.', 0);
String sub = fullRep;
if (i > 0) {
sub = fullRep.substring(0, i);
}
markRead(token, sub, true, false);
} else if (node.ctx == Attribute.Load) {
Iterator<String> it = new FullRepIterable(fullRep).iterator();
boolean found = false;
while (it.hasNext()) {
String sub = it.next();
if (it.hasNext()) {
if (markRead(token, sub, false, false)) {
found = true;
}
} else {
// I.e.: if we're in a structure where an attribute visits another attribute, we'll only
// report as not defined if it's the last one (i.e.: the last one in the stack we created).
boolean addToNotDefined = !found && visitingAttributeStack.get(representation) == curr;
// only set it to add to not defined if it was still not found
markRead(token, fullRep, addToNotDefined, true);
}
}
}
} finally {
visitingAttributeStackI -= 1;
if (visitingAttributeStackI == 0) {
visitingAttributeStack.clear();
visitingAttributeStack = null;
}
}
return null;
}
use of org.python.pydev.ast.codecompletion.revisited.modules.SourceToken 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 org.python.pydev.ast.codecompletion.revisited.modules.SourceToken in project Pydev by fabioz.
the class AbstractScopeAnalyzerVisitor method findNameTok.
protected IToken findNameTok(IToken token, String tokToCheck) {
if (token instanceof SourceToken) {
SourceToken s = (SourceToken) token;
SimpleNode ast = s.getAst();
String searchFor = FullRepIterable.getLastPart(tokToCheck);
while (ast instanceof Attribute) {
Attribute a = (Attribute) ast;
if (((NameTok) a.attr).id.equals(searchFor)) {
return new SourceToken(a.attr, searchFor, "", "", token.getParentPackage(), nature);
} else if (a.value.toString().equals(searchFor)) {
return new SourceToken(a.value, searchFor, "", "", token.getParentPackage(), nature);
}
ast = a.value;
}
}
return token;
}
use of org.python.pydev.ast.codecompletion.revisited.modules.SourceToken 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;
}
Aggregations