Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/callgraph/core/FileFinderOpener.java')
-rw-r--r--systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/callgraph/core/FileFinderOpener.java133
1 files changed, 32 insertions, 101 deletions
diff --git a/systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/callgraph/core/FileFinderOpener.java b/systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/callgraph/core/FileFinderOpener.java
index 60b2a7b97f..6b7fd4d16d 100644
--- a/systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/callgraph/core/FileFinderOpener.java
+++ b/systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/callgraph/core/FileFinderOpener.java
@@ -10,33 +10,16 @@
*******************************************************************************/
package org.eclipse.linuxtools.callgraph.core;
-import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
-import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.dom.ast.IBinding;
-import org.eclipse.cdt.core.dom.ast.IFunction;
-import org.eclipse.cdt.core.index.IIndex;
-import org.eclipse.cdt.core.index.IIndexFile;
-import org.eclipse.cdt.core.index.IIndexFileLocation;
-import org.eclipse.cdt.core.index.IIndexManager;
-import org.eclipse.cdt.core.index.IIndexName;
-import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.model.ICProject;
-import org.eclipse.core.filesystem.EFS;
-import org.eclipse.core.filesystem.IFileStore;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.linuxtools.callgraph.core.SystemTapUIErrorMessages;
+import org.eclipse.linuxtools.profiling.ui.ProfileUIUtils;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
-import org.eclipse.ui.ide.IDE;
-import org.eclipse.ui.texteditor.ITextEditor;
+
/**
* Helper class that finds and opens files. Finds based on function names,
* opens based on path and in the current default editor.
@@ -44,110 +27,58 @@ import org.eclipse.ui.texteditor.ITextEditor;
*/
public class FileFinderOpener {
- private static HashMap<String, Integer> offset = new HashMap<String, Integer>();
- private static HashMap<String, Integer> length = new HashMap<String, Integer>();
-
+ private static HashMap<String, int []> map = new HashMap<String, int []>();
/**
- * @param project : C Project Type
- * @param functionName : name of a function
- * @return an ArrayList of String paths (relative to current workspace) of
- * files with specified function name
+ * Seeks all functions in the given proejct that contains the given function name.
+ * Farms off the work of generating the list to the findFunctionsInProject function.
+ * Opens a selection dialog if more than one file is found.
+ *
+ * @param project
+ * @param functionName
+ * @return
*/
- private static ArrayList<String> findFunctionsInProject(ICProject project,
- String functionName) {
- ArrayList<String> files = new ArrayList<String>() ;
-
- IIndexManager manager = CCorePlugin.getIndexManager();
- IIndex index = null;
- try {
- index = manager.getIndex(project);
- index.acquireReadLock();
- IBinding[] bindings = index.findBindings(functionName.toCharArray(), IndexFilter.ALL, null);
- for (IBinding bind : bindings) {
- if (bind instanceof IFunction) {
- IFunction ifunction = (IFunction) bind;
- IIndexName[] names = index.findNames(ifunction,
- IIndex.FIND_DEFINITIONS);
- for (IIndexName iname : names) {
- IIndexFile file = iname.getFile();
- if (file != null) {
- IIndexFileLocation filelocation = file.getLocation();
- String loc = filelocation.getURI().getPath();
- files.add(loc);
- offset.put(loc, iname.getNodeOffset());
- length.put(loc, iname.getNodeLength());
- }
- }
- }
- }
-
- } catch (CoreException e) {
- e.printStackTrace();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- index.releaseReadLock();
- return files;
- }
-
-
- public static String findAndOpen(ICProject project, String functionName) {
- offset.clear();
- length.clear();
-
- ArrayList<String> files = findFunctionsInProject(project, functionName);
+ public static void findAndOpen(ICProject project, String functionName) {
+ //Safety valve: Do not enforce use of project names
+ if (project == null)
+ return;
+
+ map = ProfileUIUtils.findFunctionsInProject(project, functionName, -1, null);
+ ArrayList<String> files = new ArrayList<String>(map.keySet());
if (files == null || files.size() < 1)
- return null;
- StringBuilder output = new StringBuilder();
+ return;
if (files.size() == 1) {
- open(files.get(0), offset.get(files.get(0)), length.get(files.get(0)));
+ open(files.get(0), map.get(files.get(0))[0], map.get(files.get(0))[1]);
} else {
- ElementListSelectionDialog d = new ElementListSelectionDialog(
- new Shell(), new LabelProvider());
+ ElementListSelectionDialog d = new ElementListSelectionDialog(new Shell(), new LabelProvider());
d.setTitle(Messages.getString("FileFinderOpener.MultipleFilesDialog")); //$NON-NLS-1$
d.setMessage(Messages.getString("FileFinderOpener.MultFilesDialogM1") + functionName + Messages.getString("FileFinderOpener.MultFilesDialogM2") + //$NON-NLS-1$ //$NON-NLS-2$
Messages.getString("FileFinderOpener.MultFilesDialogM3")); //$NON-NLS-1$
d.setElements(files.toArray());
d.open();
+
+ if (d.getResult() == null) {
+ return;
+ }
+
for (Object o : d.getResult()) {
if (o instanceof String) {
String s = (String) o;
- output.append(open(s, offset.get(s), length.get(s)));
+ open(s, map.get(s)[0], map.get(s)[1]);
}
}
}
-
- return output.toString();
}
-
- public static String open(String path, int offset, int length) {
+ public static void open(String path, int offset, int length) {
if (path == null)
- return null;
- File fileToOpen = new File(path);
-
- if (fileToOpen.exists() && fileToOpen.isFile()) {
- IFileStore fileStore = EFS.getLocalFileSystem().getStore(fileToOpen.toURI());
- IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
-
- try {
- IEditorPart ed = IDE.openEditorOnFileStore( page, fileStore );
- if (ed instanceof ITextEditor && offset > 0) {
- ITextEditor text = (ITextEditor) ed;
- text.selectAndReveal(offset, length);
- return text.getTitle();
- }
- } catch ( PartInitException e ) {
- }
- } else {
- SystemTapUIErrorMessages mess = new SystemTapUIErrorMessages(Messages.getString("FileFinderOpener.FileNotFound"), //$NON-NLS-1$
- Messages.getString("FileFinderOpener.FileNotFound1"), Messages.getString("FileFinderOpener.FileNotFound2") + path); //$NON-NLS-1$ //$NON-NLS-2$
- mess.schedule();
+ return;
+ try {
+ ProfileUIUtils.openEditorAndSelect(path, offset, length);
+ } catch (PartInitException e) {
+ e.printStackTrace();
}
- return null;
}
}

Back to the top