Author: dazarov
Date: 2012-07-30 19:15:57 -0400 (Mon, 30 Jul 2012)
New Revision: 42791
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/projects/test_jsf_project/WebContent/pages/test_page2.xhtml
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/AddTLDMarkerResolution.java
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/action/JSPProblemMarkerResolutionGenerator.java
Log:
Make Quick Fix "Add tag library definition" work with KB Model instead of using
plain tag library list
https://issues.jboss.org/browse/JBIDE-12304
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/projects/test_jsf_project/WebContent/pages/test_page2.xhtml
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/projects/test_jsf_project/WebContent/pages/test_page2.xhtml 2012-07-30
23:08:26 UTC (rev 42790)
+++
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/projects/test_jsf_project/WebContent/pages/test_page2.xhtml 2012-07-30
23:15:57 UTC (rev 42791)
@@ -1,7 +1,6 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
-
xmlns:h="http://java.sun.com/jsf/html"
-
xmlns:f="http://java.sun.com/jsf/core">
+
xmlns:ui="http://java.sun.com/jsf/facelets">
<f:loadBundle basename="resources" var="msg" />
<head>
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-07-30
23:08:26 UTC (rev 42790)
+++
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/JSPProblemMarkerResolutionTest.java 2012-07-30
23:15:57 UTC (rev 42791)
@@ -1,7 +1,6 @@
package org.jboss.tools.jsf.ui.test;
import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -9,7 +8,6 @@
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -17,7 +15,6 @@
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
-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.ui.internal.validation.JSPContentSourceValidator;
@@ -161,17 +158,22 @@
IMarker[] markers = findMarkers(jspFile, JSP_MARKER_TYPE, "Unknown tag
(h:commandButton).");
- assertEquals(1, markers.length);
+ 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("AddTLDMarkerResolution not found", found);
validate(jspFile);
@@ -185,25 +187,30 @@
validate(jspFile);
- assertMarkerIsCreated(jspFile, XHTML_MARKER_TYPE, "Unknown tag (ui:insert).",
true, 8, 17, 31);
+ assertMarkerIsCreated(jspFile, XHTML_MARKER_TYPE, "Unknown tag
(f:loadBundle).", true, 5);
- IMarker[] markers = findMarkers(jspFile, XHTML_MARKER_TYPE, "Unknown tag
(ui:insert).");
+ IMarker[] markers = findMarkers(jspFile, XHTML_MARKER_TYPE, "Unknown tag
(f:loadBundle).");
- assertEquals(3, markers.length);
+ 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("AddTLDMarkerResolution not found", found);
validate(jspFile);
- assertMarkerIsNotCreated(jspFile, XHTML_MARKER_TYPE, "Unknown tag
(ui:insert).");
+ assertMarkerIsNotCreated(jspFile, XHTML_MARKER_TYPE, "Unknown tag
(f:loadBundle).");
}
public void testQuickFixesForTemporaryAnnotationInJSP() throws PartInitException,
BadLocationException{
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/action/AddTLDMarkerResolution.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/action/AddTLDMarkerResolution.java 2012-07-30
23:08:26 UTC (rev 42790)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/action/AddTLDMarkerResolution.java 2012-07-30
23:15:57 UTC (rev 42791)
@@ -60,14 +60,6 @@
this.prefix = prefix;
}
- public AddTLDMarkerResolution(String name, int start, int end, String uri, String
prefix){
- this.resolutionName = name;
- this.start = start;
- this.end = end;
- this.uri = uri;
- this.prefix = prefix;
- }
-
private Properties getProperties(){
Properties properties = new Properties();
properties.put(JSPPaletteInsertHelper.PROPOPERTY_ADD_TAGLIB, "true");
//$NON-NLS-1$
@@ -101,9 +93,13 @@
public String getLabel() {
return NLS.bind(Messages.AddTLDMarkerResolution_Name, resolutionName);
}
-
+
@Override
public void run(IMarker marker) {
+ if(!JSPProblemMarkerResolutionGenerator.validatePrefix(file, start, prefix)){
+ return;
+ }
+
FileEditorInput input = new FileEditorInput(file);
IDocumentProvider provider =
DocumentProviderRegistry.getDefault().getDocumentProvider(input);
try {
@@ -140,7 +136,10 @@
@Override
public void apply(IDocument document) {
-
+ if(!JSPProblemMarkerResolutionGenerator.validatePrefix(file, start, prefix)){
+ return;
+ }
+
Properties properties = getProperties();
PaletteTaglibInserter.getPrefixes(document, properties);
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-07-30
23:08:26 UTC (rev 42790)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/action/JSPProblemMarkerResolutionGenerator.java 2012-07-30
23:15:57 UTC (rev 42791)
@@ -64,6 +64,23 @@
return new IMarkerResolution[]{};
}
+ public static boolean validatePrefix(IFile file, int start, String prefix){
+ ELContext context = PageContextFactory.createPageContext(file);
+ if(context instanceof XmlContextImpl){
+ Map<String, List<INameSpace>> nameSpaces = ((XmlContextImpl)
context).getNameSpaces(start);
+ Iterator<List<INameSpace>> iterator = nameSpaces.values().iterator();
+ while(iterator.hasNext()){
+ List<INameSpace> list = iterator.next();
+ for(INameSpace ns : list){
+ if(prefix.equals(ns.getPrefix())){
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
private IJavaCompletionProposal[] isOurCase(Annotation annotation){
ArrayList<IJavaCompletionProposal> proposals = new
ArrayList<IJavaCompletionProposal>();
if(!(annotation instanceof TemporaryAnnotation)){
@@ -94,18 +111,8 @@
if(file == null)
return new IJavaCompletionProposal[]{};
- ELContext context = PageContextFactory.createPageContext(file);
- if(context instanceof XmlContextImpl){
- Map<String, List<INameSpace>> nameSpaces = ((XmlContextImpl)
context).getNameSpaces(start);
- Iterator<List<INameSpace>> iterator = nameSpaces.values().iterator();
- while(iterator.hasNext()){
- List<INameSpace> list = iterator.next();
- for(INameSpace ns : list){
- if(prefix.equals(ns.getPrefix())){
- return new IJavaCompletionProposal[]{};
- }
- }
- }
+ if(!validatePrefix(file, start, prefix)){
+ return new IJavaCompletionProposal[]{};
}
Object additionalInfo = ta.getAdditionalFixInfo();
@@ -126,7 +133,7 @@
String uri = ns.getURI();
String resolutionName = getResolutionName(xmlDocument != null &&
xmlDocument.isXMLType(), true, prefix, uri);
if(resolutionName != null && !names.contains(resolutionName) &&
l.getComponent(tagName) != null){
- proposals.add(new AddTLDMarkerResolution(resolutionName, start, end, uri,
prefix));
+ proposals.add(new AddTLDMarkerResolution(file, resolutionName, start, end, uri,
prefix));
names.add(resolutionName);
}
}
@@ -140,7 +147,7 @@
String uri = l.getURI();
String resolutionName = getResolutionName(xmlDocument != null &&
xmlDocument.isXMLType(), true, prefix, uri);
if(resolutionName != null && !names.contains(resolutionName) &&
l.getComponent(tagName) != null){
- proposals.add(new AddTLDMarkerResolution(resolutionName, start, end, uri, prefix));
+ proposals.add(new AddTLDMarkerResolution(file, resolutionName, start, end, uri,
prefix));
names.add(resolutionName);
}
}
@@ -186,18 +193,8 @@
IFile file = (IFile)marker.getResource();
- ELContext context = PageContextFactory.createPageContext(file);
- if(context instanceof XmlContextImpl){
- Map<String, List<INameSpace>> nameSpaces = ((XmlContextImpl)
context).getNameSpaces(start);
- Iterator<List<INameSpace>> iterator = nameSpaces.values().iterator();
- while(iterator.hasNext()){
- List<INameSpace> list = iterator.next();
- for(INameSpace ns : list){
- if(prefix.equals(ns.getPrefix())){
- return new IMarkerResolution[]{};
- }
- }
- }
+ if(!validatePrefix(file, start, prefix)){
+ return new IMarkerResolution[]{};
}
IKbProject kbProject = KbProjectFactory.getKbProject(file.getProject(), true);