mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-20 15:35:24 +02:00
Position trackers for non-local external files, bug 261912.
This commit is contained in:
parent
251635be7d
commit
fb5c539efc
3 changed files with 106 additions and 26 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
* Copyright (c) 2006, 2009 Wind River Systems, Inc. and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -8,9 +8,10 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.core;
|
package org.eclipse.cdt.core;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
@ -19,16 +20,10 @@ import org.eclipse.core.runtime.IPath;
|
||||||
* An interface to manage the position tracking. It allows for mapping character
|
* An interface to manage the position tracking. It allows for mapping character
|
||||||
* offsets from a file previously stored on disk to the offset in the current document
|
* offsets from a file previously stored on disk to the offset in the current document
|
||||||
* for the file.
|
* for the file.
|
||||||
*
|
|
||||||
* <p> This interface is not intended to be implemented by clients. </p>
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* <strong>EXPERIMENTAL</strong>. This interface has been added as
|
|
||||||
* part of a work in progress. There is no guarantee that this API will
|
|
||||||
* work or that it will remain the same. Please do not use this API without
|
|
||||||
* consulting with the CDT team.
|
|
||||||
* </p>
|
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
|
*
|
||||||
|
* @noextend This interface is not intended to be extended by clients.
|
||||||
|
* @noimplement This interface is not intended to be implemented by clients.
|
||||||
*/
|
*/
|
||||||
public interface IPositionTrackerManager {
|
public interface IPositionTrackerManager {
|
||||||
/**
|
/**
|
||||||
|
@ -61,4 +56,16 @@ public interface IPositionTrackerManager {
|
||||||
* @return the requested position converter or <code>null</code>.
|
* @return the requested position converter or <code>null</code>.
|
||||||
*/
|
*/
|
||||||
public IPositionConverter findPositionConverter(IPath fullPathOrExternalLocation, long timestamp);
|
public IPositionConverter findPositionConverter(IPath fullPathOrExternalLocation, long timestamp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the position tracker suitable for mapping character offsets of the
|
||||||
|
* given external file/timestamp to the current version of it. <p>
|
||||||
|
* The method cannot be used for resources that are part of the workspace.
|
||||||
|
*
|
||||||
|
* @param externalLocation an external location for which the position adapter is requested.
|
||||||
|
* @param timestamp identifies the version of the file stored on disk.
|
||||||
|
* @return the requested position converter or <code>null</code>.
|
||||||
|
* @since 5.1
|
||||||
|
*/
|
||||||
|
public IPositionConverter findPositionConverter(URI externalLocation, long timestamp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core;
|
package org.eclipse.cdt.internal.core;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
@ -25,6 +26,7 @@ import org.eclipse.core.filebuffers.IFileBuffer;
|
||||||
import org.eclipse.core.filebuffers.IFileBufferListener;
|
import org.eclipse.core.filebuffers.IFileBufferListener;
|
||||||
import org.eclipse.core.filebuffers.ITextFileBuffer;
|
import org.eclipse.core.filebuffers.ITextFileBuffer;
|
||||||
import org.eclipse.core.filebuffers.ITextFileBufferManager;
|
import org.eclipse.core.filebuffers.ITextFileBufferManager;
|
||||||
|
import org.eclipse.core.filesystem.URIUtil;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
|
||||||
|
@ -40,10 +42,16 @@ public class PositionTrackerManager implements IPositionTrackerManager, IFileBuf
|
||||||
|
|
||||||
private int fMemoryCounter= 0;
|
private int fMemoryCounter= 0;
|
||||||
private int fInstalled= 0;
|
private int fInstalled= 0;
|
||||||
private HashMap<IPath, PositionTrackerChain> fPositionTrackerMap;
|
/**
|
||||||
|
* as the key in the map we use:
|
||||||
|
* the full path for resources,
|
||||||
|
* the location as path for local non-workspace files,
|
||||||
|
* the location as URI for non-local non-workspace files.
|
||||||
|
*/
|
||||||
|
private HashMap<Object, PositionTrackerChain> fPositionTrackerMap;
|
||||||
|
|
||||||
private PositionTrackerManager() {
|
private PositionTrackerManager() {
|
||||||
fPositionTrackerMap= new HashMap<IPath, PositionTrackerChain>();
|
fPositionTrackerMap= new HashMap<Object, PositionTrackerChain>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void install() {
|
public synchronized void install() {
|
||||||
|
@ -93,13 +101,13 @@ public class PositionTrackerManager implements IPositionTrackerManager, IFileBuf
|
||||||
public void stateChanging(IFileBuffer buffer) {}
|
public void stateChanging(IFileBuffer buffer) {}
|
||||||
|
|
||||||
private synchronized void createCheckpoint(ITextFileBuffer buffer) {
|
private synchronized void createCheckpoint(ITextFileBuffer buffer) {
|
||||||
PositionTrackerChain chain= getChain(buffer);
|
final Object bufferKey= getKey(buffer);
|
||||||
|
PositionTrackerChain chain= fPositionTrackerMap.get(bufferKey);
|
||||||
if (chain == null) {
|
if (chain == null) {
|
||||||
chain = new PositionTrackerChain(buffer.getModificationStamp());
|
chain = new PositionTrackerChain(buffer.getModificationStamp());
|
||||||
fPositionTrackerMap.put(buffer.getLocation(), chain);
|
fPositionTrackerMap.put(bufferKey, chain);
|
||||||
fMemoryCounter+= PositionTrackerChain.MEMORY_SIZE + HASHMAP_ENTRY_SIZE;
|
fMemoryCounter+= PositionTrackerChain.MEMORY_SIZE + HASHMAP_ENTRY_SIZE;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
chain.stopTracking();
|
chain.stopTracking();
|
||||||
fMemoryCounter+= chain.createCheckpoint(buffer.getModificationStamp());
|
fMemoryCounter+= chain.createCheckpoint(buffer.getModificationStamp());
|
||||||
}
|
}
|
||||||
|
@ -110,18 +118,27 @@ public class PositionTrackerManager implements IPositionTrackerManager, IFileBuf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized PositionTrackerChain getChain(ITextFileBuffer buffer) {
|
private Object getKey(ITextFileBuffer buffer) {
|
||||||
return fPositionTrackerMap.get(buffer.getLocation());
|
Object key= buffer.getLocation();
|
||||||
}
|
if (key == null) {
|
||||||
|
URI uri= buffer.getFileStore().toURI();
|
||||||
|
key= URIUtil.toPath(uri);
|
||||||
|
if (key == null) {
|
||||||
|
key= uri;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
private synchronized void resetToLastCheckpoint(ITextFileBuffer buffer) {
|
private synchronized void resetToLastCheckpoint(ITextFileBuffer buffer) {
|
||||||
PositionTrackerChain chain= getChain(buffer);
|
final Object bufferKey= getKey(buffer);
|
||||||
|
PositionTrackerChain chain= fPositionTrackerMap.get(bufferKey);
|
||||||
if (chain != null) {
|
if (chain != null) {
|
||||||
chain.stopTracking();
|
chain.stopTracking();
|
||||||
chain.getActiveTracker().clear();
|
chain.getActiveTracker().clear();
|
||||||
|
|
||||||
if (!chain.isModified()) {
|
if (!chain.isModified()) {
|
||||||
fPositionTrackerMap.remove(buffer.getLocation());
|
fPositionTrackerMap.remove(bufferKey);
|
||||||
chain.dispose();
|
chain.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,6 +218,29 @@ public class PositionTrackerManager implements IPositionTrackerManager, IFileBuf
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
return findPositionConverter(location, timestamp);
|
return findPositionConverter(location, timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
URI locationURI = tu.getLocationURI();
|
||||||
|
if (locationURI != null) {
|
||||||
|
return findPositionConverter(locationURI, timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public synchronized IPositionConverter findPositionConverter(URI locationURI, long timestamp) {
|
||||||
|
PositionTrackerChain chain= fPositionTrackerMap.get(locationURI);
|
||||||
|
if (chain == null) {
|
||||||
|
IPath path= URIUtil.toPath(locationURI);
|
||||||
|
if (path != null) {
|
||||||
|
chain= fPositionTrackerMap.get(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (chain != null) {
|
||||||
|
return chain.findTrackerAt(timestamp);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
* Copyright (c) 2006, 2009 Wind River Systems, Inc. and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -9,11 +9,14 @@
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
* Ed Swartz (Nokia)
|
* Ed Swartz (Nokia)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.viewsupport;
|
package org.eclipse.cdt.internal.ui.viewsupport;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.eclipse.core.filesystem.EFS;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.jface.text.IRegion;
|
import org.eclipse.jface.text.IRegion;
|
||||||
import org.eclipse.jface.text.Region;
|
import org.eclipse.jface.text.Region;
|
||||||
|
@ -38,7 +41,6 @@ import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An utility to open editors for references or elements.
|
* An utility to open editors for references or elements.
|
||||||
* @author markus.schorn@windriver.com
|
|
||||||
*/
|
*/
|
||||||
public class EditorOpener {
|
public class EditorOpener {
|
||||||
|
|
||||||
|
@ -71,6 +73,17 @@ public class EditorOpener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void selectRegion(URI locationURI, IRegion region, long timestamp, IEditorPart editor) {
|
||||||
|
if (editor instanceof ITextEditor) {
|
||||||
|
ITextEditor te= (ITextEditor) editor;
|
||||||
|
IPositionConverter pc= CCorePlugin.getPositionTrackerManager().findPositionConverter(locationURI, timestamp);
|
||||||
|
if (pc != null) {
|
||||||
|
region= pc.historicToActual(region);
|
||||||
|
}
|
||||||
|
te.selectAndReveal(region.getOffset(), region.getLength());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens the editor for an external location, selecting the given region.
|
* Opens the editor for an external location, selecting the given region.
|
||||||
*/
|
*/
|
||||||
|
@ -87,6 +100,26 @@ public class EditorOpener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens the editor for an external EFS location, selecting the given region.
|
||||||
|
*/
|
||||||
|
public static void openExternalFile(IWorkbenchPage page, URI locationURI, IRegion region, long timestamp, ICElement context) {
|
||||||
|
IEditorPart editor= null;
|
||||||
|
try {
|
||||||
|
editor= EditorUtility.openInEditor(locationURI, context);
|
||||||
|
if (timestamp == 0) {
|
||||||
|
try {
|
||||||
|
timestamp= EFS.getStore(locationURI).fetchInfo().getLastModified();
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CUIPlugin.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
selectRegion(locationURI, region, timestamp, editor);
|
||||||
|
} catch (PartInitException e) {
|
||||||
|
CUIPlugin.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens the editor for an ICElement, selecting the id.
|
* Opens the editor for an ICElement, selecting the id.
|
||||||
* @throws CModelException
|
* @throws CModelException
|
||||||
|
|
Loading…
Add table
Reference in a new issue