コード例 #1
0
 public void update() {
   boolean enabled = false;
   ISourceReference ref = getSourceReference();
   if (ref != null) {
     ISourceRange range;
     try {
       range = ref.getSourceRange();
       enabled = range != null && range.getLength() > 0;
     } catch (ModelException e) {
       // enabled= false;
     }
   }
   setEnabled(enabled);
 }
コード例 #2
0
  /*
   * non java doc
   *
   * @see StructureSelectionAction#internalGetNewSelectionRange(ISourceRange,
   * ICompilationUnit, SelectionAnalyzer)
   */
  public ISourceRange internalGetNewSelectionRange(
      ISourceRange oldSourceRange, ISourceReference sr, SelectionAnalyzer selAnalyzer)
      throws ModelException {
    if (oldSourceRange.getLength() == 0 && selAnalyzer.getLastCoveringNode() != null) {
      ASTNode previousNode =
          NextNodeAnalyzer.perform(oldSourceRange.getOffset(), selAnalyzer.getLastCoveringNode());
      if (previousNode != null) return getSelectedNodeSourceRange(sr, previousNode);
    }
    org.eclipse.php.internal.core.ast.nodes.ASTNode first = selAnalyzer.getFirstSelectedNode();
    if (first == null) return getLastCoveringNodeRange(oldSourceRange, sr, selAnalyzer);

    org.eclipse.php.internal.core.ast.nodes.ASTNode parent = first.getParent();
    if (parent == null) return getLastCoveringNodeRange(oldSourceRange, sr, selAnalyzer);

    org.eclipse.php.internal.core.ast.nodes.ASTNode lastSelectedNode =
        selAnalyzer.getSelectedNodes()[selAnalyzer.getSelectedNodes().length - 1];
    org.eclipse.php.internal.core.ast.nodes.ASTNode nextNode =
        getNextNode(parent, lastSelectedNode);
    if (nextNode == parent) return getSelectedNodeSourceRange(sr, first.getParent());
    int offset = oldSourceRange.getOffset();
    int end = Math.min(sr.getSourceRange().getLength(), nextNode.getEnd() - 1);
    return createSourceRange(offset, end);
  }