|
From: <caw...@us...> - 2007-03-14 20:52:16
|
Revision: 2176
http://svn.sourceforge.net/rubyeclipse/?rev=2176&view=rev
Author: cawilliams
Date: 2007-03-14 13:52:14 -0700 (Wed, 14 Mar 2007)
Log Message:
-----------
start working towards more infrastructure for quick fixes
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/IRubyAnnotation.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyDocumentProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyMarkerAnnotation.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyScriptCompletion.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/correction/CorrectionMessages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/correction/RubyCorrectionProcessor.java
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/IRubyAnnotation.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/IRubyAnnotation.java 2007-03-14 20:51:49 UTC (rev 2175)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/IRubyAnnotation.java 2007-03-14 20:52:14 UTC (rev 2176)
@@ -97,4 +97,20 @@
*/
IRubyScript getRubyScript();
+ /**
+ * Returns the problem id or <code>-1</code> if no problem id can be evaluated.
+ *
+ * @return returns the problem id or <code>-1</code>
+ */
+ int getId();
+
+ /**
+ * Returns the marker type associated to this problem or <code>null<code> if no marker type
+ * can be evaluated.
+ *
+ * @return the type of the marker which would be associated to the problem or
+ * <code>null<code> if no marker type can be evaluated.
+ */
+ String getMarkerType();
+
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyDocumentProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyDocumentProvider.java 2007-03-14 20:51:49 UTC (rev 2175)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyDocumentProvider.java 2007-03-14 20:52:14 UTC (rev 2176)
@@ -9,7 +9,6 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.util.ListenerList;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
@@ -30,6 +29,7 @@
import org.eclipse.jface.text.source.IAnnotationPresentation;
import org.eclipse.jface.text.source.ImageUtilities;
import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.ListenerList;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
@@ -51,7 +51,8 @@
import org.rubypeople.rdt.core.IRubyScript;
import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.core.RubyModelException;
-import org.rubypeople.rdt.core.parser.IProblem;
+import org.rubypeople.rdt.core.compiler.CategorizedProblem;
+import org.rubypeople.rdt.core.compiler.IProblem;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.internal.ui.RubyPluginImages;
import org.rubypeople.rdt.internal.ui.text.ruby.IProblemRequestorExtension;
@@ -635,6 +636,16 @@
public IRubyScript getRubyScript() {
return fRubyScript;
}
+
+ public int getId() {
+ return fProblem.getID();
+ }
+
+ public String getMarkerType() {
+ if (fProblem instanceof CategorizedProblem)
+ return ((CategorizedProblem) fProblem).getMarkerType();
+ return null;
+ }
}
/**
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyMarkerAnnotation.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyMarkerAnnotation.java 2007-03-14 20:51:49 UTC (rev 2175)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyMarkerAnnotation.java 2007-03-14 20:52:14 UTC (rev 2176)
@@ -14,8 +14,8 @@
import java.util.Iterator;
import org.eclipse.core.resources.IMarker;
-
import org.eclipse.ui.texteditor.MarkerAnnotation;
+import org.eclipse.ui.texteditor.MarkerUtilities;
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.IRubyModelMarker;
import org.rubypeople.rdt.core.IRubyScript;
@@ -131,4 +131,12 @@
}
return null;
}
+
+ public String getMarkerType() {
+ IMarker marker= getMarker();
+ if (marker == null || !marker.exists())
+ return null;
+
+ return MarkerUtilities.getMarkerType(getMarker());
+ }
}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/correction/CorrectionMessages.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/correction/CorrectionMessages.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/correction/CorrectionMessages.java 2007-03-14 20:52:14 UTC (rev 2176)
@@ -0,0 +1,15 @@
+package org.rubypeople.rdt.internal.ui.text.correction;
+
+import org.eclipse.osgi.util.NLS;
+
+public class CorrectionMessages extends NLS {
+
+ private static final String BUNDLE_NAME = CorrectionMessages.class.getName();
+
+ public static String RubyCorrectionProcessor_error_status;
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, CorrectionMessages.class);
+ }
+
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/correction/RubyCorrectionProcessor.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/correction/RubyCorrectionProcessor.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/correction/RubyCorrectionProcessor.java 2007-03-14 20:52:14 UTC (rev 2176)
@@ -0,0 +1,174 @@
+package org.rubypeople.rdt.internal.ui.text.correction;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.ISafeRunnable;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.ui.IMarkerHelpRegistry;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.texteditor.SimpleMarkerAnnotation;
+import org.rubypeople.rdt.core.IRubyScript;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.rubyeditor.IRubyAnnotation;
+import org.rubypeople.rdt.ui.RubyUI;
+import org.rubypeople.rdt.ui.text.ruby.IQuickFixProcessor;
+
+public class RubyCorrectionProcessor implements org.eclipse.jface.text.quickassist.IQuickAssistProcessor {
+
+ private static final String QUICKFIX_PROCESSOR_CONTRIBUTION_ID= "quickFixProcessors"; //$NON-NLS-1$
+
+ private static ContributedProcessorDescriptor[] fContributedCorrectionProcessors= null;
+
+ private String fErrorMessage;
+
+ public boolean canAssist(IQuickAssistInvocationContext invocationContext) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean canFix(Annotation annotation) {
+ return hasCorrections(annotation);
+ }
+
+ public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
+ // TODO Auto-generated method stub
+ return new ICompletionProposal[0];
+ }
+
+ public String getErrorMessage() {
+ return fErrorMessage;
+ }
+
+ public static boolean hasCorrections(Annotation annotation) {
+ if (annotation instanceof IRubyAnnotation) {
+ IRubyAnnotation rubyAnnotation= (IRubyAnnotation) annotation;
+ int problemId= rubyAnnotation.getId();
+ if (problemId != -1) {
+ IRubyScript cu= rubyAnnotation.getRubyScript();
+ if (cu != null) {
+ return hasCorrections(cu, problemId, rubyAnnotation.getMarkerType());
+ }
+ }
+ }
+ if (annotation instanceof SimpleMarkerAnnotation) {
+ return hasCorrections(((SimpleMarkerAnnotation) annotation).getMarker());
+ }
+ return false;
+ }
+
+ private static boolean hasCorrections(IMarker marker) {
+ if (marker == null || !marker.exists())
+ return false;
+
+ IMarkerHelpRegistry registry= IDE.getMarkerHelpRegistry();
+ return registry != null && registry.hasResolutions(marker);
+ }
+
+ public static boolean hasCorrections(IRubyScript cu, int problemId, String markerType) {
+ ContributedProcessorDescriptor[] processors= getCorrectionProcessors();
+ SafeHasCorrections collector= new SafeHasCorrections(cu, problemId);
+ for (int i= 0; i < processors.length; i++) {
+ if (processors[i].canHandleMarkerType(markerType)) {
+ collector.process(processors[i]);
+ if (collector.hasCorrections()) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private static ContributedProcessorDescriptor[] getCorrectionProcessors() {
+ if (fContributedCorrectionProcessors == null) {
+ fContributedCorrectionProcessors= getProcessorDescriptors(QUICKFIX_PROCESSOR_CONTRIBUTION_ID, true);
+ }
+ return fContributedCorrectionProcessors;
+ }
+
+ private static ContributedProcessorDescriptor[] getProcessorDescriptors(String contributionId, boolean testMarkerTypes) {
+ IConfigurationElement[] elements= Platform.getExtensionRegistry().getConfigurationElementsFor(RubyUI.ID_PLUGIN, contributionId);
+ ArrayList res= new ArrayList(elements.length);
+
+ for (int i= 0; i < elements.length; i++) {
+ ContributedProcessorDescriptor desc= new ContributedProcessorDescriptor(elements[i], testMarkerTypes);
+ IStatus status= desc.checkSyntax();
+ if (status.isOK()) {
+ res.add(desc);
+ } else {
+ RubyPlugin.log(status);
+ }
+ }
+ return (ContributedProcessorDescriptor[]) res.toArray(new ContributedProcessorDescriptor[res.size()]);
+ }
+
+ private static class SafeHasCorrections extends SafeCorrectionProcessorAccess {
+ private final IRubyScript fCu;
+ private final int fProblemId;
+ private boolean fHasCorrections;
+
+ public SafeHasCorrections(IRubyScript cu, int problemId) {
+ fCu= cu;
+ fProblemId= problemId;
+ fHasCorrections= false;
+ }
+
+ public boolean hasCorrections() {
+ return fHasCorrections;
+ }
+
+ public void safeRun(ContributedProcessorDescriptor desc) throws Exception {
+ IQuickFixProcessor processor= (IQuickFixProcessor) desc.getProcessor(fCu);
+ if (processor != null && processor.hasCorrections(fCu, fProblemId)) {
+ fHasCorrections= true;
+ }
+ }
+ }
+
+ private static abstract class SafeCorrectionProcessorAccess implements ISafeRunnable {
+ private MultiStatus fMulti= null;
+ private ContributedProcessorDescriptor fDescriptor;
+
+ public void process(ContributedProcessorDescriptor[] desc) {
+ for (int i= 0; i < desc.length; i++) {
+ fDescriptor= desc[i];
+ SafeRunner.run(this);
+ }
+ }
+
+ public void process(ContributedProcessorDescriptor desc) {
+ fDescriptor= desc;
+ SafeRunner.run(this);
+ }
+
+ public void run() throws Exception {
+ safeRun(fDescriptor);
+ }
+
+ protected abstract void safeRun(ContributedProcessorDescriptor processor) throws Exception;
+
+ public void handleException(Throwable exception) {
+ if (fMulti == null) {
+ fMulti= new MultiStatus(RubyUI.ID_PLUGIN, IStatus.OK, CorrectionMessages.RubyCorrectionProcessor_error_status, null);
+ }
+ fMulti.merge(new Status(IStatus.ERROR, RubyUI.ID_PLUGIN, IStatus.ERROR, CorrectionMessages.RubyCorrectionProcessor_error_status, exception));
+ }
+
+ public IStatus getStatus() {
+ if (fMulti == null) {
+ return Status.OK_STATUS;
+ }
+ return fMulti;
+ }
+
+ }
+
+}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyScriptCompletion.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyScriptCompletion.java 2007-03-14 20:51:49 UTC (rev 2175)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyScriptCompletion.java 2007-03-14 20:52:14 UTC (rev 2176)
@@ -15,7 +15,7 @@
import org.rubypeople.rdt.core.CompletionRequestor;
import org.rubypeople.rdt.core.IRubyProject;
import org.rubypeople.rdt.core.IRubyScript;
-import org.rubypeople.rdt.core.parser.IProblem;
+import org.rubypeople.rdt.core.compiler.IProblem;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.ui.text.ruby.IRubyCompletionProposal;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|