Permalink
Browse files

initial draftfor search ui: search for modules in workspace

  • Loading branch information...
1 parent 0b8fc99 commit cf0620dc691c84fc2a100df11ce0810a708e0921 @JPMoresmau committed Apr 30, 2012
Showing with 1,018 additions and 20 deletions.
  1. +1 −1 docs/BW-DB.txt
  2. +0 −1 ....eclipsefp.haskell.buildwrapper/src/net/sf/eclipsefp/haskell/buildwrapper/BuildWrapperPlugin.java
  3. +6 −2 net.sf.eclipsefp.haskell.buildwrapper/src/net/sf/eclipsefp/haskell/buildwrapper/JobFacade.java
  4. +4 −0 net.sf.eclipsefp.haskell.buildwrapper/src/net/sf/eclipsefp/haskell/buildwrapper/types/Location.java
  5. +77 −0 ....eclipsefp.haskell.buildwrapper/src/net/sf/eclipsefp/haskell/buildwrapper/types/UsageResults.java
  6. +31 −0 ...f.eclipsefp.haskell.buildwrapper/src/net/sf/eclipsefp/haskell/buildwrapper/usage/ModuleUsage.java
  7. +72 −1 net.sf.eclipsefp.haskell.buildwrapper/src/net/sf/eclipsefp/haskell/buildwrapper/usage/UsageAPI.java
  8. +90 −1 net.sf.eclipsefp.haskell.buildwrapper/src/net/sf/eclipsefp/haskell/buildwrapper/usage/UsageDB.java
  9. +5 −1 ...f.eclipsefp.haskell.buildwrapper/src/net/sf/eclipsefp/haskell/buildwrapper/usage/UsageThread.java
  10. +2 −1 net.sf.eclipsefp.haskell.ui/META-INF/MANIFEST.MF
  11. +9 −1 net.sf.eclipsefp.haskell.ui/plugin.properties
  12. +113 −6 net.sf.eclipsefp.haskell.ui/plugin.xml
  13. +7 −3 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/browser/views/hoogle/HoogleView.java
  14. +29 −0 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/handlers/ReferencesProjectHandler.java
  15. +92 −0 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/handlers/ReferencesWorkspaceHandler.java
  16. +9 −0 ....eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/haskell/HaskellEditor.java
  17. +78 −0 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/search/UsageQuery.java
  18. +118 −0 ...ipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/search/UsageResultContentProvider.java
  19. +110 −0 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/search/UsageSearchPage.java
  20. +144 −0 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/search/UsageSearchResult.java
  21. +6 −0 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/util/UITexts.java
  22. +7 −1 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/util/uitexts.properties
  23. +8 −1 ...ui/src/net/sf/eclipsefp/haskell/ui/internal/views/projectexplorer/HaskellResourceExtensionLP.java
View
@@ -71,6 +71,6 @@ package + module -> unique module id + file where defined (for local modules)
-> several Main for one project can exist!! -> need component name for main
module id + name -> unique symbol id + definition (for local symbols)
symbol id -> usages (file in Eclipse format (project + path), line span)
-module id -> usages (import)
+module id -> usages (import/export)
@@ -74,7 +74,6 @@ public void start(BundleContext context) throws Exception {
public void stop(BundleContext context) throws Exception {
plugin = null;
usageThread.setShouldStop();
- usageThread.interrupt();
// wait for all pending writes for 10 secs
usageThread.join(10000);
// then close api and db
@@ -11,6 +11,7 @@
import net.sf.eclipsefp.haskell.buildwrapper.types.OutlineHandler;
import net.sf.eclipsefp.haskell.buildwrapper.types.OutlineResult;
import net.sf.eclipsefp.haskell.buildwrapper.types.ThingAtPointHandler;
+import net.sf.eclipsefp.haskell.buildwrapper.usage.UsageThread;
import net.sf.eclipsefp.haskell.buildwrapper.util.BWText;
import org.eclipse.core.resources.IFile;
@@ -147,8 +148,11 @@ protected IStatus run(IProgressMonitor monitor) {
*/
@Override
public void done(IJobChangeEvent event) {
- if (event.getResult().isOK()){
- BuildWrapperPlugin.getDefault().getUsageThread().addProject(getProject());
+ if (event.getResult().isOK() && BuildWrapperPlugin.getDefault()!=null){
+ UsageThread ut=BuildWrapperPlugin.getDefault().getUsageThread();
+ if (ut!=null){
+ ut.addProject(getProject());
+ }
}
}
});
@@ -88,6 +88,7 @@ public Location(String fileName, int startLine, int startColumn, int endLine, in
this.endLine = endLine;
this.endColumn = endColumn+mv;
}
+
public Location(String fileName, IDocument document, IRegion region) throws BadLocationException {
this.fileName = fileName;
@@ -101,6 +102,9 @@ public Location(String fileName, IDocument document, IRegion region) throws BadL
this.endColumn = endOffset - document.getLineOffset(docLine);
}
+
+
+
/**
* Returns the offset within the given document
* that the start of this {@link Location} object represents.
@@ -0,0 +1,77 @@
+/**
+ * Copyright (c) 2012 by JP Moresmau
+ * This code is made available under the terms of the Eclipse Public License,
+ * version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
+ */
+package net.sf.eclipsefp.haskell.buildwrapper.types;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+
+/**
+ * @author JP Moresmau
+ *
+ */
+public class UsageResults {
+ private Map<IProject,Map<IFile,Collection<UsageLocation>>> allResults=new HashMap<IProject, Map<IFile,Collection<UsageLocation>>>();
+
+ public void put(IFile file,Collection<UsageLocation> locs){
+ IProject p=file.getProject();
+ Map<IFile,Collection<UsageLocation>> m=allResults.get(p);
+ if (m==null){
+ m=new HashMap<IFile, Collection<UsageLocation>>();
+ allResults.put(p, m);
+ }
+ Collection<UsageLocation> allLocs=m.get(file);
+ if (allLocs==null){
+ allLocs=new ArrayList<UsageResults.UsageLocation>();
+ m.put(file, allLocs);
+ }
+ allLocs.addAll(locs);
+ }
+
+ public Set<IProject> listProjects(){
+ return allResults.keySet();
+ }
+
+ public Map<IFile,Collection<UsageLocation>> getUsageInProject(IProject p){
+ return allResults.get(p);
+ }
+
+ public static class UsageLocation {
+ private int startLine;
+ private int lengthInLine;
+
+ public UsageLocation(int startLine, int lengthInLine) {
+ super();
+ this.startLine = startLine;
+ this.lengthInLine = lengthInLine;
+ }
+
+ public UsageLocation(Location l) {
+ super();
+ this.startLine = l.getStartLine();
+ this.lengthInLine = Math.max(1, l.getEndLine()-getStartLine());
+ }
+
+ /**
+ * @return the lengthInLine
+ */
+ public int getLengthInLine() {
+ return lengthInLine;
+ }
+
+ /**
+ * @return the startLine
+ */
+ public int getStartLine() {
+ return startLine;
+ }
+ }
+}
@@ -0,0 +1,31 @@
+/**
+ * Copyright (c) 2012 by JP Moresmau
+ * This code is made available under the terms of the Eclipse Public License,
+ * version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
+ */
+package net.sf.eclipsefp.haskell.buildwrapper.usage;
+
+/**
+ * @author JP Moresmau
+ *
+ */
+public class ModuleUsage {
+ private long moduleID;
+ private String location;
+
+
+
+ public ModuleUsage(long moduleID, String location) {
+ super();
+ this.moduleID = moduleID;
+ this.location = location;
+ }
+ public long getModuleID() {
+ return moduleID;
+ }
+ public String getLocation() {
+ return location;
+ }
+
+
+}
@@ -10,19 +10,22 @@
import java.io.InputStreamReader;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import net.sf.eclipsefp.haskell.buildwrapper.BWFacade;
import net.sf.eclipsefp.haskell.buildwrapper.BuildWrapperPlugin;
import net.sf.eclipsefp.haskell.buildwrapper.types.Component;
import net.sf.eclipsefp.haskell.buildwrapper.types.Module;
+import net.sf.eclipsefp.haskell.buildwrapper.types.UsageResults;
import net.sf.eclipsefp.haskell.buildwrapper.util.BWText;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.json.JSONArray;
import org.json.JSONException;
+import org.json.JSONObject;
import org.json.JSONTokener;
/**
@@ -69,7 +72,13 @@ public void addFile(IProject p,Component c, String relPath){
String module=formatModule(c, arr.getString(1));
if (module!=null){
long fileID=db.getFileID(f);
- long moduleID=db.getModuleID(pkg, module, fileID);
+ db.clearUsageInFile(fileID);
+
+ //long moduleID=
+ db.getModuleID(pkg, module, fileID);
+ List<ModuleUsage> modUsages=new ArrayList<ModuleUsage>();
+ buildUsage(arr,modUsages);
+ db.setModuleUsages(fileID, modUsages);
db.commit();
}
} catch (SQLException sqle){
@@ -82,6 +91,57 @@ public void addFile(IProject p,Component c, String relPath){
}
}
+ private void buildUsage(JSONArray arr,List<ModuleUsage> modUsages){
+ JSONObject pkgs=arr.optJSONObject(2);
+ if (pkgs!=null){
+ for (Iterator<String> itPkg=pkgs.keys();itPkg.hasNext();){
+ String pkgKey=itPkg.next();
+ JSONObject mods=pkgs.optJSONObject(pkgKey);
+ if (mods!=null){
+ String pkg=formatPackage(pkgKey);
+ buildUsageModule(pkg,mods,modUsages);
+ }
+ }
+ }
+ }
+
+ private void buildUsageModule(String pkg,JSONObject mods,List<ModuleUsage> modUsages){
+ for (Iterator<String> itMod=mods.keys();itMod.hasNext();){
+ String modKey=itMod.next();
+ JSONObject types=mods.optJSONObject(modKey);
+ if (types!=null){
+ try {
+ long modID=db.getModuleID(pkg, modKey, null);
+
+ buildUsage(modID,types.optJSONObject("vars"),false,modUsages);
+ } catch (SQLException sqle){
+ BuildWrapperPlugin.logError(BWText.error_db, sqle);
+ }
+ }
+ }
+ }
+
+ private void buildUsage(long modID,JSONObject symbols,boolean isType,List<ModuleUsage> modUsages){
+ if (symbols!=null){
+ for (Iterator<String> itSym=symbols.keys();itSym.hasNext();){
+ String symKey=itSym.next();
+ JSONArray locs=symbols.optJSONArray(symKey);
+ if (locs!=null){
+
+ for (int a=0;a<locs.length();a++){
+ JSONArray loc=locs.optJSONArray(a);
+ if (loc!=null){
+ String sloc=loc.toString();
+ if (!isType && symKey.length()==0){
+ modUsages.add(new ModuleUsage(modID, sloc));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
public IFile getFile(Long fileid){
try {
return db.getFile(fileid);
@@ -109,6 +169,15 @@ public boolean knowsProject(IProject p){
return false;
}
+ public UsageResults getModuleReferences(String pkg,String module){
+ try {
+ return db.getModuleReferences(pkg, module);
+ } catch (SQLException sqle){
+ BuildWrapperPlugin.logError(BWText.error_db, sqle);
+ }
+ return new UsageResults();
+ }
+
private JSONArray parseUsageFile(IFile uf){
try {
InputStream is=uf.getContents();
@@ -161,4 +230,6 @@ private String formatModule(Component c,String module){
}
return ret;
}
+
+
}
Oops, something went wrong.

0 comments on commit cf0620d

Please sign in to comment.