Class: Blufin::ScannerJava
- Inherits:
-
Object
- Object
- Blufin::ScannerJava
- Defined in:
- lib/core/code_scanners/common/scanner_java.rb
Constant Summary collapse
- NAME =
'name'
- PATH =
'path'
- TEST =
'test'
- TEST_REQUIRED =
'test_required'
- TEST_NOT_RELATED_TO_CLASS =
'test_not_related_to_class'
- TYPE =
'type'
- TYPE_CLASS =
'type_class'
- TYPE_CLASS_ABSTRACT =
'type_class_abstract'
- TYPE_ENUM =
'type_enum'
- TYPE_INTERFACE =
'type_interface'
- @@scanned_classes =
{}
Class Method Summary collapse
-
.scan(file, site, error_handler) ⇒ Object
Returns a Hash containing info about the Java class.
Class Method Details
.scan(file, site, error_handler) ⇒ Object
Returns a Hash containing info about the Java class.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/core/code_scanners/common/scanner_java.rb', line 22 def self.scan(file, site, error_handler) return @@scanned_classes[file] unless @@scanned_classes[file].nil? raise RuntimeError, "Expected String, instead got: #{file.class}" unless file.is_a?(String) raise RuntimeError, "This method only accepts .java files. You passed: #{file}" unless file =~ /\.java\z/ site = Blufin::SiteResolver::validate_site(site) site_path = Blufin::SiteResolver::get_site_location(site) fps = Blufin::YmlCommon::split_to_path_file(file, site_path) info = { NAME => fps[1], PATH => fps[0], } # Is this a test? info[TEST] = (file =~ /\/src\/test\//) ? true : false info[TEST_REQUIRED] = true unless info[TEST] @test_required = false @test_not_required = false @test_not_related_to_class = false Blufin::Files::read_file(file).each do |line| get_java_class_type(info, line, file) if info[TYPE].nil? get_java_test_required(info, line) if info[TEST_REQUIRED] (info, line) if info[TEST] end # Errors tests_annotations_found = [] tests_annotations_found << Blufin::SiteServices::ANNOTATION_TEST_REQUIRED if @test_required tests_annotations_found << Blufin::SiteServices::ANNOTATION_TEST_NOT_REQUIRED if @test_not_required error_handler.add_error(Blufin::YmlErrorHandler::ANNOTATIONS_ONE_OR_ANOTHER, file, nil, nil, [Blufin::SiteServices::ANNOTATION_TEST_REQUIRED, Blufin::SiteServices::ANNOTATION_TEST_NOT_REQUIRED].inspect) if @test_required && @test_not_required error_handler.add_error(Blufin::YmlErrorHandler::ANNOTATIONS_NOT_EXPECTED, file, nil, nil, tests_annotations_found.inspect) if info[TEST] && tests_annotations_found.any? error_handler.add_error(Blufin::YmlErrorHandler::ANNOTATIONS_NOT_EXPECTED, file, nil, nil, Blufin::SiteServices::ANNOTATION_TEST_NOT_RELATED_TO_CLASS.inspect) if info[TEST] == false && @test_not_related_to_class info[TEST_REQUIRED] = true if @test_required info[TEST_REQUIRED] = false if @test_not_required raise RuntimeError, "Unrecognized ClassType: #{file}" if info[TYPE].nil? @@scanned_classes[file] = info info end |