Author: dazarov
Date: 2012-10-16 20:00:06 -0400 (Tue, 16 Oct 2012)
New Revision: 44546
Added:
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/projects/test_jsf_project/WebContent/pages/test_page2.jsp
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/util/StructuredModelWrapper.java
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/JSPProblemMarkerResolutionTest.java
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/action/JSPProblemMarkerResolutionGenerator.java
Log:
"Add missing required attribute(s)" quick fix for "Missing required
attribute" WTP problem marker JBIDE-12390
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/util/StructuredModelWrapper.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/util/StructuredModelWrapper.java 2012-10-16
23:55:58 UTC (rev 44545)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/util/StructuredModelWrapper.java 2012-10-17
00:00:06 UTC (rev 44546)
@@ -10,11 +10,15 @@
******************************************************************************/
package org.jboss.tools.common.text.ext.util;
+import java.io.IOException;
+
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.jboss.tools.common.model.XModel;
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
@@ -29,6 +33,10 @@
public void init(IDocument id) {
model = getModelManager().getExistingModelForRead(id);
}
+
+ public void init(IFile file) throws IOException, CoreException {
+ model = getModelManager().getModelForRead(file);
+ }
public Document getDocument() {
return (model instanceof IDOMModel) ? ((IDOMModel) model).getDocument() : null;
Added:
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/projects/test_jsf_project/WebContent/pages/test_page2.jsp
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/projects/test_jsf_project/WebContent/pages/test_page2.jsp
(rev 0)
+++
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/projects/test_jsf_project/WebContent/pages/test_page2.jsp 2012-10-17
00:00:06 UTC (rev 44546)
@@ -0,0 +1,10 @@
+<%@ taglib
uri="http://java.sun.com/jsp/jstl/xml" prefix="x"
%>
+
+<html>
+ <head>
+ <title>Input User Name Page</title>
+ </head>
+ <body>
+ <x:if></x:if>
+ </body>
+</html>
\ No newline at end of file
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/JSPProblemMarkerResolutionTest.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/JSPProblemMarkerResolutionTest.java 2012-10-16
23:55:58 UTC (rev 44545)
+++
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/JSPProblemMarkerResolutionTest.java 2012-10-17
00:00:06 UTC (rev 44546)
@@ -18,6 +18,11 @@
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.jst.jsp.core.internal.validation.JSPActionValidator;
+import org.eclipse.jst.jsp.core.internal.validation.JSPDirectiveValidator;
+import org.eclipse.jst.jsp.core.internal.validation.JSPJavaValidator;
+import org.eclipse.jst.jsp.core.internal.validation.JSPValidator;
+import org.eclipse.jst.jsp.ui.internal.validation.JSPActionSourceValidator;
import org.eclipse.jst.jsp.ui.internal.validation.JSPContentSourceValidator;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput;
@@ -81,26 +86,33 @@
if(JSP_EXT.equals(file.getFileExtension())){
file.deleteMarkers(JSP_MARKER_TYPE, true, IResource.DEPTH_INFINITE);
- JSPContentSourceValidator validator = new JSPContentSourceValidator();
+ JSPValidator[] validators ={
+ new JSPContentSourceValidator(),
+ new JSPActionSourceValidator(),
+ new JSPJavaValidator(),
+ new JSPDirectiveValidator()
+ };
- ValidationResult result = validator.validate(file, 0, new ValidationState(), new
NullProgressMonitor());
-
- IReporter reporter = result.getReporter(new NullProgressMonitor());
- List messages = reporter.getMessages();
- for(Object m : messages){
- if(m instanceof Message){
- Message message = (Message)m;
- IMarker marker = file.createMarker(JSP_MARKER_TYPE);
- marker.setAttributes(message.getAttributes());
- marker.setAttribute(IMarker.MESSAGE, message.getText());
- int markerSeverity = IMarker.SEVERITY_INFO;
- int sev = message.getSeverity();
- if ((sev & IMessage.HIGH_SEVERITY) != 0)markerSeverity =
IMarker.SEVERITY_ERROR;
- else if ((sev & IMessage.NORMAL_SEVERITY) != 0)markerSeverity =
IMarker.SEVERITY_WARNING;
- marker.setAttribute(IMarker.SEVERITY, markerSeverity);
- marker.setAttribute(IMarker.LINE_NUMBER, message.getLineNumber());
- marker.setAttribute(IMarker.CHAR_START, message.getOffset());
- marker.setAttribute(IMarker.CHAR_END, message.getOffset()+message.getLength());
+ for(JSPValidator validator : validators){
+ ValidationResult result = validator.validate(file, 0, new ValidationState(), new
NullProgressMonitor());
+
+ IReporter reporter = result.getReporter(new NullProgressMonitor());
+ List messages = reporter.getMessages();
+ for(Object m : messages){
+ if(m instanceof Message){
+ Message message = (Message)m;
+ IMarker marker = file.createMarker(JSP_MARKER_TYPE);
+ marker.setAttributes(message.getAttributes());
+ marker.setAttribute(IMarker.MESSAGE, message.getText());
+ int markerSeverity = IMarker.SEVERITY_INFO;
+ int sev = message.getSeverity();
+ if ((sev & IMessage.HIGH_SEVERITY) != 0)markerSeverity =
IMarker.SEVERITY_ERROR;
+ else if ((sev & IMessage.NORMAL_SEVERITY) != 0)markerSeverity =
IMarker.SEVERITY_WARNING;
+ marker.setAttribute(IMarker.SEVERITY, markerSeverity);
+ marker.setAttribute(IMarker.LINE_NUMBER, message.getLineNumber());
+ marker.setAttribute(IMarker.CHAR_START, message.getOffset());
+ marker.setAttribute(IMarker.CHAR_END, message.getOffset()+message.getLength());
+ }
}
}
}else if(XHTML_EXT.equals(file.getFileExtension())){
@@ -148,7 +160,7 @@
}
}
- public void testProblemMarkerResolutionInJSP() throws CoreException, SecurityException,
NoSuchMethodException, IllegalArgumentException, IllegalAccessException,
InvocationTargetException, InstantiationException {
+ public void testAddTLDMarkerResolutionInJSP() throws CoreException, SecurityException,
NoSuchMethodException, IllegalArgumentException, IllegalAccessException,
InvocationTargetException, InstantiationException {
IFile jspFile = project.getFile("WebContent/pages/test_page1.jsp");
assertTrue("File must be exists.",jspFile.exists());
@@ -180,7 +192,40 @@
assertMarkerIsNotCreated(jspFile, JSP_MARKER_TYPE, "Unknown tag
(h:commandButton).");
}
+
+ public void testAddAttributeMarkerResolutionInJSP() throws CoreException,
SecurityException, NoSuchMethodException, IllegalArgumentException,
IllegalAccessException, InvocationTargetException, InstantiationException {
+ IFile jspFile = project.getFile("WebContent/pages/test_page2.jsp");
+
+ assertTrue("File must be exists.",jspFile.exists());
+
+ validate(jspFile);
+ assertMarkerIsCreated(jspFile, JSP_MARKER_TYPE, "Missing required attribute
\"select\"", true, 7);
+
+ IMarker[] markers = findMarkers(jspFile, JSP_MARKER_TYPE, "Missing required
attribute \"select\"");
+
+ assertEquals("Should be 1 marker here", 1, markers.length);
+
+ JSPProblemMarkerResolutionGenerator generator = new
JSPProblemMarkerResolutionGenerator();
+
+ boolean found = false;
+
+ for(IMarker marker : markers){
+ generator.hasResolutions(marker);
+ IMarkerResolution[] resolutions = generator.getResolutions(marker);
+ for(IMarkerResolution resolution : resolutions){
+ resolution.run(marker);
+ found = true;
+ }
+ }
+
+ assertTrue("AddAttributeMarkerResolution not found", found);
+
+ validate(jspFile);
+
+ assertMarkerIsNotCreated(jspFile, JSP_MARKER_TYPE, "Missing required attribute
\"select\"");
+ }
+
public void testProblemMarkerResolutionInXHTML() throws CoreException,
SecurityException, NoSuchMethodException, IllegalArgumentException,
IllegalAccessException, InvocationTargetException, InstantiationException {
IFile jspFile = project.getFile("WebContent/pages/test_page2.xhtml");
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/action/JSPProblemMarkerResolutionGenerator.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/action/JSPProblemMarkerResolutionGenerator.java 2012-10-16
23:55:58 UTC (rev 44545)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/action/JSPProblemMarkerResolutionGenerator.java 2012-10-17
00:00:06 UTC (rev 44546)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.jst.web.ui.action;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -239,7 +240,7 @@
IDocument document = provider.getDocument(input);
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
- smw.init(document);
+ smw.init(file);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return;
@@ -250,6 +251,8 @@
String tagName = node.getNodeName();
resolutions.add(new AddAttributeMarkerResolution(file, node, attributeName, start,
end));
+ } catch (IOException ex) {
+ WebUiPlugin.getPluginLog().logError(ex);
} finally {
smw.dispose();
}