diff options
author | nitind | 2008-12-23 22:26:01 +0000 |
---|---|---|
committer | nitind | 2008-12-23 22:26:01 +0000 |
commit | 53682bc31beaf5181f7f88e617303fefbaab874d (patch) | |
tree | e8805f9fdc45667b73b5e92431f0b9b6f2c9a93b | |
parent | 86cd0bf2bea4cc2dbabab6e47c1eda601c40c193 (diff) | |
download | webtools.sourceediting-53682bc31beaf5181f7f88e617303fefbaab874d.tar.gz webtools.sourceediting-53682bc31beaf5181f7f88e617303fefbaab874d.tar.xz webtools.sourceediting-53682bc31beaf5181f7f88e617303fefbaab874d.zip |
[241794] Validation shows errors when using JSP Expressions inside JavaScript code
16 files changed, 257 insertions, 715 deletions
diff --git a/bundles/org.eclipse.wst.jsdt.web.core/META-INF/MANIFEST.MF b/bundles/org.eclipse.wst.jsdt.web.core/META-INF/MANIFEST.MF index ee025ba1e2..b25b6be5d9 100644 --- a/bundles/org.eclipse.wst.jsdt.web.core/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.wst.jsdt.web.core/META-INF/MANIFEST.MF @@ -16,7 +16,6 @@ Export-Package: org.eclipse.wst.jsdt.web.core.internal, org.eclipse.core.runtime", org.eclipse.wst.jsdt.web.core.internal.provisional.contenttype, org.eclipse.wst.jsdt.web.core.internal.provisional.text, - org.eclipse.wst.jsdt.web.core.internal.tasks, org.eclipse.wst.jsdt.web.core.internal.validation, org.eclipse.wst.jsdt.web.core.javascript, org.eclipse.wst.jsdt.web.core.javascript.search, diff --git a/bundles/org.eclipse.wst.jsdt.web.core/plugin.xml b/bundles/org.eclipse.wst.jsdt.web.core/plugin.xml index aa464721bb..5eb235cd01 100644 --- a/bundles/org.eclipse.wst.jsdt.web.core/plugin.xml +++ b/bundles/org.eclipse.wst.jsdt.web.core/plugin.xml @@ -98,8 +98,7 @@ --> <extension id="embeded.javascript" name="%extension.name.1" point="org.eclipse.core.resources.builders"> - <builder hasNature="true" callOnEmptyDelta="true"> - + <builder hasNature="true" callOnEmptyDelta="true"> <run class="org.eclipse.wst.jsdt.web.core.internal.IncrementalBuilder"/> </builder> </extension> @@ -116,48 +115,35 @@ </extension> --> - <extension point="org.eclipse.wst.sse.core.formatProcessors"> - <processor - class="org.eclipse.wst.html.core.internal.format.HTMLFormatProcessorImpl" - contentTypeId="org.eclipse.wst.html.core.htmlsource"> - </processor> - </extension> - - <!--======================================================================================--> - <!-- JSP batch validation --> + <!-- JS batch validation in Web files --> <!--======================================================================================--> <extension id="JsBatchValidator" name="%javascript.validator" - point="org.eclipse.wst.validation.validator"> - <validator> - <projectNature id="org.eclipse.wst.jsdt.core.jsNature" /> - - <filter - objectClass="org.eclipse.core.resources.IFile" - nameFilter="*.html"> - </filter> - <filter - objectClass="org.eclipse.core.resources.IFile" - nameFilter="*.htm"> - </filter> - - <filter - objectClass="org.eclipse.core.resources.IFile" - nameFilter="*.jsp"> - </filter> - - - <helper - class="org.eclipse.wst.validation.internal.operations.WorkbenchContext"> - </helper> - - <run - enabled="false" - class="org.eclipse.wst.jsdt.web.core.internal.validation.JsBatchValidator"> - </run> - </validator> + point="org.eclipse.wst.validation.validatorV2"> + <validator + build="true" + class="org.eclipse.wst.jsdt.web.core.internal.validation.JsValidator" + manual="true" + sourceid="org.eclipse.wst.jsdt.web.jssourcevalidator" + version="1" + markerId="org.eclipse.wst.jsdt.core.problem"> + <include> + <rules> + <projectNature id="org.eclipse.wst.jsdt.core.jsNature" /> + <contentType id="org.eclipse.wst.html.core.htmlsource"></contentType> + <fileext caseSensitive="false" ext="html"/> + <fileext caseSensitive="false" ext="xhtml"/> + <fileext caseSensitive="false" ext="htm"/> + <fileext caseSensitive="false" ext="htpl"/> + <fileext caseSensitive="false" ext="wml"/> + <fileext caseSensitive="false" ext="jsp"/> + <fileext caseSensitive="false" ext="jspf"/> + </rules> + </include> + <group id="org.eclipse.wst.sse.core.structuredModelGroup"/> + </validator> </extension> <extension point="org.eclipse.wst.jsdt.core.JsGlobalScopeContainerInitializer"> diff --git a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/internal/modelhandler/WebResourceChangeHandler.java b/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/internal/modelhandler/WebResourceChangeHandler.java index 9dd8e8e209..267d04e414 100644 --- a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/internal/modelhandler/WebResourceChangeHandler.java +++ b/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/internal/modelhandler/WebResourceChangeHandler.java @@ -20,12 +20,10 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.jface.text.DocumentEvent; import org.eclipse.jface.text.IDocumentListener; import org.eclipse.swt.widgets.Display; -import org.eclipse.wst.sse.core.StructuredModelManager; import org.eclipse.wst.sse.core.internal.model.ModelLifecycleEvent; import org.eclipse.wst.sse.core.internal.provisional.IModelLifecycleListener; import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; /** * * Provisional API: This class/interface is part of an interim API that is still under development and expected to @@ -44,7 +42,7 @@ public class WebResourceChangeHandler implements IResourceChangeListener, IDocum * setting to true may speed things up. * */ - private static final boolean CHECK_INTREST_LEVEL = false; +// private static final boolean CHECK_INTREST_LEVEL = false; private static Hashtable instances = new Hashtable(); private static final boolean SIGNAL_MODEL = false; @@ -79,7 +77,7 @@ public class WebResourceChangeHandler implements IResourceChangeListener, IDocum if (!WebResourceChangeHandler.SIGNAL_MODEL) { return; } - IDOMModel xmlModel = null; + IStructuredModel xmlModel = null; Object modelRef = getModel(); if (modelRef == null) { return; @@ -88,19 +86,23 @@ public class WebResourceChangeHandler implements IResourceChangeListener, IDocum // for(int i =0;i<fchangeListener.size();i++) { // ((IWebResourceChangedListener)fchangeListener.get(i)).resourceChanged(); // } - xmlModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForEdit(((IStructuredModel) modelRef).getBaseLocation()); + xmlModel = (IStructuredModel) modelRef;//(IDOMModel) StructuredModelManager.getModelManager().getExistingModelForEdit(((IStructuredModel) modelRef).getBaseLocation()); if (xmlModel != null) { IStructuredDocument doc = xmlModel.getStructuredDocument(); - xmlModel.aboutToChangeModel(); + try { + xmlModel.aboutToChangeModel(); // xmlModel.setReinitializeNeeded(true); // (doc).replace(0, doc.getLength(),doc.get()); - xmlModel.changedModel(); + } + finally { + xmlModel.changedModel(); + } } } catch (Exception e) { System.out.println(Messages.getString("WebResourceChangeHandler.0")); //$NON-NLS-1$ } finally { if (xmlModel != null) { - xmlModel.releaseFromEdit(); +// xmlModel.releaseFromEdit(); } } } diff --git a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/internal/tasks/JsFileTaskScanner.java b/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/internal/tasks/JsFileTaskScanner.java deleted file mode 100644 index f3eaa0f732..0000000000 --- a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/internal/tasks/JsFileTaskScanner.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.jsdt.web.core.internal.tasks; - -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.xml.core.internal.tasks.XMLFileTaskScanner; -/** -* -* Provisional API: This class/interface is part of an interim API that is still under development and expected to -* change significantly before reaching stability. It is being made available at this early stage to solicit feedback -* from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken -* (repeatedly) as the API evolves. -*/ -public class JsFileTaskScanner extends XMLFileTaskScanner { - - protected boolean isCommentRegion(IStructuredDocumentRegion region, ITextRegion textRegion) { - return super.isCommentRegion(region, textRegion); - } -} diff --git a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/internal/validation/JsBatchValidator.java b/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/internal/validation/JsBatchValidator.java deleted file mode 100644 index 5e06e454ae..0000000000 --- a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/internal/validation/JsBatchValidator.java +++ /dev/null @@ -1,436 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.jsdt.web.core.internal.validation; - -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceProxy; -import org.eclipse.core.resources.IResourceProxyVisitor; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExecutableExtension; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.jobs.ISchedulingRule; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.osgi.util.NLS; -import org.eclipse.wst.jsdt.core.IIncludePathAttribute; -import org.eclipse.wst.jsdt.core.IIncludePathEntry; -import org.eclipse.wst.jsdt.core.IJavaScriptProject; -import org.eclipse.wst.jsdt.core.JavaScriptCore; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; -import org.eclipse.wst.jsdt.web.core.internal.JsCoreMessages; -import org.eclipse.wst.jsdt.web.core.internal.Logger; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.validation.internal.ConfigurationManager; -import org.eclipse.wst.validation.internal.ProjectConfiguration; -import org.eclipse.wst.validation.internal.ValidationRegistryReader; -import org.eclipse.wst.validation.internal.core.Message; -import org.eclipse.wst.validation.internal.core.ValidationException; -import org.eclipse.wst.validation.internal.operations.IWorkbenchContext; -import org.eclipse.wst.validation.internal.operations.WorkbenchReporter; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; -import org.eclipse.wst.validation.internal.provisional.core.IValidationContext; -import org.eclipse.wst.validation.internal.provisional.core.IValidatorJob; - -/** - * Performs JSP validation tasks for batch validation. The individual validator - * classes will still be used for source validation. - - * - * <br><br> - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public final class JsBatchValidator implements IValidatorJob, IExecutableExtension { - // for debugging - static final boolean DEBUG = Boolean.valueOf(Platform.getDebugOption("org.eclipse.wst.jsdt.web.core/debug/jsvalidator")).booleanValue(); //$NON-NLS-1$ - private static final String PLUGIN_ID_JSP_CORE = "org.eclipse.wst.jsdt.web.core"; //$NON-NLS-1$ - private IPath[] excludeLibPaths; - - private final static String [] rhinoValidator = {"org.eclipse.atf.javascript.internal.validation.JSSyntaxValidator"}; //$NON-NLS-1$ - static { - // Temp code to clear Rhino Syntax validation markers. - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - IProject[] projects = workspace.getRoot().getProjects(); - for (int j = 0; j < projects.length; j++) { - IProject project = projects[j]; - //try { - if (project.isOpen()) { - try { - if (project.hasNature(JavaScriptCore.NATURE_ID)) { - WorkbenchReporter.removeAllMessages(project, rhinoValidator, null); - } - } catch (CoreException e) { - // Do nothing - } - } - } - - } - - /** - * Gets current validation project configuration based on current project - * (which is based on current document) - * - * @return ProjectConfiguration - */ - static private ProjectConfiguration getProjectConfiguration(IFile file) { - ProjectConfiguration projectConfiguration = null; - if (file != null) { - IProject project = file.getProject(); - if (project != null) { - try { - projectConfiguration = ConfigurationManager.getManager().getProjectConfiguration(project); - } catch (InvocationTargetException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } - } - return projectConfiguration; - } - - /** - * Checks if validator is enabled according in Validation preferences - * - * @param vmd - * @return - */ - static boolean isBatchValidatorPreferenceEnabled(IFile file) { - if (file == null) { - return true; - } - boolean enabled = true; - ProjectConfiguration configuration = JsBatchValidator.getProjectConfiguration(file); - if (configuration != null) { - org.eclipse.wst.validation.internal.ValidatorMetaData metadata = ValidationRegistryReader.getReader().getValidatorMetaData(JsBatchValidator.class.getName()); - if (configuration != null && metadata != null) { - if (!configuration.isBuildEnabled(metadata) && !configuration.isManualEnabled(metadata)) { - enabled = false; - } - } - } - return enabled; - } - class JSPFileVisitor implements IResourceProxyVisitor { - private List fFiles = new ArrayList(); - private IReporter fReporter = null; - - public JSPFileVisitor(IReporter reporter) { - fReporter = reporter; - } - - final IFile[] getFiles() { - return (IFile[]) fFiles.toArray(new IFile[fFiles.size()]); - } - - public boolean visit(IResourceProxy proxy) throws CoreException { - // check validation - if (fReporter.isCancelled()) { - return false; - } - if (proxy.getType() == IResource.FILE) { - if (Util.isJsType(proxy.getName()) && proxy.isAccessible()) { - IFile file = (IFile) proxy.requestResource(); - if (JsBatchValidator.DEBUG) { - System.out.println("(+) JSPValidator adding file: " + file.getName()); //$NON-NLS-1$ - } - fFiles.add(file); - // don't search deeper for files - return false; - } - } - return true; - } - } - class LocalizedMessage extends Message { - private String _message = null; - - public LocalizedMessage(int severity, String messageText) { - this(severity, messageText, null); - } - - public LocalizedMessage(int severity, String messageText, IResource targetObject) { - this(severity, messageText, (Object) targetObject); - } - - public LocalizedMessage(int severity, String messageText, Object targetObject) { - super(null, severity, null); - setLocalizedMessage(messageText); - setTargetObject(targetObject); - } - - private String getLocalizedText() { - return _message; - } - - - public String getText() { - return getLocalizedText(); - } - - - public String getText(ClassLoader cl) { - return getLocalizedText(); - } - - - public String getText(Locale l) { - return getLocalizedText(); - } - - - public String getText(Locale l, ClassLoader cl) { - return getLocalizedText(); - } - - public void setLocalizedMessage(String message) { - _message = message; - } - } - //String fAdditionalContentTypesIDs[] = null; - private IContentType[] fContentTypes = null; - private IContentType fJSPFContentType = null; - private JsValidator fJSPJavaValidator = new JsValidator(this); - - public void cleanup(IReporter reporter) { - fJSPJavaValidator.cleanup(reporter); - } - private IPath[] getLibraryPaths(IFile file) { - - if(excludeLibPaths!=null) return excludeLibPaths; - - IProject project = file.getProject(); - IJavaScriptProject javaProject= JavaScriptCore.create(project); - - if(javaProject==null) return new IPath[0]; - - IIncludePathEntry[] entries = new IIncludePathEntry[0]; - try { - entries = javaProject.getResolvedIncludepath(true); - } catch (JavaScriptModelException ex) { - // May run into an exception if the project isn't jsdt. - } - ArrayList ignorePaths = new ArrayList(); - nextEntry: for(int i = 0;i<entries.length;i++) { - if(entries[i].getEntryKind() == IIncludePathEntry.CPE_LIBRARY) { - IIncludePathAttribute[] attribs = entries[i].getExtraAttributes(); - for(int k=0; attribs!=null && k<attribs.length;k++) { - if(attribs[k].getName().equalsIgnoreCase("validate") && attribs[k].getValue().equalsIgnoreCase("false")) { //$NON-NLS-1$ //$NON-NLS-2$ - ignorePaths.add(entries[i].getPath()); - continue nextEntry; - } - } - } - } - - excludeLibPaths = (Path[])ignorePaths.toArray(new Path[ignorePaths.size()]); - return excludeLibPaths; - } - - - void doValidate(IValidationContext helper, IReporter reporter) throws ValidationException { - - String[] uris = helper.getURIs(); - if (uris.length > 0) { - IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); - IFile currentFile = null; - - for (int i = 0; i < uris.length && !reporter.isCancelled(); i++) { - currentFile = wsRoot.getFile(new Path(uris[i])); - if (currentFile != null && currentFile.exists()) { - if (shouldValidate(currentFile) ) { - Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, "" + (i + 1) + "/" + uris.length + " - " + currentFile.getFullPath().toString().substring(1)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - reporter.displaySubtask(this, message); - reporter.removeAllMessages(this, currentFile); - validateFile(currentFile, reporter); - } - if (JsBatchValidator.DEBUG) { - System.out.println("validating: [" + uris[i] + "]"); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - } - } else { - // if uris[] length 0 -> validate() gets called for each project - if (helper instanceof IWorkbenchContext) { - IProject project = ((IWorkbenchContext) helper).getProject(); - Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, NLS.bind(JsCoreMessages.JSPBatchValidator_0, project.getFullPath())); - reporter.displaySubtask(this, message); - JSPFileVisitor visitor = new JSPFileVisitor(reporter); - try { - // collect all jsp files for the project - project.accept(visitor, IResource.DEPTH_INFINITE); - } catch (CoreException e) { - if (JsBatchValidator.DEBUG) { - e.printStackTrace(); - } - } - IFile[] files = visitor.getFiles(); - for (int i = 0; i < files.length && !reporter.isCancelled(); i++) { - if (shouldValidate(files[i]) ) { - message = new LocalizedMessage(IMessage.LOW_SEVERITY, "" + (i + 1) + "/" + files.length + " - " + files[i].getFullPath().toString().substring(1)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - reporter.displaySubtask(this, message); - validateFile(files[i], reporter); - } - if (JsBatchValidator.DEBUG) { - System.out.println("validating: [" + files[i] + "]"); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - } - } - } - -// /** -// * Checks if file is a jsp fragment or not. If so, check if the fragment -// * should be validated or not. -// * -// * @param file -// * Assumes shouldValidate was already called on file so it should -// * not be null and does exist -// * @return false if file is a fragment and it should not be validated, true -// * otherwise -// */ -// private boolean fragmentCheck(IFile file) { -// return isFragment(file); -// } - - public ISchedulingRule getSchedulingRule(IValidationContext helper) { - if (helper instanceof IWorkbenchContext) { - /* - * Use a single build rule when running batch validation. - */ - return ResourcesPlugin.getWorkspace().getRuleFactory().buildRule(); - } - /* - * For other kinds of validation, use no specific rule - */ - return null; - } - - - - - - private void performValidation(IFile f, IReporter reporter, IStructuredModel model) { - if (!reporter.isCancelled()) { - fJSPJavaValidator.performValidation(f, reporter, model,true); - } - } - - /** - * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, - * java.lang.String, java.lang.Object) - */ - public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException { - - } - - private boolean shouldValidate(IFile file) { - //if(true) return true; - IResource resource = file; - IPath[] libPaths = getLibraryPaths(file); - IPath filePath = file.getFullPath().removeLastSegments(1); - for(int i = 0;i<libPaths.length;i++) { - if(libPaths[i].isPrefixOf(filePath)){ - return false; - } - } - - do { - if (resource.isDerived() || resource.isTeamPrivateMember() || !resource.isAccessible() || resource.getName().charAt(0) == '.') { - return false; - } - resource = resource.getParent(); - } while ((resource.getType() & IResource.PROJECT) == 0); - return true; - } - - public void validate(IValidationContext helper, IReporter reporter) throws ValidationException { - doValidate(helper, reporter); - } - - /** - * Validate one file. It's assumed that the file has JSP content type. - * - * @param f - * @param reporter - */ - void validateFile(IFile f, IReporter reporter) { - IStructuredModel model = null; - try { - // get JSP model on behalf of all JSP validators - model = StructuredModelManager.getModelManager().getExistingModelForRead(f); - if(model==null) { - model = StructuredModelManager.getModelManager().getModelForRead(f); - } - if (!reporter.isCancelled() && model != null) { - reporter.removeAllMessages(this, f); - performValidation(f, reporter, model); - } - } catch (IOException e) { - Logger.logException(e); - } catch (CoreException e) { - Logger.logException(e); - } finally { - if (model != null) { - model.releaseFromRead(); - } - } - } - - public IStatus validateInJob(final IValidationContext helper, final IReporter reporter) throws ValidationException { - Job currentJob = Platform.getJobManager().currentJob(); - ISchedulingRule rule = null; - if (currentJob != null) { - rule = currentJob.getRule(); - } - IWorkspaceRunnable validationRunnable = new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) throws CoreException { - try { - doValidate(helper, reporter); - } catch (ValidationException e) { - throw new CoreException(new Status(IStatus.ERROR, JsBatchValidator.PLUGIN_ID_JSP_CORE, 0, JsBatchValidator.PLUGIN_ID_JSP_CORE, e)); - } - } - }; - try { - JavaScriptCore.run(validationRunnable, rule, new NullProgressMonitor()); - } catch (CoreException e) { - if (e.getCause() instanceof ValidationException) { - throw (ValidationException) e.getCause(); - } - throw new ValidationException(new LocalizedMessage(IMessage.ERROR_AND_WARNING, e.getMessage()), e); - } - return Status.OK_STATUS; - } -} diff --git a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/internal/validation/JsValidator.java b/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/internal/validation/JsValidator.java index 92a29dea2e..01ee366375 100644 --- a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/internal/validation/JsValidator.java +++ b/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/internal/validation/JsValidator.java @@ -13,8 +13,10 @@ package org.eclipse.wst.jsdt.web.core.internal.validation; import java.io.IOException; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Locale; +import java.util.Set; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; @@ -24,18 +26,27 @@ import org.eclipse.core.resources.IResourceProxyVisitor; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExecutableExtension; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; import org.eclipse.wst.jsdt.core.compiler.IProblem; import org.eclipse.wst.jsdt.web.core.internal.Logger; - import org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation; import org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter; import org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapterFactory; import org.eclipse.wst.sse.core.StructuredModelManager; import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; 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.ITextRegion; +import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection; +import org.eclipse.wst.validation.AbstractValidator; +import org.eclipse.wst.validation.ValidationResult; +import org.eclipse.wst.validation.ValidationState; import org.eclipse.wst.validation.internal.core.Message; import org.eclipse.wst.validation.internal.core.ValidationException; import org.eclipse.wst.validation.internal.operations.IWorkbenchContext; @@ -45,19 +56,13 @@ import org.eclipse.wst.validation.internal.provisional.core.IValidationContext; import org.eclipse.wst.validation.internal.provisional.core.IValidator; import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -/** - * - * Provisional API: This class/interface is part of an interim API that is still under development and expected to - * change significantly before reaching stability. It is being made available at this early stage to solicit feedback - * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken - * (repeatedly) as the API evolves. - */ -public class JsValidator implements IValidator{ +public class JsValidator extends AbstractValidator implements IValidator, IExecutableExtension { private static final boolean DEBUG = Boolean.valueOf(Platform.getDebugOption("org.eclipse.wst.jsdt.web.core/debug/jsvalidator")).booleanValue(); //$NON-NLS-1$ private IValidator fMessageOriginator; + private Set fValidFileExts = new HashSet(); - private static String [] jsdtValidator = {"org.eclipse.wst.jsdt.web.core.internal.validation.JsBatchValidator"}; //$NON-NLS-1$ +// private static String [] jsdtValidator = {"org.eclipse.wst.jsdt.web.core.internal.validation.JsBatchValidator"}; //$NON-NLS-1$ protected class LocalizedMessage extends Message { @@ -109,34 +114,52 @@ public class JsValidator implements IValidator{ this.fMessageOriginator = this; } - public JsValidator(IValidator validator) { - this.fMessageOriginator = validator; - } - /** * Creates an IMessage from an IProblem * * @param problem * @param f * @param translation - * @param structuredDoc + * @param textDoc * @return message representation of the problem, or null if it could not * create one */ - private IMessage createMessageFromProblem(IProblem problem, IFile f, IJsTranslation translation, IStructuredDocument structuredDoc) { + private IMessage createMessageFromProblem(IProblem problem, IFile f, IJsTranslation translation, IDocument textDoc) { int sourceStart = problem.getSourceStart(); int sourceEnd = problem.getSourceEnd(); if (sourceStart == -1) { return null; } - // line number for marker starts @ 1 - // line number from document starts @ 0 - int lineNo = structuredDoc.getLineOfOffset(sourceStart) + 1; - int sev = problem.isError() ? IMessage.HIGH_SEVERITY : IMessage.NORMAL_SEVERITY; + + /* + * Bug 241794 - Validation shows errors when using JSP Expressions + * inside JavaScript code + */ + IStructuredDocument doc = (IStructuredDocument) textDoc; + IStructuredDocumentRegion documentRegion = doc.getRegionAtCharacterOffset(sourceStart); + if (documentRegion != null) { + ITextRegion textRegion = documentRegion.getRegionAtCharacterOffset(sourceStart); + /* + * Filter out problems from areas that aren't simple JavaScript, + * e.g. JSP. + */ + if (textRegion != null && textRegion instanceof ITextRegionCollection) + return null; + } + + int sev = problem.isError() ? IMessage.HIGH_SEVERITY : (problem.isWarning() ? IMessage.NORMAL_SEVERITY : IMessage.LOW_SEVERITY); IMessage m = new LocalizedMessage(sev, problem.getMessage(), f); - m.setLineNo(lineNo); - m.setOffset(sourceStart); - m.setLength(sourceEnd - sourceStart + 1); + // line numbers for marker starts @ 1 + // line numbers from document starts @ 0 + try { + int lineNo = textDoc.getLineOfOffset(sourceStart) + 1; + m.setLineNo(lineNo); + m.setOffset(sourceStart); + m.setLength(sourceEnd - sourceStart + 1); + } + catch (BadLocationException e) { + Logger.logException(e); + } return m; } @@ -152,8 +175,8 @@ public class JsValidator implements IValidator{ translation.setProblemCollectingActive(true); translation.reconcileCompilationUnit(); List problems = translation.getProblems(); +// if(!inBatch) reporter.removeAllMessages(this, f); // add new messages - if(!inBatch) reporter.removeAllMessages(this, f); for (int i = 0; i < problems.size() && !reporter.isCancelled(); i++) { IMessage m = createMessageFromProblem((IProblem) problems.get(i), f, translation, domModel.getStructuredDocument()); if (m != null) { @@ -164,9 +187,24 @@ public class JsValidator implements IValidator{ } } + /* Read the definition for this validator and the declared valid file extensions + * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object) + */ + public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException { + IConfigurationElement[] includes = config.getChildren("include"); //$NON-NLS-1$ + for (int i = 0; i < includes.length; i++) { + IConfigurationElement[] fileexts = includes[i].getChildren("fileext"); //$NON-NLS-1$ + for (int j = 0; j < fileexts.length; j++) { + String fileext = fileexts[j].getAttribute("ext"); //$NON-NLS-1$ + if (fileext != null) { + fValidFileExts.add(fileext); + } + } + } + } + /** - * When loading model from a file, you need to explicitly add adapter - * factory. + * Ensures that our translation adapter is present before we try to use it * * @param sm */ @@ -176,7 +214,8 @@ public class JsValidator implements IValidator{ sm.getFactoryRegistry().addFactory(factory); } } - private boolean shouldValidate(IFile file) { + + boolean shouldValidate(IFile file) { IResource resource = file; do { if (resource.isDerived() || resource.isTeamPrivateMember() || !resource.isAccessible() || resource.getName().charAt(0) == '.') { @@ -184,16 +223,17 @@ public class JsValidator implements IValidator{ } resource = resource.getParent(); } while ((resource.getType() & IResource.PROJECT) == 0); - return true; + return fValidFileExts.isEmpty() || fValidFileExts.contains(file.getFileExtension()); } + public void validate(IValidationContext helper, IReporter reporter) throws ValidationException { /* Added by BC ---- */ // if(true) return; /* end Added by BC ---- */ String[] uris = helper.getURIs(); - IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); if (uris.length > 0) { + IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); IFile currentFile = null; for (int i = 0; i < uris.length && !reporter.isCancelled(); i++) { currentFile = wsRoot.getFile(new Path(uris[i])); @@ -201,7 +241,7 @@ public class JsValidator implements IValidator{ if (currentFile != null && currentFile.exists()) { if (shouldValidate(currentFile) ){ //&& fragmentCheck(currentFile)) { int percent = (i * 100) / uris.length + 1; - Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, percent + "% " + uris[i]); //$NON-NLS-1$ + IMessage message = new LocalizedMessage(IMessage.LOW_SEVERITY, percent + "% " + uris[i]); //$NON-NLS-1$ reporter.displaySubtask(this, message); validateFile(currentFile, reporter); } @@ -214,7 +254,7 @@ public class JsValidator implements IValidator{ // if uris[] length 0 -> validate() gets called for each project if (helper instanceof IWorkbenchContext) { IProject project = ((IWorkbenchContext) helper).getProject(); - JSPFileVisitor visitor = new JSPFileVisitor(reporter); + JSFileVisitor visitor = new JSFileVisitor(reporter); try { // collect all jsp files for the project project.accept(visitor, IResource.DEPTH_INFINITE); @@ -225,12 +265,10 @@ public class JsValidator implements IValidator{ } IFile[] files = visitor.getFiles(); for (int i = 0; i < files.length && !reporter.isCancelled(); i++) { - if (shouldValidate(files[i])) { - int percent = (i * 100) / files.length + 1; - Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, percent + "% " + files[i].getFullPath().toString()); //$NON-NLS-1$ - reporter.displaySubtask(this, message); - validateFile(files[i], reporter); - } + int percent = (i * 100) / files.length + 1; + IMessage message = new LocalizedMessage(IMessage.LOW_SEVERITY, percent + "% " + files[i].getFullPath().toString()); //$NON-NLS-1$ + reporter.displaySubtask(this, message); + validateFile(files[i], reporter); if (DEBUG) { System.out.println("validating: [" + files[i] + "]"); //$NON-NLS-1$ //$NON-NLS-2$ } @@ -239,12 +277,11 @@ public class JsValidator implements IValidator{ } } - protected class JSPFileVisitor implements IResourceProxyVisitor { - private IContentType[] fContentTypes = null; + protected class JSFileVisitor implements IResourceProxyVisitor { private List fFiles = new ArrayList(); private IReporter fReporter = null; - public JSPFileVisitor(IReporter reporter) { + public JSFileVisitor(IReporter reporter) { fReporter = reporter; } @@ -261,7 +298,7 @@ public class JsValidator implements IValidator{ if (proxy.getType() == IResource.FILE) { if (Util.isJsType(proxy.getName())) { IFile file = (IFile) proxy.requestResource(); - if (file.exists()) { + if (file.exists() && shouldValidate(file)) { if (DEBUG) { System.out.println("(+) JSPValidator adding file: " + file.getName()); //$NON-NLS-1$ } @@ -291,12 +328,9 @@ public class JsValidator implements IValidator{ IStructuredModel model = null; try { // get jsp model, get tranlsation - model = StructuredModelManager.getModelManager().getExistingModelForRead(f); - if(model==null) { - model = StructuredModelManager.getModelManager().getModelForRead(f); - } + model = StructuredModelManager.getModelManager().getModelForRead(f); if (!reporter.isCancelled() && model != null) { - // get jsp model, get translation + // get DOM model then translation if (model instanceof IDOMModel) { //WorkbenchReporter.removeAllMessages(f.getProject(), jsdtValidator, f.toString()); //reporter.removeAllMessages(fMessageOriginator, f); @@ -313,4 +347,12 @@ public class JsValidator implements IValidator{ } } } + public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) { + if (resource.getType() != IResource.FILE) + return null; + ValidationResult result = new ValidationResult(); + IReporter reporter = result.getReporter(monitor); + validateFile((IFile) resource, reporter); + return result; + } } 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 58dbb88447..d27c197c8a 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 @@ -26,28 +26,23 @@ import java.util.ArrayList; import java.util.List; import java.util.Vector; -import org.eclipse.core.filebuffers.FileBuffers; // import - // org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; // import - // org.eclipse.core.resources.IProject; -// import org.eclipse.core.resources.IResource; +import org.eclipse.core.filebuffers.FileBuffers; +import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; - import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.Position; import org.eclipse.wst.jsdt.core.IBuffer; -import org.eclipse.wst.jsdt.core.IJavaScriptUnit; import org.eclipse.wst.jsdt.core.IJavaScriptElement; import org.eclipse.wst.jsdt.core.IJavaScriptProject; +import org.eclipse.wst.jsdt.core.IJavaScriptUnit; import org.eclipse.wst.jsdt.core.IPackageFragmentRoot; import org.eclipse.wst.jsdt.core.ISourceRange; -import org.eclipse.wst.jsdt.core.JavaScriptModelException; // import - // org.eclipse.wst.jsdt.core.LibrarySuperType; +import org.eclipse.wst.jsdt.core.JavaScriptModelException; import org.eclipse.wst.jsdt.core.WorkingCopyOwner; import org.eclipse.wst.jsdt.internal.core.DocumentContextFragmentRoot; import org.eclipse.wst.jsdt.internal.core.Member; @@ -83,8 +78,8 @@ public class JsTranslation implements IJsTranslation { protected String fModelBaseLocation; - private static final String SUPER_TYPE_NAME = "Window"; //$NON-NLS-1$ - private static final String SUPER_TYPE_LIBRARY = "org.eclipse.wst.jsdt.launching.baseBrowserLibrary"; //$NON-NLS-1$ +// private static final String SUPER_TYPE_NAME = "Window"; //$NON-NLS-1$ +// private static final String SUPER_TYPE_LIBRARY = "org.eclipse.wst.jsdt.launching.baseBrowserLibrary"; //$NON-NLS-1$ protected IJsTranslator fTranslator; diff --git a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/JsTranslationAdapter.java b/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/JsTranslationAdapter.java index a8e3adae32..805522dca1 100644 --- a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/JsTranslationAdapter.java +++ b/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/JsTranslationAdapter.java @@ -57,7 +57,6 @@ public class JsTranslationAdapter implements INodeAdapter, IResourceChangeListen private String baseLocation; private boolean listenForChanges=false; private static final String PRIORITY_ATTRIB = "priority"; - private static final String CLASS_ATTRIB = "class"; private IJsTranslation fTranslationElement; public JsTranslationAdapter(IDOMModel xmlModel) { diff --git a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/JsTranslationAdapterFactory.java b/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/JsTranslationAdapterFactory.java index bdf808d2aa..b621153258 100644 --- a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/JsTranslationAdapterFactory.java +++ b/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/JsTranslationAdapterFactory.java @@ -41,7 +41,6 @@ import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; public class JsTranslationAdapterFactory extends AbstractAdapterFactory { // for debugging private static final boolean DEBUG; - private boolean listenForProjectChanges; static { String value = Platform.getDebugOption("org.eclipse.wst.jsdt.web.core/debug/jstranslation"); //$NON-NLS-1$ @@ -51,7 +50,6 @@ public class JsTranslationAdapterFactory extends AbstractAdapterFactory { public JsTranslationAdapterFactory() { super(IJsTranslation.class, true); - listenForProjectChanges = true; } diff --git a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/JsTranslator.java b/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/JsTranslator.java index 44a296f12c..f7f01b2d66 100644 --- a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/JsTranslator.java +++ b/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/JsTranslator.java @@ -41,6 +41,7 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.text.DocumentEvent; +import org.eclipse.jface.text.IDocumentListener; import org.eclipse.jface.text.Position; import org.eclipse.wst.jsdt.core.IBuffer; import org.eclipse.wst.sse.core.StructuredModelManager; @@ -64,15 +65,14 @@ import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; * * @author childsb */ -public class JsTranslator extends Job implements IJsTranslator{ +public class JsTranslator extends Job implements IJsTranslator, IDocumentListener { protected static final boolean DEBUG; private static final boolean DEBUG_SAVE_OUTPUT = false; //"true".equalsIgnoreCase(Platform.getDebugOption("org.eclipse.wst.jsdt.web.core/debug/jstranslationstodisk")); //$NON-NLS-1$ //$NON-NLS-2$ - private static final String ENDL = "\n"; //$NON-NLS-1$ +// private static final String ENDL = "\n"; //$NON-NLS-1$ - private static final boolean REMOVE_XML_COMMENT = true; private static final String XML_COMMENT_START = "<!--"; //$NON-NLS-1$ - private static final String XML_COMMENT_END = "-->"; //$NON-NLS-1$ +// private static final String XML_COMMENT_END = "-->"; //$NON-NLS-1$ private static final boolean REPLACE_INNER_BLOCK_SECTIONS_WITH_SPACE = false; @@ -87,7 +87,7 @@ public class JsTranslator extends Job implements IJsTranslator{ protected ArrayList importLocationsInHtml = new ArrayList(); /* use java script by default */ protected boolean fIsGlobalJs = true; - protected ArrayList rawImports = new ArrayList(); // traslated + protected ArrayList rawImports = new ArrayList(); // translated protected ArrayList scriptLocationInHtml = new ArrayList(); protected int scriptOffset = 0; @@ -118,26 +118,7 @@ public class JsTranslator extends Job implements IJsTranslator{ protected void advanceNextNode() { setCurrentNode(getCurrentNode().getNext()); - } - - protected void cleanupXmlQuotes() { - if(REMOVE_XML_COMMENT) { - int index = -1; - int replaceLength = XML_COMMENT_START.length(); - while((index = fScriptText.indexOf(XML_COMMENT_START, index)) > -1) { - fScriptText.replace(index, index + replaceLength, new String(Util.getPad(replaceLength))); - } - - index = -1; - replaceLength = XML_COMMENT_END.length(); - while((index = fScriptText.indexOf(XML_COMMENT_END, index)) > -1) { - fScriptText.replace(index, index + replaceLength, new String(Util.getPad(replaceLength))); - } - } - } - - - + } public JsTranslator(IStructuredDocument document, String fileName) { super("JavaScript translation for : " + fileName); //$NON-NLS-1$ @@ -247,13 +228,13 @@ public class JsTranslator extends Job implements IJsTranslator{ synchronized(fLock) { scriptOffset = 0; // reset progress monitor - cancelParse = false; fScriptText = new StringBuffer(); fCurrentNode = fStructuredDocument.getFirstStructuredDocumentRegion(); rawImports.clear(); importLocationsInHtml.clear(); scriptLocationInHtml.clear(); missingEndTagRegionStart = -1; + cancelParse = false; } translate(); } @@ -273,13 +254,16 @@ public class JsTranslator extends Job implements IJsTranslator{ //setCurrentNode(fStructuredDocument.getFirstStructuredDocumentRegion()); synchronized(finished) { + if(getCurrentNode() != null) { + NodeHelper nh = new NodeHelper(getCurrentNode()); while (getCurrentNode() != null && !isCanceled()) { + nh.setDocumentRegion(getCurrentNode()); + // System.out.println("Translator Looking at Node // type:"+getCurrentNode().getType()+"---------------------------------:"); // System.out.println(new NodeHelper(getCurrentNode())); // i.println("/---------------------------------------------------"); if (getCurrentNode().getType() == DOMRegionContext.XML_TAG_NAME) { - NodeHelper nh = new NodeHelper(getCurrentNode()); if ((!nh.isEndTag() || nh.isSelfClosingTag()) && nh.nameEquals("script")) { //$NON-NLS-1$ /* * Handles the following cases: <script @@ -301,7 +285,7 @@ public class JsTranslator extends Job implements IJsTranslator{ } } // End search for <script> sections } else if (nh.containsAttribute(JsDataTypes.HTMLATREVENTS)) { - /* Check for embeded JS events in any tags */ + /* Check for embedded JS events in any tags */ translateInlineJSNode(getCurrentNode()); } else if (nh.nameEquals("META") && nh.attrEquals("http-equiv", "Content-Script-Type") && nh.containsAttribute(new String[] { "content" })) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ // <META http-equiv="Content-Script-Type" content="type"> @@ -315,7 +299,7 @@ public class JsTranslator extends Job implements IJsTranslator{ if(getCompUnitBuffer()!=null) getCompUnitBuffer().setContents(fScriptText.toString()); } finishedTranslation(); - + } } protected void finishedTranslation() { @@ -369,9 +353,6 @@ public class JsTranslator extends Job implements IJsTranslator{ } } - - cleanupXmlQuotes(); - } /* (non-Javadoc) @@ -471,28 +452,60 @@ public class JsTranslator extends Job implements IJsTranslator{ // region //System.out.println("Region text: " + container.getText().substring(region.getStart(), region.getEnd())); - boolean isBlockRegion = region instanceof ITextRegionContainer; + boolean isContainerRegion = region instanceof ITextRegionContainer; /* make sure its not a sub container region, probably JSP */ if (type == DOMRegionContext.BLOCK_TEXT ) { int scriptStart = container.getStartOffset(); - int scriptTextEnd = container.getEndOffset() - container.getStartOffset(); - String regionText = container.getText().substring(region.getStart(), region.getEnd()); - int regionLength = regionText.length(); - // /Position inScript = new Position(scriptOffset, - // regionLength); - + int scriptTextLength = container.getLength(); + String regionText = container.getFullText(region); + int regionLength = region.getLength(); spaces = Util.getPad(scriptStart - scriptOffset); fScriptText.append(spaces); // fJsToHTMLRanges.put(inScript, inHtml); - if(isBlockRegion && REPLACE_INNER_BLOCK_SECTIONS_WITH_SPACE) { + if(isContainerRegion && REPLACE_INNER_BLOCK_SECTIONS_WITH_SPACE) { spaces = Util.getPad(regionLength); fScriptText.append(spaces); - }else if(isBlockRegion){ - fScriptText.append(regionText); - }else { + } + // Bug 241794 - Validation shows errors when using JSP Expressions inside JavaScript code + else if (regionText.indexOf(XML_COMMENT_START) >= 0) { + int index = regionText.indexOf(XML_COMMENT_START); + int leadingTrim = index + XML_COMMENT_START.length(); + for (int i = 0; i < index; i++) { + /* + * ignore the comment start when it's preceded only + * by white space + */ + if (!Character.isWhitespace(regionText.charAt(i))) { + leadingTrim = 0; + break; + } + } + spaces = Util.getPad(leadingTrim); + fScriptText.append(spaces); + fScriptText.append(regionText.substring(leadingTrim)); + } +// // Bug 241794 - Validation shows errors when using JSP Expressions inside JavaScript code +// else if (regionText.indexOf(XML_COMMENT_END) >= 0) { +// int index = regionText.indexOf(XML_COMMENT_END); +// int trailingTrim = index + XML_COMMENT_END.length(); +// for (int i = index; i < trailingTrim; i++) { +// /* +// * ignore the comment end when it's followed only +// * by white space +// */ +// if (!Character.isWhitespace(regionText.charAt(i))) { +// trailingTrim = 0; +// break; +// } +// } +// spaces = Util.getPad(trailingTrim); +// fScriptText.append(spaces); +// fScriptText.append(regionText.substring(0, trailingTrim)); +// } + else { fScriptText.append(regionText); - Position inHtml = new Position(scriptStart, scriptTextEnd); + Position inHtml = new Position(scriptStart, scriptTextLength); scriptLocationInHtml.add(inHtml); } diff --git a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/Messages.java b/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/Messages.java index 92b5d30bba..4b0baff36b 100644 --- a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/Messages.java +++ b/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/Messages.java @@ -13,34 +13,34 @@ */ package org.eclipse.wst.jsdt.web.core.javascript; -import java.util.MissingResourceException; -import java.util.ResourceBundle; +import org.eclipse.osgi.util.NLS; /** -* - -* Provisional API: This class/interface is part of an interim API that is still under development and expected to -* change significantly before reaching stability. It is being made available at this early stage to solicit feedback -* from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken -* (repeatedly) as the API evolves. -* - * @author childsb - * + * + * + * Provisional API: This class/interface is part of an interim API that is + * still under development and expected to change significantly before + * reaching stability. It is being made available at this early stage to + * solicit feedback from pioneering adopters on the understanding that any + * code that uses this API will almost certainly be broken (repeatedly) as the + * API evolves. + * */ -public class Messages { +public class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.wst.jsdt.web.core.internal.java.messages"; //$NON-NLS-1$ - private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); - private Messages() { } - public static String getString(String key) { - try { - return RESOURCE_BUNDLE.getString(key); - } - catch (MissingResourceException e) { - return '!' + key + '!'; - } + static { + // initialize resource bundle + NLS.initializeMessages(Messages.BUNDLE_NAME, Messages.class); } + + public static String NodeHelper00; + public static String NodeHelper01; + public static String NodeHelper03; + public static String NodeHelper11; + public static String NodeHelper12; + } diff --git a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/NodeHelper.java b/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/NodeHelper.java index b5e3028990..34d8910a88 100644 --- a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/NodeHelper.java +++ b/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/NodeHelper.java @@ -60,7 +60,7 @@ public class NodeHelper { char lastChar = string.charAt(lastIndex); return (((firstChar == NodeHelper.SINGLE_QUOTE_CHAR) && (lastChar == NodeHelper.SINGLE_QUOTE_CHAR)) || ((firstChar == NodeHelper.DOUBLE_QUOTE_CHAR) && (lastChar == NodeHelper.DOUBLE_QUOTE_CHAR))); } - protected final IStructuredDocumentRegion region; + protected IStructuredDocumentRegion region; public NodeHelper(IStructuredDocumentRegion region) { this.region = region; @@ -76,17 +76,15 @@ public class NodeHelper { if (region == null) { return null; } - // For debuging + // For debugging ITextRegionList t = region.getRegions(); ITextRegion r; Iterator regionIterator = t.iterator(); - String StructuredValue = Messages.getString("NodeHelper.0") + getTagName() + Messages.getString("NodeHelper.1"); //$NON-NLS-1$ //$NON-NLS-2$ + String StructuredValue = Messages.NodeHelper00 + getTagName() + Messages.NodeHelper01; //$NON-NLS-1$ //$NON-NLS-2$ while (regionIterator.hasNext()) { r = (ITextRegion) regionIterator.next(); if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) { - int start = r.getStart(); - int offset = r.getTextEnd(); - StructuredValue += "\t\t" + region.getText().substring(start, offset); //$NON-NLS-1$ + StructuredValue += "\t\t" + region.getText(r); //$NON-NLS-1$ /* * Theres a XML_TAG_ATTRIBUTE_EQUALS after the * XML_TAG_ATTRIBUTE_NAME we have to get rid of @@ -94,14 +92,13 @@ public class NodeHelper { if (regionIterator.hasNext()) { regionIterator.next(); } - if (regionIterator.hasNext()) { - r = ((ITextRegion) regionIterator.next()); - } - System.out.println(Messages.getString("NodeHelper.3")); //$NON-NLS-1$ - if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) { - int valStart = r.getStart(); - int valOffset = r.getTextEnd(); - StructuredValue += "\t\t" + stripEndQuotes(region.getText().substring(valStart, valOffset)) + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ + if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) { + if (regionIterator.hasNext()) { + r = ((ITextRegion) regionIterator.next()); + } + if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) { + StructuredValue += "\t\t" + stripEndQuotes(region.getText(r)) + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ + } } } } @@ -121,9 +118,7 @@ public class NodeHelper { while (regionIterator.hasNext()) { r = (ITextRegion) regionIterator.next(); if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) { - int start = r.getStart(); - int offset = r.getTextEnd(); - String tagname = region.getText().substring(start, offset).trim(); + String tagname = region.getText(r).trim(); /* Attribute values aren't case sensative */ if (NodeHelper.isInArray(name, tagname)) { return true; @@ -146,9 +141,7 @@ public class NodeHelper { while (regionIterator.hasNext()) { r = (ITextRegion) regionIterator.next(); if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) { - int start = r.getStart(); - int offset = r.getTextEnd(); - String tagname = region.getText().substring(start, offset).trim(); + String tagname = region.getText(r).trim(); /* * Attribute values aren't case sensative, also make sure next * region is attrib value @@ -161,9 +154,7 @@ public class NodeHelper { r = ((ITextRegion) regionIterator.next()); } if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) { - int valStart = r.getStart(); - int valOffset = r.getTextEnd(); - return stripEndQuotes(region.getText().substring(valStart, valOffset)); + return stripEndQuotes(region.getText(r)); } } } @@ -196,9 +187,7 @@ public class NodeHelper { while (regionIterator.hasNext()) { r = (ITextRegion) regionIterator.next(); if (r.getType() == DOMRegionContext.XML_TAG_NAME) { - int start = r.getStart(); - int offset = r.getTextEnd(); - return region.getText().substring(start, offset); + return region.getText(r); } } return null; @@ -208,28 +197,14 @@ public class NodeHelper { if (region == null) { return false; } - ITextRegionList t = region.getRegions(); - ITextRegion r; - Iterator regionIterator = t.iterator(); - while (regionIterator.hasNext()) { - r = (ITextRegion) regionIterator.next(); - if (r.getType() == DOMRegionContext.XML_END_TAG_OPEN) { - return true; - } - } - return false; + return DOMRegionContext.XML_END_TAG_OPEN.equals(region.getFirstRegion().getType()); } public boolean isSelfClosingTag() { if (region == null) { return false; } - if (region == null) { - return false; - } - ITextRegionList regions = region.getRegions(); - ITextRegion r = regions.get(regions.size() - 1); - return r.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE; + return DOMRegionContext.XML_EMPTY_TAG_CLOSE.equals(region.getLastRegion().getType()); } public boolean nameEquals(String name) { @@ -240,6 +215,12 @@ public class NodeHelper { return ((tagName = getTagName()) != null && tagName.equalsIgnoreCase(name)); } + public void setDocumentRegion(IStructuredDocumentRegion newRegion) { + if (newRegion == null) + throw new IllegalArgumentException(); + region = newRegion; + } + public String stripEndQuotes(String text) { if (text == null) { return null; @@ -258,7 +239,7 @@ public class NodeHelper { while (regionIterator.hasNext()) { ITextRegion r = (ITextRegion) regionIterator.next(); String nodeType = r.getType(); - nodeText += (Messages.getString("NodeHelper.11") + nodeType + Messages.getString("NodeHelper.12") + region.getText().substring(r.getStart(), r.getTextEnd()) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + nodeText += (Messages.NodeHelper11 + nodeType + Messages.NodeHelper12 + region.getText(r) + "\n"); //$NON-NLS-1$ } return nodeText; } diff --git a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/WebRootFinder.java b/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/WebRootFinder.java index 2fa76bfc6c..7a4cc1d6e6 100644 --- a/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/WebRootFinder.java +++ b/bundles/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/javascript/WebRootFinder.java @@ -24,6 +24,7 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.wst.common.componentcore.ComponentCore; +import org.eclipse.wst.common.componentcore.ModuleCoreNature; import org.eclipse.wst.common.componentcore.internal.util.ComponentUtilities; import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; @@ -37,24 +38,24 @@ import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; */ public class WebRootFinder { public static IPath getServerContextRoot(IProject project) { - String contextRoot = ComponentUtilities.getServerContextRoot(project); - if(contextRoot==null) { - contextRoot = project.getName(); + if (ModuleCoreNature.isFlexibleProject(project)) { + String contextRoot = ComponentUtilities.getServerContextRoot(project); + if (contextRoot != null) { + return new Path(contextRoot); + } } - return new Path(contextRoot); - } - - private static String getProjectRoot(IProject project) { - return project.getLocation().toString(); + return Path.ROOT; } public static IPath getWebContentFolder(IProject project) { - IVirtualComponent comp = ComponentCore.createComponent(project); - if (comp != null) { - IVirtualFolder rootFolder = comp.getRootFolder(); - return rootFolder.getUnderlyingFolder().getProjectRelativePath(); + if (ModuleCoreNature.isFlexibleProject(project)) { + IVirtualComponent comp = ComponentCore.createComponent(project); + if (comp != null) { + IVirtualFolder rootFolder = comp.getRootFolder(); + return rootFolder.getUnderlyingFolder().getProjectRelativePath(); + } } - return new Path(""); //$NON-NLS-1$ + return Path.ROOT; } public static String getWebContext(IProject project) { diff --git a/bundles/org.eclipse.wst.jsdt.web.ui/plugin.properties b/bundles/org.eclipse.wst.jsdt.web.ui/plugin.properties index fe0dbb77bb..a21456c57b 100644 --- a/bundles/org.eclipse.wst.jsdt.web.ui/plugin.properties +++ b/bundles/org.eclipse.wst.jsdt.web.ui/plugin.properties @@ -11,8 +11,8 @@ Bundle-Vendor.0 = Eclipse.org Bundle-Name.0 = JSDT Web Support UI -target.name.0 = JavaScirpt Source -target.name.1 = JavaScirpt Event Source +target.name.0 = JavaScript Source +target.name.1 = JavaScript Event Source hyperlinkDetector.name.0 = Java Element HyperLink Detector hyperlinkDetector.name.1 = Java Element HyperLink Detector menu.label.0 = Declerations diff --git a/bundles/org.eclipse.wst.jsdt.web.ui/plugin.xml b/bundles/org.eclipse.wst.jsdt.web.ui/plugin.xml index 02669dcb5e..aca02e1817 100644 --- a/bundles/org.eclipse.wst.jsdt.web.ui/plugin.xml +++ b/bundles/org.eclipse.wst.jsdt.web.ui/plugin.xml @@ -3,14 +3,6 @@ <plugin> <extension point="org.eclipse.wst.sse.ui.editorConfiguration"> - - <!-- - <sourceViewerConfiguration - class="org.eclipse.wst.jsdt.web.ui.StructuredTextViewerConfigurationJSDT" - target="org.eclipse.wst.html.core.htmlsource.source" /> - - --> - <contentOutlineConfiguration class="org.eclipse.wst.jsdt.web.ui.views.provisional.contentoutline.JsContentOutlineConfig" target="org.eclipse.wst.html.core.htmlsource.source" /> @@ -357,14 +349,16 @@ <validator scope="total" class="org.eclipse.wst.jsdt.web.core.internal.validation.JsValidator" - id="org.eclipse.wst.jsdt.web.jspsourcevalidator"> + id="org.eclipse.wst.jsdt.web.jssourcevalidator"> <contentTypeIdentifier id="org.eclipse.wst.html.core.htmlsource"> - <partitionType id="org.eclipse.wst.html.SCRIPT"></partitionType> - <partitionType id="org.eclipse.wst.html.SCRIPT.EVENTHANDLER"></partitionType> + <partitionType id="org.eclipse.wst.html.SCRIPT"/> + <partitionType id="org.eclipse.wst.html.SCRIPT.EVENTHANDLER"/> + </contentTypeIdentifier> + <contentTypeIdentifier id="org.eclipse.jst.jsp.core.jspsource"> + <partitionType id="org.eclipse.wst.html.SCRIPT"/> + <partitionType id="org.eclipse.wst.html.SCRIPT.EVENTHANDLER"/> </contentTypeIdentifier> </validator> - - </extension> <!--======================================================================================--> diff --git a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/registry/AdapterFactoryProviderForJSDT.java b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/registry/AdapterFactoryProviderForJSDT.java index e3f3c909ac..f4b6a69287 100644 --- a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/registry/AdapterFactoryProviderForJSDT.java +++ b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/internal/registry/AdapterFactoryProviderForJSDT.java @@ -11,7 +11,6 @@ package org.eclipse.wst.jsdt.web.ui.internal.registry; import org.eclipse.wst.html.core.internal.modelhandler.ModelHandlerForHTML; -import org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation; import org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapterFactory; import org.eclipse.wst.jsdt.web.ui.views.contentoutline.JFaceNodeAdapterFactoryForJSDT; import org.eclipse.wst.sse.core.internal.ltk.modelhandler.IDocumentTypeHandler; @@ -51,11 +50,8 @@ public class AdapterFactoryProviderForJSDT implements AdapterFactoryProvider { factory = new JFaceNodeAdapterFactoryForJSDT(IJFaceNodeAdapter.class, true); factoryRegistry.addFactory(factory); } - factory = factoryRegistry.getFactoryFor(IJsTranslation.class); - if (factory == null) { - factory = new JsTranslationAdapterFactory(); - factoryRegistry.addFactory(factory); - } + + JsTranslationAdapterFactory.setupAdapterFactory(structuredModel); } protected void addPropagatingAdapters(IStructuredModel structuredModel) {} |