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

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


   */
  public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
    IDOMNode node = (IDOMNode) ContentAssistUtils.getNodeAt(viewer, offset);
    IStructuredDocumentRegion startStructuredDocumentRegion = node.getStartStructuredDocumentRegion();
    int index = startStructuredDocumentRegion.getEndOffset();
    ITextRegion lastRegion = startStructuredDocumentRegion.getLastRegion();
    if (lastRegion.getType() == DOMRegionContext.XML_TAG_CLOSE) {
      index--;
      lastRegion = startStructuredDocumentRegion.getRegionAtCharacterOffset(index - 1);
    }
    else if (lastRegion.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
      index = index - 2;
      lastRegion = startStructuredDocumentRegion.getRegionAtCharacterOffset(index - 1);
    }
    MultiTextEdit multiTextEdit = new MultiTextEdit();
    try {
      for (int i = 0; i < fRequiredAttrs.size(); i++) {
        CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) fRequiredAttrs.get(i);
        String requiredAttributeName = attrDecl.getAttrName();
        String defaultValue = attrDecl.getDefaultValue();
        if (defaultValue == null) {
          defaultValue = ""; //$NON-NLS-1$
        }
        String nameAndDefaultValue = " "; //$NON-NLS-1$
        if ((i == 0) && (lastRegion.getLength() > lastRegion.getTextLength())) {
          nameAndDefaultValue = ""; //$NON-NLS-1$
        }
        nameAndDefaultValue += requiredAttributeName + "=\"" + defaultValue + "\""; //$NON-NLS-1$//$NON-NLS-2$
        multiTextEdit.addChild(new InsertEdit(index, nameAndDefaultValue));
        // BUG3381: MultiTextEdit applies all child TextEdit's basing
View Full Code Here


    // check if change is only for close tag
    if (newRegions != null) {
      Iterator e = newRegions.iterator();
      while (e.hasNext()) {
        ITextRegion region = (ITextRegion) e.next();
        String regionType = region.getType();
        if (regionType == DOMRegionContext.XML_TAG_CLOSE)
          continue;

        // other region has changed
        changeStructuredDocumentRegion(flatNode);
        return;
      }
    }
    if (oldRegions != null) {
      Iterator e = oldRegions.iterator();
      while (e.hasNext()) {
        ITextRegion region = (ITextRegion) e.next();
        String regionType = region.getType();
        if (regionType == DOMRegionContext.XML_TAG_CLOSE)
          continue;

        // other region has changed
        changeStructuredDocumentRegion(flatNode);
View Full Code Here

    // check if changes are only for attributes and close tag
    boolean tagNameUnchanged = false;
    if (newRegions != null) {
      Iterator e = newRegions.iterator();
      while (e.hasNext()) {
        ITextRegion region = (ITextRegion) e.next();
        String regionType = region.getType();
        if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME || regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS || regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)
          continue;
        if (regionType == DOMRegionContext.XML_TAG_CLOSE) {
          // change from empty tag may have impact on structure
          if (!element.isEmptyTag())
            continue;
        }
        else if (regionType == DOMRegionContext.XML_TAG_NAME || isNestedTagName(regionType)) {
          String oldTagName = element.getTagName();
          String newTagName = flatNode.getText(region);
          if (oldTagName != null && newTagName != null && oldTagName.equals(newTagName)) {
            // the tag name is unchanged
            tagNameUnchanged = true;
            continue;
          }
        }

        // other region has changed
        changeStructuredDocumentRegion(flatNode);
        return;
      }
    }
    if (oldRegions != null) {
      Iterator e = oldRegions.iterator();
      while (e.hasNext()) {
        ITextRegion region = (ITextRegion) e.next();
        String regionType = region.getType();
        if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME || regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS || regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)
          continue;
        if (regionType == DOMRegionContext.XML_TAG_CLOSE) {
          // change from empty tag may have impact on structure
          if (!element.isEmptyTag())
            continue;
        }
        else if (regionType == DOMRegionContext.XML_TAG_NAME || isNestedTagName(regionType)) {
          // if new tag name is unchanged, it's OK
          if (tagNameUnchanged)
            continue;
        }

        // other region has changed
        changeStructuredDocumentRegion(flatNode);
        return;
      }
    }

    // update attributes
    ITextRegionList regions = flatNode.getRegions();
    if (regions == null)
      return; // error
    NamedNodeMap attributes = element.getAttributes();
    if (attributes == null)
      return; // error

    // first remove attributes
    int regionIndex = 0;
    int attrIndex = 0;
    AttrImpl attr = null;
    while (attrIndex < attributes.getLength()) {
      attr = (AttrImpl) attributes.item(attrIndex);
      if (attr == null) { // error
        attrIndex++;
        continue;
      }
      ITextRegion nameRegion = attr.getNameRegion();
      if (nameRegion == null) { // error
        element.removeAttributeNode(attr);
        continue;
      }
      boolean found = false;
      for (int i = regionIndex; i < regions.size(); i++) {
        ITextRegion region = regions.get(i);
        if (region == nameRegion) {
          regionIndex = i + 1; // next region
          found = true;
          break;
        }
      }
      if (found) {
        attrIndex++;
      }
      else {
        element.removeAttributeNode(attr);
      }
    }

    // insert or update attributes
    attrIndex = 0; // reset to first
    AttrImpl newAttr = null;
    ITextRegion oldValueRegion = null;
    Iterator e = regions.iterator();
    while (e.hasNext()) {
      ITextRegion region = (ITextRegion) e.next();
      String regionType = region.getType();
      if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
        if (newAttr != null) {
          // insert deferred new attribute
          element.insertAttributeNode(newAttr, attrIndex++);
          newAttr = null;
View Full Code Here

    StringBuffer data = null;
    boolean isJSPTag = false;
    Iterator e = regions.iterator();
    while (e.hasNext()) {
      ITextRegion region = (ITextRegion) e.next();
      String regionType = region.getType();
      if (isNestedCommentOpen(regionType)) {
        isJSPTag = true;
      }
      else if (regionType == DOMRegionContext.XML_COMMENT_TEXT || isNestedCommentText(regionType)) {
        if (data == null) {
View Full Code Here

    String name = null;
    String publicId = null;
    String systemId = null;
    Iterator e = regions.iterator();
    while (e.hasNext()) {
      ITextRegion region = (ITextRegion) e.next();
      String regionType = region.getType();
      if (regionType == DOMRegionContext.XML_DOCTYPE_DECLARATION) {
        isDocType = true;
      }
      else if (regionType == DOMRegionContext.XML_DOCTYPE_NAME) {
        if (name == null)
View Full Code Here

      return;

    String tagName = null;
    Iterator e = regions.iterator();
    while (e.hasNext()) {
      ITextRegion region = (ITextRegion) e.next();
      String regionType = region.getType();
      if (regionType == DOMRegionContext.XML_TAG_NAME || isNestedTagName(regionType)) {
        if (tagName == null)
          tagName = flatNode.getText(region);
      }
    }
View Full Code Here

      return;

    String name = null;
    Iterator e = regions.iterator();
    while (e.hasNext()) {
      ITextRegion region = (ITextRegion) e.next();
      String regionType = region.getType();
      if (regionType == DOMRegionContext.XML_ENTITY_REFERENCE || regionType == DOMRegionContext.XML_CHAR_REFERENCE) {
        if (name == null)
          name = StructuredDocumentRegionUtil.getEntityRefName(flatNode, region);
      }
    }
View Full Code Here

    AttrImpl attr = null;
    List attrNodes = null;
    boolean isCloseTag = false;
    Iterator e = regions.iterator();
    while (e.hasNext()) {
      ITextRegion region = (ITextRegion) e.next();
      String regionType = region.getType();
      if (isNestedTagOpen(regionType) || isNestedTagName(regionType)) {
        tagName = computeNestedTag(regionType, tagName, flatNode, region);
      }
      else if (isNestedTagClose(regionType)) {
        isCloseTag = true;
View Full Code Here

      return;

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

    boolean isEmptyTag = false;
    AttrImpl attr = null;
    List attrNodes = null;
    Iterator e = regions.iterator();
    while (e.hasNext()) {
      ITextRegion region = (ITextRegion) e.next();
      String regionType = region.getType();
      if (regionType == DOMRegionContext.XML_TAG_NAME || isNestedTagName(regionType)) {
        if (tagName == null)
          tagName = flatNode.getText(region);
      }
      else if (regionType == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
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.