Пример #1
0
  /*
   * Method declared on SelectionChangedAction.
   */
  @Override
  public void run(final ITextSelection selection) {
    // if (!ActionUtil.isProcessable(fEditor)) {
    // return;
    // }
    IErlModule module = fEditor.getModule();
    if (module == null) {
      return;
    }
    final Backend b = ErlangCore.getBackendManager().getIdeBackend();
    final ISelection sel = getSelection();
    final ITextSelection textSel = (ITextSelection) sel;
    final int offset = textSel.getOffset();
    try {
      String scannerModuleName = ErlangToolkit.createScannerModuleName(module);
      final OpenResult res =
          ErlideOpen.open(b, scannerModuleName, offset, "", ErlangCore.getModel().getPathVars());
      ErlLogger.debug("open " + res);

      // final String title =
      // "SearchMessages.SearchElementSelectionDialog_title";
      // final String message =
      // "SearchMessages.SearchElementSelectionDialog_message";

      if (res.isExternalCall()) {
        performNewSearch(SearchUtil.getRefFromOpenRes(res));
      }
    } catch (final Exception e) {
      // final String title = "SearchMessages.Search_Error_search_title";
      // final String message = "SearchMessages.Search_Error_codeResolve";
      // ExceptionHandler.handle(e, getShell(), title, message);
      ErlLogger.debug(e);
    }
  }
Пример #2
0
 @Override
 public Object execute(final ExecutionEvent event) throws ExecutionException {
   final ISelection selection = WorkbenchUIUtil.getCurrentSelection(event.getApplicationContext());
   final IWorkbenchPart activePart = WorkbenchUIUtil.getActivePart(event.getApplicationContext());
   if (selection == null || activePart == null) {
     return null;
   }
   final ISourceUnit su = LTKSelectionUtil.getSingleSourceUnit(activePart);
   if (!(su instanceof IRSourceUnit)) {
     return null;
   }
   ExtractFunctionRefactoring refactoring = null;
   if (selection instanceof ITextSelection) {
     final ITextSelection textSelection = (ITextSelection) selection;
     refactoring =
         new ExtractFunctionRefactoring(
             (IRSourceUnit) su, new Region(textSelection.getOffset(), textSelection.getLength()));
   }
   if (refactoring != null) {
     final RefactoringWizardExecutionHelper executionHelper =
         new RefactoringWizardExecutionHelper(
             new ExtractFunctionWizard(refactoring), RefactoringSaveHelper.SAVE_NOTHING);
     executionHelper.perform(activePart.getSite().getShell());
   }
   //			}
   //			catch (final CoreException e) {
   //				StatusManager.getManager().handle(new Status(
   //						IStatus.ERROR, RUI.PLUGIN_ID, -1,
   //						Messages.InlineTemp_Wizard_title, e),
   //						StatusManager.LOG | StatusManager.SHOW);
   //			}
   return null;
 }
  @SuppressWarnings("unchecked")
  protected static StatementSequence findEnclosingStatementSequence(
      IFortranAST ast, ITextSelection selection) {
    Token firstToken = findFirstTokenAfter(ast, selection.getOffset());
    Token lastToken = findLastTokenBefore(ast, selection.getOffset() + selection.getLength());
    if (firstToken == null || lastToken == null) return null;

    IASTListNode<? extends IASTNode> listContainingFirstToken =
        firstToken.findNearestAncestor(IASTListNode.class);
    IASTListNode<? extends IASTNode> listContainingLastToken =
        lastToken.findNearestAncestor(IASTListNode.class);
    if (listContainingFirstToken == null
        || listContainingLastToken == null
        || listContainingFirstToken != listContainingLastToken) return null;

    IASTListNode<? extends IASTNode> listContainingStmts = listContainingFirstToken;
    int startIndex = -1;
    int endIndex = -1;
    for (int i = 0; i < listContainingStmts.size(); i++) {
      IASTNode node = listContainingStmts.get(i);
      if (contains(node, firstToken)) startIndex = i;
      if (contains(node, lastToken)) endIndex = i;
    }
    if (startIndex < 0 || endIndex < 0 || endIndex < startIndex)
      throw new Error(
          "INTERNAL ERROR: Unable to locate selected statements in IASTListNode"); //$NON-NLS-1$

    return new StatementSequence(
        listContainingStmts.findNearestAncestor(ScopingNode.class),
        listContainingStmts,
        startIndex,
        endIndex);
  }
 @Override
 public void run(ITextSelection currentSelection) {
   if (currentSelection != null && editor != null) {
     GroovyCompilationUnit unit = editor.getGroovyCompilationUnit();
     if (unit != null) {
       ModuleNode node = unit.getModuleNode();
       if (node != null) {
         FindSurroundingNode finder =
             new FindSurroundingNode(
                 new Region(currentSelection.getOffset(), currentSelection.getLength()));
         IASTFragment result = finder.doVisitSurroundingNode(node);
         if (result != null) {
           TextSelection newSelection = new TextSelection(result.getStart(), result.getLength());
           if (!newSelection.equals(currentSelection)) {
             history.remember(
                 new SourceRange(currentSelection.getOffset(), currentSelection.getLength()));
             try {
               history.ignoreSelectionChanges();
               editor.selectAndReveal(result.getStart(), result.getLength());
             } finally {
               history.listenToSelectionChanges();
             }
           }
           editor.getSelectionProvider().setSelection(newSelection);
         }
       }
     }
   }
 }
 protected static ASTNode getNodeAtIndx(
     IFortranAST ast, ITextSelection selection, Class<? extends ASTNode> node, int off) {
   Token firstToken = findFirstTokenAfter(ast, selection.getOffset() + off);
   Token lastToken = findLastTokenBefore(ast, selection.getOffset() + selection.getLength());
   if (firstToken == null || lastToken == null) return null;
   return getNode(firstToken, lastToken, node);
 }
 /** end test code */
 protected static <T extends IASTNode> T getNode(
     IFortranAST ast, ITextSelection selection, Class<T> node) {
   Token firstToken = findFirstTokenAfter(ast, selection.getOffset());
   Token lastToken = findLastTokenBefore(ast, selection.getOffset() + selection.getLength());
   if (firstToken == null || lastToken == null) return null;
   return getNode(firstToken, lastToken, node);
 }
 public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection)
     throws CoreException {
   if (part instanceof IEditorPart) {
     IEditorPart editor = (IEditorPart) part;
     IResource resource = (IResource) editor.getEditorInput().getAdapter(IResource.class);
     ITextSelection textSelection = (ITextSelection) selection;
     int lineNumber = textSelection.getStartLine();
     IBreakpoint[] breakpoints =
         DebugPlugin.getDefault()
             .getBreakpointManager()
             .getBreakpoints(IDroolsDebugConstants.ID_DROOLS_DEBUG_MODEL);
     for (int i = 0; i < breakpoints.length; i++) {
       IBreakpoint breakpoint = breakpoints[i];
       if (resource.equals(breakpoint.getMarker().getResource())) {
         if (breakpoint.getMarker().getType().equals(IDroolsDebugConstants.DROOLS_MARKER_TYPE)) {
           if (((DroolsLineBreakpoint) breakpoint).getDRLLineNumber() == (lineNumber + 1)) {
             breakpoint.delete();
             return;
           }
         }
       }
     }
     // TODO: drools breakpoints can only be created in functions and consequences
     DroolsLineBreakpoint lineBreakpoint = new DroolsLineBreakpoint(resource, lineNumber + 1);
     DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint);
   }
 }
  /**
   * the command has been executed, so extract extract the needed information from the application
   * context.
   */
  public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (!ITextEditor.class.isAssignableFrom(activeEditor.getClass())) {
      return null;
    }
    ITextEditor iTextEditor = (ITextEditor) activeEditor;
    ISelection selection = iTextEditor.getSelectionProvider().getSelection();
    if (!ITextSelection.class.isAssignableFrom(selection.getClass())) {
      return null;
    }
    ITextSelection textSelection = (ITextSelection) selection;

    IHandlerService service =
        (IHandlerService) HandlerUtil.getActiveSite(event).getService(IHandlerService.class);
    try {
      if (textSelection.getLength() == 0) {
        service.executeCommand("org.eclipse.ui.edit.text.cut.line", null);
      } else {
        service.executeCommand("org.eclipse.ui.edit.cut", null);
      }
    } catch (NotDefinedException e) {
      throw new ExecutionException("Failed to cut line or selection", e);
    } catch (NotEnabledException e) {
      throw new ExecutionException("Failed to cut line or selection", e);
    } catch (NotHandledException e) {
      throw new ExecutionException("Failed to cut line or selection", e);
    }

    return null;
  }
  @Override
  public void run() {
    ITextSelection ts = (ITextSelection) editor.getSelectionProvider().getSelection();
    line = ts.getEndLine();
    try {
      terminateWithSemicolon();
      boolean changed;
      int count = 0;
      do {
        changed = terminateWithBrace();
        count++;
      } while (changed && count < 5);

      //			change = new DocumentChange("Terminate Statement", doc);
      //			change.setEdit(new MultiTextEdit());
      //			editor.getParseController().parse(doc, new NullProgressMonitor(), null);
      //			terminateWithParen(doc, change);
      //			change.perform(new NullProgressMonitor());

      editor.scheduleParsing();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 public boolean canToggleLineBreakpoints(IWorkbenchPart part, ISelection selection) {
   if (part instanceof IEditorPart && selection instanceof ITextSelection) {
     IEditorPart editor = (IEditorPart) part;
     IResource resource = (IResource) editor.getEditorInput().getAdapter(IResource.class);
     ITextSelection textSelection = (ITextSelection) selection;
     int lineNumber = textSelection.getStartLine();
     try {
       DRLInfo drlInfo = DroolsEclipsePlugin.getDefault().parseResource(resource, false);
       if (drlInfo != null) {
         RuleInfo ruleInfo = drlInfo.getRuleInfo(lineNumber);
         if (ruleInfo != null) {
           if (ruleInfo.getConsequenceDrlLineNumber() <= lineNumber) {
             return true;
           }
         }
         FunctionInfo functionInfo = drlInfo.getFunctionInfo(lineNumber);
         if (functionInfo != null) {
           if (functionInfo.getDrlLineNumber() <= lineNumber) {
             return true;
           }
         }
       }
     } catch (Throwable t) {
       DroolsEclipsePlugin.log(t);
     }
   }
   return false;
 }
  public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection)
      throws CoreException {
    if (selection instanceof ITextSelection) {
      ITextSelection textSel = (ITextSelection) selection;
      IEditorPart editorPart = (IEditorPart) part.getAdapter(IEditorPart.class);
      IFileEditorInput fileInput = (IFileEditorInput) editorPart.getEditorInput();
      final IFile origSrcFile = fileInput.getFile();
      final int lineNumber = textSel.getStartLine() + 1;

      IWorkspaceRunnable wr =
          new IWorkspaceRunnable() {
            public void run(IProgressMonitor monitor) throws CoreException {
              IMarker marker = findBreakpointMarker(origSrcFile, lineNumber);
              if (marker != null) {
                // The following will delete the associated marker
                clearLineBreakpoint(origSrcFile, lineNumber);
              } else {
                // The following will create a marker as a side-effect
                setLineBreakpoint(origSrcFile, lineNumber);
              }
            }
          };
      try {
        getWorkspace().run(wr, null);
      } catch (CoreException e) {
        throw new DebugException(e.getStatus());
      }
    }
  }
Пример #12
0
  /*
   * 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();
    }
  }
 public static SurroundWithTryCatchRefactoring create(
     ICompilationUnit cu, ITextSelection selection, boolean isMultiCatch) {
   return new SurroundWithTryCatchRefactoring(
       cu,
       Selection.createFromStartLength(selection.getOffset(), selection.getLength()),
       isMultiCatch);
 }
Пример #14
0
  @Override
  public void run() {
    ISearchQuery searchJob = null;

    ISelection selection = getSelection();
    if (selection instanceof IStructuredSelection) {
      Object object = ((IStructuredSelection) selection).getFirstElement();
      if (object instanceof ISourceReference) searchJob = createQuery((ISourceReference) object);
    } else if (selection instanceof ITextSelection) {
      ITextSelection selNode = (ITextSelection) selection;
      ICElement element = fEditor.getInputCElement();
      while (element != null && !(element instanceof ITranslationUnit))
        element = element.getParent();
      if (element != null) {
        if (selNode.getLength() == 0) {
          IDocument document = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
          IRegion reg = CWordFinder.findWord(document, selNode.getOffset());
          selNode = new TextSelection(document, reg.getOffset(), reg.getLength());
        }
        searchJob = createQuery(element, selNode);
      }
    }

    if (searchJob == null) {
      showStatusLineMessage(CSearchMessages.CSearchOperation_operationUnavailable_message);
      return;
    }

    clearStatusLine();
    NewSearchUI.activateSearchResultView();
    NewSearchUI.runQueryInBackground(searchJob);
  }
 private ICompletionProposal findCorrection(
     String id,
     boolean isAssist,
     ITextSelection selection,
     ICompilationUnit cu,
     IAnnotationModel model) {
   AssistContext context =
       new AssistContext(
           cu, fEditor.getViewer(), fEditor, selection.getOffset(), selection.getLength());
   Collection<IJavaCompletionProposal> proposals = new ArrayList<IJavaCompletionProposal>(10);
   if (isAssist) {
     if (id.equals(LinkedNamesAssistProposal.ASSIST_ID)) {
       return getLocalRenameProposal(context); // shortcut for local rename
     }
     JavaCorrectionProcessor.collectAssists(context, new ProblemLocation[0], proposals);
   } else {
     try {
       boolean goToClosest = selection.getLength() == 0;
       Annotation[] annotations = getAnnotations(selection.getOffset(), goToClosest);
       JavaCorrectionProcessor.collectProposals(
           context, model, annotations, true, false, proposals);
     } catch (BadLocationException e) {
       return null;
     }
   }
   for (Iterator<IJavaCompletionProposal> iter = proposals.iterator(); iter.hasNext(); ) {
     Object curr = iter.next();
     if (curr instanceof ICommandAccess) {
       if (id.equals(((ICommandAccess) curr).getCommandId())) {
         return (ICompletionProposal) curr;
       }
     }
   }
   return null;
 }
 /* (non-Javadoc)
  * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleLineBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
  */
 @Override
 public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection)
     throws CoreException {
   ITextEditor textEditor = getEditor(part);
   if (textEditor != null) {
     IResource resource = textEditor.getEditorInput().getAdapter(IResource.class);
     ITextSelection textSelection = (ITextSelection) selection;
     int lineNumber = textSelection.getStartLine();
     IBreakpoint[] breakpoints =
         DebugPlugin.getDefault()
             .getBreakpointManager()
             .getBreakpoints(DebugCorePlugin.ID_PDA_DEBUG_MODEL);
     for (int i = 0; i < breakpoints.length; i++) {
       IBreakpoint breakpoint = breakpoints[i];
       if (breakpoint instanceof ILineBreakpoint
           && resource.equals(breakpoint.getMarker().getResource())) {
         if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber + 1)) {
           // remove
           breakpoint.delete();
           return;
         }
       }
     }
     // create line breakpoint (doc line numbers start at 0)
     PDALineBreakpoint lineBreakpoint = new PDALineBreakpoint(resource, lineNumber + 1);
     DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint);
   }
 }
Пример #17
0
  @Override
  public void run(IAction action) {

    try {
      IWorkbenchWindow windoow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
      RefactoringWizard wizard = new RefactoringWizard();

      ITextSelection textSelection = getITextSelection();

      int startLine = textSelection.getStartLine() + 1;
      int endLine = textSelection.getEndLine() + 1;
      InOneMethodVisitor iomv = new InOneMethodVisitor(getICompilationUnit(), startLine, endLine);
      if (iomv.isInOne()) {
        wizard.init(windoow.getWorkbench(), getICompilationUnit(), getITextSelection());
        WizardDialog dialog = new WizardDialog(shell, wizard);
        dialog.open();
      } else {
        throw new Exception("Selected Code Block Illegal!");
      }

    } catch (Exception e) {
      // TODO Auto-generated catch block
      alert(e);
      e.printStackTrace();
    }
  }
 /**
  * Returns the variable and function names at the current line, or <code>null</code> if none.
  *
  * @param part text editor
  * @param selection text selection
  * @return the variable and function names at the current line, or <code>null</code> if none. The
  *     array has two elements, the first is the variable name, the second is the function name.
  */
 protected String[] getVariableAndFunctionName(IWorkbenchPart part, ISelection selection) {
   ITextEditor editor = getEditor(part);
   if (editor != null && selection instanceof ITextSelection) {
     ITextSelection textSelection = (ITextSelection) selection;
     IDocumentProvider documentProvider = editor.getDocumentProvider();
     try {
       documentProvider.connect(this);
       IDocument document = documentProvider.getDocument(editor.getEditorInput());
       IRegion region = document.getLineInformationOfOffset(textSelection.getOffset());
       String string = document.get(region.getOffset(), region.getLength()).trim();
       if (string.startsWith("var ")) { // $NON-NLS-1$
         String varName = string.substring(4).trim();
         String fcnName =
             getFunctionName(
                 document, varName, document.getLineOfOffset(textSelection.getOffset()));
         return new String[] {varName, fcnName};
       }
     } catch (CoreException e) {
     } catch (BadLocationException e) {
     } finally {
       documentProvider.disconnect(this);
     }
   }
   return null;
 }
Пример #19
0
 public static @Nullable Notifier getTextSelection(
     final @NonNull ITextSelection selection, @Nullable IWorkbenchPart part) {
   if (selection.getStartLine() < 0 || selection.getEndLine() < 0) {
     return null;
   }
   if (!(part instanceof XtextEditor)) {
     return null;
   }
   IXtextDocument document = ((XtextEditor) part).getDocument();
   Notifier selectedObject =
       document.readOnly(
           new IUnitOfWork<Notifier, XtextResource>() {
             public Notifier exec(XtextResource xtextResource) {
               if (xtextResource == null) {
                 return null;
               }
               IParseResult parseResult = xtextResource.getParseResult();
               if (parseResult == null) throw new NullPointerException("parseResult is null");
               ICompositeNode rootNode = parseResult.getRootNode();
               INode lastVisibleNode =
                   NodeModelUtils.findLeafNodeAtOffset(rootNode, selection.getOffset());
               if (lastVisibleNode == null) {
                 return null;
               }
               EObject currentModel = NodeModelUtils.findActualSemanticObjectFor(lastVisibleNode);
               //				if (currentModel instanceof Pivotable) {
               //					return ((Pivotable)currentModel).getPivot();
               //				}
               //				else {
               return currentModel;
               //				}
             }
           });
   return selectedObject;
 }
Пример #20
0
 /**
  * @see com.mulgasoft.emacsplus.commands.EmacsPlusCmdHandler#transform(ITextEditor, IDocument,
  *     ITextSelection, ExecutionEvent)
  */
 @Override
 protected int transform(
     ITextEditor editor, IDocument document, ITextSelection currentSelection, ExecutionEvent event)
     throws BadLocationException {
   int result = getCursorOffset(editor, currentSelection);
   // get the selection encompassing the appropriate set of lines
   ITextSelection selection = getLineSelection(editor, document, currentSelection);
   if (selection != null) {
     int offset = selection.getOffset();
     int endOffset = offset + selection.getLength();
     int begin = document.getLineOfOffset(offset);
     int end = document.getLineOfOffset(endOffset);
     if (begin != end && begin < end) {
       ArrayList<String> alst = new ArrayList<String>();
       IRegion region = document.getLineInformation(begin);
       // get text from point or mark
       alst.add(document.get(offset, region.getLength() - (offset - region.getOffset())));
       for (int i = begin + 1; i < end; i++) {
         region = document.getLineInformation(i);
         // get full line of text
         alst.add(document.get(region.getOffset(), region.getLength()));
       }
       region = document.getLineInformation(end);
       // get text to point or mark
       alst.add(document.get(region.getOffset(), endOffset - region.getOffset()));
       Collections.sort(alst, (getComparator(isUniversalPresent())));
       updateLines(document, selection, alst.toArray(new String[0]));
     } else {
       EmacsPlusUtils.showMessage(editor, NO_REGION, true);
     }
   } else {
     EmacsPlusUtils.showMessage(editor, NO_REGION, true);
   }
   return result;
 }
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    DMDLMultiPageEditor multiEditor = (DMDLMultiPageEditor) HandlerUtil.getActiveEditor(event);
    DMDLTextEditor editor = (DMDLTextEditor) multiEditor.getActiveEditor();
    DMDLDocument document = editor.getDocument();
    ModelList models = document.getModelList();

    ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
    int offset = selection.getOffset();
    DMDLToken token = models.getTokenByOffset(offset);
    if (token != null && token instanceof WordToken) {
      WordToken word = (WordToken) token;
      switch (word.getWordType()) {
        case REF_MODEL_NAME:
        case REF_PROPERTY_NAME:
          DMDLHyperlink link = new DMDLHyperlink(editor, token);
          link.open();
          break;
        default:
          break;
      }
    }

    return null;
  }
  /* (non-Javadoc)
   * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleLineBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
   */
  public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection)
      throws CoreException {
    IEditorPart editorPart = (IEditorPart) part;
    IEditorInput editorInput = editorPart.getEditorInput();
    IResource resource = null;
    if (editorInput instanceof IFileEditorInput) {
      resource = ((IFileEditorInput) editorInput).getFile();
    }
    if (resource == null) {
      Display.getCurrent().beep();
      return;
    }

    ITextSelection textSelection = (ITextSelection) selection;
    int lineNumber = textSelection.getStartLine();
    IBreakpoint[] breakpoints =
        DebugPlugin.getDefault()
            .getBreakpointManager()
            .getBreakpoints(IAntDebugConstants.ID_ANT_DEBUG_MODEL);
    for (int i = 0; i < breakpoints.length; i++) {
      IBreakpoint breakpoint = breakpoints[i];
      if (resource.equals(breakpoint.getMarker().getResource())) {
        if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber + 1)) {
          DebugUITools.deleteBreakpoints(
              new IBreakpoint[] {breakpoint}, part.getSite().getShell(), null);
          return;
        }
      }
    }
    // create line breakpoint (doc line numbers start at 0)
    new AntLineBreakpoint(resource, lineNumber + 1);
  }
  @Override
  public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection)
      throws CoreException {
    AbstractTextEditor editor = getEditor(part);

    if (editor != null) {
      IResource resource = (IResource) editor.getEditorInput().getAdapter(IResource.class);

      ITextSelection textSelection = (ITextSelection) selection;

      int lineNumber = textSelection.getStartLine() + 1;

      IBreakpoint[] breakpoints =
          DebugPlugin.getDefault()
              .getBreakpointManager()
              .getBreakpoints(DartDebugCorePlugin.DEBUG_MODEL_ID);

      for (int i = 0; i < breakpoints.length; i++) {
        IBreakpoint breakpoint = breakpoints[i];

        if (resource.equals(breakpoint.getMarker().getResource())) {
          if (((ILineBreakpoint) breakpoint).getLineNumber() == lineNumber) {
            breakpoint.delete();
            return;
          }
        }
      }

      DartBreakpoint breakpoint = new DartBreakpoint(resource, lineNumber);

      DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(breakpoint);
    }
  }
Пример #24
0
 public SearchPatternData tryErlangTextSelection(
     final SearchPatternData initData0, final IEditorPart activePart) throws ErlModelException {
   final AbstractErlangEditor erlangEditor = (AbstractErlangEditor) activePart;
   final IErlModule module = erlangEditor.getModule();
   SearchPatternData initData = initData0;
   if (module != null) {
     final ISelection ssel = erlangEditor.getSite().getSelectionProvider().getSelection();
     final ITextSelection textSel = (ITextSelection) ssel;
     final int offset = textSel.getOffset();
     OpenResult res;
     try {
       res =
           ErlangEngine.getInstance()
               .getService(OpenService.class)
               .open(
                   module.getScannerName(),
                   offset,
                   ErlangEngine.getInstance().getModelUtilService().getImportsAsList(module),
                   "",
                   ErlangEngine.getInstance().getModel().getPathVars());
     } catch (final RpcException e) {
       res = null;
     }
     ErlLogger.debug("searchPage(open) " + res);
     initData = determineInitValuesFrom(module, offset, res);
   }
   return initData;
 }
Пример #25
0
  void processAction(ITextEditor textEditor, IDocument document, ITextSelection textSelection) {
    int openCommentOffset = textSelection.getOffset();
    int closeCommentOffset = openCommentOffset + textSelection.getLength();

    if (textSelection.getLength() == 0) {
      return;
    }

    IStructuredModel model =
        StructuredModelManager.getModelManager().getExistingModelForEdit(document);
    if (model != null) {
      try {
        model.beginRecording(this, PHPUIMessages.AddBlockComment_tooltip);
        model.aboutToChangeModel();

        try {
          document.replace(closeCommentOffset, 0, CLOSE_COMMENT);
          document.replace(openCommentOffset, 0, OPEN_COMMENT);
        } catch (BadLocationException e) {
          Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
        } finally {
          model.changedModel();
          model.endRecording(this);
        }
      } finally {
        model.releaseFromEdit();
      }
    }
  }
 /* (non-JavaDoc)
  * Method declared in IAction.
  */
 public final void run() {
   ITextSelection selection = getTextSelection();
   ISourceRange newRange = getNewSelectionRange(createSourceRange(selection), null);
   // Check if new selection differs from current selection
   if (selection.getOffset() == newRange.getOffset()
       && selection.getLength() == newRange.getLength()) return;
   fEditor.selectAndReveal(newRange.getOffset(), newRange.getLength());
 }
Пример #27
0
 @Override
 public void run(ITextSelection selection) {
   if (!ActionUtil.isEditable(fEditor)) return;
   RefactoringExecutionStarter.startChangeTypeRefactoring(
       SelectionConverter.getInputAsCompilationUnit(fEditor),
       getShell(),
       selection.getOffset(),
       selection.getLength());
 }
Пример #28
0
  public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    ITextEditor textEditor = null;
    if (editor instanceof ITextEditor) textEditor = (ITextEditor) editor;
    else {
      Object o = editor.getAdapter(ITextEditor.class);
      if (o != null) textEditor = (ITextEditor) o;
    }
    if (textEditor != null) {
      IDocument document =
          textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());

      if (document != null) {
        // get current text selection
        ITextSelection textSelection = getCurrentSelection(textEditor);

        // If there is alternating or more then one block in the text
        // selection, action is aborted !
        if (isMoreThanOneContextBlockSelected(document, textSelection)) {
          // displayCommentActinosErrorDialog(editor);
          // return null;
          org.eclipse.wst.sse.ui.internal.handlers.AddBlockCommentHandler
              addBlockCommentHandlerWST =
                  new org.eclipse.wst.sse.ui.internal.handlers
                      .AddBlockCommentHandler(); // org.eclipse.wst.sse.ui.internal.handlers.AddBlockCommentHandler();
          return addBlockCommentHandlerWST.execute(event);
        }

        if (textSelection.isEmpty()) {
          return null;
        }
        if (document instanceof IStructuredDocument) {
          int selectionOffset = textSelection.getOffset();
          IStructuredDocument sDoc = (IStructuredDocument) document;
          IStructuredDocumentRegion sdRegion = sDoc.getRegionAtCharacterOffset(selectionOffset);
          ITextRegion textRegion = sdRegion.getRegionAtCharacterOffset(selectionOffset);

          ITextRegionCollection container = sdRegion;

          if (textRegion instanceof ITextRegionContainer) {
            container = (ITextRegionContainer) textRegion;
            textRegion = container.getRegionAtCharacterOffset(selectionOffset);
          }
          if (textRegion.getType() == PHPRegionContext.PHP_CONTENT) {
            processAction(textEditor, document, textSelection);
          } else {
            org.eclipse.wst.sse.ui.internal.handlers.AddBlockCommentHandler
                addBlockCommentHandlerWST =
                    new org.eclipse.wst.sse.ui.internal.handlers.AddBlockCommentHandler();
            return addBlockCommentHandlerWST.execute(event);
          }
        }
      }
    }
    return null;
  }
 private List<Statement> getStatements(Tree.Body body, ITextSelection selection) {
   List<Statement> statements = new ArrayList<Statement>();
   for (Tree.Statement s : body.getStatements()) {
     if (s.getStartIndex() >= selection.getOffset()
         && s.getStopIndex() <= selection.getOffset() + selection.getLength()) {
       statements.add(s);
     }
   }
   return statements;
 }
Пример #30
0
 /** @return the Selected text */
 public String getSelectedText() {
   ITextSelection txtSel = getTextSelection();
   int start = txtSel.getOffset();
   int len = txtSel.getLength();
   try {
     return this.doc.get(start, len);
   } catch (BadLocationException e) {
     throw new RuntimeException(e);
   }
 }