Skip to content

Commit ba50f7e

Browse files
committed
adds .j2s param j2s.class.replacements
j2s.class.replacements=org.apache.log4j.->jalview.javascript.;
1 parent 81942c7 commit ba50f7e

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

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

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
14521452
buffer.append("var $vals=[];\r\n");
14531453
// implicit Enum methods added as trailer
14541454
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");
1455+
buffer.append("Clazz.newMeth(C$, '$valueOf$S', function(name) { for (var val in $vals){ if ($vals[val].$name == name) return $vals[val]} return null }, 1);\r\n");
14561456
} else {
14571457
buffer.append(trailingBuffer); // also writes the assert string
14581458
if (isAnonymous) {
@@ -4655,6 +4655,53 @@ public void setDebugging(boolean isDebugging) {
46554655
}
46564656

46574657

4658+
4659+
private static Map<String, String> htClassReplacements;
4660+
private static List<String> lstPackageReplacements;
4661+
4662+
// j2s.class.replacements=org.apache.log4j.*:jalview.jslogger.;
4663+
public void setClassReplacements(String keyValues) {
4664+
if (keyValues == null || htClassReplacements != null)
4665+
return;
4666+
htClassReplacements = new Hashtable<String, String>();
4667+
lstPackageReplacements = new ArrayList<String>();
4668+
String[] pairs = keyValues.split(";");
4669+
for (int i = pairs.length; --i >= 0;) {
4670+
pairs[i] = pairs[i].trim();
4671+
if (pairs[i].length() == 0)
4672+
continue;
4673+
String[] kv = pairs[i].split("->");
4674+
htClassReplacements.put(kv[0], kv[1]);
4675+
if (kv[0].endsWith("."))
4676+
lstPackageReplacements.add(kv[0]);
4677+
System.err.println("class replacement " + kv[0] + " --> " + kv[1]);
4678+
}
4679+
}
4680+
4681+
4682+
private String checkClassReplacement(String className) {
4683+
if (htClassReplacements != null) {
4684+
String rep = htClassReplacements.get(className);
4685+
if (rep == null && lstPackageReplacements != null) {
4686+
for (int i = lstPackageReplacements.size(); --i >= 0;) {
4687+
rep = lstPackageReplacements.get(i);
4688+
if (className.startsWith(rep)) {
4689+
rep = htClassReplacements.get(rep) + className.substring(rep.length());
4690+
break;
4691+
}
4692+
if (i == 0)
4693+
rep = null;
4694+
}
4695+
4696+
}
4697+
if (rep != null) {
4698+
System.out.println(className + " -> " + rep);
4699+
return rep;
4700+
}
4701+
}
4702+
return className;
4703+
}
4704+
46584705
/**
46594706
* tracks file byte pointers for @j2sNative, @j2sIgnore
46604707
*/
@@ -4716,7 +4763,7 @@ private String getNestedClazzLoads(String className, boolean doCache) {
47164763
// loop through packages and outer Class
47174764
while (i < parts.length && (i == 1 || !Character.isUpperCase(parts[i - 1].charAt(0))))
47184765
s += "." + parts[i++];
4719-
s = "'" + s + "'";
4766+
s = "'" + checkClassReplacement(s) + "'";
47204767
// int nlast = parts.length;
47214768
if (i < parts.length) {
47224769
s = "[" + s;

sources/net.sf.j2s.core/src/net/sf/j2s/core/compiler/Java2ScriptCompiler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public void process(ICompilationUnit sourceUnit, IContainer binaryFolder) {
128128
Java2ScriptVisitor.setNoQualifiedNamePackages(getProperty("j2s.compiler.nonqualified.classes"));
129129
boolean isDebugging = "debug".equals(getProperty("j2s.compiler.mode"));
130130
visitor.setDebugging(isDebugging);
131+
visitor.setClassReplacements(getProperty("j2s.class.replacements"));
131132
String j2sPath = siteFolder + "/swingjs/j2s";
132133
try {
133134

sources/net.sf.j2s.java.core/src/java/security/AccessController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ public static <T> T doPrivileged(PrivilegedAction<T> action) {
88
return action.run();
99
}
1010

11+
public static void doPrivileged(PrivilegedExceptionAction<Void> privilegedExceptionAction) {
12+
try {
13+
privilegedExceptionAction.run();
14+
} catch (Exception e) {
15+
}
16+
}
17+
1118
public static AccessControlContext getContext() {
1219
return new AccessController();
1320
}

0 commit comments

Comments
 (0)