Skip to content

Commit 4a13f8d

Browse files
committed
[refactor] reorder and format FunctionSignature
1 parent 8c79132 commit 4a13f8d

File tree

1 file changed

+47
-53
lines changed

1 file changed

+47
-53
lines changed

exist-core/src/main/java/org/exist/xquery/FunctionSignature.java

Lines changed: 47 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Arrays;
2525
import java.util.HashMap;
2626
import java.util.Map;
27+
2728
import org.exist.Namespaces;
2829
import org.exist.dom.QName;
2930
import org.exist.xquery.value.FunctionParameterSequenceType;
@@ -33,7 +34,7 @@
3334
/**
3435
* Describes the signature of a built-in or user-defined function, i.e.
3536
* its name, the type and cardinality of its arguments and its return type.
36-
*
37+
*
3738
* @author wolf
3839
* @author lcahlander
3940
* @version 1.3
@@ -43,25 +44,20 @@ public class FunctionSignature {
4344
/**
4445
* Default sequence type for function parameters.
4546
*/
46-
public final static SequenceType DEFAULT_TYPE = new SequenceType(Type.ITEM, Cardinality.ZERO_OR_MORE);
47+
public static final SequenceType DEFAULT_TYPE = new SequenceType(Type.ITEM, Cardinality.ZERO_OR_MORE);
4748

4849
/**
4950
* Empty array to specify if a function doesn't take any arguments.
5051
*/
51-
public final static SequenceType[] NO_ARGS = new SequenceType[0];
52+
public static final SequenceType[] NO_ARGS = new SequenceType[0];
5253

5354
private static final String DEPRECATION_REMOVAL_MESSAGE = "\nThis function could be removed in the next major release version.";
54-
55-
public static SequenceType[] singleArgument(final SequenceType arg) {
56-
return new SequenceType[] { arg };
57-
}
58-
59-
private Annotation[] annotations;
6055
private final QName name;
56+
private Annotation[] annotations;
6157
private SequenceType[] arguments;
6258
private SequenceType returnType;
63-
private boolean isOverloaded = false;
64-
private String description = null;
59+
private boolean isVariadic;
60+
private String description;
6561
private String deprecated = null;
6662
private Map<String, String> metadata = null;
6763

@@ -70,7 +66,7 @@ public FunctionSignature(final FunctionSignature other) {
7066
this.arguments = other.arguments != null ? Arrays.copyOf(other.arguments, other.arguments.length) : null;
7167
this.returnType = other.returnType;
7268
this.annotations = other.annotations != null ? Arrays.copyOf(other.annotations, other.annotations.length) : null;
73-
this.isOverloaded = other.isOverloaded;
69+
this.isVariadic = other.isVariadic;
7470
this.deprecated = other.deprecated;
7571
this.description = other.description;
7672
this.metadata = other.metadata != null ? new HashMap<>(other.metadata) : null;
@@ -89,17 +85,13 @@ public FunctionSignature(final QName name, final SequenceType[] arguments, final
8985
}
9086

9187
public FunctionSignature(final QName name, final String description, final SequenceType[] arguments, final SequenceType returnType) {
92-
this(name, description, arguments, returnType, false);
88+
this(name, description, arguments, returnType, false);
9389
}
9490

9591
public FunctionSignature(final QName name, final String description, final SequenceType[] arguments, final SequenceType returnType, final String deprecated) {
9692
this(name, description, arguments, returnType, false);
9793
setDeprecated(deprecated);
9894
}
99-
100-
// public FunctionSignature(final QName name, final String description, final SequenceType[] arguments, final SequenceType returnType, final FunctionSignature deprecatedBy) {
101-
// this(name, description, arguments, returnType, false, "Moved to the module: " + deprecatedBy.getName().getNamespaceURI() + ", you should now use '" + deprecatedBy.getName().getPrefix() + ":" + deprecatedBy.getName().getLocalPart() + "' instead!");
102-
// }
10395

10496
public FunctionSignature(final QName name, final String description, final SequenceType[] arguments, final SequenceType returnType, final boolean overloaded, final String deprecated) {
10597
this(name, description, arguments, returnType, overloaded);
@@ -108,40 +100,44 @@ public FunctionSignature(final QName name, final String description, final Seque
108100

109101
/**
110102
* Create a new function signature.
111-
*
112-
* @param name the QName of the function.
103+
*
104+
* @param name the QName of the function.
113105
* @param description documentation string describing the function
114-
* @param arguments the sequence types of all expected arguments
115-
* @param returnType the sequence type returned by the function
116-
* @param overloaded set to true if the function may expect additional parameters
117-
*/
106+
* @param arguments the sequence types of all expected arguments
107+
* @param returnType the sequence type returned by the function
108+
* @param overloaded set to true if the function may expect additional parameters
109+
*/
118110
public FunctionSignature(final QName name, final String description, final SequenceType[] arguments, final SequenceType returnType, final boolean overloaded) {
119111
this.name = name;
120112
this.arguments = arguments;
121113
this.returnType = returnType;
122-
this.isOverloaded = overloaded;
114+
this.isVariadic = overloaded;
123115
this.description = description;
124116
}
125117

126118
public Annotation[] getAnnotations() {
127119
return annotations;
128120
}
129-
121+
122+
public void setAnnotations(final Annotation[] annotations) {
123+
this.annotations = annotations;
124+
}
125+
130126
public QName getName() {
131127
return name;
132128
}
133129

134130
public int getArgumentCount() {
135-
if(isOverloaded) {
131+
if (isVariadic) {
136132
return -1;
137133
}
138134
return arguments != null ? arguments.length : 0;
139135
}
140-
136+
141137
public FunctionId getFunctionId() {
142138
return new FunctionId(name, getArgumentCount());
143139
}
144-
140+
145141
public SequenceType getReturnType() {
146142
return returnType;
147143
}
@@ -157,21 +153,17 @@ public SequenceType[] getArgumentTypes() {
157153
public void setArgumentTypes(final SequenceType[] types) {
158154
this.arguments = types;
159155
}
160-
161-
public void setAnnotations(final Annotation[] annotations) {
162-
this.annotations = annotations;
163-
}
164-
156+
165157
public String getDescription() {
166-
return description;
158+
return description;
167159
}
168160

169161
public void setDescription(final String description) {
170162
this.description = description;
171163
}
172164

173165
public void addMetadata(final String key, final String value) {
174-
if(metadata == null) {
166+
if (metadata == null) {
175167
metadata = new HashMap<>(5);
176168
}
177169
final String old = metadata.get(key);
@@ -192,7 +184,7 @@ public Map<String, String> getMetadata() {
192184
}
193185

194186
public boolean isOverloaded() {
195-
return isOverloaded;
187+
return isVariadic;
196188
}
197189

198190
public boolean isDeprecated() {
@@ -206,17 +198,17 @@ public String getDeprecated() {
206198
return null;
207199
}
208200
}
209-
201+
210202
public final void setDeprecated(final String message) {
211203
deprecated = message;
212204
}
213205

214206
public boolean isPrivate() {
215207
final Annotation[] annotations = getAnnotations();
216-
if(annotations != null) {
217-
for(final Annotation annot : annotations) {
208+
if (annotations != null) {
209+
for (final Annotation annot : annotations) {
218210
final QName qn = annot.getName();
219-
if(qn.getNamespaceURI().equals(Namespaces.XPATH_FUNCTIONS_NS) && "private".equals(qn.getLocalPart())) {
211+
if (qn.getNamespaceURI().equals(Namespaces.XPATH_FUNCTIONS_NS) && "private".equals(qn.getLocalPart())) {
220212
return true;
221213
}
222214
}
@@ -229,29 +221,29 @@ public String toString() {
229221
final StringBuilder buf = new StringBuilder();
230222
buf.append(name.getStringValue());
231223
buf.append('(');
232-
if(arguments != null) {
224+
if (arguments != null) {
233225
final char ANON_VAR = 'a';
234-
for(int i = 0; i < arguments.length; i++) {
235-
if(i > 0) {
226+
for (int i = 0; i < arguments.length; i++) {
227+
if (i > 0) {
236228
buf.append(", ");
237229
}
238230
buf.append('$');
239-
if(arguments[i] instanceof FunctionParameterSequenceType) {
240-
buf.append(((FunctionParameterSequenceType)arguments[i]).getAttributeName());
231+
if (arguments[i] instanceof FunctionParameterSequenceType) {
232+
buf.append(((FunctionParameterSequenceType) arguments[i]).getAttributeName());
241233
} else {
242-
buf.append((char)(ANON_VAR + i));
234+
buf.append((char) (ANON_VAR + i));
243235
}
244236
buf.append(" as ");
245237
buf.append(arguments[i].toString());
246238
}
247-
248-
if(isOverloaded) {
239+
240+
if (isVariadic) {
249241
buf.append(", ...");
250242
}
251243
}
252244
buf.append(") as ");
253245
buf.append(returnType.toString());
254-
246+
255247
return buf.toString();
256248
}
257249

@@ -261,14 +253,16 @@ public boolean equals(final Object obj) {
261253
return false;
262254
}
263255
// quick comparison by object identity
264-
if (this == obj) { return true; }
256+
if (this == obj) {
257+
return true;
258+
}
265259

266260
// anonymous functions cannot be compared by name and argument count
267261
final FunctionSignature other = (FunctionSignature) obj;
268262
if (
269263
name == null || other.name == null ||
270-
name.getLocalPart().equals("") ||
271-
other.name.getLocalPart().equals("")
264+
name.getLocalPart().equals("") ||
265+
other.name.getLocalPart().equals("")
272266
) {
273267
return false;
274268
}
@@ -288,7 +282,7 @@ public FunctionSignature rename(final QName newName) {
288282
final SequenceType[] argumentsCopy = arguments != null ? Arrays.copyOf(arguments, arguments.length) : null;
289283
final FunctionSignature newFunctionSignature = new FunctionSignature(newName, description, argumentsCopy, returnType, deprecated);
290284
newFunctionSignature.annotations = annotations != null ? Arrays.copyOf(annotations, annotations.length) : null;
291-
newFunctionSignature.isOverloaded = isOverloaded;
285+
newFunctionSignature.isVariadic = isVariadic;
292286
newFunctionSignature.metadata = metadata != null ? new HashMap<>(metadata) : null;
293287
return newFunctionSignature;
294288
}

0 commit comments

Comments
 (0)