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

Commitfeadcb3

Browse files
author
zhourenjian
committed
Synchronize from Eclipse 3.3 branch
1 parent5e0e402 commitfeadcb3

File tree

5 files changed

+224
-49
lines changed

5 files changed

+224
-49
lines changed

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

Lines changed: 129 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
importorg.eclipse.jdt.core.dom.IMethodBinding;
3232
importorg.eclipse.jdt.core.dom.ITypeBinding;
3333
importorg.eclipse.jdt.core.dom.IVariableBinding;
34+
importorg.eclipse.jdt.core.dom.IfStatement;
3435
importorg.eclipse.jdt.core.dom.InfixExpression;
3536
importorg.eclipse.jdt.core.dom.Initializer;
3637
importorg.eclipse.jdt.core.dom.Javadoc;
@@ -45,6 +46,7 @@
4546
importorg.eclipse.jdt.core.dom.SimpleName;
4647
importorg.eclipse.jdt.core.dom.SimpleType;
4748
importorg.eclipse.jdt.core.dom.SingleVariableDeclaration;
49+
importorg.eclipse.jdt.core.dom.Statement;
4850
importorg.eclipse.jdt.core.dom.SuperConstructorInvocation;
4951
importorg.eclipse.jdt.core.dom.SuperFieldAccess;
5052
importorg.eclipse.jdt.core.dom.SuperMethodInvocation;
@@ -1113,6 +1115,10 @@ public void endVisit(MethodDeclaration node) {
11131115
}
11141116
super.endVisit(node);
11151117
}
1118+
1119+
protectedString[]getFilterMethods() {
1120+
returnnewString[0];
1121+
}
11161122

11171123
publicbooleanvisit(MethodDeclarationnode) {
11181124
if (getJ2SDocTag(node,"@j2sIgnore") !=null) {
@@ -1144,8 +1150,9 @@ public boolean visit(MethodDeclaration node) {
11441150
Blockbody =node.getBody();
11451151
booleanneedToCheckArgs =false;
11461152
ListargsList =null;
1147-
if (body !=null &&body.statements().size() ==1) {
1148-
Objectstatement =body.statements().get(0);
1153+
if (body !=null &&containsOnlySuperCall(body)) {
1154+
Liststs =body.statements();
1155+
Objectstatement =sts.get(sts.size() -1);
11491156
if (statementinstanceofReturnStatement) {
11501157
ReturnStatementret = (ReturnStatement)statement;
11511158
Expressionexp =ret.getExpression();
@@ -1390,6 +1397,81 @@ public boolean visit(MethodDeclaration node) {
13901397
returnfalse;
13911398
}
13921399

1400+
privatebooleancontainsOnlySuperCall(Blockbody) {
1401+
booleanisOnlyOneCall =false;
1402+
Listss =body.statements();
1403+
intsize =ss.size();
1404+
if (size ==1) {
1405+
isOnlyOneCall =true;
1406+
}else {
1407+
/*
1408+
* If all method invocations before super call is filtered, then super call
1409+
* is still considered as the only one.
1410+
*
1411+
* For example, the filtered methods may be:
1412+
* checkWidget();
1413+
* checkDevice();
1414+
*/
1415+
String[]filterMethods =getFilterMethods();
1416+
if (filterMethods.length >0 &&size >1) {
1417+
Objectobj =ss.get(size -1);
1418+
if (objinstanceofExpressionStatement) {
1419+
ExpressionStatementsmt = (ExpressionStatement)obj;
1420+
Expressione =smt.getExpression();
1421+
if (einstanceofSuperMethodInvocation) {// the last is super call
1422+
isOnlyOneCall =true;
1423+
for (inti =0;i <size -1;i++) {// check previous calls
1424+
Objectstatement =ss.get(i);
1425+
MethodInvocationmethod =null;
1426+
if (statementinstanceofExpressionStatement) {
1427+
ExpressionStatementsttmt = (ExpressionStatement)statement;
1428+
Expressionexp =sttmt.getExpression();
1429+
if (expinstanceofMethodInvocation) {
1430+
method = (MethodInvocation)exp;
1431+
}
1432+
}elseif (statementinstanceofIfStatement) {// if (...) checkWidget();
1433+
IfStatementifSss = (IfStatement)statement;
1434+
if (ifSss.getElseStatement() ==null) {
1435+
StatementthenStatement =ifSss.getThenStatement();
1436+
if (thenStatementinstanceofBlock) {
1437+
Blockblock = (Block)thenStatement;
1438+
Liststatements =block.statements();
1439+
if (statements.size() ==1) {
1440+
thenStatement = (Statement)statements.get(0);
1441+
}
1442+
}
1443+
if (thenStatementinstanceofExpressionStatement) {
1444+
ExpressionStatementexpStmt = (ExpressionStatement)thenStatement;
1445+
Expressionexp =expStmt.getExpression();
1446+
if (expinstanceofMethodInvocation) {
1447+
method = (MethodInvocation)exp;
1448+
}
1449+
}
1450+
}
1451+
}
1452+
if (method !=null) {
1453+
booleanisFiltered =false;
1454+
IMethodBindingmethodBinding =method.resolveMethodBinding();
1455+
for (intj =0;j <filterMethods.length;j +=2) {
1456+
if (Bindings.isMethodInvoking(methodBinding,filterMethods[j],filterMethods[j +1])) {
1457+
isFiltered =true;
1458+
break;
1459+
}
1460+
}
1461+
if (isFiltered) {
1462+
continue;
1463+
}
1464+
}
1465+
isOnlyOneCall =false;
1466+
break;
1467+
}
1468+
}
1469+
}
1470+
}
1471+
}
1472+
returnisOnlyOneCall;
1473+
}
1474+
13931475
publicbooleanvisit(MethodInvocationnode) {
13941476
Expressionexpression =node.getExpression();
13951477
if (expression !=null) {
@@ -1435,9 +1517,17 @@ public boolean visit(MethodInvocation node) {
14351517
if (paramTypes.length -1 >0) {
14361518
buffer.append(", ");
14371519
}
1438-
buffer.append("[");
1520+
booleanneedBrackets =true;
1521+
//if (args.size() == 1) {
1522+
Expressionarg = (Expression)args.get(args.size() -1);
1523+
ITypeBindingresolveTypeBinding =arg.resolveTypeBinding();
1524+
if (resolveTypeBinding.isArray()) {
1525+
needBrackets =false;
1526+
}
1527+
//}
1528+
if (needBrackets)buffer.append("[");
14391529
visitList(args,", ",paramTypes.length -1,size);
1440-
buffer.append("]");
1530+
if (needBrackets)buffer.append("]");
14411531
}else {
14421532
for (Iteratoriter =args.iterator();iter.hasNext();) {
14431533
ASTNodeelement = (ASTNode)iter.next();
@@ -1921,9 +2011,25 @@ public boolean visit(SuperMethodInvocation node) {
19212011
publicbooleanvisit(ThisExpressionnode) {
19222012
Namequalifier =node.getQualifier();
19232013
if (qualifier !=null) {
1924-
buffer.append("this.callbacks[\"");
1925-
qualifier.accept(this);
1926-
buffer.append("\"]");
2014+
ASTNodexparent =node.getParent();
2015+
while (xparent !=null
2016+
&& !(xparentinstanceofAbstractTypeDeclaration)
2017+
&& !(xparentinstanceofAnonymousClassDeclaration)) {
2018+
xparent =xparent.getParent();
2019+
}
2020+
if (xparent ==null
2021+
||xparent.getParent() ==null// CompilationUnit
2022+
||xparent.getParent().getParent() ==null) {
2023+
buffer.append("this");
2024+
}else {
2025+
/*
2026+
* only need callbacks wrapper in inner classes
2027+
* or anonymous classes.
2028+
*/
2029+
buffer.append("this.callbacks[\"");
2030+
qualifier.accept(this);
2031+
buffer.append("\"]");
2032+
}
19272033
}else {
19282034
buffer.append("this");
19292035
}
@@ -2548,7 +2654,22 @@ public static void main(String[] args) {
25482654
}
25492655

25502656
publicbooleanvisit(TypeLiteralnode) {
2551-
node.getType().accept(this);
2657+
Typetype =node.getType();
2658+
if (type.isPrimitiveType()) {
2659+
ITypeBindingresolveBinding =type.resolveBinding();
2660+
Stringname =resolveBinding.getName();
2661+
if ("boolean".equals(name)) {
2662+
buffer.append("Boolean");
2663+
returnfalse;
2664+
}else {// TODO: More types? Integer, Long, Double, ... ?
2665+
buffer.append("Number");
2666+
returnfalse;
2667+
}
2668+
}elseif (type.isArrayType()) {
2669+
buffer.append("Array");
2670+
returnfalse;
2671+
}
2672+
type.accept(this);
25522673
returnfalse;
25532674
}
25542675

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

Lines changed: 67 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ protected void checkSuperType(Set set) {
108108
for (Iteratoriterator =classBindingSet.iterator();iterator
109109
.hasNext();) {
110110
ITypeBindingbinding = (ITypeBinding)iterator.next();
111-
if (Bindings.isSuperType(binding,qn.binding)) {
111+
if (qn.binding !=null &&Bindings.isSuperType(binding,qn.binding)) {
112112
removed.add(qn);
113113
isRemoved =true;
114114
break;
@@ -126,11 +126,38 @@ protected void checkSuperType(Set set) {
126126
set.add(qn.qualifiedName);
127127
}
128128
}
129+
130+
131+
protectedvoidremedyReflectionDependency(Setset) {
132+
booleanneedRemedy =false;;
133+
for (Iteratoriterator =set.iterator();iterator.hasNext();) {
134+
Objectnext =iterator.next();
135+
Stringname =null;
136+
if (nextinstanceofQNTypeBinding) {
137+
QNTypeBindingqn = (QNTypeBinding)next;
138+
name =qn.qualifiedName;
139+
}else {
140+
name = (String)next;
141+
}
142+
if ("net.sf.j2s.ajax.AClass".equals(name)
143+
||"net.sf.j2s.ajax.ASWTClass".equals(name)) {
144+
needRemedy =true;
145+
break;
146+
}
147+
}
148+
if (needRemedy) {
149+
set.add("java.lang.reflect.Constructor");
150+
}
151+
}
152+
129153
publicStringgetDependencyScript(StringBuffermainJS) {
130154
checkSuperType(musts);
131155
checkSuperType(requires);
132156
checkSuperType(optionals);
133-
157+
remedyReflectionDependency(musts);
158+
remedyReflectionDependency(requires);
159+
remedyReflectionDependency(optionals);
160+
134161
musts.remove("");
135162
requires.remove("");
136163
optionals.remove("");
@@ -449,6 +476,15 @@ public boolean isClassKnown(String qualifiedName) {
449476
publicbooleanisQualifiedNameOK(StringqualifiedName,ASTNodenode) {
450477
if (qualifiedName !=null
451478
&& !isClassKnown(qualifiedName)
479+
&&qualifiedName.indexOf('[') == -1
480+
&& !"int".equals(qualifiedName)
481+
&& !"float".equals(qualifiedName)
482+
&& !"double".equals(qualifiedName)
483+
&& !"long".equals(qualifiedName)
484+
&& !"short".equals(qualifiedName)
485+
&& !"byte".equals(qualifiedName)
486+
&& !"char".equals(qualifiedName)
487+
&& !"boolean".equals(qualifiedName)
452488
&& !qualifiedName.startsWith("org.w3c.dom.")
453489
&& !qualifiedName.startsWith("org.eclipse.swt.internal.xhtml.")) {
454490
ASTNoderoot =node.getRoot();
@@ -573,7 +609,7 @@ protected void visitForRequires(AbstractTypeDeclaration node) {
573609
}
574610
}
575611
}
576-
612+
577613
privateDependencyASTVisitorgetSelfVisitor() {
578614
try {
579615
Objectobj =this.getClass().getConstructor(newClass[0]).newInstance(newObject[0]);
@@ -715,34 +751,34 @@ public boolean visit(ClassInstanceCreation node) {
715751
returnsuper.visit(node);
716752
}
717753

718-
/* (non-Javadoc)
719-
* @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.ArrayCreation)
720-
*/
721-
publicbooleanvisit(ArrayCreationnode) {
722-
ArrayTypetype =node.getType();
723-
TypeelementType =type.getElementType();
724-
if (!elementType.isPrimitiveType()) {
725-
ITypeBindingresolveTypeBinding =elementType.resolveBinding();
726-
ITypeBindingdeclaringClass =resolveTypeBinding.getDeclaringClass();
727-
QNTypeBindingqn =newQNTypeBinding();
728-
StringqualifiedName =null;
729-
if (declaringClass !=null) {
730-
qualifiedName =declaringClass.getQualifiedName();
731-
qn.binding =declaringClass;
732-
}else {
733-
qualifiedName =resolveTypeBinding.getQualifiedName();
734-
qn.binding =resolveTypeBinding;
735-
}
736-
qualifiedName =discardGenericType(qualifiedName);
737-
qn.qualifiedName =qualifiedName;
738-
if (isQualifiedNameOK(qualifiedName,node)
739-
&& !musts.contains(qn)
740-
&& !requires.contains(qn)) {
741-
optionals.add(qn);
742-
}
743-
}
744-
returnsuper.visit(node);
745-
}
754+
///* (non-Javadoc)
755+
// * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.ArrayCreation)
756+
// */
757+
//public boolean visit(ArrayCreation node) {
758+
//ArrayType type = node.getType();
759+
//Type elementType = type.getElementType();
760+
//if (!elementType.isPrimitiveType()) {
761+
//ITypeBinding resolveTypeBinding = elementType.resolveBinding();
762+
//ITypeBinding declaringClass = resolveTypeBinding.getDeclaringClass();
763+
//QNTypeBinding qn = new QNTypeBinding();
764+
//String qualifiedName = null;
765+
//if (declaringClass != null) {
766+
//qualifiedName = declaringClass.getQualifiedName();
767+
//qn.binding = declaringClass;
768+
//} else {
769+
//qualifiedName = resolveTypeBinding.getQualifiedName();
770+
//qn.binding = resolveTypeBinding;
771+
//}
772+
//qualifiedName = discardGenericType(qualifiedName);
773+
//qn.qualifiedName = qualifiedName;
774+
//if (isQualifiedNameOK(qualifiedName, node)
775+
//&& !musts.contains(qn)
776+
//&& !requires.contains(qn)) {
777+
//optionals.add(qn);
778+
//}
779+
//}
780+
//return super.visit(node);
781+
//}
746782

747783
/* (non-Javadoc)
748784
* @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodInvocation)

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ public static boolean checkReference(ASTNode node, String methodSignature) {
5151
*/
5252
publicbooleanvisit(ClassInstanceCreationnode) {
5353
IMethodBindingconstructorBinding =node.resolveConstructorBinding();
54-
if (methodSignature.equals(constructorBinding.getKey())) {
54+
Stringkey =constructorBinding.getKey();
55+
if (key !=null) {
56+
key =key.replaceAll("<[^>]+>","");
57+
}
58+
if (methodSignature.equals(key)) {
5559
isReferenced =true;
5660
returnfalse;
5761
}
@@ -63,7 +67,11 @@ public boolean visit(ClassInstanceCreation node) {
6367
*/
6468
publicbooleanvisit(ConstructorInvocationnode) {
6569
IMethodBindingconstructorBinding =node.resolveConstructorBinding();
66-
if (methodSignature.equals(constructorBinding.getKey())) {
70+
Stringkey =constructorBinding.getKey();
71+
if (key !=null) {
72+
key =key.replaceAll("<[^>]+>","");
73+
}
74+
if (methodSignature.equals(key)) {
6775
isReferenced =true;
6876
returnfalse;
6977
}
@@ -75,7 +83,11 @@ public boolean visit(ConstructorInvocation node) {
7583
*/
7684
publicbooleanvisit(MethodInvocationnode) {
7785
IMethodBindingmethodBinding =node.resolveMethodBinding();
78-
if (methodSignature.equals(methodBinding.getKey())) {
86+
Stringkey =methodBinding.getKey();
87+
if (key !=null) {
88+
key =key.replaceAll("<[^>]+>","");
89+
}
90+
if (methodSignature.equals(key)) {
7991
isReferenced =true;
8092
returnfalse;
8193
}
@@ -87,7 +99,11 @@ public boolean visit(MethodInvocation node) {
8799
*/
88100
publicbooleanvisit(SuperMethodInvocationnode) {
89101
IMethodBindingmethodBinding =node.resolveMethodBinding();
90-
if (methodSignature.equals(methodBinding.getKey())) {
102+
Stringkey =methodBinding.getKey();
103+
if (key !=null) {
104+
key =key.replaceAll("<[^>]+>","");
105+
}
106+
if (methodSignature.equals(key)) {
91107
isReferenced =true;
92108
returnfalse;
93109
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp