|
58 | 58 | import org.eclipse.jdt.core.dom.TypeLiteral; |
59 | 59 | import org.eclipse.jdt.core.dom.VariableDeclarationFragment; |
60 | 60 |
|
61 | | -// TODO Clazz._4Name replaces Class.forName$S |
62 | | - |
63 | 61 | // BH 8/19/2017 -- String must implement CharSequence, so all .length() -> .length$() |
64 | 62 | // BH 8/19/2017 -- varargs logic fixed for missing argument |
65 | 63 | // BH 8/18/2017 -- array instanceof, reflection, componentType fixes |
@@ -1183,24 +1181,24 @@ public boolean visit(MethodDeclaration node) { |
1183 | 1181 | visitList(parameters, ", "); |
1184 | 1182 | buffer.append(") "); |
1185 | 1183 | if (node.isConstructor()) { |
1186 | | - boolean isSuperOrThis = false; |
| 1184 | + boolean hasSuperOrThis = false; |
1187 | 1185 | @SuppressWarnings("unchecked") |
1188 | 1186 | List<ASTNode> statements = node.getBody().statements(); |
1189 | 1187 | if (statements.size() > 0) { |
1190 | 1188 | ASTNode firstStatement = statements.get(0); |
1191 | 1189 | if (firstStatement instanceof SuperConstructorInvocation |
1192 | 1190 | || firstStatement instanceof ConstructorInvocation) { |
1193 | | - isSuperOrThis = true; |
| 1191 | + hasSuperOrThis = true; |
1194 | 1192 | } |
1195 | 1193 | } |
1196 | 1194 | // BH @j2sIgnoreSuperConstructor removed from options |
1197 | 1195 | // as it is too risky to do this -- lose all initialization. |
1198 | | - IMethodBinding binding = node.resolveBinding(); |
1199 | | - boolean existedSuperClass = binding != null && hasSuperClass(binding.getDeclaringClass()); |
1200 | | - if (isSuperOrThis) { |
| 1196 | + if (hasSuperOrThis) { |
1201 | 1197 | if (!checkJ2STags(node, true)) |
1202 | 1198 | node.getBody().accept(this); |
1203 | 1199 | } else { |
| 1200 | + IMethodBinding binding = node.resolveBinding(); |
| 1201 | + boolean existedSuperClass = binding != null && hasSuperClass(binding.getDeclaringClass()); |
1204 | 1202 | buffer.append("{\r\n"); |
1205 | 1203 | if (existedSuperClass) { |
1206 | 1204 | addSuperConstructor(null, null); |
@@ -1804,30 +1802,26 @@ public boolean visit(SingleVariableDeclaration node) { |
1804 | 1802 |
|
1805 | 1803 | public boolean visit(SuperConstructorInvocation node) { |
1806 | 1804 | IMethodBinding constructorBinding = node.resolveConstructorBinding(); |
1807 | | - if (constructorBinding == null) { |
1808 | | - return false; |
1809 | | - } |
1810 | | - ITypeBinding declaringClass = constructorBinding.getDeclaringClass(); |
1811 | | - if ("java.lang.Object".equals(declaringClass.getQualifiedName())) { |
1812 | | - return false; |
| 1805 | + ITypeBinding declaringClass = (constructorBinding == null ? null : constructorBinding.getDeclaringClass()); |
| 1806 | + if (constructorBinding != null && declaringClass != null && !"java.lang.Object".equals(declaringClass.getQualifiedName())) { |
| 1807 | + // // BH NEVER NEVER NEVER ignore superconstructor, as it |
| 1808 | + // includes an <init> call. |
| 1809 | + // ASTNode parent = node.getParent(); |
| 1810 | + // if (parent instanceof Block) { |
| 1811 | + // Block methoBlock = (Block) parent; |
| 1812 | + // ASTNode methodParent = methoBlock.getParent(); |
| 1813 | + // if (methodParent instanceof MethodDeclaration) { |
| 1814 | + // MethodDeclaration method = (MethodDeclaration) methodParent; |
| 1815 | + // if (getJ2STag(method, "@j2sIgnoreSuperConstructor") != null) |
| 1816 | + // { |
| 1817 | + // return false; |
| 1818 | + // } |
| 1819 | + // } |
| 1820 | + // } |
| 1821 | + addSuperConstructor(node, constructorBinding.getMethodDeclaration()); |
| 1822 | + } else { |
| 1823 | + addCallInit(); |
1813 | 1824 | } |
1814 | | -// // BH NEVER NEVER NEVER ignore superconstructor, as it includes an <init> call. |
1815 | | -// ASTNode parent = node.getParent(); |
1816 | | -// if (parent instanceof Block) { |
1817 | | -// Block methoBlock = (Block) parent; |
1818 | | -// ASTNode methodParent = methoBlock.getParent(); |
1819 | | -// if (methodParent instanceof MethodDeclaration) { |
1820 | | -// MethodDeclaration method = (MethodDeclaration) methodParent; |
1821 | | -// if (getJ2STag(method, "@j2sIgnoreSuperConstructor") != null) { |
1822 | | -// return false; |
1823 | | -// } |
1824 | | -// } |
1825 | | -// } |
1826 | | - /* |
1827 | | - * TODO: expression before the "super" should be considered. |
1828 | | - */ |
1829 | | - IMethodBinding methodDeclaration = constructorBinding.getMethodDeclaration(); |
1830 | | - addSuperConstructor(node, methodDeclaration); |
1831 | 1825 | return false; |
1832 | 1826 | } |
1833 | 1827 |
|
|
0 commit comments