|
From: <caw...@us...> - 2007-03-23 15:01:40
|
Revision: 2215
http://svn.sourceforge.net/rubyeclipse/?rev=2215&view=rev
Author: cawilliams
Date: 2007-03-23 08:01:37 -0700 (Fri, 23 Mar 2007)
Log Message:
-----------
avoid classcastexception. domore work towards moving to a compilationParticipant model
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScriptProblemFinder.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/RubyCodeAnalyzer.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/RdtWarnings.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/TaskParser.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/warnings/ConstantReassignmentVisitor.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/warnings/DelegatingVisitor.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/warnings/EmptyStatementVisitor.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/warnings/RubyLintVisitor.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/warnings/StaticConditionalVisitor.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScriptProblemFinder.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScriptProblemFinder.java 2007-03-23 12:55:08 UTC (rev 2214)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScriptProblemFinder.java 2007-03-23 15:01:37 UTC (rev 2215)
@@ -4,20 +4,23 @@
package org.rubypeople.rdt.internal.core;
import java.io.StringReader;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.jruby.ast.Node;
-import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.SyntaxException;
-import org.rubypeople.rdt.core.IProblemRequestor;
import org.rubypeople.rdt.core.IRubyModelMarker;
+import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.core.compiler.CategorizedProblem;
import org.rubypeople.rdt.internal.core.parser.RdtWarnings;
import org.rubypeople.rdt.internal.core.parser.RubyParser;
import org.rubypeople.rdt.internal.core.parser.TaskParser;
+import org.rubypeople.rdt.internal.core.parser.TaskTag;
+import org.rubypeople.rdt.internal.core.parser.Warning;
import org.rubypeople.rdt.internal.core.parser.warnings.DelegatingVisitor;
import org.rubypeople.rdt.internal.core.parser.warnings.RubyLintVisitor;
@@ -33,28 +36,30 @@
RubyParser parser = new RubyParser(warnings);
String contents = new String(charContents);
-// runLint(script, problemRequestor, parser, contents); FIXME Make all these compilationParticipants
+ List<CategorizedProblem> generatedProblems = runLint(script, parser, contents); // FIXME Make all these compilationParticipants
TaskParser taskParser = new TaskParser(script.getRubyProject().getOptions(true));
taskParser.parse(contents);
-
- problems.put(IRubyModelMarker.RUBY_MODEL_PROBLEM_MARKER, warnings.getWarnings());
- problems.put(IRubyModelMarker.TASK_MARKER, taskParser.getTasks());
+ generatedProblems.addAll(warnings.getWarnings());
+ List<TaskTag> tasks = taskParser.getTasks();
+ problems.put(IRubyModelMarker.RUBY_MODEL_PROBLEM_MARKER, generatedProblems.toArray(new CategorizedProblem[generatedProblems.size()]));
+ problems.put(IRubyModelMarker.TASK_MARKER, tasks.toArray(new CategorizedProblem[tasks.size()]));
}
- private static void runLint(RubyScript script, IProblemRequestor problemRequestor, RubyParser parser, String contents) {
+ private static List<CategorizedProblem> runLint(RubyScript script, RubyParser parser, String contents) {
try {
Node node = parser.parse((IFile) script.getUnderlyingResource(), new StringReader(contents));
- if (node == null) return;
- List<RubyLintVisitor> visitors = DelegatingVisitor.createVisitors(contents, problemRequestor);
- NodeVisitor visitor = new DelegatingVisitor(visitors);
+ if (node == null) return new ArrayList<CategorizedProblem>();
+ List<RubyLintVisitor> visitors = DelegatingVisitor.createVisitors(contents);
+ DelegatingVisitor visitor = new DelegatingVisitor(visitors);
node.accept(visitor);
+ return visitor.getProblems();
} catch (SyntaxException e) {
// Eat the exception
// problemRequestor.acceptProblem(new Error(e.getPosition(), e.getMessage()));
} catch (RubyModelException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ RubyCore.log(e);
}
+ return new ArrayList<CategorizedProblem>();
}
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/RubyCodeAnalyzer.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/RubyCodeAnalyzer.java 2007-03-23 12:55:08 UTC (rev 2214)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/RubyCodeAnalyzer.java 2007-03-23 15:01:37 UTC (rev 2215)
@@ -58,7 +58,7 @@
try {
Node rootNode = parser.parse(file, new StringReader(contents));
if (rootNode == null) return;
- List<RubyLintVisitor> visitors = DelegatingVisitor.createVisitors(contents, new ProblemRequestorMarkerManager(file, markerManager));
+ List<RubyLintVisitor> visitors = DelegatingVisitor.createVisitors(contents); // FIXME How do we hook the warnings/errors up now?!
NodeVisitor visitor = new DelegatingVisitor(visitors);
rootNode.accept(visitor);
indexUpdater.update(file, rootNode, true);
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/RdtWarnings.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/RdtWarnings.java 2007-03-23 12:55:08 UTC (rev 2214)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/RdtWarnings.java 2007-03-23 15:01:37 UTC (rev 2215)
@@ -15,13 +15,13 @@
*/
public class RdtWarnings implements IRdtWarnings {
- private List warnings;
+ private List<Warning> warnings;
public RdtWarnings() {
- warnings = new ArrayList();
+ warnings = new ArrayList<Warning>();
}
- public List getWarnings() {
+ public List<Warning> getWarnings() {
return Collections.unmodifiableList(warnings);
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/TaskParser.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/TaskParser.java 2007-03-23 12:55:08 UTC (rev 2214)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/TaskParser.java 2007-03-23 15:01:37 UTC (rev 2215)
@@ -25,7 +25,7 @@
private boolean fCaseSensitive = false;
private String[] fTags;
private int[] fPriorities;
- private List tasks;
+ private List<TaskTag> tasks;
public TaskParser(Map preferences) {
String caseSensitive = getString(preferences, RubyCore.COMPILER_TASK_CASE_SENSITIVE, RubyCore.ENABLED);
@@ -34,7 +34,7 @@
String priorities = getString(preferences, RubyCore.COMPILER_TASK_PRIORITIES, RubyCore.DEFAULT_TASK_PRIORITIES);
fTags = tokenize(tags, ",");
fPriorities = convertPriorities(tokenize(priorities, ","));
- tasks = new ArrayList();
+ tasks = new ArrayList<TaskTag>();
}
private String getString(Map preferences, String key, String def) {
@@ -140,7 +140,7 @@
}
}
- public List getTasks() {
+ public List<TaskTag> getTasks() {
return Collections.unmodifiableList(tasks);
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/warnings/ConstantReassignmentVisitor.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/warnings/ConstantReassignmentVisitor.java 2007-03-23 12:55:08 UTC (rev 2214)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/warnings/ConstantReassignmentVisitor.java 2007-03-23 15:01:37 UTC (rev 2215)
@@ -5,14 +5,13 @@
import org.jruby.ast.ConstDeclNode;
import org.jruby.evaluator.Instruction;
-import org.rubypeople.rdt.core.IProblemRequestor;
public class ConstantReassignmentVisitor extends RubyLintVisitor {
private Set<String> assignedConstants;
- public ConstantReassignmentVisitor(String contents, IProblemRequestor problemRequestor) {
- super(contents, problemRequestor);
+ public ConstantReassignmentVisitor(String contents) {
+ super(contents);
assignedConstants = new HashSet<String>();
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/warnings/DelegatingVisitor.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/warnings/DelegatingVisitor.java 2007-03-23 12:55:08 UTC (rev 2214)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/warnings/DelegatingVisitor.java 2007-03-23 15:01:37 UTC (rev 2215)
@@ -1,6 +1,7 @@
package org.rubypeople.rdt.internal.core.parser.warnings;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import org.jruby.ast.AliasNode;
@@ -99,6 +100,7 @@
import org.jruby.ast.ZSuperNode;
import org.jruby.evaluator.Instruction;
import org.rubypeople.rdt.core.IProblemRequestor;
+import org.rubypeople.rdt.core.compiler.CategorizedProblem;
import org.rubypeople.rdt.internal.core.parser.InOrderVisitor;
/**
@@ -117,15 +119,23 @@
private List<RubyLintVisitor> visitors;
- public static List<RubyLintVisitor> createVisitors(String contents, IProblemRequestor requestor) {
+ public static List<RubyLintVisitor> createVisitors(String contents) {
List<RubyLintVisitor> visitors = new ArrayList<RubyLintVisitor>();
// FIXME Run through a map of keys to classes and add instances of
// classes whose key is not set to ignore
- visitors.add(new EmptyStatementVisitor(contents, requestor));
- visitors.add(new StaticConditionalVisitor(contents, requestor));
- visitors.add(new ConstantReassignmentVisitor(contents, requestor));
+ visitors.add(new EmptyStatementVisitor(contents));
+ visitors.add(new StaticConditionalVisitor(contents));
+ visitors.add(new ConstantReassignmentVisitor(contents));
return visitors;
}
+
+ public List<CategorizedProblem> getProblems() {
+ List<CategorizedProblem> problems = new ArrayList<CategorizedProblem>();
+ for (RubyLintVisitor visitor : visitors) {
+ problems.addAll(visitor.getProblems());
+ }
+ return problems;
+ }
public DelegatingVisitor(List<RubyLintVisitor> visitors) {
this.visitors = visitors;
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/warnings/EmptyStatementVisitor.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/warnings/EmptyStatementVisitor.java 2007-03-23 12:55:08 UTC (rev 2214)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/warnings/EmptyStatementVisitor.java 2007-03-23 15:01:37 UTC (rev 2215)
@@ -6,13 +6,12 @@
import org.jruby.ast.IterNode;
import org.jruby.ast.WhenNode;
import org.jruby.evaluator.Instruction;
-import org.rubypeople.rdt.core.IProblemRequestor;
import org.rubypeople.rdt.core.RubyCore;
public class EmptyStatementVisitor extends RubyLintVisitor {
- public EmptyStatementVisitor(String contents, IProblemRequestor problemRequestor) {
- super(contents, problemRequestor);
+ public EmptyStatementVisitor(String contents) {
+ super(contents);
}
@Override
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/warnings/RubyLintVisitor.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/warnings/RubyLintVisitor.java 2007-03-23 12:55:08 UTC (rev 2214)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/warnings/RubyLintVisitor.java 2007-03-23 15:01:37 UTC (rev 2215)
@@ -1,5 +1,8 @@
package org.rubypeople.rdt.internal.core.parser.warnings;
+import java.util.ArrayList;
+import java.util.List;
+
import org.jruby.ast.BlockNode;
import org.jruby.ast.ClassNode;
import org.jruby.ast.DefnNode;
@@ -12,8 +15,8 @@
import org.jruby.ast.visitor.AbstractVisitor;
import org.jruby.evaluator.Instruction;
import org.jruby.lexer.yacc.ISourcePosition;
-import org.rubypeople.rdt.core.IProblemRequestor;
import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.core.compiler.CategorizedProblem;
import org.rubypeople.rdt.core.compiler.IProblem;
import org.rubypeople.rdt.internal.core.parser.Error;
import org.rubypeople.rdt.internal.core.parser.NodeUtil;
@@ -21,28 +24,32 @@
public abstract class RubyLintVisitor extends AbstractVisitor {
- private IProblemRequestor problemRequestor;
private String contents;
+ private List<CategorizedProblem> problems;
- public RubyLintVisitor(String contents, IProblemRequestor problemRequestor) {
- this.problemRequestor = problemRequestor;
+ public RubyLintVisitor(String contents) {
+ this.problems = new ArrayList<CategorizedProblem>();
this.contents = contents;
}
protected String getSource(Node node) {
return NodeUtil.getSource(contents, node);
}
+
+ public List<CategorizedProblem> getProblems() {
+ return problems;
+ }
protected void createProblem(ISourcePosition position, String message) {
String value = RubyCore.getOption(getOptionKey());
if (value != null && value.equals(RubyCore.IGNORE))
return;
- IProblem problem;
+ CategorizedProblem problem;
if (value != null && value.equals(RubyCore.ERROR))
problem = new Error(position, message, getProblemID());
else
problem = new Warning(position, message, getProblemID());
- problemRequestor.acceptProblem(problem);
+ problems.add(problem);
}
@Override
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/warnings/StaticConditionalVisitor.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/warnings/StaticConditionalVisitor.java 2007-03-23 12:55:08 UTC (rev 2214)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/warnings/StaticConditionalVisitor.java 2007-03-23 15:01:37 UTC (rev 2215)
@@ -6,12 +6,11 @@
import org.jruby.ast.Node;
import org.jruby.ast.TrueNode;
import org.jruby.evaluator.Instruction;
-import org.rubypeople.rdt.core.IProblemRequestor;
public class StaticConditionalVisitor extends RubyLintVisitor {
- public StaticConditionalVisitor(String contents, IProblemRequestor problemRequestor) {
- super(contents, problemRequestor);
+ public StaticConditionalVisitor(String contents) {
+ super(contents);
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|