Skip to content

Commit ce86500

Browse files
committed
Simplify InputLocation templates
- Remove isMavenModel conditionals from InputLocation/InputLocationTracker templates - Keep isMavenModel conditional only for modelId field in InputSource This simplifies the template logic while preserving all Maven-specific functionality.
1 parent 81389f5 commit ce86500

File tree

3 files changed

+29
-52
lines changed

3 files changed

+29
-52
lines changed

src/mdo/java/InputLocation.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,34 @@
2222
import java.util.Collection;
2323
import java.util.Collections;
2424
import java.util.LinkedHashMap;
25-
import java.util.Map;
26-
#if ( $isMavenModel )
2725
import java.util.List;
26+
import java.util.Map;
2827
import java.util.Objects;
2928
import java.util.stream.Collectors;
3029
import java.util.stream.Stream;
31-
#end
3230

3331
/**
34-
#if ( $isMavenModel )
3532
* Represents the location of an element within a model source file.
3633
* <p>
3734
* This class tracks the line and column numbers of elements in source files like POM files.
3835
* It's used for error reporting and debugging to help identify where specific model elements
3936
* are defined in the source files.
4037
*
4138
* @since 4.0.0
42-
#else
43-
* Class InputLocation.
44-
#end
4539
*/
4640
public class InputLocation implements Serializable, InputLocationTracker {
4741
private final int lineNumber;
4842
private final int columnNumber;
4943
private final InputSource source;
5044
private final Map<Object, InputLocation> locations;
51-
#if ( $isMavenModel )
5245
private final InputLocation importedFrom;
53-
#end
5446

5547
public InputLocation(InputSource source) {
5648
this.lineNumber = -1;
5749
this.columnNumber = -1;
5850
this.source = source;
5951
this.locations = Collections.singletonMap(0, this);
60-
#if ( $isMavenModel )
6152
this.importedFrom = null;
62-
#end
6353
}
6454

6555
public InputLocation(int lineNumber, int columnNumber) {
@@ -76,30 +66,24 @@ public InputLocation(int lineNumber, int columnNumber, InputSource source, Objec
7666
this.source = source;
7767
this.locations =
7868
selfLocationKey != null ? Collections.singletonMap(selfLocationKey, this) : Collections.emptyMap();
79-
#if ( $isMavenModel )
8069
this.importedFrom = null;
81-
#end
8270
}
8371

8472
public InputLocation(int lineNumber, int columnNumber, InputSource source, Map<Object, InputLocation> locations) {
8573
this.lineNumber = lineNumber;
8674
this.columnNumber = columnNumber;
8775
this.source = source;
8876
this.locations = ImmutableCollections.copy(locations);
89-
#if ( $isMavenModel )
9077
this.importedFrom = null;
91-
#end
9278
}
9379

94-
#if ( $isMavenModel )
9580
public InputLocation(InputLocation original) {
9681
this.lineNumber = original.lineNumber;
9782
this.columnNumber = original.columnNumber;
9883
this.source = original.source;
9984
this.locations = original.locations;
10085
this.importedFrom = original.importedFrom;
10186
}
102-
#end
10387

10488
public int getLineNumber() {
10589
return lineNumber;
@@ -122,7 +106,6 @@ public Map<Object, InputLocation> getLocations() {
122106
return locations;
123107
}
124108

125-
#if ( $isMavenModel )
126109
/**
127110
* Gets the parent InputLocation where this InputLocation may have been imported from.
128111
* Can return {@code null}.
@@ -134,7 +117,6 @@ public Map<Object, InputLocation> getLocations() {
134117
public InputLocation getImportedFrom() {
135118
return importedFrom;
136119
}
137-
#end
138120

139121
/**
140122
* Merges the {@code source} location into the {@code target} location.
@@ -223,15 +205,8 @@ public interface StringFormatter {
223205
String toString(InputLocation location);
224206
}
225207

226-
#if ( $isMavenModel )
227208
@Override
228209
public String toString() {
229210
return String.format("%s @ %d:%d", source != null ? source.getLocation() : "n/a", lineNumber, columnNumber);
230211
}
231-
#else
232-
@Override
233-
public String toString() {
234-
return getLineNumber() + " : " + getColumnNumber() + ", " + getSource();
235-
}
236-
#end
237212
}

src/mdo/java/InputLocationTracker.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
public interface InputLocationTracker {
2222
InputLocation getLocation(Object field);
2323

24-
#if ( $isMavenModel )
2524
/**
2625
* Gets the parent InputLocation where this InputLocation may have been imported from.
2726
* Can return {@code null}.
@@ -30,5 +29,4 @@ public interface InputLocationTracker {
3029
* @since 4.0.0
3130
*/
3231
InputLocation getImportedFrom();
33-
#end
3432
}

src/mdo/java/InputSource.java

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,31 @@
1919
package ${package};
2020

2121
import java.io.Serializable;
22-
#if ( $isMavenModel )
2322
import java.util.Collection;
2423
import java.util.List;
2524
import java.util.Objects;
2625
import java.util.stream.Collectors;
2726
import java.util.stream.Stream;
28-
#end
2927

3028
/**
31-
#if ( $isMavenModel )
3229
* Represents the source of a model input, such as a POM file.
3330
* <p>
3431
* This class tracks the origin of model elements, including their location in source files
3532
* and relationships between imported models. It's used for error reporting and debugging
3633
* to help identify where specific model elements came from.
3734
*
3835
* @since 4.0.0
39-
#else
40-
* Class InputSource.
41-
#end
4236
*/
4337
public class InputSource implements Serializable {
4438

4539
#if ( $isMavenModel )
4640
private final String modelId;
4741
#end
4842
private final String location;
49-
#if ( $isMavenModel )
5043
private final List<InputSource> inputs;
5144
private final InputLocation importedFrom;
5245

46+
#if ( $isMavenModel )
5347
public InputSource(String modelId, String location) {
5448
this(modelId, location, null);
5549
}
@@ -60,26 +54,28 @@ public InputSource(String modelId, String location, InputLocation importedFrom)
6054
this.inputs = null;
6155
this.importedFrom = importedFrom;
6256
}
57+
#end
58+
59+
public InputSource(String location) {
60+
#if ( $isMavenModel )
61+
this.modelId = null;
62+
#end
63+
this.location = location;
64+
this.inputs = null;
65+
this.importedFrom = null;
66+
}
6367

6468
public InputSource(Collection<InputSource> inputs) {
69+
#if ( $isMavenModel )
6570
this.modelId = null;
71+
#end
6672
this.location = null;
6773
this.inputs = ImmutableCollections.copy(inputs);
6874
this.importedFrom = null;
6975
}
70-
#else
71-
72-
public InputSource(String location) {
73-
this.location = location;
74-
}
75-
#end
7676

7777
/**
78-
#if ( $isMavenModel )
7978
* Get the path/URL of the POM or {@code null} if unknown.
80-
#else
81-
* Get the path/URL of the settings definition or {@code null} if unknown.
82-
#end
8379
*
8480
* @return the location
8581
*/
@@ -96,6 +92,7 @@ public String getLocation() {
9692
public String getModelId() {
9793
return this.modelId;
9894
}
95+
#end
9996

10097
/**
10198
* Gets the parent InputLocation where this InputLocation may have been imported from.
@@ -117,14 +114,23 @@ public boolean equals(Object o) {
117114
return false;
118115
}
119116
InputSource that = (InputSource) o;
117+
#if ( $isMavenModel )
120118
return Objects.equals(modelId, that.modelId)
121119
&& Objects.equals(location, that.location)
122120
&& Objects.equals(inputs, that.inputs);
121+
#else
122+
return Objects.equals(location, that.location)
123+
&& Objects.equals(inputs, that.inputs);
124+
#end
123125
}
124126

125127
@Override
126128
public int hashCode() {
129+
#if ( $isMavenModel )
127130
return Objects.hash(modelId, location, inputs);
131+
#else
132+
return Objects.hash(location, inputs);
133+
#end
128134
}
129135

130136
Stream<InputSource> sources() {
@@ -136,16 +142,14 @@ public String toString() {
136142
if (inputs != null) {
137143
return inputs.stream().map(InputSource::toString).collect(Collectors.joining(", ", "merged[", "]"));
138144
}
139-
return getModelId() + " " + getLocation();
145+
#if ( $isMavenModel )
146+
return getModelId() != null ? getModelId() + " " + getLocation() : getLocation();
147+
#else
148+
return getLocation();
149+
#end
140150
}
141151

142152
public static InputSource merge(InputSource src1, InputSource src2) {
143153
return new InputSource(Stream.concat(src1.sources(), src2.sources()).collect(Collectors.toSet()));
144154
}
145-
#else
146-
@Override
147-
public String toString() {
148-
return getLocation();
149-
}
150-
#end
151155
}

0 commit comments

Comments
 (0)