19
19
package $ {package };
20
20
21
21
import java .io .Serializable ;
22
- #if ( $isMavenModel )
23
22
import java .util .Collection ;
24
23
import java .util .List ;
25
24
import java .util .Objects ;
26
25
import java .util .stream .Collectors ;
27
26
import java .util .stream .Stream ;
28
- #end
29
27
30
28
/**
31
- #if ( $isMavenModel )
32
29
* Represents the source of a model input, such as a POM file.
33
30
* <p>
34
31
* This class tracks the origin of model elements, including their location in source files
35
32
* and relationships between imported models. It's used for error reporting and debugging
36
33
* to help identify where specific model elements came from.
37
34
*
38
35
* @since 4.0.0
39
- #else
40
- * Class InputSource.
41
- #end
42
36
*/
43
37
public class InputSource implements Serializable {
44
38
45
39
#if ( $isMavenModel )
46
40
private final String modelId ;
47
41
#end
48
42
private final String location ;
49
- #if ( $isMavenModel )
50
43
private final List <InputSource > inputs ;
51
44
private final InputLocation importedFrom ;
52
45
46
+ #if ( $isMavenModel )
53
47
public InputSource (String modelId , String location ) {
54
48
this (modelId , location , null );
55
49
}
@@ -60,26 +54,28 @@ public InputSource(String modelId, String location, InputLocation importedFrom)
60
54
this .inputs = null ;
61
55
this .importedFrom = importedFrom ;
62
56
}
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
+ }
63
67
64
68
public InputSource (Collection <InputSource > inputs ) {
69
+ #if ( $isMavenModel )
65
70
this .modelId = null ;
71
+ #end
66
72
this .location = null ;
67
73
this .inputs = ImmutableCollections .copy (inputs );
68
74
this .importedFrom = null ;
69
75
}
70
- #else
71
-
72
- public InputSource (String location ) {
73
- this .location = location ;
74
- }
75
- #end
76
76
77
77
/**
78
- #if ( $isMavenModel )
79
78
* 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
83
79
*
84
80
* @return the location
85
81
*/
@@ -96,6 +92,7 @@ public String getLocation() {
96
92
public String getModelId () {
97
93
return this .modelId ;
98
94
}
95
+ #end
99
96
100
97
/**
101
98
* Gets the parent InputLocation where this InputLocation may have been imported from.
@@ -117,14 +114,23 @@ public boolean equals(Object o) {
117
114
return false ;
118
115
}
119
116
InputSource that = (InputSource ) o ;
117
+ #if ( $isMavenModel )
120
118
return Objects .equals (modelId , that .modelId )
121
119
&& Objects .equals (location , that .location )
122
120
&& Objects .equals (inputs , that .inputs );
121
+ #else
122
+ return Objects .equals (location , that .location )
123
+ && Objects .equals (inputs , that .inputs );
124
+ #end
123
125
}
124
126
125
127
@ Override
126
128
public int hashCode () {
129
+ #if ( $isMavenModel )
127
130
return Objects .hash (modelId , location , inputs );
131
+ #else
132
+ return Objects .hash (location , inputs );
133
+ #end
128
134
}
129
135
130
136
Stream <InputSource > sources () {
@@ -136,16 +142,14 @@ public String toString() {
136
142
if (inputs != null ) {
137
143
return inputs .stream ().map (InputSource ::toString ).collect (Collectors .joining (", " , "merged[" , "]" ));
138
144
}
139
- return getModelId () + " " + getLocation ();
145
+ #if ( $isMavenModel )
146
+ return getModelId () != null ? getModelId () + " " + getLocation () : getLocation ();
147
+ #else
148
+ return getLocation ();
149
+ #end
140
150
}
141
151
142
152
public static InputSource merge (InputSource src1 , InputSource src2 ) {
143
153
return new InputSource (Stream .concat (src1 .sources (), src2 .sources ()).collect (Collectors .toSet ()));
144
154
}
145
- #else
146
- @ Override
147
- public String toString () {
148
- return getLocation ();
149
- }
150
- #end
151
155
}
0 commit comments