[361553] [formatting] Formatting a JSP file, containing Java snippets, leads to misformatted or even lost code
diff --git a/bundles/org.eclipse.wst.jsdt.web.core/.settings/.api_filters b/bundles/org.eclipse.wst.jsdt.web.core/.settings/.api_filters
index 0e5c897..69ddd39 100644
--- a/bundles/org.eclipse.wst.jsdt.web.core/.settings/.api_filters
+++ b/bundles/org.eclipse.wst.jsdt.web.core/.settings/.api_filters
@@ -11,6 +11,11 @@
<resource path="src/org/eclipse/wst/jsdt/web/core/javascript/JsTranslation.java" type="org.eclipse.wst.jsdt.web.core.javascript.JsTranslation">
<filter id="1143996420">
<message_arguments>
+ <message_argument value="getElementsFromWebRange(int, int)"/>
+ </message_arguments>
+ </filter>
+ <filter id="1143996420">
+ <message_arguments>
<message_argument value="getJavaScriptOffset(int)"/>
</message_arguments>
</filter>
diff --git a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/JsTranslation.java b/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/JsTranslation.java
index 3470397..9021f94 100644
--- a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/JsTranslation.java
+++ b/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/JsTranslation.java
@@ -312,6 +312,12 @@
}
return result;
}
+
+ public IJavaScriptElement[] getElementsFromWebRange(int webPositionStart, int webPositionEnd) {
+ int javaPositionStart = getJavaScriptOffset(webPositionStart);
+ int javaPositionEnd = getJavaScriptOffset(webPositionEnd);
+ return getElementsFromJsRange(javaPositionStart, javaPositionEnd);
+ }
private String getHtmlPageName() {
IPath path = new Path(fModelBaseLocation);
diff --git a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/contentassist/JSDTCompletionProposal.java b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/contentassist/JSDTCompletionProposal.java
index c32f660..2204dfe 100644
--- a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/contentassist/JSDTCompletionProposal.java
+++ b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/contentassist/JSDTCompletionProposal.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 IBM Corporation and others.
+ * Copyright (c) 2007, 2012 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
@@ -19,7 +19,6 @@
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.wst.jsdt.internal.ui.text.java.JavaCompletionProposal;
-import org.eclipse.wst.jsdt.internal.ui.text.java.LazyJavaCompletionProposal;
import org.eclipse.wst.jsdt.internal.ui.text.java.LazyJavaTypeCompletionProposal;
import org.eclipse.wst.jsdt.ui.text.java.IJavaCompletionProposal;
@@ -57,12 +56,12 @@
* <p>Uses the wrapped proposal if its lazy</p>
*/
public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
- if (this.fJavaCompletionProposal instanceof LazyJavaCompletionProposal) {
- ((LazyJavaCompletionProposal) this.fJavaCompletionProposal).apply(viewer, trigger, stateMask, offset);
- }
- else {
+// if (this.fJavaCompletionProposal instanceof LazyJavaCompletionProposal) {
+// ((LazyJavaCompletionProposal) this.fJavaCompletionProposal).apply(viewer, trigger, stateMask, offset);
+// }
+// else {
super.apply(viewer, trigger, stateMask, offset);
- }
+// }
}
/**
@@ -72,12 +71,12 @@
*/
public Point getSelection(IDocument document) {
Point selection;
- if (this.fJavaCompletionProposal instanceof LazyJavaCompletionProposal) {
- selection = this.fJavaCompletionProposal.getSelection(document);
- }
- else {
+// if (this.fJavaCompletionProposal instanceof LazyJavaCompletionProposal) {
+// selection = this.fJavaCompletionProposal.getSelection(document);
+// }
+// else {
selection = super.getSelection(document);
- }
+// }
return selection;
}
diff --git a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/contentassist/JSDTContentAssistantProcessor.java b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/contentassist/JSDTContentAssistantProcessor.java
index 29b5e26..9ada6ea 100644
--- a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/contentassist/JSDTContentAssistantProcessor.java
+++ b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/contentassist/JSDTContentAssistantProcessor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 IBM Corporation and others.
+ * Copyright (c) 2007, 2012 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
@@ -16,6 +16,7 @@
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.wst.jsdt.core.IJavaScriptUnit;
import org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation;
+import org.eclipse.wst.jsdt.web.core.javascript.JsTranslation;
import org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter;
import org.eclipse.wst.jsdt.web.ui.internal.JsUIMessages;
import org.eclipse.wst.sse.core.StructuredModelManager;
@@ -75,7 +76,7 @@
if (translationAdapter != null) {
IJsTranslation translation = translationAdapter.getJsTranslation(true);
- fJavaPosition = getDocumentPosition();
+ fJavaPosition = ((JsTranslation)translation).getJavaScriptOffset(getDocumentPosition());
try {
IJavaScriptUnit cu = translation.getCompilationUnit();
// can't get java proposals w/out a compilation unit
diff --git a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/contentassist/JSDTProposalCollector.java b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/contentassist/JSDTProposalCollector.java
index 9f873f5..cc7b354 100644
--- a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/contentassist/JSDTProposalCollector.java
+++ b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/contentassist/JSDTProposalCollector.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 IBM Corporation and others.
+ * Copyright (c) 2007, 2012 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
@@ -23,6 +23,7 @@
import org.eclipse.wst.jsdt.ui.text.java.CompletionProposalComparator;
import org.eclipse.wst.jsdt.ui.text.java.IJavaCompletionProposal;
import org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation;
+import org.eclipse.wst.jsdt.web.core.javascript.JsTranslation;
/**
@@ -91,9 +92,9 @@
JSDTCompletionProposal jspProposal;
String completion = String.valueOf(proposal.getCompletion());
// java offset
- int offset = proposal.getReplaceStart();
+ int offset = ((JsTranslation)fTranslation).getWebPageOffset(proposal.getReplaceStart());
// replacement length
- int length = proposal.getReplaceEnd() - offset;
+ int length = proposal.getReplaceEnd() - proposal.getReplaceStart();
// translate offset from Java > JSP
// cursor position after must be calculated
int positionAfter = calculatePositionAfter(proposal, completion);
diff --git a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/hyperlink/JSDTHyperlinkDetector.java b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/hyperlink/JSDTHyperlinkDetector.java
index 2193098..6011638 100644
--- a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/hyperlink/JSDTHyperlinkDetector.java
+++ b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/hyperlink/JSDTHyperlinkDetector.java
@@ -35,6 +35,7 @@
import org.eclipse.wst.jsdt.core.JavaScriptModelException;
import org.eclipse.wst.jsdt.internal.core.JavaElement;
import org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation;
+import org.eclipse.wst.jsdt.web.core.javascript.JsTranslation;
import org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter;
import org.eclipse.wst.jsdt.web.ui.internal.Logger;
import org.eclipse.wst.sse.core.StructuredModelManager;
@@ -158,7 +159,7 @@
IDocument document = textViewer.getDocument();
IJsTranslation jsTranslation = getJsTranslation(document);
if (jsTranslation != null) {
- IJavaScriptElement[] elements = jsTranslation.getElementsFromJsRange(region.getOffset(), region.getOffset() + region.getLength());
+ IJavaScriptElement[] elements = ((JsTranslation)jsTranslation).getElementsFromWebRange(region.getOffset(), region.getOffset() + region.getLength());
if (elements != null && elements.length > 0) {
// create a hyperlink for each JavaScript element
for (int i = 0; i < elements.length; ++i) {
diff --git a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/java/search/JsFindOccurrencesProcessor.java b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/java/search/JsFindOccurrencesProcessor.java
index 7a0d93d..7e4cc6a 100644
--- a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/java/search/JsFindOccurrencesProcessor.java
+++ b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/java/search/JsFindOccurrencesProcessor.java
@@ -17,6 +17,7 @@
import org.eclipse.search.ui.ISearchQuery;
import org.eclipse.wst.jsdt.core.IJavaScriptElement;
import org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation;
+import org.eclipse.wst.jsdt.web.core.javascript.JsTranslation;
import org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter;
import org.eclipse.wst.jsdt.web.core.text.IJsPartitions;
import org.eclipse.wst.sse.core.StructuredModelManager;
@@ -57,7 +58,7 @@
if (adapter != null) {
IJsTranslation translation = adapter.getJsTranslation(false);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102211
- elements = translation.getElementsFromJsRange(selection.getOffset(), selection.getOffset() + selection.getLength());
+ elements = ((JsTranslation)translation).getElementsFromWebRange(selection.getOffset(), selection.getOffset() + selection.getLength());
}
}
} finally {
diff --git a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/taginfo/JSDTHoverProcessor.java b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/taginfo/JSDTHoverProcessor.java
index d5e1669..e1ee74e 100644
--- a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/taginfo/JSDTHoverProcessor.java
+++ b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/taginfo/JSDTHoverProcessor.java
@@ -20,6 +20,7 @@
import org.eclipse.wst.jsdt.ui.JSdocContentAccess;
import org.eclipse.wst.jsdt.ui.JavaScriptElementLabels;
import org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation;
+import org.eclipse.wst.jsdt.web.core.javascript.JsTranslation;
import org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter;
import org.eclipse.wst.sse.core.StructuredModelManager;
import org.eclipse.wst.sse.ui.internal.taginfo.AbstractHoverProcessor;
@@ -102,7 +103,7 @@
JsTranslationAdapter adapter = (JsTranslationAdapter) xmlDoc.getAdapterFor(IJsTranslation.class);
if (adapter != null) {
IJsTranslation translation = adapter.getJsTranslation(true);
- IJavaScriptElement[] result = translation.getElementsFromJsRange(hoverRegion.getOffset(), hoverRegion.getOffset() + hoverRegion.getLength());
+ IJavaScriptElement[] result = ((JsTranslation)translation).getElementsFromWebRange(hoverRegion.getOffset(), hoverRegion.getOffset() + hoverRegion.getLength());
// Vector filteredResults = new Vector();
// List badFunctions = translation.getGeneratedFunctionNames();
// boolean bad = false;