Skip to content

Commit 483ddb6

Browse files
authored
Merge pull request #24 from BobHanson/yadav1
Yadav1
2 parents fef1a1a + edacf79 commit 483ddb6

23 files changed

+4634
-43
lines changed
585 Bytes
Binary file not shown.
585 Bytes
Binary file not shown.

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

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
import org.eclipse.jdt.core.dom.WhileStatement;
123123
import org.eclipse.jdt.core.dom.WildcardType;
124124

125+
// BH 6/19/2018 -- adds .j2s j2s.class.replacements=org.apache.log4j.->jalview.javascript.log4j.;
125126
// BH 5/15/2018 -- fix for a[pt++] |= 3 incrementing pt twice and disregarding a[][] (see test/Test_Or.java)
126127
// BH 3/27/2018 -- fix for anonymous inner classes of inner classes not having this.this$0
127128
// BH 1/5/2018 -- @j2sKeep removed; refactored into one class
@@ -1450,7 +1451,9 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
14501451
buffer.append(trailingBuffer.getAssertString());
14511452
addDefaultConstructor();
14521453
buffer.append("var $vals=[];\r\n");
1453-
buffer.append("Clazz.newMeth(C$, 'values', function() { return $vals }, 1);\r\n");
1454+
// implicit Enum methods added as trailer
1455+
buffer.append("Clazz.newMeth(C$, 'values', function() { return $vals }, 1);\r\n");
1456+
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");
14541457
} else {
14551458
buffer.append(trailingBuffer); // also writes the assert string
14561459
if (isAnonymous) {
@@ -4359,9 +4362,10 @@ private static String j2sGetParamCode(ITypeBinding binding, boolean addAAA, bool
43594362
name = "S";
43604363
break;
43614364
default:
4362-
if (prefix != null)
4365+
if (prefix == null)
4366+
name = checkClassReplacement(name);
4367+
else
43634368
name = (asGenericObject ? "O" : prefix + name); // "O";//
4364-
43654369
name = name.replace("java.lang.", "").replace('.', '_');
43664370
break;
43674371
}
@@ -4653,6 +4657,54 @@ public void setDebugging(boolean isDebugging) {
46534657
}
46544658

46554659

4660+
4661+
private static Map<String, String> htClassReplacements;
4662+
private static List<String> lstPackageReplacements;
4663+
4664+
public static void setClassReplacements(String keyValues) {
4665+
// j2s.class.replacements=org.apache.log4j.*:jalview.jslogger.;
4666+
htClassReplacements = null;
4667+
if (keyValues == null)
4668+
return;
4669+
htClassReplacements = new Hashtable<String, String>();
4670+
lstPackageReplacements = new ArrayList<String>();
4671+
String[] pairs = keyValues.split(";");
4672+
for (int i = pairs.length; --i >= 0;) {
4673+
pairs[i] = pairs[i].trim();
4674+
if (pairs[i].length() == 0)
4675+
continue;
4676+
String[] kv = pairs[i].split("->");
4677+
htClassReplacements.put(kv[0], kv[1]);
4678+
if (kv[0].endsWith("."))
4679+
lstPackageReplacements.add(kv[0]);
4680+
System.err.println("class replacement " + kv[0] + " --> " + kv[1]);
4681+
}
4682+
}
4683+
4684+
4685+
private static String checkClassReplacement(String className) {
4686+
if (htClassReplacements != null) {
4687+
String rep = htClassReplacements.get(className);
4688+
if (rep == null && lstPackageReplacements != null) {
4689+
for (int i = lstPackageReplacements.size(); --i >= 0;) {
4690+
rep = lstPackageReplacements.get(i);
4691+
if (className.startsWith(rep)) {
4692+
rep = htClassReplacements.get(rep) + className.substring(rep.length());
4693+
break;
4694+
}
4695+
if (i == 0)
4696+
rep = null;
4697+
}
4698+
4699+
}
4700+
if (rep != null) {
4701+
System.out.println(className + " -> " + rep);
4702+
return rep;
4703+
}
4704+
}
4705+
return className;
4706+
}
4707+
46564708
/**
46574709
* tracks file byte pointers for @j2sNative, @j2sIgnore
46584710
*/
@@ -4714,7 +4766,7 @@ private String getNestedClazzLoads(String className, boolean doCache) {
47144766
// loop through packages and outer Class
47154767
while (i < parts.length && (i == 1 || !Character.isUpperCase(parts[i - 1].charAt(0))))
47164768
s += "." + parts[i++];
4717-
s = "'" + s + "'";
4769+
s = "'" + checkClassReplacement(s) + "'";
47184770
// int nlast = parts.length;
47194771
if (i < parts.length) {
47204772
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+
Java2ScriptVisitor.setClassReplacements(getProperty("j2s.class.replacements"));
131132
String j2sPath = siteFolder + "/swingjs/j2s";
132133
try {
133134

-2.63 MB
Binary file not shown.

sources/net.sf.j2s.java.core/build_core_applet.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@
294294

295295
<echo>TODO: Could delete demo html files? </echo>
296296

297-
<echo>creating SwingJS-site.zip </echo>
298-
<zip destfile="SwingJS-site.zip" basedir="site" />
297+
<echo>creating dist/SwingJS-site.zip </echo>
298+
<zip destfile="dist/SwingJS-site.zip" basedir="site" />
299299

300300
</target>
301301

2.66 MB
Binary file not shown.

sources/net.sf.j2s.java.core/src/a2s/TextArea.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public TextArea(String text, int rows, int cols) {
2929
setViewportView(ta = new JTextArea(text, rows, cols));
3030
awtDefaults();
3131
}
32+
33+
public void setCaretPosition(int pos) {
34+
ta.setCaretPosition(pos);
35+
}
3236

3337
void awtDefaults() {
3438
// setAutoscrolls(true);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 1996, 1997, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package java.beans;
27+
28+
import java.util.EventListener;
29+
30+
/**
31+
* A VetoableChange event gets fired whenever a bean changes a "constrained"
32+
* property. You can register a VetoableChangeListener with a source bean
33+
* so as to be notified of any constrained property updates.
34+
*/
35+
public interface VetoableChangeListener extends EventListener {
36+
/**
37+
* This method gets called when a constrained property is changed.
38+
*
39+
* @param evt a <code>PropertyChangeEvent</code> object describing the
40+
* event source and the property that has changed.
41+
* @exception PropertyVetoException if the recipient wishes the property
42+
* change to be rolled back.
43+
*/
44+
void vetoableChange(PropertyChangeEvent evt)
45+
throws PropertyVetoException;
46+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package java.beans;
27+
28+
import java.util.EventListenerProxy;
29+
30+
/**
31+
* A class which extends the <code>EventListenerProxy</code> specifically
32+
* for associating a <code>VetoableChangeListener</code> with a "constrained"
33+
* property. Instances of this class can be added as a
34+
* <code>VetoableChangeListener</code> to a bean which supports firing
35+
* VetoableChange events.
36+
* <p>
37+
* If the object has a <code>getVetoableChangeListeners()</code>
38+
* method then the array returned could be a mixture of
39+
* <code>VetoableChangeListener</code> and
40+
* <code>VetoableChangeListenerProxy</code> objects.
41+
* <p>
42+
* @see java.util.EventListenerProxy
43+
* @see VetoableChangeListener
44+
* @see VetoableChangeSupport#getVetoableChangeListeners
45+
* @since 1.4
46+
*/
47+
public class VetoableChangeListenerProxy extends EventListenerProxy
48+
implements VetoableChangeListener {
49+
50+
private String propertyName;
51+
52+
/**
53+
* @param propertyName The name of the property to listen on.
54+
* @param listener The listener object
55+
*/
56+
public VetoableChangeListenerProxy(String propertyName,
57+
VetoableChangeListener listener) {
58+
super(listener);
59+
this.propertyName = propertyName;
60+
}
61+
62+
/**
63+
* Forwards the property change event to the listener delegate.
64+
*
65+
* @param evt the property change event
66+
*
67+
* @exception PropertyVetoException if the recipient wishes the property
68+
* change to be rolled back.
69+
*/
70+
public void vetoableChange(PropertyChangeEvent evt) throws
71+
PropertyVetoException{
72+
((VetoableChangeListener)getListener()).vetoableChange(evt);
73+
}
74+
75+
/**
76+
* Returns the name of the named property associated with the
77+
* listener.
78+
*/
79+
public String getPropertyName() {
80+
return propertyName;
81+
}
82+
}

0 commit comments

Comments
 (0)