Exemplo n.º 1
0
  public final ItemAuction[] getAuctions() {
    final ItemAuction[] auctions;

    synchronized (_auctions) {
      auctions = _auctions.getValues(new ItemAuction[_auctions.size()]);
    }

    return auctions;
  }
Exemplo n.º 2
0
 public TreeNode[] copyChildren() {
   return children.getValues(new TreeNode[children.size()]);
 }
  @Override
  @NotNull
  public List<TextEditorHighlightingPass> instantiatePasses(
      @NotNull final PsiFile psiFile,
      @NotNull final Editor editor,
      @NotNull final int[] passesToIgnore) {
    synchronized (this) {
      if (!checkedForCycles) {
        checkedForCycles = true;
        checkForCycles();
      }
    }
    PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
    final Document document = editor.getDocument();
    PsiFile fileFromDoc = documentManager.getPsiFile(document);
    if (!(fileFromDoc instanceof PsiCompiledElement)) {
      assert fileFromDoc == psiFile : "Files are different: " + psiFile + ";" + fileFromDoc;
      Document documentFromFile = documentManager.getDocument(psiFile);
      assert documentFromFile == document
          : "Documents are different. Doc: "
              + document
              + "; Doc from file: "
              + documentFromFile
              + "; File: "
              + psiFile
              + "; Virtual file: "
              + PsiUtilCore.getVirtualFile(psiFile);
    }
    final TIntObjectHashMap<TextEditorHighlightingPass> id2Pass =
        new TIntObjectHashMap<TextEditorHighlightingPass>();
    final TIntArrayList passesRefusedToCreate = new TIntArrayList();
    myRegisteredPassFactories.forEachKey(
        new TIntProcedure() {
          @Override
          public boolean execute(int passId) {
            if (ArrayUtil.find(passesToIgnore, passId) != -1) {
              return true;
            }
            PassConfig passConfig = myRegisteredPassFactories.get(passId);
            TextEditorHighlightingPassFactory factory = passConfig.passFactory;
            final TextEditorHighlightingPass pass = factory.createHighlightingPass(psiFile, editor);

            if (pass == null) {
              passesRefusedToCreate.add(passId);
            } else {
              // init with editor's colors scheme
              pass.setColorsScheme(editor.getColorsScheme());

              TIntArrayList ids = new TIntArrayList(passConfig.completionPredecessorIds.length);
              for (int id : passConfig.completionPredecessorIds) {
                if (myRegisteredPassFactories.containsKey(id)) ids.add(id);
              }
              pass.setCompletionPredecessorIds(
                  ids.isEmpty() ? ArrayUtil.EMPTY_INT_ARRAY : ids.toNativeArray());
              ids = new TIntArrayList(passConfig.startingPredecessorIds.length);
              for (int id : passConfig.startingPredecessorIds) {
                if (myRegisteredPassFactories.containsKey(id)) ids.add(id);
              }
              pass.setStartingPredecessorIds(
                  ids.isEmpty() ? ArrayUtil.EMPTY_INT_ARRAY : ids.toNativeArray());
              pass.setId(passId);
              id2Pass.put(passId, pass);
            }
            return true;
          }
        });

    DaemonCodeAnalyzerEx daemonCodeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(myProject);
    final FileStatusMap statusMap = daemonCodeAnalyzer.getFileStatusMap();
    passesRefusedToCreate.forEach(
        new TIntProcedure() {
          @Override
          public boolean execute(int passId) {
            statusMap.markFileUpToDate(document, passId);
            return true;
          }
        });

    return (List) Arrays.asList(id2Pass.getValues());
  }
Exemplo n.º 4
0
 private boolean allDirtyScopesAreNull() {
   for (Object o : dirtyScopes.getValues()) {
     if (o != null) return false;
   }
   return true;
 }
Exemplo n.º 5
0
  final void checkAndSetCurrentAndNextAuction() {
    final ItemAuction[] auctions = _auctions.getValues(new ItemAuction[_auctions.size()]);

    ItemAuction currentAuction = null;
    ItemAuction nextAuction = null;

    switch (auctions.length) {
      case 0:
        {
          nextAuction = createAuction(System.currentTimeMillis() + START_TIME_SPACE);
          break;
        }

      case 1:
        {
          switch (auctions[0].getAuctionState()) {
            case CREATED:
              {
                if (auctions[0].getStartingTime()
                    < (System.currentTimeMillis() + START_TIME_SPACE)) {
                  currentAuction = auctions[0];
                  nextAuction = createAuction(System.currentTimeMillis() + START_TIME_SPACE);
                } else {
                  nextAuction = auctions[0];
                }
                break;
              }

            case STARTED:
              {
                currentAuction = auctions[0];
                nextAuction =
                    createAuction(
                        Math.max(
                            currentAuction.getEndingTime() + FINISH_TIME_SPACE,
                            System.currentTimeMillis() + START_TIME_SPACE));
                break;
              }

            case FINISHED:
              {
                currentAuction = auctions[0];
                nextAuction = createAuction(System.currentTimeMillis() + START_TIME_SPACE);
                break;
              }

            default:
              throw new IllegalArgumentException();
          }
          break;
        }

      default:
        {
          Arrays.sort(
              auctions,
              new Comparator<ItemAuction>() {
                @Override
                public final int compare(final ItemAuction o1, final ItemAuction o2) {
                  return ((Long) o2.getStartingTime()).compareTo(o1.getStartingTime());
                }
              });

          // just to make sure we won`t skip any auction because of little different times
          final long currentTime = System.currentTimeMillis();

          for (int i = 0; i < auctions.length; i++) {
            final ItemAuction auction = auctions[i];
            if (auction.getAuctionState() == ItemAuctionState.STARTED) {
              currentAuction = auction;
              break;
            } else if (auction.getStartingTime() <= currentTime) {
              currentAuction = auction;
              break; // only first
            }
          }

          for (int i = 0; i < auctions.length; i++) {
            final ItemAuction auction = auctions[i];
            if (auction.getStartingTime() > currentTime && currentAuction != auction) {
              nextAuction = auction;
              break;
            }
          }

          if (nextAuction == null)
            nextAuction = createAuction(System.currentTimeMillis() + START_TIME_SPACE);
          break;
        }
    }

    _auctions.put(nextAuction.getAuctionId(), nextAuction);

    _currentAuction = currentAuction;
    _nextAuction = nextAuction;

    if (currentAuction != null && currentAuction.getAuctionState() != ItemAuctionState.FINISHED) {
      if (currentAuction.getAuctionState() == ItemAuctionState.STARTED)
        setStateTask(
            ThreadPoolManager.getInstance()
                .scheduleGeneral(
                    new ScheduleAuctionTask(currentAuction),
                    Math.max(currentAuction.getEndingTime() - System.currentTimeMillis(), 0L)));
      else
        setStateTask(
            ThreadPoolManager.getInstance()
                .scheduleGeneral(
                    new ScheduleAuctionTask(currentAuction),
                    Math.max(currentAuction.getStartingTime() - System.currentTimeMillis(), 0L)));
      _log.log(
          Level.INFO,
          "L2ItemAuctionInstance: Schedule current auction "
              + currentAuction.getAuctionId()
              + " for instance "
              + _instanceId);
    } else {
      setStateTask(
          ThreadPoolManager.getInstance()
              .scheduleGeneral(
                  new ScheduleAuctionTask(nextAuction),
                  Math.max(nextAuction.getStartingTime() - System.currentTimeMillis(), 0L)));
      _log.log(
          Level.INFO,
          "L2ItemAuctionInstance: Schedule next auction "
              + nextAuction.getAuctionId()
              + " on "
              + DATE_FORMAT.format(new Date(nextAuction.getStartingTime()))
              + " for instance "
              + _instanceId);
    }
  }