View | Details | Raw Unified | Return to bug 308428
Collapse All | Expand All

(-)model/org/eclipse/jdt/core/CorrectionEngine.java (-2 / +15 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
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
Lines 235-241 Link Here
235
	private void correct(char[] argument) {
235
	private void correct(char[] argument) {
236
		try {
236
		try {
237
			String source = this.compilationUnit.getSource();
237
			String source = this.compilationUnit.getSource();
238
			Scanner scanner = new Scanner();
238
			Map currentProjectOptions = this.compilationUnit.getJavaProject().getOptions(true);
239
			long sourceLevel = CompilerOptions.versionToJdkLevel(currentProjectOptions.get(JavaCore.COMPILER_SOURCE));
240
			long complianceLevel = CompilerOptions.versionToJdkLevel(currentProjectOptions.get(JavaCore.COMPILER_COMPLIANCE));
241
			
242
			Scanner scanner =
243
				new Scanner(
244
					false /*comment*/,
245
					false /*whitespace*/,
246
					false /*nls*/,
247
					sourceLevel,
248
					complianceLevel,
249
					null/*taskTag*/,
250
					null/*taskPriorities*/,
251
					true /*taskCaseSensitive*/);
239
			scanner.setSource(source.toCharArray());
252
			scanner.setSource(source.toCharArray());
240
253
241
			scanner.resetTo(this.correctionStart, this.correctionEnd);
254
			scanner.resetTo(this.correctionStart, this.correctionEnd);
(-)src/org/eclipse/jdt/core/tests/model/CodeCorrectionTests.java (-7 / +44 lines)
Lines 10-23 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.model;
11
package org.eclipse.jdt.core.tests.model;
12
12
13
import junit.framework.*;
13
import junit.framework.Test;
14
14
15
import org.eclipse.core.resources.*;
15
import org.eclipse.core.resources.IMarker;
16
import org.eclipse.core.runtime.*;
16
import org.eclipse.core.resources.IResource;
17
import org.eclipse.jdt.core.*;
17
import org.eclipse.core.resources.IncrementalProjectBuilder;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.jdt.core.CorrectionEngine;
20
import org.eclipse.jdt.core.ICompilationUnit;
21
import org.eclipse.jdt.core.IJavaElement;
22
import org.eclipse.jdt.core.IJavaModelMarker;
23
import org.eclipse.jdt.core.IJavaProject;
24
import org.eclipse.jdt.core.JavaCore;
25
import org.eclipse.jdt.core.JavaModelException;
18
import org.eclipse.jdt.core.compiler.IProblem;
26
import org.eclipse.jdt.core.compiler.IProblem;
19
import org.eclipse.jdt.core.search.*;
27
import org.eclipse.jdt.core.search.IJavaSearchConstants;
20
28
import org.eclipse.jdt.core.search.IJavaSearchScope;
29
import org.eclipse.jdt.core.search.SearchEngine;
30
import org.eclipse.jdt.core.search.SearchPattern;
31
import org.eclipse.jdt.core.search.TypeNameRequestor;
21
32
22
public class CodeCorrectionTests extends AbstractJavaModelTests {
33
public class CodeCorrectionTests extends AbstractJavaModelTests {
23
	public static boolean DEBUG = false;
34
	public static boolean DEBUG = false;
Lines 54-60 Link Here
54
public void setUpSuite() throws Exception {
65
public void setUpSuite() throws Exception {
55
	super.setUpSuite();
66
	super.setUpSuite();
56
67
57
	IJavaProject project = setUpJavaProject("CodeCorrection");
68
	IJavaProject project = setUpJavaProject("CodeCorrection", "1.5");
58
69
59
	// dummy query for waiting until the indexes are ready
70
	// dummy query for waiting until the indexes are ready
60
	SearchEngine engine = new SearchEngine();
71
	SearchEngine engine = new SearchEngine();
Lines 659-664 Link Here
659
		""+end,
670
		""+end,
660
		requestor.getEnds());
671
		requestor.getEnds());
661
}
672
}
673
public void testCorrectLocalVariable2() throws JavaModelException {
674
	CorrectionEngine engine = new CorrectionEngine(JavaCore.getOptions());
675
	CodeCorrectionTestsRequestor requestor = new CodeCorrectionTestsRequestor();
676
	ICompilationUnit cu= getCompilationUnit("CodeCorrection", "src", "", "CorrectLocalVariable2.java");
677
	IMarker[] markers = getMarkers(cu);
678
	assertTrue("should have one problem",markers.length == 1);
679
	engine.computeCorrections(markers[0], null, 0, requestor);
680
681
	String src = cu.getSource();
682
	String error = "ba\\ud842\\udf9fr";
683
	int start = src.lastIndexOf(error);
684
	int end = start + error.length();
685
686
	assertEquals(
687
		"should have one suggestion",
688
		"ba\ud842\udf9fr0",
689
		requestor.getSuggestions());
690
	assertEquals(
691
		"a start of a suggestion is not correct",
692
		""+start,
693
		requestor.getStarts());
694
	assertEquals(
695
		"a end of a suggestion is not correct",
696
		""+end,
697
		requestor.getEnds());
698
}
662
public void testCorrectArgument1() throws JavaModelException {
699
public void testCorrectArgument1() throws JavaModelException {
663
	CorrectionEngine engine = new CorrectionEngine(JavaCore.getOptions());
700
	CorrectionEngine engine = new CorrectionEngine(JavaCore.getOptions());
664
	CodeCorrectionTestsRequestor requestor = new CodeCorrectionTestsRequestor();
701
	CodeCorrectionTestsRequestor requestor = new CodeCorrectionTestsRequestor();
(-)workspace/CodeCorrection/src/CorrectLocalVariable2.java (+6 lines)
Added Link Here
1
public class CorrectLocalVariable2 {
2
	void foo(){
3
		int ba\ud842\udf9fr0;
4
		ba\ud842\udf9fr = 5;
5
	}
6
}

Return to bug 308428