/*
   * Method declared in IAction.
   */
  @Override
  public final void run() {
    DartElement inputElement = EditorUtility.getEditorInputJavaElement(fEditor, false);
    if (!(inputElement instanceof SourceReference && inputElement.exists())) {
      return;
    }

    SourceReference source = (SourceReference) inputElement;
    SourceRange sourceRange;
    try {
      sourceRange = source.getSourceRange();
      if (sourceRange == null || sourceRange.getLength() == 0) {
        MessageDialog.openInformation(
            fEditor.getEditorSite().getShell(),
            SelectionActionMessages.StructureSelect_error_title,
            SelectionActionMessages.StructureSelect_error_message);
        return;
      }
    } catch (DartModelException e) {
    }
    ITextSelection selection = getTextSelection();
    SourceRange newRange = getNewSelectionRange(createSourceRange(selection), source);
    // Check if new selection differs from current selection
    if (selection.getOffset() == newRange.getOffset()
        && selection.getLength() == newRange.getLength()) {
      return;
    }
    fSelectionHistory.remember(newSourceRange(selection.getOffset(), selection.getLength()));
    try {
      fSelectionHistory.ignoreSelectionChanges();
      fEditor.selectAndReveal(newRange.getOffset(), newRange.getLength());
    } finally {
      fSelectionHistory.listenToSelectionChanges();
    }
  }
Esempio n. 2
0
 private void addResult(String name, DartElement element, SearchListener listener)
     throws DartModelException {
   SourceRange range = null;
   switch (element.getElementType()) {
     case DartElement.FIELD:
     case DartElement.METHOD:
       SourceReference method = (SourceReference) element;
       range = method.getNameRange();
       break;
     default:
       return;
   }
   SearchMatch match = new SearchMatch(MatchQuality.EXACT, element, range);
   listener.matchFound(match);
 }
 protected static SourceRange getSelectedNodeSourceRange(SourceReference sr, DartNode nodeToSelect)
     throws DartModelException {
   int offset = nodeToSelect.getSourceStart();
   int end =
       Math.min(
           sr.getSourceRange().getLength(),
           nodeToSelect.getSourceStart() + nodeToSelect.getSourceLength() - 1);
   return createSourceRange(offset, end);
 }