Search in sources :

Example 1 with IInfo

use of org.python.pydev.core.IInfo in project Pydev by fabioz.

the class TreeIO method dumpTreeToBuffer.

/**
 * Tree is written as:
 * line 1= tree size
 * cub|2|CubeColourDialog!13&999@CUBIC!263@cube!202&999@
 */
public static void dumpTreeToBuffer(SortedMap<String, Set<IInfo>> tree, FastStringBuffer tempBuf, Map<String, Integer> strToInt) {
    Set<Entry<String, Set<IInfo>>> entrySet = tree.entrySet();
    Iterator<Entry<String, Set<IInfo>>> it = entrySet.iterator();
    tempBuf.append(entrySet.size());
    tempBuf.append('\n');
    while (it.hasNext()) {
        Entry<String, Set<IInfo>> next = it.next();
        tempBuf.append(next.getKey());
        Set<IInfo> value = next.getValue();
        tempBuf.append('|');
        tempBuf.append(value.size());
        tempBuf.append('|');
        Iterator<IInfo> it2 = value.iterator();
        Integer integer;
        while (it2.hasNext()) {
            IInfo info = it2.next();
            tempBuf.append(info.getName());
            tempBuf.append(NAME_CHAR_SEPARATOR);
            String path = info.getPath();
            if (path != null) {
                integer = strToInt.get(path);
                if (integer == null) {
                    integer = strToInt.size() + 1;
                    strToInt.put(path, integer);
                }
                tempBuf.append(integer);
                tempBuf.append(PATH_CHAR_SEPARATOR);
            }
            String file = info.getFile();
            if (file != null) {
                integer = strToInt.get(file);
                if (integer == null) {
                    integer = strToInt.size() + 1;
                    strToInt.put(file, integer);
                }
                tempBuf.append(integer);
                tempBuf.append(FILE_CHAR_SEPARATOR);
            }
            tempBuf.append(info.getLine());
            tempBuf.append(LINE_CHAR_SEPARATOR);
            tempBuf.append(info.getCol());
            tempBuf.append(COL_CHAR_SEPARATOR);
            String modName = info.getDeclaringModuleName();
            integer = strToInt.get(modName);
            if (integer == null) {
                integer = strToInt.size() + 1;
                strToInt.put(modName, integer);
            }
            int v = integer << 3;
            v |= info.getType();
            // Write a single for name+type
            tempBuf.append(v);
            tempBuf.append('@');
        }
        tempBuf.append('\n');
    }
    tempBuf.append("-- END TREE\n");
}
Also used : IInfo(org.python.pydev.core.IInfo) Entry(java.util.Map.Entry) Set(java.util.Set) HashSet(java.util.HashSet)

Example 2 with IInfo

use of org.python.pydev.core.IInfo in project Pydev by fabioz.

the class AbstractAdditionalDependencyInfo method addInfoToModuleOnRestoreInsertCommand.

protected void addInfoToModuleOnRestoreInsertCommand(Tuple<ModulesKey, List<IInfo>> data) {
    CompleteIndexKey key = new CompleteIndexKey(data.o1);
    if (data.o1.file != null) {
        key.lastModified = FileUtils.lastModified(data.o1.file);
    }
    completeIndex.add(key);
    // current way (saves a list of iinfo)
    for (Iterator<IInfo> it = data.o2.iterator(); it.hasNext(); ) {
        IInfo info = it.next();
        if (info.getPath() == null || info.getPath().length() == 0) {
            this.add(info, TOP_LEVEL);
        } else {
            this.add(info, INNER);
        }
    }
}
Also used : IInfo(org.python.pydev.core.IInfo) CompleteIndexKey(org.python.pydev.core.cache.CompleteIndexKey)

Example 3 with IInfo

use of org.python.pydev.core.IInfo in project Pydev by fabioz.

the class AbstractAdditionalDependencyInfo method addAstInfo.

@Override
public List<IInfo> addAstInfo(SimpleNode node, ModulesKey key, boolean generateDelta) {
    List<IInfo> addAstInfo = new ArrayList<IInfo>();
    if (node == null || key == null || key.name == null) {
        return addAstInfo;
    }
    try {
        synchronized (lock) {
            addAstInfo = super.addAstInfo(node, key, generateDelta);
            CompleteIndexKey completeIndexKey = new CompleteIndexKey(key);
            if (key.file != null) {
                completeIndexKey.lastModified = FileUtils.lastModified(key.file);
            }
            completeIndex.add(completeIndexKey);
        }
    } catch (Exception e) {
        Log.log(e);
    }
    return addAstInfo;
}
Also used : IInfo(org.python.pydev.core.IInfo) CompleteIndexKey(org.python.pydev.core.cache.CompleteIndexKey) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) MisconfigurationException(org.python.pydev.core.MisconfigurationException)

Example 4 with IInfo

use of org.python.pydev.core.IInfo in project Pydev by fabioz.

the class IOUtils method addAstInfo.

/**
 * Adds ast info information for a module.
 *
 * @param m the module we want to add to the info
 */
public List<IInfo> addAstInfo(SimpleNode node, ModulesKey key, boolean generateDelta) {
    List<IInfo> createdInfos = new ArrayList<IInfo>();
    if (node == null || key.name == null) {
        return createdInfos;
    }
    try {
        Tuple<DefinitionsASTIteratorVisitor, Iterator<ASTEntry>> tup = getInnerEntriesForAST(node);
        if (DebugSettings.DEBUG_ANALYSIS_REQUESTS) {
            org.python.pydev.shared_core.log.ToLogFile.toLogFile(this, "Adding ast info to: " + key.name);
        }
        try {
            Iterator<ASTEntry> entries = tup.o2;
            FastStack<SimpleNode> tempStack = new FastStack<SimpleNode>(10);
            synchronized (this.lock) {
                synchronized (ObjectsInternPool.lock) {
                    final String file = key.file != null ? ObjectsInternPool.internUnsynched(key.file.toString()) : null;
                    key.name = ObjectsInternPool.internUnsynched(key.name);
                    while (entries.hasNext()) {
                        ASTEntry entry = entries.next();
                        IInfo infoCreated = null;
                        if (entry.parent == null) {
                            // we only want those that are in the global scope
                            if (entry.node instanceof ClassDef) {
                                // no intern construct (locked in this loop)
                                NameTok name = (NameTok) ((ClassDef) entry.node).name;
                                ClassInfo info = new ClassInfo(ObjectsInternPool.internUnsynched(name.id), key.name, null, false, getNature(), file, name.beginLine, name.beginColumn);
                                add(info, TOP_LEVEL);
                                infoCreated = info;
                            } else if (entry.node instanceof FunctionDef) {
                                // no intern construct (locked in this loop)
                                NameTok name = (NameTok) ((FunctionDef) entry.node).name;
                                FuncInfo info2 = new FuncInfo(ObjectsInternPool.internUnsynched(name.id), key.name, null, false, getNature(), file, name.beginLine, name.beginColumn);
                                add(info2, TOP_LEVEL);
                                infoCreated = info2;
                            } else {
                                // it is an assign
                                infoCreated = this.addAssignTargets(entry, key.name, TOP_LEVEL, null, false, file);
                            }
                        } else {
                            if (entry.node instanceof ClassDef || entry.node instanceof FunctionDef) {
                                // ok, it has a parent, so, let's check to see if the path we got only has class definitions
                                // as the parent (and get that path)
                                Tuple<String, Boolean> pathToRoot = this.getPathToRoot(entry, false, false, tempStack);
                                if (pathToRoot != null && pathToRoot.o1 != null && pathToRoot.o1.length() > 0) {
                                    if (entry.node instanceof ClassDef) {
                                        NameTok name = ((NameTok) ((ClassDef) entry.node).name);
                                        ClassInfo info = new ClassInfo(ObjectsInternPool.internUnsynched(name.id), key.name, ObjectsInternPool.internUnsynched(pathToRoot.o1), false, getNature(), file, name.beginLine, name.beginColumn);
                                        add(info, INNER);
                                        infoCreated = info;
                                    } else {
                                        // FunctionDef
                                        NameTok name = ((NameTok) ((FunctionDef) entry.node).name);
                                        FuncInfo info2 = new FuncInfo(ObjectsInternPool.internUnsynched(name.id), key.name, ObjectsInternPool.internUnsynched(pathToRoot.o1), false, getNature(), file, name.beginLine, name.beginColumn);
                                        add(info2, INNER);
                                        infoCreated = info2;
                                    }
                                }
                            } else {
                                // it is an assign
                                Tuple<String, Boolean> pathToRoot = this.getPathToRoot(entry, true, false, tempStack);
                                if (pathToRoot != null && pathToRoot.o1 != null && pathToRoot.o1.length() > 0) {
                                    infoCreated = this.addAssignTargets(entry, key.name, INNER, pathToRoot.o1, pathToRoot.o2, file);
                                }
                            }
                        }
                        if (infoCreated != null) {
                            createdInfos.add(infoCreated);
                        }
                    }
                // end while
                }
            // end lock ObjectsPool.lock
            }
        // end this.lock
        } catch (Exception e) {
            Log.log(e);
        }
    } catch (Exception e) {
        Log.log(e);
    }
    return createdInfos;
}
Also used : FastStack(org.python.pydev.shared_core.structure.FastStack) ArrayList(java.util.ArrayList) FunctionDef(org.python.pydev.parser.jython.ast.FunctionDef) IOException(java.io.IOException) MisconfigurationException(org.python.pydev.core.MisconfigurationException) SimpleNode(org.python.pydev.parser.jython.SimpleNode) IInfo(org.python.pydev.core.IInfo) ClassDef(org.python.pydev.parser.jython.ast.ClassDef) Iterator(java.util.Iterator) ASTEntry(org.python.pydev.parser.visitors.scope.ASTEntry) DefinitionsASTIteratorVisitor(org.python.pydev.parser.visitors.scope.DefinitionsASTIteratorVisitor) NameTok(org.python.pydev.parser.jython.ast.NameTok)

Example 5 with IInfo

use of org.python.pydev.core.IInfo in project Pydev by fabioz.

the class IOUtils method getAllTokens.

/**
 * @return all the tokens that are in this info (top level or inner)
 */
public Collection<IInfo> getAllTokens() {
    synchronized (lock) {
        Collection<Set<IInfo>> lInfo = this.topLevelInitialsToInfo.values();
        ArrayList<IInfo> toks = new ArrayList<IInfo>();
        for (Set<IInfo> list : lInfo) {
            for (IInfo info : list) {
                toks.add(info);
            }
        }
        lInfo = this.innerInitialsToInfo.values();
        for (Set<IInfo> list : lInfo) {
            for (IInfo info : list) {
                toks.add(info);
            }
        }
        return toks;
    }
}
Also used : IInfo(org.python.pydev.core.IInfo) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList)

Aggregations

IInfo (org.python.pydev.core.IInfo)33 ArrayList (java.util.ArrayList)12 MisconfigurationException (org.python.pydev.core.MisconfigurationException)10 HashSet (java.util.HashSet)8 AbstractAdditionalTokensInfo (com.python.pydev.analysis.additionalinfo.AbstractAdditionalTokensInfo)6 Set (java.util.Set)6 FastStringBuffer (org.python.pydev.shared_core.string.FastStringBuffer)6 AdditionalSystemInterpreterInfo (com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo)5 ItemPointer (org.python.pydev.ast.item_pointer.ItemPointer)5 ICodeCompletionASTManager (org.python.pydev.core.ICodeCompletionASTManager)5 Entry (java.util.Map.Entry)4 IPythonNature (org.python.pydev.core.IPythonNature)4 Document (org.eclipse.jface.text.Document)3 CompareContext (org.python.pydev.ast.codecompletion.ProposalsComparator.CompareContext)3 SourceModule (org.python.pydev.ast.codecompletion.revisited.modules.SourceModule)3 InterpreterInfo (org.python.pydev.ast.interpreter_managers.InterpreterInfo)3 IInterpreterInfo (org.python.pydev.core.IInterpreterInfo)3 AbstractAdditionalDependencyInfo (com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo)2 AdditionalInfoAndIInfo (com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo)2 AdditionalProjectInterpreterInfo (com.python.pydev.analysis.additionalinfo.AdditionalProjectInterpreterInfo)2