allows java.lang.String.length() + test + doc

This commit is contained in:
Renaud Pawlak 2016-01-06 16:07:24 +01:00
parent 4b3fcff2e6
commit 64b024bc0f
5 changed files with 9 additions and 0 deletions

View File

@ -126,6 +126,7 @@ Here follows the list of allowed Java classes in JSweet:
\item \texttt{indexOf(java.lang.String)}
\item \texttt{lastIndexOf(java.lang.String)}
\item \texttt{lastIndexOf(java.lang.String,int)}
\item \texttt{length()} (transpiles to \texttt{length})
\item \texttt{substring(int)}
\item \texttt{substring(int,int)} (with the JavaScript behavior)
\item \texttt{replace(java.lang.String,java.lang.String)}

View File

@ -109,6 +109,7 @@ public class TypeChecker {
AUTHORIZED_STRING_METHODS.add("trim()");
AUTHORIZED_STRING_METHODS.add("toLowerCase()");
AUTHORIZED_STRING_METHODS.add("toUpperCase()");
AUTHORIZED_STRING_METHODS.add("length()");
FORBIDDEN_JDK_FUNCTIONAL_METHODS.add("and");
FORBIDDEN_JDK_FUNCTIONAL_METHODS.add("negate");

View File

@ -282,7 +282,12 @@ public class Java2TypeScriptAdapter extends AbstractPrinterAdapter {
getPrinter().print(")");
return true;
}
if (matchesMethod(targetClassName, targetMethodName, String.class.getName(), "length")) {
getPrinter().print(invocation.meth);
return true;
}
if (matchesMethod(targetClassName, targetMethodName, null, INDEXED_GET_FUCTION_NAME)) {
if (isWithinGlobals(targetClassName)) {
report(invocation, JSweetProblem.GLOBAL_INDEXER_GET);

View File

@ -55,6 +55,7 @@ public class ApiTests extends AbstractTest {
assertEquals("testc", result.<String> get("s4"));
assertEquals(2, result.<Number> get("i1").intValue());
assertEquals(-1, result.<Number> get("i2").intValue());
assertEquals(4, result.<Number> get("l").intValue());
}, getSourceFile(JdkInvocations.class));
}

View File

@ -36,6 +36,7 @@ public class JdkInvocations {
$export("s4", s.concat("c"));
$export("i1", s.indexOf("s"));
$export("i2", s.lastIndexOf("gg"));
$export("l", s.length());
s.lastIndexOf("", 10);
Other4 o2 = new Other4();
o2.toString();