Package org.eclipse.wst.sse.core.internal.provisional.text

Examples of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion


    boolean insertSpace = false;
    String attrValueClose = null;
    if (oldAttr != null) {
      AttrImpl impl = (AttrImpl) oldAttr;
      ITextRegion nameRegion = impl.getNameRegion();
      if (nameRegion == null)
        return; // must never happen
      ITextRegion lastRegion = impl.getValueRegion();
      if (lastRegion != null) {
        end += lastRegion.getEnd();
      }
      else {
        lastRegion = impl.getEqualRegion();
        if (lastRegion != null) {
          end += lastRegion.getEnd();
        }
        else {
          end += nameRegion.getEnd();
          lastRegion = nameRegion;
        }
      }
      // check there are extra space before the last attribute
      IStructuredDocumentRegion flatNode = element.getStartStructuredDocumentRegion();
      if (flatNode == null)
        return; // must never happen
      ITextRegionList regions = flatNode.getRegions();
      if (regions == null)
        return; // must never happen
      ITextRegion prevRegion = null;
      ITextRegion nextRegion = null;
      for (int i = 0; i < regions.size(); i++) {
        ITextRegion region = regions.get(i);
        if (region == nameRegion) {
          if (i > 0) {
            prevRegion = regions.get(i - 1);
          }
        }
        if (region == lastRegion) {
          if (i + 1 < regions.size()) {
            nextRegion = regions.get(i + 1);
          }
          break;
        }
      }
      boolean isLastAttr = false;
      if (nextRegion != null) {
        String regionType = nextRegion.getType();
        if (regionType == DOMRegionContext.XML_TAG_CLOSE || regionType == DOMRegionContext.XML_EMPTY_TAG_CLOSE || isNestedTagClose(regionType)) {
          isLastAttr = true;
        }
      }
      if (isLastAttr && prevRegion != null) {
        start += prevRegion.getTextEnd();
      }
      else {
        start += nameRegion.getStart();
      }

      // impl.resetRegions(ownerElement);
      impl.resetRegions(element);
    }
    else { // append attribute
      IStructuredDocumentRegion flatNode = element.getStartStructuredDocumentRegion();
      if (flatNode == null)
        return; // must never happen

      attrValueClose = getAttrValueClose(element);
      if (attrValueClose != null && attrValueClose.length() > 0) {
        insertSpace = true;
        start = flatNode.getEndOffset();
        end = start;
      }
      else {
        ITextRegionList regions = flatNode.getRegions();
        if (regions == null)
          return; // must never happen
        int attrStart = 0;
        for (int i = regions.size() - 1; i >= 0; i--) {
          ITextRegion region = regions.get(i);
          String regionType = region.getType();
          if (regionType == DOMRegionContext.XML_TAG_CLOSE || regionType == DOMRegionContext.XML_EMPTY_TAG_CLOSE || isNestedTagClose(regionType))
            continue;
          int regionEnd = region.getEnd();
          if (regionEnd == region.getTextEnd())
            insertSpace = true;
          attrStart = regionEnd;
          break;
        }
        if (attrStart == 0)
View Full Code Here


      return;
    int index = -1;
    AttrImpl attr = null;
    Iterator e = regions.iterator();
    while (e.hasNext()) {
      ITextRegion region = (ITextRegion) e.next();
      String regionType = region.getType();
      if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
        attr = (AttrImpl) attributes.item(++index);
        if (attr != null) {
          attr.setNameRegion(region);
          // reset other regions
View Full Code Here

      return NodeImpl.EMPTY_STRING;
    ITextRegionList regions = flatNode.getRegions();
    if (regions == null)
      return NodeImpl.EMPTY_STRING;

    ITextRegion targetRegion = null;
    ITextRegion dataRegion = null;
    ITextRegion closeRegion = null;
    Iterator e = regions.iterator();
    while (e.hasNext()) {
      ITextRegion region = (ITextRegion) e.next();
      String regionType = region.getType();
      if (regionType == DOMRegionContext.XML_PI_OPEN)
        continue;
      if (regionType == DOMRegionContext.XML_PI_CLOSE) {
        closeRegion = region;
      }
View Full Code Here

      node = node.getParentNode();
    }
    IDOMNode xmlnode = (IDOMNode) node;
    ContentAssistRequest contentAssistRequest = null;
    IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
    ITextRegion completionRegion = getCompletionRegion(documentPosition,
        node);

    String matchString = getMatchString(sdRegion, completionRegion,
        documentPosition);
View Full Code Here

        int replaceLength = completionRegion.getTextLength();

        // if container region, be sure replace length is only the
        // attribute value region not the entire container
        if (completionRegion instanceof ITextRegionContainer) {
          ITextRegion openRegion = ((ITextRegionContainer) completionRegion)
              .getFirstRegion();
          ITextRegion closeRegion = ((ITextRegionContainer) completionRegion)
              .getLastRegion();

          /*
           * check to see if the container is opened the same way its
           * closed. Such as: <img src=' ' But not: <img src='
           *
           * </body> </html> In the latter case we only want to
           * replace the opening text of the container Admittedly
           * crude test, but effective.
           */
          if (openRegion.getType() != closeRegion.getType()) {
            replaceLength = openRegion.getTextLength();
          }
        }

        contentAssistRequest = new ContentAssistRequest(nodeAtOffset,
View Full Code Here

    int completionRegionStart = sdRegion.getStartOffset(completionRegion);
    int completionRegionLength = completionRegion.getLength();
    IStructuredDocumentRegion sdRegionAtCompletionOffset = node
        .getStructuredDocument().getRegionAtCharacterOffset(
            completionRegionStart + completionRegionLength);
    ITextRegion regionAtEndOfCompletion = sdRegionAtCompletionOffset
        .getRegionAtCharacterOffset(completionRegionStart
            + completionRegionLength);

    if ((documentPosition != completionRegionStart)
        && (regionAtEndOfCompletion != null)
        && (regionAtEndOfCompletion.getType() == DOMRegionContext.XML_TAG_NAME)) {
      ITextRegion nameRegion = regionAtEndOfCompletion;
      contentAssistRequest = new ContentAssistRequest(nodeAtOffset,
          nodeAtOffset.getParentNode(), sdRegion, completionRegion,
          sdRegion.getStartOffset(nameRegion),
          nameRegion.getTextLength(), matchString);
    } else {
      if (nodeAtOffset.getFirstStructuredDocumentRegion() == sdRegion) {
        // abnormal case, this unmatched end tag will be a sibling
        contentAssistRequest = new ContentAssistRequest(nodeAtOffset,
            nodeAtOffset.getParentNode(), sdRegion,
View Full Code Here

    int documentPosition = context.getInvocationOffset();
    ContentAssistRequest contentAssistRequest = null;
    IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
    System.out.println(sdRegion.toString());
    ITextRegion valueRegion = node.getStartStructuredDocumentRegion()
        .getRegionAtCharacterOffset(
            sdRegion.getStartOffset(completionRegion)
                + completionRegion.getLength());
    if ((valueRegion != null)
        && (valueRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)
        && (sdRegion.getStartOffset(valueRegion) <= documentPosition)) {
      // replace the adjacent attribute value
      contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node,
          sdRegion, valueRegion,
          sdRegion.getStartOffset(valueRegion),
          valueRegion.getTextLength(), matchString);
    } else {
      // append an attribute value after the '='
      contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node,
          sdRegion, completionRegion, documentPosition, 0,
          matchString);
View Full Code Here

          && (node.getEndStructuredDocumentRegion() == null)) {
        addEndTagProposals(contentAssistRequest, context);
      }
    } else {
      // at the start of the tag's close or within it
      ITextRegion closeRegion = sdRegion.getLastRegion();
      boolean insideTag = !sdRegion.isEnded()
          || (documentPosition <= sdRegion
              .getStartOffset(closeRegion));
      if (insideTag) {
        // this is a request for completions within a tag
View Full Code Here

              completionRegion.getTextLength(), matchString);
          addStartDocumentProposals(contentAssistRequest, context);
        }
      } else {
        // within the white space
        ITextRegion name = getNameRegion(node
            .getStartStructuredDocumentRegion());
        // (pa) ITextRegion refactor
        // if (name != null && name.containsOffset(documentPosition))
        // {
        if ((name != null)
            && ((sdRegion.getStartOffset(name) <= documentPosition) && (sdRegion
                .getEndOffset(name) >= documentPosition))
            && (sdRegion.getLastRegion().getType() == DOMRegionContext.XML_TAG_CLOSE || sdRegion
                .getLastRegion().getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE)) {

          // replace the existing name
          contentAssistRequest = new ContentAssistRequest(node,
              node.getParentNode(), sdRegion, completionRegion,
              sdRegion.getStartOffset(name),
              name.getTextLength(), matchString);
        } else {
          // insert a valid new name, or possibly an end tag
          contentAssistRequest = new ContentAssistRequest(
              nodeAtOffset,
              ((Node) nodeAtOffset).getParentNode(), sdRegion,
View Full Code Here

    return contentAssistRequest;
  }

  private ITextRegion getCompletionRegion(int offset,
      IStructuredDocumentRegion sdRegion) {
    ITextRegion region = sdRegion.getRegionAtCharacterOffset(offset);
    if (region == null) {
      return null;
    }

    if (sdRegion.getStartOffset(region) == offset) {
      // The offset is at the beginning of the region
      if ((sdRegion.getStartOffset(region) == sdRegion.getStartOffset())
          && (sdRegion.getPrevious() != null)
          && (!sdRegion.getPrevious().isEnded())) {
        // Is the region also the start of the node? If so, the
        // previous IStructuredDocumentRegion is
        // where to look for a useful region.
        region = sdRegion.getPrevious().getRegionAtCharacterOffset(
            offset - 1);
      } else {
        // Is there no separating whitespace from the previous region?
        // If not,
        // then that region is the important one
        ITextRegion previousRegion = sdRegion
            .getRegionAtCharacterOffset(offset - 1);
        if ((previousRegion != null)
            && (previousRegion != region)
            && (previousRegion.getTextLength() == previousRegion
                .getLength())) {
          region = previousRegion;
        }
      }
    } else {
      // The offset is NOT at the beginning of the region
      if (offset > sdRegion.getStartOffset(region)
          + region.getTextLength()) {
        // Is the offset within the whitespace after the text in this
        // region?
        // If so, use the next region
        ITextRegion nextRegion = sdRegion
            .getRegionAtCharacterOffset(sdRegion
                .getStartOffset(region) + region.getLength());
        if (nextRegion != null) {
          region = nextRegion;
        }
      } else {
        // Is the offset within the important text for this region?
        // If so, then we've already got the right one.
      }
    }

    // valid WHITE_SPACE region handler (#179924)
    if ((region != null)
        && (region.getType() == DOMRegionContext.WHITE_SPACE)) {
      ITextRegion previousRegion = sdRegion
          .getRegionAtCharacterOffset(sdRegion.getStartOffset(region) - 1);
      if (previousRegion != null) {
        region = previousRegion;
      }
    }
View Full Code Here

TOP

Related Classes of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.