Skip to content

Commit df6f2ae

Browse files
committed
fix for Enum.valueOf(String) missing
1 parent 1673c46 commit df6f2ae

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/Java2ScriptVisitor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,9 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
14501450
buffer.append(trailingBuffer.getAssertString());
14511451
addDefaultConstructor();
14521452
buffer.append("var $vals=[];\r\n");
1453-
buffer.append("Clazz.newMeth(C$, 'values', function() { return $vals }, 1);\r\n");
1453+
// implicit Enum methods added as trailer
1454+
buffer.append("Clazz.newMeth(C$, 'values', function() { return $vals }, 1);\r\n");
1455+
buffer.append("Clazz.newMeth(C$, 'valueOf$S, '$valueOf$S', function(name) { for (var val in $vals){ if ($vals[val].$name == name) return $vals[val]} return null }, 1);\r\n");
14541456
} else {
14551457
buffer.append(trailingBuffer); // also writes the assert string
14561458
if (isAnonymous) {

0 commit comments

Comments
 (0)