Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commited155c9

Browse files
committed
Fixed bug that initializing arrays in static blocks is incorrect
1 parentf6c0eef commited155c9

File tree

2 files changed

+95
-10
lines changed

2 files changed

+95
-10
lines changed

‎sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/ASTKeywordVisitor.java‎

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public boolean visit(ArrayCreation node) {
201201
}else {
202202
Listdim =node.dimensions();
203203
ITypeBindingelementType =node.getType().getElementType().resolveBinding();
204-
if(elementType !=null){
204+
if(elementType !=null){
205205
if (elementType.isPrimitive()) {
206206
StringtypeCode =elementType.getName();
207207
if ("int".equals(typeCode)
@@ -258,10 +258,58 @@ public boolean visit(ArrayInitializer node) {
258258
/*
259259
* TODO: should be tested
260260
*/
261-
buffer.append("[");
262-
Listlist =node.expressions();
263-
visitList(list,", ");
264-
buffer.append("]");
261+
Listexpressions =node.expressions();
262+
ITypeBindingarrType =node.resolveTypeBinding();
263+
ITypeBindingelementType =null;
264+
if (arrType !=null) {
265+
elementType =arrType.getComponentType();
266+
}
267+
if (elementType ==null) {
268+
buffer.append("[");
269+
visitList(expressions,", ");
270+
buffer.append("]");
271+
returnfalse;
272+
}
273+
if (elementType.isPrimitive()) {
274+
StringtypeCode =elementType.getName();
275+
if ("int".equals(typeCode)
276+
||"float".equals(typeCode)
277+
||"double".equals(typeCode)
278+
||"byte".equals(typeCode)
279+
||"long".equals(typeCode)
280+
||"short".equals(typeCode)) {
281+
//buffer.append(" Clazz.newArray (");
282+
buffer.append(" Clazz.new");
283+
buffer.append(typeCode.substring(0,1).toUpperCase());
284+
buffer.append(typeCode.substring(1));
285+
buffer.append("Array (-1, ");
286+
buffer.append("[");
287+
visitList(expressions,", ");
288+
buffer.append("])");
289+
}elseif ("char".equals(typeCode)) {
290+
//buffer.append(" Clazz.newArray (");
291+
buffer.append(" Clazz.newCharArray (-1, ");
292+
buffer.append("[");
293+
visitList(expressions,", ");
294+
buffer.append("])");
295+
}elseif ("boolean".equals(typeCode)) {
296+
//buffer.append(" Clazz.newArray (");
297+
buffer.append(" Clazz.newBooleanArray (-1, ");
298+
buffer.append("[");
299+
visitList(expressions,", ");
300+
buffer.append("])");
301+
}else {
302+
buffer.append(" Clazz.newArray (-1, ");
303+
buffer.append("[");
304+
visitList(expressions,", ");
305+
buffer.append("])");
306+
}
307+
}else {
308+
buffer.append(" Clazz.newArray (-1, ");
309+
buffer.append("[");
310+
visitList(expressions,", ");
311+
buffer.append("])");
312+
}
265313
returnfalse;
266314
}
267315

@@ -1340,11 +1388,30 @@ public boolean visit(ReturnStatement node) {
13401388
Expressionexpression =node.getExpression();
13411389
if (expression !=null) {
13421390
buffer.append(' ');
1343-
ITypeBindingtBinding =expression.resolveTypeBinding();
1344-
if (tBinding !=null && !("char".equals(tBinding.getName()))) {
1345-
buffer.append("String.fromCharCode (");
1346-
expression.accept(this);
1347-
buffer.append(")");
1391+
booleanneedCharWrapping =false;
1392+
ASTNodeparent =node.getParent();
1393+
while (parent !=null && !(parentinstanceofMethodDeclaration)) {
1394+
parent =parent.getParent();
1395+
}
1396+
if (parent !=null) {
1397+
MethodDeclarationm = (MethodDeclaration)parent;
1398+
IMethodBindingbinding =m.resolveBinding();
1399+
if (binding !=null) {
1400+
ITypeBindingreturnType =binding.getReturnType();
1401+
if (returnType !=null &&"char".equals(returnType.getName())) {
1402+
needCharWrapping =true;
1403+
}
1404+
}
1405+
}
1406+
if (needCharWrapping) {
1407+
ITypeBindingtBinding =expression.resolveTypeBinding();
1408+
if (tBinding !=null && !("char".equals(tBinding.getName()))) {
1409+
buffer.append("String.fromCharCode (");
1410+
expression.accept(this);
1411+
buffer.append(")");
1412+
}else {
1413+
expression.accept(this);
1414+
}
13481415
}else {
13491416
expression.accept(this);
13501417
}

‎sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/DependencyASTVisitor.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
importjava.util.Iterator;
1919
importjava.util.List;
2020
importjava.util.Set;
21+
2122
importorg.eclipse.jdt.core.dom.ASTNode;
2223
importorg.eclipse.jdt.core.dom.AbstractTypeDeclaration;
2324
importorg.eclipse.jdt.core.dom.Annotation;
@@ -40,6 +41,7 @@
4041
importorg.eclipse.jdt.core.dom.IfStatement;
4142
importorg.eclipse.jdt.core.dom.ImportDeclaration;
4243
importorg.eclipse.jdt.core.dom.Initializer;
44+
importorg.eclipse.jdt.core.dom.InstanceofExpression;
4345
importorg.eclipse.jdt.core.dom.Javadoc;
4446
importorg.eclipse.jdt.core.dom.MethodDeclaration;
4547
importorg.eclipse.jdt.core.dom.MethodInvocation;
@@ -902,6 +904,22 @@ public boolean visit(ClassInstanceCreation node) {
902904
returnsuper.visit(node);
903905
}
904906

907+
publicbooleanvisit(InstanceofExpressionnode) {
908+
Typetype =node.getRightOperand();
909+
ITypeBindingresolveTypeBinding =type.resolveBinding();
910+
QNTypeBindingqn =newQNTypeBinding();
911+
StringqualifiedName =resolveTypeBinding.getQualifiedName();
912+
qn.binding =resolveTypeBinding;
913+
qualifiedName =discardGenericType(qualifiedName);
914+
qn.qualifiedName =qualifiedName;
915+
if (isQualifiedNameOK(qualifiedName,node)
916+
&& !musts.contains(qn)
917+
&& !requires.contains(qn)) {
918+
optionals.add(qn);
919+
}
920+
returnsuper.visit(node);
921+
}
922+
905923
///* (non-Javadoc)
906924
// * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.ArrayCreation)
907925
// */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp