4 # Will yield one trigger per java import - each with the name of the imported
5 # namespace. Example java source file:
9 # will yield a trigger with name='com.foo.bar'
10 class FindJavaImportsRule < FileRule
11 attr_reader :keywords, :language
18 def process_source_file(source_file)
19 return unless source_file.language_breakdown('java')
21 java_code = source_file.language_breakdown('java').code
22 java_code.scan(import_regexp).each do |matches|
24 @trigger_hash[name] = @trigger_hash[name].to_i + 1
28 # implement deep clone
30 self.class.new(:min => @min_count)
33 def triggers(gestalt_engine)
35 @trigger_hash.each do |k,v|
36 triggers << Trigger.new(:name => FindJavaImportsRule.truncate_name(k, 3), :count => v)
42 /^\s*import\s+([a-zA-Z][\w\.\*\-]*)\b/
45 # Truncates the java import namespace to a maximum depth.
47 # truncate_name("com.sun.identity.authentication", 3) => "com.sun.identity"
48 def self.truncate_name(s, max_depth)
49 s.to_s.split('.')[0, max_depth].join('.')