Skip to content

Commit

Permalink
Merge pull request #903 from uhafner/line-range
Browse files Browse the repository at this point in the history
Synchronize line range with analysis-model
  • Loading branch information
uhafner authored Jan 23, 2024
2 parents 9a5f7a1 + b7cc33b commit 4e6f3b2
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 27 deletions.
1 change: 1 addition & 0 deletions bin/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
git pull
git push
mvn -B clean build-helper:parse-version release:prepare release:perform -DdevelopmentVersion=\${parsedVersion.majorVersion}.\${parsedVersion.nextMinorVersion}.0-SNAPSHOT
mvn -Dproject.version=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.patchVersion} com.github.ferstl:depgraph-maven-plugin:graph scm:add -Dincludes=doc/dependency-graph.puml
6 changes: 6 additions & 0 deletions bin/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

git pull
git push
mvn build-helper:parse-version
mvn -Dproject.version=1.0.0 com.github.ferstl:depgraph-maven-plugin:graph
11 changes: 11 additions & 0 deletions doc/dependency-graph.puml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,15 @@ skinparam rectangle {
BackgroundColor<<runtime>> lightBlue
BackgroundColor<<provided>> lightGray
}
rectangle "spotbugs-annotations\n\n4.8.3" as com_github_spotbugs_spotbugs_annotations_jar
rectangle "jsr305\n\n3.0.2" as com_google_code_findbugs_jsr305_jar
rectangle "codingstyle\n\n3.41.0-SNAPSHOT" as edu_hm_hafner_codingstyle_jar
rectangle "error_prone_annotations\n\n2.24.1" as com_google_errorprone_error_prone_annotations_jar
rectangle "commons-lang3\n\n3.14.0" as org_apache_commons_commons_lang3_jar
rectangle "commons-io\n\n2.15.1" as commons_io_commons_io_jar
com_github_spotbugs_spotbugs_annotations_jar -[#000000]-> com_google_code_findbugs_jsr305_jar
edu_hm_hafner_codingstyle_jar -[#000000]-> com_github_spotbugs_spotbugs_annotations_jar
edu_hm_hafner_codingstyle_jar -[#000000]-> com_google_errorprone_error_prone_annotations_jar
edu_hm_hafner_codingstyle_jar -[#000000]-> org_apache_commons_commons_lang3_jar
edu_hm_hafner_codingstyle_jar -[#000000]-> commons_io_commons_io_jar
@enduml
37 changes: 18 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@
<releaseProfiles>release</releaseProfiles>
<goals>deploy</goals>
<tagNameFormat>v@{project.version}</tagNameFormat>
<preparationGoals>clean install com.github.ferstl:depgraph-maven-plugin:graph scm:add -Dincludes=doc/dependency-graph.puml</preparationGoals>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -724,21 +723,24 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.ferstl</groupId>
<artifactId>depgraph-maven-plugin</artifactId>
<version>${depgraph-maven-plugin.version}</version>
<configuration>
<graphFormat>puml</graphFormat>
<classpathScope>compile</classpathScope>
<showClassifiers>true</showClassifiers>
<showVersions>true</showVersions>
<showConflicts>true</showConflicts>
<showDuplicates>true</showDuplicates>
<outputFileName>dependency-graph</outputFileName>
<outputDirectory>${project.basedir}/doc</outputDirectory>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.github.ferstl</groupId>
<artifactId>depgraph-maven-plugin</artifactId>
<version>${depgraph-maven-plugin.version}</version>
<configuration>
<graphFormat>puml</graphFormat>
<classpathScope>compile</classpathScope>
<showClassifiers>true</showClassifiers>
<showVersions>true</showVersions>
<showConflicts>true</showConflicts>
<showDuplicates>true</showDuplicates>
<outputFileName>dependency-graph</outputFileName>
<outputDirectory>${project.basedir}/doc</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
Expand All @@ -748,9 +750,6 @@
<pushChanges>true</pushChanges>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
Expand Down
31 changes: 29 additions & 2 deletions src/main/java/edu/hm/hafner/util/LineRange.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package edu.hm.hafner.util;

import java.io.Serializable;
import java.util.NavigableSet;
import java.util.TreeSet;

import edu.umd.cs.findbugs.annotations.CheckForNull;

/**
* A line range in a source file is defined by its first and last line.
*
* @author Ullrich Hafner
*/
public class LineRange implements Serializable {
public final class LineRange implements Serializable {
private static final long serialVersionUID = -4124143085672930110L;

private final int start;
Expand Down Expand Up @@ -64,6 +68,29 @@ public int getEnd() {
return end;
}

/**
* Returns the lines of this line lange in a sorted set.
*
* @return the containing lines, one by one
*/
public NavigableSet<Integer> getLines() {
var lines = new TreeSet<Integer>();
for (int line = getStart(); line <= getEnd(); line++) {
lines.add(line);
}
return lines;
}

/**
* Returns whether the specified line is contained in this range.
*
* @param line the line to check
* @return {@code true} if the line is contained in this range, {@code false} otherwise
*/
public boolean contains(final int line) {
return line >= start && line <= end;
}

/**
* Returns whether this range is just a single line.
*
Expand All @@ -74,7 +101,7 @@ public boolean isSingleLine() {
}

@Override
public boolean equals(final Object o) {
public boolean equals(@CheckForNull final Object o) {
if (this == o) {
return true;
}
Expand Down
28 changes: 22 additions & 6 deletions src/test/java/edu/hm/hafner/util/LineRangeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,31 @@ void shouldRefuseIllegalValue() {
}

@Test
void shouldCreateSingleLine() {
assertThat(new LineRange(5, 5)).hasStart(5).hasEnd(5).isSingleLine();
assertThat(new LineRange(5)).hasStart(5).hasEnd(5).isSingleLine();
void shouldFindLinesInsideAndOutsideOfLineRange() {
var lineRange = new LineRange(1, 2);

assertThat(new LineRange(5, 4)).hasStart(4).hasEnd(5).isNotSingleLine();
assertThat(lineRange.contains(0)).isFalse();
assertThat(lineRange.contains(1)).isTrue();
assertThat(lineRange.contains(2)).isTrue();
assertThat(lineRange.contains(3)).isFalse();
assertThat(lineRange).hasStart(1).hasEnd(2).hasLines(1, 2).hasToString("[1-2]");

var wrongOrder = new LineRange(2, 1);
assertThat(wrongOrder.contains(0)).isFalse();
assertThat(wrongOrder.contains(1)).isTrue();
assertThat(wrongOrder.contains(2)).isTrue();
assertThat(wrongOrder.contains(3)).isFalse();
assertThat(wrongOrder).hasStart(1).hasEnd(2).hasLines(1, 2).hasToString("[1-2]");

var point = new LineRange(2);
assertThat(point.contains(1)).isFalse();
assertThat(point.contains(2)).isTrue();
assertThat(point.contains(3)).isFalse();
assertThat(point).hasStart(2).hasEnd(2).hasLines(2).hasToString("[2-2]");
}

@Test
void shouldObeyEqualsContract() {
EqualsVerifier.simple().forClass(LineRange.class).verify();
void shouldAdhereToEquals() {
EqualsVerifier.forClass(LineRange.class).verify();
}
}

0 comments on commit 4e6f3b2

Please sign in to comment.