Index: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/actions/GenerateDartdocAction.java |
=================================================================== |
--- editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/actions/GenerateDartdocAction.java (revision 20556) |
+++ editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/actions/GenerateDartdocAction.java (working copy) |
@@ -14,7 +14,11 @@ |
package com.google.dart.tools.ui.actions; |
+import com.google.dart.engine.element.Element; |
+import com.google.dart.engine.element.LibraryElement; |
import com.google.dart.tools.core.DartCore; |
+import com.google.dart.tools.core.DartCoreDebug; |
+import com.google.dart.tools.core.analysis.model.ProjectManager; |
import com.google.dart.tools.core.dartdoc.DartdocGenerator; |
import com.google.dart.tools.core.model.DartElement; |
import com.google.dart.tools.core.model.DartLibrary; |
@@ -23,6 +27,7 @@ |
import com.google.dart.tools.ui.instrumentation.UIInstrumentationBuilder; |
import com.google.dart.tools.ui.internal.util.ExternalBrowserUtil; |
+import org.eclipse.core.resources.IFile; |
import org.eclipse.core.resources.IResource; |
import org.eclipse.core.resources.ResourcesPlugin; |
import org.eclipse.core.runtime.IProgressMonitor; |
@@ -54,12 +59,12 @@ |
ISelectionListener, IPartListener { |
class DeployOptimizedJob extends InstrumentedJob { |
- private DartLibrary library; |
+ private IFile file; |
- public DeployOptimizedJob(IWorkbenchPage page, DartLibrary library) { |
+ public DeployOptimizedJob(IWorkbenchPage page, IFile file) { |
super(ActionMessages.GenerateDartdocAction_jobTitle); |
- this.library = library; |
+ this.file = file; |
// Synchronize on the workspace root to catch any builds that are in progress. |
setRule(ResourcesPlugin.getWorkspace().getRoot()); |
@@ -71,13 +76,11 @@ |
@Override |
protected IStatus doRun(IProgressMonitor monitor, UIInstrumentationBuilder instrumentation) { |
try { |
- |
- ActionInstrumentationUtilities.recordLibrary(library, instrumentation); |
monitor.beginTask( |
- ActionMessages.GenerateDartdocAction_Compiling + library.getElementName(), |
+ ActionMessages.GenerateDartdocAction_Compiling + file.getName(), |
IProgressMonitor.UNKNOWN); |
- DartdocGenerator.generateDartdoc(library, monitor, DartCore.getConsole()); |
+ DartdocGenerator.generateDartdoc(file, monitor, DartCore.getConsole()); |
return Status.OK_STATUS; |
} catch (OperationCanceledException exception) { |
@@ -98,22 +101,15 @@ |
return Status.CANCEL_STATUS; |
} finally { |
if (OPEN_BROWSER_AFTER_GENERATION) { |
- try { |
- String url = "file://" |
- + DartdocGenerator.getDocsIndexPath( |
- library.getCorrespondingResource().getLocation()).toOSString(); |
+ String url = "file://" |
+ + DartdocGenerator.getDocsIndexPath(file.getLocation()).toOSString(); |
- instrumentation.metric("DartDocOpenInBrowser", "Opening"); |
- instrumentation.data("DartDocOpenInBrowser", url); |
+ instrumentation.metric("DartDocOpenInBrowser", "Opening"); |
+ instrumentation.data("DartDocOpenInBrowser", url); |
- ExternalBrowserUtil.openInExternalBrowser(url); |
- } catch (DartModelException e) { |
+ ExternalBrowserUtil.openInExternalBrowser(url); |
+ } |
- instrumentation.metric("Problem-Exception", e.getClass().toString()); |
- instrumentation.data("Problem-Exception", e.toString()); |
- e.printStackTrace(); |
- } |
- } |
monitor.done(); |
} |
} |
@@ -194,24 +190,84 @@ |
} |
} |
- final DartLibrary library = getCurrentLibrary(); |
+ IFile libraryFile = getCurrentLibrary(); |
- ActionInstrumentationUtilities.recordLibrary(library, instrumentation); |
- |
- if (library == null) { |
+ if (libraryFile == null) { |
instrumentation.metric("Problem", "No library selected"); |
MessageDialog.openError( |
window.getShell(), |
ActionMessages.GenerateDartdocAction_unableToLaunch, |
ActionMessages.GenerateDartdocAction_noneSelected); |
} else { |
- DeployOptimizedJob job = new DeployOptimizedJob(page, library); |
+ DeployOptimizedJob job = new DeployOptimizedJob(page, libraryFile); |
job.schedule(isSaveNeeded ? 100 : 0); |
} |
} |
- private DartLibrary getCurrentLibrary() { |
+ private IFile getCurrentLibrary() { |
+ if (DartCoreDebug.ENABLE_NEW_ANALYSIS) { |
+ LibraryElement library = getCurrentLibrary_newModel(); |
+ |
+ if (library != null) { |
+ ProjectManager manager = DartCore.getProjectManager(); |
+ |
+ return (IFile) manager.getResource(library.getDefiningCompilationUnit().getSource()); |
+ } |
+ } else { |
+ DartLibrary library = getCurrentLibrary_oldModel(); |
+ |
+ if (library != null) { |
+ try { |
+ return (IFile) library.getDefiningCompilationUnit().getCorrespondingResource(); |
+ } catch (DartModelException e) { |
+ |
+ } |
+ } |
+ } |
+ |
+ return null; |
+ } |
+ |
+ private LibraryElement getCurrentLibrary_newModel() { |
+ ProjectManager manager = DartCore.getProjectManager(); |
+ |
IResource resource = null; |
+ Element element = null; |
+ |
+ if (selectedObject == null) { |
+ IWorkbenchPage page = window.getActivePage(); |
+ |
+ if (page != null) { |
+ IEditorPart part = page.getActiveEditor(); |
+ |
+ if (part != null) { |
+ selectedObject = part.getEditorInput().getAdapter(IResource.class); |
+ } |
+ } |
+ } |
+ |
+ if (selectedObject instanceof IResource) { |
+ resource = (IResource) selectedObject; |
+ } |
+ |
+ if (resource instanceof IFile) { |
+ element = manager.getLibraryElement((IFile) resource); |
+ } |
+ |
+ if (selectedObject instanceof Element) { |
+ element = (Element) selectedObject; |
+ } |
+ |
+ if (element != null) { |
+ return element.getLibrary(); |
+ } |
+ |
+ return null; |
+ } |
+ |
+ @Deprecated |
+ private DartLibrary getCurrentLibrary_oldModel() { |
+ IResource resource = null; |
DartElement element = null; |
if (selectedObject == null) { |
@@ -225,6 +281,7 @@ |
} |
} |
} |
+ |
if (selectedObject instanceof IResource) { |
resource = (IResource) selectedObject; |
} |