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

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


          continue;
        }
        if (child.getStartOffset() > offset) {
          break;
        }
        IStructuredDocumentRegion startStructuredDocumentRegion = child.getStartStructuredDocumentRegion();
        if (startStructuredDocumentRegion != null) {
          if (startStructuredDocumentRegion.getEnd() > offset)
            return child;
        }
        IStructuredDocumentRegion endStructuredDocumentRegion = child.getEndStructuredDocumentRegion();
        if (endStructuredDocumentRegion != null) {
          if (endStructuredDocumentRegion.getStart() <= offset)
            return child;
        }
        // dig more
        parent = child;
        child = (IDOMNode) parent.getFirstChild();
      }
    }
    else {
      // search from the last
      IDOMNode child = (IDOMNode) this.document.getLastChild();
      while (child != null) {
        if (child.getStartOffset() > offset) {
          child = (IDOMNode) child.getPreviousSibling();
          continue;
        }
        if (child.getEndOffset() <= offset) {
          break;
        }
        IStructuredDocumentRegion startStructuredDocumentRegion = child.getStartStructuredDocumentRegion();
        if (startStructuredDocumentRegion != null) {
          if (startStructuredDocumentRegion.getEnd() > offset)
            return child;
        }
        IStructuredDocumentRegion endStructuredDocumentRegion = child.getEndStructuredDocumentRegion();
        if (endStructuredDocumentRegion != null) {
          if (endStructuredDocumentRegion.getStart() <= offset)
            return child;
        }
        // dig more
        parent = child;
        child = (IDOMNode) parent.getLastChild();
View Full Code Here


   * @param structuredDocumentEvent
   */
  public void regionChanged(RegionChangedEvent event) {
    if (event == null)
      return;
    IStructuredDocumentRegion flatNode = event.getStructuredDocumentRegion();
    if (flatNode == null)
      return;
    ITextRegion region = event.getRegion();
    if (region == null)
      return;
View Full Code Here

   * @param event
   */
  public void regionsReplaced(RegionsReplacedEvent event) {
    if (event == null)
      return;
    IStructuredDocumentRegion flatNode = event.getStructuredDocumentRegion();
    if (flatNode == null)
      return;
    ITextRegionList oldRegions = event.getOldRegions();
    ITextRegionList newRegions = event.getNewRegions();
    if (oldRegions == null && newRegions == null)
View Full Code Here

  protected void addAttributeNameProposals(
      ContentAssistRequest contentAssistRequest,
      CompletionProposalInvocationContext context) {
   
    IDOMNode node = (IDOMNode) contentAssistRequest.getNode();
    IStructuredDocumentRegion sdRegion = contentAssistRequest.getDocumentRegion();
    // retrieve the list of attributes
    CMElementDeclaration elementDecl = getCMElementDeclaration(node);
    if (elementDecl != null) {
      CMNamedNodeMapImpl attributes = new CMNamedNodeMapImpl(elementDecl.getAttributes());
      addModelQueryAttributeDeclarations(node, elementDecl,attributes);

      String matchString = contentAssistRequest.getMatchString();
      int cursorOffset = context.getInvocationOffset();
      // check whether an attribute really exists for the replacement
      // offsets AND if it possesses a value
      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

   
    IDOMNode node = (IDOMNode) contentAssistRequest.getNode();

    // Find the attribute region and name for which this position should
    // have a value proposed
    IStructuredDocumentRegion open = node.getFirstStructuredDocumentRegion();
    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
    if (nameRegion != null) {
      // Retrieve the declaration
      CMElementDeclaration elementDecl = getCMElementDeclaration(node);

      // String attributeName = nameRegion.getText();
      String attributeName = open.getText(nameRegion);

      CMAttributeDeclaration attrDecl = null;

      // No CMElementDeclaration means no attribute metadata, but retrieve the
      // declaration for the attribute otherwise
View Full Code Here

    boolean addProposal = false;

    if (node.getNodeType() == Node.ELEMENT_NODE) {
      // ////////////////////////////////////////////////////////////////////////////////////
      IStructuredDocument sDoc = (IStructuredDocument) context.getDocument();
      IStructuredDocumentRegion xmlEndTagOpen = sDoc.getRegionAtCharacterOffset(contentAssistRequest.getReplacementBeginPosition());
      // skip backward to "<", "</", or the (unclosed) start tag, null if not found
      String type = ""; //$NON-NLS-1$
      while ((xmlEndTagOpen != null) &&
          ((type = xmlEndTagOpen.getType()) != DOMRegionContext.XML_END_TAG_OPEN) &&
          (type != DOMRegionContext.XML_TAG_CLOSE) && !needsEndTag(xmlEndTagOpen, context) &&
          (type != DOMRegionContext.XML_TAG_OPEN)) {
       
        xmlEndTagOpen = xmlEndTagOpen.getPrevious();
      }

      if (xmlEndTagOpen == null) {
        return;
      }

      node = (IDOMNode) node.getModel().getIndexedRegion(xmlEndTagOpen.getStartOffset());
      node = (IDOMNode) node.getParentNode();

      if (isStartTag(xmlEndTagOpen)) {
        // this is the case for a start tag w/out end tag
        // eg:
        // <p>
        // <% String test = "test"; %>
        // |
        if (needsEndTag(xmlEndTagOpen, context)) {
          String tagName = getTagName(xmlEndTagOpen);
          xmlEndTagOpen.getTextEndOffset();
          replaceLength = 0;
          replaceText = "</" + tagName + ">"; //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$
          cursorOffset = tagName.length() + 3;
          displayString = NLS.bind(XMLUIMessages.End_with__, (new Object[]{tagName}));
          addProposal = true;
        }
      }
      else if (type == DOMRegionContext.XML_END_TAG_OPEN) {
        // this is the case for: <tag> </ |
        // possibly <tag> </ |<anotherTag>
        // should only be replacing white space...
        replaceLength = (replaceBegin > xmlEndTagOpen.getTextEndOffset()) ? replaceBegin - xmlEndTagOpen.getTextEndOffset() : 0;
        replaceText = node.getNodeName() + ">"; //$NON-NLS-1$
        cursorOffset = replaceText.length();
        replaceBegin = xmlEndTagOpen.getTextEndOffset();
        displayString = NLS.bind(XMLUIMessages.End_with_, (new Object[]{node.getNodeName()}));
        addProposal = true;
      }
      else if (type == DOMRegionContext.XML_TAG_OPEN) {
        // this is the case for: <tag> < |
        replaceText = "/" + node.getNodeName() + ">"; //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$
        cursorOffset = replaceText.length();

        // should only be replacing white space...
        replaceLength = (replaceBegin > xmlEndTagOpen.getTextEndOffset()) ? replaceBegin - xmlEndTagOpen.getTextEndOffset() : 0;
        replaceBegin = xmlEndTagOpen.getTextEndOffset();
        displayString = NLS.bind(XMLUIMessages.End_with_, (new Object[]{"/" + node.getNodeName()})); //$NON-NLS-1$
        addProposal = true;
      }
    }
    // ////////////////////////////////////////////////////////////////////////////////////
View Full Code Here

          // prompt with the closer for the start tag and an end tag if one is not present
          if (node.getEndStructuredDocumentRegion() == null) {
            // make sure tag name is actually what it thinks it
            // is...(eg. <%@ vs. <jsp:directive)
            IStructuredDocumentRegion sdr = contentAssistRequest.getDocumentRegion();
            String openingTagText = (sdr != null) ? sdr.getFullText() : ""; //$NON-NLS-1$
            if ((openingTagText != null) && (openingTagText.indexOf(node.getNodeName()) != -1)) {
              proposal = new MarkupCompletionProposal("></" + node.getNodeName() + ">", //$NON-NLS-2$//$NON-NLS-1$
                    contentAssistRequest.getReplacementBeginPosition(),
                    // this is one of the few times to
                    // ignore the length -- always insert
View Full Code Here

    StringBuffer buffer = new StringBuffer();
    buffer.append(getNodeName());
    buffer.append('(');
    buffer.append(getData());
    buffer.append(')');
    IStructuredDocumentRegion flatNode = getStructuredDocumentRegion();
    if (flatNode != null) {
      buffer.append('@');
      buffer.append(flatNode.toString());
    }
    return buffer.toString();
  }
View Full Code Here

      IDOMNode treeNode,CompletionProposalInvocationContext context) {
   
    // only handle XML content for now
    int documentPosition = context.getInvocationOffset();
    Vector proposals = new Vector(); // ICompletionProposals
    IStructuredDocumentRegion sdRegion =
      ContentAssistUtils.getStructuredDocumentRegion(context.getViewer(), context.getInvocationOffset());
    if ((completionRegion != null) && (completionRegion.getType() == DOMRegionContext.XML_CONTENT)) {
      int nodeOffset = documentPosition - sdRegion.getStartOffset(completionRegion);
      String regionText = sdRegion.getFullText(completionRegion);

      // if directly to the right of a &, region will be null, need to
      // move to
      // the previous region...there might be a better way to do this
      if ((regionText != null) && regionText.trim().equals("") && (documentPosition > 0)) { //$NON-NLS-1$
        IStructuredDocumentRegion prev = treeNode.getStructuredDocument().getRegionAtCharacterOffset(documentPosition - 1);
        if ((prev != null) && prev.getText().equals("&")) { //$NON-NLS-1$
          // https://bugs.eclipse.org/bugs/show_bug.cgi?id=206680
          // examine previous region
          sdRegion = prev;
          completionRegion = prev.getLastRegion();
          regionText = prev.getFullText();
          nodeOffset = 1;
        }
      }

      // string must start w/ &
View Full Code Here

  public int getNameRegionEndOffset() {
    if (this.ownerElement == null)
      return 0;
    // assuming the firstStructuredDocumentRegion is the one that contains
    // attributes
    IStructuredDocumentRegion flatNode = this.ownerElement.getFirstStructuredDocumentRegion();
    if (flatNode == null)
      return 0;
    return flatNode.getEndOffset(this.nameRegion);
  }
View Full Code Here

TOP

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

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.