mirror of
https://github.com/cincheo/jsweet.git
synced 2025-12-15 15:29:22 +00:00
handle static indexers + typo
This commit is contained in:
parent
2961cbb63a
commit
2259a5f3f3
@ -494,7 +494,7 @@ Globals myVariable = null;
|
|||||||
|
|
||||||
One must remember that `Globals` classes and `global` packages are erased at runtime so that their members will be directly accessible. For instance `mypackage.Globals.m()` in a JSweet program corresponds to the `mypackage.m()` function in the generated code and in the JavaScript VM at runtime. Also, `mypackage.globals.Globals.m()` corresponds to *m()*.
|
One must remember that `Globals` classes and `global` packages are erased at runtime so that their members will be directly accessible. For instance `mypackage.Globals.m()` in a JSweet program corresponds to the `mypackage.m()` function in the generated code and in the JavaScript VM at runtime. Also, `mypackage.globals.Globals.m()` corresponds to *m()*.
|
||||||
|
|
||||||
In order to erase packages in the generated code, programmers can also use the `@Root` annotation, which will be explained in Section \[packaging\].
|
In order to erase packages in the generated code, programmers can also use the `@Root` annotation, which will be explained in Section \[packaging\].
|
||||||
|
|
||||||
### Optional parameters
|
### Optional parameters
|
||||||
|
|
||||||
|
|||||||
@ -521,7 +521,7 @@ Globals myVariable = null;
|
|||||||
|
|
||||||
One must remember that \texttt{Globals} classes and \texttt{global} packages are erased at runtime so that their members will be directly accessible. For instance \texttt{mypackage.Globals.m()} in a JSweet program corresponds to the \texttt{mypackage.m()} function in the generated code and in the JavaScript VM at runtime. Also, \texttt{mypackage.globals.Globals.m()} corresponds to \emph{m()}.
|
One must remember that \texttt{Globals} classes and \texttt{global} packages are erased at runtime so that their members will be directly accessible. For instance \texttt{mypackage.Globals.m()} in a JSweet program corresponds to the \texttt{mypackage.m()} function in the generated code and in the JavaScript VM at runtime. Also, \texttt{mypackage.globals.Globals.m()} corresponds to \emph{m()}.
|
||||||
|
|
||||||
In order to erase packages in the generated code, programmers can also use the \texttt{@Root} annotation, which will be explained in Section~\ref{packaging}.
|
In order to erase packages in the generated code, programmers can also use the \texttt{@Root} annotation, which will be explained in Section \ref{packaging}.
|
||||||
|
|
||||||
\section{Optional parameters}
|
\section{Optional parameters}
|
||||||
\label{optional-parameters}
|
\label{optional-parameters}
|
||||||
|
|||||||
@ -186,6 +186,10 @@ public abstract class JSweetConfig {
|
|||||||
/** The constant for indexed assignment function. */
|
/** The constant for indexed assignment function. */
|
||||||
public static final String INDEXED_SET_FUCTION_NAME = "$set";
|
public static final String INDEXED_SET_FUCTION_NAME = "$set";
|
||||||
public static final String INDEXED_DELETE_FUCTION_NAME = "$delete";
|
public static final String INDEXED_DELETE_FUCTION_NAME = "$delete";
|
||||||
|
public static final String INDEXED_GET_STATIC_FUCTION_NAME = "$getStatic";
|
||||||
|
/** The constant for indexed assignment function. */
|
||||||
|
public static final String INDEXED_SET_STATIC_FUCTION_NAME = "$setStatic";
|
||||||
|
public static final String INDEXED_DELETE_STATIC_FUCTION_NAME = "$deleteStatic";
|
||||||
public static final String NEW_FUNCTION_NAME = "$new";
|
public static final String NEW_FUNCTION_NAME = "$new";
|
||||||
public static final String ANONYMOUS_FUNCTION_NAME = "$apply";
|
public static final String ANONYMOUS_FUNCTION_NAME = "$apply";
|
||||||
public static final String ANONYMOUS_STATIC_FUNCTION_NAME = "$applyStatic";
|
public static final String ANONYMOUS_STATIC_FUNCTION_NAME = "$applyStatic";
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.jsweet.transpiler.typescript;
|
package org.jsweet.transpiler.typescript;
|
||||||
|
|
||||||
import static org.jsweet.JSweetConfig.ANNOTATION_ERASED;
|
import static org.jsweet.JSweetConfig.ANNOTATION_ERASED;
|
||||||
@ -26,6 +26,9 @@ import static org.jsweet.JSweetConfig.GLOBALS_PACKAGE_NAME;
|
|||||||
import static org.jsweet.JSweetConfig.INDEXED_DELETE_FUCTION_NAME;
|
import static org.jsweet.JSweetConfig.INDEXED_DELETE_FUCTION_NAME;
|
||||||
import static org.jsweet.JSweetConfig.INDEXED_GET_FUCTION_NAME;
|
import static org.jsweet.JSweetConfig.INDEXED_GET_FUCTION_NAME;
|
||||||
import static org.jsweet.JSweetConfig.INDEXED_SET_FUCTION_NAME;
|
import static org.jsweet.JSweetConfig.INDEXED_SET_FUCTION_NAME;
|
||||||
|
import static org.jsweet.JSweetConfig.INDEXED_DELETE_STATIC_FUCTION_NAME;
|
||||||
|
import static org.jsweet.JSweetConfig.INDEXED_GET_STATIC_FUCTION_NAME;
|
||||||
|
import static org.jsweet.JSweetConfig.INDEXED_SET_STATIC_FUCTION_NAME;
|
||||||
import static org.jsweet.JSweetConfig.LANG_PACKAGE;
|
import static org.jsweet.JSweetConfig.LANG_PACKAGE;
|
||||||
import static org.jsweet.JSweetConfig.TUPLE_CLASSES_PACKAGE;
|
import static org.jsweet.JSweetConfig.TUPLE_CLASSES_PACKAGE;
|
||||||
import static org.jsweet.JSweetConfig.UNION_CLASS_NAME;
|
import static org.jsweet.JSweetConfig.UNION_CLASS_NAME;
|
||||||
@ -291,6 +294,16 @@ public class Java2TypeScriptAdapter extends AbstractPrinterAdapter {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (matchesMethod(targetClassName, targetMethodName, null, INDEXED_GET_STATIC_FUCTION_NAME)) {
|
||||||
|
if (isWithinGlobals(targetClassName)) {
|
||||||
|
report(invocation, JSweetProblem.GLOBAL_INDEXER_GET);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
getPrinter().print(fieldAccess.selected).print("[").print(invocation.args.head).print("]");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (matchesMethod(targetClassName, targetMethodName, null, INDEXED_SET_FUCTION_NAME)) {
|
if (matchesMethod(targetClassName, targetMethodName, null, INDEXED_SET_FUCTION_NAME)) {
|
||||||
|
|
||||||
if (isWithinGlobals(targetClassName)) {
|
if (isWithinGlobals(targetClassName)) {
|
||||||
@ -317,6 +330,18 @@ public class Java2TypeScriptAdapter extends AbstractPrinterAdapter {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (matchesMethod(targetClassName, targetMethodName, null, INDEXED_SET_STATIC_FUCTION_NAME)) {
|
||||||
|
|
||||||
|
if (isWithinGlobals(targetClassName)) {
|
||||||
|
report(invocation, JSweetProblem.GLOBAL_INDEXER_SET);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
getPrinter().print(fieldAccess.selected).print("[").print(invocation.args.head).print("] = ").print(invocation.args.tail.head);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (matchesMethod(targetClassName, targetMethodName, null, INDEXED_DELETE_FUCTION_NAME)) {
|
if (matchesMethod(targetClassName, targetMethodName, null, INDEXED_DELETE_FUCTION_NAME)) {
|
||||||
if (isWithinGlobals(targetClassName)) {
|
if (isWithinGlobals(targetClassName)) {
|
||||||
report(invocation, JSweetProblem.GLOBAL_DELETE);
|
report(invocation, JSweetProblem.GLOBAL_DELETE);
|
||||||
@ -331,6 +356,16 @@ public class Java2TypeScriptAdapter extends AbstractPrinterAdapter {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (matchesMethod(targetClassName, targetMethodName, null, INDEXED_DELETE_STATIC_FUCTION_NAME)) {
|
||||||
|
if (isWithinGlobals(targetClassName)) {
|
||||||
|
report(invocation, JSweetProblem.GLOBAL_DELETE);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
getPrinter().print("delete ").print(fieldAccess.selected).print("[").print(invocation.args.head).print("]");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (targetClassName != null && targetClassName.endsWith(GLOBALS_CLASS_NAME)) {
|
if (targetClassName != null && targetClassName.endsWith(GLOBALS_CLASS_NAME)) {
|
||||||
if (getPrinter().getContext().useModules) {
|
if (getPrinter().getContext().useModules) {
|
||||||
if (JSweetConfig.GLOBALS_PACKAGE_NAME.equals(targetType.getEnclosingElement().getSimpleName().toString())) {
|
if (JSweetConfig.GLOBALS_PACKAGE_NAME.equals(targetType.getEnclosingElement().getSimpleName().toString())) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user