{"action":"opened","issue":{"url":"https://api.github.com/repos/cincheo/jsweet/issues/269","repository_url":"https://api.github.com/repos/cincheo/jsweet","labels_url":"https://api.github.com/repos/cincheo/jsweet/issues/269/labels{/name}","comments_url":"https://api.github.com/repos/cincheo/jsweet/issues/269/comments","events_url":"https://api.github.com/repos/cincheo/jsweet/issues/269/events","html_url":"https://github.com/cincheo/jsweet/issues/269","id":227731224,"number":269,"title":"Enums that implement an interface blow up on transpile","user":{"login":"StormeHawke","id":540587,"avatar_url":"https://avatars2.githubusercontent.com/u/540587?v=3","gravatar_id":"","url":"https://api.github.com/users/StormeHawke","html_url":"https://github.com/StormeHawke","followers_url":"https://api.github.com/users/StormeHawke/followers","following_url":"https://api.github.com/users/StormeHawke/following{/other_user}","gists_url":"https://api.github.com/users/StormeHawke/gists{/gist_id}","starred_url":"https://api.github.com/users/StormeHawke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StormeHawke/subscriptions","organizations_url":"https://api.github.com/users/StormeHawke/orgs","repos_url":"https://api.github.com/users/StormeHawke/repos","events_url":"https://api.github.com/users/StormeHawke/events{/privacy}","received_events_url":"https://api.github.com/users/StormeHawke/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-05-10T16:03:56Z","updated_at":"2017-05-10T16:03:56Z","closed_at":null,"body":"Consider the following simple case:\r\n\r\n```java\r\npublic enum DayOfWeek implements SomeInterface {\r\n    Sunday(0),\r\n    Monday(1),\r\n    Tuesday(2),\r\n    Wednesday(3),\r\n    Thursday(4),\r\n    Friday(5),\r\n    Saturday(6);\r\n\r\n    public final int persistenceValue;\r\n\r\n    DayOfWeek(int persistenceValue) {\r\n        this.persistenceValue = persistenceValue;\r\n    }\r\n}\r\n```\r\n\r\nAny interface will cause the problem, with or without methods that need overriding:\r\n\r\n```java\r\npublic interface SomeInterface {\r\n}\r\n```\r\n\r\nWhen attempting to transpile TS to JS with the above class, I get the following error output:\r\n```\r\n2017-05-10 11:10:35.035 INFO  JSweetTranspiler:1121 - launching tsc...\r\n2017-05-10 11:10:35.035 DEBUG ProcessUtil:181 - run command: /Users/brian.trezise/.jsweet-node_modules/bin/tsc --target ES5 --experimentalDecorators --sourceMap --rootDir /Users/brian.trezise/git/workforce-management-api-contract/target/ts --outDir /Users/brian.trezise/git/workforce-management-api-contract/target/js .tsc-rootfile.ts bundle.ts ../../.jsweet/candies/typings/src/typings/j4ts/0.4.0/.tsc-rootfile.d.ts ../../.jsweet/candies/typings/src/typings/j4ts/0.4.0/bundle.d.ts\r\n2017-05-10 11:10:36.036 INFO  JSweetTranspiler:1132 - bundle.ts(259,27): error TS1005: '{' expected.\r\n2017-05-10 11:10:36.036 ERROR output:46 - '{' expected at /Users/brian.trezise/git/workforce-management-api-contract/src/main/java/com/inin/wfm/api/constants/DayOfWeek.java(3)\r\n2017-05-10 11:10:36.036 INFO  JSweetTranspiler:1132 - bundle.ts(259,38): error TS1005: ';' expected.\r\n2017-05-10 11:10:36.036 ERROR output:46 - ';' expected at /Users/brian.trezise/git/workforce-management-api-contract/src/main/java/com/inin/wfm/api/constants/DayOfWeek.java(3)\r\n2017-05-10 11:10:36.036 INFO  JSweetTranspiler:1132 - bundle.ts(259,79): error TS1005: ';' expected.\r\n2017-05-10 11:10:36.036 ERROR output:46 - ';' expected at /Users/brian.trezise/git/workforce-management-api-contract/src/main/java/com/inin/wfm/api/constants/DayOfWeek.java(3)\r\n2017-05-10 11:10:38.038 INFO  JSweetTranspiler:721 - transpilation process finished in 4408 ms\r\n[ERROR] transpilation failed\r\norg.apache.maven.plugin.MojoFailureException: transpilation failed with 3 error(s) and 1 warning(s)\r\n\tat org.jsweet.AbstractJSweetMojo.transpile(AbstractJSweetMojo.java:337)\r\n\tat org.jsweet.JSweetMojo.execute(JSweetMojo.java:41)\r\n\tat org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)\r\n\tat org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)\r\n\tat org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)\r\n\tat org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)\r\n\tat org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)\r\n\tat org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)\r\n\tat org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)\r\n\tat org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)\r\n\tat org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)\r\n\tat org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)\r\n\tat org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)\r\n\tat org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)\r\n\tat org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)\r\n\tat org.apache.maven.cli.MavenCli.main(MavenCli.java:191)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat java.lang.reflect.Method.invoke(Method.java:498)\r\n\tat org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)\r\n\tat org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)\r\n\tat org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)\r\n\tat org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)\r\n```\r\nWe have several enums similar to this because our persistence layer saves the ordinal value whilst our api wants the string values, and I don't want to directly depend on the built-in enum ordinal as I consider that dangerous and unwise.\r\n\r\nI have written an external utility class to translate from ordinal to String as JSweet doesn't appear to be able to handle iterating over `Enum.values()` nor can I seem to pre-populate a static map to cache the values, but that utility currently relies on reflection to get the ordinal value, which is less than ideal.  \r\n\r\nThere are several possible fixes that would be helpful here, I'll list them in order from \"top preference\" to \"it's an improvement\":\r\n\r\n1. Allow me to statically populate a static map of values, similar to \r\n```java\r\n    private final static Map<Integer, DayOfWeek> ORDINAL_MAP = new HashMap<>();\r\n    static {\r\n        for (DayOfWeek c : values()) {\r\n            ORDINAL_MAP.put(c.backEndOrdinal, c);\r\n        }\r\n    }\r\n\r\n    public static DayOfWeek fromPersistenceValue(Integer value) {\r\n        return ORDINAL_MAP.get(value);\r\n    }\r\n```\r\n2. Support  `.values()` so I can iterate over that\r\n3. Don't break when an enum implements an interface (even if only by outputting a warning that it's not supported and skipping the interface portion, in this case the TS/JS code don't care about the ordinals anyway)"}}
{"actor":{"display_login":"StormeHawke"}}