219761 Syntax error reported at wrong location
diff --git a/tests/org.eclipse.jst.jsp.core.tests/src/org/eclipse/jst/jsp/core/tests/translation/JSPJavaTranslatorCoreTest.java b/tests/org.eclipse.jst.jsp.core.tests/src/org/eclipse/jst/jsp/core/tests/translation/JSPJavaTranslatorCoreTest.java index a23101f..9ff7ddb 100644 --- a/tests/org.eclipse.jst.jsp.core.tests/src/org/eclipse/jst/jsp/core/tests/translation/JSPJavaTranslatorCoreTest.java +++ b/tests/org.eclipse.jst.jsp.core.tests/src/org/eclipse/jst/jsp/core/tests/translation/JSPJavaTranslatorCoreTest.java
@@ -42,6 +42,7 @@ import org.eclipse.jst.jsp.core.tests.validation.ValidationContextForTest; import org.eclipse.wst.sse.core.StructuredModelManager; import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; +import org.eclipse.wst.validation.ValidationFramework; import org.eclipse.wst.validation.internal.operations.ValidatorManager; import org.eclipse.wst.validation.internal.provisional.core.IReporter; import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; @@ -306,4 +307,47 @@ } assertEquals("problem markers found" + s.toString(), 0, markers.length); } + + public void test_219761a() throws Exception { + /** + * Broken behavior has a Java syntax error on line 19, which only + * contains an include directive to a fragment that doesn't exist. + * + * All syntax errors should be on lines 25 or 28 and after offset 373 + * (single character line delimiter!). + */ + String testName = "testTranslatorMessagesWithIncludes"; + // Create new project + IProject project = BundleResourceUtil.createSimpleProject(testName, null, null); + assertTrue(project.exists()); + BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + testName, "/" + testName); + + waitForBuildAndValidation(project); + ValidationFramework.getDefault().validate(new IProject[]{project}, true, true, new NullProgressMonitor()); + waitForBuildAndValidation(project); + + IFile main = project.getFile("/WebContent/sample.jsp"); + assertTrue("sample test file does not exist", main.isAccessible()); + IMarker[] markers = main.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ZERO); + StringBuffer markerText = new StringBuffer(); + for (int i = 0; i < markers.length; i++) { + // line/start-end + markerText.append("\nL" + markers[i].getAttribute(IMarker.LINE_NUMBER) + "/o" + markers[i].getAttribute(IMarker.CHAR_START) + "-" + markers[i].getAttribute(IMarker.CHAR_END) + ":" + markers[i].getAttribute(IMarker.MESSAGE)); + } + int numberOfSyntaxErrors = 0; + for (int i = 0; i < markers.length; i++) { + Object message = markers[i].getAttribute(IMarker.MESSAGE); + assertNotNull("Marker message was null!", message); + if (message.toString().startsWith("Syntax error")) { + numberOfSyntaxErrors++; + assertTrue("Syntax error reported before line 25" + markerText, ((Integer) markers[i].getAttribute(IMarker.LINE_NUMBER)).intValue() >= 25); + assertTrue("Syntax error reported before offset 374" + markerText, ((Integer) markers[i].getAttribute(IMarker.CHAR_START)).intValue() >= 373); + assertTrue("Syntax error reported after 459" + markerText, ((Integer) markers[i].getAttribute(IMarker.CHAR_START)).intValue() < 459); + } + } + assertEquals("wrong number of syntax errors reported\n" + markerText, 3, numberOfSyntaxErrors); + + // clean up if we got to the end + project.delete(true, true, null); + } }
diff --git a/tests/org.eclipse.jst.jsp.core.tests/testfiles/testTranslatorMessagesWithIncludes/.classpath b/tests/org.eclipse.jst.jsp.core.tests/testfiles/testTranslatorMessagesWithIncludes/.classpath new file mode 100644 index 0000000..5ec3b3b --- /dev/null +++ b/tests/org.eclipse.jst.jsp.core.tests/testfiles/testTranslatorMessagesWithIncludes/.classpath
@@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="output" path="WebContent/WEB-INF/classes"/> +</classpath>
diff --git a/tests/org.eclipse.jst.jsp.core.tests/testfiles/testTranslatorMessagesWithIncludes/.project b/tests/org.eclipse.jst.jsp.core.tests/testfiles/testTranslatorMessagesWithIncludes/.project new file mode 100644 index 0000000..bdab090 --- /dev/null +++ b/tests/org.eclipse.jst.jsp.core.tests/testfiles/testTranslatorMessagesWithIncludes/.project
@@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>testTranslatorMessagesWithIncludes</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription>
diff --git a/tests/org.eclipse.jst.jsp.core.tests/testfiles/testTranslatorMessagesWithIncludes/WebContent/WEB-INF/input.tld b/tests/org.eclipse.jst.jsp.core.tests/testfiles/testTranslatorMessagesWithIncludes/WebContent/WEB-INF/input.tld new file mode 100644 index 0000000..53c815a --- /dev/null +++ b/tests/org.eclipse.jst.jsp.core.tests/testfiles/testTranslatorMessagesWithIncludes/WebContent/WEB-INF/input.tld
@@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="ISO-8859-1" ?> +<!DOCTYPE taglib + PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" + "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd"> +<taglib> + <tlib-version>1.0</tlib-version> + <jsp-version>1.2</jsp-version> + <short-name>input</short-name> + + <description> + </description> + + + <!-- HTML Text TAG --> + <tag> + <name>text</name> + <tag-class>test.taglib.Text</tag-class> + <body-content>empty</body-content> + <description> + Tag lib to show validation error. + </description> + <attribute> + <name>name</name> + <required>true</required> + <rtexprvalue>true</rtexprvalue> + </attribute> + </tag> + + + + + +</taglib>
diff --git a/tests/org.eclipse.jst.jsp.core.tests/testfiles/testTranslatorMessagesWithIncludes/WebContent/WEB-INF/web.xml b/tests/org.eclipse.jst.jsp.core.tests/testfiles/testTranslatorMessagesWithIncludes/WebContent/WEB-INF/web.xml new file mode 100644 index 0000000..1990ad7 --- /dev/null +++ b/tests/org.eclipse.jst.jsp.core.tests/testfiles/testTranslatorMessagesWithIncludes/WebContent/WEB-INF/web.xml
@@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<web-app + id="WebApp_ID" + version="2.4" + xmlns="http://java.sun.com/xml/ns/j2ee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" +> + <display-name>test1</display-name> + <welcome-file-list> + <welcome-file>index.html</welcome-file> + <welcome-file>index.htm</welcome-file> + <welcome-file>index.jsp</welcome-file> + <welcome-file>default.html</welcome-file> + <welcome-file>default.htm</welcome-file> + <welcome-file>default.jsp</welcome-file> + </welcome-file-list> +</web-app>
diff --git a/tests/org.eclipse.jst.jsp.core.tests/testfiles/testTranslatorMessagesWithIncludes/WebContent/sample.jsp b/tests/org.eclipse.jst.jsp.core.tests/testfiles/testTranslatorMessagesWithIncludes/WebContent/sample.jsp new file mode 100644 index 0000000..a58fcbf --- /dev/null +++ b/tests/org.eclipse.jst.jsp.core.tests/testfiles/testTranslatorMessagesWithIncludes/WebContent/sample.jsp
@@ -0,0 +1,36 @@ + <%@page import="java.util.Calendar"%> +<%@ taglib uri="/WEB-INF/input.tld" prefix="input" %> +<HTML> + +<HEAD> + +</HEAD> + + + +<BODY> + +<p> + The problem in both cases is a missing equals sign after the percent. However the include file=is + highlighed instead of the actual error + + + + <%@ include file="../commonEventHandlers.jspf"%> + </p> + + <p> + + + <input:text name="<% Calendar.DAY_OF_MONTH %>" /> + </p> + <p> + <input:text name="<% Calendar.DAY_OF_MONTH %>" /> + + + +</p> + +</BODY> +</HTML> +
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.jst.jsp.ui.tests/META-INF/MANIFEST.MF index 24c55ec..6f56d7e 100644 --- a/tests/org.eclipse.jst.jsp.ui.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.jst.jsp.ui.tests/META-INF/MANIFEST.MF
@@ -29,6 +29,7 @@ Require-Bundle: org.eclipse.jface.text, org.eclipse.ui, org.eclipse.core.resources, + org.eclipse.jdt.ui, org.eclipse.jdt.core, org.eclipse.jst.jsp.ui, org.junit;bundle-version="[3.8.0,4.0.0)", @@ -46,6 +47,8 @@ org.eclipse.wst.xml.ui, com.ibm.icu, org.eclipse.wst.html.ui, - org.eclipse.wst.validation + org.eclipse.wst.validation, + org.eclipse.core.commands, + org.eclipse.core.expressions Eclipse-LazyStart: true Bundle-RequiredExecutionEnvironment: J2SE-1.4
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/plugin.properties b/tests/org.eclipse.jst.jsp.ui.tests/plugin.properties index 8b19d42..be2912a 100644 --- a/tests/org.eclipse.jst.jsp.ui.tests/plugin.properties +++ b/tests/org.eclipse.jst.jsp.ui.tests/plugin.properties
@@ -12,4 +12,5 @@ Bundle-Vendor.0 = Eclipse.org Bundle-Name.0 = Structured Source Editor for JSP Tests view.name.0 = Embedded JSP Structured Text Viewer -taglibview.name.0=TaglibIndex Delta Trace View \ No newline at end of file +taglibview.name.0=TaglibIndex Delta Trace View +_UI_SHOW_TRANSLATION=Show Translation \ No newline at end of file
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/plugin.xml b/tests/org.eclipse.jst.jsp.ui.tests/plugin.xml index 6ac3a4b..cb2f478 100644 --- a/tests/org.eclipse.jst.jsp.ui.tests/plugin.xml +++ b/tests/org.eclipse.jst.jsp.ui.tests/plugin.xml
@@ -16,5 +16,28 @@ class="org.eclipse.jst.jsp.ui.tests.TaglibIndexDeltaTraceView" id="org.eclipse.jst.jsp.ui.tests.TaglibIndexDeltaTraceView" /> </extension> - + <extension + point="org.eclipse.ui.commands"> + <command + id="org.eclipse.jst.jsp.ui.showTranslation" + name="%_UI_SHOW_TRANSLATION"> + </command> + </extension> + <extension point="org.eclipse.ui.bindings"> + <!-- win32: M1=CTRL, M2=SHIFT, M3=ALT, M4=- + carbon: M1=COMMAND, M2=SHIFT, M3=ALT, M4=CTRL + gtk: ? + --> + <key + sequence="M1+M2+9" + contextId="org.eclipse.wst.sse.ui.structuredTextEditorScope" + commandId="org.eclipse.jst.jsp.ui.showTranslation" + schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/> + </extension> + <extension point="org.eclipse.ui.handlers"> + <handler + class="org.eclipse.jst.jsp.ui.tests.ShowTranslationHandler" + commandId="org.eclipse.jst.jsp.ui.showTranslation"> + </handler> + </extension> </plugin>
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/JSPTranslationEditorInput.java b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/JSPTranslationEditorInput.java new file mode 100644 index 0000000..d0f7382 --- /dev/null +++ b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/JSPTranslationEditorInput.java
@@ -0,0 +1,168 @@ +/******************************************************************************* + * Copyright (c) 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.jst.jsp.ui.tests; + +import java.io.InputStream; + +import org.eclipse.core.resources.IStorage; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jst.jsp.core.internal.java.IJSPTranslation; +import org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter; +import org.eclipse.ui.IPersistableElement; +import org.eclipse.ui.IStorageEditorInput; +import org.eclipse.wst.sse.core.internal.util.DocumentInputStream; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; + +/** + * @author nitin + * + */ +public class JSPTranslationEditorInput implements IStorageEditorInput { + private class JSPTranslationStorage implements IStorage { + /** + * + */ + public JSPTranslationStorage(IDOMModel jspModel) { + fModel = jspModel; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) + */ + public Object getAdapter(Class adapter) { + return fModel.getAdapter(adapter); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.resources.IStorage#getContents() + */ + public InputStream getContents() throws CoreException { + return new DocumentInputStream(getTranslationAdapter().getJSPTranslation().getJavaDocument()); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.resources.IStorage#getFullPath() + */ + public IPath getFullPath() { + return new Path(getTranslationAdapter().getJSPTranslation().getJavaPath()); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.resources.IStorage#getName() + */ + public String getName() { + return getTranslationAdapter().getJSPTranslation().getCompilationUnit().getElementName(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.resources.IStorage#isReadOnly() + */ + public boolean isReadOnly() { + return true; + } + } + + IDOMModel fModel; + + private JSPTranslationStorage fStorage; + + /** + * + */ + public JSPTranslationEditorInput(IDOMModel model) { + fStorage = new JSPTranslationStorage(model); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IEditorInput#exists() + */ + public boolean exists() { + return false; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) + */ + public Object getAdapter(Class adapter) { + return fModel.getAdapter(adapter); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IEditorInput#getImageDescriptor() + */ + public ImageDescriptor getImageDescriptor() { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IEditorInput#getName() + */ + public String getName() { + return new Path(fModel.getBaseLocation()).lastSegment() + ".java"; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IEditorInput#getPersistable() + */ + public IPersistableElement getPersistable() { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IStorageEditorInput#getStorage() + */ + public IStorage getStorage() throws CoreException { + return fStorage; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IEditorInput#getToolTipText() + */ + public String getToolTipText() { + return fModel.getBaseLocation(); + } + + JSPTranslationAdapter getTranslationAdapter() { + JSPTranslationAdapter adapter = (JSPTranslationAdapter) fModel.getDocument().getAdapterFor(IJSPTranslation.class); + return adapter; + } + + +}
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/ShowTranslationHandler.java b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/ShowTranslationHandler.java new file mode 100644 index 0000000..29405ed --- /dev/null +++ b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/ShowTranslationHandler.java
@@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 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.jst.jsp.ui.tests; + +import java.util.List; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.expressions.EvaluationContext; +import org.eclipse.core.resources.IMarker; +import org.eclipse.jdt.core.compiler.IProblem; +import org.eclipse.jdt.ui.JavaUI; +import org.eclipse.jface.text.Position; +import org.eclipse.jface.text.source.Annotation; +import org.eclipse.jface.text.source.IAnnotationModel; +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; +import org.eclipse.jst.jsp.core.internal.java.JSPTranslationExtension; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IStorageEditorInput; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.texteditor.AnnotationTypeLookup; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; + + +/** + * Opens the current JSP editor's current translated source in a Java editor + * + * Invoke with M1+M2+9 + * + * @author nitin + */ +public class ShowTranslationHandler extends AbstractHandler { + + /** + * + */ + public ShowTranslationHandler() { + } + + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands + * .ExecutionEvent) + */ + public Object execute(ExecutionEvent event) throws ExecutionException { + // IDE.openEditor(event.getApplicationContext(), createEditorInput(), + // JavaUI.ID_CU_EDITOR, true); + EvaluationContext evaluationContext = (EvaluationContext) event.getApplicationContext(); + if (evaluationContext != null) { + Object selection = evaluationContext.getDefaultVariable(); + if (selection instanceof List) { + List list = (List) selection; + if (!list.isEmpty()) { + if (list.get(0) instanceof IDOMNode) { + IDOMModel model = ((IDOMNode) list.get(0)).getModel(); + INodeAdapter adapter = model.getDocument().getAdapterFor(IJSPTranslation.class); + if (adapter != null) { + // create an IEditorInput for the Java editor + 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); + JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class); + JSPTranslationExtension translation = translationAdapter.getJSPTranslation(); + 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 null; + } +}