View | Details | Raw Unified | Return to bug 98378 | Differences between
and this patch

Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java (-8 / +16 lines)
Lines 133-139 Link Here
133
						if ((includeMask & APPLICATION_LIBRARIES) != 0) {
133
						if ((includeMask & APPLICATION_LIBRARIES) != 0) {
134
							IPath path = entry.getPath();
134
							IPath path = entry.getPath();
135
							if (pathToAdd == null || pathToAdd.equals(path)) {
135
							if (pathToAdd == null || pathToAdd.equals(path)) {
136
								add("", path.toString(), true, access); //$NON-NLS-1$
136
								String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
137
								add("", pathToString, true, access); //$NON-NLS-1$
137
								addEnclosingProjectOrJar(path);
138
								addEnclosingProjectOrJar(path);
138
							}
139
							}
139
						}
140
						}
Lines 145-151 Link Here
145
								|| (includeMask & SYSTEM_LIBRARIES) != 0) {
146
								|| (includeMask & SYSTEM_LIBRARIES) != 0) {
146
							IPath path = entry.getPath();
147
							IPath path = entry.getPath();
147
							if (pathToAdd == null || pathToAdd.equals(path)) {
148
							if (pathToAdd == null || pathToAdd.equals(path)) {
148
								add("", path.toString(), true, access); //$NON-NLS-1$
149
								String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
150
								add("", pathToString, true, access); //$NON-NLS-1$
149
								addEnclosingProjectOrJar(path);
151
								addEnclosingProjectOrJar(path);
150
							}
152
							}
151
						}
153
						}
Lines 178-183 Link Here
178
 */
180
 */
179
public void add(IJavaElement element) throws JavaModelException {
181
public void add(IJavaElement element) throws JavaModelException {
180
	IPath containerPath = null;
182
	IPath containerPath = null;
183
	String containerPathToString = null;
181
	int includeMask = SOURCES | APPLICATION_LIBRARIES | SYSTEM_LIBRARIES;
184
	int includeMask = SOURCES | APPLICATION_LIBRARIES | SYSTEM_LIBRARIES;
182
	switch (element.getElementType()) {
185
	switch (element.getElementType()) {
183
		case IJavaElement.JAVA_MODEL:
186
		case IJavaElement.JAVA_MODEL:
Lines 190-201 Link Here
190
			IPackageFragmentRoot root = (IPackageFragmentRoot)element;
193
			IPackageFragmentRoot root = (IPackageFragmentRoot)element;
191
			IPath rootPath = root.getPath();
194
			IPath rootPath = root.getPath();
192
			containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath;
195
			containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath;
196
			containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
193
			IResource rootResource = root.getResource();
197
			IResource rootResource = root.getResource();
194
			if (rootResource != null && rootResource.isAccessible()) {
198
			if (rootResource != null && rootResource.isAccessible()) {
195
				String relativePath = Util.relativePath(rootResource.getFullPath(), containerPath.segmentCount());
199
				String relativePath = Util.relativePath(rootResource.getFullPath(), containerPath.segmentCount());
196
				add(relativePath, containerPath.toString(), true, null);
200
				add(relativePath, containerPathToString, true, null);
197
			} else {
201
			} else {
198
				add("", containerPath.toString(), true, null); //$NON-NLS-1$
202
				add("", containerPathToString, true, null); //$NON-NLS-1$
199
			}
203
			}
200
			break;
204
			break;
201
		case IJavaElement.PACKAGE_FRAGMENT:
205
		case IJavaElement.PACKAGE_FRAGMENT:
Lines 203-215 Link Here
203
			if (root.isArchive()) {
207
			if (root.isArchive()) {
204
				String relativePath = Util.concatWith(((PackageFragment) element).names, '/');
208
				String relativePath = Util.concatWith(((PackageFragment) element).names, '/');
205
				containerPath = root.getPath();
209
				containerPath = root.getPath();
206
				add(relativePath, containerPath.toString(), false, null);
210
				containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
211
				add(relativePath, containerPathToString, false, null);
207
			} else {
212
			} else {
208
				IResource resource = element.getResource();
213
				IResource resource = element.getResource();
209
				if (resource != null && resource.isAccessible()) {
214
				if (resource != null && resource.isAccessible()) {
210
					containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.getPath();
215
					containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.getPath();
216
					containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
211
					String relativePath = Util.relativePath(resource.getFullPath(), containerPath.segmentCount());
217
					String relativePath = Util.relativePath(resource.getFullPath(), containerPath.segmentCount());
212
					add(relativePath, containerPath.toString(), false, null);
218
					add(relativePath, containerPathToString, false, null);
213
				}
219
				}
214
			}
220
			}
215
			break;
221
			break;
Lines 230-236 Link Here
230
				containerPath = root.getPath();
236
				containerPath = root.getPath();
231
				relativePath = getPath(element, true/*relative path*/).toString();
237
				relativePath = getPath(element, true/*relative path*/).toString();
232
			}
238
			}
233
			add(relativePath, containerPath.toString(), true, null);
239
			containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
240
			add(relativePath, containerPathToString, true, null);
234
	}
241
	}
235
	
242
	
236
	if (containerPath != null)
243
	if (containerPath != null)
Lines 342-349 Link Here
342
	IPackageFragmentRoot root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
349
	IPackageFragmentRoot root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
343
	if (root != null && root.isArchive()) {
350
	if (root != null && root.isArchive()) {
344
		IPath rootPath = root.getPath();
351
		IPath rootPath = root.getPath();
352
		String rootPathToString = rootPath.getDevice() == null ? rootPath.toString() : rootPath.toOSString();
345
		IPath relativePath = getPath(element, true/*relative path*/);
353
		IPath relativePath = getPath(element, true/*relative path*/);
346
		return indexOf(relativePath.toString(), rootPath.toString()) >= 0;
354
		return indexOf(relativePath.toString(), rootPathToString) >= 0;
347
	}
355
	}
348
	return this.indexOf(getPath(element, false/*full path*/).toString(), null) >= 0;
356
	return this.indexOf(getPath(element, false/*full path*/).toString(), null) >= 0;
349
}
357
}
(-)search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java (-8 / +10 lines)
Lines 189-206 Link Here
189
		}
189
		}
190
190
191
		// index isn't cached, consider reusing an existing index file
191
		// index isn't cached, consider reusing an existing index file
192
		String containerPathString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
192
		if (reuseExistingFile) {
193
		if (reuseExistingFile) {
193
			File indexFile = new File(indexLocation);
194
			File indexFile = new File(indexLocation);
194
			if (indexFile.exists()) { // check before creating index so as to avoid creating a new empty index if file is missing
195
			if (indexFile.exists()) { // check before creating index so as to avoid creating a new empty index if file is missing
195
				try {
196
				try {
196
					index = new Index(indexLocation, containerPath.toString(), true /*reuse index file*/); //$NON-NLS-1$
197
					index = new Index(indexLocation, containerPathString, true /*reuse index file*/); //$NON-NLS-1$
197
					indexes.put(indexLocation, index);
198
					indexes.put(indexLocation, index);
198
					return index;
199
					return index;
199
				} catch (IOException e) {
200
				} catch (IOException e) {
200
					// failed to read the existing file or its no longer compatible
201
					// failed to read the existing file or its no longer compatible
201
					if (currentIndexState != REBUILDING_STATE) { // rebuild index if existing file is corrupt, unless the index is already being rebuilt
202
					if (currentIndexState != REBUILDING_STATE) { // rebuild index if existing file is corrupt, unless the index is already being rebuilt
202
						if (VERBOSE)
203
						if (VERBOSE)
203
							Util.verbose("-> cannot reuse existing index: "+indexLocation+" path: "+containerPath.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$
204
							Util.verbose("-> cannot reuse existing index: "+indexLocation+" path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$
204
						rebuildIndex(indexLocation, containerPath);
205
						rebuildIndex(indexLocation, containerPath);
205
						return null;
206
						return null;
206
					} 
207
					} 
Lines 216-228 Link Here
216
		if (createIfMissing) {
217
		if (createIfMissing) {
217
			try {
218
			try {
218
				if (VERBOSE)
219
				if (VERBOSE)
219
					Util.verbose("-> create empty index: "+indexLocation+" path: "+containerPath.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$
220
					Util.verbose("-> create empty index: "+indexLocation+" path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$
220
				index = new Index(indexLocation, containerPath.toString(), false /*do not reuse index file*/); //$NON-NLS-1$
221
				index = new Index(indexLocation, containerPathString, false /*do not reuse index file*/); //$NON-NLS-1$
221
				indexes.put(indexLocation, index);
222
				indexes.put(indexLocation, index);
222
				return index;
223
				return index;
223
			} catch (IOException e) {
224
			} catch (IOException e) {
224
				if (VERBOSE)
225
				if (VERBOSE)
225
					Util.verbose("-> unable to create empty index: "+indexLocation+" path: "+containerPath.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$
226
					Util.verbose("-> unable to create empty index: "+indexLocation+" path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$
226
				// The file could not be created. Possible reason: the project has been deleted.
227
				// The file could not be created. Possible reason: the project has been deleted.
227
				return null;
228
				return null;
228
			}
229
			}
Lines 423-428 Link Here
423
 */
424
 */
424
public synchronized Index recreateIndex(IPath containerPath) {
425
public synchronized Index recreateIndex(IPath containerPath) {
425
	// only called to over write an existing cached index...
426
	// only called to over write an existing cached index...
427
	String containerPathString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
426
	try {
428
	try {
427
		// Path is already canonical
429
		// Path is already canonical
428
		String indexLocation = computeIndexLocation(containerPath);
430
		String indexLocation = computeIndexLocation(containerPath);
Lines 431-445 Link Here
431
		ReadWriteMonitor monitor = index == null ? null : index.monitor;
433
		ReadWriteMonitor monitor = index == null ? null : index.monitor;
432
434
433
		if (VERBOSE)
435
		if (VERBOSE)
434
			Util.verbose("-> recreating index: "+indexLocation+" for path: "+containerPath.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$
436
			Util.verbose("-> recreating index: "+indexLocation+" for path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$
435
		index = new Index(indexLocation, containerPath.toString(), false /*reuse index file*/); //$NON-NLS-1$
437
		index = new Index(indexLocation, containerPathString, false /*reuse index file*/); //$NON-NLS-1$
436
		this.indexes.put(indexLocation, index);
438
		this.indexes.put(indexLocation, index);
437
		index.monitor = monitor;
439
		index.monitor = monitor;
438
		return index;
440
		return index;
439
	} catch (IOException e) {
441
	} catch (IOException e) {
440
		// The file could not be created. Possible reason: the project has been deleted.
442
		// The file could not be created. Possible reason: the project has been deleted.
441
		if (VERBOSE) {
443
		if (VERBOSE) {
442
			Util.verbose("-> failed to recreate index for path: "+containerPath.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$
444
			Util.verbose("-> failed to recreate index for path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$
443
			e.printStackTrace();
445
			e.printStackTrace();
444
		}
446
		}
445
		return null;
447
		return null;
(-)search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java (+14 lines)
Lines 539-550 Link Here
539
 */
539
 */
540
protected IJavaElement createHandle(FieldDeclaration fieldDeclaration, TypeDeclaration typeDeclaration, IJavaElement parent) {
540
protected IJavaElement createHandle(FieldDeclaration fieldDeclaration, TypeDeclaration typeDeclaration, IJavaElement parent) {
541
	if (!(parent instanceof IType)) return parent;
541
	if (!(parent instanceof IType)) return parent;
542
	IType type = (IType) parent;
542
543
543
	switch (fieldDeclaration.getKind()) {
544
	switch (fieldDeclaration.getKind()) {
544
		case AbstractVariableDeclaration.FIELD :
545
		case AbstractVariableDeclaration.FIELD :
545
		case AbstractVariableDeclaration.ENUM_CONSTANT :
546
		case AbstractVariableDeclaration.ENUM_CONSTANT :
546
			return ((IType) parent).getField(new String(fieldDeclaration.name));
547
			return ((IType) parent).getField(new String(fieldDeclaration.name));
547
	}
548
	}
549
	if (type.isBinary()) {
550
		// do not return initializer for binary types
551
		// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=98378
552
		return type;
553
	}
548
	// find occurence count of the given initializer in its type declaration
554
	// find occurence count of the given initializer in its type declaration
549
	int occurrenceCount = 0;
555
	int occurrenceCount = 0;
550
	FieldDeclaration[] fields = typeDeclaration.fields;
556
	FieldDeclaration[] fields = typeDeclaration.fields;
Lines 1904-1909 Link Here
1904
 */
1910
 */
1905
protected void reportMatching(CompilationUnitDeclaration unit, boolean mustResolve) throws CoreException {
1911
protected void reportMatching(CompilationUnitDeclaration unit, boolean mustResolve) throws CoreException {
1906
	MatchingNodeSet nodeSet = this.currentPossibleMatch.nodeSet;
1912
	MatchingNodeSet nodeSet = this.currentPossibleMatch.nodeSet;
1913
	if (BasicSearchEngine.VERBOSE) {
1914
		System.out.println("Report matching: "); //$NON-NLS-1$
1915
		System.out.println("	- node set:\n"+nodeSet); //$NON-NLS-1$
1916
		System.out.println("	- must resolve: "+mustResolve); //$NON-NLS-1$
1917
	}
1907
	boolean locatorMustResolve = this.patternLocator.mustResolve;
1918
	boolean locatorMustResolve = this.patternLocator.mustResolve;
1908
	if (nodeSet.mustResolve) this.patternLocator.mustResolve = true;
1919
	if (nodeSet.mustResolve) this.patternLocator.mustResolve = true;
1909
	if (mustResolve) {
1920
	if (mustResolve) {
Lines 1927-1932 Link Here
1927
			nodeSet.addMatch(node, this.patternLocator.resolveLevel(node));
1938
			nodeSet.addMatch(node, this.patternLocator.resolveLevel(node));
1928
		}
1939
		}
1929
		nodeSet.possibleMatchingNodesSet = new SimpleSet(3);
1940
		nodeSet.possibleMatchingNodesSet = new SimpleSet(3);
1941
		if (BasicSearchEngine.VERBOSE) {
1942
			System.out.println("	- resolved node set:\n"+nodeSet); //$NON-NLS-1$
1943
		}
1930
	} else {
1944
	} else {
1931
		this.unitScope = null;
1945
		this.unitScope = null;
1932
	}
1946
	}

Return to bug 98378