|
From: <caw...@us...> - 2007-08-21 19:23:39
|
Revision: 3034
http://rubyeclipse.svn.sourceforge.net/rubyeclipse/?rev=3034&view=rev
Author: cawilliams
Date: 2007-08-21 12:23:38 -0700 (Tue, 21 Aug 2007)
Log Message:
-----------
fix #5630 - Add quick fix for Enumerable inclusion missing "each" method definition
Modified Paths:
--------------
trunk/com.aptana.rdt.ui/src/com/aptana/rdt/internal/ui/text/correction/QuickFixProcessor.java
Modified: trunk/com.aptana.rdt.ui/src/com/aptana/rdt/internal/ui/text/correction/QuickFixProcessor.java
===================================================================
--- trunk/com.aptana.rdt.ui/src/com/aptana/rdt/internal/ui/text/correction/QuickFixProcessor.java 2007-08-21 19:22:31 UTC (rev 3033)
+++ trunk/com.aptana.rdt.ui/src/com/aptana/rdt/internal/ui/text/correction/QuickFixProcessor.java 2007-08-21 19:23:38 UTC (rev 3034)
@@ -6,17 +6,13 @@
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
-import org.jruby.ast.BlockNode;
import org.jruby.ast.ClassNode;
-import org.jruby.ast.CommentNode;
import org.jruby.ast.DefnNode;
-import org.jruby.ast.InstAsgnNode;
import org.jruby.ast.ModuleNode;
import org.jruby.ast.Node;
import org.jruby.ast.visitor.rewriter.DefaultFormatHelper;
import org.jruby.ast.visitor.rewriter.FormatHelper;
import org.jruby.ast.visitor.rewriter.ReWriteVisitor;
-import org.jruby.lexer.yacc.IDESourcePosition;
import org.rubypeople.rdt.core.IRubyScript;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.core.formatter.Indents;
@@ -35,6 +31,8 @@
public class QuickFixProcessor implements IQuickFixProcessor {
+ private static final String NEWLINE = "\n";
+
public IRubyCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations) throws CoreException {
if (locations == null || locations.length == 0) {
return null;
@@ -51,6 +49,20 @@
}
return (IRubyCompletionProposal[]) resultingCollections.toArray(new IRubyCompletionProposal[resultingCollections.size()]);
}
+
+ public boolean hasCorrections(IRubyScript unit, int problemId) {
+ switch (problemId) {
+ case IProblem.MisspelledConstructor:
+ case IProblem.ConstantNamingConvention:
+ case IProblem.MethodMissingWithoutRespondTo:
+ case IProblem.LocalAndMethodNamingConvention:
+ case IProblem.ComparableInclusionMissingCompareMethod:
+ case IProblem.EnumerableInclusionMissingEachMethod:
+ return true;
+ default:
+ return false;
+ }
+ }
private void process(IInvocationContext context, IProblemLocation problem, Collection<IRubyCompletionProposal> proposals) throws CoreException {
int id = problem.getProblemId();
@@ -82,6 +94,11 @@
text = insertedMethodText(context, offset, "<=>", new String[] {"other"});
LocalCorrectionsSubProcessor.addReplacementProposal(offset, 0, text, "Add <=> method stub", proposals);
break;
+ case IProblem.EnumerableInclusionMissingEachMethod:
+ offset = getOffsetOfFirstLineInsideType(context, problem);
+ text = insertedMethodText(context, offset, "each", new String[] {});
+ LocalCorrectionsSubProcessor.addReplacementProposal(offset, 0, text, "Add each method stub", proposals);
+ break;
default:
}
}
@@ -100,23 +117,23 @@
String text = ReWriteVisitor.createCodeFromNode(insert, src, getFormatHelper());
StringBuffer buffer = new StringBuffer(text);
- int index = text.indexOf("\n", 1);
+ int index = text.indexOf(NEWLINE, 1);
buffer.insert(index + 1, " # TODO Auto-generated method stub\n");
// Figure out indent at offset and apply that to each line of text and at end of text
String indent = findIndent(offset, script, src);
buffer.insert(0, indent);
- buffer.append("\n");
+ buffer.append(NEWLINE);
text = buffer.toString();
- text = text.replaceAll("\\n", "\n" + indent);
+ text = text.replaceAll("\\n", NEWLINE + indent);
return text;
}
private String findIndent(int offset, IRubyScript script, String src) {
if (src == null || src.length() == 0) return "";
- int index = src.indexOf("\n", offset);
+ int index = src.indexOf(NEWLINE, offset);
if (index < 1 || index > src.length()) return "";
String line = src.substring(0, index);
- index = line.lastIndexOf("\n");
+ index = line.lastIndexOf(NEWLINE);
Map options = script.getRubyProject().getOptions(true);
if (index == -1 || ((index + 1) >= line.length()) ) return Indents.extractIndentString(line, options);
line = line.substring(index + 1);
@@ -153,17 +170,4 @@
protected FormatHelper getFormatHelper() {
return new DefaultFormatHelper();
}
-
- public boolean hasCorrections(IRubyScript unit, int problemId) {
- switch (problemId) {
- case IProblem.MisspelledConstructor:
- case IProblem.ConstantNamingConvention:
- case IProblem.MethodMissingWithoutRespondTo:
- case IProblem.LocalAndMethodNamingConvention:
- case IProblem.ComparableInclusionMissingCompareMethod:
- return true;
- default:
- return false;
- }
- }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|