Class: Redcar::Groovy::SyntaxChecker
- Inherits:
-
SyntaxCheck::Checker
- Object
- SyntaxCheck::Checker
- Redcar::Groovy::SyntaxChecker
- Defined in:
- lib/groovy/syntax_checker.rb
Class Method Summary collapse
Instance Method Summary collapse
- #check(*args) ⇒ Object
- #classpath(project) ⇒ Object
- #classpath_files(project) ⇒ Object
- #create_shell ⇒ Object
- #create_syntax_error(doc, message, name) ⇒ Object
-
#initialize(document) ⇒ SyntaxChecker
constructor
A new instance of SyntaxChecker.
Constructor Details
#initialize(document) ⇒ SyntaxChecker
Returns a new instance of SyntaxChecker.
19 20 21 22 |
# File 'lib/groovy/syntax_checker.rb', line 19 def initialize(document) super SyntaxChecker.load_dependencies end |
Class Method Details
.load_dependencies ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/groovy/syntax_checker.rb', line 9 def self.load_dependencies unless @loaded Groovy.load_dependencies import 'groovy.lang.GroovyShell' import 'org.codehaus.groovy.control.CompilationFailedException' import 'org.codehaus.groovy.control.CompilerConfiguration' @loaded = true end end |
Instance Method Details
#check(*args) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/groovy/syntax_checker.rb', line 24 def check(*args) path = manifest_path(doc) name = File.basename(path) shell = create_shell text = doc.get_all_text io = java.io.File.new(path) begin shell.parse(io) rescue CompilationFailedException => e create_syntax_error(doc, e., name).annotate rescue Object => e Redcar::SyntaxCheck.( "An error occurred while parsing #{name}: #{e.}",:error) end end |
#classpath(project) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/groovy/syntax_checker.rb', line 51 def classpath(project) parts = [] shell = GroovyShell.new files = classpath_files(project) return unless files.any? files.each do |path| begin file = java.io.File.new(path) part = shell.run(file, []) parts += part if part rescue Object => e Redcar::SyntaxCheck.( "An error occurred while loading groovy classpath file #{path}: #{e.}",:error) end end parts end |
#classpath_files(project) ⇒ Object
47 48 49 |
# File 'lib/groovy/syntax_checker.rb', line 47 def classpath_files(project) project.config_files("classpath.groovy") end |
#create_shell ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/groovy/syntax_checker.rb', line 69 def create_shell config = CompilerConfiguration.new if project = Redcar::Project::Manager.focussed_project classpath = classpath(project) config.setClasspathList(classpath) if classpath and classpath.any? end shell = GroovyShell.new(config) shell.setProperty("out",nil) shell end |
#create_syntax_error(doc, message, name) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/groovy/syntax_checker.rb', line 40 def create_syntax_error(doc, , name) =~ /#{Regexp.escape(name)}: (\d+):(.*)/ line = $1.to_i - 1 = $2 Redcar::SyntaxCheck::Error.new(doc, line, ) end |