[407553] 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 9b9e9f2..b2d11a8 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
@@ -1301,12 +1301,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..7fff05c 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
@@ -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;
}