in boot/src/main/java/org/netbeans/html/boot/impl/JsCallback.java [27:116]
final String parse(String body, boolean promise) {
StringBuilder sb = new StringBuilder();
int pos = 0;
for (;;) {
int next = body.indexOf(".@", pos);
if (next == -1) {
sb.append(body.substring(pos));
body = sb.toString();
break;
}
int ident = next;
while (ident > 0) {
if (!Character.isJavaIdentifierPart(body.charAt(--ident))) {
ident++;
break;
}
}
String refId = body.substring(ident, next);
sb.append(body.substring(pos, ident));
int sigBeg = body.indexOf('(', next);
int sigEnd = body.indexOf(')', sigBeg);
int colon4 = body.indexOf("::", next);
if (sigBeg == -1 || sigEnd == -1 || colon4 == -1) {
throw new IllegalStateException(
"""
Wrong format of instance callback. Should be: 'inst.@pkg.Class::method(Ljava/lang/Object;)(param)':
"""
+ body
);
}
String fqn = body.substring(next + 2, colon4);
String method = body.substring(colon4 + 2, sigBeg);
String params = body.substring(sigBeg, sigEnd + 1);
int paramBeg = body.indexOf('(', sigEnd + 1);
if (paramBeg == -1) {
throw new IllegalStateException(
"""
Wrong format of instance callback. Should be: 'inst.@pkg.Class::method(Ljava/lang/Object;)(param)':
"""
+ body
);
}
sb.append(callMethod(refId, promise, fqn, method, params));
if (body.charAt(paramBeg + 1) != (')')) {
sb.append(",");
}
pos = paramBeg + 1;
}
pos = 0;
sb = null;
for (;;) {
int next = body.indexOf("@", pos);
if (next == -1) {
if (sb == null) {
return body;
}
sb.append(body.substring(pos));
return sb.toString();
}
if (sb == null) {
sb = new StringBuilder();
}
sb.append(body.substring(pos, next));
int sigBeg = body.indexOf('(', next);
int sigEnd = body.indexOf(')', sigBeg);
int colon4 = body.indexOf("::", next);
int paramBeg = body.indexOf('(', sigEnd + 1);
if (sigBeg == -1 || sigEnd == -1 || colon4 == -1 || paramBeg == -1) {
throw new IllegalStateException(
"""
Wrong format of static callback. Should be: '@pkg.Class::staticMethod(Ljava/lang/Object;)(param)':
"""
+ body
);
}
String fqn = body.substring(next + 1, colon4);
String method = body.substring(colon4 + 2, sigBeg);
String params = body.substring(sigBeg, sigEnd + 1);
sb.append(callMethod(null, promise, fqn, method, params));
pos = paramBeg + 1;
}
}