예제 #1
0
 private boolean hasMatches(Object element) {
   if (element instanceof LineElement) {
     LineElement lineElement = (LineElement) element;
     return lineElement.getNumberOfMatches(fResult) > 0;
   }
   return fResult.getMatchCount(element) > 0;
 }
예제 #2
0
    private LineElement getLineElement(int offset, TextSearchMatchAccess matchRequestor) {
      int lineNumber = 1;
      int lineStart = 0;
      if (!fCachedMatches.isEmpty()) {
        // match on same line as last?
        FileMatch last = (FileMatch) fCachedMatches.get(fCachedMatches.size() - 1);
        LineElement lineElement = last.getLineElement();
        if (lineElement.contains(offset)) {
          return lineElement;
        }
        // start with the offset and line information from the last match
        lineStart = lineElement.getOffset() + lineElement.getLength();
        lineNumber = lineElement.getLine() + 1;
      }
      if (offset < lineStart) {
        return null; // offset before the last line
      }

      int i = lineStart;
      int contentLength = matchRequestor.getFileContentLength();
      while (i < contentLength) {
        char ch = matchRequestor.getFileContentChar(i++);
        if (ch == '\n' || ch == '\r') {
          if (ch == '\r' && i < contentLength && matchRequestor.getFileContentChar(i) == '\n') {
            i++;
          }
          if (offset < i) {
            String lineContent =
                getContents(matchRequestor, lineStart, i); // include line delimiter
            return new LineElement(matchRequestor.getFile(), lineNumber, lineStart, lineContent);
          }
          lineNumber++;
          lineStart = i;
        }
      }
      if (offset < i) {
        String lineContent = getContents(matchRequestor, lineStart, i); // until end of file
        return new LineElement(matchRequestor.getFile(), lineNumber, lineStart, lineContent);
      }
      return null; // offset outside of range
    }
예제 #3
0
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.search.internal.ui.text.IFileSearchContentProvider#
  * elementsChanged(java.lang.Object[])
  */
 public synchronized void elementsChanged(Object[] updatedElements) {
   for (int i = 0; i < updatedElements.length; i++) {
     if (!(updatedElements[i] instanceof LineElement)) {
       // change events to elements are reported in file search
       if (fResult.getMatchCount(updatedElements[i]) > 0) insert(updatedElements[i], true);
       else remove(updatedElements[i], true);
     } else {
       // change events to line elements are reported in text search
       LineElement lineElement = (LineElement) updatedElements[i];
       int nMatches = lineElement.getNumberOfMatches(fResult);
       if (nMatches > 0) {
         if (hasChild(lineElement.getParent(), lineElement)) {
           fTreeViewer.update(new Object[] {lineElement, lineElement.getParent()}, null);
         } else {
           insert(lineElement, true);
         }
       } else {
         remove(lineElement, true);
       }
     }
   }
 }