Skip to content

Commit 6506b5a

Browse files
author
jossonsmith
committed
Merging /trunk to [214]
1 parent 051de3a commit 6506b5a

File tree

3 files changed

+73
-9
lines changed

3 files changed

+73
-9
lines changed

src/net/sf/j2s/core/astvisitors/ASTScriptVisitor.java

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,21 +308,55 @@ public boolean visit(CastExpression node) {
308308
* TODO: some casting should have its meaning!
309309
*/
310310
if (type.isPrimitiveType()) {
311+
ITypeBinding resolveTypeBinding = node.getExpression().resolveTypeBinding();
312+
String name = resolveTypeBinding.getName();
311313
PrimitiveType pType = (PrimitiveType) type;
312314
if (pType.getPrimitiveTypeCode() == PrimitiveType.INT
313315
|| pType.getPrimitiveTypeCode() == PrimitiveType.BYTE
314316
|| pType.getPrimitiveTypeCode() == PrimitiveType.SHORT
315317
|| pType.getPrimitiveTypeCode() == PrimitiveType.LONG) {
316-
buffer.append("parseInt (");
317-
node.getExpression().accept(this);
318-
buffer.append (")");
319-
return false;
318+
if ("char".equals(name)) {
319+
buffer.append("(");
320+
node.getExpression().accept(this);
321+
buffer.append (").charCodeAt (0)");
322+
return false;
323+
} else if ("float".equals(name) || "double".equals(name)) {
324+
// TODO:
325+
buffer.append("Math.round (");
326+
node.getExpression().accept(this);
327+
buffer.append (")");
328+
// } else if ("int".equals(name) || "byte".equals(name)
329+
// || "double".equals(name) || "float".equals(name)
330+
// || "short".equals(name) || "long".equals(name)) {
331+
332+
}
333+
// buffer.append("parseInt (");
334+
// node.getExpression().accept(this);
335+
// buffer.append (")");
336+
// return false;
320337
}
321338
if (pType.getPrimitiveTypeCode() == PrimitiveType.CHAR) {
322-
buffer.append("String.fromCharCode (");
323-
node.getExpression().accept(this);
324-
buffer.append (")");
325-
return false;
339+
if ("char".equals(name)) {
340+
// buffer.append("(");
341+
// node.getExpression().accept(this);
342+
// buffer.append (").charCodeAt (0)");
343+
// return false;
344+
} else if ("float".equals(name) || "double".equals(name)) {
345+
// TODO:
346+
buffer.append("String.fromCharCode (");
347+
buffer.append("Math.round (");
348+
node.getExpression().accept(this);
349+
buffer.append (")");
350+
buffer.append (")");
351+
return false;
352+
} else if ("int".equals(name) || "byte".equals(name)
353+
|| "double".equals(name) || "float".equals(name)
354+
|| "short".equals(name) || "long".equals(name)) {
355+
buffer.append("String.fromCharCode (");
356+
node.getExpression().accept(this);
357+
buffer.append (")");
358+
return false;
359+
}
326360
}
327361
}
328362
node.getExpression().accept(this);

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.eclipse.jdt.core.dom.TextElement;
4444
import org.eclipse.jdt.core.dom.Type;
4545
import org.eclipse.jdt.core.dom.TypeDeclaration;
46+
import org.eclipse.jdt.core.dom.TypeLiteral;
4647
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
4748

4849
/**
@@ -414,6 +415,30 @@ protected void readClasses(TagElement tagEl, Set set) {
414415
}
415416
}
416417
}
418+
/* (non-Javadoc)
419+
* @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.TypeLiteral)
420+
*/
421+
public boolean visit(TypeLiteral node) {
422+
ITypeBinding resolveTypeBinding = node.getType().resolveBinding();
423+
ITypeBinding declaringClass = resolveTypeBinding.getDeclaringClass();
424+
QNTypeBinding qn = new QNTypeBinding();
425+
String qualifiedName = null;
426+
if (declaringClass != null) {
427+
qualifiedName = declaringClass.getQualifiedName();
428+
qn.binding = declaringClass;
429+
} else {
430+
qualifiedName = resolveTypeBinding.getQualifiedName();
431+
qn.binding = resolveTypeBinding;
432+
}
433+
qualifiedName = JavaLangUtil.ripGeneric(qualifiedName);
434+
qn.qualifiedName = qualifiedName;
435+
if (isQualifiedNameOK(qualifiedName, node)
436+
&& !musts.contains(qn)
437+
&& !requires.contains(qn)) {
438+
optionals.add(qn);
439+
}
440+
return false;
441+
}
417442
/*
418443
* (non-Javadoc)
419444
*

src/net/sf/j2s/core/astvisitors/JavaLangUtil.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ public static String ripJavaLang(String name) {
2424
|| ((ch = name.charAt(index + 10)) >= 'A' && ch <= 'Z'))) {
2525
// ((idx2 = name.indexOf('.', index + 10)) == -1
2626
// || !name.substring(index + 10, idx2).startsWith ("ref"))) {
27-
name = name.substring(10);
27+
if (name.indexOf ("Error") != -1 || name.indexOf("Exception") != -1
28+
|| name.indexOf("ThreadDeath") != -1) {
29+
30+
} else {
31+
name = name.substring(10);
32+
}
2833
}
2934
String swt = "org.eclipse.swt.SWT";
3035
index = name.indexOf(swt);

0 commit comments

Comments
 (0)