class JavaFeedbackHook::JavaExplainer

Public Instance Methods

explain_cannot_find_symbol(_, result) click to toggle source
# File lib/feedback_hook.rb, line 35
def explain_cannot_find_symbol(_, result)
  (/#{error} cannot find symbol#{near_regex}#{symbol_regex}#{location_regex}/.match result).try do |it|
    symbol = it[2].strip
    location = it[3].strip

    {near: it[1], symbol: localize_symbol(symbol), at_location: at_location(symbol, location) }
  end
end
explain_implemented_method_should_be_public(_, result) click to toggle source
# File lib/feedback_hook.rb, line 78
def explain_implemented_method_should_be_public(_, result)
 (/#{error} (.*) in (.*) cannot implement (.*) in (.*)#{near_regex}\n  attempting to assign weaker access privileges/.match result).try do |it|
   {method: it[1], class: it[2], near: it[5]}
 end
end
explain_incompatible_types(_, result) click to toggle source
# File lib/feedback_hook.rb, line 50
def explain_incompatible_types(_, result)
  (/#{error} incompatible types: (.*) cannot be converted to (.*)#{near_regex}/.match result).try do |it|
    actual = it[1]
    expected = it[2]
    near = it[3]

    { message: I18n.t(type_incompatibilty_kind(actual, expected), actual: actual, expected: expected, near: near) }
  end
end
explain_lossy_conversion(_, result) click to toggle source
# File lib/feedback_hook.rb, line 44
def explain_lossy_conversion(_, result)
  (/#{error} incompatible types: possible lossy conversion from (.*) to (.*)#{near_regex}/.match result).try do |it|
    { from: it[1], to: it[2], near: it[3] }
  end
end
explain_missing_bracket(_, result) click to toggle source
# File lib/feedback_hook.rb, line 19
def explain_missing_bracket(_, result)
  missing_character result, '\{'
end
explain_missing_implementation(_, result) click to toggle source
# File lib/feedback_hook.rb, line 84
def explain_missing_implementation(_, result)
  (/#{error} (.*) is not abstract and does not override abstract method (.*) in (.*)#{near_regex}/.match result).try do |it|
    {down: it[1], method: it[2], up: it[3] }
  end
end
explain_missing_parameter_type(_, result) click to toggle source
# File lib/feedback_hook.rb, line 23
def explain_missing_parameter_type(_, result)
  (/#{error} <identifier> expected#{near_regex}/.match result).try do |it|
    {near: it[1]}
  end
end
explain_missing_parenthesis(_, result) click to toggle source
# File lib/feedback_hook.rb, line 15
def explain_missing_parenthesis(_, result)
  missing_character result, '\('
end
explain_missing_return_statement(_, result) click to toggle source
# File lib/feedback_hook.rb, line 29
def explain_missing_return_statement(_, result)
  (/#{error} missing return statement#{near_regex}/.match result).try do |it|
    {near: it[1]}
  end
end
explain_missing_return_type(_, result) click to toggle source
# File lib/feedback_hook.rb, line 90
def explain_missing_return_type(_, result)
  (/#{error} invalid method declaration; return type required#{near_regex}/.match result).try do |it|
    { near: it[1] }
  end
end
explain_missing_semicolon(_, result) click to toggle source
# File lib/feedback_hook.rb, line 11
def explain_missing_semicolon(_, result)
  missing_character result, ';'
end
explain_unexpected_close_curly(_, result) click to toggle source
# File lib/feedback_hook.rb, line 66
def explain_unexpected_close_curly(_, result)
  (/\(line (.*), .*\):\nunexpected CloseCurly/.match result).try do |it|
    {line: it[1]}
  end
end
explain_unexpected_close_paren(_, result) click to toggle source
# File lib/feedback_hook.rb, line 72
def explain_unexpected_close_paren(_, result)
  (/\(line (.*), .*\):\nunexpected CloseParen/.match result).try do |it|
    {line: it[1]}
  end
end
explain_wrong_constructor_arguments(_, result) click to toggle source
# File lib/feedback_hook.rb, line 60
def explain_wrong_constructor_arguments(_, result)
  (/#{error} constructor (.*) in class (.*) cannot be applied to given types;#{near_regex}/.match result).try do |it|
    { class: it[2] }
  end
end

Private Instance Methods

at_location(symbol, location) click to toggle source
# File lib/feedback_hook.rb, line 132
def at_location(symbol, location)
  symbol_type, _ = parse_symbol symbol
  return '' if symbol_type == 'class'

  ' ' + I18n.t(:at_location, {
    location: localize_symbol(location)
  })
end
error() click to toggle source
# File lib/feedback_hook.rb, line 122
def error
  '[eE]rror:'
end
localize_of_type(type) click to toggle source
# File lib/feedback_hook.rb, line 149
def localize_of_type(type)
  return '' if type.nil?

  ' ' + I18n.t(:of_type, type: type)
end
localize_symbol(symbol) click to toggle source
# File lib/feedback_hook.rb, line 141
def localize_symbol(symbol)
  symbol_type, name, type = parse_symbol symbol
  i18n_key = "symbol_#{symbol_type}"
  return "`#{symbol}`" unless I18n.exists? i18n_key

  I18n.t(i18n_key, { name: name }) + localize_of_type(type)
end
location_regex() click to toggle source
# File lib/feedback_hook.rb, line 110
def location_regex
  start_regex 'location:'
end
missing_character(result, character) click to toggle source
# File lib/feedback_hook.rb, line 126
def missing_character(result, character)
  (/#{error} '#{character}' expected#{near_regex}/.match result).try do |it|
    {near: it[1]}
  end
end
near_regex() click to toggle source
# File lib/feedback_hook.rb, line 102
def near_regex
  /#{start_regex}\n[ \t]+\^/
end
parse_symbol(result) click to toggle source
# File lib/feedback_hook.rb, line 155
def parse_symbol(result)
  parts = /^(\w+) ([\w\(\)]+)( of type (\w+))?/.match result
  return ['', '', ''] if parts.nil?

  [parts[1], parts[2], parts[4]]
end
primitive_types() click to toggle source
# File lib/feedback_hook.rb, line 118
def primitive_types
  ['byte', 'short', 'int', 'long', 'float', 'double', 'boolean', 'char']
end
start_regex(symbol=' ') click to toggle source
# File lib/feedback_hook.rb, line 98
def start_regex(symbol=' ')
  /.*[\t \n]*#{symbol}*(.*)/
end
symbol_regex() click to toggle source
# File lib/feedback_hook.rb, line 106
def symbol_regex
  start_regex 'symbol:'
end
type_incompatibilty_kind(a_type, another) click to toggle source
# File lib/feedback_hook.rb, line 114
def type_incompatibilty_kind(a_type, another)
  [a_type, another].any? { |it| primitive_types.include?(it) } ? :incompatible_types_primitives : :incompatible_types_classes
end