Search in sources :

Example 31 with IInfo

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

the class TreeIO method loadTreeFrom.

public static PyPublicTreeMap<String, Set<IInfo>> loadTreeFrom(final FastBufferedReader reader, final Map<Integer, String> dictionary, FastStringBuffer buf, ObjectsPoolMap objectsPoolMap, IPythonNature nature) throws IOException {
    PyPublicTreeMap<String, Set<IInfo>> tree = new PyPublicTreeMap<String, Set<IInfo>>();
    final int size = StringUtils.parsePositiveInt(reader.readLine());
    try {
        final Entry[] entries = new Entry[size];
        // note: the path (2nd int in record) is optional
        for (int iEntry = 0; iEntry < size; iEntry++) {
            buf.clear();
            FastStringBuffer readLine = reader.readLine();
            if (readLine == null || readLine.startsWith("-- ")) {
                throw new RuntimeException("Unexpected line: " + readLine);
            }
            char[] internalCharsArray = readLine.getInternalCharsArray();
            int length = readLine.length();
            String key = null;
            String infoName = null;
            String path = null;
            String file = null;
            int line = 0;
            int col = 0;
            int i = 0;
            OUT: for (; i < length; i++) {
                char c = internalCharsArray[i];
                switch(c) {
                    case '|':
                        key = ObjectsInternPool.internLocal(objectsPoolMap, buf.toString());
                        buf.clear();
                        i++;
                        break OUT;
                    default:
                        buf.appendResizeOnExc(c);
                }
            }
            int hashSize = 0;
            OUT2: for (; i < length; i++) {
                char c = internalCharsArray[i];
                switch(c) {
                    case '|':
                        hashSize = StringUtils.parsePositiveInt(buf);
                        buf.clear();
                        i++;
                        break OUT2;
                    default:
                        buf.appendResizeOnExc(c);
                }
            }
            HashSet<IInfo> set = new HashSet<IInfo>(hashSize);
            for (; i < length; i++) {
                char c = internalCharsArray[i];
                switch(c) {
                    case NAME_CHAR_SEPARATOR:
                        infoName = ObjectsInternPool.internLocal(objectsPoolMap, buf.toString());
                        buf.clear();
                        break;
                    case PATH_CHAR_SEPARATOR:
                        path = dictionary.get(StringUtils.parsePositiveInt(buf));
                        buf.clear();
                        break;
                    case FILE_CHAR_SEPARATOR:
                        file = dictionary.get(StringUtils.parsePositiveInt(buf));
                        buf.clear();
                        break;
                    case LINE_CHAR_SEPARATOR:
                        line = StringUtils.parsePositiveInt(buf);
                        buf.clear();
                        break;
                    case COL_CHAR_SEPARATOR:
                        col = StringUtils.parsePositiveInt(buf);
                        buf.clear();
                        break;
                    case END_IINFO_SEPARATOR:
                        int dictKey = StringUtils.parsePositiveInt(buf);
                        byte type = (byte) dictKey;
                        // leave only the 3 least significant bits there (this is the type -- value from 0 - 8).
                        type &= 0x07;
                        // the entry in the dict doesn't have the least significant bits there.
                        dictKey = (dictKey >> 3);
                        buf.clear();
                        String moduleDeclared = dictionary.get(dictKey);
                        if (moduleDeclared == null) {
                            throw new AssertionError("Unable to find key: " + dictKey);
                        }
                        if (infoName == null) {
                            throw new AssertionError("Info name may not be null. Line: " + line);
                        }
                        switch(type) {
                            case IInfo.CLASS_WITH_IMPORT_TYPE:
                                set.add(new ClassInfo(infoName, moduleDeclared, path, false, nature, file, line, col));
                                break;
                            case IInfo.METHOD_WITH_IMPORT_TYPE:
                                set.add(new FuncInfo(infoName, moduleDeclared, path, false, nature, file, line, col));
                                break;
                            case IInfo.ATTRIBUTE_WITH_IMPORT_TYPE:
                                set.add(new AttrInfo(infoName, moduleDeclared, path, false, nature, file, line, col));
                                break;
                            case IInfo.NAME_WITH_IMPORT_TYPE:
                                set.add(new NameInfo(infoName, moduleDeclared, path, false, nature, file, line, col));
                                break;
                            case IInfo.MOD_IMPORT_TYPE:
                                set.add(new ModInfo(infoName, false, nature, file, line, col));
                                break;
                            default:
                                Log.log("Unexpected type: " + type);
                        }
                        file = null;
                        infoName = null;
                        path = null;
                        file = null;
                        line = 0;
                        col = 0;
                        break;
                    default:
                        buf.appendResizeOnExc(c);
                }
            }
            entries[iEntry] = new MapEntry(key, set);
        }
        tree.buildFromSorted(size, new Iterator() {

            private int iNext;

            @Override
            public boolean hasNext() {
                return iNext > size;
            }

            @Override
            public Object next() {
                Object o = entries[iNext];
                iNext++;
                return o;
            }

            @Override
            public void remove() {
            }
        }, null, null);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
    return tree;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) PyPublicTreeMap(org.python.pydev.ast.codecompletion.revisited.PyPublicTreeMap) Entry(java.util.Map.Entry) Iterator(java.util.Iterator) HashSet(java.util.HashSet) FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer) IInfo(org.python.pydev.core.IInfo)

Example 32 with IInfo

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

the class IOUtils method entrySetToString.

/**
 * @param buffer
 * @param name
 */
private void entrySetToString(FastStringBuffer buffer, Set<Entry<String, Set<IInfo>>> name) {
    synchronized (lock) {
        for (Entry<String, Set<IInfo>> entry : name) {
            Set<IInfo> value = entry.getValue();
            for (IInfo info : value) {
                buffer.append(info.toString());
                buffer.append("\n");
            }
        }
    }
}
Also used : IInfo(org.python.pydev.core.IInfo) HashSet(java.util.HashSet) Set(java.util.Set)

Example 33 with IInfo

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

the class SearchTest method testSearchParameter.

public void testSearchParameter() throws Exception {
    // class Param(object): - this is line 0
    // 
    // def hasParams(self, aa, bb):
    // #TestStatic has static1 and static2
    // print aa.static1() - line 4
    // print aa.static2()
    List<IInfo> tokens = AdditionalProjectInterpreterInfo.getTokensEqualTo("static1", nature, AbstractAdditionalTokensInfo.TOP_LEVEL | AbstractAdditionalTokensInfo.INNER);
    // if this fails, the cache is outdated (i.e.: delete AdditionalProjectInterpreterInfo.pydevinfo)
    assertEquals(1, tokens.size());
    String line = "print aa.static1()";
    final File file = new File(TestDependent.TEST_PYSRC_TESTING_LOC + "extendable/parameters.py");
    RefactoringRequest refactoringRequest = createRefactoringRequest(line, file);
    refactoringRequest.ps = new PySelection(refactoringRequest.getDoc(), 4, line.length());
    ItemPointer[] pointers = refactorer.findDefinition(refactoringRequest);
    assertEquals(1, pointers.length);
    assertEquals(new File(TestDependent.TEST_PYSRC_TESTING_LOC + "extendable/static.py"), pointers[0].file);
    // found the module
    assertEquals(3, pointers[0].start.line);
    assertEquals(8, pointers[0].start.column);
}
Also used : IInfo(org.python.pydev.core.IInfo) RefactoringRequest(org.python.pydev.ast.refactoring.RefactoringRequest) PySelection(org.python.pydev.core.docutils.PySelection) File(java.io.File) ItemPointer(org.python.pydev.ast.item_pointer.ItemPointer)

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