Java Code Examples for org.eclipse.jdt.internal.core.util.Util#verbose()

The following examples show how to use org.eclipse.jdt.internal.core.util.Util#verbose() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SaveIndex.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean execute(IProgressMonitor progressMonitor) {

		if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true;

		/* ensure no concurrent write access to index */
		Index index = this.manager.getIndex(this.containerPath, true /*reuse index file*/, false /*don't create if none*/);
		if (index == null) return true;
		ReadWriteMonitor monitor = index.monitor;
		if (monitor == null) return true; // index got deleted since acquired

		try {
			monitor.enterWrite(); // ask permission to write
			this.manager.saveIndex(index);
		} catch (IOException e) {
			if (JobManager.VERBOSE) {
				Util.verbose("-> failed to save index " + this.containerPath + " because of the following exception:", System.err); //$NON-NLS-1$ //$NON-NLS-2$
				e.printStackTrace();
			}
			return false;
		} finally {
			monitor.exitWrite(); // free write lock
		}
		return true;
	}
 
Example 2
Source File: IndexManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Recreates the index for a given path, keeping the same read-write monitor.
 * Returns the new empty index or null if it didn't exist before.
 * Warning: Does not check whether index is consistent (not being used)
 */
public synchronized Index recreateIndex(IPath containerPath) {
	// only called to over write an existing cached index...
	String containerPathString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
	try {
		// Path is already canonical
		IndexLocation indexLocation = computeIndexLocation(containerPath);
		Index index = getIndex(indexLocation);
		ReadWriteMonitor monitor = index == null ? null : index.monitor;

		if (VERBOSE)
			Util.verbose("-> recreating index: "+indexLocation+" for path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$
		index = new Index(indexLocation, containerPathString, false /*do not reuse index file*/);
		this.indexes.put(indexLocation, index);
		index.monitor = monitor;
		return index;
	} catch (IOException e) {
		// The file could not be created. Possible reason: the project has been deleted.
		if (VERBOSE) {
			Util.verbose("-> failed to recreate index for path: "+containerPathString); //$NON-NLS-1$
			e.printStackTrace();
		}
		return null;
	}
}
 
Example 3
Source File: JavaModelManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void verbose_container_value_after_initialization(IJavaProject project, IPath containerPath, IClasspathContainer container) {
	StringBuffer buffer = new StringBuffer();
	buffer.append("CPContainer INIT - after resolution\n"); //$NON-NLS-1$
	buffer.append("	project: " + project.getElementName() + '\n'); //$NON-NLS-1$
	buffer.append("	container path: " + containerPath + '\n'); //$NON-NLS-1$
	if (container != null){
		buffer.append("	container: "+container.getDescription()+" {\n"); //$NON-NLS-2$//$NON-NLS-1$
		IClasspathEntry[] entries = container.getClasspathEntries();
		if (entries != null){
			for (int i = 0; i < entries.length; i++) {
				buffer.append("		" + entries[i] + '\n'); //$NON-NLS-1$
			}
		}
		buffer.append("	}");//$NON-NLS-1$
	} else {
		buffer.append("	container: {unbound}");//$NON-NLS-1$
	}
	Util.verbose(buffer.toString());
}
 
Example 4
Source File: JavaModelManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void verbose_reentering_project_container_access(	IPath containerPath, IJavaProject project, IClasspathContainer previousContainer) {
	StringBuffer buffer = new StringBuffer();
	buffer.append("CPContainer INIT - reentering access to project container during its initialization, will see previous value\n"); //$NON-NLS-1$
	buffer.append("	project: " + project.getElementName() + '\n'); //$NON-NLS-1$
	buffer.append("	container path: " + containerPath + '\n'); //$NON-NLS-1$
	buffer.append("	previous value: "); //$NON-NLS-1$
	buffer.append(previousContainer.getDescription());
	buffer.append(" {\n"); //$NON-NLS-1$
	IClasspathEntry[] entries = previousContainer.getClasspathEntries();
	if (entries != null){
		for (int j = 0; j < entries.length; j++){
			buffer.append(" 		"); //$NON-NLS-1$
			buffer.append(entries[j]);
			buffer.append('\n');
		}
	}
	buffer.append(" 	}"); //$NON-NLS-1$
	Util.verbose(buffer.toString());
	new Exception("<Fake exception>").printStackTrace(System.out); //$NON-NLS-1$
}
 
Example 5
Source File: IndexManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void readParticipantsIndexNamesFile() {
	SimpleLookupTable containers = new SimpleLookupTable(3);
	try {
		char[] participantIndexNames = org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent(this.participantIndexNamesFile, null);
		if (participantIndexNames.length > 0) {
			char[][] names = CharOperation.splitOn('\n', participantIndexNames);
			if (names.length >= 3) {
				// First line is DiskIndex signature  (see writeParticipantsIndexNamesFile())
				if (DiskIndex.SIGNATURE.equals(new String(names[0]))) {					
					for (int i = 1, l = names.length-1 ; i < l ; i+=2) {
						IndexLocation indexLocation = new FileIndexLocation(new File(new String(names[i])), true);
						containers.put(indexLocation, new Path(new String(names[i+1])));
					}
				}				
			}
		}	
	} catch (IOException ignored) {
		if (VERBOSE)
			Util.verbose("Failed to read participant index file names"); //$NON-NLS-1$
	}
	this.participantsContainers = containers;
	return;
}
 
Example 6
Source File: IndexManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private SimpleLookupTable getIndexStates() {
	if (this.indexStates != null) return this.indexStates;

	this.indexStates = new SimpleLookupTable();
	File indexesDirectoryPath = getSavedIndexesDirectory();
	char[][] savedNames = readIndexState(getJavaPluginWorkingLocation().toOSString());
	if (savedNames != null) {
		for (int i = 1, l = savedNames.length; i < l; i++) { // first name is saved signature, see readIndexState()
			char[] savedName = savedNames[i];
			if (savedName.length > 0) {
				IndexLocation indexLocation = new FileIndexLocation(new File(indexesDirectoryPath, String.valueOf(savedName))); // shares indexesDirectoryPath's segments
				if (VERBOSE)
					Util.verbose("Reading saved index file " + indexLocation); //$NON-NLS-1$
				this.indexStates.put(indexLocation, SAVED_STATE);
			}
		}
	} else {
		// All the index files are getting deleted and hence there is no need to 
		// further check for change in javaLikeNames. 
		writeJavaLikeNamesFile();
		this.javaLikeNamesChanged = false;
		deleteIndexFiles();
	}
	readIndexMap();
	return this.indexStates;
}
 
Example 7
Source File: IndexManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void saveIndex(Index index) throws IOException {
	// must have permission to write from the write monitor
	if (index.hasChanged()) {
		if (VERBOSE)
			Util.verbose("-> saving index " + index.getIndexLocation()); //$NON-NLS-1$
		index.save();
	}
	synchronized (this) {
		IPath containerPath = new Path(index.containerPath);
		if (this.jobEnd > this.jobStart) {
			for (int i = this.jobEnd; i > this.jobStart; i--) { // skip the current job
				IJob job = this.awaitingJobs[i];
				if (job instanceof IndexRequest)
					if (((IndexRequest) job).containerPath.equals(containerPath)) return;
			}
		}
		IndexLocation indexLocation = computeIndexLocation(containerPath);
		updateIndexState(indexLocation, SAVED_STATE);
	}
}
 
Example 8
Source File: JavaModelManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void verbose_container_null_failure_container(IJavaProject project, IPath containerPath,  ClasspathContainerInitializer initializer) {
	Util.verbose(
		"CPContainer INIT - FAILED (and failure container is null)\n" + //$NON-NLS-1$
		"	project: " + project.getElementName() + '\n' + //$NON-NLS-1$
		"	container path: " + containerPath + '\n' + //$NON-NLS-1$
		"	initializer: " + initializer); //$NON-NLS-1$
}
 
Example 9
Source File: IndexManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Removes the index for a given path.
 * This is a no-op if the index did not exist.
 */
public synchronized void removeIndex(IPath containerPath) {
	if (VERBOSE || DEBUG)
		Util.verbose("removing index " + containerPath); //$NON-NLS-1$
	IndexLocation indexLocation = computeIndexLocation(containerPath);
	Index index = getIndex(indexLocation);
	File indexFile = null;
	if (index != null) {
		index.monitor = null;
		indexFile = index.getIndexFile();
	}
	if (indexFile == null)
		indexFile = indexLocation.getIndexFile(); // index is not cached yet, but still want to delete the file
	if (this.indexStates.get(indexLocation) == REUSE_STATE) {
		indexLocation.close();
		this.indexLocations.put(containerPath, null);
	} else if (indexFile != null && indexFile.exists()) {
		if (DEBUG)
			Util.verbose("removing index file " + indexFile); //$NON-NLS-1$
		indexFile.delete();
	}
	this.indexes.removeKey(indexLocation);
	if (IS_MANAGING_PRODUCT_INDEXES_PROPERTY) {
		this.indexLocations.removeKey(containerPath);
	}
	updateIndexState(indexLocation, null);
}
 
Example 10
Source File: JavaModelManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void verbose_reentering_variable_access(String variableName, IPath previousPath) {
	Util.verbose(
		"CPVariable INIT - reentering access to variable during its initialization, will see previous value\n" + //$NON-NLS-1$
		"	variable: "+ variableName + '\n' + //$NON-NLS-1$
		"	previous value: " + previousPath); //$NON-NLS-1$
	new Exception("<Fake exception>").printStackTrace(System.out); //$NON-NLS-1$
}
 
Example 11
Source File: JavaModelManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Remove from secondary types cache all types belonging to a given file.
 * Clean secondary types cache built while indexing if requested.
 *
 * Project's secondary types cache is found using file location.
 *
 * @param file File to remove
 */
public void secondaryTypesRemoving(IFile file, boolean cleanIndexCache) {
	if (VERBOSE) {
		StringBuffer buffer = new StringBuffer("JavaModelManager.removeFromSecondaryTypesCache("); //$NON-NLS-1$
		buffer.append(file.getName());
		buffer.append(')');
		Util.verbose(buffer.toString());
	}
	if (file != null) {
		PerProjectInfo projectInfo = getPerProjectInfo(file.getProject(), false);
		if (projectInfo != null && projectInfo.secondaryTypes != null) {
			if (VERBOSE) {
				Util.verbose("-> remove file from cache of project: "+file.getProject().getName()); //$NON-NLS-1$
			}

			// Clean current cache
			secondaryTypesRemoving(projectInfo.secondaryTypes, file);

			// Clean indexing cache if necessary
			HashMap indexingCache = (HashMap) projectInfo.secondaryTypes.get(INDEXED_SECONDARY_TYPES);
			if (!cleanIndexCache) {
				if (indexingCache == null) {
					// Need to signify that secondary types indexing will happen before any request happens
					// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=152841
					projectInfo.secondaryTypes.put(INDEXED_SECONDARY_TYPES, new HashMap());
				}
				return;
			}
			if (indexingCache != null) {
				Set keys = indexingCache.keySet();
				int filesSize = keys.size(), filesCount = 0;
				IFile[] removed = null;
				Iterator cachedFiles = keys.iterator();
				while (cachedFiles.hasNext()) {
					IFile cachedFile = (IFile) cachedFiles.next();
					if (file.equals(cachedFile)) {
						if (removed == null) removed = new IFile[filesSize];
						filesSize--;
						removed[filesCount++] = cachedFile;
					}
				}
				if (removed != null) {
					for (int i=0; i<filesCount; i++) {
						indexingCache.remove(removed[i]);
					}
				}
			}
		}
	}
}
 
Example 12
Source File: SetVariablesOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void verbose_set_variables() {
	Util.verbose(
		"CPVariable SET  - setting variables\n" + //$NON-NLS-1$
		"	variables: " + org.eclipse.jdt.internal.compiler.util.Util.toString(this.variableNames) + '\n' +//$NON-NLS-1$
		"	values: " + org.eclipse.jdt.internal.compiler.util.Util.toString(this.variablePaths)); //$NON-NLS-1$
}
 
Example 13
Source File: IndexManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Removes all indexes whose paths start with (or are equal to) the given path.
 */
public synchronized void removeIndexPath(IPath path) {
	if (VERBOSE || DEBUG)
		Util.verbose("removing index path " + path); //$NON-NLS-1$
	Object[] keyTable = this.indexes.keyTable;
	Object[] valueTable = this.indexes.valueTable;
	IndexLocation[] locations = null;
	int max = this.indexes.elementSize;
	int count = 0;
	for (int i = 0, l = keyTable.length; i < l; i++) {
		IndexLocation indexLocation = (IndexLocation) keyTable[i];
		if (indexLocation == null)
			continue;
		if (indexLocation.startsWith(path)) {
			Index index = (Index) valueTable[i];
			index.monitor = null;
			if (locations == null)
				locations = new IndexLocation[max];
			locations[count++] = indexLocation;
			if (this.indexStates.get(indexLocation) == REUSE_STATE) {
				indexLocation.close();
			} else {
				if (DEBUG)
					Util.verbose("removing index file " + indexLocation); //$NON-NLS-1$
				indexLocation.delete();
			}
		} else {
			max--;
		}
	}
	if (locations != null) {
		for (int i = 0; i < count; i++)
			this.indexes.removeKey(locations[i]);
		removeIndexesState(locations);
		if (this.participantsContainers != null) {
			boolean update = false;
			for (int i = 0; i < count; i++) {
				if (this.participantsContainers.get(locations[i]) != null) {
					update = true;
					this.participantsContainers.removeKey(locations[i]);
				}
			}
			if (update) writeParticipantsIndexNamesFile();
		}
	}
}
 
Example 14
Source File: BasicSearchEngine.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void searchDeclarations(IJavaElement enclosingElement, SearchRequestor requestor, SearchPattern pattern, IProgressMonitor monitor) throws JavaModelException {
	if (VERBOSE) {
		Util.verbose("	- java element: "+enclosingElement); //$NON-NLS-1$
	}
	IJavaSearchScope scope = createJavaSearchScope(new IJavaElement[] {enclosingElement});
	IResource resource = ((JavaElement) enclosingElement).resource();
	if (enclosingElement instanceof IMember) {
		IMember member = (IMember) enclosingElement;
		ICompilationUnit cu = member.getCompilationUnit();
		if (cu != null) {
			resource = cu.getResource();
		} else if (member.isBinary()) {
			// binary member resource cannot be used as this
			// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=148215
			resource = null;
		}
	}
	try {
		if (resource instanceof IFile) {
			try {
				requestor.beginReporting();
				if (VERBOSE) {
					Util.verbose("Searching for " + pattern + " in " + resource.getFullPath()); //$NON-NLS-1$//$NON-NLS-2$
				}
				SearchParticipant participant = getDefaultSearchParticipant();
				SearchDocument[] documents = MatchLocator.addWorkingCopies(
					pattern,
					new SearchDocument[] {new JavaSearchDocument(enclosingElement.getPath().toString(), participant)},
					getWorkingCopies(enclosingElement),
					participant);
				participant.locateMatches(
					documents,
					pattern,
					scope,
					requestor,
					monitor);
			} finally {
				requestor.endReporting();
			}
		} else {
			search(
				pattern,
				new SearchParticipant[] {getDefaultSearchParticipant()},
				scope,
				requestor,
				monitor);
		}
	} catch (CoreException e) {
		if (e instanceof JavaModelException)
			throw (JavaModelException) e;
		throw new JavaModelException(e);
	}
}
 
Example 15
Source File: UserLibraryClasspathContainer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void verbose_no_user_library_found(String userLibraryName) {
	Util.verbose(
		"UserLibrary INIT - FAILED (no user library found)\n" + //$NON-NLS-1$
		"	userLibraryName: " + userLibraryName); //$NON-NLS-1$
}
 
Example 16
Source File: SetContainerOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void verbose_set_container_invocation_trace() {
	Util.verbose(
		"CPContainer SET  - setting container\n" + //$NON-NLS-1$
		"	invocation stack trace:"); //$NON-NLS-1$
		new Exception("<Fake exception>").printStackTrace(System.out); //$NON-NLS-1$
}
 
Example 17
Source File: UserLibraryClasspathContainerInitializer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void verbose_not_a_user_library(IJavaProject project, IPath containerPath) {
	Util.verbose(
		"UserLibrary INIT - FAILED (not a user library)\n" + //$NON-NLS-1$
		"	project: " + project.getElementName() + '\n' + //$NON-NLS-1$
		"	container path: " + containerPath); //$NON-NLS-1$
}
 
Example 18
Source File: UserLibraryClasspathContainerInitializer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void verbose_no_user_library_found(IJavaProject project, String userLibraryName) {
	Util.verbose(
		"UserLibrary INIT - FAILED (no user library found)\n" + //$NON-NLS-1$
		"	project: " + project.getElementName() + '\n' + //$NON-NLS-1$
		"	userLibraryName: " + userLibraryName); //$NON-NLS-1$
}
 
Example 19
Source File: JavaModelManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void verbose_triggering_container_initialization_invocation_trace() {
	Util.verbose(
		"CPContainer INIT - triggering initialization\n" + //$NON-NLS-1$
		"	invocation trace:"); //$NON-NLS-1$
	new Exception("<Fake exception>").printStackTrace(System.out); //$NON-NLS-1$
}
 
Example 20
Source File: JavaModelManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void verbose_no_container_initializer_found(IJavaProject project, IPath containerPath) {
	Util.verbose(
		"CPContainer INIT - no initializer found\n" + //$NON-NLS-1$
		"	project: " + project.getElementName() + '\n' + //$NON-NLS-1$
		"	container path: " + containerPath); //$NON-NLS-1$
}