Skip to content

Commit 3da6320

Browse files
committed
j2s runtime refactoring 2/2
1 parent 13a7075 commit 3da6320

File tree

6 files changed

+68
-77
lines changed

6 files changed

+68
-77
lines changed

sources/net.sf.j2s.java.core/src/java/awt/Component.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5235,7 +5235,7 @@ private boolean checkCoelescence() {
52355235
/**
52365236
* @j2sNative
52375237
*
5238-
* return Clazz.getDeclaringClazzForMethod$(this, "coalesceEvents$java_awt_AWTEvent$java_awt_AWTEvent") != C$;
5238+
* return this.coalesceEvents$java_awt_AWTEvent$java_awt_AWTEvent.exClazz != C$;
52395239
*/
52405240
{
52415241
return false;

sources/net.sf.j2s.java.core/src/java/lang/Class.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ public Class<? super T> getSuperclass() {
924924
* @since JDK1.1
925925
*/
926926
public Class<?> getComponentType() {
927-
// Array classes have this method added via Clazz.arrayClass$()
927+
// Array classes have this method added via Clazz.array()
928928
return null;
929929
}
930930

@@ -2223,7 +2223,7 @@ public InputStream getResourceAsStream(String name) {
22232223
var fname = baseFolder;
22242224
if (fname.charAt(fname.length - 1) != '/')
22252225
fname += "/";
2226-
var map = Clazz.allPackage;
2226+
var map = Clazz._allPackage;
22272227
for (var i = 0; i < pkgs.length - 1; i++) {
22282228
if (!(map = map[pkgs[i]]))
22292229
break;

sources/net.sf.j2s.java.core/src/java/util/regex/Matcher.js

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
//BH fix for String not having .length() or .subSequence()
55
//BH fix for not reinitializing correctly
66
//BH note that start(groupIndex) is not implemented for groupIndex > 0
7-
(function(){Clazz.newPackage$("java.util.regex");
7+
(function(){Clazz.newPackage("java.util.regex");
88

9-
var C$=Clazz.newClass$(java.util.regex,"Matcher",function(){
10-
Clazz.newInstance$(this,arguments);
9+
var C$=Clazz.newClass(java.util.regex,"Matcher",function(){
10+
Clazz.newInstance(this,arguments);
1111
},null,"java.util.regex.MatchResult");
1212

1313

@@ -18,28 +18,28 @@ Clazz.load(C$, 1);
1818

1919
(function(){
2020

21-
var C$=Clazz.newClass$(java.util.regex,"Matcher$1",function(){
22-
Clazz.newInstance$(this, arguments[0], true);
21+
var C$=Clazz.newClass(java.util.regex,"Matcher$1",function(){
22+
Clazz.newInstance(this, arguments[0], true);
2323
});
2424

2525
C$.$clinit$ = function() {delete C$.$clinit$;Clazz.load(C$, 1);}
2626

27-
Clazz.newMethod$(C$, "$init$", function() {
27+
Clazz.newMeth(C$, "$init$", function() {
2828
this.grN=0;
2929
}, 1);
30-
Clazz.newMethod$(C$,"toString", function(){
30+
Clazz.newMeth(C$,"toString", function(){
3131
return this.b$["java.util.regex.Matcher"].group(this.grN);
3232
});
3333
})();
3434

35-
Clazz.newMethod$(C$, 'c$$java_util_regex_Pattern$CharSequence', function(pat,cs){
35+
Clazz.newMeth(C$, 'c$$java_util_regex_Pattern$CharSequence', function(pat,cs){
3636
this.pat=pat;
3737
this.charSeq=cs;
3838
this.leftBound=0;
3939
this.rightBound=this.charSeq.length$();
4040
}, 1);
4141

42-
Clazz.newMethod$(C$,"reset$CharSequence",function(newSequence){
42+
Clazz.newMeth(C$,"reset$CharSequence",function(newSequence){
4343
if(newSequence==null){
4444
throw new NullPointerException("Empty new sequence!");
4545
}
@@ -48,7 +48,7 @@ Clazz.newMethod$(C$,"reset$CharSequence",function(newSequence){
4848
return this.reset();
4949
});
5050

51-
Clazz.newMethod$(C$,"reset",function(){
51+
Clazz.newMeth(C$,"reset",function(){
5252
this.leftBound=0;
5353
this.rightBound=this.charSeq.length$();
5454
this.appendPos=0;
@@ -62,7 +62,7 @@ Clazz.newMethod$(C$,"reset",function(){
6262
return this;
6363
});
6464

65-
Clazz.newMethod$(C$,"find",function(){
65+
Clazz.newMeth(C$,"find",function(){
6666
// 'find next'
6767
if (this.strString == null)
6868
this.strString = this.charSeq.toString();
@@ -75,7 +75,7 @@ Clazz.newMethod$(C$,"find",function(){
7575
return (this.results != null);
7676
});
7777

78-
Clazz.newMethod$(C$,"find$I",function(startIndex){
78+
Clazz.newMeth(C$,"find$I",function(startIndex){
7979
var stringLength=this.charSeq.length$();
8080
if(startIndex<0||startIndex>stringLength)
8181
throw new IndexOutOfBoundsException$S("Out of bound "+startIndex);
@@ -84,38 +84,38 @@ Clazz.newMethod$(C$,"find$I",function(startIndex){
8484
return this.find();
8585
});
8686

87-
Clazz.newMethod$(C$,"start",function(){
87+
Clazz.newMeth(C$,"start",function(){
8888
return this.start$I(0);
8989
});
9090

91-
Clazz.newMethod$(C$,"start$I", function(groupIndex){
91+
Clazz.newMeth(C$,"start$I", function(groupIndex){
9292
return this.startImpl$I(groupIndex);
9393
});
9494

95-
Clazz.newMethod$(C$,"startImpl$I", function(groupIndex){
95+
Clazz.newMeth(C$,"startImpl$I", function(groupIndex){
9696
// BH SAEM
9797
// NOTE: TODO groupIndex is not implemented!
9898
return this.pat.regexp.lastIndex - this.results[0].length;
9999
});
100100

101-
Clazz.newMethod$(C$,"end",function(){
101+
Clazz.newMeth(C$,"end",function(){
102102
return this.end$I(0);
103103
});
104104

105-
Clazz.newMethod$(C$,"end$I",function(groupIndex){
105+
Clazz.newMeth(C$,"end$I",function(groupIndex){
106106
return this.pat.regexp.lastIndex;
107107
});
108108

109109

110-
Clazz.newMethod$(C$,"appendReplacement$StringBuffer$S",function(sb,replacement){
110+
Clazz.newMeth(C$,"appendReplacement$StringBuffer$S",function(sb,replacement){
111111
this.processedRepl=this.processReplacement$S(replacement);
112112
sb.append$S(this.charSeq.subSequence$I$I(this.appendPos,this.start()));
113113
sb.append$S(this.processedRepl);
114114
this.appendPos=this.end();
115115
return this;
116116
});
117117

118-
Clazz.newMethod$(C$,"processReplacement$S",function(replacement){
118+
Clazz.newMeth(C$,"processReplacement$S",function(replacement){
119119
if(this.replacement!=null&&this.replacement.equals$O(replacement)){
120120
if(this.replacementParts==null){
121121
return this.processedRepl;
@@ -145,15 +145,15 @@ Clazz.newMethod$(C$,"processReplacement$S",function(replacement){
145145
}else{
146146
if((repl[index]).charCodeAt(0)==('$').charCodeAt(0)){
147147
if(this.replacementParts==null){
148-
this.replacementParts=Clazz.newArray$(String, 0);
148+
this.replacementParts=Clazz.array(String, 0);
149149
}
150150
try{
151151
var gr=Integer.parseInt$S(String.instantialize(repl,++index,1));
152152
if(replacementPos!=res.length$()){
153153
this.replacementParts[this.replacementParts.length]=res.subSequence$I$I(replacementPos,res.length$());
154154
replacementPos=res.length$();
155155
}
156-
this.replacementParts[this.replacementParts.length]= Clazz.new(Clazz.incl$("java.util.regex.Matcher$1").c$,[this]);
156+
this.replacementParts[this.replacementParts.length]= Clazz.new(Clazz.load("java.util.regex.Matcher$1").c$,[this]);
157157
var group=this.group(gr);
158158
replacementPos+=group.length;
159159
res.append$S(group);
@@ -186,7 +186,7 @@ Clazz.newMethod$(C$,"processReplacement$S",function(replacement){
186186
});
187187

188188

189-
Clazz.newMethod$(C$,"region$I$I",function(leftBound,rightBound){
189+
Clazz.newMeth(C$,"region$I$I",function(leftBound,rightBound){
190190
if(leftBound>rightBound||leftBound<0||rightBound<0||leftBound>this.charSeq.length$()||rightBound>this.charSeq.length$()){
191191
throw Clazz.new(IndexOutOfBoundsException.c$, [leftBound+" is out of bound of "+rightBound]);
192192
}
@@ -198,11 +198,11 @@ Clazz.newMethod$(C$,"region$I$I",function(leftBound,rightBound){
198198
return this;
199199
});
200200

201-
Clazz.newMethod$(C$,"appendTail$StringBuffer",function(sb){
201+
Clazz.newMeth(C$,"appendTail$StringBuffer",function(sb){
202202
return sb.append$S(this.charSeq.subSequence(this.appendPos,this.charSeq.length$()));
203203
},"StringBuffer");
204204

205-
Clazz.newMethod$(C$,"replaceFirst$S",function(replacement){
205+
Clazz.newMeth(C$,"replaceFirst$S",function(replacement){
206206
this.reset();
207207
if(this.find()){
208208
var sb=new StringBuffer();
@@ -212,7 +212,7 @@ Clazz.newMethod$(C$,"replaceFirst$S",function(replacement){
212212
return this.charSeq.toString();
213213
});
214214

215-
Clazz.newMethod$(C$,"replaceAll$S", function(replacement){
215+
Clazz.newMeth(C$,"replaceAll$S", function(replacement){
216216
var sb=new StringBuffer();
217217
this.reset();
218218
while(this.find()){
@@ -221,22 +221,22 @@ Clazz.newMethod$(C$,"replaceAll$S", function(replacement){
221221
return this.appendTail$StringBuffer(sb).toString();
222222
});
223223

224-
Clazz.newMethod$(C$,"pattern",function(){
224+
Clazz.newMeth(C$,"pattern",function(){
225225
return this.pat;
226226
});
227227

228-
Clazz.newMethod$(C$,"group$I",function(groupIndex){
228+
Clazz.newMeth(C$,"group$I",function(groupIndex){
229229
if(this.results==null||groupIndex<0||groupIndex>this.results.length){
230230
return null;
231231
}
232232
return this.results[groupIndex];
233233
});
234234

235-
Clazz.newMethod$(C$,"group",function(){
235+
Clazz.newMeth(C$,"group",function(){
236236
return this.group(0);
237237
});
238238

239-
Clazz.newMethod$(C$,"matches",function(){
239+
Clazz.newMeth(C$,"matches",function(){
240240
// UB: the find must match the complete input and not modify the RE object
241241
var old_lastIndex = this.pat.regexp.lastIndex;
242242
try {
@@ -249,7 +249,7 @@ Clazz.newMethod$(C$,"matches",function(){
249249
}
250250
});
251251

252-
Clazz.newMethod$(C$,"quoteReplacement$S",function(string){
252+
Clazz.newMeth(C$,"quoteReplacement$S",function(string){
253253
if(string.indexOf('\\') < 0 && string.indexOf ('$')<0) ; // '))
254254
return string;
255255
var res= Clazz.new(StringBuffer, [string.length*2]);
@@ -272,52 +272,52 @@ Clazz.newMethod$(C$,"quoteReplacement$S",function(string){
272272
return res.toString();
273273
}, 1);
274274

275-
Clazz.newMethod$(C$,"lookingAt",function(){
275+
Clazz.newMeth(C$,"lookingAt",function(){
276276
return false;
277277
});
278278

279-
Clazz.newMethod$(C$,"groupCount",function(){
279+
Clazz.newMeth(C$,"groupCount",function(){
280280
return this.results==null?0:this.results.length;
281281
});
282282

283283

284-
Clazz.newMethod$(C$,"toMatchResult",function(){
284+
Clazz.newMeth(C$,"toMatchResult",function(){
285285
return this;
286286
});
287287

288-
Clazz.newMethod$(C$,"useAnchoringBounds$Z",function(value){
288+
Clazz.newMeth(C$,"useAnchoringBounds$Z",function(value){
289289
return this;
290290
});
291291

292-
Clazz.newMethod$(C$,"hasAnchoringBounds",function(){
292+
Clazz.newMeth(C$,"hasAnchoringBounds",function(){
293293
return false;
294294
});
295295

296-
Clazz.newMethod$(C$,"useTransparentBounds$Z",function(value){
296+
Clazz.newMeth(C$,"useTransparentBounds$Z",function(value){
297297
return this;
298298
});
299299

300-
Clazz.newMethod$(C$,"hasTransparentBounds",function(){
300+
Clazz.newMeth(C$,"hasTransparentBounds",function(){
301301
return false;
302302
});
303303

304-
Clazz.newMethod$(C$,"regionStart",function(){
304+
Clazz.newMeth(C$,"regionStart",function(){
305305
return this.leftBound;
306306
});
307307

308-
Clazz.newMethod$(C$,"regionEnd",function(){
308+
Clazz.newMeth(C$,"regionEnd",function(){
309309
return this.rightBound;
310310
});
311311

312-
Clazz.newMethod$(C$,"requireEnd",function(){
312+
Clazz.newMeth(C$,"requireEnd",function(){
313313
return false;
314314
});
315315

316-
Clazz.newMethod$(C$,"hitEnd",function(){
316+
Clazz.newMeth(C$,"hitEnd",function(){
317317
return false;
318318
});
319319

320-
Clazz.newMethod$(C$,"usePattern$java.util_regex_Pattern",function(pat){
320+
Clazz.newMeth(C$,"usePattern$java.util_regex_Pattern",function(pat){
321321
if(pat==null){
322322
throw new IllegalArgumentException("Empty pattern!");
323323
}

sources/net.sf.j2s.java.core/src/java/util/regex/Pattern.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
// BH 9/24/2017 4:21:05 PM new syntax for decorateAsClass
22
(function() {
3-
Clazz.newPackage$("java.util.regex");
3+
Clazz.newPackage("java.util.regex");
44

5-
var C$=Clazz.newClass$(java.util.regex,"Pattern",function(){
6-
Clazz.newInstance$(this,arguments);
5+
var C$=Clazz.newClass(java.util.regex,"Pattern",function(){
6+
Clazz.newInstance(this,arguments);
77
});
88

99
C$.$clinit$ = function() {delete C$.$clinit$;Clazz.load(C$, 1);}
1010

11-
Clazz.newMethod$(C$,"$init$", function(){
11+
Clazz.newMeth(C$,"$init$", function(){
1212
this.$flags=0;
1313
this.regexp=null;
1414
}, 1);
1515

16-
Clazz.newMethod$(C$,"$c", function(){
16+
Clazz.newMeth(C$,"$c", function(){
1717
C$.$init$.apply(this);
1818
}, 1);
1919

20-
Clazz.newMethod$(C$,"matcher$CharSequence", function(cs){
20+
Clazz.newMeth(C$,"matcher$CharSequence", function(cs){
2121
return Clazz.new(Clazz.load("java.util.regex.Matcher").c$$java_util_regex_Pattern$CharSequence, [this, cs]);
2222
});
2323

24-
Clazz.newMethod$(C$,"split$CharSequence$I", function(input,limit){
25-
var res=Clazz.newArray$(String);
24+
Clazz.newMeth(C$,"split$CharSequence$I", function(input,limit){
25+
var res=Clazz.array(String);
2626
var mat=this.matcher$CharSequence(input);
2727
var index=0;
2828
var curPos=0;
@@ -45,27 +45,27 @@ Clazz.newMethod$(C$,"split$CharSequence$I", function(input,limit){
4545
return res;
4646
});
4747

48-
Clazz.newMethod$(C$,"split$CharSequence", function(input){
48+
Clazz.newMeth(C$,"split$CharSequence", function(input){
4949
return this.split(input,0);
5050
});
5151

52-
Clazz.newMethod$(C$,"pattern", function(){
52+
Clazz.newMeth(C$,"pattern", function(){
5353
return this.regexp.source;
5454
});
5555

56-
Clazz.newMethod$(C$,"toString", function(){
56+
Clazz.newMeth(C$,"toString", function(){
5757
return this.pattern();
5858
});
5959

60-
Clazz.newMethod$(C$,"flags", function(){
60+
Clazz.newMeth(C$,"flags", function(){
6161
return this.$flags;
6262
});
6363

64-
Clazz.newMethod$(C$,"compile$S",function(pattern){
64+
Clazz.newMeth(C$,"compile$S",function(pattern){
6565
return java.util.regex.Pattern.compile$S$I(pattern,0);
6666
}, 1);
6767

68-
Clazz.newMethod$(C$,"compile$S$I",function(regex,flags){
68+
Clazz.newMeth(C$,"compile$S$I",function(regex,flags){
6969
if((flags!=0)&&((flags|239)!=239)){
7070
throw new IllegalArgumentException("Illegal flags");
7171
}
@@ -81,11 +81,11 @@ Clazz.newMethod$(C$,"compile$S$I",function(regex,flags){
8181
return pattern;
8282
}, 1);
8383

84-
Clazz.newMethod$(C$,"matches$S$CharSequence",function(regex,input){
84+
Clazz.newMeth(C$,"matches$S$CharSequence",function(regex,input){
8585
return java.util.regex.Pattern.compile(regex).matcher(input).matches();
8686
}, 1);
8787

88-
Clazz.newMethod$(C$,"quote$S",function(s){
88+
Clazz.newMeth(C$,"quote$S",function(s){
8989
var sb=new StringBuffer().append("\\Q");
9090
var apos=0;
9191
var k;

0 commit comments

Comments
 (0)