|
From: <caw...@us...> - 2007-08-21 18:08:35
|
Revision: 3022
http://rubyeclipse.svn.sourceforge.net/rubyeclipse/?rev=3022&view=rev
Author: cawilliams
Date: 2007-08-21 11:08:33 -0700 (Tue, 21 Aug 2007)
Log Message:
-----------
move quick fixes for problems defined in RDT core into RDT UI. Keep com.aptana.rdt.ui to only do quick fixes for com.aptana.rdt
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/plugin.xml
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/correction/CorrectionProposal.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/correction/QuickFixProcessor.java
Modified: trunk/org.rubypeople.rdt.ui/plugin.xml
===================================================================
--- trunk/org.rubypeople.rdt.ui/plugin.xml 2007-08-21 18:03:57 UTC (rev 3021)
+++ trunk/org.rubypeople.rdt.ui/plugin.xml 2007-08-21 18:08:33 UTC (rev 3022)
@@ -1498,4 +1498,11 @@
<startup class="org.rubypeople.rdt.internal.ui.ForceIndexer"/>
<startup class="org.rubypeople.rdt.internal.ui.RubyInstalledDetector"/>
</extension>
+ <extension
+ point="org.rubypeople.rdt.ui.quickFixProcessors">
+ <quickFixProcessor
+ class="org.rubypeople.rdt.internal.ui.text.correction.QuickFixProcessor"
+ id="org.rubypeople.rdt.ui.quickFixProcessor"
+ name="Default Quick Fix Processor"/>
+ </extension>
</plugin>
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/correction/CorrectionProposal.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/correction/CorrectionProposal.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/correction/CorrectionProposal.java 2007-08-21 18:08:33 UTC (rev 3022)
@@ -0,0 +1,25 @@
+package org.rubypeople.rdt.internal.ui.text.correction;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.swt.graphics.Image;
+import org.rubypeople.rdt.internal.ui.text.ruby.RubyCompletionProposal;
+
+public class CorrectionProposal extends RubyCompletionProposal {
+
+ public CorrectionProposal(String replacementString, int replacementOffset, int replacementLength, Image image, String displayString, int relevance) {
+ super(replacementString, replacementOffset, replacementLength, image, displayString, relevance);
+ }
+
+ @Override
+ protected boolean isValidPrefix(String prefix) {
+ return true;
+ }
+
+ @Override
+ public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
+ IDocument document= viewer.getDocument();
+ apply(document, trigger, getReplacementOffset());
+ }
+
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/correction/CorrectionProposal.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/correction/QuickFixProcessor.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/correction/QuickFixProcessor.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/correction/QuickFixProcessor.java 2007-08-21 18:08:33 UTC (rev 3022)
@@ -0,0 +1,76 @@
+package org.rubypeople.rdt.internal.ui.text.correction;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.ISharedImages;
+import org.jruby.ast.visitor.rewriter.DefaultFormatHelper;
+import org.jruby.ast.visitor.rewriter.FormatHelper;
+import org.rubypeople.rdt.core.IRubyScript;
+import org.rubypeople.rdt.core.compiler.IProblem;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.ui.text.ruby.IInvocationContext;
+import org.rubypeople.rdt.ui.text.ruby.IProblemLocation;
+import org.rubypeople.rdt.ui.text.ruby.IQuickFixProcessor;
+import org.rubypeople.rdt.ui.text.ruby.IRubyCompletionProposal;
+
+public class QuickFixProcessor implements IQuickFixProcessor {
+
+ public IRubyCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations) throws CoreException {
+ if (locations == null || locations.length == 0) {
+ return null;
+ }
+
+ HashSet<Integer> handledProblems = new HashSet<Integer>(locations.length);
+ ArrayList<IRubyCompletionProposal> resultingCollections = new ArrayList<IRubyCompletionProposal>();
+ for (int i = 0; i < locations.length; i++) {
+ IProblemLocation curr = locations[i];
+ Integer id = new Integer(curr.getProblemId());
+ if (handledProblems.add(id)) {
+ process(context, curr, resultingCollections);
+ }
+ }
+ return (IRubyCompletionProposal[]) resultingCollections.toArray(new IRubyCompletionProposal[resultingCollections.size()]);
+ }
+
+ private void process(IInvocationContext context, IProblemLocation problem, Collection<IRubyCompletionProposal> proposals) throws CoreException {
+ int id = problem.getProblemId();
+ if (id == 0) { // no proposals for none-problem locations
+ return;
+ }
+ switch (id) {
+ case IProblem.UnusedPrivateMethod:
+ case IProblem.UnusedPrivateField:
+ case IProblem.LocalVariableIsNeverUsed:
+ case IProblem.ArgumentIsNeverUsed:
+ addUnusedMemberProposal(context, problem, proposals);
+ break;
+ default:
+ }
+ }
+
+ protected FormatHelper getFormatHelper() {
+ return new DefaultFormatHelper();
+ }
+
+ public boolean hasCorrections(IRubyScript unit, int problemId) {
+ switch (problemId) {
+ case IProblem.UnusedPrivateMethod:
+ case IProblem.UnusedPrivateField:
+ case IProblem.LocalVariableIsNeverUsed:
+ case IProblem.ArgumentIsNeverUsed:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ public static void addUnusedMemberProposal(IInvocationContext context, IProblemLocation problem, Collection<IRubyCompletionProposal> proposals) {
+ Image image= RubyPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE);
+ CorrectionProposal proposal = new CorrectionProposal("", problem.getOffset(), problem.getLength(), image, "clean up unused code", 100);
+ proposals.add(proposal);
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/correction/QuickFixProcessor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|