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

Commitf4a571b

Browse files
author
soheil_h_y
committed
1. Nullpointer Exceptions thrown removed from source!
1 parent3956d32 commitf4a571b

File tree

10 files changed

+150
-129
lines changed

10 files changed

+150
-129
lines changed

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

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,27 +71,29 @@ public boolean visit(Block node) {
7171
returnfalse;
7272
}
7373
IMethodBindingmethodBinding =method.resolveBinding();
74-
ITypeBindingsuperclass =methodBinding.getDeclaringClass().getSuperclass();
75-
booleancontainsSuperPrivateMethod =false;
76-
while (superclass !=null) {
77-
IMethodBinding[]methods =superclass.getDeclaredMethods();
78-
for (inti =0;i <methods.length;i++) {
79-
if (methods[i].getName().equals(methodBinding.getName())
80-
&& (methods[i].getModifiers() &Modifier.PRIVATE) !=0) {
81-
containsSuperPrivateMethod =true;
74+
if(methodBinding !=null){
75+
ITypeBindingsuperclass =methodBinding.getDeclaringClass().getSuperclass();
76+
booleancontainsSuperPrivateMethod =false;
77+
while (superclass !=null) {
78+
IMethodBinding[]methods =superclass.getDeclaredMethods();
79+
for (inti =0;i <methods.length;i++) {
80+
if (methods[i].getName().equals(methodBinding.getName())
81+
&& (methods[i].getModifiers() &Modifier.PRIVATE) !=0) {
82+
containsSuperPrivateMethod =true;
83+
break;
84+
}
85+
}
86+
if (containsSuperPrivateMethod) {
8287
break;
8388
}
89+
superclass =superclass.getSuperclass();
8490
}
8591
if (containsSuperPrivateMethod) {
86-
break;
92+
buffer.append("var $private = Clazz.checkPrivateMethod (arguments);\r\n");
93+
buffer.append("if ($private != null) {\r\n");
94+
buffer.append("return $private.apply (this, arguments);\r\n");
95+
buffer.append("}\r\n");
8796
}
88-
superclass =superclass.getSuperclass();
89-
}
90-
if (containsSuperPrivateMethod) {
91-
buffer.append("var $private = Clazz.checkPrivateMethod (arguments);\r\n");
92-
buffer.append("if ($private != null) {\r\n");
93-
buffer.append("return $private.apply (this, arguments);\r\n");
94-
buffer.append("}\r\n");
9597
}
9698
}elseif (parentinstanceofInitializer) {
9799
Initializerinitializer = (Initializer)parent;

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

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public boolean visit(ArrayAccess node) {
146146
Expressionindex =node.getIndex();
147147
index.accept(this);
148148
ITypeBindingrightTypeBinding =index.resolveTypeBinding();
149-
if ("char".equals(rightTypeBinding.getName())) {
149+
if (rightTypeBinding !=null &&"char".equals(rightTypeBinding.getName())) {
150150
buffer.append(".charCodeAt (0)");
151151
}
152152
buffer.append(']');
@@ -163,35 +163,37 @@ public boolean visit(ArrayCreation node) {
163163
}else {
164164
Listdim =node.dimensions();
165165
ITypeBindingbinding =node.getType().resolveBinding();
166-
ITypeBindingelementType =binding.getElementType();
167-
if (elementType.isPrimitive()) {
168-
StringtypeCode =elementType.getName();
169-
if ("int".equals(typeCode)
170-
||"float".equals(typeCode)
171-
||"double".equals(typeCode)
172-
||"byte".equals(typeCode)
173-
||"long".equals(typeCode)
174-
||"short".equals(typeCode)) {
175-
buffer.append(" Clazz.newArray (");
176-
visitList(dim,", ");
177-
buffer.append(", 0)");
178-
}elseif ("char".equals(typeCode)) {
179-
buffer.append(" Clazz.newArray (");
180-
visitList(dim,", ");
181-
buffer.append(", '\\0')");
182-
}elseif ("boolean".equals(typeCode)) {
183-
buffer.append(" Clazz.newArray (");
184-
visitList(dim,", ");
185-
buffer.append(", false)");
186-
}else {
187-
if (dim !=null &&dim.size() >1) {
166+
if(binding !=null){
167+
ITypeBindingelementType =binding.getElementType();
168+
if (elementType.isPrimitive()) {
169+
StringtypeCode =elementType.getName();
170+
if ("int".equals(typeCode)
171+
||"float".equals(typeCode)
172+
||"double".equals(typeCode)
173+
||"byte".equals(typeCode)
174+
||"long".equals(typeCode)
175+
||"short".equals(typeCode)) {
176+
buffer.append(" Clazz.newArray (");
177+
visitList(dim,", ");
178+
buffer.append(", 0)");
179+
}elseif ("char".equals(typeCode)) {
188180
buffer.append(" Clazz.newArray (");
189181
visitList(dim,", ");
190-
buffer.append(", null)");
182+
buffer.append(", '\\0')");
183+
}elseif ("boolean".equals(typeCode)) {
184+
buffer.append(" Clazz.newArray (");
185+
visitList(dim,", ");
186+
buffer.append(", false)");
191187
}else {
192-
buffer.append(" new Array (");
193-
visitList(dim,"");
194-
buffer.append(")");
188+
if (dim !=null &&dim.size() >1) {
189+
buffer.append(" Clazz.newArray (");
190+
visitList(dim,", ");
191+
buffer.append(", null)");
192+
}else {
193+
buffer.append(" new Array (");
194+
visitList(dim,"");
195+
buffer.append(")");
196+
}
195197
}
196198
}
197199
}else {
@@ -329,7 +331,7 @@ public boolean visit(Assignment node) {
329331
ITypeBindingtypeBinding =left.resolveTypeBinding();
330332
Stringop =node.getOperator().toString();
331333
Expressionright =node.getRightHandSide();
332-
if (typeBinding.isPrimitive()) {
334+
if (typeBinding !=null &&typeBinding.isPrimitive()) {
333335
if ("boolean".equals(typeBinding.getName())) {
334336
if (op.startsWith("^")
335337
||op.startsWith("|")
@@ -352,7 +354,7 @@ public boolean visit(Assignment node) {
352354
buffer.append(".valueOf ()");
353355
returnfalse;
354356
}
355-
}elseif ("char".equals(typeBinding.getName())) {
357+
}elseif (typeBinding !=null &&"char".equals(typeBinding.getName())) {
356358
booleanisMixedOp =op.trim().length() >1;
357359
if (!isMixedOp) {
358360
if (rightinstanceofName ||rightinstanceofCharacterLiteral
@@ -407,7 +409,7 @@ public boolean visit(Assignment node) {
407409
buffer.append(' ');
408410
buffer.append(op);
409411
buffer.append(' ');
410-
if ("char".equals(right.resolveTypeBinding().getName())) {
412+
if (right.resolveTypeBinding() !=null &&"char".equals(right.resolveTypeBinding().getName())) {
411413
buffer.append('(');
412414
right.accept(this);
413415
buffer.append(").charCodeAt (0)");
@@ -700,7 +702,7 @@ public void endVisit(PostfixExpression node) {
700702
return ;
701703
}
702704
ITypeBindingtypeBinding =node.getOperand().resolveTypeBinding();
703-
if (typeBinding.isPrimitive()) {
705+
if (typeBinding !=null &&typeBinding.isPrimitive()) {
704706
if ("char".equals(typeBinding.getName())) {
705707
return ;
706708
}
@@ -800,7 +802,7 @@ public boolean visit(PostfixExpression node) {
800802
returnfalse;
801803
}
802804
ITypeBindingtypeBinding =node.getOperand().resolveTypeBinding();
803-
if (typeBinding.isPrimitive()) {
805+
if (typeBinding !=null &&typeBinding.isPrimitive()) {
804806
if ("char".equals(typeBinding.getName())) {
805807
buffer.append("(");
806808
node.getOperand().accept(this);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ public static void registerAllMaps() {
171171

172172

173173
privatebooleantestForceOverriding(IMethodBindingmethod) {
174+
if(method ==null){
175+
returntrue;
176+
}
174177
StringmethodName =method.getName();
175178
ITypeBindingclassInHierarchy =method.getDeclaringClass();
176179
do {
@@ -205,7 +208,7 @@ private boolean testForceOverriding(IMethodBinding method) {
205208
protectedbooleancanAutoOverride(MethodDeclarationnode) {
206209
booleanisOK2AutoOverriding =false;
207210
IMethodBindingmethodBinding =node.resolveBinding();
208-
if (testForceOverriding(methodBinding)) {
211+
if (methodBinding !=null &&testForceOverriding(methodBinding)) {
209212
IMethodBindingsuperMethod =Bindings.findMethodDeclarationInHierarchy(methodBinding.getDeclaringClass(),methodBinding);
210213
if (superMethod !=null) {
211214
ASTNodeparentRoot =node.getParent();

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

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -372,45 +372,47 @@ public boolean visit(CastExpression node) {
372372
*/
373373
if (type.isPrimitiveType()) {
374374
ITypeBindingresolveTypeBinding =node.getExpression().resolveTypeBinding();
375-
Stringname =resolveTypeBinding.getName();
376-
PrimitiveTypepType = (PrimitiveType)type;
377-
if (pType.getPrimitiveTypeCode() ==PrimitiveType.INT
378-
||pType.getPrimitiveTypeCode() ==PrimitiveType.BYTE
379-
||pType.getPrimitiveTypeCode() ==PrimitiveType.SHORT
380-
||pType.getPrimitiveTypeCode() ==PrimitiveType.LONG) {
381-
if ("char".equals(name)) {
382-
buffer.append("(");
383-
node.getExpression().accept(this);
384-
buffer.append (").charCodeAt (0)");
385-
returnfalse;
386-
}elseif ("float".equals(name) ||"double".equals(name)) {
387-
buffer.append("Math.round (");
388-
node.getExpression().accept(this);
389-
buffer.append (")");
390-
returnfalse;
375+
if(resolveTypeBinding !=null){
376+
Stringname =resolveTypeBinding.getName();
377+
PrimitiveTypepType = (PrimitiveType)type;
378+
if (pType.getPrimitiveTypeCode() ==PrimitiveType.INT
379+
||pType.getPrimitiveTypeCode() ==PrimitiveType.BYTE
380+
||pType.getPrimitiveTypeCode() ==PrimitiveType.SHORT
381+
||pType.getPrimitiveTypeCode() ==PrimitiveType.LONG) {
382+
if ("char".equals(name)) {
383+
buffer.append("(");
384+
node.getExpression().accept(this);
385+
buffer.append (").charCodeAt (0)");
386+
returnfalse;
387+
}elseif ("float".equals(name) ||"double".equals(name)) {
388+
buffer.append("Math.round (");
389+
node.getExpression().accept(this);
390+
buffer.append (")");
391+
returnfalse;
392+
}
391393
}
392-
}
393-
if (pType.getPrimitiveTypeCode() ==PrimitiveType.CHAR) {
394-
if ("char".equals(name)) {
395-
//buffer.append("(");
396-
//node.getExpression().accept(this);
397-
//buffer.append (").charCodeAt (0)");
398-
//return false;
399-
}elseif ("float".equals(name) ||"double".equals(name)) {
400-
// TODO:
401-
buffer.append("String.fromCharCode (");
402-
buffer.append("Math.round (");
403-
node.getExpression().accept(this);
404-
buffer.append (")");
405-
buffer.append (")");
406-
returnfalse;
407-
}elseif ("int".equals(name) ||"byte".equals(name)
408-
||"double".equals(name) ||"float".equals(name)
409-
||"short".equals(name) ||"long".equals(name)) {
410-
buffer.append("String.fromCharCode (");
411-
node.getExpression().accept(this);
412-
buffer.append (")");
413-
returnfalse;
394+
if (pType.getPrimitiveTypeCode() ==PrimitiveType.CHAR) {
395+
if ("char".equals(name)) {
396+
//buffer.append("(");
397+
//node.getExpression().accept(this);
398+
//buffer.append (").charCodeAt (0)");
399+
//return false;
400+
}elseif ("float".equals(name) ||"double".equals(name)) {
401+
// TODO:
402+
buffer.append("String.fromCharCode (");
403+
buffer.append("Math.round (");
404+
node.getExpression().accept(this);
405+
buffer.append (")");
406+
buffer.append (")");
407+
returnfalse;
408+
}elseif ("int".equals(name) ||"byte".equals(name)
409+
||"double".equals(name) ||"float".equals(name)
410+
||"short".equals(name) ||"long".equals(name)) {
411+
buffer.append("String.fromCharCode (");
412+
node.getExpression().accept(this);
413+
buffer.append (")");
414+
returnfalse;
415+
}
414416
}
415417
}
416418
}
@@ -1223,10 +1225,12 @@ public boolean visit(MethodDeclaration node) {
12231225
}
12241226
}
12251227
if ((node.getModifiers() &Modifier.PRIVATE) !=0) {
1226-
booleanisReferenced =MethodReferenceASTVisitor.checkReference(node.getRoot(),
1227-
node.resolveBinding().getKey());
1228-
if (!isReferenced &&getJ2SDocTag(node,"@j2sKeep") ==null) {
1229-
returnfalse;
1228+
if(node.resolveBinding() !=null){
1229+
booleanisReferenced =MethodReferenceASTVisitor.checkReference(node.getRoot(),
1230+
node.resolveBinding().getKey());
1231+
if (!isReferenced &&getJ2SDocTag(node,"@j2sKeep") ==null) {
1232+
returnfalse;
1233+
}
12301234
}
12311235
}
12321236

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ public String getTypeStringName(Type type) {
230230
returngetTypeStringName(qualType.getQualifier()) +"." +qualType.getName().getIdentifier();//.getFullyQualifiedName();
231231
}elseif (typeinstanceofSimpleType) {
232232
SimpleTypesimpType = (SimpleType)type;
233-
returnsimpType.resolveBinding().getQualifiedName();
233+
if(simpType.resolveBinding() !=null){
234+
returnsimpType.resolveBinding().getQualifiedName();
235+
}
234236
}
235237
returnnull;
236238
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ private static boolean areSubTypeCompatible(IMethodBinding overridden, IMethodBi
13341334
}
13351335

13361336
publicstaticbooleanisMethodInvoking(IMethodBindingmethodBinding,StringclassName,StringmethodName) {
1337-
if (methodName.equals(methodBinding.getName())) {
1337+
if (methodBinding !=null &&methodName.equals(methodBinding.getName())) {
13381338
IMethodBindingfindMethodInHierarchy =Bindings.findMethodInHierarchy(methodBinding.getDeclaringClass(),methodName,null);
13391339
IMethodBindinglast =findMethodInHierarchy;
13401340
intcount =0;

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

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -728,10 +728,10 @@ public boolean visit(ClassInstanceCreation node) {
728728
ITypeBindingresolveTypeBinding =node.resolveTypeBinding();
729729
QNTypeBindingqn =newQNTypeBinding();
730730
StringqualifiedName =null;
731-
if (resolveTypeBinding.isAnonymous()) {
731+
if (resolveTypeBinding !=null &&resolveTypeBinding.isAnonymous()) {
732732
qualifiedName =node.getType().resolveBinding().getQualifiedName();
733733
qn.binding =node.getType().resolveBinding();
734-
}else {
734+
}elseif(resolveTypeBinding !=null){
735735
ITypeBindingdeclaringClass =resolveTypeBinding.getDeclaringClass();
736736
if (declaringClass !=null) {
737737
qualifiedName =declaringClass.getQualifiedName();
@@ -740,6 +740,8 @@ public boolean visit(ClassInstanceCreation node) {
740740
qualifiedName =resolveTypeBinding.getQualifiedName();
741741
qn.binding =resolveTypeBinding;
742742
}
743+
}else{
744+
returnsuper.visit(node);
743745
}
744746
qualifiedName =discardGenericType(qualifiedName);
745747
qn.qualifiedName =qualifiedName;
@@ -759,22 +761,24 @@ public boolean visit(ClassInstanceCreation node) {
759761
//Type elementType = type.getElementType();
760762
//if (!elementType.isPrimitiveType()) {
761763
//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);
764+
//if(resolveTypeBinding != null){
765+
//ITypeBinding declaringClass = resolveTypeBinding.getDeclaringClass();
766+
//QNTypeBinding qn = new QNTypeBinding();
767+
//String qualifiedName = null;
768+
//if (declaringClass != null) {
769+
//qualifiedName = declaringClass.getQualifiedName();
770+
//qn.binding = declaringClass;
771+
//} else {
772+
//qualifiedName = resolveTypeBinding.getQualifiedName();
773+
//qn.binding = resolveTypeBinding;
774+
//}
775+
//qualifiedName = discardGenericType(qualifiedName);
776+
//qn.qualifiedName = qualifiedName;
777+
//if (isQualifiedNameOK(qualifiedName, node)
778+
//&& !musts.contains(qn)
779+
//&& !requires.contains(qn)) {
780+
//optionals.add(qn);
781+
//}
778782
//}
779783
//}
780784
//return super.visit(node);
@@ -912,7 +916,7 @@ public boolean visit(FieldAccess node) {
912916
ObjectconstValue =node.resolveConstantExpressionValue();
913917
IVariableBindingresolveFieldBinding =node.resolveFieldBinding();
914918
Expressionexp =node.getExpression();
915-
if (constValue ==null &&Modifier.isStatic(resolveFieldBinding.getModifiers())) {
919+
if (resolveFieldBinding !=null &&constValue ==null &&Modifier.isStatic(resolveFieldBinding.getModifiers())) {
916920
Expressionexpression =exp;
917921
if (expressioninstanceofName) {
918922
Namename = (Name)expression;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp