1 11 12 package org.eclipse.jdt.internal.ui.text.comment; 13 14 import org.eclipse.jface.text.Position; 15 16 import org.eclipse.jdt.internal.ui.text.javadoc.IHtmlTagConstants; 17 18 23 public class CommentRange extends Position implements ICommentAttributes, IHtmlTagConstants { 24 25 26 private int fAttributes= 0; 27 28 36 public CommentRange(final int position, final int count) { 37 super(position, count); 38 } 39 40 48 protected final boolean hasAttribute(final int attribute) { 49 return (fAttributes & attribute) == attribute; 50 } 51 52 62 protected final boolean isClosingTag(final String token, final String tag) { 63 64 boolean result= token.startsWith(HTML_CLOSE_PREFIX) && token.charAt(token.length() - 1) == HTML_TAG_POSTFIX; 65 if (result) { 66 67 setAttribute(COMMENT_CLOSE); 68 result= token.substring(HTML_CLOSE_PREFIX.length(), token.length() - 1).equals(tag); 69 } 70 return result; 71 } 72 73 83 protected final boolean isOpeningTag(final String token, final String tag) { 84 85 boolean result= token.length() > 0 && token.charAt(0) == HTML_TAG_PREFIX && !token.startsWith(HTML_CLOSE_PREFIX) && token.charAt(token.length() - 1) == HTML_TAG_POSTFIX; 86 if (result) { 87 88 setAttribute(COMMENT_OPEN); 89 result= token.startsWith(tag, 1); 90 } 91 return result; 92 } 93 94 110 protected final void markHtmlTag(final String [] tags, final String token, final int attribute, final boolean open, final boolean close) { 111 112 if (token.charAt(0) == HTML_TAG_PREFIX && token.charAt(token.length() - 1) == HTML_TAG_POSTFIX) { 113 114 String tag= null; 115 boolean isOpen= false; 116 boolean isClose= false; 117 118 for (int index= 0; index < tags.length; index++) { 119 120 tag= tags[index]; 121 122 isOpen= isOpeningTag(token, tag); 123 isClose= isClosingTag(token, tag); 124 125 if ((open && isOpen) || (close && isClose)) { 126 127 setAttribute(attribute); 128 break; 129 } 130 } 131 } 132 } 133 134 143 protected final void markPrefixTag(final String [] tags, final char prefix, final String token, final int attribute) { 144 145 if (token.charAt(0) == prefix) { 146 147 String tag= null; 148 for (int index= 0; index < tags.length; index++) { 149 150 tag= tags[index]; 151 if (token.equals(tag)) { 152 153 setAttribute(attribute); 154 break; 155 } 156 } 157 } 158 } 159 160 171 protected final int markTagRange(final String token, final String tag, int level, final int key, final boolean html) { 172 173 if (isOpeningTag(token, tag)) { 174 if (level++ > 0) 175 setAttribute(key); 176 } else if (isClosingTag(token, tag)) { 177 if (--level > 0) 178 setAttribute(key); 179 } else if (level > 0) { 180 if (html || !hasAttribute(COMMENT_HTML)) 181 setAttribute(key); 182 } 183 return level; 184 } 185 186 192 public final void move(final int delta) { 193 offset += delta; 194 } 195 196 202 protected final void setAttribute(final int attribute) { 203 fAttributes |= attribute; 204 } 205 206 212 public final void trimBegin(final int delta) { 213 offset += delta; 214 length -= delta; 215 } 216 217 223 public final void trimEnd(final int delta) { 224 length += delta; 225 } 226 } 227 | Popular Tags |