[407565] JSP translation incorrect for expressions in script blocks
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslator.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslator.java index ae8de80..dbfe789 100644 --- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslator.java +++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslator.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -1296,12 +1296,7 @@ StringBuffer fullText = new StringBuffer(containerRegion.getFullText(region)); while(regions.hasNext()) { region = (ITextRegion)regions.next(); - if (region instanceof ITextRegionContainer) { - // pass in block text's container & iterator - Iterator regionIterator = ((ITextRegionCollection) region).getRegions().iterator(); - translateJSPNode(region, regionIterator, type, EMBEDDED_JSP); - } - + // Do not immediately translate container regions, since they may use variables declared within the full text if(region.getType() == DOMRegionContext.BLOCK_TEXT) { fullText.append(containerRegion.getFullText(region)); } else {
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/XMLJSPRegionHelper.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/XMLJSPRegionHelper.java index d281590..39a1a77 100644 --- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/XMLJSPRegionHelper.java +++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/XMLJSPRegionHelper.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -230,6 +230,20 @@ processDeclaration(sdRegion); } } + else { + final String previousType = sdRegion.getPrevious() != null ? sdRegion.getPrevious().getType() : null; + if (previousType != null) { + if (DOMJSPRegionContexts.JSP_EXPRESSION_OPEN.equals(previousType)) { + processExpression(sdRegion, true); + } + else if (DOMJSPRegionContexts.JSP_SCRIPTLET_OPEN.equals(previousType)) { + processScriptlet(sdRegion, true); + } + else if (DOMJSPRegionContexts.JSP_DECLARATION_OPEN.equals(previousType)) { + processDeclaration(sdRegion, true); + } + } + } } else { fTagname = null; @@ -314,23 +328,50 @@ } protected void processDeclaration(IStructuredDocumentRegion sdRegion) { + processDeclaration(sdRegion, false); + } + + protected void processDeclaration(IStructuredDocumentRegion sdRegion, boolean embedded) { prepareText(sdRegion); IStructuredDocumentRegion currentNode = fTranslator.getCurrentNode(); - this.fTranslator.translateDeclarationString(fStrippedText, currentNode, currentNode.getStartOffset(), currentNode.getLength(), fAppendAsIndirectSource); + if (embedded) { + this.fTranslator.translateDeclarationString(fStrippedText, sdRegion, currentNode.getStartOffset() + sdRegion.getStartOffset(), sdRegion.getLength(), fAppendAsIndirectSource); + } + else { + this.fTranslator.translateDeclarationString(fStrippedText, currentNode, currentNode.getStartOffset(), currentNode.getLength(), fAppendAsIndirectSource); + } fPossibleOwner = JSPTranslator.DECLARATION; } protected void processExpression(IStructuredDocumentRegion sdRegion) { + processExpression(sdRegion, false); + } + + protected void processExpression(IStructuredDocumentRegion sdRegion, boolean embedded) { prepareText(sdRegion); IStructuredDocumentRegion currentNode = fTranslator.getCurrentNode(); - this.fTranslator.translateExpressionString(fStrippedText, currentNode, currentNode.getStartOffset(), currentNode.getLength(), fAppendAsIndirectSource); + if (embedded) { + this.fTranslator.translateExpressionString(fStrippedText, sdRegion, currentNode.getStartOffset() + sdRegion.getStartOffset(), sdRegion.getLength(), fAppendAsIndirectSource); + } + else { + this.fTranslator.translateExpressionString(fStrippedText, currentNode, currentNode.getStartOffset(), currentNode.getLength(), fAppendAsIndirectSource); + } fPossibleOwner = JSPTranslator.EXPRESSION; } protected void processScriptlet(IStructuredDocumentRegion sdRegion) { + processScriptlet(sdRegion, false); + } + + protected void processScriptlet(IStructuredDocumentRegion sdRegion, boolean embedded) { prepareText(sdRegion); IStructuredDocumentRegion currentNode = fTranslator.getCurrentNode(); - this.fTranslator.translateScriptletString(fStrippedText, currentNode, currentNode.getStartOffset(), currentNode.getLength(), fAppendAsIndirectSource); + if (embedded) { + this.fTranslator.translateScriptletString(fStrippedText, sdRegion, currentNode.getStartOffset() + sdRegion.getStartOffset(), sdRegion.getLength(), fAppendAsIndirectSource); + } + else { + this.fTranslator.translateScriptletString(fStrippedText, currentNode, currentNode.getStartOffset(), currentNode.getLength(), fAppendAsIndirectSource); + } fPossibleOwner = JSPTranslator.SCRIPTLET; }