Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2009-02-02 11:27:05 -0500
committerMarkus Schorn2009-02-02 11:27:05 -0500
commit76173183100894560fcd162ed3ce9bed63a01d8e (patch)
treeec3eda97cd9b74c87ed4e1f54637e0fb05748e92
parent9d8831aad8e53d64dd53e48cccc7c74c51ad53cb (diff)
downloadorg.eclipse.cdt-76173183100894560fcd162ed3ce9bed63a01d8e.tar.gz
org.eclipse.cdt-76173183100894560fcd162ed3ce9bed63a01d8e.tar.xz
org.eclipse.cdt-76173183100894560fcd162ed3ce9bed63a01d8e.zip
Position trackers for non-local external files, bug 261912.
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/PositionTrackerManager.java94
-rw-r--r--core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF2
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/EditorOpener.java45
3 files changed, 109 insertions, 32 deletions
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/PositionTrackerManager.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/PositionTrackerManager.java
index 7adf0b156d..98d59f7531 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/PositionTrackerManager.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/PositionTrackerManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,9 +8,9 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
-
package org.eclipse.cdt.internal.core;
+import java.net.URI;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
@@ -26,6 +26,7 @@ import org.eclipse.core.filebuffers.IFileBuffer;
import org.eclipse.core.filebuffers.IFileBufferListener;
import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.core.filebuffers.ITextFileBufferManager;
+import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
@@ -41,10 +42,16 @@ public class PositionTrackerManager implements IPositionTrackerManager, IFileBuf
private int fMemoryCounter= 0;
private int fInstalled= 0;
- private HashMap 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() {
- fPositionTrackerMap= new HashMap();
+ fPositionTrackerMap= new HashMap<Object, PositionTrackerChain>();
}
public synchronized void install() {
@@ -94,13 +101,13 @@ public class PositionTrackerManager implements IPositionTrackerManager, IFileBuf
public void stateChanging(IFileBuffer buffer) {}
private synchronized void createCheckpoint(ITextFileBuffer buffer) {
- PositionTrackerChain chain= getChain(buffer);
+ final Object bufferKey= getKey(buffer);
+ PositionTrackerChain chain= fPositionTrackerMap.get(bufferKey);
if (chain == null) {
chain = new PositionTrackerChain(buffer.getModificationStamp());
- fPositionTrackerMap.put(buffer.getLocation(), chain);
+ fPositionTrackerMap.put(bufferKey, chain);
fMemoryCounter+= PositionTrackerChain.MEMORY_SIZE + HASHMAP_ENTRY_SIZE;
- }
- else {
+ } else {
chain.stopTracking();
fMemoryCounter+= chain.createCheckpoint(buffer.getModificationStamp());
}
@@ -111,18 +118,27 @@ public class PositionTrackerManager implements IPositionTrackerManager, IFileBuf
}
}
- private synchronized PositionTrackerChain getChain(ITextFileBuffer buffer) {
- return (PositionTrackerChain) fPositionTrackerMap.get(buffer.getLocation());
- }
+ private Object getKey(ITextFileBuffer buffer) {
+ 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) {
- PositionTrackerChain chain= getChain(buffer);
+ final Object bufferKey= getKey(buffer);
+ PositionTrackerChain chain= fPositionTrackerMap.get(bufferKey);
if (chain != null) {
chain.stopTracking();
chain.getActiveTracker().clear();
if (!chain.isModified()) {
- fPositionTrackerMap.remove(buffer.getLocation());
+ fPositionTrackerMap.remove(bufferKey);
chain.dispose();
}
}
@@ -130,22 +146,21 @@ public class PositionTrackerManager implements IPositionTrackerManager, IFileBuf
private synchronized void runCleanup() {
fMemoryCounter= 0;
- for (Iterator iter = fPositionTrackerMap.values().iterator(); iter.hasNext();) {
- PositionTrackerChain chain= (PositionTrackerChain) iter.next();
+ for (PositionTrackerChain chain : fPositionTrackerMap.values()) {
fMemoryCounter+= HASHMAP_ENTRY_SIZE;
fMemoryCounter+= chain.getMemorySize();
}
if (fMemoryCounter > MAX_MEMORY_AFTER_CLEANUP) {
- SortedMap map= new TreeMap();
- for (Iterator iter = fPositionTrackerMap.values().iterator(); iter.hasNext();) {
- PositionTrackerChain chain = (PositionTrackerChain) iter.next();
+ SortedMap<Long, List<PositionTrackerChain>> map= new TreeMap<Long, List<PositionTrackerChain>>();
+ for (Iterator<PositionTrackerChain> iter = fPositionTrackerMap.values().iterator(); iter.hasNext();) {
+ PositionTrackerChain chain = iter.next();
addChain(map, chain);
}
while (!map.isEmpty()) {
- Long key= (Long) map.firstKey();
- List list= (List) map.remove(key);
- for (Iterator iter = list.iterator(); iter.hasNext();) {
- PositionTrackerChain chain = (PositionTrackerChain) iter.next();
+ Long key= map.firstKey();
+ List<PositionTrackerChain> list= map.remove(key);
+ for (Iterator<PositionTrackerChain> iter = list.iterator(); iter.hasNext();) {
+ PositionTrackerChain chain = iter.next();
fMemoryCounter+= chain.removeOldest();
addChain(map, chain);
}
@@ -156,13 +171,13 @@ public class PositionTrackerManager implements IPositionTrackerManager, IFileBuf
}
}
- private synchronized void addChain(SortedMap map, PositionTrackerChain chain) {
+ private synchronized void addChain(SortedMap<Long, List<PositionTrackerChain>> map, PositionTrackerChain chain) {
long or= chain.getOldestRetirement();
if (or != Long.MAX_VALUE) {
Long lor= new Long(or);
- List list= (List) map.get(lor);
+ List<PositionTrackerChain> list= map.get(lor);
if (list == null) {
- list= new LinkedList();
+ list= new LinkedList<PositionTrackerChain>();
map.put(lor, list);
}
list.add(chain);
@@ -173,7 +188,7 @@ public class PositionTrackerManager implements IPositionTrackerManager, IFileBuf
* {@inheritDoc}
*/
public synchronized IPositionConverter findPositionConverter(IFile file, long timestamp) {
- PositionTrackerChain chain= (PositionTrackerChain) fPositionTrackerMap.get(file.getFullPath());
+ PositionTrackerChain chain= fPositionTrackerMap.get(file.getFullPath());
if (chain != null) {
return chain.findTrackerAt(timestamp);
}
@@ -184,7 +199,7 @@ public class PositionTrackerManager implements IPositionTrackerManager, IFileBuf
* {@inheritDoc}
*/
public synchronized IPositionConverter findPositionConverter(IPath externalLocation, long timestamp) {
- PositionTrackerChain chain= (PositionTrackerChain) fPositionTrackerMap.get(externalLocation);
+ PositionTrackerChain chain= fPositionTrackerMap.get(externalLocation);
if (chain != null) {
return chain.findTrackerAt(timestamp);
}
@@ -198,11 +213,34 @@ public class PositionTrackerManager implements IPositionTrackerManager, IFileBuf
IFile file= (IFile) tu.getResource();
if (file != null) {
return findPositionConverter(file, timestamp);
- }
+ }
IPath location= tu.getLocation();
if (location != null) {
return findPositionConverter(location, timestamp);
}
+
+ URI locationURI = tu.getLocationURI();
+ if (locationURI != null) {
+ return findPositionConverter(locationURI, timestamp);
+ }
+
return null;
}
+
+ /**
+ * Will be API in 5.1
+ */
+ 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;
+ }
}
diff --git a/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF
index fd3438ed75..0d59d8f184 100644
--- a/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF
+++ b/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF
@@ -88,7 +88,7 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.3.0,4.0.0)",
org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
org.eclipse.search;bundle-version="[3.2.0,4.0.0)",
org.eclipse.compare;bundle-version="[3.3.0,4.0.0)",
- org.eclipse.cdt.core;bundle-version="[5.0.0,6.0.0)",
+ org.eclipse.cdt.core;bundle-version="[5.0.2,6.0.0)",
org.eclipse.ui.console;bundle-version="[3.1.100,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.help;bundle-version="[3.2.0,4.0.0)",
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/EditorOpener.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/EditorOpener.java
index a1f108bc28..cea6e25244 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/EditorOpener.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/EditorOpener.java
@@ -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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -9,11 +9,14 @@
* Markus Schorn - initial API and implementation
* Ed Swartz (Nokia)
*******************************************************************************/
-
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.IResource;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
@@ -25,6 +28,7 @@ import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IPositionConverter;
+import org.eclipse.cdt.core.IPositionTrackerManager;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ISourceRange;
@@ -32,13 +36,13 @@ import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.internal.core.PositionTrackerManager;
import org.eclipse.cdt.internal.core.model.ext.ICElementHandle;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
/**
* An utility to open editors for references or elements.
- * @author markus.schorn@windriver.com
*/
public class EditorOpener {
@@ -68,6 +72,21 @@ public class EditorOpener {
te.selectAndReveal(region.getOffset(), region.getLength());
}
}
+
+ private static void selectRegion(URI locationURI, IRegion region, long timestamp, IEditorPart editor) {
+ if (editor instanceof ITextEditor) {
+ ITextEditor te= (ITextEditor) editor;
+ final IPositionTrackerManager ptm = CCorePlugin.getPositionTrackerManager();
+ if (ptm instanceof PositionTrackerManager) {
+ // will be API in 5.0
+ IPositionConverter pc= ((PositionTrackerManager)ptm).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.
@@ -84,6 +103,26 @@ public class EditorOpener {
CUIPlugin.log(e);
}
}
+
+ /**
+ * 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.

Back to the top