コード例 #1
0
ファイル: PyEditTitle.java プロジェクト: pmahoney/Pydev
  /** @return This is the Path that the editor is editing. */
  private IPath getPathFromInput(IEditorInput otherInput) {
    IPath path = null;
    if (otherInput instanceof IPathEditorInput) {
      IPathEditorInput iPathEditorInput = (IPathEditorInput) otherInput;
      try {
        path = iPathEditorInput.getPath();
      } catch (IllegalArgumentException e) {
        // ignore: we may have the trace below inside the FileEditorInput.
        // java.lang.IllegalArgumentException
        // at org.eclipse.ui.part.FileEditorInput.getPath(FileEditorInput.java:208)
        // at org.python.pydev.editor.PyEditTitle.getPathFromInput(PyEditTitle.java:751)

      }
    }
    if (path == null) {
      if (otherInput instanceof IFileEditorInput) {
        IFileEditorInput iFileEditorInput = (IFileEditorInput) otherInput;
        path = iFileEditorInput.getFile().getFullPath();
      }
    }
    if (path == null) {
      try {
        if (otherInput instanceof IURIEditorInput) {
          IURIEditorInput iuriEditorInput = (IURIEditorInput) otherInput;
          path = Path.fromOSString(new File(iuriEditorInput.getURI()).toString());
        }
      } catch (Throwable e) {
        // Ignore (IURIEditorInput not available on 3.2)
      }
    }
    return path;
  }
コード例 #2
0
  /** @return the IFile corresponding to the given input, or null if none */
  public static IFile getFile(IEditorInput editorInput) {
    IFile file = null;

    if (editorInput instanceof IFileEditorInput) {
      IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput;
      file = fileEditorInput.getFile();
    } else if (editorInput instanceof IPathEditorInput) {
      IPathEditorInput pathInput = (IPathEditorInput) editorInput;
      IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
      if (wsRoot.getLocation().isPrefixOf(pathInput.getPath())) {
        file = ResourcesPlugin.getWorkspace().getRoot().getFile(pathInput.getPath());
      } else {
        // Can't get an IFile for an arbitrary file on the file system; return null
      }
    } else if (editorInput instanceof IStorageEditorInput) {
      file = null; // Can't get an IFile for an arbitrary IStorageEditorInput
    } else if (editorInput instanceof IURIEditorInput) {
      IURIEditorInput uriEditorInput = (IURIEditorInput) editorInput;
      IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
      URI uri = uriEditorInput.getURI();
      String path = uri.getPath();
      // Bug 526: uri.getHost() can be null for a local file URL
      if (uri.getScheme().equals("file")
          && (uri.getHost() == null || uri.getHost().equals("localhost"))
          && !path.startsWith(wsRoot.getLocation().toOSString())) {
        file = wsRoot.getFile(new Path(path));
      }
    }
    return file;
  }
コード例 #3
0
  /**
   * Performs this action.
   *
   * @param action the action proxy that handles the presentation portion of the action
   */
  @Override
  public void run(IAction action) {
    IPathEditorInput originalInput = (IPathEditorInput) editor.getEditorInput();
    IEditorInput input = createEditorInput(originalInput.getPath().toString());

    // check if text editor plug-in is loaded
    if (Platform.getBundle(IOperationsConstants.ID_TEXT_EDITOR_PLUGIN) != null) {
      try {
        page.closeEditor(editor, true);
        page.openEditor(input, IOperationsConstants.ID_TEXT_EDITOR, true);
      } catch (PartInitException e) {
        MessageDialog.openWarning(
            page.getWorkbenchWindow().getShell(),
            Messages.OpenInTextEditorAction_0,
            Messages.OpenInTextEditorAction_1);
      }
    } else {
      MessageDialog.openError(
          page.getWorkbenchWindow().getShell(),
          Messages.OpenInTextEditorAction_0,
          Messages.OpenInTextEditorAction_2);
    }
  }
コード例 #4
0
ファイル: PyEditTitle.java プロジェクト: httpdss/Pydev
 /** @return This is the Path that the editor is editing. */
 private IPath getPathFromInput(IEditorInput otherInput) {
   IPath path = null;
   if (otherInput instanceof IPathEditorInput) {
     IPathEditorInput iPathEditorInput = (IPathEditorInput) otherInput;
     path = iPathEditorInput.getPath();
   }
   if (path == null) {
     if (otherInput instanceof IFileEditorInput) {
       IFileEditorInput iFileEditorInput = (IFileEditorInput) otherInput;
       path = iFileEditorInput.getFile().getFullPath();
     }
   }
   if (path == null) {
     try {
       if (otherInput instanceof IURIEditorInput) {
         IURIEditorInput iuriEditorInput = (IURIEditorInput) otherInput;
         path = Path.fromOSString(new File(iuriEditorInput.getURI()).toString());
       }
     } catch (Throwable e) {
       // Ignore (IURIEditorInput not available on 3.2)
     }
   }
   return path;
 }
コード例 #5
0
  @Override
  public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
    IPath path = null;

    try {
      IEditorInput input = editor.getEditorInput();

      if (input instanceof IPathEditorInput) {
        IPathEditorInput pathInput = (IPathEditorInput) input;
        path = pathInput.getPath();
      }
    } catch (NullPointerException npe) {

    }

    ArrayList<ICompletionProposal> results = new ArrayList<ICompletionProposal>();

    if (path != null) {
      String filename = path.toOSString();
      IDocument document = viewer.getDocument();
      CodeContext codeContext = codeContexts.get(filename);

      @SuppressWarnings("unused")
      int linenumber = 0;

      try {
        // the following starts on line 0?, so we add 1 to the result
        linenumber = document.getLineOfOffset(offset) + 1;
      } catch (BadLocationException e1) {
        GocodePlugin.logError(e1);
      }

      if (codeContext == null) {
        try {
          codeContext = CodeContext.getCodeContext(getProjectFor(editor), filename, document.get());
        } catch (IOException e) {
          GocodePlugin.logError(e);
        }
      }

      if (path != null) {
        String fileName = path.toOSString();

        List<String> completions =
            client.getCompletions(getProjectFor(editor), fileName, document.get(), offset);

        if (completions == null) {
          completions = Collections.emptyList();
        }

        for (String string : completions) {
          String prefix = "";
          prefix = lastWord(document, offset);
          int firstComma = string.indexOf(",,");
          int secondComma = string.indexOf(",,", firstComma + 2);

          if (firstComma != -1 && secondComma != -1) {
            String type = string.substring(0, firstComma);

            if ("PANIC".equals(type)) {
              GocodePlugin.logError("PANIC from gocode - likely go/gocode version mismatch?");
              continue;
            }

            String identifier = string.substring(firstComma + 2, secondComma);

            if ("PANIC".equals(identifier)) {
              GocodePlugin.logError("PANIC from gocode - likely go/gocode version mismatch?");
              continue;
            }

            String spec = string.substring(secondComma + 2);

            String descriptiveString = identifier + " : " + spec;
            String description = codeContext.getDescriptionForName(identifier).trim();
            IContextInformation info = new ContextInformation(description, description);
            // MessageFormat.format(JavaEditorMessages.getString("CompletionProcessor.Proposal.ContextInfo.pattern"), new Object[] { fgProposals[i] })); //$NON-NLS-1$

            Image image = defaultImage;
            String substr = identifier.substring(prefix.length());
            int replacementLength = identifier.length() - prefix.length();

            if (descriptiveString != null && descriptiveString.contains(" : func")) {
              if (codeContext.isMethodName(identifier)) {
                image = privateFuncImage;

              } else {
                image = funcImage;
              }

              substr = identifier.substring(prefix.length()) + "()";
              replacementLength++;

            } else if (descriptiveString != null && descriptiveString.contains(" : interface")) {
              image = interfaceImage;

            } else if (descriptiveString != null && descriptiveString.contains(" : struct")) {
              image = structImage;

            } else if ("package".equals(type)) {
              image = importImage;

              substr = identifier.substring(prefix.length()) + ".";
              replacementLength++;
            } else {
              if (substr != null
                  && substr.length() > 0
                  && Character.isUpperCase(substr.charAt(0))) {
                image = publicVarImage;

              } else {
                image = privateVarImage;
              }
            }

            // format the output
            descriptiveString =
                descriptiveString
                    .replace(" : func", " ")
                    .replace(" : interface", " ")
                    .replace(" : struct", " ")
                    .replace("(", "( ")
                    .replace(")", " )");

            results.add(
                new CompletionProposal(
                    identifier,
                    offset - prefix.length(),
                    prefix.length(),
                    identifier.length(),
                    image,
                    descriptiveString,
                    info,
                    description));
          }
        }
      }
    }

    return results.toArray(new ICompletionProposal[] {});
  }