@@ -31,7 +31,7 @@ public class MacroLocationFactory {
3131 private MacroLocationFactory () {}
3232
3333 /** The singleton instance of the factory. */
34- private static MacroLocationFactory instance = new MacroLocationFactory ();
34+ private static final MacroLocationFactory instance = new MacroLocationFactory ();
3535
3636 /**
3737 * Returns the singleton instance of the factory.
@@ -49,7 +49,7 @@ public static MacroLocationFactory getInstance() {
4949 * @return a new {@link MacroLocation} object for an unknown location.
5050 */
5151 public MacroLocation createUnknownLocation (@ Nonnull String name ) {
52- return new MacroLocation (name , MacroSource .unknown , "" );
52+ return new MacroLocation (name , MacroSource .unknown , "" , "" );
5353 }
5454
5555 /**
@@ -59,7 +59,11 @@ public MacroLocation createUnknownLocation(@Nonnull String name) {
5959 * @return a new {@link MacroLocation} object for a global Panel.
6060 */
6161 public MacroLocation createGlobalLocation (@ Nonnull String name ) {
62- return new MacroLocation (name , MacroSource .global , MacroSource .global .getSourceName ());
62+ return new MacroLocation (
63+ name ,
64+ MacroSource .global ,
65+ MacroSource .global .getSourceName (),
66+ MacroSource .global .getSourceName ());
6367 }
6468
6569 /**
@@ -69,7 +73,11 @@ public MacroLocation createGlobalLocation(@Nonnull String name) {
6973 * @return a new {@link MacroLocation} object for a campaign Panel.
7074 */
7175 public MacroLocation createCampaignLocation (@ Nonnull String name ) {
72- return new MacroLocation (name , MacroSource .campaign , MacroSource .campaign .getSourceName ());
76+ return new MacroLocation (
77+ name ,
78+ MacroSource .campaign ,
79+ MacroSource .campaign .getSourceName (),
80+ MacroSource .campaign .getSourceName ());
7381 }
7482
7583 /**
@@ -80,7 +88,7 @@ public MacroLocation createCampaignLocation(@Nonnull String name) {
8088 * @return a new {@link MacroLocation} object for a token.
8189 */
8290 public MacroLocation createTokenLocation (@ Nonnull String name , @ Nonnull Token token ) {
83- return new MacroLocation (name , MacroSource .token , token .getName (), null , token );
91+ return new MacroLocation (name , MacroSource .token , token .getName (), "Token:" + token . getName () );
8492 }
8593
8694 /**
@@ -92,7 +100,7 @@ public MacroLocation createTokenLocation(@Nonnull String name, @Nonnull Token to
92100 */
93101 public MacroLocation createLibTokenLocation (@ Nonnull String name , @ Nonnull Token libToken ) {
94102 return new MacroLocation (
95- name , MacroSource .library , libToken .getName ().substring (4 ), null , libToken );
103+ name , MacroSource .library , libToken .getName ().substring (4 ), libToken . getName () );
96104 }
97105
98106 /**
@@ -102,18 +110,22 @@ public MacroLocation createLibTokenLocation(@Nonnull String name, @Nonnull Token
102110 * @return a new {@link MacroLocation} object for a GM Panel.
103111 */
104112 public MacroLocation createGmLocation (@ Nonnull String name ) {
105- return new MacroLocation (name , MacroSource .gm , MacroSource .gm .getSourceName ());
113+ return new MacroLocation (
114+ name , MacroSource .gm , MacroSource .gm .getSourceName (), MacroSource .gm .getSourceName ());
106115 }
107116
108117 /**
109118 * Creates a new {@link MacroLocation} object for a library location.
110119 *
111- * @param name the name of the macro .
120+ * @param functionName the name of the function .
112121 * @return a new {@link MacroLocation} object for a library location.
113122 */
114123 public MacroLocation createExecFunctionLocation (@ Nonnull String functionName ) {
115124 return new MacroLocation (
116- MacroSource .execFunction .getSourceName (), MacroSource .execFunction , functionName );
125+ MacroSource .execFunction .getSourceName (),
126+ MacroSource .execFunction ,
127+ functionName ,
128+ functionName );
117129 }
118130
119131 /**
@@ -126,6 +138,7 @@ public MacroLocation createMacroLinkLocation(@Nonnull String name) {
126138 return new MacroLocation (
127139 MacroSource .macroLink .getSourceName (),
128140 MacroSource .macroLink ,
141+ MacroSource .macroLink .getSourceName (),
129142 MacroSource .macroLink .getSourceName ());
130143 }
131144
@@ -136,13 +149,14 @@ public MacroLocation createMacroLinkLocation(@Nonnull String name) {
136149 * @return a new {@link MacroLocation} object for an event.
137150 */
138151 public MacroLocation createEventLocation (@ Nonnull String name ) {
139- return new MacroLocation (MacroSource .event .getSourceName (), MacroSource .event , name );
152+ return new MacroLocation (MacroSource .event .getSourceName (), MacroSource .event , name , name );
140153 }
141154
142155 public MacroLocation createSentryIoLoggingLocation () {
143156 return new MacroLocation (
144157 MacroSource .sentryIoLogging .getSourceName (),
145158 MacroSource .sentryIoLogging ,
159+ MacroSource .sentryIoLogging .getSourceName (),
146160 MacroSource .sentryIoLogging .getSourceName ());
147161 }
148162
@@ -154,29 +168,40 @@ public MacroLocation createSentryIoLoggingLocation() {
154168 * @return a new {@link MacroLocation} object for a URI location.
155169 */
156170 public MacroLocation createUriLocation (@ Nonnull String name , @ Nullable URI calledFrom ) {
171+ URI uri ;
157172 try {
158- var uri = new URI (name );
159- if (uri .getScheme () == null ) {
160- if (calledFrom == null ) {
161- return createUnknownLocation (name );
162- }
163- uri = calledFrom .resolve (uri );
164- }
165- return new MacroLocation (uri .getPath (), MacroSource .uri , uri .getHost (), uri , null );
173+ uri = new URI (name );
166174 } catch (URISyntaxException e ) {
167175 return createUnknownLocation (name );
168176 }
177+
178+ if (uri .getHost () == null ) {
179+ if (calledFrom == null ) {
180+ return createUnknownLocation (name );
181+ }
182+ uri = calledFrom .resolve (uri );
183+ }
184+
185+ var scheme = uri .getScheme ();
186+ if (scheme == null || !scheme .equalsIgnoreCase ("lib" )) {
187+ return createUnknownLocation (name );
188+ }
189+
190+ return new MacroLocation (
191+ uri .getPath ().substring (1 ), MacroSource .uri , uri .getHost (), uri .getHost (), uri );
169192 }
170193
171194 /**
172195 * Creates a new {@link MacroLocation} object for the chat box.
173196 *
174- * @param token the token associated with the chat box.
175197 * @return a new {@link MacroLocation} object for a the chat box.
176198 */
177199 public MacroLocation createChatLocation () {
178200 return new MacroLocation (
179- MacroSource .chat .getSourceName (), MacroSource .chat , MacroSource .chat .getSourceName ());
201+ MacroSource .chat .getSourceName (),
202+ MacroSource .chat ,
203+ MacroSource .chat .getSourceName (),
204+ MacroSource .chat .getSourceName ());
180205 }
181206
182207 /**
@@ -186,11 +211,8 @@ public MacroLocation createChatLocation() {
186211 * @return a new {@link MacroLocation} object for a tooltip.
187212 */
188213 public MacroLocation createToolTipLocation (@ Nullable Token token ) {
214+ var location = token != null ? token .getName () : "" ;
189215 return new MacroLocation (
190- MacroSource .tooltip .getSourceName (),
191- MacroSource .tooltip ,
192- token != null ? token .getName () : "" ,
193- null ,
194- token );
216+ MacroSource .tooltip .getSourceName (), MacroSource .tooltip , location , location );
195217 }
196218}
0 commit comments