|
33 | 33 | import org.eclipse.jdt.core.dom.IMethodBinding; |
34 | 34 | import org.eclipse.jdt.core.dom.ITypeBinding; |
35 | 35 | import org.eclipse.jdt.core.dom.IVariableBinding; |
36 | | -import org.eclipse.jdt.core.dom.InfixExpression; |
37 | 36 | import org.eclipse.jdt.core.dom.Initializer; |
38 | 37 | import org.eclipse.jdt.core.dom.MethodDeclaration; |
39 | 38 | import org.eclipse.jdt.core.dom.MethodInvocation; |
|
57 | 56 | import org.eclipse.jdt.core.dom.TypeLiteral; |
58 | 57 | import org.eclipse.jdt.core.dom.VariableDeclarationFragment; |
59 | 58 |
|
60 | | -// TODO: assert |
61 | | - |
62 | 59 | // TODO: static calls to static methods do not trigger "musts" dependency |
63 | 60 |
|
64 | | -// BH 9/8/2017 -- primitive numeric casting -- (byte) was ignored so that (byte) 0xFF remained 0xFF. |
| 61 | + |
| 62 | +//TODO: doubleToInt; not just /= |
| 63 | + |
| 64 | +// BH 9/7/2017 -- primitive casting for *=,/=,+=,-=,&=,|=,^= |
| 65 | +// BH 9/7/2017 -- primitive numeric casting -- (byte) was ignored so that (byte) 0xFF remained 0xFF. |
65 | 66 | // BH 9/7/2017 -- fixed multiple issues with char and Character |
66 | 67 | // BH 9/4/2017 -- java.awt, javax.swing, swingjs code added; additional fixes required |
67 | 68 | // BH 8/30/2017 -- all i/o working, including printf and FileOutputStream |
@@ -249,10 +250,6 @@ protected boolean checkSameName(ITypeBinding binding, String name) { |
249 | 250 | return ((ASTJ2SMapVisitor) getAdaptable(ASTJ2SMapVisitor.class)).checkSameName(binding, name); |
250 | 251 | } |
251 | 252 |
|
252 | | - public boolean isPrimNumberType(String type) { |
253 | | - return ((ASTTypeVisitor) getAdaptable(ASTTypeVisitor.class)).isNumericType(type); |
254 | | - } |
255 | | - |
256 | 253 | public String getClassName() { |
257 | 254 | return ((ASTTypeVisitor) getAdaptable(ASTTypeVisitor.class)).getClassName(); |
258 | 255 | } |
@@ -838,25 +835,6 @@ public boolean visit(EnumConstantDeclaration node) { |
838 | 835 | return super.visit(node); |
839 | 836 | } |
840 | 837 |
|
841 | | - public boolean visit(FieldAccess node) { |
842 | | - // Expression . Identifier |
843 | | - // TODO: more complicated rules should be considered. read the JavaDoc |
844 | | - IVariableBinding varBinding = node.resolveFieldBinding(); |
845 | | - Expression expression = node.getExpression(); |
846 | | - if (checkStaticBinding(varBinding)) { |
847 | | - buffer.append('('); |
848 | | - expression.accept(this); |
849 | | - buffer.append(", "); |
850 | | - buffer.append(assureQualifiedName(removeJavaLang(varBinding.getDeclaringClass().getQualifiedName()))); |
851 | | - buffer.append(')'); |
852 | | - } else { |
853 | | - expression.accept(this); |
854 | | - } |
855 | | - buffer.append("."); |
856 | | - node.getName().accept(this); |
857 | | - return false; |
858 | | - } |
859 | | - |
860 | 838 | public boolean visit(FieldDeclaration node) { |
861 | 839 | if (isStatic(node)) |
862 | 840 | return false; |
@@ -916,173 +894,10 @@ private ITypeBinding resolveParentBinding(ASTNode xparent) { |
916 | 894 | : null); |
917 | 895 | } |
918 | 896 |
|
919 | | - /** |
920 | | - * The left operand is primitive boolean. Check to see if the operator is ^, |
921 | | - * |, or &, or if the left or right operand is such an expression. |
922 | | - * |
923 | | - * If so, we are going to box this all as a Boolean(....).valueOf() |
924 | | - * |
925 | | - * @param node |
926 | | - * @return |
927 | | - */ |
928 | | - private boolean isBitwiseBinaryOperator(InfixExpression node) { |
929 | | - if (checkSimpleBooleanOperator(node.getOperator().toString())) { |
930 | | - return true; |
931 | | - } |
932 | | - Expression left = node.getLeftOperand(); |
933 | | - if (left instanceof InfixExpression) { |
934 | | - if (isBitwiseBinaryOperator((InfixExpression) left)) { |
935 | | - return true; |
936 | | - } |
937 | | - } |
938 | | - Expression right = node.getRightOperand(); |
939 | | - if (right instanceof InfixExpression) { |
940 | | - if (isBitwiseBinaryOperator((InfixExpression) right)) { |
941 | | - return true; |
942 | | - } |
943 | | - } |
944 | | - return false; |
945 | | - } |
946 | | - |
947 | | - private boolean checkSimpleBooleanOperator(String op) { |
948 | | - return (op.equals("^") || op.equals("|") || op.equals("&")); |
949 | | - } |
950 | | - |
951 | | - public boolean visit(InfixExpression node) { |
952 | | - // TODO check for String + Double/Float --> String + ... .toString() |
953 | | - // and change to String + double/float --> String + new |
954 | | - // Double/Float(...).toString() |
955 | | - String constValue = checkConstantValue(node); |
956 | | - if (constValue != null) { |
957 | | - buffer.append(constValue); |
958 | | - return false; |
959 | | - } |
960 | | - ITypeBinding expTypeBinding = node.resolveTypeBinding(); |
961 | | - if (expTypeBinding == null) |
962 | | - return false; |
963 | | - boolean toString = (expTypeBinding.getName().indexOf("String") >= 0); |
964 | | - String operator = node.getOperator().toString(); |
965 | | - Expression left = node.getLeftOperand(); |
966 | | - Expression right = node.getRightOperand(); |
967 | | - ITypeBinding leftTypeBinding = left.resolveTypeBinding(); |
968 | | - ITypeBinding rightTypeBinding = right.resolveTypeBinding(); |
969 | | - if (leftTypeBinding == null || rightTypeBinding == null) |
970 | | - return false; |
971 | | - String leftName = leftTypeBinding.getName(); |
972 | | - String rightName = rightTypeBinding.getName(); |
973 | | - if ("!==<=>=".indexOf(operator) >= 0) { |
974 | | - // < > <= >= == != |
975 | | - switch (leftName) { |
976 | | - case "char": |
977 | | - case "Character": |
978 | | - switch (rightName) { |
979 | | - case "char": |
980 | | - case "Character": |
981 | | - boxingNode(left); |
982 | | - buffer.append(' '); |
983 | | - buffer.append(operator); |
984 | | - buffer.append(' '); |
985 | | - boxingNode(right); |
986 | | - return false; |
987 | | - default: |
988 | | - } |
989 | | - break; |
990 | | - default: |
991 | | - break; |
992 | | - } |
993 | | - } else if ("/".equals(operator)) { |
994 | | - // what about CHAR here? |
995 | | - if (leftTypeBinding.isPrimitive() && isPrimNumberType(leftName) && isPrimNumberType(rightName)) { |
996 | | - // left and right are some sort of primitive byte, short, int, |
997 | | - // or, long |
998 | | - // division must take care of this. |
999 | | - // TODO more issues here... |
1000 | | - StringBuffer oldBuffer = buffer; |
1001 | | - buffer = new StringBuffer(); |
1002 | | - buffer.append("Clazz.doubleToInt ("); |
1003 | | - { |
1004 | | - addOperand(left, toString); |
1005 | | - buffer.append(" / "); |
1006 | | - addOperand(right, toString); |
1007 | | - } |
1008 | | - buffer.append(')'); |
1009 | | - List<?> extendedOperands = node.extendedOperands(); |
1010 | | - if (extendedOperands.size() > 0) { |
1011 | | - for (Iterator<?> iter = extendedOperands.iterator(); iter.hasNext();) { |
1012 | | - ASTNode element = (ASTNode) iter.next(); |
1013 | | - boolean is2Floor = false; |
1014 | | - if (element instanceof Expression) { |
1015 | | - Expression exp = (Expression) element; |
1016 | | - ITypeBinding expBinding = exp.resolveTypeBinding(); |
1017 | | - if (isPrimNumberType(expBinding.getName())) { |
1018 | | - buffer.insert(0, "Clazz.doubleToInt ("); |
1019 | | - is2Floor = true; |
1020 | | - } |
1021 | | - } |
1022 | | - buffer.append(" / "); |
1023 | | - addOperand((Expression) element, toString); |
1024 | | - if (is2Floor) { |
1025 | | - buffer.append(')'); |
1026 | | - } |
1027 | | - } |
1028 | | - } |
1029 | | - oldBuffer.append(buffer); |
1030 | | - buffer = oldBuffer; |
1031 | | - oldBuffer = null; |
1032 | | - return false; |
1033 | | - } |
1034 | | - } |
1035 | | - boolean toBoolean = false; |
1036 | | - if (leftTypeBinding.isPrimitive() && "boolean".equals(leftName) && isBitwiseBinaryOperator(node)) { |
1037 | | - // box this as Boolean(...).valueOf(); |
1038 | | - buffer.append(" new Boolean ("); |
1039 | | - toBoolean = true; |
1040 | | - } |
1041 | | - // left |
1042 | | - addOperand(left, toString); |
1043 | | - buffer.append(' '); |
1044 | | - // op |
1045 | | - buffer.append(operator); |
1046 | | - if (("==".equals(operator) || "!=".equals(operator)) && !leftTypeBinding.isPrimitive() |
1047 | | - && !(left instanceof NullLiteral) && !(right instanceof NullLiteral)) { |
1048 | | - buffer.append('='); |
1049 | | - } |
1050 | | - buffer.append(' '); |
1051 | | - // right |
1052 | | - addOperand(right, toString); |
1053 | | - |
1054 | | - // ok, this is trouble |
1055 | | - // The extended operands is the preferred way of representing deeply |
1056 | | - // nested expressions of the form L op R op R2 op R3... where the same |
1057 | | - // operator appears between all the operands (the most common case being |
1058 | | - // lengthy string concatenation expressions). Using the extended |
1059 | | - // operands keeps the trees from getting too deep; this decreases the |
1060 | | - // risk is running out of thread stack space at runtime when traversing |
1061 | | - // such trees. ((a + b) + c) + d would be translated to: leftOperand: a |
1062 | | - // rightOperand: b extendedOperands: {c, d} operator: + |
1063 | | - |
1064 | | - List<?> extendedOperands = node.extendedOperands(); |
1065 | | - if (extendedOperands.size() > 0) { |
1066 | | - for (Iterator<?> iter = extendedOperands.iterator(); iter.hasNext();) { |
1067 | | - buffer.append(' '); |
1068 | | - buffer.append(operator); |
1069 | | - buffer.append(' '); |
1070 | | - ASTNode element = (ASTNode) iter.next(); |
1071 | | - addOperand((Expression) element, toString); |
1072 | | - } |
1073 | | - } |
1074 | | - if (toBoolean) { |
1075 | | - // unbox Boolean(...) |
1076 | | - buffer.append(").valueOf()"); |
1077 | | - } |
1078 | | - return false; |
1079 | | - } |
1080 | | - |
1081 | 897 | public boolean visit(Initializer node) { |
1082 | 898 | if (checkj2sIgnore(node)) { |
1083 | 899 | return false; |
1084 | 900 | } |
1085 | | - // visitList(node.getBody().statements(), "\r\n"); |
1086 | 901 | node.getBody().accept(this); |
1087 | 902 | buffer.append("\r\n"); |
1088 | 903 | return false; |
|
0 commit comments