コード例 #1
0
  public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
    List<ICompletionProposal> result = new ArrayList<ICompletionProposal>();

    try {
      IDocument document = viewer.getDocument();
      ITypedRegion partition = document.getPartition(offset);
      if (isOffsetValidForProposal(document, offset, partition.getOffset())) {
        result.add(
            new CompletionProposal("1 ", offset, 0, 2, null, "1 Heading level 1", null, null));
        result.add(
            new CompletionProposal("1.1 ", offset, 0, 4, null, "1.1 Heading level 2", null, null));
        result.add(
            new CompletionProposal(
                "1.1.1 ", offset, 0, 6, null, "1.1.1 Heading level 3", null, null));
        result.add(
            new CompletionProposal(
                "1.1.1.1 ", offset, 0, 8, null, "1.1.1.1 Heading level 4", null, null));
        result.add(
            new CompletionProposal(
                "1.1.1.1.1 ", offset, 0, 10, null, "1.1.1.1.1 Heading level 5", null, null));
        result.add(
            new CompletionProposal(
                "1.1.1.1.1.1 ", offset, 0, 12, null, "1.1.1.1.1.1 Heading level 6", null, null));
      }
    } catch (BadLocationException e) {
      CoreLog.logError("Content assist error", e);
    }

    if (result.size() > 0) {
      return result.toArray(new ICompletionProposal[result.size()]);
    }

    return null;
  }
コード例 #2
0
 private ITypedRegion getPartition(IDocument document, ITextSelection textSelection) {
   ITypedRegion region = null;
   if (textSelection != null) {
     try {
       region = document.getPartition(textSelection.getOffset());
     } catch (BadLocationException e) {
       region = null;
     }
   }
   return region;
 }
コード例 #3
0
ファイル: TagUtil.java プロジェクト: arcaneadam/studio3
 /**
  * Returns null when no match found! Assumes the document has been partitioned via HTML partition
  * scanner
  *
  * @param document
  * @param offset
  * @param partitionsToSearch A collection of the string partition names to search for tags.
  *     Optimization to avoid looking in non HTML/XML tags!
  * @return
  */
 public static IRegion findMatchingTag(
     IDocument document, int offset, Collection<String> partitionsToSearch) {
   try {
     ITypedRegion region = document.getPartition(offset);
     if (!partitionsToSearch.contains(region.getType())) {
       return null;
     }
     String src = document.get(region.getOffset(), region.getLength());
     if (src.startsWith("</")) // $NON-NLS-1$
     {
       return findMatchingOpen(document, region, partitionsToSearch);
     }
     // Handle self-closing tags!
     if (src.endsWith("/>")) // $NON-NLS-1$
     {
       return null;
     }
     return findMatchingClose(document, region, partitionsToSearch);
   } catch (BadLocationException e) {
     XMLPlugin.logError(e.getMessage(), e);
   }
   return null;
 }
コード例 #4
0
 /**
  * Returns the partition type located at offset in the document
  *
  * @param document - assumes document is not null
  * @param offset
  * @return String partition type
  */
 protected String getPartitionType(IDocument document, int offset) {
   String type = null;
   try {
     // TODO: provide partitioning information so we're not using a default like this
     if (document instanceof IStructuredDocument) {
       type =
           TextUtilities.getContentType(
               document, IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING, offset, false);
     }
   } catch (BadLocationException e1) {
   } finally {
     if (type == null) {
       try {
         ITypedRegion region = document.getPartition(offset);
         if (region != null) {
           type = region.getType();
         }
       } catch (BadLocationException e) {
         type = null;
       }
     }
   }
   return type;
 }