diff options
author | Noopur Gupta | 2015-09-03 13:12:10 +0000 |
---|---|---|
committer | Noopur Gupta | 2015-09-03 13:12:10 +0000 |
commit | fc2cd778fa525c5e5c56a38bb1f8161df3eb659e (patch) | |
tree | 3e4e20d97e2663e4d1e4a8527f0ec39fdaa65432 | |
parent | a4a51ce7e8b69675e4d335f8af00d59474899482 (diff) | |
download | eclipse.jdt.ui-fc2cd778fa525c5e5c56a38bb1f8161df3eb659e.tar.gz eclipse.jdt.ui-fc2cd778fa525c5e5c56a38bb1f8161df3eb659e.tar.xz eclipse.jdt.ui-fc2cd778fa525c5e5c56a38bb1f8161df3eb659e.zip |
Fixed bug 476517 - [1.8][quick fix] "Add unimplemented methods" creates
stubs for methods with default implementation
Change-Id: I5db0514c72d6515f80941baaa9d8a7cc5bde0724
2 files changed, 70 insertions, 2 deletions
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest18.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest18.java index 4225793c49..4235954bff 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest18.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest18.java @@ -429,6 +429,71 @@ public class QuickFixTest18 extends QuickFixTest { assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 }); } + public void testUnimplementedMethods6() throws Exception { + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); + StringBuffer buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("import java.math.BigInteger;\n"); + buf.append("interface IHasInt {\n"); + buf.append(" int getInt();\n"); + buf.append("}\n"); + buf.append("interface IHasIntAsBigInteger extends IHasInt {\n"); + buf.append(" default int getInt() {\n"); + buf.append(" return getIntAsBigInteger().intValue();\n"); + buf.append(" }\n"); + buf.append(" BigInteger getIntAsBigInteger();\n"); + buf.append("}\n"); + buf.append("class C implements IHasIntAsBigInteger {\n"); + buf.append("}\n"); + ICompilationUnit cu= pack1.createCompilationUnit("IHasInt.java", buf.toString(), false, null); + + CompilationUnit astRoot= getASTRoot(cu); + ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); + + assertCorrectLabels(proposals); + assertNumberOfProposals(proposals, 2); + + String[] expected= new String[2]; + buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("import java.math.BigInteger;\n"); + buf.append("interface IHasInt {\n"); + buf.append(" int getInt();\n"); + buf.append("}\n"); + buf.append("interface IHasIntAsBigInteger extends IHasInt {\n"); + buf.append(" default int getInt() {\n"); + buf.append(" return getIntAsBigInteger().intValue();\n"); + buf.append(" }\n"); + buf.append(" BigInteger getIntAsBigInteger();\n"); + buf.append("}\n"); + buf.append("class C implements IHasIntAsBigInteger {\n"); + buf.append("\n"); + buf.append(" @Override\n"); + buf.append(" public BigInteger getIntAsBigInteger() {\n"); + buf.append(" return null;\n"); + buf.append(" }\n"); + buf.append("}\n"); + expected[0]= buf.toString(); + + buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("import java.math.BigInteger;\n"); + buf.append("interface IHasInt {\n"); + buf.append(" int getInt();\n"); + buf.append("}\n"); + buf.append("interface IHasIntAsBigInteger extends IHasInt {\n"); + buf.append(" default int getInt() {\n"); + buf.append(" return getIntAsBigInteger().intValue();\n"); + buf.append(" }\n"); + buf.append(" BigInteger getIntAsBigInteger();\n"); + buf.append("}\n"); + buf.append("abstract class C implements IHasIntAsBigInteger {\n"); + buf.append("}\n"); + expected[1]= buf.toString(); + + assertExpectedExistInProposals(proposals, expected); + } + public void testLambdaReturnType1() throws Exception { StringBuffer buf= new StringBuffer(); IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2.java index fa9ae07be6..60850f6446 100644 --- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2.java +++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2.java @@ -596,9 +596,12 @@ public final class StubUtility2 { toImplement.remove(oneMethod); } } - if (Modifier.isAbstract(curr.getModifiers())) { - toImplement.add(curr); + int modifiers= curr.getModifiers(); + if (!Modifier.isStatic(modifiers)) { allMethods.add(curr); + if (Modifier.isAbstract(modifiers)) { + toImplement.add(curr); + } } } ITypeBinding[] superInterfaces= typeBinding.getInterfaces(); |