Ejemplo n.º 1
0
 /**
  * Returns the positions of a specific category of the given document.
  *
  * @param document the document to get the positions from
  * @param category the position's category
  * @return an array of positions. If there is none return an array with the length = 0
  */
 public org.eclipse.jface.text.Position[] getPositions(
     org.eclipse.jface.text.IDocument document, String category) {
   try {
     return document.getPositions(category);
   } catch (org.eclipse.jface.text.BadPositionCategoryException e) {
   }
   return new org.eclipse.jface.text.Position[0];
 }
Ejemplo n.º 2
0
 /**
  * Returns the first position of a specific category of the given document.
  *
  * @param document the document to get the positions from
  * @param category the category of the position
  * @return a position. If there is none return <code>null</code>.
  */
 public org.eclipse.jface.text.Position getFirstPosition(
     org.eclipse.jface.text.IDocument document, String category) {
   try {
     org.eclipse.jface.text.Position[] positions = document.getPositions(category);
     if (positions.length > 0) {
       return positions[0];
     }
   } catch (org.eclipse.jface.text.BadPositionCategoryException e) {
   }
   return null;
 }
Ejemplo n.º 3
0
 public static XMLNode getArtifactAt(String positionCategory, IDocument doc, int offset) {
   try {
     Position[] pos = doc.getPositions(positionCategory);
     for (int i = 0; i < pos.length; i++) {
       if (offset >= pos[i].getOffset() && offset <= pos[i].getOffset() + pos[i].getLength())
         return (XMLNode) pos[i];
     }
   } catch (BadPositionCategoryException e) {
     // do nothing
   }
   return null;
 }
Ejemplo n.º 4
0
  public XMLNode getPreviousSiblingTag(String allowed) {
    if (parent == null || parent.getType().equals("/") || allowed == null) return null;
    Position[] pos = null;
    try {
      pos = document.getPositions(XMLDocumentPartitioner.CONTENT_TYPES_CATEGORY);
    } catch (BadPositionCategoryException e) {
      e.printStackTrace();
      return null;
    }
    Arrays.sort(pos, COMPARATOR);
    int index = 0;
    while (pos[index] != this) index++;
    if (index > 0) {
      XMLNode result = null;
      for (int i = index - 1; i >= 0; i--) {
        result = (XMLNode) pos[i];
        if (result == parent) return null;
        String type = result.getType();
        if (result.getParent() != parent
            || (type.equals(ITypeConstants.TEXT)
                || type.equals(ITypeConstants.COMMENT)
                || type.equals(ITypeConstants.DECL))) {
          continue;
        }

        String name = result.getName();
        if (name == null) continue;
        if (type.equals(ITypeConstants.ENDTAG)) {
          XMLNode corresponding = result.getCorrespondingNode();
          if (allowed.indexOf(corresponding.getName().toLowerCase()) >= 0) return corresponding;
        } else if (allowed.indexOf(name) >= 0) {
          return result;
        }
      }
    }

    return null;
  }