Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 409520
Collapse All | Expand All

(-)test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java (+32 lines)
Lines 4-9 Link Here
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and
9
 * is made available for testing and evaluation purposes only.
10
 * The code is not compatible with any specification of the JCP.
7
 *
11
 *
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
Lines 88-93 Link Here
88
	public static final IPath RT_STUBS_15= new Path("testresources/rtstubs15.jar");
92
	public static final IPath RT_STUBS_15= new Path("testresources/rtstubs15.jar");
89
	public static final IPath RT_STUBS_16= new Path("testresources/rtstubs16.jar");
93
	public static final IPath RT_STUBS_16= new Path("testresources/rtstubs16.jar");
90
	public static final IPath RT_STUBS_17= new Path("testresources/rtstubs17.jar");
94
	public static final IPath RT_STUBS_17= new Path("testresources/rtstubs17.jar");
95
96
	public static final IPath RT_STUBS_18= new Path("testresources/rtstubs18.jar");
91
	public static final IPath JUNIT_SRC_381= new Path("testresources/junit381-noUI-src.zip");
97
	public static final IPath JUNIT_SRC_381= new Path("testresources/junit381-noUI-src.zip");
92
	public static final String JUNIT_SRC_ENCODING= "ISO-8859-1";
98
	public static final String JUNIT_SRC_ENCODING= "ISO-8859-1";
93
99
Lines 189-194 Link Here
189
	}
195
	}
190
196
191
	/**
197
	/**
198
	 * Sets the compiler options to 1.8 for the given project.
199
	 * 
200
	 * @param project the java project
201
	 */
202
	public static void set18CompilerOptions(IJavaProject project) {
203
		Map options= project.getOptions(false);
204
		JavaProjectHelper.set18CompilerOptions(options);
205
		project.setOptions(options);
206
	}
207
208
	/**
192
	 * Sets the compiler options to 1.7 for the given project.
209
	 * Sets the compiler options to 1.7 for the given project.
193
	 * @param project the java project
210
	 * @param project the java project
194
	 */
211
	 */
Lines 226-231 Link Here
226
		Map options= project.getOptions(false);
243
		Map options= project.getOptions(false);
227
		JavaProjectHelper.set14CompilerOptions(options);
244
		JavaProjectHelper.set14CompilerOptions(options);
228
		project.setOptions(options);
245
		project.setOptions(options);
246
	}
247
248
	/**
249
	 * Sets the compiler options to 1.8
250
	 * 
251
	 * @param options The compiler options to configure
252
	 */
253
	public static void set18CompilerOptions(Map options) {
254
		JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options);
229
	}
255
	}
230
256
231
	/**
257
	/**
Lines 690-695 Link Here
690
		return addLibrary(jproject, rtJarPath[0], rtJarPath[1], rtJarPath[2]);
716
		return addLibrary(jproject, rtJarPath[0], rtJarPath[1], rtJarPath[2]);
691
	}
717
	}
692
718
719
	public static IPackageFragmentRoot addRTJar18(IJavaProject jproject) throws CoreException {
720
		IPath[] rtJarPath= findRtJar(RT_STUBS_18);
721
		set17CompilerOptions(jproject);
722
		return addLibrary(jproject, rtJarPath[0], rtJarPath[1], rtJarPath[2]);
723
	}
724
693
	/**
725
	/**
694
	 * Adds a variable entry with source attachment to a IJavaProject.
726
	 * Adds a variable entry with source attachment to a IJavaProject.
695
	 * Can return null if variable can not be resolved.
727
	 * Can return null if variable can not be resolved.
(-)ui/org/eclipse/jdt/ui/tests/core/Java18ProjectTestSetup.java (+62 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and
9
 * is made available for testing and evaluation purposes only.
10
 * The code is not compatible with any specification of the JCP.
11
 *
12
 * Contributors:
13
 *     IBM Corporation - initial API and implementation
14
 *******************************************************************************/
15
package org.eclipse.jdt.ui.tests.core;
16
17
import junit.framework.Test;
18
19
import org.eclipse.jdt.testplugin.JavaProjectHelper;
20
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IPath;
23
24
import org.eclipse.core.resources.IProject;
25
import org.eclipse.core.resources.ResourcesPlugin;
26
27
import org.eclipse.jdt.core.IClasspathEntry;
28
import org.eclipse.jdt.core.IJavaProject;
29
import org.eclipse.jdt.core.JavaCore;
30
31
public class Java18ProjectTestSetup extends ProjectTestSetup {
32
33
	public static final String PROJECT_NAME18= "TestSetupProject18";
34
35
	public static IJavaProject getProject() {
36
		IProject project= ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME18);
37
		return JavaCore.create(project);
38
	}
39
40
	public static IClasspathEntry[] getDefaultClasspath() throws CoreException {
41
		IPath[] rtJarPath= JavaProjectHelper.findRtJar(JavaProjectHelper.RT_STUBS_18);
42
		return new IClasspathEntry[] { JavaCore.newLibraryEntry(rtJarPath[0], rtJarPath[1], rtJarPath[2], true) };
43
	}
44
45
	public Java18ProjectTestSetup(Test test) {
46
		super(test);
47
	}
48
49
	@Override
50
	protected boolean projectExists() {
51
		return getProject().exists();
52
	}
53
54
	@Override
55
	protected IJavaProject createAndInitializeProject() throws CoreException {
56
		IJavaProject javaProject= JavaProjectHelper.createJavaProject(PROJECT_NAME18, "bin");
57
		javaProject.setRawClasspath(getDefaultClasspath(), null);
58
		JavaProjectHelper.set18CompilerOptions(javaProject);
59
		return javaProject;
60
	}
61
62
}
(-)ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest18.java (+199 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and
9
 * is made available for testing and evaluation purposes only.
10
 * The code is not compatible with any specification of the JCP.
11
 * 
12
 * Contributors:
13
 *     IBM Corporation - initial API and implementation
14
 *******************************************************************************/
15
package org.eclipse.jdt.ui.tests.quickfix;
16
17
import java.util.ArrayList;
18
import java.util.Hashtable;
19
20
import junit.framework.Test;
21
import junit.framework.TestSuite;
22
23
import org.eclipse.jdt.testplugin.JavaProjectHelper;
24
import org.eclipse.jdt.testplugin.TestOptions;
25
26
import org.eclipse.jface.preference.IPreferenceStore;
27
28
import org.eclipse.jdt.core.ICompilationUnit;
29
import org.eclipse.jdt.core.IJavaProject;
30
import org.eclipse.jdt.core.IPackageFragment;
31
import org.eclipse.jdt.core.IPackageFragmentRoot;
32
import org.eclipse.jdt.core.JavaCore;
33
import org.eclipse.jdt.core.dom.CompilationUnit;
34
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
35
36
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
37
import org.eclipse.jdt.internal.corext.template.java.CodeTemplateContextType;
38
39
import org.eclipse.jdt.ui.PreferenceConstants;
40
import org.eclipse.jdt.ui.tests.core.Java18ProjectTestSetup;
41
import org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal;
42
43
import org.eclipse.jdt.internal.ui.JavaPlugin;
44
45
public class QuickFixTest18 extends QuickFixTest {
46
47
	private static final Class THIS= QuickFixTest18.class;
48
49
	private IJavaProject fJProject1;
50
51
	private IPackageFragmentRoot fSourceFolder;
52
53
	public QuickFixTest18(String name) {
54
		super(name);
55
	}
56
57
	public static Test suite() {
58
		return new Java18ProjectTestSetup(new TestSuite(THIS));
59
	}
60
61
	public static Test setUpTest(Test test) {
62
		return new Java18ProjectTestSetup(test);
63
	}
64
65
	@Override
66
	protected void setUp() throws Exception {
67
		Hashtable options= TestOptions.getDefaultOptions();
68
		options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
69
		options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4");
70
		options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE, JavaCore.DO_NOT_INSERT);
71
72
73
		JavaCore.setOptions(options);
74
75
		IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore();
76
		store.setValue(PreferenceConstants.CODEGEN_ADD_COMMENTS, false);
77
78
		fJProject1= Java18ProjectTestSetup.getProject();
79
80
		StubUtility.setCodeTemplate(CodeTemplateContextType.METHODSTUB_ID, "", null);
81
		StubUtility.setCodeTemplate(CodeTemplateContextType.CONSTRUCTORSTUB_ID, "", null);
82
83
		fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
84
	}
85
86
87
	@Override
88
	protected void tearDown() throws Exception {
89
		JavaProjectHelper.clear(fJProject1, Java18ProjectTestSetup.getDefaultClasspath());
90
	}
91
92
	public void testUnimplementedMethods() throws Exception {
93
		IPackageFragment pack2= fSourceFolder.createPackageFragment("test2", false, null);
94
		StringBuffer buf= new StringBuffer();
95
		buf.append("package test2;\n");
96
		buf.append("import java.io.IOException;\n");
97
		buf.append("public interface Inter {\n");
98
		buf.append("    int getCount(Object[] o) throws IOException;\n");
99
		buf.append("    static int staticMethod(Object[] o) throws IOException{return 10;}\n");
100
		buf.append("    default int defaultMethod(Object[] o) throws IOException{return 20;}\n");
101
		buf.append("}\n");
102
		pack2.createCompilationUnit("Inter.java", buf.toString(), false, null);
103
104
105
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
106
		buf= new StringBuffer();
107
		buf.append("package test1;\n");
108
		buf.append("import test2.Inter;\n");
109
		buf.append("public class E implements Inter{\n");
110
		buf.append("}\n");
111
		ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
112
113
		CompilationUnit astRoot= getASTRoot(cu);
114
		ArrayList proposals= collectCorrections(cu, astRoot);
115
		assertNumberOfProposals(proposals, 2);
116
		assertCorrectLabels(proposals);
117
118
		CUCorrectionProposal proposal= (CUCorrectionProposal)proposals.get(1);
119
		String preview1= getPreviewContent(proposal);
120
121
		buf= new StringBuffer();
122
		buf.append("package test1;\n");
123
		buf.append("import test2.Inter;\n");
124
		buf.append("public abstract class E implements Inter{\n");
125
		buf.append("}\n");
126
		String expected1= buf.toString();
127
128
		proposal= (CUCorrectionProposal)proposals.get(0);
129
		String preview2= getPreviewContent(proposal);
130
131
		buf= new StringBuffer();
132
		buf.append("package test1;\n");
133
		buf.append("import java.io.IOException;\n");
134
		buf.append("\n");
135
		buf.append("import test2.Inter;\n");
136
		buf.append("public class E implements Inter{\n");
137
		buf.append("\n");
138
		buf.append("    @Override\n");
139
		buf.append("    public int getCount(Object[] o) throws IOException {\n");
140
		buf.append("        return 0;\n");
141
		buf.append("    }\n");
142
		buf.append("}\n");
143
		String expected2= buf.toString();
144
145
		assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 });
146
147
	}
148
149
	public void testUnimplementedMethods2() throws Exception {
150
		StringBuffer buf= new StringBuffer();
151
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
152
		buf= new StringBuffer();
153
		buf.append("package test1;\n");
154
		buf.append("public class MyString implements CharSequence{\n");
155
		buf.append("}\n");
156
		ICompilationUnit cu= pack1.createCompilationUnit("MyString.java", buf.toString(), false, null);
157
158
		CompilationUnit astRoot= getASTRoot(cu);
159
		ArrayList proposals= collectCorrections(cu, astRoot, 3);
160
		assertNumberOfProposals(proposals, 2);
161
		assertCorrectLabels(proposals);
162
163
		CUCorrectionProposal proposal= (CUCorrectionProposal)proposals.get(1);
164
		String preview1= getPreviewContent(proposal);
165
166
		buf= new StringBuffer();
167
		buf.append("package test1;\n");
168
		buf.append("public abstract class MyString implements CharSequence{\n");
169
		buf.append("}\n");
170
		String expected1= buf.toString();
171
172
		proposal= (CUCorrectionProposal)proposals.get(0);
173
		String preview2= getPreviewContent(proposal);
174
175
		buf= new StringBuffer();
176
		buf.append("package test1;\n");
177
		buf.append("public class MyString implements CharSequence{\n");
178
		buf.append("\n");
179
		buf.append("    @Override\n");
180
		buf.append("    public char charAt(int arg0) {\n");
181
		buf.append("        return 0;\n");
182
		buf.append("    }\n\n");
183
		buf.append("    @Override\n");
184
		buf.append("    public int length() {\n");
185
		buf.append("        return 0;\n");
186
		buf.append("    }\n\n");
187
		buf.append("    @Override\n");
188
		buf.append("    public CharSequence subSequence(int arg0, int arg1) {\n");
189
		buf.append("        return null;\n");
190
		buf.append("    }\n");
191
		buf.append("}\n");
192
		String expected2= buf.toString();
193
194
		assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 });
195
196
	}
197
198
199
}
(-)core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2.java (-2 / +9 lines)
Lines 5-10 Link Here
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and
9
 * is made available for testing and evaluation purposes only.
10
 * The code is not compatible with any specification of the JCP.
11
 * 
8
 * Contributors:
12
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
14
 *******************************************************************************/
Lines 547-554 Link Here
547
				if (impl == null || !Bindings.isVisibleInHierarchy(impl, currPack)) {
551
				if (impl == null || !Bindings.isVisibleInHierarchy(impl, currPack)) {
548
					if (impl != null)
552
					if (impl != null)
549
						allMethods.remove(impl);
553
						allMethods.remove(impl);
550
					toImplement.add(curr);
554
					// static and default methods need not be considered.
551
					allMethods.add(curr);
555
					if (Modifier.isAbstract(curr.getModifiers())) {
556
						toImplement.add(curr);
557
						allMethods.add(curr);
558
					}
552
				}
559
				}
553
			}
560
			}
554
			ITypeBinding[] superInterfaces= typeBinding.getInterfaces();
561
			ITypeBinding[] superInterfaces= typeBinding.getInterfaces();

Return to bug 409520