### Eclipse Workspace Patch 1.0 #P org.eclipse.jst.jsp.core Index: src/org/eclipse/jst/jsp/core/internal/java/jspel/ELGeneratorVisitor.java =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/ELGeneratorVisitor.java,v retrieving revision 1.8 diff -u -r1.8 ELGeneratorVisitor.java --- src/org/eclipse/jst/jsp/core/internal/java/jspel/ELGeneratorVisitor.java 10 Apr 2007 17:02:52 -0000 1.8 +++ src/org/eclipse/jst/jsp/core/internal/java/jspel/ELGeneratorVisitor.java 24 Jun 2008 21:52:48 -0000 @@ -19,6 +19,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import org.eclipse.jface.text.Position; import org.eclipse.jst.jsp.core.internal.contentmodel.TaglibController; @@ -35,8 +36,11 @@ private static final String ENDL = "\n"; //$NON-NLS-1$ private static final String fExpressionHeader1 = "public String _elExpression"; //$NON-NLS-1$ + + //TODO What exceptions are the generated functions allowed to throw? Think of called mapped el functions... private static final String fExpressionHeader2 = "()" + ENDL + //$NON-NLS-1$ - "\t\tthrows java.io.IOException, javax.servlet.ServletException {" + ENDL + //$NON-NLS-1$ + "\t\tthrows java.io.IOException, javax.servlet.ServletException, javax.servlet.jsp.JspException" + + " {" + ENDL + //$NON-NLS-1$ "javax.servlet.jsp.PageContext pageContext = null;" + ENDL + //$NON-NLS-1$ "java.util.Map param = null;" + ENDL + //$NON-NLS-1$ "java.util.Map paramValues = null;" + ENDL + //$NON-NLS-1$ @@ -76,6 +80,8 @@ private IStructuredDocument fDocument = null; private int fContentStart; private static Map fOperatorMap; + // start of the generated function definition, if any: + private int fGeneratedFunctionStart; // this flag lets us know if we were unable to generate for some reason. One possible reason is that the expression // contains a reference to a variable for which information is only available at runtime. @@ -116,6 +122,7 @@ fContentStart = contentStart; fDocument = document; fCurrentNode = currentNode; + fGeneratedFunctionStart = -1; //set when generating function definition } /** @@ -214,23 +221,40 @@ * Handle top-level expression */ public Object visit(ASTExpression node, Object data) { - int start = node.getFirstToken().beginColumn - 1; - int end = node.lastToken.endColumn - 1; - append(fExpressionHeader1, start, start); + return node.childrenAccept(this, data); + } + + public void startFunctionDefinition(int start) { + fGeneratedFunctionStart = fResult.length(); + append(fExpressionHeader1, start, start); append(Integer.toString(getMethodCounter()), start, start); append(fExpressionHeader2, start, start); - - Object retval = node.childrenAccept(this, data); + } - append(fFooter, end, end); - - // something is preventing good code generation so empty out the result and the map. - if(!fCanGenerate) { - fResult.delete(0, fResult.length()); - fCodeMap.clear(); - } - return retval; - } + public void endFunctionDefinition(int end) { + if (fGeneratedFunctionStart < 0) { + throw new IllegalStateException("Cannot end function definition because none has been started."); + } + append(fFooter, end, end); + + // something is preventing good code generation so empty out the result and the map. + if(!fCanGenerate) { + fResult.delete(fGeneratedFunctionStart, fResult.length()); + fOffsetInUserCode = fResult.length(); + //remove all fCodeMap entries for the removed code: + for (Iterator it = fCodeMap.entrySet().iterator(); it.hasNext();) { + Map.Entry entry = (Entry) it.next(); + if (entry.getKey() instanceof Position) { + Position pos = (Position) entry.getKey(); + if (pos.getOffset() >= fGeneratedFunctionStart) { + it.remove(); + } + } + } + } + fGeneratedFunctionStart = -1; + + } /** * Generically generate an operator node. @@ -378,7 +402,7 @@ */ public Object visit(ASTValuePrefix node, Object data) { // this is a raw identifier. May sure it's an implicit object. - // This is the primary plae where modification is needed to + // This is the primary place where modification is needed to // support JSF backing beans. if(null == node.children) { if(isCompletingObject(node.firstToken.image)) { @@ -457,8 +481,12 @@ * Literal */ public Object visit(ASTLiteral node, Object data) { - // TODO any further translation needed? - append(node.firstToken); + String literal = node.firstToken.image; + if (literal.startsWith("'") && literal.endsWith("'")) { + literal = "\"" + literal.substring(1, literal.length() - 1) + "\""; + } + // TODO any further translation needed? + append(literal, node.firstToken); return null; } } Index: src/org/eclipse/jst/jsp/core/internal/java/jspel/ELGenerator.java =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/ELGenerator.java,v retrieving revision 1.4 diff -u -r1.4 ELGenerator.java --- src/org/eclipse/jst/jsp/core/internal/java/jspel/ELGenerator.java 10 Apr 2007 17:02:52 -0000 1.4 +++ src/org/eclipse/jst/jsp/core/internal/java/jspel/ELGenerator.java 24 Jun 2008 21:52:48 -0000 @@ -40,6 +40,8 @@ */ public void generate(ASTExpression root, IStructuredDocumentRegion currentNode, StringBuffer result, Map codeMap, IStructuredDocument document, ITextRegionCollection jspReferenceRegion, int contentStart, int contentLength) { ELGeneratorVisitor visitor = new ELGeneratorVisitor(result, currentNode, codeMap, document, jspReferenceRegion, contentStart); + visitor.startFunctionDefinition(root.getFirstToken().beginColumn - 1); root.jjtAccept(visitor, null); + visitor.endFunctionDefinition(root.getLastToken().endColumn - 1); } }