|
From: <caw...@us...> - 2006-08-19 23:56:23
|
Revision: 1572 Author: cawilliams Date: 2006-08-19 16:56:16 -0700 (Sat, 19 Aug 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1572&view=rev Log Message: ----------- Modified Paths: -------------- 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/DefaultProblem.java trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/RubyLintVisitor.java 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 2006-08-19 23:28:28 UTC (rev 1571) +++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/RubyCodeAnalyzer.java 2006-08-19 23:56:16 UTC (rev 1572) @@ -16,6 +16,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; +import java.io.StringReader; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; @@ -48,7 +49,7 @@ String contents = readContents(reader); markerManager.removeProblemsAndTasksFor(file); try { - Node rootNode = parser.parse(file, reader); + Node rootNode = parser.parse(file, new StringReader(contents)); RubyLintVisitor visitor = new RubyLintVisitor(contents, new ProblemRequestorMarkerManager(file, markerManager)); rootNode.accept(visitor); indexUpdater.update(file, rootNode, true); Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/DefaultProblem.java =================================================================== --- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/DefaultProblem.java 2006-08-19 23:28:28 UTC (rev 1571) +++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/DefaultProblem.java 2006-08-19 23:56:16 UTC (rev 1572) @@ -45,4 +45,8 @@ public int getSourceStart() { return position.getStartOffset(); } + + public String toString() { + return position.toString() + " => " + message; + } } Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/RubyLintVisitor.java =================================================================== --- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/RubyLintVisitor.java 2006-08-19 23:28:28 UTC (rev 1571) +++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/RubyLintVisitor.java 2006-08-19 23:56:16 UTC (rev 1572) @@ -1,77 +1,44 @@ package org.rubypeople.rdt.internal.core.parser; -import java.io.Reader; - import java.util.HashSet; - import java.util.Set; - import org.jruby.ast.BlockNode; - import org.jruby.ast.CallNode; - import org.jruby.ast.ConstDeclNode; - import org.jruby.ast.DefnNode; - import org.jruby.ast.DefsNode; - import org.jruby.ast.FCallNode; - import org.jruby.ast.FalseNode; - import org.jruby.ast.IfNode; - import org.jruby.ast.IterNode; - import org.jruby.ast.NilNode; - import org.jruby.ast.Node; - import org.jruby.ast.ScopeNode; - import org.jruby.ast.TrueNode; - import org.jruby.ast.WhenNode; - 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.parser.IProblem; public class RubyLintVisitor extends InOrderVisitor { private IProblemRequestor problemRequestor; - private Set assignedConstants; - private Set methodsCalled; - private String contents; public RubyLintVisitor(String contents, IProblemRequestor problemRequestor) { - this.problemRequestor = problemRequestor; - assignedConstants = new HashSet(); - methodsCalled = new HashSet(); - this.contents = contents; - } public Instruction visitFCallNode(FCallNode iVisited) { - methodsCalled.add(iVisited.getName()); - return super.visitFCallNode(iVisited); - } public Instruction visitCallNode(CallNode iVisited) { @@ -99,143 +66,76 @@ } public Instruction visitWhenNode(WhenNode iVisited) { - if (iVisited.getBodyNode() == null) { - - IProblem problem = createProblem( - - RubyCore.COMPILER_PB_EMPTY_STATEMENT, iVisited - - .getPosition(), "Empty When Body"); - + IProblem problem = createProblem(RubyCore.COMPILER_PB_EMPTY_STATEMENT, iVisited.getPosition(), "Empty When Body"); if (problem != null) problemRequestor.acceptProblem(problem); - } - return super.visitWhenNode(iVisited); - } public Instruction visitBlockNode(BlockNode iVisited) { - return super.visitBlockNode(iVisited); - } public Instruction visitIterNode(IterNode iVisited) { - if (iVisited.getBodyNode() == null) { + IProblem problem = createProblem(RubyCore.COMPILER_PB_EMPTY_STATEMENT, iVisited.getPosition(), "Empty Block"); - IProblem problem = createProblem( - - RubyCore.COMPILER_PB_EMPTY_STATEMENT, iVisited - - .getPosition(), "Empty Block"); - if (problem != null) problemRequestor.acceptProblem(problem); - } - return super.visitIterNode(iVisited); - } public Instruction visitDefnNode(DefnNode iVisited) { - // TODO Analyze method visibility. Create warning for uncalled private - // methods - ScopeNode scope = iVisited.getBodyNode(); - if (scope.getBodyNode() == null) { - - IProblem problem = createProblem( - - RubyCore.COMPILER_PB_EMPTY_STATEMENT, iVisited - - .getPosition(), "Empty Method Definition"); - + IProblem problem = createProblem(RubyCore.COMPILER_PB_EMPTY_STATEMENT, iVisited.getPosition(), "Empty Method Definition"); if (problem != null) problemRequestor.acceptProblem(problem); - } - return super.visitDefnNode(iVisited); - } public Instruction visitDefsNode(DefsNode iVisited) { - ScopeNode scope = iVisited.getBodyNode(); - if (scope.getBodyNode() == null) { + IProblem problem = createProblem(RubyCore.COMPILER_PB_EMPTY_STATEMENT, iVisited.getPosition(), "Empty Method Definition"); - IProblem problem = createProblem( - - RubyCore.COMPILER_PB_EMPTY_STATEMENT, iVisited - - .getPosition(), "Empty Method Definition"); - if (problem != null) problemRequestor.acceptProblem(problem); - } - return super.visitDefsNode(iVisited); - } protected Instruction handleNode(Node visited) { - // System.out.println(visited.toString() + ", position -> " - // + visited.getPosition()); - return super.handleNode(visited); - } public Instruction visitConstDeclNode(ConstDeclNode iVisited) { - String name = iVisited.getName(); if (assignedConstants.contains(name)) { - - problemRequestor.acceptProblem(new Warning(iVisited.getPosition(), - - "Reassignment of a constant")); - + problemRequestor.acceptProblem(new Warning(iVisited.getPosition(), "Reassignment of a constant")); } else - assignedConstants.add(name); - return super.visitConstDeclNode(iVisited); - } - private IProblem createProblem(String compilerOption, - - ISourcePosition position, String message) { - + private IProblem createProblem(String compilerOption, ISourcePosition position, String message) { String value = RubyCore.getOption(compilerOption); - if (value == null) - return new Error(position, message); - if (value.equals(RubyCore.WARNING)) - return new Warning(position, message); - if (value.equals(RubyCore.ERROR)) - return new Error(position, message); - return null; - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |