Esempio n. 1
0
  public static Map<Integer, String> loadDictFrom(
      FastBufferedReader reader, FastStringBuffer buf, ObjectsPoolMap objectsPoolMap)
      throws IOException {
    int size = StringUtils.parsePositiveInt(reader.readLine());
    HashMap<Integer, String> map = new HashMap<Integer, String>(size + 5);

    FastStringBuffer line;
    int val = 0;
    while (true) {
      line = reader.readLine();
      if (line == null) {
        return map;

      } else if (line.startsWith("-- ")) {
        if (line.startsWith("-- END DICTIONARY")) {
          return map;
        }
        throw new RuntimeException("Unexpected line: " + line);

      } else {
        int length = line.length();
        // line is str=int
        for (int i = 0; i < length; i++) {
          char c = line.charAt(i);
          if (c == '=') {
            val = StringUtils.parsePositiveInt(buf);
            buf.clear();
          } else {
            buf.appendResizeOnExc(c);
          }
        }
        String bufStr = buf.toString();
        String interned = objectsPoolMap.get(bufStr);
        if (interned == null) {
          interned = bufStr;
          objectsPoolMap.put(bufStr, bufStr);
        }
        map.put(val, interned);
        buf.clear();
      }
    }
  }
Esempio n. 2
0
  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];
      // each line is something as: cub|CubeColourDialog!13&999@CUBIC!263@cube!202&999@
      // note: the path (2nd int in record) is optional
      for (int iEntry = 0; iEntry < size; iEntry++) {
        buf.clear();
        FastStringBuffer line = reader.readLine();
        if (line == null || line.startsWith("-- ")) {
          throw new RuntimeException("Unexpected line: " + line);
        }
        char[] internalCharsArray = line.getInternalCharsArray();
        int length = line.length();
        String key = null;
        String infoName = null;
        String path = null;

        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 '!':
              infoName = ObjectsInternPool.internLocal(objectsPoolMap, buf.toString());
              buf.clear();
              break;

            case '&':
              path = dictionary.get(StringUtils.parsePositiveInt(buf));
              buf.clear();
              break;

            case '@':
              int dictKey = StringUtils.parsePositiveInt(buf);
              byte type = (byte) dictKey;
              type &=
                  0x07; // leave only the 3 least significant bits there (this is the type -- value
              // from 0 - 8).

              dictKey =
                  (dictKey
                      >> 3); // the entry in the dict doesn't have the least significant bits there.
              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));
                  break;
                case IInfo.METHOD_WITH_IMPORT_TYPE:
                  set.add(new FuncInfo(infoName, moduleDeclared, path, false, nature));
                  break;
                case IInfo.ATTRIBUTE_WITH_IMPORT_TYPE:
                  set.add(new AttrInfo(infoName, moduleDeclared, path, false, nature));
                  break;
                case IInfo.NAME_WITH_IMPORT_TYPE:
                  set.add(new NameInfo(infoName, moduleDeclared, path, false, nature));
                  break;
                case IInfo.MOD_IMPORT_TYPE:
                  set.add(new ModInfo(infoName, false, nature));
                  break;
                default:
                  Log.log("Unexpected type: " + type);
              }
              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;
  }