[574786] JSP EL translator must account for Jakarta EE 9 package change
diff --git a/web/bundles/org.eclipse.jst.jsp.core/META-INF/MANIFEST.MF b/web/bundles/org.eclipse.jst.jsp.core/META-INF/MANIFEST.MF
index 21d3961..a1ea487 100644
--- a/web/bundles/org.eclipse.jst.jsp.core/META-INF/MANIFEST.MF
+++ b/web/bundles/org.eclipse.jst.jsp.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jst.jsp.core;singleton:=true
-Bundle-Version: 1.4.0.qualifier
+Bundle-Version: 1.4.100.qualifier
Bundle-Activator: org.eclipse.jst.jsp.core.internal.JSPCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/web/bundles/org.eclipse.jst.jsp.core/pom.xml b/web/bundles/org.eclipse.jst.jsp.core/pom.xml
index 2046350..0779833 100644
--- a/web/bundles/org.eclipse.jst.jsp.core/pom.xml
+++ b/web/bundles/org.eclipse.jst.jsp.core/pom.xml
@@ -21,6 +21,6 @@
<groupId>org.eclipse.webtools.sourceediting</groupId>
<artifactId>org.eclipse.jst.jsp.core</artifactId>
- <version>1.4.0-SNAPSHOT</version>
+ <version>1.4.100-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contenttype/DeploymentDescriptorPropertyCache.java b/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contenttype/DeploymentDescriptorPropertyCache.java
index 8d613da..ba8d459 100644
--- a/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contenttype/DeploymentDescriptorPropertyCache.java
+++ b/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contenttype/DeploymentDescriptorPropertyCache.java
@@ -18,6 +18,7 @@
import java.io.StringReader;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
+import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -687,7 +688,7 @@
/**
* Map of project names to a structure representing the available Servlet API.
*/
- Map<String, ServletAPIDescriptor> apiVersions = new HashMap<>();
+ Map<String, Reference<ServletAPIDescriptor>> apiVersions = new HashMap<>();
final static Object LOCK = new Object();
@@ -1040,14 +1041,15 @@
* Build Path, <code>null</code> if none was discoverable.
*/
public ServletAPIDescriptor getServletAPIVersion(IProject project) {
- ServletAPIDescriptor descriptor = apiVersions.get(project.getName());
+ Reference<ServletAPIDescriptor> ref = apiVersions.get(project.getName());
+ ServletAPIDescriptor descriptor = ref != null ? ref.get() : null;
if (descriptor == null) {
descriptor = discoverServletAPIVersion(project);
if (descriptor != null) {
- apiVersions.put(project.getName(), descriptor);
+ apiVersions.put(project.getName(), new SoftReference<>(descriptor));
}
else {
- apiVersions.put(project.getName(), ServletAPIDescriptor.DEFAULT);
+ apiVersions.put(project.getName(), new WeakReference<>(ServletAPIDescriptor.DEFAULT));
descriptor = ServletAPIDescriptor.DEFAULT;
}
}
diff --git a/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contenttype/ServletAPIDescriptor.java b/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contenttype/ServletAPIDescriptor.java
index 22927ce..5aecef3 100644
--- a/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contenttype/ServletAPIDescriptor.java
+++ b/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contenttype/ServletAPIDescriptor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2020 IBM Corporation and others.
+ * Copyright (c) 2020, 2021 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -18,7 +18,7 @@
* project. Typically this will have been discovered against actual libraries.
*/
public class ServletAPIDescriptor {
- public static ServletAPIDescriptor DEFAULT = new ServletAPIDescriptor("javax.servlet", 4);
+ public static ServletAPIDescriptor DEFAULT = new ServletAPIDescriptor("jakarta.servlet", 5);
public ServletAPIDescriptor(String rootPackage, float apiVersion) {
super();
diff --git a/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslator.java b/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslator.java
index ef72691..f530633 100644
--- a/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslator.java
+++ b/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslator.java
@@ -130,7 +130,7 @@
* @see #writeRanges(ObjectOutput, HashMap)
* @see #readRanges(ObjectInput)
*/
- private static final long serialVersionUID = 3L;
+ private static final long serialVersionUID = 4L;
/** for debugging */
private static final boolean DEBUG = Boolean.valueOf(Platform.getDebugOption("org.eclipse.jst.jsp.core/debug/jspjavamapping")).booleanValue(); //$NON-NLS-1$
@@ -1335,7 +1335,7 @@
/**
*
- * @return the status of the translator's progrss monitor, false if the
+ * @return the status of the translator's progress monitor, false if the
* monitor is null
*/
private boolean isCanceled() {
@@ -1908,7 +1908,7 @@
// id
// Iterate over all declared extensions of this extension point.
- // A single plugin may extend the extension point more than once,
+ // A single plug-in may extend the extension point more than once,
// although it's not recommended.
IConfigurationElement bestTranslator = null;
IExtension[] extensions = extensionPoint.getExtensions();
diff --git a/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/ELGeneratorVisitor.java b/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/ELGeneratorVisitor.java
index 868f5c5..dd9aaf6 100644
--- a/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/ELGeneratorVisitor.java
+++ b/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/ELGeneratorVisitor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 BEA Systems and others.
+ * Copyright (c) 2005, 2021 BEA Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -26,7 +26,9 @@
import java.util.Map.Entry;
import java.util.Set;
+import org.eclipse.core.filebuffers.FileBuffers;
import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.filebuffers.ITextFileBufferManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
@@ -47,10 +49,13 @@
import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager;
import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker;
import org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDFunction;
+import org.eclipse.jst.jsp.core.internal.contenttype.DeploymentDescriptorPropertyCache;
+import org.eclipse.jst.jsp.core.internal.contenttype.ServletAPIDescriptor;
import org.eclipse.jst.jsp.core.internal.preferences.JSPCorePreferenceNames;
import org.eclipse.jst.jsp.core.jspel.ELProblem;
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.sse.core.internal.FileBufferModelManager;
+import org.eclipse.wst.sse.core.internal.Logger;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection;
@@ -63,35 +68,9 @@
private static final String ENDL = "\n"; //$NON-NLS-1$
private static final String fExpressionHeader1 = "public String _elExpression"; //$NON-NLS-1$
- private static final String fExpressionHeader2 = "()" + 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$
- "java.util.Map header = null;" + ENDL + //$NON-NLS-1$
- "java.util.Map headerValues = null;" + ENDL + //$NON-NLS-1$
- "java.util.Map cookie = null;" + ENDL + //$NON-NLS-1$
- "java.util.Map initParam = null;" + ENDL + //$NON-NLS-1$
- "java.util.Map pageScope = null;" + ENDL + //$NON-NLS-1$
- "java.util.Map requestScope = null;" + ENDL + //$NON-NLS-1$
- "java.util.Map sessionScope = null;" + ENDL + //$NON-NLS-1$
- "java.util.Map applicationScope = null;" + ENDL + //$NON-NLS-1$
- "return \"\"+( "; //$NON-NLS-1$
- private static final String fExpressionHeader2_param = "()" + 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<String, String> param = null;" + ENDL + //$NON-NLS-1$
- "java.util.Map<String, String[]> paramValues = null;" + ENDL + //$NON-NLS-1$
- "java.util.Map<String, String> header = null;" + ENDL + //$NON-NLS-1$
- "java.util.Map<String, String[]> headerValues = null;" + ENDL + //$NON-NLS-1$
- "java.util.Map<String, javax.servlet.http.Cookie> cookie = null;" + ENDL + //$NON-NLS-1$
- "java.util.Map<String, String> initParam = null;" + ENDL + //$NON-NLS-1$
- "java.util.Map<String, Object> pageScope = null;" + ENDL + //$NON-NLS-1$
- "java.util.Map<String, Object> requestScope = null;" + ENDL + //$NON-NLS-1$
- "java.util.Map<String, Object> sessionScope = null;" + ENDL + //$NON-NLS-1$
- "java.util.Map<String, Object> applicationScope = null;" + ENDL + //$NON-NLS-1$
- "return \"\"+( "; //$NON-NLS-1$
+ private String fExpressionHeader2 = null;
+ private String fExpressionHeader2_param = null;
private static final String fJspImplicitObjects[] = { "pageContext" }; //$NON-NLS-1$
@@ -138,11 +117,11 @@
private boolean fUseParameterizedTypes;
- private List fELProblems;
+ private List<ELProblem> fELProblems;
private IScopeContext[] fScopeContexts = null;
/**
- * Tranlsation of XML-style operators to java
+ * Translation of XML-style operators to java
*/
static {
fOperatorMap = new HashMap();
@@ -176,8 +155,9 @@
fCurrentNode = currentNode;
fGeneratedFunctionStart = -1; //set when generating function definition
fUseParameterizedTypes = compilerSupportsParameterizedTypes();
- fELProblems = new ArrayList();
+ fELProblems = new ArrayList<>();
fScopeContexts = getScopeContexts();
+ initForAPIContext(document);
}
/**
@@ -229,6 +209,55 @@
fOffsetInUserCode += newText.length();
}
+
+ ServletAPIDescriptor initForAPIContext(IStructuredDocument document) {
+ ServletAPIDescriptor apiContext = ServletAPIDescriptor.DEFAULT;
+ ITextFileBufferManager textFileBufferManager = FileBuffers.getTextFileBufferManager();
+ if (textFileBufferManager != null) {
+ ITextFileBuffer textFileBuffer = textFileBufferManager.getTextFileBuffer(document);
+ if (textFileBuffer != null) {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(textFileBuffer.getLocation().segment(0));
+ apiContext = DeploymentDescriptorPropertyCache.getInstance().getServletAPIVersion(project);
+ }
+ else {
+ Logger.log(Logger.ERROR, "No file buffer for document " + document);
+ }
+ }
+ else {
+ Logger.log(Logger.ERROR, "Missing text file buffer manager");
+ }
+ fExpressionHeader2 = "()" + ENDL + //$NON-NLS-1$
+ "\t\tthrows java.io.IOException, "+apiContext.getRootPackage()+".ServletException, "+apiContext.getRootPackage()+".jsp.JspException {" + ENDL + //$NON-NLS-1$
+ apiContext.getRootPackage()+".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$
+ "java.util.Map header = null;" + ENDL + //$NON-NLS-1$
+ "java.util.Map headerValues = null;" + ENDL + //$NON-NLS-1$
+ "java.util.Map cookie = null;" + ENDL + //$NON-NLS-1$
+ "java.util.Map initParam = null;" + ENDL + //$NON-NLS-1$
+ "java.util.Map pageScope = null;" + ENDL + //$NON-NLS-1$
+ "java.util.Map requestScope = null;" + ENDL + //$NON-NLS-1$
+ "java.util.Map sessionScope = null;" + ENDL + //$NON-NLS-1$
+ "java.util.Map applicationScope = null;" + ENDL + //$NON-NLS-1$
+ "return \"\"+( "; //$NON-NLS-1$
+
+ fExpressionHeader2_param = "()" + ENDL + //$NON-NLS-1$
+ "\t\tthrows java.io.IOException, "+apiContext.getRootPackage()+".ServletException, "+apiContext.getRootPackage()+".jsp.JspException {" + ENDL + //$NON-NLS-1$
+ apiContext.getRootPackage()+".jsp.PageContext pageContext = null;" + ENDL + //$NON-NLS-1$
+ "java.util.Map<String, String> param = null;" + ENDL + //$NON-NLS-1$
+ "java.util.Map<String, String[]> paramValues = null;" + ENDL + //$NON-NLS-1$
+ "java.util.Map<String, String> header = null;" + ENDL + //$NON-NLS-1$
+ "java.util.Map<String, String[]> headerValues = null;" + ENDL + //$NON-NLS-1$
+ "java.util.Map<String, "+apiContext.getRootPackage()+".http.Cookie> cookie = null;" + ENDL + //$NON-NLS-1$
+ "java.util.Map<String, String> initParam = null;" + ENDL + //$NON-NLS-1$
+ "java.util.Map<String, Object> pageScope = null;" + ENDL + //$NON-NLS-1$
+ "java.util.Map<String, Object> requestScope = null;" + ENDL + //$NON-NLS-1$
+ "java.util.Map<String, Object> sessionScope = null;" + ENDL + //$NON-NLS-1$
+ "java.util.Map<String, Object> applicationScope = null;" + ENDL + //$NON-NLS-1$
+ "return \"\"+( "; //$NON-NLS-1$
+ return apiContext;
+ }
+
/**
* Generate a function invocation.
*
@@ -243,9 +272,9 @@
if (docMgr == null)
return null;
- Iterator taglibs = docMgr.getCMDocumentTrackers(fCurrentNode.getStartOffset()).iterator();
+ Iterator<TaglibTracker> taglibs = docMgr.getCMDocumentTrackers(fCurrentNode.getStartOffset()).iterator();
while (taglibs.hasNext()) {
- TaglibTracker tracker = (TaglibTracker)taglibs.next();
+ TaglibTracker tracker = taglibs.next();
if(tracker.getPrefix().equals(prefix)) {
CMDocumentImpl doc = (CMDocumentImpl)tracker.getDocument();
@@ -606,7 +635,7 @@
/**
* @return the {@link ELProblem}s found by this visitor
*/
- public List getELProblems() {
+ public List<ELProblem> getELProblems() {
return fELProblems;
}
diff --git a/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/JSPELTranslator.java b/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/JSPELTranslator.java
index a853cf9..a1fc317 100644
--- a/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/JSPELTranslator.java
+++ b/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/JSPELTranslator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 BEA Systems and others.
+ * Copyright (c) 2005, 2021 BEA Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -50,12 +50,12 @@
*/
private JSPELParser elParser = null;
- public List translateEL(String elText, String delim,
+ public List<ELProblem> translateEL(String elText, String delim,
IStructuredDocumentRegion currentNode, int contentStart,
int contentLength, StringBuffer fUserELExpressions,
HashMap fUserELRanges, IStructuredDocument document) {
- ArrayList elProblems = new ArrayList();
+ List<ELProblem> elProblems = new ArrayList<>();
try {
synchronized(this) {
@@ -67,7 +67,7 @@
ASTExpression expression = elParser.Expression();
ELGenerator gen = new ELGenerator();
- List generatorELProblems = gen.generate(expression, currentNode, fUserELExpressions, fUserELRanges, document, currentNode, contentStart, contentLength);
+ List<ELProblem> generatorELProblems = gen.generate(expression, currentNode, fUserELExpressions, fUserELRanges, document, currentNode, contentStart, contentLength);
elProblems.addAll(generatorELProblems);
}
} catch (ParseException e) {
diff --git a/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/jspel/IJSPELTranslator.java b/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/jspel/IJSPELTranslator.java
index 24592fc..9b734bc 100644
--- a/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/jspel/IJSPELTranslator.java
+++ b/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/jspel/IJSPELTranslator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 BEA Systems and others.
+ * Copyright (c) 2005, 2021 BEA Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -39,7 +39,7 @@
* @param document The structured document.
* @return A list of ELProblems that describes any syntactic issues found.
*/
- public List translateEL(String elText,
+ public List<ELProblem> translateEL(String elText,
String delim,
IStructuredDocumentRegion currentNode,
int contentStart,
diff --git a/web/tests/org.eclipse.jst.jsp.ui.tests/META-INF/MANIFEST.MF b/web/tests/org.eclipse.jst.jsp.ui.tests/META-INF/MANIFEST.MF
index 80ff2a5..8c9243b 100644
--- a/web/tests/org.eclipse.jst.jsp.ui.tests/META-INF/MANIFEST.MF
+++ b/web/tests/org.eclipse.jst.jsp.ui.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name.0
Bundle-SymbolicName: org.eclipse.jst.jsp.ui.tests; singleton:=true
-Bundle-Version: 1.1.0.qualifier
+Bundle-Version: 1.1.1.qualifier
Bundle-Activator: org.eclipse.jst.jsp.ui.tests.JSPUITestsPlugin
Bundle-Vendor: %Bundle-Vendor.0
Bundle-Localization: plugin
diff --git a/web/tests/org.eclipse.jst.jsp.ui.tests/pom.xml b/web/tests/org.eclipse.jst.jsp.ui.tests/pom.xml
index 06bc441..dc96e87 100644
--- a/web/tests/org.eclipse.jst.jsp.ui.tests/pom.xml
+++ b/web/tests/org.eclipse.jst.jsp.ui.tests/pom.xml
@@ -21,7 +21,7 @@
<groupId>org.eclipse.webtools.sourceediting</groupId>
<artifactId>org.eclipse.jst.jsp.ui.tests</artifactId>
- <version>1.1.0-SNAPSHOT</version>
+ <version>1.1.1-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
diff --git a/web/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/ShowTranslationHandler.java b/web/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/ShowTranslationHandler.java
index 1a17704..ec444eb 100644
--- a/web/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/ShowTranslationHandler.java
+++ b/web/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/ShowTranslationHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2017 IBM Corporation and others.
+ * Copyright (c) 2008, 2021 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -25,11 +25,10 @@
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.IAnnotationModel;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jst.jsp.core.internal.java.IJSPProblem;
import org.eclipse.jst.jsp.core.internal.java.IJSPTranslation;
import org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter;
@@ -44,9 +43,10 @@
import org.eclipse.ui.progress.UIJob;
import org.eclipse.ui.texteditor.AnnotationTypeLookup;
import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.wst.sse.core.StructuredModelManager;
import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
/**
@@ -72,63 +72,83 @@
* .ExecutionEvent)
*/
public Object execute(final ExecutionEvent event) throws ExecutionException {
- ISelection selection = HandlerUtil.getCurrentSelection(event);
- if (selection instanceof IStructuredSelection) {
- List list = ((IStructuredSelection) selection).toList();
- if (!list.isEmpty()) {
- if (list.get(0) instanceof IDOMNode) {
- final IDOMModel model = ((IDOMNode) list.get(0)).getModel();
- INodeAdapter adapter = model.getDocument().getAdapterFor(IJSPTranslation.class);
- if (adapter != null) {
- Job opener = new UIJob("Opening JSP Java Translation") {
- public IStatus runInUIThread(IProgressMonitor monitor) {
- JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
- final JSPTranslationExtension translation = translationAdapter.getJSPTranslation();
+ IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
+ if (activeEditor != null) {
+ ITextEditor textEditor = activeEditor.getAdapter(ITextEditor.class);
+ if (textEditor != null) {
+ IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
+ IStructuredModel baseModel = null;
+ try {
+ baseModel = StructuredModelManager.getModelManager().getExistingModelForRead(document);
+ if (baseModel instanceof IDOMModel) {
+ final IDOMModel model = (IDOMModel) baseModel;
+ INodeAdapter adapter = model.getDocument().getAdapterFor(IJSPTranslation.class);
+ if (adapter != null) {
+ Job opener = new UIJob("Opening JSP Java Translation") {
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
+ final JSPTranslationExtension translation = translationAdapter.getJSPTranslation();
- // create an IEditorInput for the Java editor
- final IStorageEditorInput input = new JSPTranslationEditorInput(model);
- try {
- IEditorPart editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), input, JavaUI.ID_CU_EDITOR, true);
- // Now add the problems we found
- if (editor instanceof ITextEditor) {
- IAnnotationModel annotationModel = ((ITextEditor) editor).getDocumentProvider().getAnnotationModel(input);
- translation.reconcileCompilationUnit();
- List problemsList = translation.getProblems();
- IProblem[] problems = (IProblem[]) problemsList.toArray(new IProblem[problemsList.size()]);
- AnnotationTypeLookup lookup = new AnnotationTypeLookup();
- for (int i = 0; i < problems.length; i++) {
- if (problems[i] instanceof IJSPProblem)
- continue;
- int length = problems[i].getSourceEnd() - problems[i].getSourceStart() + 1;
- Position position = new Position(problems[i].getSourceStart(), length);
- Annotation annotation = null;
- String type = lookup.getAnnotationType(IMarker.PROBLEM, IMarker.SEVERITY_INFO);
- if (problems[i].isError()) {
- type = lookup.getAnnotationType(IMarker.PROBLEM, IMarker.SEVERITY_ERROR);
- }
- else if (problems[i].isWarning()) {
- type = lookup.getAnnotationType(IMarker.PROBLEM, IMarker.SEVERITY_WARNING);
- }
- annotation = new Annotation(type, false, problems[i].getMessage());
- if (annotation != null) {
- annotationModel.addAnnotation(annotation, position);
+ // create an IEditorInput for the Java
+ // editor
+ final IStorageEditorInput input = new JSPTranslationEditorInput(model);
+ try {
+ IEditorPart editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), input, JavaUI.ID_CU_EDITOR, true);
+ // Now add the problems we found
+ if (editor instanceof ITextEditor) {
+ IAnnotationModel annotationModel = ((ITextEditor) editor).getDocumentProvider().getAnnotationModel(input);
+ translation.reconcileCompilationUnit();
+ List problemsList = translation.getProblems();
+ IProblem[] problems = (IProblem[]) problemsList.toArray(new IProblem[problemsList.size()]);
+ AnnotationTypeLookup lookup = new AnnotationTypeLookup();
+ for (int i = 0; i < problems.length; i++) {
+ if (problems[i] instanceof IJSPProblem)
+ continue;
+ int length = problems[i].getSourceEnd() - problems[i].getSourceStart() + 1;
+ Position position = new Position(problems[i].getSourceStart(), length);
+ Annotation annotation = null;
+ String type = lookup.getAnnotationType(IMarker.PROBLEM, IMarker.SEVERITY_INFO);
+ if (problems[i].isError()) {
+ type = lookup.getAnnotationType(IMarker.PROBLEM, IMarker.SEVERITY_ERROR);
+ }
+ else if (problems[i].isWarning()) {
+ type = lookup.getAnnotationType(IMarker.PROBLEM, IMarker.SEVERITY_WARNING);
+ }
+ annotation = new Annotation(type, false, problems[i].getMessage());
+ if (annotation != null) {
+ annotationModel.addAnnotation(annotation, position);
+ }
}
}
}
+ catch (PartInitException e) {
+ e.printStackTrace();
+ Display.getCurrent().beep();
+ }
+ return Status.OK_STATUS;
}
- catch (PartInitException e) {
- e.printStackTrace();
- Display.getCurrent().beep();
- }
- return Status.OK_STATUS;
- }
- };
- opener.setSystem(false);
- opener.setUser(true);
- opener.schedule();
+ };
+ opener.setSystem(false);
+ opener.setUser(true);
+ opener.schedule();
+ }
+ }
+ else {
+ Logger.log(Logger.ERROR, "Not an IDOMModel");
+ }
+ }
+ finally {
+ if (baseModel != null) {
+ baseModel.releaseFromRead();
}
}
}
+ else {
+ Logger.log(Logger.ERROR, "No text editor found");
+ }
+ }
+ else {
+ Logger.log(Logger.ERROR, "No active editor found");
}
return null;
}