Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1078)

Unified Diff: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/editor/DartOutlinePage_NEW.java

Issue 311053005: Updates for the Outline API and use it in Editor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/editor/DartOutlinePage_NEW.java
diff --git a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/editor/DartOutlinePage_NEW.java b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/editor/DartOutlinePage_NEW.java
index caab51b1a52b5c5cab98d2e683d373c43d692c4c..b79542de44d16bdc155af6edb974df4dd77c7286 100644
--- a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/editor/DartOutlinePage_NEW.java
+++ b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/editor/DartOutlinePage_NEW.java
@@ -14,9 +14,11 @@
package com.google.dart.tools.ui.internal.text.editor;
import com.google.common.base.Objects;
+import com.google.dart.server.ElementKind;
import com.google.dart.server.Outline;
import com.google.dart.tools.core.DartCore;
import com.google.dart.tools.internal.search.ui.DartSearchActionGroup;
+import com.google.dart.tools.ui.DartElementImageDescriptor;
import com.google.dart.tools.ui.DartPluginImages;
import com.google.dart.tools.ui.DartToolsPlugin;
import com.google.dart.tools.ui.actions.InstrumentedAction;
@@ -26,7 +28,9 @@ import com.google.dart.tools.ui.instrumentation.UIInstrumentationBuilder;
import com.google.dart.tools.ui.internal.text.DartHelpContextIds;
import com.google.dart.tools.ui.internal.util.SWTUtil;
import com.google.dart.tools.ui.internal.viewsupport.ColoredViewersManager;
+import com.google.dart.tools.ui.internal.viewsupport.ImageDescriptorRegistry;
+import org.apache.commons.lang3.StringUtils;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.jface.action.IAction;
@@ -35,6 +39,7 @@ import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider;
@@ -56,6 +61,7 @@ import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
@@ -89,11 +95,10 @@ public class DartOutlinePage_NEW extends Page implements IContentOutlinePage {
return NOT_ELEMENT;
}
Outline outline = (Outline) e;
- throw new IllegalStateException("com.google.dart.server.Outline not yet supported.");
-// if (outline.getElement().isPrivate()) {
-// return PRIVATE_ELEMENT;
-// }
-// return PUBLIC_ELEMENT;
+ if (outline.isPrivate()) {
+ return PRIVATE_ELEMENT;
+ }
+ return PUBLIC_ELEMENT;
}
@Override
@@ -152,30 +157,105 @@ public class DartOutlinePage_NEW extends Page implements IContentOutlinePage {
}
public static class OutlineLabelProvider extends LabelProvider implements IStyledLabelProvider {
- private final ElementLabelProvider_NEW elementLabelProvider = new ElementLabelProvider_NEW();
+ private static final Point SIZE = new Point(22, 16);
+ private static final ImageDescriptorRegistry registry = DartToolsPlugin.getImageDescriptorRegistry();
+ private static final String RIGHT_ARROW = " \u2192 "; //$NON-NLS-1$
+
+ public static ImageDescriptor getImageDescriptor(Outline element) {
+ ElementKind kind = element.getKind();
+ ImageDescriptor base = getBaseImageDescriptor(kind, element.isPrivate());
+ if (base == null) {
+ return null;
+ }
+ int flags = 0;
+ if (kind == ElementKind.CONSTRUCTOR) {
+ flags |= DartElementImageDescriptor.CONSTRUCTOR;
+ }
+ if (kind == ElementKind.GETTER) {
+ flags |= DartElementImageDescriptor.GETTER;
+ }
+ if (kind == ElementKind.SETTER) {
+ flags |= DartElementImageDescriptor.SETTER;
+ }
+ if (element.isAbstract()) {
+ flags |= DartElementImageDescriptor.ABSTRACT;
+ }
+ if (element.isStatic()) {
+ flags |= DartElementImageDescriptor.STATIC;
+ }
+ return new DartElementImageDescriptor(base, flags, SIZE);
+ }
+
+ private static ImageDescriptor getBaseImageDescriptor(ElementKind kind, boolean isPrivate) {
+ if (kind == ElementKind.CLASS || kind == ElementKind.CLASS_TYPE_ALIAS) {
+ return isPrivate ? DartPluginImages.DESC_DART_CLASS_PRIVATE
+ : DartPluginImages.DESC_DART_CLASS_PUBLIC;
+ }
+ if (kind == ElementKind.FUNCTION_TYPE_ALIAS) {
+ return isPrivate ? DartPluginImages.DESC_DART_FUNCTIONTYPE_PRIVATE
+ : DartPluginImages.DESC_DART_FUNCTIONTYPE_PUBLIC;
+ }
+ if (kind == ElementKind.FIELD || kind == ElementKind.TOP_LEVEL_VARIABLE) {
+ return isPrivate ? DartPluginImages.DESC_DART_FIELD_PRIVATE
+ : DartPluginImages.DESC_DART_FIELD_PUBLIC;
+ }
+ if (kind == ElementKind.CONSTRUCTOR || kind == ElementKind.FUNCTION
+ || kind == ElementKind.GETTER || kind == ElementKind.METHOD || kind == ElementKind.SETTER) {
+ return isPrivate ? DartPluginImages.DESC_DART_METHOD_PRIVATE
+ : DartPluginImages.DESC_DART_METHOD_PUBLIC;
+ }
+ if (kind == ElementKind.COMPILATION_UNIT) {
+ return DartPluginImages.DESC_DART_COMP_UNIT;
+ }
+ if (kind == ElementKind.LIBRARY) {
+ return DartPluginImages.DESC_DART_LIB_FILE;
+ }
+ if (kind == ElementKind.UNIT_TEST_CASE) {
+ return DartPluginImages.DESC_DART_TEST_CASE;
+ }
+ if (kind == ElementKind.UNIT_TEST_GROUP) {
+ return DartPluginImages.DESC_DART_TEST_GROUP;
+ }
+ return null;
+ }
@Override
public Image getImage(Object obj) {
- throw new IllegalStateException("com.google.dart.server.Outline not yet supported.");
-// Outline outline = (Outline) obj;
-// Element element = outline.getElement();
-// return elementLabelProvider.getImage(element);
+ Outline outline = (Outline) obj;
+ ImageDescriptor descriptor = getImageDescriptor(outline);
+ if (descriptor != null) {
+ return registry.get(descriptor);
+ }
+ return null;
}
@Override
public StyledString getStyledText(Object obj) {
- throw new IllegalStateException("com.google.dart.server.Outline not yet supported.");
-// Outline outline = (Outline) obj;
-// Element element = outline.getElement();
-// return elementLabelProvider.getStyledText(element);
+ Outline outline = (Outline) obj;
+ StyledString styledString = new StyledString(getText(obj));
+ // append parameters
+ String parameters = outline.getParameters();
+ if (parameters != null) {
+ styledString.append(parameters, StyledString.DECORATIONS_STYLER);
+ }
+ // append return type
+ String returnType = outline.getReturnType();
+ if (!StringUtils.isEmpty(returnType)) {
+ ElementKind kind = outline.getKind();
+ if (kind == ElementKind.FIELD || kind == ElementKind.TOP_LEVEL_VARIABLE) {
+ styledString.append(" : " + returnType, StyledString.QUALIFIER_STYLER);
+ } else {
+ styledString.append(RIGHT_ARROW + returnType, StyledString.QUALIFIER_STYLER);
+ }
+ }
+ // done
+ return styledString;
}
@Override
public String getText(Object obj) {
- throw new IllegalStateException("com.google.dart.server.Outline not yet supported.");
-// Outline outline = (Outline) obj;
-// Element element = outline.getElement();
-// return elementLabelProvider.getText(element);
+ Outline outline = (Outline) obj;
+ return outline.getName();
}
}
@@ -191,8 +271,8 @@ public class DartOutlinePage_NEW extends Page implements IContentOutlinePage {
if (!(e2 instanceof Outline)) {
return 0;
}
- int offset1 = ((Outline) e1).getOffset();
- int offset2 = ((Outline) e2).getOffset();
+ int offset1 = ((Outline) e1).getNameOffset();
+ int offset2 = ((Outline) e2).getNameOffset();
return offset1 - offset2;
}
}

Powered by Google App Engine
This is Rietveld 408576698