/**
   * @return int
   * @param node org.eclipse.wst.css.core.model.interfaces.ICSSNode
   * @param insertPos int
   */
  public int getLengthToReformatAfter(ICSSNode node, int insertPos) {
    if (node == null) return 0;
    IndexedRegion nnode = (IndexedRegion) node;
    if (insertPos < 0 || !nnode.contains(insertPos)) return 0;

    IStructuredDocumentRegion flatNode =
        node.getOwnerDocument()
            .getModel()
            .getStructuredDocument()
            .getRegionAtCharacterOffset(insertPos);
    if (flatNode == null) return 0;
    ITextRegion region = flatNode.getRegionAtCharacterOffset(insertPos);
    if (region == null) return 0;
    RegionIterator it = new RegionIterator(flatNode, region);
    boolean found = false;
    while (it.hasNext()) {
      region = it.next();
      // if (region.getType() != CSSRegionContexts.CSS_S &&
      // region.getType() != CSSRegionContexts.CSS_DELIMITER &&
      // region.getType() !=
      // CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
      if (region.getType() != CSSRegionContexts.CSS_S) {
        found = true;
        break;
      }
    }
    int pos =
        (found
                ? it.getStructuredDocumentRegion().getStartOffset(region)
                : it.getStructuredDocumentRegion().getTextEndOffset(region))
            - insertPos;
    return (pos >= 0) ? pos : 0;
  }
Пример #2
0
 /**
  * Get the node absolute start location in its residing IStructuredModel.
  *
  * @param p
  * @return the location
  */
 public static int getIndexedRegionLocation(IDOMPosition p) {
   if (!EditValidateUtil.validPosition(p)) {
     return -1;
   }
   Node parent = p.getContainerNode();
   if (p.isText()) {
     return ((IndexedRegion) parent).getStartOffset() + p.getOffset();
   }
   int index = p.getOffset();
   if (!parent.hasChildNodes()) {
     // Element:
     if (!isDocument(parent)) {
       IStructuredDocumentRegion region = ((IDOMNode) parent).getStartStructuredDocumentRegion();
       return region.getEnd();
     }
     // Document node:
     int offset = ((IndexedRegion) parent).getStartOffset();
     return offset;
   }
   NodeList children = parent.getChildNodes();
   // After rightmost child
   if (children.getLength() == index) {
     if (!isDocument(parent)) {
       int pos = getNodeEndNameStartIndex(parent);
       return pos;
     }
     int offset = ((IndexedRegion) parent).getEndOffset();
     return offset;
   }
   Node node = children.item(index);
   return ((IndexedRegion) node).getStartOffset();
 }
  protected List<IRegion> getAttributeValueRegions(ITextViewer viewer) {
    List<IRegion> regions = new ArrayList<IRegion>();
    IDocument document = viewer.getDocument();
    int startOffset = 0;
    int endOffset = document.getLength();

    IStructuredDocumentRegion sdRegion = null;

    while (startOffset < endOffset
        && (sdRegion = ContentAssistUtils.getStructuredDocumentRegion(viewer, startOffset))
            != null) {
      ITextRegionList list = sdRegion.getRegions();

      for (int i = 0; list != null && i < list.size(); i++) {
        ITextRegion region = list.get(i);
        if (region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {

          final int regionOffset = sdRegion.getStartOffset() + region.getStart();
          final int regionLength = region.getTextLength();

          regions.add(new Region(regionOffset, regionLength));
        }
      }
      startOffset += sdRegion.getLength();
    }

    return regions;
  }
  // public List getSelectedNodes() {
  // ViewerSelectionManager vsm = getViewerSelectionManager();
  // return (vsm != null) ? vsm.getSelectedNodes() : null;
  // }
  public int getStartOffset(Node node) {
    if ((node == null) || !(node instanceof IDOMText)) {
      return -1;
    }

    IStructuredDocumentRegion fnode = ((IDOMText) node).getFirstStructuredDocumentRegion();
    return fnode.getStartOffset();
  }
 public void reset(IStructuredDocument structuredDocument, int index) {
   documentRegion = structuredDocument.getRegionAtCharacterOffset(index);
   curDocumentRegion = documentRegion;
   if (documentRegion != null) {
     ITextRegion region = documentRegion.getRegionAtCharacterOffset(index);
     current = documentRegion.getRegions().indexOf(region);
   }
 }
Пример #6
0
  public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    ITextEditor textEditor = null;
    if (editor instanceof ITextEditor) textEditor = (ITextEditor) editor;
    else {
      Object o = editor.getAdapter(ITextEditor.class);
      if (o != null) textEditor = (ITextEditor) o;
    }
    if (textEditor != null) {
      IDocument document =
          textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());

      if (document != null) {
        // get current text selection
        ITextSelection textSelection = getCurrentSelection(textEditor);

        // If there is alternating or more then one block in the text
        // selection, action is aborted !
        if (isMoreThanOneContextBlockSelected(document, textSelection)) {
          // displayCommentActinosErrorDialog(editor);
          // return null;
          org.eclipse.wst.sse.ui.internal.handlers.AddBlockCommentHandler
              addBlockCommentHandlerWST =
                  new org.eclipse.wst.sse.ui.internal.handlers
                      .AddBlockCommentHandler(); // org.eclipse.wst.sse.ui.internal.handlers.AddBlockCommentHandler();
          return addBlockCommentHandlerWST.execute(event);
        }

        if (textSelection.isEmpty()) {
          return null;
        }
        if (document instanceof IStructuredDocument) {
          int selectionOffset = textSelection.getOffset();
          IStructuredDocument sDoc = (IStructuredDocument) document;
          IStructuredDocumentRegion sdRegion = sDoc.getRegionAtCharacterOffset(selectionOffset);
          ITextRegion textRegion = sdRegion.getRegionAtCharacterOffset(selectionOffset);

          ITextRegionCollection container = sdRegion;

          if (textRegion instanceof ITextRegionContainer) {
            container = (ITextRegionContainer) textRegion;
            textRegion = container.getRegionAtCharacterOffset(selectionOffset);
          }
          if (textRegion.getType() == PHPRegionContext.PHP_CONTENT) {
            processAction(textEditor, document, textSelection);
          } else {
            org.eclipse.wst.sse.ui.internal.handlers.AddBlockCommentHandler
                addBlockCommentHandlerWST =
                    new org.eclipse.wst.sse.ui.internal.handlers.AddBlockCommentHandler();
            return addBlockCommentHandlerWST.execute(event);
          }
        }
      }
    }
    return null;
  }
 private IJavaProject getJavaProject(ContentAssistRequest request) {
   if (request != null) {
     IStructuredDocumentRegion region = request.getDocumentRegion();
     if (region != null) {
       IDocument document = region.getParentDocument();
       return MybatipseXmlUtil.getJavaProject(document);
     }
   }
   return null;
 }
  public static IProject getProject(ContentAssistRequest request) {

    if (request != null) {
      IStructuredDocumentRegion region = request.getDocumentRegion();
      if (region != null) {
        IDocument document = region.getParentDocument();
        return getProject(document);
      }
    }
    return null;
  }
  /**
   * Returns the subregion at the given offset, with a bias to the left or a bias to the right. In
   * other words, if | represents the caret position, in the XML {@code <foo>|</bar>} then the
   * subregion with bias left is the closing {@code >} and the subregion with bias right is the
   * opening {@code </}.
   *
   * @param doc the document
   * @param offset the offset in the document
   * @param biasLeft whether we should look at the token on the left or on the right
   * @return the subregion at the given offset, or null if not found
   */
  private static ITextRegion getRegionAt(IStructuredDocument doc, int offset, boolean biasLeft) {
    if (biasLeft) {
      offset--;
    }
    IStructuredDocumentRegion region = doc.getRegionAtCharacterOffset(offset);
    if (region != null) {
      return region.getRegionAtCharacterOffset(offset);
    }

    return null;
  }
 protected String getOtherClose(Node notATagNode) {
   if (notATagNode instanceof IDOMNode) {
     IStructuredDocumentRegion node = ((IDOMNode) notATagNode).getStartStructuredDocumentRegion();
     if ((node != null)
         && (node.getNumberOfRegions() > 1)
         && node.getRegions()
             .get(0)
             .getType()
             .equals(DOMJSPRegionContextsPrivateCopy.JSP_DIRECTIVE_OPEN)) {
       return "%>"; //$NON-NLS-1$
     }
   }
   return null;
 }
  protected int getValidPosition(IDocument idoc, int lineNumber) {
    if (!(getSourceEditingTextTools() instanceof IDOMSourceEditingTextTools)) {
      return NO_VALID_CONTENT;
    }
    if (idoc == null) return NO_VALID_CONTENT;

    int startOffset, endOffset;
    try {
      startOffset = idoc.getLineOffset(lineNumber - 1);
      endOffset = idoc.getLineOffset(lineNumber) - 1;

      if (idoc == null) return NO_VALID_CONTENT;
      String lineText = idoc.get(startOffset, endOffset - startOffset).trim();

      // blank lines or lines with only an open or close brace or
      // scriptlet tag cannot have a breakpoint
      if (lineText.equals("")
          || lineText.equals("{")
          || //$NON-NLS-2$//$NON-NLS-1$
          lineText.equals("}")
          || lineText.equals("<%")) // $NON-NLS-2$//$NON-NLS-1$
      return NO_VALID_CONTENT;
    } catch (BadLocationException e) {
      return NO_VALID_CONTENT;
    }

    IStructuredDocumentRegion flatNode =
        ((IStructuredDocument) idoc).getRegionAtCharacterOffset(startOffset);
    // go through the node's regions looking for JSP content
    // until reaching the end of the line
    while (flatNode != null) {
      int validPosition =
          getValidRegionPosition(
              ((IDOMDocument)
                      ((IDOMSourceEditingTextTools) getSourceEditingTextTools()).getDOMDocument())
                  .getModel(),
              flatNode,
              startOffset,
              endOffset);

      if (validPosition == END_OF_LINE) return NO_VALID_CONTENT;

      if (validPosition >= 0) return validPosition;

      flatNode = flatNode.getNext();
    }
    return NO_VALID_CONTENT;
  }
 public void reset(IStructuredDocumentRegion flatNode, ITextRegion region) {
   if (region != null && flatNode != null) {
     this.documentRegion = flatNode;
     curDocumentRegion = flatNode;
     current = flatNode.getRegions().indexOf(region);
   }
 }
 private String getCollapsedText(ITextRegion region) {
   if (fParentRegion == null) return ""; // $NON-NLS-1$
   StringBuffer text = new StringBuffer(fParentRegion.getFullText(region));
   if (region.getLength() > region.getTextLength())
     text.replace(region.getTextLength(), region.getLength(), " "); // $NON-NLS-1$
   return text.toString();
 }
  CSSStyleDeclItemImpl setupDeclarationItem(IStructuredDocumentRegion flatNode) {
    if (flatNode == null) {
      return null;
    }
    if (!hasColonSeparator(flatNode)) {
      return null;
    }

    fParentRegion = flatNode;

    ITextRegionList nodeRegions = new TextRegionListImpl(flatNode.getRegions()); // make
    // copy
    CSSStyleDeclItemImpl newItem = createDeclarationItem(nodeRegions);
    if (newItem == null) {
      return null;
    }
    if (!fTempStructuredDocument && flatNode != null) {
      newItem.setRangeStructuredDocumentRegion(flatNode, flatNode);
    }

    CSSUtil.stripSurroundingSpace(nodeRegions);
    // Now, nodeRegions just has regions for value.
    setupValues(newItem, nodeRegions, null);
    return newItem;
  }
  /**
   * Returns a pair of (tag-balance,bracket-balance) for the range textStart to offset.
   *
   * @param doc the document
   * @param start the offset of the starting character (inclusive)
   * @param end the offset of the ending character (exclusive)
   * @return the balance of tags and brackets
   */
  private static Pair<Integer, Integer> getBalance(IStructuredDocument doc, int start, int end) {
    // Balance of open and closing tags
    // <foo></foo> has tagBalance = 0, <foo> has tagBalance = 1
    int tagBalance = 0;
    // Balance of open and closing brackets
    // <foo attr1="value1"> has bracketBalance = 1, <foo has bracketBalance = 1
    int bracketBalance = 0;
    IStructuredDocumentRegion region = doc.getRegionAtCharacterOffset(start);

    if (region != null) {
      boolean inOpenTag = true;
      while (region != null && region.getStartOffset() < end) {
        int regionStart = region.getStartOffset();
        ITextRegionList subRegions = region.getRegions();
        for (int i = 0, n = subRegions.size(); i < n; i++) {
          ITextRegion subRegion = subRegions.get(i);
          int subRegionStart = regionStart + subRegion.getStart();
          int subRegionEnd = regionStart + subRegion.getEnd();
          if (subRegionEnd < start || subRegionStart >= end) {
            continue;
          }
          String type = subRegion.getType();

          if (XML_TAG_OPEN.equals(type)) {
            bracketBalance++;
            inOpenTag = true;
          } else if (XML_TAG_CLOSE.equals(type)) {
            bracketBalance--;
            if (inOpenTag) {
              tagBalance++;
            } else {
              tagBalance--;
            }
          } else if (XML_END_TAG_OPEN.equals(type)) {
            bracketBalance++;
            inOpenTag = false;
          } else if (XML_EMPTY_TAG_CLOSE.equals(type)) {
            bracketBalance--;
          }
        }

        region = region.getNext();
      }
    }

    return Pair.of(tagBalance, bracketBalance);
  }
Пример #16
0
 // different btwn XML-JSP and JSP tags
 protected String getRegionName(IStructuredDocumentRegion sdRegion) {
   ITextRegion nameRegion = null;
   String nameStr = ""; // $NON-NLS-1$
   int size = sdRegion.getRegions().size();
   if (size > 1) {
     // presumably XML-JSP <jsp:scriptlet> | <jsp:expression> | <jsp:declaration>
     nameRegion = sdRegion.getRegions().get(1);
   } else if (size == 1) {
     // presumably JSP open <% | <%= | <%!
     nameRegion = sdRegion.getRegions().get(0);
   }
   if (nameRegion != null)
     nameStr =
         fTextToParse.substring(
             sdRegion.getStartOffset(nameRegion), sdRegion.getTextEndOffset(nameRegion));
   return nameStr.trim();
 }
  public ITextRegion next() {
    if (documentRegion == null) return null;
    if (current < 0
        || documentRegion.getRegions() == null
        || documentRegion.getRegions().size() <= current) return null;

    ITextRegion region = documentRegion.getRegions().get(current);
    curDocumentRegion = documentRegion;

    if (current >= documentRegion.getRegions().size() - 1) {
      documentRegion = documentRegion.getNext();
      current = -1;
    }
    current++;

    return region;
  }
Пример #18
0
 /*
  * return true for elements whose contents we might want to add to the java file we are building
  */
 protected boolean isJSPStartRegion(IStructuredDocumentRegion sdRegion) {
   String type = sdRegion.getFirstRegion().getType();
   return type == DOMRegionContext.XML_TAG_OPEN
       || type == DOMJSPRegionContexts.JSP_DECLARATION_OPEN
       || type == DOMJSPRegionContexts.JSP_EXPRESSION_OPEN
       || type == DOMJSPRegionContexts.JSP_SCRIPTLET_OPEN
       || type == DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN
       || type == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME;
 }
  public ITextRegion prev() {
    if (documentRegion == null) return null;
    if (current < 0
        || documentRegion.getRegions() == null
        || documentRegion.getRegions().size() <= current) return null;

    ITextRegion region = documentRegion.getRegions().get(current);
    curDocumentRegion = documentRegion;

    if (current == 0) {
      documentRegion = documentRegion.getPrevious();
      if (documentRegion != null) current = documentRegion.getRegions().size();
      else current = 0;
    }
    current--;

    return region;
  }
Пример #20
0
 /**
  * Return 'node' indexed end name' start position Example: <a>aaa| </a>, the position is indicated
  * by '|' If node is <a /> style or there is no </a> to pair with <a>, the function return -1.
  *
  * @param node
  * @return the start index
  */
 public static int getNodeEndNameStartIndex(Node node) {
   if (isText(node)) {
     return getNodeEndIndex(node);
   }
   if (EditValidateUtil.validNode(node) && node instanceof IDOMNode) {
     IStructuredDocumentRegion region = ((IDOMNode) node).getEndStructuredDocumentRegion();
     if (region != null) {
       return region.getStartOffset();
     }
     // else
     // {
     // if (node.hasChildNodes())
     // {
     // return getNodeEndIndex(node);
     // }
     // }
   }
   return getNodeEndIndex(node);
 }
 protected IndexedRegion getCorrespondingNode(IStructuredDocumentRegion sdRegion) {
   IStructuredModel sModel =
       StructuredModelManager.getModelManager().getExistingModelForRead(fDocument);
   IndexedRegion indexedRegion = null;
   try {
     if (sModel != null) indexedRegion = sModel.getIndexedRegion(sdRegion.getStart());
   } finally {
     if (sModel != null) sModel.releaseFromRead();
   }
   return indexedRegion;
 }
  /**
   * Creates an IMessage from an IProblem
   *
   * @param problem
   * @param f
   * @param translation
   * @param textDoc
   * @return message representation of the problem, or null if it could not create one
   */
  private IMessage createMessageFromProblem(
      IProblem problem, IFile f, IJsTranslation translation, IDocument textDoc) {
    int sourceStart = problem.getSourceStart();
    int sourceEnd = problem.getSourceEnd();
    if (sourceStart == -1) {
      return null;
    }
    sourceStart = translation.getWebPageOffset(sourceStart);
    sourceEnd = translation.getWebPageOffset(sourceEnd);
    /*
     * Bug 241794 - Validation shows errors when using JSP Expressions
     * inside JavaScript code
     */
    IStructuredDocument doc = (IStructuredDocument) textDoc;
    IStructuredDocumentRegion documentRegion = doc.getRegionAtCharacterOffset(sourceStart);
    if (documentRegion != null) {
      ITextRegion textRegion = documentRegion.getRegionAtCharacterOffset(sourceStart);
      /*
       * Filter out problems from areas that aren't simple JavaScript,
       * e.g. JSP.
       */
      if (textRegion != null && textRegion instanceof ITextRegionCollection) return null;
    }

    int sev =
        problem.isError()
            ? IMessage.HIGH_SEVERITY
            : (problem.isWarning() ? IMessage.NORMAL_SEVERITY : IMessage.LOW_SEVERITY);
    IMessage m = new LocalizedMessage(sev, problem.getMessage(), f);
    // line numbers for marker starts @ 1
    // line numbers from document starts @ 0
    try {
      int lineNo = textDoc.getLineOfOffset(sourceStart) + 1;
      m.setLineNo(lineNo);
      m.setOffset(sourceStart);
      m.setLength(sourceEnd - sourceStart + 1);
    } catch (BadLocationException e) {
      Logger.logException(e);
    }
    return m;
  }
 protected CompoundRegion[] getRegionsWithoutWhiteSpaces(
     IStructuredDocument model, IRegion reg, CSSCleanupStrategy stgy) {
   int start = reg.getOffset();
   int end = reg.getOffset() + reg.getLength() - 1;
   ArrayList list = new ArrayList();
   IStructuredDocumentRegion flatNode = model.getRegionAtCharacterOffset(start);
   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 (region.getType() != CSSRegionContexts.CSS_S
           || (isCleanup() && !stgy.isFormatSource())) // for
         // not
         // formatting
         // case
         // on
         // cleanup
         // action
         list.add(new CompoundRegion(flatNode, region));
     }
     flatNode = flatNode.getNext();
   }
   if (list.size() > 0) {
     CompoundRegion[] regions = new CompoundRegion[list.size()];
     list.toArray(regions);
     return regions;
   }
   return new CompoundRegion[0];
 }
  protected String computeNestedTag(
      String regionType,
      String tagName,
      IStructuredDocumentRegion structuredDocumentRegion,
      ITextRegion region) {

    if (regionType.equals(TwigRegionTypes.TWIG_STMT_OPEN)) {

      try {

        String text = structuredDocumentRegion.getText();
        Object cached = cache.get(text);

        if (cached != null) {
          return (String) cached;
        }

        CharStream content = new ANTLRStringStream(text);
        TwigLexer lexer = new TwigLexer(content);

        TwigParser parser = new TwigParser(new CommonTokenStream(lexer));

        parser.setTreeAdaptor(new TwigCommonTreeAdaptor());
        TwigParser.twig_source_return root;

        root = parser.twig_source();
        TwigCommonTree tree = (TwigCommonTree) root.getTree();
        TwigStatementVisitor visitor = new TwigStatementVisitor();

        tree.accept(visitor);

        if (visitor.getStatementType() == TwigParser.TWIG_TAG) {
          String tag = visitor.getTag();
          cache.put(text, tag);
          return tag;
        }

      } catch (Exception e) {

        e.printStackTrace();
      }

      return TWIG_STMT_TAG;

    } else if (regionType.equals(TwigRegionTypes.TWIG_OPEN)) {

      return TWIG_PRINT_TAG;
    }

    return TWIG_STMT_TAG;
  }
Пример #25
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);
 }
  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];
  }
  public static boolean hasColonSeparator(IStructuredDocumentRegion flatNode) {
    if (flatNode == null) {
      return false;
    }
    ITextRegionList regions = flatNode.getRegions();
    if (regions == null || regions.size() == 0) {
      return false;
    }

    for (Iterator i = regions.iterator(); i.hasNext(); ) {
      ITextRegion region = (ITextRegion) i.next();
      if (region == null) {
        continue;
      }
      if (region.getType() == CSSRegionContexts.CSS_DECLARATION_SEPARATOR) {
        return true;
      }
    }

    return false;
  }
  protected void addAttributeValueProposals(
      ContentAssistRequest contentAssistRequest, CompletionProposalInvocationContext context) {
    IDOMNode node = (IDOMNode) contentAssistRequest.getNode();
    String tagName = node.getNodeName();
    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;
    }

    // get the attribute in question (first attr name to the left of the cursor)
    String attributeName = null;
    if (nameRegion != null) attributeName = open.getText(nameRegion);

    ProposalType proposalType = resolveProposalType(tagName, attributeName);
    if (ProposalType.None.equals(proposalType)) {
      return;
    }

    String currentValue = null;
    if (contentAssistRequest.getRegion().getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)
      currentValue = contentAssistRequest.getText();
    else currentValue = "";

    String matchString = null;
    int matchStrLen = contentAssistRequest.getMatchString().length();
    int start = contentAssistRequest.getReplacementBeginPosition();
    int length = contentAssistRequest.getReplacementLength();
    if (currentValue.length() > StringUtils.strip(currentValue).length()
        && (currentValue.startsWith("\"") || currentValue.startsWith("'"))
        && matchStrLen > 0) {
      // Value is surrounded by (double) quotes.
      matchString = currentValue.substring(1, matchStrLen);
      start++;
      length = currentValue.length() - 2;
      currentValue = currentValue.substring(1, length + 1);
    } else {
      matchString = currentValue.substring(0, matchStrLen);
    }

    IJavaProject project = getJavaProject(contentAssistRequest);
    try {
      switch (proposalType) {
        case Package:
          proposePackage(contentAssistRequest, project, matchString, start, length);
          break;
        case TypeAlias:
          addProposals(
              contentAssistRequest,
              ProposalComputorHelper.proposeJavaType(project, start, length, false, matchString));
          break;
        case ResultType:
          addProposals(
              contentAssistRequest,
              ProposalComputorHelper.proposeJavaType(project, start, length, true, matchString));
          break;
        case ResultProperty:
          proposeProperty(contentAssistRequest, matchString, start, length, node);
          break;
        case TypeHandlerType:
          addProposals(
              contentAssistRequest,
              ProposalComputorHelper.proposeTypeHandler(project, start, length, matchString));
          break;
        case CacheType:
          addProposals(
              contentAssistRequest,
              ProposalComputorHelper.proposeCacheType(project, start, length, matchString));
          break;
        case SettingName:
          addProposals(
              contentAssistRequest,
              ProposalComputorHelper.proposeSettingName(start, length, matchString));
          break;
        case ObjectFactory:
          addProposals(
              contentAssistRequest,
              ProposalComputorHelper.proposeObjectFactory(project, start, length, matchString));
          break;
        case ObjectWrapperFactory:
          addProposals(
              contentAssistRequest,
              ProposalComputorHelper.proposeObjectWrapperFactory(
                  project, start, length, matchString));
          break;
        case StatementId:
          proposeStatementId(contentAssistRequest, project, matchString, start, length, node);
          break;
        case MapperNamespace:
          proposeMapperNamespace(contentAssistRequest, project, start, length);
          break;
        case ResultMap:
          String ownId =
              "resultMap".equals(tagName) && "extends".equals(attributeName)
                  ? XpathUtil.xpathString(node, "@id")
                  : null;
          addProposals(
              contentAssistRequest,
              proposeResultMapReference(
                  project,
                  node.getOwnerDocument(),
                  start,
                  currentValue,
                  matchString.length(),
                  ownId));
          break;
        case Include:
          addProposals(
              contentAssistRequest,
              ProposalComputorHelper.proposeReference(
                  project, node.getOwnerDocument(), matchString, start, length, "sql", null));
          break;
        case SelectId:
          // TODO: include mapper methods with @Select.
          addProposals(
              contentAssistRequest,
              ProposalComputorHelper.proposeReference(
                  project, node.getOwnerDocument(), matchString, start, length, "select", null));
          break;
        case KeyProperty:
          String nodeName = node.getNodeName();
          Node statementNode =
              "update".equals(nodeName) || "insert".equals(nodeName)
                  ? node
                  : MybatipseXmlUtil.findEnclosingStatementNode(node.getParentNode());
          addProposals(
              contentAssistRequest,
              proposeParameter(project, start, length, statementNode, false, matchString));
          break;
        case ParamProperty:
          addProposals(
              contentAssistRequest,
              proposeParameter(
                  project,
                  start,
                  length,
                  MybatipseXmlUtil.findEnclosingStatementNode(node),
                  true,
                  matchString));
          break;
        case ParamPropertyPartial:
          AttrTextParser parser = new AttrTextParser(currentValue, matchString.length());
          addProposals(
              contentAssistRequest,
              proposeParameter(
                  project,
                  start + parser.getMatchStringStart(),
                  parser.getReplacementLength(),
                  MybatipseXmlUtil.findEnclosingStatementNode(node.getParentNode()),
                  true,
                  parser.getMatchString()));
          break;
        default:
          break;
      }
    } catch (Exception e) {
      Activator.log(Status.ERROR, e.getMessage(), e);
    }
  }
 public boolean hasNext() {
   if (documentRegion == null) return false;
   if (current < 0) return false;
   if (current < documentRegion.getRegions().size()) return true;
   return false;
 }
 private String getText(ITextRegion region) {
   return (fParentRegion != null) ? fParentRegion.getText(region) : ""; // $NON-NLS-1$
 }