protected CompoundRegion[] getRegions(
      IStructuredDocument model, IRegion reg, IRegion exceptFor, String pickupType) {
    int start = reg.getOffset();
    int end = reg.getOffset() + reg.getLength();
    int startE = (exceptFor != null) ? exceptFor.getOffset() : -1;
    int endE = (exceptFor != null) ? exceptFor.getOffset() + exceptFor.getLength() : 0;

    ArrayList list = new ArrayList();
    IStructuredDocumentRegion flatNode = model.getRegionAtCharacterOffset(start);
    boolean pickuped = false;
    while (flatNode != null && flatNode.getStartOffset() < end) {
      ITextRegionList regionList = flatNode.getRegions();
      Iterator it = regionList.iterator();
      while (it.hasNext()) {
        ITextRegion region = (ITextRegion) it.next();
        if (flatNode.getStartOffset(region) < start) continue;
        if (end <= flatNode.getStartOffset(region)) break;
        if (startE >= 0
            && startE <= flatNode.getStartOffset(region)
            && flatNode.getEndOffset(region) <= endE) continue;
        if (region.getType() == CSSRegionContexts.CSS_COMMENT
            || region.getType() == CSSRegionContexts.CSS_CDC
            || region.getType() == CSSRegionContexts.CSS_CDO)
          list.add(new CompoundRegion(flatNode, region));
        else if (!pickuped && region.getType() == pickupType) {
          list.add(new CompoundRegion(flatNode, region));
          pickuped = true;
        }
      }
      flatNode = flatNode.getNext();
    }
    if (list.size() > 0) {
      CompoundRegion[] regions = new CompoundRegion[list.size()];
      list.toArray(regions);
      return regions;
    }
    return new CompoundRegion[0];
  }
Example #2
0
 /**
  * Return 'node' indexed start name's end position Example: <a>|aaa </a>, the position is
  * indicated by '|'
  *
  * @param node
  * @return the index
  */
 public static int getNodeStartNameEndIndex(Node node) {
   if (isText(node)) {
     return getNodeStartIndex(node);
   }
   if (EditValidateUtil.validNode(node) && node instanceof IDOMNode) {
     IStructuredDocumentRegion region = ((IDOMNode) node).getStartStructuredDocumentRegion();
     if (region != null) {
       return region.getEndOffset();
     }
     // else
     // {
     // // if (node.hasChildNodes())
     // // {
     // // // Node should always have start name, so this part should
     // never reach,
     // // // the assert is for inner debug.
     // // Assert.isTrue(false);
     // // return getNodeStartIndex(node);
     // // }
     // }
   }
   // This should never happen.
   return getNodeStartIndex(node);
 }
  @Override
  public boolean prepareTextRegions(
      IStructuredDocumentRegion structuredDocumentRegion,
      int partitionStartOffset,
      int partitionLength,
      Collection<StyleRange> holdResults) {

    boolean handled = false;
    final int partitionEndOffset = partitionStartOffset + partitionLength - 1;
    while (structuredDocumentRegion != null
        && structuredDocumentRegion.getStartOffset() <= partitionEndOffset) {
      ITextRegion region = null;
      ITextRegionList regions = structuredDocumentRegion.getRegions();
      int nRegions = regions.size();
      StyleRange styleRange = null;

      for (int i = 0; i < nRegions; i++) {
        region = regions.get(i);

        TextAttribute attr = null;
        //                TextAttribute previousAttr = null;
        final int startOffset = structuredDocumentRegion.getStartOffset(region);

        if (startOffset > partitionEndOffset) break;
        if (structuredDocumentRegion.getEndOffset(region) <= partitionStartOffset) continue;

        if (region instanceof ITextRegionCollection) {
          handled =
              prepareTextRegion(
                  (ITextRegionCollection) region,
                  partitionStartOffset,
                  partitionLength,
                  holdResults);
        } else {

          if (region.getType() == TwigRegionContext.TWIG_CONTENT
              || region.getType() == TwigRegionContext.TWIG_COMMENT) {
            handled =
                prepareTwigRegions(
                    holdResults,
                    (ITwigScriptRegion) region,
                    startOffset,
                    partitionStartOffset,
                    partitionLength);
          } else {

            attr = getAttributeFor(region);
            if (attr != null) {
              handled = true;
              styleRange =
                  createStyleRange(
                      structuredDocumentRegion,
                      region,
                      attr,
                      partitionStartOffset,
                      partitionLength);
              holdResults.add(styleRange);
              // technically speaking, we don't need to update
              // previousAttr
              // in the other case, because the other case is
              // when it hasn't changed
              //                            previousAttr = attr;
            } else {
              //                            previousAttr = null;
            }
          }
        }
      }
      structuredDocumentRegion = structuredDocumentRegion.getNext();
    }
    return handled;
  }
 protected void prepareText(IStructuredDocumentRegion sdRegion) {
   fStrippedText =
       fTextBefore = fTextToParse.substring(sdRegion.getStartOffset(), sdRegion.getEndOffset());
 }