Examples of ITextRegion


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

    String whitespaceStrategy = constraints.getWhitespaceStrategy();
    int indentLevel = constraints.getIndentLevel();
    ITextRegionList textRegions = currentDocumentRegion.getRegions();
    int currentTextRegionIndex = 1;

    ITextRegion currentTextRegion = textRegions.get(currentTextRegionIndex);
    String currentType = currentTextRegion.getType();
    // tag name should always be the first text region
    if (DOMRegionContext.XML_TAG_NAME.equals(currentType)) {
      ITextRegion nextTextRegion = textRegions.get(currentTextRegionIndex + 1);
      String nextType = (nextTextRegion != null) ? nextTextRegion.getType() : null;
      if (DOMRegionContext.XML_TAG_CLOSE.equals(nextType)) {
        // already at tag close
        formatStartTagWithNoAttr(textEdit, constraints, currentDocumentRegion, previousDocumentRegion, availableLineWidth, indentStrategy, whitespaceStrategy, currentTextRegion);
        return false;
      }
      else if (DOMRegionContext.XML_EMPTY_TAG_CLOSE.equals(nextType)) {
        // already at empty tag close
        formatEmptyStartTagWithNoAttr(textEdit, constraints, currentDocumentRegion, previousDocumentRegion, availableLineWidth, indentStrategy, whitespaceStrategy, currentTextRegion);
        return true;
      }
      else {
        availableLineWidth -= (currentTextRegion.getTextLength() + 2);
        boolean alignFinalBracket = getFormattingPreferences().getAlignFinalBracket();
        boolean oneSpaceInTagName = getFormattingPreferences().getSpaceBeforeEmptyCloseTag();
        boolean indentMultipleAttribute = getFormattingPreferences().getIndentMultipleAttributes();
        // indicates if tag spanned more than one line
        boolean spanMoreThan1Line = false;
        // indicates if all attributes should be indented
        boolean indentAllAttributes = false;
        if (indentMultipleAttribute) {
          int attributesCount = 0;
          int i = 2;
          final int size = textRegions.size();
          while (i < size && attributesCount < 2) {
            if (DOMRegionContext.XML_TAG_ATTRIBUTE_NAME.equals(textRegions.get(i).getType())) {
              ++attributesCount;
            }
            i++;
          }
          indentAllAttributes = (attributesCount > 1);
        }

        while ((currentTextRegionIndex + 1) < textRegions.size()) {
          nextTextRegion = textRegions.get(currentTextRegionIndex + 1);
          nextType = nextTextRegion.getType();
          if (DOMRegionContext.XML_TAG_ATTRIBUTE_NAME.equals(nextType)) {
            boolean indentAttribute = indentAllAttributes;
            if (!indentAttribute)
              indentAttribute = shouldIndentBeforeAttribute(constraints, textRegions, availableLineWidth, currentTextRegionIndex, currentTextRegion, nextTextRegion);
            if (indentAttribute) {
View Full Code Here

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

      parentConstraints.setAvailableLineWidth(lineWidth);
      return;
    }

    Iterator it = currentRegion.getRegions().iterator();
    ITextRegion previous = null;
    if (previousRegion == null)
      previousRegion = currentRegion.getPrevious();
    // Iterate over each text region of the comment
    Node parent = currentDOMRegion.domNode.getParentNode();
    while(it.hasNext()) {
      ITextRegion text = (ITextRegion) it.next();
      String type = text.getType();
      if (type == DOMRegionContext.XML_COMMENT_OPEN) {
        int indentLevel = (parent != null && parent.getNodeType() == Node.DOCUMENT_NODE) ? 0 : 1;
        int width = formatCommentStart(textEdit, parentConstraints, indentLevel, currentRegion, previousRegion, text);
        parentConstraints.setAvailableLineWidth(width);
      }
View Full Code Here

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

      indentAttribute = true;
    else {
      if ((currentTextRegionIndex + 2) < textRegions.size()) {
        // still okay, so try next region
        // something attrName=
        ITextRegion textRegion = textRegions.get(currentTextRegionIndex + 2);
        if (DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS.equals(textRegion.getType())) {
          ++currentWidth;
          if (currentWidth > availableLineWidth)
            indentAttribute = true;
          else {
            if ((currentTextRegionIndex + 3) < textRegions.size()) {
              // still okay, so try next region
              // something attrName=attrValue
              textRegion = textRegions.get(currentTextRegionIndex + 3);
              if (DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE.equals(textRegion.getType())) {
                currentWidth = +textRegion.getTextLength();
                if (currentWidth > availableLineWidth)
                  indentAttribute = true;
              }
            }
          }
View Full Code Here

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

          ITextRegionList textRegions = currentRegion.getRegions();
          int i = 0;
          boolean xmlSpaceFound = false;
          boolean preserveFound = false;
          while (i < textRegions.size() && !xmlSpaceFound) {
            ITextRegion textRegion = textRegions.get(i);
            if (DOMRegionContext.XML_TAG_ATTRIBUTE_NAME.equals(textRegion.getType())) {
              String regionText = currentRegion.getText(textRegion);
              if (XML_SPACE.equals(regionText)) {
                if ((i + 1) < textRegions.size()) {
                  ++i;
                  textRegion = textRegions.get(i);
                  if (DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS.equals(textRegion.getType()) && ((i + 1) < textRegions.size())) {
                    ++i;
                    textRegion = textRegions.get(i);
                    regionText = currentRegion.getText(textRegion);
                    if (PRESERVE.equals(regionText) || PRESERVE_QUOTED.equals(regionText)) {
                      preserveFound = true;
View Full Code Here

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

    if (event == null)
      return;
    IStructuredDocumentRegion flatNode = event.getStructuredDocumentRegion();
    if (flatNode == null)
      return;
    ITextRegion region = event.getRegion();
    if (region == null)
      return;
    XMLModelUpdater updater = getActiveUpdater();
    if (updater != null) { // being updated
      try {
View Full Code Here

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

      boolean attrAtLocationHasValue = false;
      boolean proposalNeedsSpace = false;
      NamedNodeMap attrs = node.getAttributes();
      for (int i = 0; i < attrs.getLength(); i++) {
        AttrImpl existingAttr = (AttrImpl) attrs.item(i);
        ITextRegion name = existingAttr.getNameRegion();
       
        if (name != null && (sdRegion.getStartOffset(name) <= contentAssistRequest.getReplacementBeginPosition()) &&
            (sdRegion.getStartOffset(name) + name.getLength() >= contentAssistRequest.getReplacementBeginPosition() + contentAssistRequest.getReplacementLength()) &&
            (existingAttr.getValueRegion() != null)) {
          // selected region is attribute name
          if (cursorOffset >= sdRegion.getStartOffset(name) && contentAssistRequest.getReplacementLength() != 0)
            attrAtLocationHasValue = true;
          // propose new attribute, cursor is at the start of another attribute name
          else if (cursorOffset == sdRegion.getStartOffset(name))
            proposalNeedsSpace = true;
          break;
        }
      }

      // only add proposals for the attributes whose names begin with the matchstring
      if (attributes != null) {
        for (int i = 0; i < attributes.getLength(); i++) {
          CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) attributes.item(i);

          if(validModelQueryNode(attrDecl)) {
            int isRequired = 0;
            if (attrDecl.getUsage() == CMAttributeDeclaration.REQUIRED) {
              isRequired = XMLRelevanceConstants.R_REQUIRED;
            }
 
            boolean showAttribute = true;
            showAttribute = showAttribute && beginsWith(getRequiredName(node, attrDecl), matchString.trim());
            AttrImpl attr = (AttrImpl) node.getAttributes().getNamedItem(getRequiredName(node, attrDecl));
            ITextRegion nameRegion = attr != null ? attr.getNameRegion() : null;
            // nameRegion.getEndOffset() + 1 is required to allow for
            // matches against the full name of an existing Attr
            showAttribute = showAttribute && ((attr == null) || nameRegion == null ||
                ((nameRegion != null) &&
                    (sdRegion.getStartOffset(nameRegion) <
                      contentAssistRequest.getReplacementBeginPosition()) &&
                    (sdRegion.getStartOffset(nameRegion) + nameRegion.getLength() >=
                      (contentAssistRequest.getReplacementBeginPosition() +
                      contentAssistRequest.getReplacementLength()) )));
            if (showAttribute) {
              //get the proposal image
              Image attrImage = CMImageUtil.getImage(attrDecl);
View Full Code Here

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

    ITextRegionList openRegions = open.getRegions();
    int i = openRegions.indexOf(contentAssistRequest.getRegion());
    if (i < 0) {
      return;
    }
    ITextRegion nameRegion = null;
    while (i >= 0) {
      nameRegion = openRegions.get(i--);
      if (nameRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
        break;
      }
    }

    // the name region is REQUIRED to do anything useful
View Full Code Here

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

  }
 
  private boolean isStartTag(IStructuredDocumentRegion sdRegion) {
    boolean result = false;
    if (sdRegion.getRegions().size() > 0) {
      ITextRegion r = sdRegion.getRegions().get(0);
      result = (r.getType() == DOMRegionContext.XML_TAG_OPEN) && sdRegion.isEnded();
    }
    return result;
  }
View Full Code Here

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

    return regions.get(regions.size() - 1).getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE;
  }
 
  private String getTagName(IStructuredDocumentRegion sdRegion) {
    ITextRegionList regions = sdRegion.getRegions();
    ITextRegion region = null;
    String name = ""; //$NON-NLS-1$
    for (int i = 0; i < regions.size(); i++) {
      region = regions.get(i);
      if (region.getType() == DOMRegionContext.XML_TAG_NAME) {
        name = sdRegion.getText(region);
        break;
      }
    }
    return name;
View Full Code Here

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

    ITextRegionList regions = ((ITextRegionContainer) this.fValueRegion).getRegions();
    if (regions == null)
      return false;
    Iterator e = regions.iterator();
    while (e.hasNext()) {
      ITextRegion region = (ITextRegion) e.next();
      if (region == null)
        continue;
      String regionType = region.getType();
      if (regionType == DOMRegionContext.XML_TAG_OPEN || isNestedLanguageOpening(regionType))
        return true;
    }
    return false;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.