-
Notifications
You must be signed in to change notification settings - Fork 38
#570 Add located specification id #571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
ed35603
Avoid warning during Maven Central release
0b73382
Fix warning about missing frontmatter
cb96982
Enable compiler release option in Eclipse config
b630b95
Add located specification ID
58f201b
Fix unit tests
eba1764
Add unit tests for equals contract
b3cf638
Add clarifying comment
1ffdb71
Add missing JavaDoc
c1f1451
Update formatter configuration: Allow comment line length 120
160bfcd
Update formatter setting for comments
8924392
Update formatter to latest Eclipse version
a3893a3
Never join lines in JavaDoc comments
3e22537
Fix formatting
3b6db74
Update exported formatter to latest Eclipse version
65b2a87
Apply suggestions from code review
kaklakariada 112c555
Add unit tests
ec236e9
Merge branch 'feature/#570-add-located-spec-id' of https://github.com…
0435c59
Implement review findings
d3e6765
Fix sonar finding, improve unit test
d52d0b5
Add link to refactoring ticket
0ada235
Fix sonar warnings
c5d2126
Implement review finding
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
kaklakariada marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
197 changes: 197 additions & 0 deletions
197
api/src/main/java/org/itsallcode/openfasttrace/api/core/LocatedSpecificationItemId.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| package org.itsallcode.openfasttrace.api.core; | ||
|
|
||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
|
|
||
| /** | ||
| * One occurrence of a specification item ID in an imported source artifact. | ||
| * Component ranges are absent when the corresponding ID component was generated | ||
| * by an importer instead of being present in the source. | ||
|
kaklakariada marked this conversation as resolved.
Outdated
|
||
| */ | ||
| public final class LocatedSpecificationItemId | ||
| { | ||
| private final SpecificationItemId id; | ||
| private final SourceRange range; | ||
| private final SourceRange artifactTypeRange; | ||
| private final SourceRange nameRange; | ||
| private final SourceRange revisionRange; | ||
|
|
||
| private LocatedSpecificationItemId(final Builder builder) | ||
| { | ||
| this.id = Objects.requireNonNull(builder.id, "id"); | ||
|
kaklakariada marked this conversation as resolved.
Outdated
|
||
| this.range = builder.range; | ||
| this.artifactTypeRange = builder.artifactTypeRange; | ||
| this.nameRange = builder.nameRange; | ||
| this.revisionRange = builder.revisionRange; | ||
| } | ||
|
|
||
| /** | ||
| * Create a new builder for {@link LocatedSpecificationItemId}. | ||
| * | ||
| * @return a new builder instance for {@link LocatedSpecificationItemId}. | ||
| */ | ||
| public static Builder builder() | ||
| { | ||
| return new Builder(); | ||
| } | ||
|
|
||
| /** | ||
| * Get the semantic ID of this located specification item. | ||
| * | ||
| * @return the semantic ID | ||
| */ | ||
| public SpecificationItemId getId() | ||
| { | ||
| return this.id; | ||
| } | ||
|
|
||
| /** | ||
| * Get the source range of the complete source construct. | ||
| * | ||
| * @return range of the complete source construct | ||
| */ | ||
| public SourceRange getRange() | ||
| { | ||
| return this.range; | ||
| } | ||
|
|
||
| /** | ||
| * Get the source range of the artifact type, if represented in source. | ||
| * | ||
| * @return source range of the artifact type, if represented in source | ||
| */ | ||
| public Optional<SourceRange> getArtifactTypeRange() | ||
| { | ||
| return Optional.ofNullable(this.artifactTypeRange); | ||
| } | ||
|
|
||
| /** | ||
| * Get the source range of the name, if represented in source. | ||
| * | ||
| * @return source range of the name, if represented in source | ||
| */ | ||
| public Optional<SourceRange> getNameRange() | ||
| { | ||
| return Optional.ofNullable(this.nameRange); | ||
| } | ||
|
|
||
| /** | ||
| * Get the source range of the revision, if represented in source. | ||
| * | ||
| * @return source range of the revision, if represented in source | ||
| */ | ||
| public Optional<SourceRange> getRevisionRange() | ||
| { | ||
| return Optional.ofNullable(this.revisionRange); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(final Object other) | ||
| { | ||
| if (!(other instanceof final LocatedSpecificationItemId that)) | ||
| { | ||
| return false; | ||
| } | ||
| return Objects.equals(this.id, that.id) && Objects.equals(this.range, that.range) | ||
| && Objects.equals(this.artifactTypeRange, that.artifactTypeRange) | ||
| && Objects.equals(this.nameRange, that.nameRange) | ||
| && Objects.equals(this.revisionRange, that.revisionRange); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() | ||
| { | ||
| return Objects.hash(this.id, this.range, this.artifactTypeRange, this.nameRange, this.revisionRange); | ||
| } | ||
|
|
||
| /** | ||
| * Builder for {@link LocatedSpecificationItemId}. | ||
| */ | ||
| public static class Builder | ||
|
Check warning on line 110 in api/src/main/java/org/itsallcode/openfasttrace/api/core/LocatedSpecificationItemId.java
|
||
|
kaklakariada marked this conversation as resolved.
Outdated
|
||
| { | ||
| private SpecificationItemId id; | ||
| private SourceRange range; | ||
| private SourceRange artifactTypeRange; | ||
| private SourceRange nameRange; | ||
| private SourceRange revisionRange; | ||
|
|
||
| private Builder() | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Set the semantic ID | ||
|
kaklakariada marked this conversation as resolved.
Outdated
|
||
| * | ||
| * @param id | ||
| * the semantic ID | ||
| * @return this builder instance | ||
| */ | ||
| public Builder id(final SpecificationItemId id) | ||
| { | ||
| this.id = id; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Set the source range of the complete source construct | ||
| * | ||
| * @param range | ||
| * the source range | ||
| * @return this builder instance | ||
| */ | ||
| public Builder range(final SourceRange range) | ||
| { | ||
| this.range = range; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Set the source range of the artifact type, if represented in source | ||
| * | ||
| * @param artifactTypeRange | ||
| * the source range of the artifact type | ||
| * @return this builder instance | ||
| */ | ||
| public Builder artifactTypeRange(final SourceRange artifactTypeRange) | ||
| { | ||
| this.artifactTypeRange = artifactTypeRange; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Set the source range of the name, if represented in source | ||
| * | ||
| * @param nameRange | ||
| * the source range of the name | ||
| * @return this builder instance | ||
| */ | ||
| public Builder nameRange(final SourceRange nameRange) | ||
| { | ||
| this.nameRange = nameRange; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Set the source range of the revision, if represented in source | ||
| * | ||
| * @param revisionRange | ||
| * the source range of the revision | ||
| * @return this builder instance | ||
| */ | ||
| public Builder revisionRange(final SourceRange revisionRange) | ||
| { | ||
| this.revisionRange = revisionRange; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Build a new instance of {@link LocatedSpecificationItemId}. | ||
| * | ||
| * @return a new instance of {@link LocatedSpecificationItemId} | ||
| */ | ||
| public LocatedSpecificationItemId build() | ||
| { | ||
| return new LocatedSpecificationItemId(this); | ||
| } | ||
| } | ||
| } | ||
73 changes: 73 additions & 0 deletions
73
api/src/main/java/org/itsallcode/openfasttrace/api/core/SourcePosition.java
|
kaklakariada marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package org.itsallcode.openfasttrace.api.core; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * A zero-based position in source text. The character offset is measured in | ||
| * UTF-16 code units, matching Java strings and editor protocols. | ||
| */ | ||
| public final class SourcePosition | ||
| { | ||
| private final int line; | ||
| private final int column; | ||
|
|
||
| /** | ||
| * Create a source position. | ||
| * | ||
| * @param line | ||
| * zero-based line number | ||
| * @param column | ||
| * zero-based UTF-16 character offset | ||
| */ | ||
| public SourcePosition(final int line, final int column) | ||
| { | ||
| if (line < 0 || column < 0) | ||
| { | ||
| throw new IllegalArgumentException("Source positions must not be negative"); | ||
| } | ||
| this.line = line; | ||
| this.column = column; | ||
| } | ||
|
|
||
| /** | ||
| * Get the zero-based line number. | ||
| * | ||
| * @return the zero-based line number | ||
| */ | ||
| public int getLine() | ||
| { | ||
| return this.line; | ||
| } | ||
|
|
||
| /** | ||
| * Get the zero-based UTF-16 character offset. | ||
| * | ||
| * @return the zero-based UTF-16 character offset | ||
| */ | ||
| public int getColumn() | ||
| { | ||
| return this.column; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(final Object other) | ||
| { | ||
| if (!(other instanceof final SourcePosition that)) | ||
| { | ||
| return false; | ||
| } | ||
| return this.line == that.line && this.column == that.column; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() | ||
| { | ||
| return Objects.hash(this.line, this.column); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() | ||
| { | ||
| return this.line + ":" + this.column; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.