Class: ASAutotest::Problem

Inherits:
Object
  • Object
show all
Defined in:
lib/asautotest/problematic-file.rb

Defined Under Namespace

Classes: BogusOverride, ConstantAssignment, ImplementationProblem, InaccessibleProperty, InterfaceNotFound, InvalidNullComparison, MissingImplementation, MissingPublicDefinition, MissingReturnType, MissingTypeDeclaration, TooFewArguments, TooManyArguments, TypeMismatch, UndefinedImport, UndefinedMethod, UndefinedProperty, UndefinedType, Unknown, WrongClassName, WrongImplementation, WrongPackage

Constant Summary collapse

MESSAGE_COLUMN_WIDTH =
56
LINE_NUMBER_COLUMN_WIDTH =
4

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fileObject

Returns the value of attribute file.



162
163
164
# File 'lib/asautotest/problematic-file.rb', line 162

def file
  @file
end

#locationObject

Returns the value of attribute location.



161
162
163
# File 'lib/asautotest/problematic-file.rb', line 161

def location
  @location
end

Class Method Details

.[](message, location) ⇒ Object



193
194
195
196
197
# File 'lib/asautotest/problematic-file.rb', line 193

def self.[] message, location
  returning parse(message) do |problem|
    problem.location = location
  end
end

.parse(message) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/asautotest/problematic-file.rb', line 199

def self.parse(message)
  case message.sub(/^(Error|Warning):\s+/, "")
  when /^Definition (\S+) could not be found.$/i
    UndefinedImport.new(Type.parse($1))
  when /^Call to a possibly undefined method (\S+) .* type (\S+).$/i
    UndefinedMethod.new(Member[Type.parse($2), $1])
  when /^Call to a possibly undefined method (\S+).$/i
    UndefinedMethod.new(Member[nil, $1])
  when /^Access of undefined property (\S+).$/i
    UndefinedProperty.new(Member[nil, $1])
  when /^Access of possibly undefined property (\S+)/i
    UndefinedProperty.new(Member[nil, $1])
  when /^Attempted access of inaccessible property (\S+)/i
    InaccessibleProperty.new(Member[nil, $1])
  when /^A file found in a source-path must have .*? '(\S+?)'/i
    WrongPackage.new(Type[$1, nil])
  when /^A file found in a source-path '(\S+?)' must .* as the class/i
    WrongClassName.new(Type[nil, $1])
  when /^Type was not found or was not a compile-time constant: (\S+).$/i
    UndefinedType.new(Type.parse($1))
  when /^The definition of base class (\S+) was not found.$/i
    UndefinedType.new(Type.parse($1))
  when /^Illegal assignment to a variable specified as constant.$/i
    ConstantAssignment.new
  when /^Method marked override must override another method.$/i
    BogusOverride.new
  when /^Incorrect number of arguments.\s* Expected no more than (\d+).$/i
    TooManyArguments.new($1.to_i)
  when /^Incorrect number of arguments.\s* Expected (0).$/i
    TooManyArguments.new($1.to_i)
  when /^Incorrect number of arguments.\s* Expected (\d+).$/i
    TooFewArguments.new($1.to_i)
  when /^return value for function '(\S+)' has no type declaration.$/i
    MissingReturnType.new(Member[nil, $1])
  when /^(?:variable|parameter) '(\S+)' has no type declaration.$/i
    MissingTypeDeclaration.new
  when /^Interface (\S+) was not found.$/i
    InterfaceNotFound.new(Type.parse($1))
  when /^Implicit coercion of a value of type (\S+) to an unrelated type (\S+).$/i
    TypeMismatch.new(Type.parse($2), Type.parse($1))
  when /^Comparison between a value with static type (\S+) and a possibly unrelated type Null.$/i
    InvalidNullComparison.new
  when /^Interface method ((?:get |set )?\S+) in namespace (\S+) not implemented by class (\S+).$/i
    MissingImplementation.new(Member[Type.parse($2), $1], Type.parse($3))
  when /^Interface method ((?:get |set )?\S+) in namespace (\S+) is implemented with an incompatible signature in class (\S+).$/i
    WrongImplementation.new(Member[Type.parse($2), $1], Type.parse($3))
  when /^A file (.*) must have an externally visible definition./
    MissingPublicDefinition.new
  else
    Unknown.new(message)
  end
end

Instance Method Details

#bullet_details(content) ⇒ Object



522
523
524
# File 'lib/asautotest/problematic-file.rb', line 522

def bullet_details(content)
  "\e[0m  * #{content}\e[0m"
end

#column_numberObject



185
186
187
# File 'lib/asautotest/problematic-file.rb', line 185

def column_number
  location.column_number - indentation_width rescue "?"
end

#detailObject



252
# File 'lib/asautotest/problematic-file.rb', line 252

def detail ; nil end

#detailsObject



164
# File 'lib/asautotest/problematic-file.rb', line 164

def details ; nil end

#details_columnObject



463
464
465
# File 'lib/asautotest/problematic-file.rb', line 463

def details_column
  ljust("  #{details}  ", MESSAGE_COLUMN_WIDTH)
end

#dummy_line_number_columnObject



471
472
473
# File 'lib/asautotest/problematic-file.rb', line 471

def dummy_line_number_column
  rjust("\e[0m|\e[0m", LINE_NUMBER_COLUMN_WIDTH)
end

#extra_detailsObject



165
# File 'lib/asautotest/problematic-file.rb', line 165

def extra_details ; nil end

#identifier_source_line_detailsObject



495
496
497
498
499
# File 'lib/asautotest/problematic-file.rb', line 495

def identifier_source_line_details
  "\e[0m  ... #{problematic_identifier_pre}" +
    "\e[1;4m#{problematic_identifier}\e[0m" +
    "#{problematic_identifier_post}"
end

#identifier_source_line_partsObject



513
514
515
516
# File 'lib/asautotest/problematic-file.rb', line 513

def identifier_source_line_parts
  source_line =~ /^(.{#{column_number.to_i}})([\w$]+)(.*)$/
  [$1, $2, $3]
end

#indentation_widthObject



189
190
191
# File 'lib/asautotest/problematic-file.rb', line 189

def indentation_width
  location.source_line =~ /^(\s*)/ ; $1.size
end

#last_detailsObject



479
480
481
# File 'lib/asautotest/problematic-file.rb', line 479

def last_details
  previous.details if previous
end

#last_extra_detailsObject



483
484
485
# File 'lib/asautotest/problematic-file.rb', line 483

def last_extra_details
  previous.extra_details if previous
end

#last_messageObject



475
476
477
# File 'lib/asautotest/problematic-file.rb', line 475

def last_message
  previous.message if previous
end

#line_numberObject



181
182
183
# File 'lib/asautotest/problematic-file.rb', line 181

def line_number
  location.line_number rescue "?"
end

#line_number_columnObject



467
468
469
# File 'lib/asautotest/problematic-file.rb', line 467

def line_number_column
  rjust("\e[1m#{line_number}\e[0m", LINE_NUMBER_COLUMN_WIDTH)
end

#member_detailsObject



518
519
520
# File 'lib/asautotest/problematic-file.rb', line 518

def member_details
  bullet_details(@member)
end

#message_columnObject



459
460
461
# File 'lib/asautotest/problematic-file.rb', line 459

def message_column
  ljust("  #{message}", MESSAGE_COLUMN_WIDTH)
end

#message_column_overflowed?Boolean

Returns:

  • (Boolean)


455
456
457
# File 'lib/asautotest/problematic-file.rb', line 455

def message_column_overflowed?
  message_column.size > MESSAGE_COLUMN_WIDTH
end

#plain_messageObject



253
254
255
256
257
258
259
# File 'lib/asautotest/problematic-file.rb', line 253

def plain_message
  if detail
    "#{message} #{detail}"
  else
    message.sub(/:$/, ".")
  end
end

#previousObject



487
488
489
# File 'lib/asautotest/problematic-file.rb', line 487

def previous
  file.problem_before(self)
end


432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
# File 'lib/asautotest/problematic-file.rb', line 432

def print_report
  unless message == last_message
    print message_column
    print dummy_line_number_column unless message_column_overflowed?
    puts
  end

  if details and details != last_details
    print details_column
    print line_number_column
    puts
  end

  if extra_details and extra_details != last_extra_details
    for line in extra_details
      puts "\e[34m    #{line.chomp}\e[0m"
    end
  end
end

#problematic_identifierObject



505
506
507
# File 'lib/asautotest/problematic-file.rb', line 505

def problematic_identifier
  identifier_source_line_parts[1]
end

#problematic_identifier_postObject



509
510
511
# File 'lib/asautotest/problematic-file.rb', line 509

def problematic_identifier_post
  identifier_source_line_parts[2]
end

#problematic_identifier_preObject



501
502
503
# File 'lib/asautotest/problematic-file.rb', line 501

def problematic_identifier_pre
  identifier_source_line_parts[0]
end

#sort_keyObject



177
178
179
# File 'lib/asautotest/problematic-file.rb', line 177

def sort_key
  location ? location.sort_key : [0]
end

#source_lineObject



168
169
170
171
172
173
174
175
# File 'lib/asautotest/problematic-file.rb', line 168

def source_line
  if location
    build_string do |result|
      result << location.source_line.trim
      result << " ..." unless location.source_line =~ /[;{}]\s*$/
    end
  end
end

#source_line_detailsObject



491
492
493
# File 'lib/asautotest/problematic-file.rb', line 491

def source_line_details
  "\e[0m  ... #{source_line}\e[0m"
end

#type_warning?Boolean

Returns:

  • (Boolean)


166
# File 'lib/asautotest/problematic-file.rb', line 166

def type_warning? ; false end