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

(-)codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionOnQualifiedTypeReference.java (-5 / +14 lines)
Lines 25-31 Link Here
25
import org.eclipse.jdt.core.compiler.CharOperation;
25
import org.eclipse.jdt.core.compiler.CharOperation;
26
import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference;
26
import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference;
27
import org.eclipse.jdt.internal.compiler.lookup.Binding;
27
import org.eclipse.jdt.internal.compiler.lookup.Binding;
28
import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
28
import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
29
import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
30
import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding;
29
import org.eclipse.jdt.internal.compiler.lookup.Scope;
31
import org.eclipse.jdt.internal.compiler.lookup.Scope;
30
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
32
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
31
33
Lines 42-52 Link Here
42
	// it can be a package, type or member type
44
	// it can be a package, type or member type
43
	Binding binding = scope.getTypeOrPackage(tokens);
45
	Binding binding = scope.getTypeOrPackage(tokens);
44
	if (!binding.isValidBinding()) {
46
	if (!binding.isValidBinding()) {
45
			// tolerate some error cases
47
		// tolerate some error cases
46
			if (binding.problemId() == ProblemReasons.NotVisible){
48
		if (binding.problemId() == ProblemReasons.NotVisible){
47
				throw new SelectionNodeFound(binding);
49
			throw new SelectionNodeFound(binding);
48
			}
50
		}
49
		scope.problemReporter().invalidType(this, (TypeBinding) binding);
51
		
52
		if (binding instanceof TypeBinding) {
53
			scope.problemReporter().invalidType(this, (TypeBinding) binding);
54
		} else if (binding instanceof PackageBinding) {
55
			ProblemReferenceBinding problemBinding = new ProblemReferenceBinding(((PackageBinding)binding).compoundName, null, binding.problemId());
56
			scope.problemReporter().invalidType(this, problemBinding);
57
		}
58
		
50
		throw new SelectionNodeFound();
59
		throw new SelectionNodeFound();
51
	}
60
	}
52
61
(-)codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionOnSingleTypeReference.java (-1 / +8 lines)
Lines 24-30 Link Here
24
import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference;
24
import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference;
25
import org.eclipse.jdt.internal.compiler.lookup.Binding;
25
import org.eclipse.jdt.internal.compiler.lookup.Binding;
26
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
26
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
27
import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
27
import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
28
import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
29
import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding;
28
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
30
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
29
import org.eclipse.jdt.internal.compiler.lookup.Scope;
31
import org.eclipse.jdt.internal.compiler.lookup.Scope;
30
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
32
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
Lines 40-46 Link Here
40
	// it can be a package, type or member type
42
	// it can be a package, type or member type
41
	Binding binding = scope.getTypeOrPackage(new char[][] {token});
43
	Binding binding = scope.getTypeOrPackage(new char[][] {token});
42
	if (!binding.isValidBinding()) {
44
	if (!binding.isValidBinding()) {
43
		scope.problemReporter().invalidType(this, (TypeBinding) binding);
45
		if (binding instanceof TypeBinding) {
46
			scope.problemReporter().invalidType(this, (TypeBinding) binding);
47
		} else if (binding instanceof PackageBinding) {
48
			ProblemReferenceBinding problemBinding = new ProblemReferenceBinding(((PackageBinding)binding).compoundName, null, binding.problemId());
49
			scope.problemReporter().invalidType(this, problemBinding);
50
		}
44
		throw new SelectionNodeFound();
51
		throw new SelectionNodeFound();
45
	}
52
	}
46
	throw new SelectionNodeFound(binding);
53
	throw new SelectionNodeFound(binding);
(-)src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java (+1 lines)
Lines 86-91 Link Here
86
		
86
		
87
		// Support for "open on" feature tests
87
		// Support for "open on" feature tests
88
		ResolveTests.class,
88
		ResolveTests.class,
89
		ResolveTests2.class,
89
		ResolveTests_1_5.class,
90
		ResolveTests_1_5.class,
90
		SelectionJavadocModelTests.class,
91
		SelectionJavadocModelTests.class,
91
92
(-)src/org/eclipse/jdt/core/tests/model/ResolveTests2.java (+195 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 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
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.model;
12
13
import org.eclipse.jdt.core.*;
14
15
import junit.framework.*;
16
17
public class ResolveTests2 extends ModifyingResourceTests {
18
19
static {
20
//	TESTS_NAMES = new String[] { "testSecondaryTypes" };
21
}
22
public static Test suite() {
23
	return buildModelTestSuite(ResolveTests2.class);
24
}
25
26
public ResolveTests2(String name) {
27
	super(name);
28
}
29
public void setUpSuite() throws Exception {
30
	super.setUpSuite();
31
	
32
	setUpJavaProject("Resolve");
33
}
34
public void tearDownSuite() throws Exception {
35
	deleteProject("Resolve");
36
	
37
	super.tearDownSuite();
38
}
39
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227822
40
public void testBug227822a() throws Exception {
41
	try {
42
		// create P1
43
		this.createJavaProject(
44
			"P1",
45
			new String[]{"src"},
46
			new String[]{},
47
			 "bin");
48
		
49
		this.createFolder("/P1/src/a");
50
		this.createFile(
51
				"/P1/src/a/Test.java",
52
				"package a;\n"+
53
				"public class Test {\n" + 
54
				"  java.lang.Object var;\n"+
55
				"}");
56
		
57
		waitUntilIndexesReady();
58
		
59
		// do code select
60
		ICompilationUnit cu= getCompilationUnit("P1", "src", "a", "Test.java");
61
		
62
		String str = cu.getSource();
63
		
64
		String selection = "java.lang.Object";
65
		int start = str.lastIndexOf(selection);
66
		int length = selection.length();
67
		IJavaElement[] elements = cu.codeSelect(start, length);
68
		
69
		assertElementsEqual(
70
			"Unexpected elements",
71
			"",
72
			elements
73
		);
74
	} finally {
75
		this.deleteProject("P1");
76
	}
77
}
78
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227822
79
public void testBug227822b() throws Exception {
80
	try {
81
		// create P1
82
		this.createJavaProject(
83
			"P1",
84
			new String[]{"src"},
85
			new String[]{},
86
			 "bin");
87
		
88
		this.createFolder("/P1/src/a");
89
		this.createFile(
90
				"/P1/src/a/Test.java",
91
				"package a;\n"+
92
				"public class Test {\n" + 
93
				"  javaz.lang.Objectz var;\n"+
94
				"}");
95
		
96
		waitUntilIndexesReady();
97
		
98
		// do code select
99
		ICompilationUnit cu= getCompilationUnit("P1", "src", "a", "Test.java");
100
		
101
		String str = cu.getSource();
102
		
103
		String selection = "javaz.lang.Objectz";
104
		int start = str.lastIndexOf(selection);
105
		int length = selection.length();
106
		IJavaElement[] elements = cu.codeSelect(start, length);
107
		
108
		assertElementsEqual(
109
			"Unexpected elements",
110
			"",
111
			elements
112
		);
113
	} finally {
114
		this.deleteProject("P1");
115
	}
116
}
117
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227822
118
public void testBug227822c() throws Exception {
119
	try {
120
		// create P1
121
		this.createJavaProject(
122
			"P1",
123
			new String[]{"src"},
124
			new String[]{},
125
			 "bin");
126
		
127
		this.createFolder("/P1/src/a");
128
		this.createFile(
129
				"/P1/src/a/Test.java",
130
				"package a;\n"+
131
				"public class Test {\n" + 
132
				"  java var;\n"+
133
				"}");
134
		
135
		waitUntilIndexesReady();
136
		
137
		// do code select
138
		ICompilationUnit cu= getCompilationUnit("P1", "src", "a", "Test.java");
139
		
140
		String str = cu.getSource();
141
		
142
		String selection = "java";
143
		int start = str.lastIndexOf(selection);
144
		int length = selection.length();
145
		IJavaElement[] elements = cu.codeSelect(start, length);
146
		
147
		assertElementsEqual(
148
			"Unexpected elements",
149
			"",
150
			elements
151
		);
152
	} finally {
153
		this.deleteProject("P1");
154
	}
155
}
156
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227822
157
public void testBug227822d() throws Exception {
158
	try {
159
		// create P1
160
		this.createJavaProject(
161
			"P1",
162
			new String[]{"src"},
163
			new String[]{},
164
			 "bin");
165
		
166
		this.createFolder("/P1/src/a");
167
		this.createFile(
168
				"/P1/src/a/Test.java",
169
				"package a;\n"+
170
				"public class Test {\n" + 
171
				"  javaz var;\n"+
172
				"}");
173
		
174
		waitUntilIndexesReady();
175
		
176
		// do code select
177
		ICompilationUnit cu= getCompilationUnit("P1", "src", "a", "Test.java");
178
		
179
		String str = cu.getSource();
180
		
181
		String selection = "javaz";
182
		int start = str.lastIndexOf(selection);
183
		int length = selection.length();
184
		IJavaElement[] elements = cu.codeSelect(start, length);
185
		
186
		assertElementsEqual(
187
			"Unexpected elements",
188
			"",
189
			elements
190
		);
191
	} finally {
192
		this.deleteProject("P1");
193
	}
194
}
195
}

Return to bug 227822