• ■ ■ ■ ■
    commons-codeassist/pom.xml
    skipped 4 lines
    5 5   <parent>
    6 6   <groupId>io.onedev</groupId>
    7 7   <artifactId>commons</artifactId>
    8  - <version>2.0.3</version>
     8 + <version>2.0.4</version>
    9 9   </parent>
    10 10   <build>
    11 11   <plugins>
    skipped 68 lines
  • ■ ■ ■ ■
    commons-jsymbol/pom.xml
    skipped 3 lines
    4 4   <parent>
    5 5   <groupId>io.onedev</groupId>
    6 6   <artifactId>commons</artifactId>
    7  - <version>2.0.3</version>
     7 + <version>2.0.4</version>
    8 8   </parent>
    9 9   <artifactId>commons-jsymbol</artifactId>
    10 10   <build>
    skipped 148 lines
  • ■ ■ ■ ■
    commons-jsyntax/pom.xml
    skipped 3 lines
    4 4   <parent>
    5 5   <groupId>io.onedev</groupId>
    6 6   <artifactId>commons</artifactId>
    7  - <version>2.0.3</version>
     7 + <version>2.0.4</version>
    8 8   </parent>
    9 9   <artifactId>commons-jsyntax</artifactId>
    10 10   <dependencies>
    skipped 46 lines
  • ■ ■ ■ ■
    commons-launcher/commons-launcher-bootstrap/pom.xml
    skipped 3 lines
    4 4   <parent>
    5 5   <groupId>io.onedev</groupId>
    6 6   <artifactId>commons-launcher</artifactId>
    7  - <version>2.0.3</version>
     7 + <version>2.0.4</version>
    8 8   </parent>
    9 9   <artifactId>commons-launcher-bootstrap</artifactId>
    10 10   <build>
    skipped 30 lines
  • ■ ■ ■ ■
    commons-launcher/commons-launcher-loader/pom.xml
    skipped 4 lines
    5 5   <parent>
    6 6   <groupId>io.onedev</groupId>
    7 7   <artifactId>commons-launcher</artifactId>
    8  - <version>2.0.3</version>
     8 + <version>2.0.4</version>
    9 9   </parent>
    10 10   <build>
    11 11   <plugins>
    skipped 45 lines
  • ■ ■ ■ ■
    commons-launcher/pom.xml
    skipped 3 lines
    4 4   <parent>
    5 5   <groupId>io.onedev</groupId>
    6 6   <artifactId>commons</artifactId>
    7  - <version>2.0.3</version>
     7 + <version>2.0.4</version>
    8 8   </parent>
    9 9   <artifactId>commons-launcher</artifactId>
    10 10   <packaging>pom</packaging>
    skipped 73 lines
  • ■ ■ ■ ■
    commons-utils/pom.xml
    skipped 4 lines
    5 5   <parent>
    6 6   <groupId>io.onedev</groupId>
    7 7   <artifactId>commons</artifactId>
    8  - <version>2.0.3</version>
     8 + <version>2.0.4</version>
    9 9   </parent>
    10 10   <artifactId>commons-utils</artifactId>
    11 11   <dependencies>
    skipped 91 lines
  • ■ ■ ■ ■ ■ ■
    commons-utils/src/main/java/io/onedev/commons/utils/PlanarRange.java
    1 1  package io.onedev.commons.utils;
    2 2   
    3 3  import java.io.Serializable;
     4 +import java.util.List;
    4 5   
    5 6  import javax.annotation.Nullable;
    6 7   
    7 8  import org.apache.commons.lang3.StringUtils;
    8 9  import org.apache.commons.lang3.builder.EqualsBuilder;
    9 10  import org.apache.commons.lang3.builder.HashCodeBuilder;
     11 + 
     12 +import com.google.common.base.Splitter;
    10 13   
    11 14  public class PlanarRange implements Serializable {
    12 15  
    13 16   private static final long serialVersionUID = 1L;
    14 17  
    15  - private final int fromRow, fromColumn, toRow, toColumn;
     18 + private final int fromRow, fromColumn, toRow, toColumn, tabWidth;
    16 19  
    17  - public PlanarRange(int fromRow, int fromColumn, int toRow, int toColumn) {
     20 + public PlanarRange(int fromRow, int fromColumn, int toRow, int toColumn, int tabWidth) {
    18 21   this.fromRow = fromRow;
    19 22   this.fromColumn = fromColumn;
    20 23   this.toRow = toRow;
    21 24   this.toColumn = toColumn;
     25 + this.tabWidth = tabWidth;
     26 + }
     27 +
     28 + public PlanarRange(int fromRow, int fromColumn, int toRow, int toColumn) {
     29 + this(fromRow, fromColumn, toRow, toColumn, 1);
    22 30   }
    23 31  
    24 32   public PlanarRange(PlanarRange range) {
    skipped 1 lines
    26 34   fromColumn = range.fromColumn;
    27 35   toRow = range.toRow;
    28 36   toColumn = range.toColumn;
     37 + tabWidth = range.tabWidth;
    29 38   }
    30 39  
    31 40   public PlanarRange(String string) {
    32  - String from = StringUtils.substringBefore(string, "-");
    33  - String to = StringUtils.substringAfter(string, "-");
     41 + List<String> fields = Splitter.on("-").splitToList(string);
     42 + String from = fields.get(0);
     43 + String to = fields.get(1);
    34 44   fromRow = Integer.parseInt(StringUtils.substringBefore(from, "."))-1;
    35 45   fromColumn = Integer.parseInt(StringUtils.substringAfter(from, "."));
    36 46   toRow = Integer.parseInt(StringUtils.substringBefore(to, "."))-1;
    37 47   toColumn = Integer.parseInt(StringUtils.substringAfter(to, "."));
     48 +
     49 + if (fields.size() >= 3)
     50 + tabWidth = Integer.parseInt(fields.get(2));
     51 + else
     52 + tabWidth = 1;
    38 53   }
    39 54  
    40 55   public int getFromRow() {
    skipped 10 lines
    51 66   
    52 67   public int getToColumn() {
    53 68   return toColumn;
     69 + }
     70 +
     71 + public int getTabWidth() {
     72 + return tabWidth;
    54 73   }
    55 74  
    56 75   @Override
    57 76   public String toString() {
    58  - return (fromRow+1) + "." + fromColumn + "-" + (toRow+1) + "." + toColumn;
     77 + return (fromRow+1) + "." + fromColumn + "-" + (toRow+1) + "." + toColumn + "-" + tabWidth;
     78 + }
     79 +
     80 + private int normalizeColumn(String lineContent, int column, int tabWidth) {
     81 + int pos = 0;
     82 + int normalizedColumn = 0;
     83 + for (int i = 0; i < lineContent.length(); i++) {
     84 + if (pos >= column)
     85 + break;
     86 + char ch = lineContent.charAt(i);
     87 + if (ch == '\t')
     88 + pos += tabWidth;
     89 + else
     90 + pos++;
     91 + normalizedColumn++;
     92 + }
     93 + return normalizedColumn;
     94 + }
     95 +
     96 + public PlanarRange normalize(List<String> lines) {
     97 + int normalizedFromRow, normalizedFromColumn, normalizedToRow, normalizedToColumn;
     98 + if (fromColumn == -1) { // only fromRow is set
     99 + normalizedFromRow = fromRow;
     100 + normalizedFromColumn = 0;
     101 + normalizedToRow = fromRow;
     102 + normalizedToColumn = lines.get(fromRow).length();
     103 + } else if (toRow == -1) { // only fromRow and fromColumn is set
     104 + normalizedFromRow = fromRow;
     105 + normalizedFromColumn = normalizeColumn(lines.get(fromRow), fromColumn, tabWidth);
     106 + normalizedToRow = fromRow;
     107 + normalizedToColumn = normalizedFromColumn+1;
     108 + } else {
     109 + normalizedFromRow = fromRow;
     110 + normalizedFromColumn = normalizeColumn(lines.get(fromRow), fromColumn, tabWidth);
     111 + normalizedToRow = toRow;
     112 + normalizedToColumn = normalizeColumn(lines.get(toRow), toColumn, tabWidth);
     113 + }
     114 + return new PlanarRange(normalizedFromRow, normalizedFromColumn, normalizedToRow,
     115 + normalizedToColumn, 1);
    59 116   }
    60 117  
    61 118   @Override
    skipped 8 lines
    70 127   .append(fromColumn, otherRange.fromColumn)
    71 128   .append(toRow, otherRange.toRow)
    72 129   .append(toColumn, otherRange.toColumn)
     130 + .append(tabWidth, otherRange.tabWidth)
    73 131   .isEquals();
    74 132   }
    75 133   
    skipped 4 lines
    80 138   .append(fromColumn)
    81 139   .append(toRow)
    82 140   .append(toColumn)
     141 + .append(tabWidth)
    83 142   .toHashCode();
    84 143   }
    85 144  
    skipped 9 lines
  • ■ ■ ■ ■ ■ ■
    commons-utils/src/test/java/io/onedev/commons/utils/PlanarRangeTest.java
     1 +package io.onedev.commons.utils;
     2 + 
     3 +import static org.junit.Assert.*;
     4 + 
     5 +import org.junit.Test;
     6 + 
     7 +public class PlanarRangeTest {
     8 + 
     9 + @Test
     10 + public void test() {
     11 + PlanarRange range = new PlanarRange("1.2-3.4-8");
     12 + assertEquals(0, range.getFromRow());
     13 + assertEquals(4, range.getToColumn());
     14 + assertEquals(8, range.getTabWidth());
     15 +
     16 + range = new PlanarRange("1.2-3.4");
     17 + assertEquals(0, range.getFromRow());
     18 + assertEquals(4, range.getToColumn());
     19 + assertEquals(1, range.getTabWidth());
     20 + }
     21 + 
     22 +}
     23 + 
  • ■ ■ ■ ■
    pom.xml
    skipped 8 lines
    9 9   <version>1.0.5</version>
    10 10   </parent>
    11 11   <artifactId>commons</artifactId>
    12  - <version>2.0.3</version>
     12 + <version>2.0.4</version>
    13 13   <packaging>pom</packaging>
    14 14   <modules>
    15 15   <module>commons-utils</module>
    skipped 291 lines
Please wait...
Page is in error, reload to recover