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;
}
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");
}
}
}
}
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);
}
Aggregations