Exemple #1
0
  private void calculateBuckets(
      Set<? extends Person> persons,
      DynamicDoubleArray sums,
      DynamicIntArray counts,
      String xAttrKey,
      String yAttrKey) {
    TIntDoubleHashMap sumBuckets = new TIntDoubleHashMap();
    TIntIntHashMap countBuckets = new TIntIntHashMap();

    for (Person person : persons) {
      String xValStr = person.getAttribute(xAttrKey);
      String yValStr = person.getAttribute(yAttrKey);

      if (xValStr != null && yValStr != null) {
        double xVal = Double.parseDouble(xValStr);
        double yVal = Double.parseDouble(yValStr);

        int bucketIdx = xDataDiscr.index(xVal);

        sumBuckets.adjustOrPutValue(bucketIdx, yVal, yVal);
        countBuckets.adjustOrPutValue(bucketIdx, 1, 1);
      }
    }

    TIntDoubleIterator it = sumBuckets.iterator();
    for (int i = 0; i < sumBuckets.size(); i++) {
      it.advance();
      int bucketIndex = it.key();
      double sum = it.value();
      int cnt = countBuckets.get(bucketIndex);

      sums.set(bucketIndex, sum);
      counts.set(bucketIndex, cnt);
    }
  }
 @Override
 public void setLightLevel(int id, short data, int level) {
   if (!originalLight.containsKey(id)) {
     originalLight.put(id, getLightLevel(id, data));
   }
   net.minecraft.server.Block.s[id] = level;
 }
 @Override
 public void setOpaque(int id, short data, boolean opacity) {
   if (!originalOpacity.containsKey(id)) {
     originalOpacity.put(id, isOpaque(id, data) ? 1 : 0);
   }
   net.minecraft.server.Block.o[id] = opacity;
 }
  public void count() {

    TIntIntHashMap docCounts = new TIntIntHashMap();

    int index = 0;

    if (instances.size() == 0) {
      logger.info("Instance list is empty");
      return;
    }

    if (instances.get(0).getData() instanceof FeatureSequence) {

      for (Instance instance : instances) {
        FeatureSequence features = (FeatureSequence) instance.getData();

        for (int i = 0; i < features.getLength(); i++) {
          docCounts.adjustOrPutValue(features.getIndexAtPosition(i), 1, 1);
        }

        int[] keys = docCounts.keys();
        for (int i = 0; i < keys.length - 1; i++) {
          int feature = keys[i];
          featureCounts[feature] += docCounts.get(feature);
          documentFrequencies[feature]++;
        }

        docCounts = new TIntIntHashMap();

        index++;
        if (index % 1000 == 0) {
          System.err.println(index);
        }
      }
    } else if (instances.get(0).getData() instanceof FeatureVector) {

      for (Instance instance : instances) {
        FeatureVector features = (FeatureVector) instance.getData();

        for (int location = 0; location < features.numLocations(); location++) {
          int feature = features.indexAtLocation(location);
          double value = features.valueAtLocation(location);

          documentFrequencies[feature]++;
          featureCounts[feature] += value;
        }

        index++;
        if (index % 1000 == 0) {
          System.err.println(index);
        }
      }
    } else {
      logger.info("Unsupported data class: " + instances.get(0).getData().getClass().getName());
    }
  }
 public void setCustomItemBlock(int id, Integer blockId, Short metaData) {
   if (blockId != null || metaData == null) {
     itemBlock.put(id, blockId);
     itemMetaData.put(id, metaData);
   } else {
     itemBlock.remove(id);
     itemMetaData.remove(id);
   }
   updateCustomClientData(id);
 }
 @NotNull
 private static TIntIntHashMap getCommitsMap(@NotNull Iterable<Integer> hashes) {
   TIntIntHashMap commits = new TIntIntHashMap();
   int row = 0;
   for (Integer commitId : hashes) {
     commits.put(commitId, row);
     row++;
   }
   return commits;
 }
  private void collectNonCoveredFileInfo(
      final File outputFile,
      final List<RangeHighlighter> highlighters,
      final MarkupModel markupModel,
      final TreeMap<Integer, LineData> executableLines,
      final boolean coverageByTestApplicable) {
    final CoverageSuitesBundle coverageSuite =
        CoverageDataManager.getInstance(myProject).getCurrentSuitesBundle();
    if (coverageSuite == null) return;
    final TIntIntHashMap mapping;
    if (outputFile.lastModified() < getVirtualFile().getTimeStamp()) {
      mapping = getOldToNewLineMapping(outputFile.lastModified());
      if (mapping == null) return;
    } else {
      mapping = null;
    }

    final List<Integer> uncoveredLines =
        coverageSuite
            .getCoverageEngine()
            .collectSrcLinesForUntouchedFile(outputFile, coverageSuite);

    final int lineCount = myDocument.getLineCount();
    if (uncoveredLines == null) {
      for (int lineNumber = 0; lineNumber < lineCount; lineNumber++) {
        addHighlighter(
            outputFile,
            highlighters,
            markupModel,
            executableLines,
            coverageByTestApplicable,
            coverageSuite,
            lineNumber,
            lineNumber);
      }
    } else {
      for (int lineNumber : uncoveredLines) {
        if (lineNumber >= lineCount) {
          continue;
        }

        final int updatedLineNumber = mapping != null ? mapping.get(lineNumber) : lineNumber;

        addHighlighter(
            outputFile,
            highlighters,
            markupModel,
            executableLines,
            coverageByTestApplicable,
            coverageSuite,
            lineNumber,
            updatedLineNumber);
      }
    }
  }
 private void sortCommitsByRow(
     @NotNull List<T> result, @NotNull final TIntIntHashMap rowsForCommits) {
   ContainerUtil.sort(
       result,
       (details1, details2) -> {
         int row1 =
             rowsForCommits.get(myHashMap.getCommitIndex(details1.getId(), details1.getRoot()));
         int row2 =
             rowsForCommits.get(myHashMap.getCommitIndex(details2.getId(), details2.getRoot()));
         return Comparing.compare(row1, row2);
       });
 }
  private void runLoadCommitsData(@NotNull Iterable<Integer> hashes) {
    long taskNumber = myCurrentTaskIndex++;
    TIntIntHashMap commits = getCommitsMap(hashes);
    TIntHashSet toLoad = new TIntHashSet();

    for (int id : commits.keys()) {
      cacheCommit(id, taskNumber);
      toLoad.add(id);
    }

    myLoader.queue(new TaskDescriptor(toLoad));
  }
  private int computeTextWidth(@NotNull Font font, final boolean mainTextOnly) {
    int result = 0;
    int baseSize = font.getSize();
    boolean wasSmaller = false;
    for (int i = 0; i < myAttributes.size(); i++) {
      SimpleTextAttributes attributes = myAttributes.get(i);
      boolean isSmaller = attributes.isSmaller();
      if (font.getStyle() != attributes.getFontStyle()
          || isSmaller != wasSmaller) { // derive font only if it is necessary
        font =
            font.deriveFont(
                attributes.getFontStyle(),
                isSmaller ? UIUtil.getFontSize(UIUtil.FontSize.SMALL) : baseSize);
      }
      wasSmaller = isSmaller;

      result += computeStringWidth(i, font);

      final int fixedWidth = myFragmentPadding.get(i);
      if (fixedWidth > 0 && result < fixedWidth) {
        result = fixedWidth;
      }
      if (mainTextOnly && myMainTextLastIndex >= 0 && i == myMainTextLastIndex) break;
    }
    return result;
  }
Exemple #11
0
 /**
  * Tries to calculate given line's indent column assuming that there might be a comment at the
  * given indent offset (see {@link #getCommentPrefix(IElementType)}).
  *
  * @param line target line
  * @param indentOffset start indent offset to use for the given line
  * @param lineEndOffset given line's end offset
  * @param fallbackColumn column to return if it's not possible to apply comment-specific indent
  *     calculation rules
  * @return given line's indent column to use
  */
 private int calcIndent(int line, int indentOffset, int lineEndOffset, int fallbackColumn) {
   final HighlighterIterator it = myEditor.getHighlighter().createIterator(indentOffset);
   IElementType tokenType = it.getTokenType();
   Language language = tokenType.getLanguage();
   TokenSet comments = myComments.get(language);
   if (comments == null) {
     ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
     if (definition != null) {
       comments = definition.getCommentTokens();
     }
     if (comments == null) {
       return fallbackColumn;
     } else {
       myComments.put(language, comments);
     }
   }
   if (comments.contains(tokenType) && indentOffset == it.getStart()) {
     String prefix = COMMENT_PREFIXES.get(tokenType);
     if (prefix == null) {
       prefix = getCommentPrefix(tokenType);
     }
     if (!NO_COMMENT_INFO_MARKER.equals(prefix)) {
       final int indentInsideCommentOffset =
           CharArrayUtil.shiftForward(
               myChars, indentOffset + prefix.length(), lineEndOffset, " \t");
       if (indentInsideCommentOffset < lineEndOffset) {
         int indent = myEditor.calcColumnNumber(indentInsideCommentOffset, line);
         indentAfterUncomment.put(line, indent - prefix.length());
         return indent;
       }
     }
   }
   return fallbackColumn;
 }
 private synchronized void _clear() {
   myIcon = null;
   myPaintFocusBorder = false;
   myFragments.clear();
   myLayouts.clear();
   myAttributes.clear();
   myFragmentTags = null;
   myMainTextLastIndex = -1;
   myFragmentPadding.clear();
 }
  private void loadCommitsData(
      @NotNull final TIntIntHashMap commits,
      @NotNull final Consumer<List<T>> consumer,
      @Nullable ProgressIndicator indicator) {
    final List<T> result = ContainerUtil.newArrayList();
    final TIntHashSet toLoad = new TIntHashSet();

    long taskNumber = myCurrentTaskIndex++;

    for (int id : commits.keys()) {
      T details = getFromCache(id);
      if (details == null || details instanceof LoadingDetails) {
        toLoad.add(id);
        cacheCommit(id, taskNumber);
      } else {
        result.add(details);
      }
    }

    if (toLoad.isEmpty()) {
      sortCommitsByRow(result, commits);
      consumer.consume(result);
    } else {
      Task.Backgroundable task =
          new Task.Backgroundable(
              null, "Loading Selected Details", true, PerformInBackgroundOption.ALWAYS_BACKGROUND) {
            @Override
            public void run(@NotNull final ProgressIndicator indicator) {
              indicator.checkCanceled();
              try {
                TIntObjectHashMap<T> map = preLoadCommitData(toLoad);
                map.forEachValue(
                    value -> {
                      result.add(value);
                      return true;
                    });
                sortCommitsByRow(result, commits);
                notifyLoaded();
              } catch (VcsException e) {
                LOG.error(e);
              }
            }

            @Override
            public void onSuccess() {
              consumer.consume(result);
            }
          };
      if (indicator != null) {
        ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, indicator);
      } else {
        ProgressManager.getInstance().run(task);
      }
    }
  }
Exemple #14
0
  private void updateCustomClientData(Player[] players, int id) {

    int blockId = itemBlock.get(id);

    short metaData = (short) itemMetaData.get(id);

    @SuppressWarnings("unused")
    String pluginName = (String) itemPlugin.get(id);

    PacketCustomItem p = new PacketCustomItem(id, blockId, metaData);

    for (Player player : players) {
      if (player instanceof SpoutCraftPlayer) {
        SpoutCraftPlayer sp = (SpoutCraftPlayer) player;
        if (sp.isSpoutCraftEnabled()) {
          sp.sendPacket(p);
        }
      }
    }
  }
  private static TIntIntHashMap getCoverageVersionToCurrentLineMapping(
      Diff.Change change, int firstNLines) {
    TIntIntHashMap result = new TIntIntHashMap();
    int prevLineInFirst = 0;
    int prevLineInSecond = 0;
    while (change != null) {

      for (int l = 0; l < change.line0 - prevLineInFirst; l++) {
        result.put(prevLineInFirst + l, prevLineInSecond + l);
      }

      prevLineInFirst = change.line0 + change.deleted;
      prevLineInSecond = change.line1 + change.inserted;

      change = change.link;
    }

    for (int i = prevLineInFirst; i < firstNLines; i++) {
      result.put(i, prevLineInSecond + i - prevLineInFirst);
    }

    return result;
  }
Exemple #16
0
  public UNVDomain(UNVParser parser, int id, Color color) {
    this.id = id;
    this.color = color;
    TIntHashSet nodeset = new TIntHashSet();
    tria3 = parser.getTria3FromGroup(id);
    if (tria3.length > 0) {
      nodeset.ensureCapacity(tria3.length);
      nodeset.addAll(tria3);
    }
    quad4 = parser.getQuad4FromGroup(id);
    if (quad4.length > 0) {
      nodeset.ensureCapacity(nodeset.size() + quad4.length);
      nodeset.addAll(quad4);
    }
    beam2 = parser.getBeam2FromGroup(id);
    if (beam2.length > 0) {
      nodeset.ensureCapacity(nodeset.size() + beam2.length);
      nodeset.addAll(beam2);
    }
    tria6 = parser.getTria6FromGroup(id);
    if (tria6.length > 0) {
      nodeset.ensureCapacity(nodeset.size() + tria6.length);
      nodeset.addAll(tria6);
    }

    int[] nodesID = nodeset.toArray();
    nodes = readNodes(nodesID, parser.getNodesCoordinates());

    // Compute inverse relation
    TIntIntHashMap map = new TIntIntHashMap(nodesID.length);
    for (int i = 0; i < nodesID.length; i++) map.put(nodesID[i], i);

    for (int i = 0; i < tria3.length; i++) tria3[i] = map.get(tria3[i]);
    for (int i = 0; i < quad4.length; i++) quad4[i] = map.get(quad4[i]);
    for (int i = 0; i < beam2.length; i++) beam2[i] = map.get(beam2[i]);
    for (int i = 0; i < tria6.length; i++) tria6[i] = map.get(tria6[i]);
  }
  /**
   * Returns the index of text fragment at the specified X offset.
   *
   * @param x the offset
   * @return the index of the fragment, {@link #FRAGMENT_ICON} if the icon is at the offset, or -1
   *     if nothing is there.
   */
  public int findFragmentAt(int x) {
    int curX = myIpad.left;
    if (myIcon != null && !myIconOnTheRight) {
      final int iconRight = myIcon.getIconWidth() + myIconTextGap;
      if (x < iconRight) {
        return FRAGMENT_ICON;
      }
      curX += iconRight;
    }

    Font font = getBaseFont();

    int baseSize = font.getSize();
    boolean wasSmaller = false;
    for (int i = 0; i < myAttributes.size(); i++) {
      SimpleTextAttributes attributes = myAttributes.get(i);
      boolean isSmaller = attributes.isSmaller();
      if (font.getStyle() != attributes.getFontStyle()
          || isSmaller != wasSmaller) { // derive font only if it is necessary
        font =
            font.deriveFont(
                attributes.getFontStyle(),
                isSmaller ? UIUtil.getFontSize(UIUtil.FontSize.SMALL) : baseSize);
      }
      wasSmaller = isSmaller;

      final int curWidth = computeStringWidth(i, font);
      if (x >= curX && x < curX + curWidth) {
        return i;
      }
      curX += curWidth;
      final int fragmentPadding = myFragmentPadding.get(i);
      if (fragmentPadding > 0 && curX < fragmentPadding) {
        curX = fragmentPadding;
      }
    }

    if (myIcon != null && myIconOnTheRight) {
      curX += myIconTextGap;
      if (x >= curX && x < curX + myIcon.getIconWidth()) {
        return FRAGMENT_ICON;
      }
    }
    return -1;
  }
 /**
  * @param padding end offset that will be set after drawing current text fragment
  * @param align alignment of the current text fragment, if it is SwingConstants.RIGHT or
  *     SwingConstants.TRAILING then the text fragment will be aligned to the right at the padding,
  *     otherwise it will be aligned to the left
  */
 public synchronized void appendTextPadding(
     int padding, @JdkConstants.HorizontalAlignment int align) {
   final int alignIndex = myFragments.size() - 1;
   myFragmentPadding.put(alignIndex, padding);
   myFragmentAlignment.put(alignIndex, align);
 }
Exemple #19
0
  private List<IndentGuideDescriptor> buildDescriptors() {
    if (!myEditor.getSettings().isIndentGuidesShown()) return Collections.emptyList();

    IndentsCalculator calculator = new IndentsCalculator();
    calculator.calculate();
    int[] lineIndents = calculator.lineIndents;
    TIntIntHashMap effectiveCommentColumns = calculator.indentAfterUncomment;

    List<IndentGuideDescriptor> descriptors = new ArrayList<IndentGuideDescriptor>();

    IntStack lines = new IntStack();
    IntStack indents = new IntStack();

    lines.push(0);
    indents.push(0);
    assert myDocument != null;
    final CharSequence chars = myDocument.getCharsSequence();
    for (int line = 1; line < lineIndents.length; line++) {
      ProgressManager.checkCanceled();
      int curIndent = lineIndents[line];

      while (!indents.empty() && curIndent <= indents.peek()) {
        ProgressManager.checkCanceled();
        final int level = indents.pop();
        int startLine = lines.pop();
        if (level > 0) {
          boolean addDescriptor =
              effectiveCommentColumns.contains(startLine); // Indent started at comment
          if (!addDescriptor) {
            for (int i = startLine; i < line; i++) {
              if (level != lineIndents[i] && level != effectiveCommentColumns.get(i)) {
                addDescriptor = true;
                break;
              }
            }
          }
          if (addDescriptor) {
            descriptors.add(createDescriptor(level, startLine, line, chars));
          }
        }
      }

      int prevLine = line - 1;
      int prevIndent = lineIndents[prevLine];

      if (curIndent - prevIndent > 1) {
        lines.push(prevLine);
        indents.push(prevIndent);
      }
    }

    while (!indents.empty()) {
      ProgressManager.checkCanceled();
      final int level = indents.pop();
      int startLine = lines.pop();
      if (level > 0) {
        descriptors.add(createDescriptor(level, startLine, myDocument.getLineCount(), chars));
      }
    }
    return descriptors;
  }
  public ResultSet doMatch(
      String queryNumber, MatchingQueryTerms queryTerms, final FatResultSet fat)
      throws IOException {
    final int numResults = fat.getResultSize();
    final FeaturedQueryResultSet rtr = new FeaturedQueryResultSet(fat);
    if (fat.getResultSize() == 0) {
      rtr.scores = new double[0];
      rtr.docids = new int[0];
      rtr.occurrences = new short[0];
      return rtr;
    }

    if (sampleFeature) rtr.putFeatureScores("SAMPLE", fat.getScores());

    // for each WMODEL feature
    for (int fid = 0; fid < wModels.length; fid++) {
      final ResultSet thinChild = wModels[fid].doMatch(queryNumber, queryTerms, fat);
      rtr.putFeatureScores(wModelNames[fid], thinChild.getScores());
    }

    // for each QI features
    if (qiFeatures.length > 0) {
      WritablePosting[][] postings = fat.getPostings();
      int[] docids = fat.getDocids();
      for (int fid = 0; fid < qiFeatures.length; fid++) {
        WeightingModel wm = qiFeatures[fid];
        double[] scores = new double[numResults];
        for (int di = 0; di < numResults; di++) {
          WritablePosting p = FatUtils.firstPosting(postings[di]);
          if (p == null) {
            p = new BlockFieldPostingImpl(docids[di], 0, new int[0], new int[4]); // hack
            ((FieldPosting) p).setFieldLengths(new int[4]);
          }
          scores[di] = wm.score(p);
        }
        rtr.putFeatureScores(qiFeatureNames[fid], scores);
      }
    }

    // for each DSM feature
    if (dsms.length > 0) {
      TIntIntHashMap docidMap = new TIntIntHashMap(numResults);
      int position = 0;
      for (int docid : fat.getDocids()) {
        docidMap.put(docid, position++);
      }
      final Index fatIndex = FatUtils.makeIndex(fat);
      for (int fid = 0; fid < dsms.length; fid++) {
        final double[] scores = new double[numResults];
        final int[] docids = new int[numResults];
        final short[] occurrences = new short[numResults];
        System.arraycopy(fat.getDocids(), 0, docids, 0, numResults);
        System.arraycopy(fat.getOccurrences(), 0, occurrences, 0, numResults);

        // Sort by docid so that term postings we have a recoverable score ordering
        MultiSort.ascendingHeapSort(docids, scores, occurrences, docids.length);

        final ResultSet thinChild = new QueryResultSet(docids, scores, occurrences);
        final MatchingQueryTerms mqtLocal = new MatchingQueryTerms(queryNumber);
        mqtLocal.setDefaultTermWeightingModel(queryTerms.defaultWeightingModel);
        int ti = 0;
        for (String t : fat.getQueryTerms()) {
          mqtLocal.setTermProperty(t, fat.getKeyFrequencies()[ti]);
          mqtLocal.setTermProperty(t, fat.getEntryStatistics()[ti]);
          ti++;
        }
        // apply the dsm on the temporary resultset
        dsms[fid].modifyScores(fatIndex, mqtLocal, thinChild);

        // map scores back into original ordering
        double[] scoresFinal = new double[numResults];
        for (int i = 0; i < numResults; i++) {
          scoresFinal[docidMap.get(docids[i])] = scores[i];
        }
        // add the feature, regardless of whether it has scores or not
        rtr.putFeatureScores(dsmNames[fid], scoresFinal);
      }
    }
    final String[] labels = new String[rtr.getResultSize()];
    Arrays.fill(labels, "-1");
    rtr.setLabels(labels);

    if (fat.hasMetaItems("docno")) {
      rtr.addMetaItems("docno", fat.getMetaItems("docno"));
    }
    if (fat.hasMetaItems("label")) rtr.setLabels(fat.getMetaItems("label"));

    return rtr;
  }
Exemple #21
0
 public int getItemBlock(int damage) {
   return itemBlock.get(damage);
 }
Exemple #22
0
 public short getItemMetaData(int damage) {
   return (short) itemMetaData.get(damage);
 }
Exemple #23
0
 @Override
 public void resetOpacity(int id, short data) {
   if (originalOpacity.containsKey(id)) {
     setOpaque(id, data, originalOpacity.get(id) != 0);
   }
 }
Exemple #24
0
 @Override
 public void resetLightLevel(int id, short data) {
   if (originalLight.containsKey(id)) {
     setLightLevel(id, data, originalLight.get(id));
   }
 }
  protected int doPaintText(Graphics2D g, int offset, boolean focusAroundIcon) {
    // If there is no icon, then we have to add left internal padding
    if (offset == 0) {
      offset = myIpad.left;
    }

    int textStart = offset;
    if (myBorder != null) {
      offset += myBorder.getBorderInsets(this).left;
    }

    final List<Object[]> searchMatches = new ArrayList<>();

    applyAdditionalHints(g);
    final Font baseFont = getBaseFont();
    g.setFont(baseFont);
    offset += computeTextAlignShift(baseFont);
    int baseSize = baseFont.getSize();
    FontMetrics baseMetrics = g.getFontMetrics();
    Rectangle area = computePaintArea();
    final int textBaseline = area.y + getTextBaseLine(baseMetrics, area.height);
    boolean wasSmaller = false;
    for (int i = 0; i < myFragments.size(); i++) {
      final SimpleTextAttributes attributes = myAttributes.get(i);

      Font font = g.getFont();
      boolean isSmaller = attributes.isSmaller();
      if (font.getStyle() != attributes.getFontStyle()
          || isSmaller != wasSmaller) { // derive font only if it is necessary
        font =
            font.deriveFont(
                attributes.getFontStyle(),
                isSmaller ? UIUtil.getFontSize(UIUtil.FontSize.SMALL) : baseSize);
      }
      wasSmaller = isSmaller;

      g.setFont(font);
      final FontMetrics metrics = g.getFontMetrics(font);

      final int fragmentWidth = computeStringWidth(i, font);

      final int fragmentPadding = myFragmentPadding.get(i);

      final Color bgColor = attributes.isSearchMatch() ? null : attributes.getBgColor();
      if ((attributes.isOpaque() || isOpaque()) && bgColor != null) {
        g.setColor(bgColor);
        g.fillRect(offset, 0, fragmentWidth, getHeight());
      }

      Color color = attributes.getFgColor();
      if (color
          == null) { // in case if color is not defined we have to get foreground color from Swing
                     // hierarchy
        color = getForeground();
      }
      if (!isEnabled()) {
        color = UIUtil.getInactiveTextColor();
      }
      g.setColor(color);

      final int fragmentAlignment = myFragmentAlignment.get(i);

      final int endOffset;
      if (fragmentPadding > 0 && fragmentPadding > fragmentWidth) {
        endOffset = fragmentPadding;
        if (fragmentAlignment == SwingConstants.RIGHT
            || fragmentAlignment == SwingConstants.TRAILING) {
          offset = fragmentPadding - fragmentWidth;
        }
      } else {
        endOffset = offset + fragmentWidth;
      }

      if (!attributes.isSearchMatch()) {
        if (shouldDrawMacShadow()) {
          g.setColor(SHADOW_COLOR);
          doDrawString(g, i, offset, textBaseline + 1);
        }

        if (shouldDrawDimmed()) {
          color = ColorUtil.dimmer(color);
        }

        g.setColor(color);
        doDrawString(g, i, offset, textBaseline);
      }

      // for some reason strokeState here may be incorrect, resetting the stroke helps
      g.setStroke(g.getStroke());

      // 1. Strikeout effect
      if (attributes.isStrikeout() && !attributes.isSearchMatch()) {
        EffectPainter.STRIKE_THROUGH.paint(
            g, offset, textBaseline, fragmentWidth, getCharHeight(g), font);
      }
      // 2. Waved effect
      if (attributes.isWaved()) {
        if (attributes.getWaveColor() != null) {
          g.setColor(attributes.getWaveColor());
        }
        EffectPainter.WAVE_UNDERSCORE.paint(
            g, offset, textBaseline + 1, fragmentWidth, Math.max(2, metrics.getDescent()), font);
      }
      // 3. Underline
      if (attributes.isUnderline()) {
        EffectPainter.LINE_UNDERSCORE.paint(
            g, offset, textBaseline, fragmentWidth, metrics.getDescent(), font);
      }
      // 4. Bold Dotted Line
      if (attributes.isBoldDottedLine()) {
        final int dottedAt = SystemInfo.isMac ? textBaseline : textBaseline + 1;
        final Color lineColor = attributes.getWaveColor();
        UIUtil.drawBoldDottedLine(
            g, offset, offset + fragmentWidth, dottedAt, bgColor, lineColor, isOpaque());
      }

      if (attributes.isSearchMatch()) {
        searchMatches.add(
            new Object[] {
              offset,
              offset + fragmentWidth,
              textBaseline,
              myFragments.get(i),
              g.getFont(),
              attributes
            });
      }

      offset = endOffset;
    }

    // Paint focus border around the text and icon (if necessary)
    if (myPaintFocusBorder && myBorder != null) {
      if (focusAroundIcon) {
        myBorder.paintBorder(this, g, 0, 0, getWidth(), getHeight());
      } else {
        myBorder.paintBorder(this, g, textStart, 0, getWidth() - textStart, getHeight());
      }
    }

    // draw search matches after all
    for (final Object[] info : searchMatches) {
      Integer x1 = (Integer) info[0];
      Integer x2 = (Integer) info[1];
      UIUtil.drawSearchMatch(g, x1, x2, getHeight());
      g.setFont((Font) info[4]);

      Integer baseline = (Integer) info[2];
      String text = (String) info[3];
      if (shouldDrawMacShadow()) {
        g.setColor(SHADOW_COLOR);
        g.drawString(text, x1, baseline + 1);
      }

      g.setColor(new JBColor(Gray._50, Gray._0));
      g.drawString(text, x1, baseline);

      if (((SimpleTextAttributes) info[5]).isStrikeout()) {
        EffectPainter.STRIKE_THROUGH.paint(g, x1, baseline, x2 - x1, getCharHeight(g), g.getFont());
      }
    }
    return offset;
  }
  private RangeHighlighter createRangeHighlighter(
      final long date,
      final MarkupModel markupModel,
      final boolean coverageByTestApplicable,
      final TreeMap<Integer, LineData> executableLines,
      @Nullable final String className,
      final int line,
      final int lineNumberInCurrent,
      @NotNull final CoverageSuitesBundle coverageSuite,
      Object[] lines) {
    EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
    final TextAttributes attributes =
        scheme.getAttributes(CoverageLineMarkerRenderer.getAttributesKey(line, executableLines));
    TextAttributes textAttributes = null;
    if (attributes.getBackgroundColor() != null) {
      textAttributes = attributes;
    }
    final int startOffset = myDocument.getLineStartOffset(lineNumberInCurrent);
    final int endOffset = myDocument.getLineEndOffset(lineNumberInCurrent);
    final RangeHighlighter highlighter =
        markupModel.addRangeHighlighter(
            startOffset,
            endOffset,
            HighlighterLayer.SELECTION - 1,
            textAttributes,
            HighlighterTargetArea.LINES_IN_RANGE);
    final Function<Integer, Integer> newToOldConverter =
        newLine -> {
          if (myEditor == null) return -1;
          final TIntIntHashMap oldLineMapping = getNewToOldLineMapping(date);
          return oldLineMapping != null
              ? oldLineMapping.get(newLine.intValue())
              : newLine.intValue();
        };
    final Function<Integer, Integer> oldToNewConverter =
        newLine -> {
          if (myEditor == null) return -1;
          final TIntIntHashMap newLineMapping = getOldToNewLineMapping(date);
          return newLineMapping != null
              ? newLineMapping.get(newLine.intValue())
              : newLine.intValue();
        };
    final CoverageLineMarkerRenderer markerRenderer =
        coverageSuite
            .getCoverageEngine()
            .getLineMarkerRenderer(
                line,
                className,
                executableLines,
                coverageByTestApplicable,
                coverageSuite,
                newToOldConverter,
                oldToNewConverter,
                CoverageDataManager.getInstance(myProject).isSubCoverageActive());
    highlighter.setLineMarkerRenderer(markerRenderer);

    final LineData lineData = className != null ? (LineData) lines[line + 1] : null;
    if (lineData != null && lineData.getStatus() == LineCoverage.NONE) {
      highlighter.setErrorStripeMarkColor(markerRenderer.getErrorStripeColor(myEditor));
      highlighter.setThinErrorStripeMark(true);
      highlighter.setGreedyToLeft(true);
      highlighter.setGreedyToRight(true);
    }
    return highlighter;
  }