Пример #1
0
  public RefactoringInfo(PyEdit edit, ITextSelection selection) throws MisconfigurationException {
    IEditorInput input = edit.getEditorInput();
    this.indentPrefs = edit.getIndentPrefs();
    IPythonNature localNature = edit.getPythonNature();

    if (input instanceof IFileEditorInput) {
      IFileEditorInput editorInput = (IFileEditorInput) input;
      this.sourceFile = editorInput.getFile();
      this.realFile = sourceFile != null ? sourceFile.getLocation().toFile() : null;
    } else {
      this.realFile = edit.getEditorFile();
    }

    if (localNature == null) {
      Tuple<IPythonNature, String> infoForFile = PydevPlugin.getInfoForFile(this.realFile);
      if (infoForFile != null && infoForFile.o1 != null) {
        localNature = infoForFile.o1;
      }
    }
    this.nature = localNature;

    this.doc = edit.getDocument();

    this.project = edit.getProject();
    versionProvider = this.nature;
    initInfo(selection);
  }
Пример #2
0
  /**
   * @param markOccurrencesRequest
   * @return true if the annotations were removed and added without any problems and false otherwise
   */
  @Override
  protected synchronized Map<Annotation, Position> getAnnotationsToAddAsMap(
      final BaseEditor baseEditor,
      IAnnotationModel annotationModel,
      MarkOccurrencesRequest markOccurrencesRequest,
      IProgressMonitor monitor)
      throws BadLocationException {
    PyEdit pyEdit = (PyEdit) baseEditor;
    PySourceViewer viewer = pyEdit.getPySourceViewer();
    if (viewer == null || monitor.isCanceled()) {
      return null;
    }
    if (viewer.getIsInToggleCompletionStyle() || monitor.isCanceled()) {
      return null;
    }

    PyMarkOccurrencesRequest pyMarkOccurrencesRequest =
        (PyMarkOccurrencesRequest) markOccurrencesRequest;
    Set<ASTEntry> occurrences = pyMarkOccurrencesRequest.getOccurrences();
    if (occurrences == null) {
      if (DEBUG) {
        System.out.println("Occurrences == null");
      }
      return null;
    }

    IDocument doc = pyEdit.getDocument();
    Map<Annotation, Position> toAddAsMap = new HashMap<Annotation, Position>();
    boolean markOccurrencesInStrings = MarkOccurrencesPreferencesPage.useMarkOccurrencesInStrings();

    // get the annotations to add
    for (ASTEntry entry : occurrences) {
      if (!markOccurrencesInStrings) {
        if (entry.node instanceof Name) {
          Name name = (Name) entry.node;
          if (name.ctx == Name.Artificial) {
            continue;
          }
        }
      }

      SimpleNode node = entry.getNameNode();
      IRegion lineInformation = doc.getLineInformation(node.beginLine - 1);

      try {
        Annotation annotation = new Annotation(getOccurrenceAnnotationsType(), false, "occurrence");
        Position position =
            new Position(
                lineInformation.getOffset() + node.beginColumn - 1,
                pyMarkOccurrencesRequest.getInitialName().length());
        toAddAsMap.put(annotation, position);

      } catch (Exception e) {
        Log.log(e);
      }
    }
    return toAddAsMap;
  }
 public static List<IMarker> getMarkersFromCurrentFile(PyEdit edit, int line) {
   return getMarkersFromEditorResource(
       PyMarkerUtils.getResourceForTextEditor(edit),
       edit.getDocument(),
       getExternalFileEditorInput(edit),
       line,
       true,
       edit.getAnnotationModel());
 }