Package org.bluezoo.gumdrop.servlet.jsp
Class DeclarationElement
java.lang.Object
org.bluezoo.gumdrop.servlet.jsp.DeclarationElement
- All Implemented Interfaces:
JSPElement
Represents a JSP declaration element:
<%! java declarations %>.
Declarations contain Java code that becomes class-level members of the generated servlet. This includes instance variables, methods, and inner classes. Declarations are executed when the servlet is instantiated, not during request processing.
Example declarations:
<%!
private int counter = 0;
private String formatDate(Date date) {
return new SimpleDateFormat("yyyy-MM-dd").format(date);
}
static {
System.out.println("Servlet class loaded");
}
%>
Note: Instance variables declared in JSP declarations are shared across all requests to the servlet, so thread safety must be considered.
- Author:
- Chris Burdess
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.bluezoo.gumdrop.servlet.jsp.JSPElement
JSPElement.Type -
Constructor Summary
ConstructorsConstructorDescriptionDeclarationElement(String declaration, int lineNumber, int columnNumber) Creates a new declaration element. -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(JSPElementVisitor visitor) Accepts a visitor for processing this element.booleanChecks if this declaration appears to contain field definitions.booleanChecks if this declaration appears to contain method definitions.booleanintGets the column number where this element begins in the source JSP file.Gets the Java declaration code contained in this element.intGets the line number where this element begins in the source JSP file.getType()Gets the type of this JSP element.inthashCode()booleanisEmpty()Checks if this declaration contains only whitespace or comments.toString()
-
Constructor Details
-
DeclarationElement
Creates a new declaration element.- Parameters:
declaration- the Java declaration codelineNumber- the line number where this element begins (1-based)columnNumber- the column number where this element begins (1-based)
-
-
Method Details
-
getType
Description copied from interface:JSPElementGets the type of this JSP element.- Specified by:
getTypein interfaceJSPElement- Returns:
- the element type
-
getLineNumber
public int getLineNumber()Description copied from interface:JSPElementGets the line number where this element begins in the source JSP file.- Specified by:
getLineNumberin interfaceJSPElement- Returns:
- the line number (1-based), or -1 if not available
-
getColumnNumber
public int getColumnNumber()Description copied from interface:JSPElementGets the column number where this element begins in the source JSP file.- Specified by:
getColumnNumberin interfaceJSPElement- Returns:
- the column number (1-based), or -1 if not available
-
getDeclaration
Gets the Java declaration code contained in this element.- Returns:
- the Java declaration code (never null)
-
isEmpty
public boolean isEmpty()Checks if this declaration contains only whitespace or comments.- Returns:
trueif the declaration is effectively empty
-
containsMethods
public boolean containsMethods()Checks if this declaration appears to contain method definitions. This is a heuristic check for code organization purposes.- Returns:
trueif the declaration likely contains methods
-
containsFields
public boolean containsFields()Checks if this declaration appears to contain field definitions. This is a heuristic check for code organization purposes.- Returns:
trueif the declaration likely contains fields
-
accept
Description copied from interface:JSPElementAccepts a visitor for processing this element. This enables the visitor pattern for code generation and other tree traversal operations.- Specified by:
acceptin interfaceJSPElement- Parameters:
visitor- the visitor to accept- Throws:
Exception- if the visitor encounters an error
-
toString
-
equals
-
hashCode
public int hashCode()
-