1 19 20 package org.netbeans.modules.web.core.syntax; 21 22 import java.util.*; 23 24 import javax.swing.text.*; 25 26 import org.netbeans.editor.ext.*; 27 28 33 public abstract class SyntaxElement extends Object { 34 35 private JspSyntaxSupport support; 36 private SyntaxElement previous; 37 private SyntaxElement next; 38 39 int offset; 40 int length; 41 42 43 public SyntaxElement( JspSyntaxSupport support, int from, int to ) { 44 this.support = support; 45 this.offset = from; 46 this.length = to-from; 47 } 48 49 public abstract int getCompletionContext(); 50 51 public int getElementOffset() { 52 return offset; 53 } 54 55 public int getElementLength() { 56 return length; 57 } 58 59 public SyntaxElement getPrevious() throws BadLocationException { 60 if( previous == null ) { 61 previous = support.getPreviousElement( offset ); 62 if( previous != null ) previous.next = this; 63 } 64 return previous; 65 } 66 67 public SyntaxElement getNext() throws BadLocationException { 68 if ( next == null ) { 69 next = support.getNextElement( offset+length ); 70 if ( next != null ) next.previous = this; 71 } 72 return next; 73 } 74 75 public String getImage() throws BadLocationException { 76 return support.getDocument().getText(offset, length); 77 } 78 79 public String toString() { 80 String content = "???"; 81 try { 82 content = support.getDocument().getText(getElementOffset(), getElementLength()); 83 }catch(BadLocationException e) { 84 } 86 return "Element [" + offset + "," + (offset+length-1) + "] (" + content + ")"; } 88 89 public static class Comment extends SyntaxElement { 90 public Comment( JspSyntaxSupport support, int from, int to ) { 91 super( support, from, to ); 92 } 93 94 public int getCompletionContext() { 95 return JspSyntaxSupport.COMMENT_COMPLETION_CONTEXT; 96 } 97 98 public String toString() { 99 return "JSP Comment " + super.toString(); } 101 } 102 103 public static class ExpressionLanguage extends SyntaxElement { 104 public ExpressionLanguage( JspSyntaxSupport support, int from, int to ) { 105 super( support, from, to ); 106 } 107 108 public int getCompletionContext() { 109 return JspSyntaxSupport.EL_COMPLETION_CONTEXT; 110 } 111 112 public String toString() { 113 return "Expression Language " + super.toString(); } 115 } 116 117 public static class Text extends SyntaxElement { 118 public Text( JspSyntaxSupport support, int from, int to ) { 119 super( support, from, to ); 120 } 121 122 public int getCompletionContext() { 123 return JspSyntaxSupport.TEXT_COMPLETION_CONTEXT; 124 } 125 126 public String toString() { 127 return "JSP Text " + super.toString(); } 129 } 130 131 public static class ContentL extends SyntaxElement { 132 public ContentL( JspSyntaxSupport support, int from, int to ) { 133 super( support, from, to ); 134 } 135 136 public int getCompletionContext() { 137 return JspSyntaxSupport.CONTENTL_COMPLETION_CONTEXT; 138 } 139 140 public String toString() { 141 return "JSP Content Language " + super.toString(); } 143 } 144 145 public static class ScriptingL extends SyntaxElement { 146 public ScriptingL( JspSyntaxSupport support, int from, int to ) { 147 super( support, from, to ); 148 } 149 150 public int getCompletionContext() { 151 return JspSyntaxSupport.SCRIPTINGL_COMPLETION_CONTEXT; 152 } 153 154 public String toString() { 155 return "JSP Scripting Language " + super.toString(); } 157 } 158 159 public static class Error extends SyntaxElement { 160 public Error( JspSyntaxSupport support, int from, int to ) { 161 super( support, from, to ); 162 } 163 164 public int getCompletionContext() { 165 return JspSyntaxSupport.ERROR_COMPLETION_CONTEXT; 166 } 167 168 public String toString() { 169 return "JSP Error " + super.toString(); } 171 } 172 173 public static abstract class TagLikeElement extends SyntaxElement { 174 String name; 175 176 public TagLikeElement(JspSyntaxSupport support, int from, int to, String name) { 177 super( support, from,to ); 178 this.name = name; 179 } 180 181 public String getName() { 182 return name; 183 } 184 185 public String toString() { 186 return super.toString() + " - '" + name + "'"; } 188 } 189 190 public static class EndTag extends TagLikeElement { 191 public EndTag(JspSyntaxSupport support, int from, int to, String name) { 192 super(support, from, to, name); 193 } 194 195 public int getCompletionContext() { 196 return JspSyntaxSupport.ENDTAG_COMPLETION_CONTEXT; 197 } 198 199 public String toString() { 200 return "JSP EndTag " + super.toString(); } 202 } 203 204 205 public static abstract class TagDirective extends TagLikeElement { 206 Map attribs; 207 208 public TagDirective( JspSyntaxSupport support, int from, int to, String name, Map attribs ) { 209 super(support, from, to, name); 210 this.attribs = attribs; 211 } 212 213 public Map getAttributes() { 214 return attribs; 215 } 216 217 public String toString() { 218 StringBuffer ret = new StringBuffer (super.toString() + " - {" ); 220 for( Iterator i = attribs.keySet().iterator(); i.hasNext(); ) { 221 Object next = i.next(); 222 ret.append( next ). 223 append( "='" ). append( attribs.get(next) ). 225 append( "', " ); } 227 228 ret.append( "}" ); return ret.toString(); 230 } 231 } 232 233 public static class Tag extends TagDirective { 234 235 private boolean isClosed; 236 237 public Tag( JspSyntaxSupport support, int from, int to, String name, Map attribs, boolean isClosed) { 238 super(support, from, to, name, attribs); 239 this.isClosed = isClosed; 240 } 241 242 public Tag( JspSyntaxSupport support, int from, int to, String name, Map attribs ) { 243 this(support, from, to, name, attribs, false); 244 } 245 246 public int getCompletionContext() { 247 return JspSyntaxSupport.TAG_COMPLETION_CONTEXT; 248 } 249 250 public boolean isClosed () { 251 return isClosed; 252 } 253 254 public String toString() { 255 return "JSP Tag " + super.toString(); } 257 } 258 259 public static class Directive extends TagDirective { 260 261 public Directive( JspSyntaxSupport support, int from, int to, String name, Map attribs ) { 262 super(support, from, to, name, attribs); 263 } 264 265 public int getCompletionContext() { 266 return JspSyntaxSupport.DIRECTIVE_COMPLETION_CONTEXT; 267 } 268 269 public String toString() { 270 return "JSP Directive " + super.toString(); } 272 } 273 274 275 } | Popular Tags |