Search in sources :

Example 1 with GenAndTok

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);
}
Also used : IToken(org.python.pydev.core.IToken) ScopeItems(com.python.pydev.analysis.visitors.ScopeItems) Found(com.python.pydev.analysis.visitors.Found) GenAndTok(com.python.pydev.analysis.visitors.GenAndTok)

Example 2 with GenAndTok

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;
}
Also used : ArrayList(java.util.ArrayList) Found(com.python.pydev.analysis.visitors.Found) GenAndTok(com.python.pydev.analysis.visitors.GenAndTok) Tuple4(org.python.pydev.shared_core.structure.Tuple4) IToken(org.python.pydev.core.IToken) ASTEntry(org.python.pydev.parser.visitors.scope.ASTEntry) HashSet(java.util.HashSet)

Example 3 with GenAndTok

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);
            }
        }
    }
}
Also used : Found(com.python.pydev.analysis.visitors.Found) GenAndTok(com.python.pydev.analysis.visitors.GenAndTok) IToken(org.python.pydev.core.IToken) ScopeItems(com.python.pydev.analysis.visitors.ScopeItems) SourceToken(org.python.pydev.ast.codecompletion.revisited.modules.SourceToken) Tuple(org.python.pydev.parser.jython.ast.Tuple)

Aggregations

Found (com.python.pydev.analysis.visitors.Found)3 GenAndTok (com.python.pydev.analysis.visitors.GenAndTok)3 IToken (org.python.pydev.core.IToken)3 ScopeItems (com.python.pydev.analysis.visitors.ScopeItems)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 SourceToken (org.python.pydev.ast.codecompletion.revisited.modules.SourceToken)1 Tuple (org.python.pydev.parser.jython.ast.Tuple)1 ASTEntry (org.python.pydev.parser.visitors.scope.ASTEntry)1 Tuple4 (org.python.pydev.shared_core.structure.Tuple4)1