protected String getSourceHandle(IDeclaration declaration) {
   ITranslationUnit tu = declaration.getTranslationUnit();
   if (tu != null) {
     IPath location = tu.getLocation();
     if (location != null) {
       return location.toOSString();
     }
   }
   return ""; //$NON-NLS-1$
 }
Пример #2
0
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);

    if (selection == null) {
      return null;
    }

    if (selection instanceof IStructuredSelection) {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      PrintStream ps = new PrintStream(baos);

      Iterator<?> iter = ((IStructuredSelection) selection).iterator();
      while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof Executable) {
          Executable exe = (Executable) obj;
          ps.println(exe.getName());
        } else if (obj instanceof ITranslationUnit) {
          ITranslationUnit tu = (ITranslationUnit) obj;
          ps.println(tu.getLocation().toFile().getName());
        } else ps.println(obj.toString());
      }
      ps.flush();
      try {
        baos.flush();
      } catch (IOException e) {
        throw new ExecutionException("", e); // $NON-NLS-1$
      }
      Clipboard cp = getClipboard();
      cp.setContents(
          new Object[] {baos.toString().trim()}, new Transfer[] {TextTransfer.getInstance()});
    }

    return null;
  }