Community
Participate
Working Groups
quick assist could help me change my == expressions to equals() ands vice versa (this is only possible when both sides of == are reference types and left side is not the null literal, but that should be trivially checkable)
Created attachment 7404 [details] fix @@ implementation notes @@ <object A>.equals(<object B>) offer only quick assist if <fully qualified name of A>.equals(<fully qualified name)
Created attachment 7405 [details] fix forgot to remove debug string :/
Created attachment 7406 [details] tests
Thanks, Sebastian! Can you look at the tests again, as they collide with the tests you wrote for bug 37432. You transform a.equals(b); to a == b; which is not a valid statement. I think it would be better to not return a quick assist in that case. I try to keep the offered quick fixes as precice as possible to avoid big lists. I think it would make sense to have all the equals tests together. The idea would be to somthing like the test I attached. For the tests please look that you are not depended on the order of the proposals. public void testChangeEqualsToSame() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" boolean b= \"a\".equals(\"b\");\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); String str= "equals"; AssistContext context= getCorrectionContext(cu, buf.toString().indexOf (str), 0); List proposals= collectAssists(context, FILTER_EQ); assertNumberOf("proposals", proposals.size(), 2); assertCorrectLabels(proposals); CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); String preview1= proposal.getCompilationUnitChange().getPreviewContent(); buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" boolean b= \"a\" == \"b\";\n"); buf.append(" }\n"); buf.append("}\n"); String expected1= buf.toString(); proposal= (CUCorrectionProposal) proposals.get(1); String preview2= proposal.getCompilationUnitChange().getPreviewContent(); buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" boolean b= \"b\".equals(\"a\");\n"); buf.append(" }\n"); buf.append("}\n"); String expected2= buf.toString(); assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 }); }
BTW, there's still a System.out in the code. Some other remarks: - 'resultingCollections' can be null. That means that this is only a requst if there is a quick assist, but no proposal should be created (yet). This is used to show the quick assist light bulb. - Can you merge the code for bug 37432 and 'equals to =='? They have more or less the same prereq testing, so it would make sense to have single method. (But do as you prefer) - Use 'ASTRewriteCorrectionProposal' instead of 'LinkedNamesAssistProposal' as your proposals don't enter the linked mode. - right.resolveTypeBinding(); can return null - you can compare bindings by idendity (if (binding1 == binding2)) {.. - you miss the case: int[] a = null, b = null; if (a.equals(b)) {} (also applies to bug 37432) -> I think you could change your code to if (binding.isNullType() || binding.isPrimitive()) { //overloaded equals w/ non-class/interface arg return false; }
sebastian? do you prefer I take over?
I have a bandwidth restriction of 1 GB download per month. Unfortunately, I have already used it up. I could continue work on this PR at the beginning of next month. If you don't want to wait that long, please go ahead. Sorry for the inconvenience :/