[jbosstools-commits] JBoss Tools SVN: r41555 - in trunk: common/plugins/org.jboss.tools.common.text.xml/META-INF and 7 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed May 30 18:38:59 EDT 2012


Author: dazarov
Date: 2012-05-30 18:38:55 -0400 (Wed, 30 May 2012)
New Revision: 41555

Added:
   trunk/common/plugins/org.jboss.tools.common.text.xml/schema/quickFix.exsd
   trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/
   trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/IQuickFixGenerator.java
   trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/MarkerAnnotationInfo.java
   trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/QuickFixExtension.java
   trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/QuickFixManager.java
   trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/QuickFixProposal.java
Modified:
   trunk/common/plugins/org.jboss.tools.common.text.xml/
   trunk/common/plugins/org.jboss.tools.common.text.xml/META-INF/MANIFEST.MF
   trunk/common/plugins/org.jboss.tools.common.text.xml/plugin.xml
   trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/BaseQuickAssistProcessor.java
   trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/xpl/MarkerProblemAnnotationHoverProcessor.java
   trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/JSPTextViewerConfiguration.java
   trunk/jst/plugins/org.jboss.tools.jst.web.ui/plugin.xml
   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 for problem markers "Unknown tag" work on temporary WTP annotations https://issues.jboss.org/browse/JBIDE-10958


Property changes on: trunk/common/plugins/org.jboss.tools.common.text.xml
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/https:/svn.jboss.org/repos/jbosstools/workspace/dazarov/branches/jbosstools-3.4.x/common/plugins/org.jboss.tools.common.text.xml:39727-39732
/workspace/dazarov/branches/jbosstools-3.4.x/common/plugins/org.jboss.tools.common.text.xml:39733-41542

Modified: trunk/common/plugins/org.jboss.tools.common.text.xml/META-INF/MANIFEST.MF
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.text.xml/META-INF/MANIFEST.MF	2012-05-30 21:33:36 UTC (rev 41554)
+++ trunk/common/plugins/org.jboss.tools.common.text.xml/META-INF/MANIFEST.MF	2012-05-30 22:38:55 UTC (rev 41555)
@@ -10,6 +10,7 @@
  org.jboss.tools.common.text.xml.contentassist,
  org.jboss.tools.common.text.xml.info,
  org.jboss.tools.common.text.xml.internal.ui.preferencies,
+ org.jboss.tools.common.text.xml.quickfix,
  org.jboss.tools.common.text.xml.ui,
  org.jboss.tools.common.text.xml.ui.xpl,
  org.jboss.tools.common.text.xml.xpl,

Modified: trunk/common/plugins/org.jboss.tools.common.text.xml/plugin.xml
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.text.xml/plugin.xml	2012-05-30 21:33:36 UTC (rev 41554)
+++ trunk/common/plugins/org.jboss.tools.common.text.xml/plugin.xml	2012-05-30 22:38:55 UTC (rev 41555)
@@ -3,6 +3,7 @@
 <plugin>
 
    <extension-point id="contentAssistProcessor" name="Content Assist Processor Extension Point Extension" schema="schema/contentAssistProcessor.exsd"/>
+   <extension-point id="quickFix" name="Quick Fix Generator" schema="schema/quickFix.exsd"/>
 
 <!--
 	<extension-point id="foldingStructureProviders" name="%foldingStructureProvidersExtensionPoint" schema="schema/foldingStructureProviders.exsd"/> 

Added: trunk/common/plugins/org.jboss.tools.common.text.xml/schema/quickFix.exsd
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.text.xml/schema/quickFix.exsd	                        (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.text.xml/schema/quickFix.exsd	2012-05-30 22:38:55 UTC (rev 41555)
@@ -0,0 +1,129 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.jboss.tools.common.text.xml" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+      <appInfo>
+         <meta.schema plugin="org.jboss.tools.common.text.xml" id="quickFix" name="Quick Fix Generator"/>
+      </appInfo>
+      <documentation>
+         This extenion point is used to send information about Quick fix generators to QuickFixManager.
+      </documentation>
+   </annotation>
+
+   <element name="extension">
+      <annotation>
+         <appInfo>
+            <meta.element />
+         </appInfo>
+      </annotation>
+      <complexType>
+         <sequence>
+            <element ref="quick-fix-generator" minOccurs="1" maxOccurs="unbounded"/>
+         </sequence>
+         <attribute name="point" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="id" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="name" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appInfo>
+                  <meta.attribute translatable="true"/>
+               </appInfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="quick-fix-generator">
+      <complexType>
+         <attribute name="id" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appInfo>
+                  <meta.attribute kind="identifier"/>
+               </appInfo>
+            </annotation>
+         </attribute>
+         <attribute name="generator-class" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appInfo>
+                  <meta.attribute kind="java" basedOn=":org.jboss.tools.common.text.xml.quickfix.IQuickFixGenerator"/>
+               </appInfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="since"/>
+      </appInfo>
+      <documentation>
+         JBoss Tools 3.4
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="examples"/>
+      </appInfo>
+      <documentation>
+         &lt;extension point=&quot;org.jboss.tools.common.text.xml.quickFix&quot;&gt;
+ &lt;quick-fix-generator id=&quot;seam.searcher&quot; generator-class=&quot;org.jboss.tools.jst.web.ui.action.JSPProblemMarkerResolutionGenerator&quot; /&gt;
+&lt;/extension&gt;
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="apiinfo"/>
+      </appInfo>
+      <documentation>
+         [Enter API information here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="implementation"/>
+      </appInfo>
+      <documentation>
+         [Enter information about supplied implementation of this extension point.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="copyright"/>
+      </appInfo>
+      <documentation>
+         Copyright (c) 2009 Red Hat, Inc. 
+Distributed under license by Red Hat, Inc. All rights reserved. 
+This program is 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: 
+Red Hat, Inc. - initial API and implementation
+      </documentation>
+   </annotation>
+
+</schema>


Property changes on: trunk/common/plugins/org.jboss.tools.common.text.xml/schema/quickFix.exsd
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/BaseQuickAssistProcessor.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/BaseQuickAssistProcessor.java	2012-05-30 21:33:36 UTC (rev 41554)
+++ trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/BaseQuickAssistProcessor.java	2012-05-30 22:38:55 UTC (rev 41555)
@@ -22,7 +22,8 @@
 import org.eclipse.jface.text.source.IAnnotationModel;
 import org.eclipse.ui.texteditor.SimpleMarkerAnnotation;
 import org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation;
-import org.jboss.tools.common.text.xml.MarkerAnnotationInfo.AnnotationInfo;
+import org.jboss.tools.common.text.xml.quickfix.MarkerAnnotationInfo;
+import org.jboss.tools.common.text.xml.quickfix.MarkerAnnotationInfo.AnnotationInfo;
 
 public class BaseQuickAssistProcessor implements IQuickAssistProcessor {
 

Added: trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/IQuickFixGenerator.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/IQuickFixGenerator.java	                        (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/IQuickFixGenerator.java	2012-05-30 22:38:55 UTC (rev 41555)
@@ -0,0 +1,37 @@
+/******************************************************************************* 
+ * Copyright (c) 2012 Red Hat, Inc. 
+ * Distributed under license by Red Hat, Inc. All rights reserved. 
+ * This program is 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: 
+ * Red Hat, Inc. - initial API and implementation 
+ ******************************************************************************/
+package org.jboss.tools.common.text.xml.quickfix;
+
+import java.util.List;
+
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.source.Annotation;
+
+public interface IQuickFixGenerator {
+	
+	/**
+     * Returns whether there are any proposals for the given annotation.
+     *
+     * @param annotation the annotation
+     * @return <code>true</code> if there are proposals for the given annotation,
+     *   <code>false</code> if not
+     */
+	public boolean hasProposals(Annotation annotation);
+	
+	/**
+     * Returns list of proposals for the given annotation (may
+     * be empty).
+     *
+     * @param annotation the annotation
+     * @return list of proposals for the given annotation
+     */
+	public List<ICompletionProposal> getProposals(Annotation annotation);
+}


Property changes on: trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/IQuickFixGenerator.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/MarkerAnnotationInfo.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/MarkerAnnotationInfo.java	                        (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/MarkerAnnotationInfo.java	2012-05-30 22:38:55 UTC (rev 41555)
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ *     Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/ 
+package org.jboss.tools.common.text.xml.quickfix;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext;
+import org.eclipse.jface.text.quickassist.IQuickAssistProcessor;
+import org.eclipse.jface.text.quickassist.IQuickFixableAnnotation;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.ui.IMarkerResolution;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.texteditor.SimpleMarkerAnnotation;
+import org.eclipse.wst.sse.ui.StructuredTextInvocationContext;
+import org.eclipse.wst.sse.ui.internal.correction.QuickFixRegistry;
+import org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation;
+
+public class MarkerAnnotationInfo {
+	public final List<AnnotationInfo> infos;
+	public final ISourceViewer viewer;
+
+	public MarkerAnnotationInfo(List<AnnotationInfo> infos, ISourceViewer textViewer) {
+		this.infos = infos;
+		this.viewer = textViewer;
+	}
+	
+	public List<ICompletionProposal> getCompletionProposals(AnnotationInfo info) {
+
+		if(info.isTop())
+			return getMarkerProposals(info);
+		else
+			return getProposals(info);
+		
+	}
+
+	public List<ICompletionProposal> getMarkerProposals(AnnotationInfo info) {
+		SimpleMarkerAnnotation annotation = (SimpleMarkerAnnotation)info.annotation;
+		
+		ArrayList<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
+		
+		IMarker marker = annotation.getMarker();
+		IMarkerResolution[] resolutions = IDE.getMarkerHelpRegistry().getResolutions(marker);
+		for (IMarkerResolution resolution : resolutions) {
+			proposals.add(new QuickFixProposal(resolution, marker));
+		}
+		
+		return proposals;
+	}
+	
+	public List<ICompletionProposal> getProposals(AnnotationInfo info) {
+		TemporaryAnnotation annotation = (TemporaryAnnotation)info.annotation;
+		
+		List<ICompletionProposal> allProposals = new ArrayList<ICompletionProposal>();
+		List<IQuickAssistProcessor> processors = new ArrayList<IQuickAssistProcessor>();
+		if (canFix(annotation)) {
+			Object o = annotation.getAdditionalFixInfo();
+			if (o instanceof IQuickAssistProcessor) {
+				processors.add((IQuickAssistProcessor)o);
+			}
+			
+			// get all relevant quick fixes for this annotation
+			if(QuickFixManager.getInstance().hasProposals(annotation)){
+				annotation.setAdditionalFixInfo(viewer.getDocument());
+				List<ICompletionProposal> proposals = QuickFixManager.getInstance().getProposals(annotation);
+				allProposals.addAll(proposals);
+			}
+
+			QuickFixRegistry registry = QuickFixRegistry.getInstance();
+			processors.addAll(Arrays.asList(registry.getQuickFixProcessors(annotation)));
+
+			// set up context
+			Map attributes = null;
+			attributes = annotation.getAttributes();
+			StructuredTextInvocationContext sseContext = new StructuredTextInvocationContext(viewer, info.position.getOffset(), info.position.getLength(), attributes);
+
+			// call each processor
+			for (int i = 0; i < processors.size(); ++i) {
+				List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
+				collectProposals((IQuickAssistProcessor) processors.get(i), annotation, sseContext, proposals);
+
+				if (proposals.size() > 0) {
+					allProposals.addAll(proposals);
+				}
+			}
+
+		}
+
+		return allProposals;
+	}
+	
+	private void collectProposals(IQuickAssistProcessor processor, Annotation annotation, IQuickAssistInvocationContext invocationContext, List<ICompletionProposal> proposalsList) {
+		ICompletionProposal[] proposals = processor.computeQuickAssistProposals(invocationContext);
+		if (proposals != null && proposals.length > 0) {
+			proposalsList.addAll(Arrays.asList(proposals));
+		}
+	}
+	
+	public boolean canFix(Annotation annotation) {
+		if (annotation instanceof IQuickFixableAnnotation) {
+			if (((IQuickFixableAnnotation) annotation).isQuickFixableStateSet()) {
+				return ((IQuickFixableAnnotation) annotation).isQuickFixable();
+			}
+		}else if(annotation instanceof TemporaryAnnotation){
+			if (((TemporaryAnnotation) annotation).isQuickFixableStateSet()) {
+				return ((TemporaryAnnotation) annotation).isQuickFixable();
+			}
+		}
+		return false;
+	}
+	
+	public static class AnnotationInfo {
+		public Annotation annotation;
+		public Position position;
+		
+		public AnnotationInfo(Annotation annotation, Position position){
+			this.annotation = annotation;
+			this.position = position;
+		}
+		
+		public boolean isTop(){
+			return annotation instanceof SimpleMarkerAnnotation;
+		}
+	}
+
+	@Override
+	public String toString() {
+		return null;
+	}
+}
\ No newline at end of file


Property changes on: trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/MarkerAnnotationInfo.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/QuickFixExtension.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/QuickFixExtension.java	                        (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/QuickFixExtension.java	2012-05-30 22:38:55 UTC (rev 41555)
@@ -0,0 +1,47 @@
+package org.jboss.tools.common.text.xml.quickfix;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.Platform;
+import org.jboss.tools.common.text.xml.XmlEditorPlugin;
+
+public class QuickFixExtension {
+	public static String EXTENSION_POINT = "org.jboss.tools.common.text.xml.quickFix"; //$NON-NLS-1$
+
+	String id;
+	IQuickFixGenerator generator;
+
+	public QuickFixExtension() {}
+
+	public String getId() {
+		return id;
+	}
+
+	public IQuickFixGenerator getQuickFixGenerator() {
+		return generator;
+	}
+
+	static QuickFixExtension[] INSTANCES;
+
+	public static QuickFixExtension[] getInstances() {
+		if(INSTANCES != null) return INSTANCES;
+		List<QuickFixExtension> list = new ArrayList<QuickFixExtension>();
+		IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(EXTENSION_POINT);
+		IConfigurationElement[] es = point.getConfigurationElements();
+		for (IConfigurationElement e: es) {
+			QuickFixExtension n = new QuickFixExtension();
+			n.id = e.getAttribute("id"); //$NON-NLS-1$
+			try{
+				n.generator = (IQuickFixGenerator)e.createExecutableExtension("generator-class"); //$NON-NLS-1$
+			}catch(CoreException ex){
+				XmlEditorPlugin.getDefault().logError(ex);
+			}
+			list.add(n);
+		}
+		return INSTANCES = list.toArray(new QuickFixExtension[0]);
+	}
+}


Property changes on: trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/QuickFixExtension.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/QuickFixManager.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/QuickFixManager.java	                        (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/QuickFixManager.java	2012-05-30 22:38:55 UTC (rev 41555)
@@ -0,0 +1,70 @@
+/******************************************************************************* 
+ * Copyright (c) 2012 Red Hat, Inc. 
+ * Distributed under license by Red Hat, Inc. All rights reserved. 
+ * This program is 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: 
+ * Red Hat, Inc. - initial API and implementation 
+ ******************************************************************************/
+package org.jboss.tools.common.text.xml.quickfix;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.source.Annotation;
+
+public class QuickFixManager {
+	private static QuickFixManager instance = null;
+	
+	private HashMap<String, IQuickFixGenerator> generators = new HashMap<String, IQuickFixGenerator>();
+	
+	public static QuickFixManager getInstance(){
+		if(instance == null){
+			instance = new QuickFixManager();
+		}
+		return instance;
+	}
+	
+	public QuickFixManager(){
+		QuickFixExtension[] extensions = QuickFixExtension.getInstances();
+		for(QuickFixExtension extension : extensions){
+			IQuickFixGenerator generator = extension.getQuickFixGenerator();
+			if(generator != null){
+				addQuickFixGenerator(generator);
+			}
+		}
+	}
+	
+	public void addQuickFixGenerator(IQuickFixGenerator generator){
+		if(!generators.containsKey(generator.getClass().toString())){
+			generators.put(generator.getClass().toString(), generator);
+		}
+	}
+	
+	public void removeQuickFixGenerator(IQuickFixGenerator generator){
+		generators.remove(generator);
+	}
+	
+	public boolean hasProposals(Annotation annotation){
+		for(IQuickFixGenerator generator : generators.values()){
+			if(generator.hasProposals(annotation)){
+				return true;
+			}
+		}
+		return false;
+	}
+	
+	public List<ICompletionProposal> getProposals(Annotation annotation){
+		ArrayList<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
+		for(IQuickFixGenerator generator : generators.values()){
+			List<ICompletionProposal> pp = generator.getProposals(annotation);
+			proposals.addAll(pp);
+		}
+		
+		return proposals;
+	}
+}


Property changes on: trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/QuickFixManager.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/QuickFixProposal.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/QuickFixProposal.java	                        (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/QuickFixProposal.java	2012-05-30 22:38:55 UTC (rev 41555)
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ *     Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/ 
+package org.jboss.tools.common.text.xml.quickfix;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.ui.IMarkerResolution;
+import org.eclipse.ui.IMarkerResolution2;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+
+public class QuickFixProposal implements ICompletionProposal{
+	private IMarkerResolution resolution;
+	private IMarker marker;
+	
+	public QuickFixProposal(IMarkerResolution resolution, IMarker marker){
+		this.resolution = resolution;
+		this.marker = marker;
+	}
+
+	public void apply(IDocument document) {
+		resolution.run(marker);
+	}
+
+	public Point getSelection(IDocument document) {
+		return null;
+	}
+
+	public String getAdditionalProposalInfo() {
+		if (resolution instanceof IMarkerResolution2)
+			return ((IMarkerResolution2) resolution).getDescription();
+		
+		return (String)marker.getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$
+	}
+
+	public String getDisplayString() {
+		return resolution.getLabel();
+	}
+
+	public Image getImage() {
+		if (resolution instanceof IMarkerResolution2)
+			return ((IMarkerResolution2)resolution).getImage();
+		return null;
+	}
+
+	public IContextInformation getContextInformation() {
+		return null;
+	}
+}


Property changes on: trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/quickfix/QuickFixProposal.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/xpl/MarkerProblemAnnotationHoverProcessor.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/xpl/MarkerProblemAnnotationHoverProcessor.java	2012-05-30 21:33:36 UTC (rev 41554)
+++ trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/xpl/MarkerProblemAnnotationHoverProcessor.java	2012-05-30 22:38:55 UTC (rev 41555)
@@ -63,8 +63,8 @@
 import org.eclipse.ui.texteditor.SimpleMarkerAnnotation;
 import org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation;
 import org.eclipse.wst.sse.ui.internal.taginfo.ProblemAnnotationHoverProcessor;
-import org.jboss.tools.common.text.xml.MarkerAnnotationInfo;
-import org.jboss.tools.common.text.xml.MarkerAnnotationInfo.AnnotationInfo;
+import org.jboss.tools.common.text.xml.quickfix.MarkerAnnotationInfo;
+import org.jboss.tools.common.text.xml.quickfix.MarkerAnnotationInfo.AnnotationInfo;
 import org.jboss.tools.common.text.xml.TextXMLMessages;
 
 public class MarkerProblemAnnotationHoverProcessor extends ProblemAnnotationHoverProcessor implements ITextHoverExtension, ITextHoverExtension2{

Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/JSPTextViewerConfiguration.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/JSPTextViewerConfiguration.java	2012-05-30 21:33:36 UTC (rev 41554)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/JSPTextViewerConfiguration.java	2012-05-30 22:38:55 UTC (rev 41555)
@@ -176,7 +176,7 @@
 			ISourceViewer sourceViewer, String partitionType) {
 		// TODO Auto-generated method stub
 //		return super.getContentAssistProcessors(sourceViewer, partitionType);
-		return new IContentAssistProcessor[0];
+		return null;
 	}
 	
 	/**

Modified: trunk/jst/plugins/org.jboss.tools.jst.web.ui/plugin.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.ui/plugin.xml	2012-05-30 21:33:36 UTC (rev 41554)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.ui/plugin.xml	2012-05-30 22:38:55 UTC (rev 41555)
@@ -793,4 +793,8 @@
          	<keywordReference id="org.eclipse.wst.html.ui.webcontent"/>
 		</page>
 	</extension>
+	
+	<extension point="org.jboss.tools.common.text.xml.quickFix">
+		<quick-fix-generator generator-class="org.jboss.tools.jst.web.ui.action.JSPProblemMarkerResolutionGenerator" id="org.jboss.tools.jst.web.ui.action.JSPProblemMarkerResolutionGenerator" />
+    </extension>
 </plugin>

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-05-30 21:33:36 UTC (rev 41554)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/action/AddTLDMarkerResolution.java	2012-05-30 22:38:55 UTC (rev 41555)
@@ -17,12 +17,21 @@
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
 import org.eclipse.osgi.util.NLS;
 import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
 import org.eclipse.ui.IMarkerResolution2;
 import org.eclipse.ui.part.FileEditorInput;
 import org.eclipse.ui.texteditor.DocumentProviderRegistry;
 import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.jboss.tools.common.model.ui.views.palette.PaletteInsertHelper;
+import org.jboss.tools.jst.jsp.jspeditor.dnd.JSPPaletteInsertHelper;
 import org.jboss.tools.jst.jsp.jspeditor.dnd.PaletteTaglibInserter;
 import org.jboss.tools.jst.web.ui.Messages;
 import org.jboss.tools.jst.web.ui.WebUiPlugin;
@@ -33,21 +42,34 @@
  * @author Daniel Azarov
  *
  */
-public class AddTLDMarkerResolution implements IMarkerResolution2{
+public class AddTLDMarkerResolution implements IMarkerResolution2, ICompletionProposal{
 	private IFile file;
 	private Properties properties;
+	
 	private String resolutionName;
+	private int start, end;
+	private String uri, prefix;
 	
 	public AddTLDMarkerResolution(IFile file, String name, Properties properties){
 		this.file = file;
 		this.properties = properties;
 		this.resolutionName = name;
 	}
+	
+	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;
+	}
 
+	@Override
 	public String getLabel() {
 		return NLS.bind(Messages.AddTLDMarkerResolution_Name, resolutionName);
 	}
 
+	@Override
 	public void run(IMarker marker) {
 		FileEditorInput input = new FileEditorInput(file);
 		IDocumentProvider provider = DocumentProviderRegistry.getDefault().getDocumentProvider(input);
@@ -68,11 +90,68 @@
 		}
 	}
 
+	@Override
 	public String getDescription() {
 		return getLabel();
 	}
 
+	@Override
 	public Image getImage() {
 		return null;//ImageDescriptor.createFromFile(AddTLDMarkerResolution.class,	"images/xstudio/editors/taglibs_file.gif").createImage(); //$NON-NLS-1$
 	}
+
+	@Override
+	public void apply(IDocument document) {
+		properties = new Properties();
+		properties.put(JSPPaletteInsertHelper.PROPOPERTY_ADD_TAGLIB, "true"); //$NON-NLS-1$
+		properties.put(PaletteInsertHelper.PROPOPERTY_START_TEXT, ""); //$NON-NLS-1$
+		properties.put(JSPPaletteInsertHelper.PROPOPERTY_TAGLIBRARY_URI, uri);
+		properties.put(JSPPaletteInsertHelper.PROPOPERTY_DEFAULT_PREFIX, prefix);
+		properties.put(PaletteInsertHelper.PROPOPERTY_SELECTION_PROVIDER, new ISelectionProvider() {
+			
+			@Override
+			public void setSelection(ISelection selection) {
+			}
+			
+			@Override
+			public void removeSelectionChangedListener(
+					ISelectionChangedListener listener) {
+			}
+			
+			@Override
+			public ISelection getSelection() {
+				return new TextSelection(start, end-start);
+			}
+			
+			@Override
+			public void addSelectionChangedListener(ISelectionChangedListener listener) {
+			}
+		});
+		
+		
+		Properties p = PaletteTaglibInserter.getPrefixes(document, properties);
+		
+		PaletteTaglibInserter inserter = new PaletteTaglibInserter();
+		inserter.inserTaglib(document, properties);
+	}
+
+	@Override
+	public Point getSelection(IDocument document) {
+		return null;
+	}
+
+	@Override
+	public String getAdditionalProposalInfo() {
+		return getDescription();
+	}
+
+	@Override
+	public String getDisplayString() {
+		return getLabel();
+	}
+
+	@Override
+	public IContextInformation getContextInformation() {
+		return null;
+	}
 }
\ No newline at end of file

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-05-30 21:33:36 UTC (rev 41554)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/action/JSPProblemMarkerResolutionGenerator.java	2012-05-30 22:38:55 UTC (rev 41555)
@@ -10,14 +10,20 @@
  ******************************************************************************/
 package org.jboss.tools.jst.web.ui.action;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.Properties;
+import java.util.Set;
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IMarker;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.source.Annotation;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.ISelectionProvider;
@@ -26,7 +32,14 @@
 import org.eclipse.ui.part.FileEditorInput;
 import org.eclipse.ui.texteditor.DocumentProviderRegistry;
 import org.eclipse.ui.texteditor.IDocumentProvider;
+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.sse.ui.internal.reconcile.TemporaryAnnotation;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
 import org.jboss.tools.common.model.ui.views.palette.PaletteInsertHelper;
+import org.jboss.tools.common.text.xml.quickfix.IQuickFixGenerator;
 import org.jboss.tools.jst.jsp.jspeditor.dnd.JSPPaletteInsertHelper;
 import org.jboss.tools.jst.jsp.jspeditor.dnd.PaletteTaglibInserter;
 import org.jboss.tools.jst.web.ui.WebUiPlugin;
@@ -37,7 +50,7 @@
  * @author Daniel Azarov
  *
  */
-public class JSPProblemMarkerResolutionGenerator implements IMarkerResolutionGenerator2 {
+public class JSPProblemMarkerResolutionGenerator implements IMarkerResolutionGenerator2, IQuickFixGenerator {
 	
 	private static final String HTML_VALIDATOR_MARKER="org.eclipse.wst.html.core.validationMarker"; //$NON-NLS-1$
 	private static final String JSP_VALIDATOR_MARKER="org.eclipse.jst.jsp.core.validationMarker"; //$NON-NLS-1$
@@ -60,6 +73,7 @@
 	private Properties properties;
 	private String resolutionName;
 	
+	@Override
 	public IMarkerResolution[] getResolutions(IMarker marker) {
 		try{
 			if(isOurCase(marker)){
@@ -73,6 +87,48 @@
 		return new IMarkerResolution[]{};
 	}
 	
+	private ICompletionProposal isOurCase(Annotation annotation){
+		if(!(annotation instanceof TemporaryAnnotation)){
+			return null;
+		}
+		TemporaryAnnotation ta = (TemporaryAnnotation)annotation;
+		
+		
+		String message = annotation.getText();
+		if(ta.getPosition() == null)
+			return null;
+		
+		final int start = ta.getPosition().getOffset();
+		
+		final int end = ta.getPosition().getOffset()+ta.getPosition().getLength();
+		
+		if(!message.startsWith(UNKNOWN_TAG))
+			return null;
+		
+		String prefix = getPrifix(message);
+		if(prefix == null)
+			return null;
+		
+		if(!libs.containsKey(prefix))
+			return null;
+		
+		Object additionalInfo = ta.getAdditionalFixInfo();
+		if(additionalInfo instanceof IDocument){
+			IStructuredModel model = StructuredModelManager.getModelManager().getModelForRead((IStructuredDocument)additionalInfo);
+			IDOMDocument xmlDocument = (model instanceof IDOMModel) ? ((IDOMModel) model).getDocument() : null;
+			if(xmlDocument != null && xmlDocument.isXMLType()){
+				resolutionName = "xmlns: "+prefix+" = \""+libs.get(prefix)+"\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+			}else{
+				resolutionName = "<%@ taglib uri = \""+libs.get(prefix)+"\" prefix=\""+prefix+"\" %>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+			}
+			
+		}
+		
+		
+		
+		return new AddTLDMarkerResolution(resolutionName, start, end, libs.get(prefix), prefix);
+	}
+	
 	private boolean isOurCase(IMarker marker) throws CoreException{
 		String message = (String)marker.getAttribute(IMarker.MESSAGE);
 		
@@ -86,7 +142,7 @@
 			return false;
 		final int end = attribute.intValue();
 		
-		if(!message.startsWith(UNKNOWN_TAG)) //$NON-NLS-1$
+		if(!message.startsWith(UNKNOWN_TAG))
 			return false;
 		
 		String prefix = getPrifix(message);
@@ -115,17 +171,21 @@
 		properties.put(JSPPaletteInsertHelper.PROPOPERTY_DEFAULT_PREFIX, prefix);
 		properties.put(PaletteInsertHelper.PROPOPERTY_SELECTION_PROVIDER, new ISelectionProvider() {
 			
+			@Override
 			public void setSelection(ISelection selection) {
 			}
 			
+			@Override
 			public void removeSelectionChangedListener(
 					ISelectionChangedListener listener) {
 			}
 			
+			@Override
 			public ISelection getSelection() {
 				return new TextSelection(start, end-start);
 			}
 			
+			@Override
 			public void addSelectionChangedListener(ISelectionChangedListener listener) {
 			}
 		});
@@ -163,6 +223,7 @@
 		return prefix;
 	}
 
+	@Override
 	public boolean hasResolutions(IMarker marker) {
 		try{
 			String message = (String)marker.getAttribute(IMarker.MESSAGE);
@@ -172,4 +233,20 @@
 		}
 		return false;
 	}
+
+	@Override
+	public boolean hasProposals(Annotation annotation) {
+		String message = annotation.getText();
+		return message.startsWith(UNKNOWN_TAG);
+	}
+
+	@Override
+	public List<ICompletionProposal> getProposals(Annotation annotation) {
+		ArrayList<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
+		ICompletionProposal proposal = isOurCase(annotation); 
+		if(proposal != null){
+			proposals.add(proposal);
+		}
+		return proposals;
+	}
 }
\ No newline at end of file



More information about the jbosstools-commits mailing list