Skip to content

Commit

Permalink
eliminate redundant lineNumber fields
Browse files Browse the repository at this point in the history
when that information is already stored in the sourceCodeLocation object

Signed-off-by: Manfred Hanke <[email protected]>
  • Loading branch information
hankem committed Dec 29, 2023
1 parent 773a9eb commit 1c23935
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
public final class Dependency implements HasDescription, Comparable<Dependency>, HasSourceCodeLocation {
private final JavaClass originClass;
private final JavaClass targetClass;
private final int lineNumber;
private final String description;
private final SourceCodeLocation sourceCodeLocation;
private final int hashCode;
Expand All @@ -70,7 +69,6 @@ private Dependency(JavaClass originClass, JavaClass targetClass, int lineNumber,

this.originClass = originClass;
this.targetClass = targetClass;
this.lineNumber = lineNumber;
this.description = description;
this.sourceCodeLocation = SourceCodeLocation.of(originClass, lineNumber);
hashCode = Objects.hash(originClass, targetClass, lineNumber, description);
Expand Down Expand Up @@ -276,7 +274,7 @@ public SourceCodeLocation getSourceCodeLocation() {
@PublicAPI(usage = ACCESS)
public int compareTo(Dependency o) {
return ComparisonChain.start()
.compare(lineNumber, o.lineNumber)
.compare(sourceCodeLocation.getLineNumber(), o.sourceCodeLocation.getLineNumber())
.compare(getDescription(), o.getDescription())
.result();
}
Expand All @@ -297,7 +295,7 @@ public boolean equals(Object obj) {
Dependency other = (Dependency) obj;
return Objects.equals(this.originClass, other.originClass)
&& Objects.equals(this.targetClass, other.targetClass)
&& Objects.equals(this.lineNumber, other.lineNumber)
&& Objects.equals(this.sourceCodeLocation.getLineNumber(), other.sourceCodeLocation.getLineNumber())
&& Objects.equals(this.description, other.description);
}

Expand All @@ -306,7 +304,7 @@ public String toString() {
return MoreObjects.toStringHelper(this)
.add("originClass", originClass)
.add("targetClass", targetClass)
.add("lineNumber", lineNumber)
.add("sourceCodeLocation", sourceCodeLocation)
.add("description", description)
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ public final class InstanceofCheck implements HasType, HasOwner<JavaCodeUnit>, H

private final JavaCodeUnit owner;
private final JavaClass type;
private final int lineNumber;
private final boolean declaredInLambda;
private final SourceCodeLocation sourceCodeLocation;

private InstanceofCheck(JavaCodeUnit owner, JavaClass type, int lineNumber, boolean declaredInLambda) {
this.owner = checkNotNull(owner);
this.type = checkNotNull(type);
this.lineNumber = lineNumber;
this.declaredInLambda = declaredInLambda;
sourceCodeLocation = SourceCodeLocation.of(owner.getOwner(), lineNumber);
}
Expand All @@ -61,7 +59,7 @@ public JavaCodeUnit getOwner() {

@PublicAPI(usage = ACCESS)
public int getLineNumber() {
return lineNumber;
return sourceCodeLocation.getLineNumber();
}

@PublicAPI(usage = ACCESS)
Expand All @@ -79,7 +77,7 @@ public String toString() {
return toStringHelper(this)
.add("owner", owner)
.add("type", type)
.add("lineNumber", lineNumber)
.add("sourceCodeLocation", sourceCodeLocation)
.add("declaredInLambda", declaredInLambda)
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ public abstract class JavaAccess<TARGET extends AccessTarget>

private final JavaCodeUnit origin;
private final TARGET target;
private final int lineNumber;
private final SourceCodeLocation sourceCodeLocation;
private final boolean declaredInLambda;

JavaAccess(JavaAccessBuilder<TARGET, ?> builder) {
this.origin = checkNotNull(builder.getOrigin());
this.target = checkNotNull(builder.getTarget());
this.lineNumber = builder.getLineNumber();
this.sourceCodeLocation = SourceCodeLocation.of(getOriginOwner(), lineNumber);
this.sourceCodeLocation = SourceCodeLocation.of(getOriginOwner(), builder.getLineNumber());
this.declaredInLambda = builder.isDeclaredInLambda();
}

Expand Down Expand Up @@ -77,7 +75,7 @@ public TARGET getTarget() {

@PublicAPI(usage = ACCESS)
public int getLineNumber() {
return lineNumber;
return sourceCodeLocation.getLineNumber();
}

@Override
Expand All @@ -100,7 +98,7 @@ public boolean isDeclaredInLambda() {
@Override
public String toString() {
return getClass().getSimpleName() +
"{origin=" + origin + ", target=" + target + ", lineNumber=" + lineNumber + additionalToStringFields() + '}';
"{origin=" + origin + ", target=" + target + ", lineNumber=" + getLineNumber() + additionalToStringFields() + '}';
}

String additionalToStringFields() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@
public final class ReferencedClassObject implements HasType, HasOwner<JavaCodeUnit>, HasSourceCodeLocation {
private final JavaCodeUnit owner;
private final JavaClass value;
private final int lineNumber;
private final SourceCodeLocation sourceCodeLocation;
private final boolean declaredInLambda;

private ReferencedClassObject(JavaCodeUnit owner, JavaClass value, int lineNumber, boolean declaredInLambda) {
this.owner = checkNotNull(owner);
this.value = checkNotNull(value);
this.lineNumber = lineNumber;
sourceCodeLocation = SourceCodeLocation.of(owner.getOwner(), lineNumber);
this.declaredInLambda = declaredInLambda;
}
Expand Down Expand Up @@ -66,7 +64,7 @@ public JavaClass getValue() {

@PublicAPI(usage = ACCESS)
public int getLineNumber() {
return lineNumber;
return sourceCodeLocation.getLineNumber();
}

@Override
Expand Down

0 comments on commit 1c23935

Please sign in to comment.