Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 232274 Details for
Bug 409520
[1.8][quick fix] "Add unimplemented methods" should not create stubs for default methods
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch with testcases.
eclipse.jdt.ui.patch (text/plain), 14.11 KB, created by
Martin Mathew
on 2013-06-12 05:26:04 EDT
(
hide
)
Description:
Patch with testcases.
Filename:
MIME Type:
Creator:
Martin Mathew
Created:
2013-06-12 05:26:04 EDT
Size:
14.11 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui.tests >diff --git test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java >index 1a7dc73..12f8653 100644 >--- test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java >+++ test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java >@@ -4,6 +4,10 @@ > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at > * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and >+ * is made available for testing and evaluation purposes only. >+ * The code is not compatible with any specification of the JCP. > * > * Contributors: > * IBM Corporation - initial API and implementation >@@ -88,6 +92,8 @@ > public static final IPath RT_STUBS_15= new Path("testresources/rtstubs15.jar"); > public static final IPath RT_STUBS_16= new Path("testresources/rtstubs16.jar"); > public static final IPath RT_STUBS_17= new Path("testresources/rtstubs17.jar"); >+ >+ public static final IPath RT_STUBS_18= new Path("testresources/rtstubs18.jar"); > public static final IPath JUNIT_SRC_381= new Path("testresources/junit381-noUI-src.zip"); > public static final String JUNIT_SRC_ENCODING= "ISO-8859-1"; > >@@ -189,6 +195,17 @@ > } > > /** >+ * Sets the compiler options to 1.8 for the given project. >+ * >+ * @param project the java project >+ */ >+ public static void set18CompilerOptions(IJavaProject project) { >+ Map options= project.getOptions(false); >+ JavaProjectHelper.set18CompilerOptions(options); >+ project.setOptions(options); >+ } >+ >+ /** > * Sets the compiler options to 1.7 for the given project. > * @param project the java project > */ >@@ -226,6 +243,15 @@ > Map options= project.getOptions(false); > JavaProjectHelper.set14CompilerOptions(options); > project.setOptions(options); >+ } >+ >+ /** >+ * Sets the compiler options to 1.8 >+ * >+ * @param options The compiler options to configure >+ */ >+ public static void set18CompilerOptions(Map options) { >+ JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options); > } > > /** >@@ -690,6 +716,12 @@ > return addLibrary(jproject, rtJarPath[0], rtJarPath[1], rtJarPath[2]); > } > >+ public static IPackageFragmentRoot addRTJar18(IJavaProject jproject) throws CoreException { >+ IPath[] rtJarPath= findRtJar(RT_STUBS_18); >+ set17CompilerOptions(jproject); >+ return addLibrary(jproject, rtJarPath[0], rtJarPath[1], rtJarPath[2]); >+ } >+ > /** > * Adds a variable entry with source attachment to a IJavaProject. > * Can return null if variable can not be resolved. >diff --git ui/org/eclipse/jdt/ui/tests/core/Java18ProjectTestSetup.java ui/org/eclipse/jdt/ui/tests/core/Java18ProjectTestSetup.java >new file mode 100644 >index 0000000..b22752c >--- /dev/null >+++ ui/org/eclipse/jdt/ui/tests/core/Java18ProjectTestSetup.java >@@ -0,0 +1,62 @@ >+/******************************************************************************* >+ * Copyright (c) 2013 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and >+ * is made available for testing and evaluation purposes only. >+ * The code is not compatible with any specification of the JCP. >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.ui.tests.core; >+ >+import junit.framework.Test; >+ >+import org.eclipse.jdt.testplugin.JavaProjectHelper; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IPath; >+ >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.ResourcesPlugin; >+ >+import org.eclipse.jdt.core.IClasspathEntry; >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.JavaCore; >+ >+public class Java18ProjectTestSetup extends ProjectTestSetup { >+ >+ public static final String PROJECT_NAME18= "TestSetupProject18"; >+ >+ public static IJavaProject getProject() { >+ IProject project= ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME18); >+ return JavaCore.create(project); >+ } >+ >+ public static IClasspathEntry[] getDefaultClasspath() throws CoreException { >+ IPath[] rtJarPath= JavaProjectHelper.findRtJar(JavaProjectHelper.RT_STUBS_18); >+ return new IClasspathEntry[] { JavaCore.newLibraryEntry(rtJarPath[0], rtJarPath[1], rtJarPath[2], true) }; >+ } >+ >+ public Java18ProjectTestSetup(Test test) { >+ super(test); >+ } >+ >+ @Override >+ protected boolean projectExists() { >+ return getProject().exists(); >+ } >+ >+ @Override >+ protected IJavaProject createAndInitializeProject() throws CoreException { >+ IJavaProject javaProject= JavaProjectHelper.createJavaProject(PROJECT_NAME18, "bin"); >+ javaProject.setRawClasspath(getDefaultClasspath(), null); >+ JavaProjectHelper.set18CompilerOptions(javaProject); >+ return javaProject; >+ } >+ >+} >diff --git ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest18.java ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest18.java >new file mode 100644 >index 0000000..d1c5d34 >--- /dev/null >+++ ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest18.java >@@ -0,0 +1,199 @@ >+/******************************************************************************* >+ * Copyright (c) 2013 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and >+ * is made available for testing and evaluation purposes only. >+ * The code is not compatible with any specification of the JCP. >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.ui.tests.quickfix; >+ >+import java.util.ArrayList; >+import java.util.Hashtable; >+ >+import junit.framework.Test; >+import junit.framework.TestSuite; >+ >+import org.eclipse.jdt.testplugin.JavaProjectHelper; >+import org.eclipse.jdt.testplugin.TestOptions; >+ >+import org.eclipse.jface.preference.IPreferenceStore; >+ >+import org.eclipse.jdt.core.ICompilationUnit; >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.IPackageFragment; >+import org.eclipse.jdt.core.IPackageFragmentRoot; >+import org.eclipse.jdt.core.JavaCore; >+import org.eclipse.jdt.core.dom.CompilationUnit; >+import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; >+ >+import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility; >+import org.eclipse.jdt.internal.corext.template.java.CodeTemplateContextType; >+ >+import org.eclipse.jdt.ui.PreferenceConstants; >+import org.eclipse.jdt.ui.tests.core.Java18ProjectTestSetup; >+import org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal; >+ >+import org.eclipse.jdt.internal.ui.JavaPlugin; >+ >+public class QuickFixTest18 extends QuickFixTest { >+ >+ private static final Class THIS= QuickFixTest18.class; >+ >+ private IJavaProject fJProject1; >+ >+ private IPackageFragmentRoot fSourceFolder; >+ >+ public QuickFixTest18(String name) { >+ super(name); >+ } >+ >+ public static Test suite() { >+ return new Java18ProjectTestSetup(new TestSuite(THIS)); >+ } >+ >+ public static Test setUpTest(Test test) { >+ return new Java18ProjectTestSetup(test); >+ } >+ >+ @Override >+ protected void setUp() throws Exception { >+ Hashtable options= TestOptions.getDefaultOptions(); >+ options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE); >+ options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4"); >+ options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE, JavaCore.DO_NOT_INSERT); >+ >+ >+ JavaCore.setOptions(options); >+ >+ IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore(); >+ store.setValue(PreferenceConstants.CODEGEN_ADD_COMMENTS, false); >+ >+ fJProject1= Java18ProjectTestSetup.getProject(); >+ >+ StubUtility.setCodeTemplate(CodeTemplateContextType.METHODSTUB_ID, "", null); >+ StubUtility.setCodeTemplate(CodeTemplateContextType.CONSTRUCTORSTUB_ID, "", null); >+ >+ fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); >+ } >+ >+ >+ @Override >+ protected void tearDown() throws Exception { >+ JavaProjectHelper.clear(fJProject1, Java18ProjectTestSetup.getDefaultClasspath()); >+ } >+ >+ public void testUnimplementedMethods() throws Exception { >+ IPackageFragment pack2= fSourceFolder.createPackageFragment("test2", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test2;\n"); >+ buf.append("import java.io.IOException;\n"); >+ buf.append("public interface Inter {\n"); >+ buf.append(" int getCount(Object[] o) throws IOException;\n"); >+ buf.append(" static int staticMethod(Object[] o) throws IOException{return 10;}\n"); >+ buf.append(" default int defaultMethod(Object[] o) throws IOException{return 20;}\n"); >+ buf.append("}\n"); >+ pack2.createCompilationUnit("Inter.java", buf.toString(), false, null); >+ >+ >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("import test2.Inter;\n"); >+ buf.append("public class E implements Inter{\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= getASTRoot(cu); >+ ArrayList proposals= collectCorrections(cu, astRoot); >+ assertNumberOfProposals(proposals, 2); >+ assertCorrectLabels(proposals); >+ >+ CUCorrectionProposal proposal= (CUCorrectionProposal)proposals.get(1); >+ String preview1= getPreviewContent(proposal); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("import test2.Inter;\n"); >+ buf.append("public abstract class E implements Inter{\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ proposal= (CUCorrectionProposal)proposals.get(0); >+ String preview2= getPreviewContent(proposal); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("import java.io.IOException;\n"); >+ buf.append("\n"); >+ buf.append("import test2.Inter;\n"); >+ buf.append("public class E implements Inter{\n"); >+ buf.append("\n"); >+ buf.append(" @Override\n"); >+ buf.append(" public int getCount(Object[] o) throws IOException {\n"); >+ buf.append(" return 0;\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected2= buf.toString(); >+ >+ assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 }); >+ >+ } >+ >+ public void testUnimplementedMethods2() throws Exception { >+ StringBuffer buf= new StringBuffer(); >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class MyString implements CharSequence{\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("MyString.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= getASTRoot(cu); >+ ArrayList proposals= collectCorrections(cu, astRoot, 3); >+ assertNumberOfProposals(proposals, 2); >+ assertCorrectLabels(proposals); >+ >+ CUCorrectionProposal proposal= (CUCorrectionProposal)proposals.get(1); >+ String preview1= getPreviewContent(proposal); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public abstract class MyString implements CharSequence{\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ proposal= (CUCorrectionProposal)proposals.get(0); >+ String preview2= getPreviewContent(proposal); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class MyString implements CharSequence{\n"); >+ buf.append("\n"); >+ buf.append(" @Override\n"); >+ buf.append(" public char charAt(int arg0) {\n"); >+ buf.append(" return 0;\n"); >+ buf.append(" }\n\n"); >+ buf.append(" @Override\n"); >+ buf.append(" public int length() {\n"); >+ buf.append(" return 0;\n"); >+ buf.append(" }\n\n"); >+ buf.append(" @Override\n"); >+ buf.append(" public CharSequence subSequence(int arg0, int arg1) {\n"); >+ buf.append(" return null;\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected2= buf.toString(); >+ >+ assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 }); >+ >+ } >+ >+ >+} >#P org.eclipse.jdt.ui >diff --git core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2.java core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2.java >index 5b2be40..58b044d 100644 >--- core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2.java >+++ core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2.java >@@ -5,6 +5,10 @@ > * which accompanies this distribution, and is available at > * http://www.eclipse.org/legal/epl-v10.html > * >+ * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and >+ * is made available for testing and evaluation purposes only. >+ * The code is not compatible with any specification of the JCP. >+ * > * Contributors: > * IBM Corporation - initial API and implementation > *******************************************************************************/ >@@ -547,8 +551,11 @@ > if (impl == null || !Bindings.isVisibleInHierarchy(impl, currPack)) { > if (impl != null) > allMethods.remove(impl); >- toImplement.add(curr); >- allMethods.add(curr); >+ // static and default methods need not be considered. >+ if (Modifier.isAbstract(curr.getModifiers())) { >+ toImplement.add(curr); >+ allMethods.add(curr); >+ } > } > } > ITypeBinding[] superInterfaces= typeBinding.getInterfaces();
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 409520
: 232274