Пример #1
0
 private void process(BasicBlock bb, TIntArrayList locks) {
   int n = bb.size();
   int k = locks.size();
   for (int i = 0; i < n; i++) {
     Quad q = bb.getQuad(i);
     Operator op = q.getOperator();
     if (op instanceof Monitor) {
       if (op instanceof MONITORENTER) {
         TIntArrayList locks2 = new TIntArrayList(k + 1);
         for (int j = 0; j < k; j++) locks2.add(locks.get(j));
         int lIdx = domL.indexOf(q);
         assert (lIdx >= 0);
         locks2.add(lIdx);
         locks = locks2;
         k++;
       } else {
         k--;
         TIntArrayList locks2 = new TIntArrayList(k);
         for (int j = 0; j < k; j++) locks2.add(locks.get(j));
         locks = locks2;
       }
     } else if (op.isHeapInst() && k > 0) {
       int eIdx = domE.indexOf(q);
       assert (eIdx >= 0);
       add(locks.get(k - 1), eIdx);
     }
   }
   for (Object o : bb.getSuccessors()) {
     BasicBlock bb2 = (BasicBlock) o;
     if (!visited.contains(bb2)) {
       visited.add(bb2);
       process(bb2, locks);
     }
   }
 }
 @Override
 public void save(final DataOutput out, final TIntArrayList value) throws IOException {
   int size = value.size();
   if (size == 0) {
     DataInputOutputUtil.writeSINT(out, Integer.MAX_VALUE);
   } else if (size == 1) {
     DataInputOutputUtil.writeSINT(out, -value.get(0));
   } else {
     DataInputOutputUtil.writeSINT(out, size);
     for (int i = 0; i < size; i++) {
       DataInputOutputUtil.writeINT(out, value.get(i));
     }
   }
 }
Пример #3
0
  public void act() {
    Message message_NF;
    Message message_LFF;
    Message message_LFS;
    // Link failure handling
    if (failure_type == Link_F) {
      message_LFF = new Message(Values.interruptMessage, Values.ReachLoss, second_node);
      kernel.schedule(
          new ArrivalEventV2(first_node, message_LFF, kernel, GetTime.getNextSchedule(kernel)));
      message_LFS = new Message(Values.interruptMessage, Values.ReachLoss, first_node);
      kernel.schedule(
          new ArrivalEventV2(second_node, message_LFS, kernel, GetTime.getNextSchedule(kernel)));
    }
    // Node failure handling
    else {
      if (failure_type == Node_F) {
        NodeV2 Failed_Node = Topology.getNodeByAddressV2(failed_node);
        adjacenes = (TIntArrayList) (Failed_Node.getAdjacenes().clone());
        Failed_Node.eraseState();
        message_NF = new Message(Values.interruptMessage, Values.ReachLoss, failed_node);

        for (int i = 0; i < adjacenes.size(); i++) {
          kernel.schedule(
              new ArrivalEventV2(
                  adjacenes.get(i), message_NF, kernel, GetTime.getNextSchedule(kernel)));
        }
      } else {

      }
    }
  }
  private void applyChildrenChangeEvents(VirtualFile parent, List<VFileEvent> events) {
    final NewVirtualFileSystem delegate = getDelegate(parent);
    TIntArrayList childrenIdsUpdated = new TIntArrayList();
    List<VirtualFile> childrenToBeUpdated = new SmartList<VirtualFile>();

    assert parent != null && parent != mySuperRoot;
    final int parentId = getFileId(parent);
    assert parentId != 0;
    TIntHashSet parentChildrenIds = new TIntHashSet(FSRecords.list(parentId));
    boolean hasRemovedChildren = false;

    for (VFileEvent event : events) {
      if (event instanceof VFileCreateEvent) {
        String name = ((VFileCreateEvent) event).getChildName();
        final VirtualFile fake = new FakeVirtualFile(parent, name);
        final FileAttributes attributes = delegate.getAttributes(fake);

        if (attributes != null) {
          final int childId = createAndFillRecord(delegate, fake, parentId, attributes);
          assert parent instanceof VirtualDirectoryImpl : parent;
          final VirtualDirectoryImpl dir = (VirtualDirectoryImpl) parent;
          VirtualFileSystemEntry child = dir.createChild(name, childId, dir.getFileSystem());
          childrenToBeUpdated.add(child);
          childrenIdsUpdated.add(childId);
          parentChildrenIds.add(childId);
        }
      } else if (event instanceof VFileDeleteEvent) {
        VirtualFile file = ((VFileDeleteEvent) event).getFile();
        if (!file.exists()) {
          LOG.error("Deleting a file, which does not exist: " + file.getPath());
          continue;
        }

        hasRemovedChildren = true;
        int id = getFileId(file);

        childrenToBeUpdated.add(file);
        childrenIdsUpdated.add(-id);
        parentChildrenIds.remove(id);
      }
    }

    FSRecords.updateList(parentId, parentChildrenIds.toArray());

    if (hasRemovedChildren) clearIdCache();
    VirtualDirectoryImpl parentImpl = (VirtualDirectoryImpl) parent;

    for (int i = 0, len = childrenIdsUpdated.size(); i < len; ++i) {
      final int childId = childrenIdsUpdated.get(i);
      final VirtualFile childFile = childrenToBeUpdated.get(i);

      if (childId > 0) {
        parentImpl.addChild((VirtualFileSystemEntry) childFile);
      } else {
        FSRecords.deleteRecordRecursively(-childId);
        parentImpl.removeChild(childFile);
        invalidateSubtree(childFile);
      }
    }
  }
Пример #5
0
 private void onTextLayoutPerformed(int startOffset, int endOffset) {
   if (checkDirty()) return;
   boolean purePaintingMode = myEditor.isPurePaintingMode();
   boolean foldingEnabled = myEditor.getFoldingModel().isFoldingEnabled();
   myEditor.setPurePaintingMode(false);
   myEditor.getFoldingModel().setFoldingEnabled(true);
   try {
     int startVisualLine = myView.offsetToVisualLine(startOffset, false);
     int endVisualLine = myView.offsetToVisualLine(endOffset, true);
     boolean sizeInvalidated = false;
     for (int i = startVisualLine; i <= endVisualLine; i++) {
       if (myLineWidths.get(i) < 0) {
         myLineWidths.set(i, UNKNOWN_WIDTH);
         sizeInvalidated = true;
       }
     }
     if (sizeInvalidated) {
       myWidthInPixels = -1;
       myEditor.getContentComponent().revalidate();
     }
   } finally {
     myEditor.setPurePaintingMode(purePaintingMode);
     myEditor.getFoldingModel().setFoldingEnabled(foldingEnabled);
   }
 }
  public static boolean checkParametersNumber(
      @NotNull List<CandidateInfo> conflicts,
      final int argumentsCount,
      boolean ignoreIfStaticsProblem) {
    boolean atLeastOneMatch = false;
    TIntArrayList unmatchedIndices = null;
    for (int i = 0; i < conflicts.size(); i++) {
      ProgressManager.checkCanceled();
      CandidateInfo info = conflicts.get(i);
      if (ignoreIfStaticsProblem && !info.isStaticsScopeCorrect()) return true;
      if (!(info instanceof MethodCandidateInfo)) continue;
      PsiMethod method = ((MethodCandidateInfo) info).getElement();
      if (method.isVarArgs()) return true;
      if (method.getParameterList().getParametersCount() == argumentsCount) {
        // remove all unmatched before
        if (unmatchedIndices != null) {
          for (int u = unmatchedIndices.size() - 1; u >= 0; u--) {
            int index = unmatchedIndices.get(u);
            conflicts.remove(index);
            i--;
          }
          unmatchedIndices = null;
        }
        atLeastOneMatch = true;
      } else if (atLeastOneMatch) {
        conflicts.remove(i);
        i--;
      } else {
        if (unmatchedIndices == null) unmatchedIndices = new TIntArrayList(conflicts.size() - i);
        unmatchedIndices.add(i);
      }
    }

    return atLeastOneMatch;
  }
  @Override
  public String getInstalledPluginNameByPath(Project project, @NotNull VirtualFile pluginPath) {
    String nameFromPluginXml = super.getInstalledPluginNameByPath(project, pluginPath);
    if (nameFromPluginXml != null) {
      return nameFromPluginXml;
    }

    VirtualFile pluginJson = pluginPath.findChild("plugin.json");
    if (pluginJson != null) {
      String pluginAndVersion = pluginPath.getName(); // pluginName-version

      TIntArrayList separatorIndexes = new TIntArrayList();
      int start = -1;
      while (true) {
        start = pluginAndVersion.indexOf('-', start + 1);
        if (start == -1) break;
        separatorIndexes.add(start);
      }

      if (separatorIndexes.size() == 1) {
        return pluginAndVersion.substring(0, separatorIndexes.get(0));
      }

      if (separatorIndexes.size() > 0) {
        String json;
        try {
          json = VfsUtil.loadText(pluginJson);
        } catch (IOException e) {
          return null;
        }

        for (int i = 0; i < separatorIndexes.size(); i++) {
          int idx = separatorIndexes.get(i);
          String name = pluginAndVersion.substring(0, idx);
          String version = pluginAndVersion.substring(idx + 1);

          if (hasValue(PLUGIN_NAME_JSON_PATTERN, json, name)
              && hasValue(PLUGIN_VERSION_JSON_PATTERN, json, version)) {
            return name;
          }
        }
      }
    }

    return null;
  }
Пример #8
0
  @Nullable
  private VirtualFileSystemEntry findFileById(
      int id, boolean cachedOnly, TIntArrayList visited, int mask) {
    VirtualFileSystemEntry cached = myIdToDirCache.get(id);
    if (cached != null) return cached;

    if (visited != null
        && (visited.size() >= DEPTH_LIMIT || (mask & id) == id && visited.contains(id))) {
      @NonNls
      String sb =
          "Dead loop detected in persistent FS (id=" + id + " cached-only=" + cachedOnly + "):";
      for (int i = 0; i < visited.size(); i++) {
        int _id = visited.get(i);
        sb +=
            "\n  "
                + _id
                + " '"
                + getName(_id)
                + "' "
                + String.format("%02x", getFileAttributes(_id))
                + ' '
                + myIdToDirCache.containsKey(_id);
      }
      LOG.error(sb);
      return null;
    }

    int parentId = getParent(id);
    if (parentId >= id) {
      if (visited == null) visited = new TIntArrayList(DEPTH_LIMIT);
    }
    if (visited != null) visited.add(id);

    VirtualFileSystemEntry result;
    if (parentId == 0) {
      myRootsLock.readLock().lock();
      try {
        result = myRootsById.get(id);
      } finally {
        myRootsLock.readLock().unlock();
      }
    } else {
      VirtualFileSystemEntry parentFile = findFileById(parentId, cachedOnly, visited, mask | id);
      if (parentFile instanceof VirtualDirectoryImpl) {
        result = ((VirtualDirectoryImpl) parentFile).findChildById(id, cachedOnly);
      } else {
        result = null;
      }
    }

    if (result != null && result.isDirectory()) {
      VirtualFileSystemEntry old = myIdToDirCache.put(id, result);
      if (old != null) result = old;
    }
    return result;
  }
 void lineLayoutCreated(int logicalLine) {
   int startVisualLine =
       myView.offsetToVisualLine(myDocument.getLineStartOffset(logicalLine), false);
   int endVisualLine = myView.offsetToVisualLine(myDocument.getLineEndOffset(logicalLine), false);
   boolean sizeInvalidated = false;
   for (int i = startVisualLine; i <= endVisualLine; i++) {
     if (myLineWidths.get(i) < 0) {
       myLineWidths.set(i, UNKNOWN_WIDTH);
       sizeInvalidated = true;
     }
   }
   if (sizeInvalidated) {
     myWidthInPixels = -1;
     myEditor.getContentComponent().revalidate();
   }
 }
Пример #10
0
 private int calculatePreferredWidth() {
   if (checkDirty()) return 1;
   assertValidState();
   VisualLinesIterator iterator = new VisualLinesIterator(myView, 0);
   int maxWidth = 0;
   while (!iterator.atEnd()) {
     int visualLine = iterator.getVisualLine();
     int width = myLineWidths.get(visualLine);
     if (width == UNKNOWN_WIDTH) {
       final Ref<Boolean> approximateValue = new Ref<Boolean>(Boolean.FALSE);
       width = getVisualLineWidth(iterator, () -> approximateValue.set(Boolean.TRUE));
       if (approximateValue.get()) width = -width;
       myLineWidths.set(visualLine, width);
     }
     maxWidth = Math.max(maxWidth, Math.abs(width));
     iterator.advance();
   }
   return maxWidth;
 }
Пример #11
0
  /**
   * It's possible that we need to expand quick doc control's width in order to provide better
   * visual representation (see http://youtrack.jetbrains.com/issue/IDEA-101425). This method
   * calculates that width expand.
   *
   * @param buttonWidth icon button's width
   * @param updatedText text which will be should at the quick doc control
   * @return width increase to apply to the target quick doc control (zero if no additional width
   *     increase is required)
   */
  private static int calculateWidthIncrease(int buttonWidth, String updatedText) {
    int maxLineWidth = 0;
    TIntArrayList lineWidths = new TIntArrayList();
    for (String lineText : StringUtil.split(updatedText, "<br/>")) {
      String html = HintUtil.prepareHintText(lineText, HintUtil.getInformationHint());
      int width = new JLabel(html).getPreferredSize().width;
      maxLineWidth = Math.max(maxLineWidth, width);
      lineWidths.add(width);
    }

    if (!lineWidths.isEmpty()) {
      int firstLineAvailableTrailingWidth = maxLineWidth - lineWidths.get(0);
      if (firstLineAvailableTrailingWidth >= buttonWidth) {
        return 0;
      } else {
        return buttonWidth - firstLineAvailableTrailingWidth;
      }
    }
    return 0;
  }
 private int calculatePreferredWidth() {
   int lineCount = myLineWidths.size();
   int maxWidth = 0;
   for (int i = 0; i < lineCount; i++) {
     int width = myLineWidths.get(i);
     if (width == UNKNOWN_WIDTH) {
       myApproximateWidthCalculated = false;
       myView.getTextLayoutCache().enableQuickLayouts(true);
       try {
         width = myView.getMaxWidthInLineRange(i, i);
       } finally {
         myView.getTextLayoutCache().enableQuickLayouts(false);
       }
       if (myApproximateWidthCalculated) width = -width;
       myLineWidths.set(i, width);
     }
     maxWidth = Math.max(maxWidth, Math.abs(width));
   }
   return maxWidth;
 }
Пример #13
0
    @SuppressWarnings("AssignmentToForLoopParameter")
    @Override
    public void replace(
        @NotNull ArrangementEntryWrapper<E> newWrapper,
        @NotNull ArrangementEntryWrapper<E> oldWrapper,
        @Nullable ArrangementEntryWrapper<E> previous,
        @NotNull Context<E> context) {
      // Calculate blank lines before the arrangement.
      int blankLinesBefore = 0;
      TIntArrayList lineFeedOffsets = new TIntArrayList();
      int oldStartLine = context.document.getLineNumber(oldWrapper.getStartOffset());
      if (oldStartLine > 0) {
        int lastLineFeed = context.document.getLineStartOffset(oldStartLine) - 1;
        lineFeedOffsets.add(lastLineFeed);
        for (int i = lastLineFeed - 1 - myParentShift; i >= 0; i--) {
          i = CharArrayUtil.shiftBackward(myParentText, i, " \t");
          if (myParentText.charAt(i) == '\n') {
            blankLinesBefore++;
            lineFeedOffsets.add(i + myParentShift);
          } else {
            break;
          }
        }
      }

      ArrangementEntryWrapper<E> parentWrapper = oldWrapper.getParent();
      int desiredBlankLinesNumber =
          context.rearranger.getBlankLines(
              context.settings,
              parentWrapper == null ? null : parentWrapper.getEntry(),
              previous == null ? null : previous.getEntry(),
              newWrapper.getEntry());
      if (desiredBlankLinesNumber == blankLinesBefore && newWrapper.equals(oldWrapper)) {
        return;
      }

      String newEntryText =
          myParentText.substring(
              newWrapper.getStartOffset() - myParentShift,
              newWrapper.getEndOffset() - myParentShift);
      int lineFeedsDiff = desiredBlankLinesNumber - blankLinesBefore;
      if (lineFeedsDiff == 0 || desiredBlankLinesNumber < 0) {
        context.addMoveInfo(
            newWrapper.getStartOffset() - myParentShift,
            newWrapper.getEndOffset() - myParentShift,
            oldWrapper.getStartOffset());
        context.document.replaceString(
            oldWrapper.getStartOffset(), oldWrapper.getEndOffset(), newEntryText);
        return;
      }

      if (lineFeedsDiff > 0) {
        // Insert necessary number of blank lines.
        StringBuilder buffer = new StringBuilder(StringUtil.repeat("\n", lineFeedsDiff));
        buffer.append(newEntryText);
        context.document.replaceString(
            oldWrapper.getStartOffset(), oldWrapper.getEndOffset(), buffer);
      } else {
        // Cut exceeding blank lines.
        int replacementStartOffset = lineFeedOffsets.get(-lineFeedsDiff) + 1;
        context.document.replaceString(
            replacementStartOffset, oldWrapper.getEndOffset(), newEntryText);
      }

      // Update wrapper ranges.
      ArrangementEntryWrapper<E> parent = oldWrapper.getParent();
      if (parent == null) {
        return;
      }

      Deque<ArrangementEntryWrapper<E>> parents = new ArrayDeque<ArrangementEntryWrapper<E>>();
      do {
        parents.add(parent);
        parent.setEndOffset(parent.getEndOffset() + lineFeedsDiff);
        parent = parent.getParent();
      } while (parent != null);

      while (!parents.isEmpty()) {

        for (ArrangementEntryWrapper<E> wrapper = parents.removeLast().getNext();
            wrapper != null;
            wrapper = wrapper.getNext()) {
          wrapper.applyShift(lineFeedsDiff);
        }
      }
    }