openhab-jrubyscripting 5.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/openhab/core/actions.rb +163 -0
- data/lib/openhab/core/entity_lookup.rb +144 -0
- data/lib/openhab/core/events/abstract_event.rb +17 -0
- data/lib/openhab/core/events/item_channel_link.rb +36 -0
- data/lib/openhab/core/events/item_command_event.rb +78 -0
- data/lib/openhab/core/events/item_event.rb +22 -0
- data/lib/openhab/core/events/item_state_changed_event.rb +52 -0
- data/lib/openhab/core/events/item_state_event.rb +51 -0
- data/lib/openhab/core/events/thing.rb +29 -0
- data/lib/openhab/core/events/thing_status_info_event.rb +53 -0
- data/lib/openhab/core/events.rb +10 -0
- data/lib/openhab/core/items/accepted_data_types.rb +29 -0
- data/lib/openhab/core/items/color_item.rb +52 -0
- data/lib/openhab/core/items/contact_item.rb +52 -0
- data/lib/openhab/core/items/date_time_item.rb +58 -0
- data/lib/openhab/core/items/dimmer_item.rb +148 -0
- data/lib/openhab/core/items/generic_item.rb +344 -0
- data/lib/openhab/core/items/group_item.rb +174 -0
- data/lib/openhab/core/items/image_item.rb +109 -0
- data/lib/openhab/core/items/location_item.rb +34 -0
- data/lib/openhab/core/items/metadata/hash.rb +390 -0
- data/lib/openhab/core/items/metadata/namespace_hash.rb +469 -0
- data/lib/openhab/core/items/metadata.rb +11 -0
- data/lib/openhab/core/items/number_item.rb +62 -0
- data/lib/openhab/core/items/numeric_item.rb +22 -0
- data/lib/openhab/core/items/persistence.rb +327 -0
- data/lib/openhab/core/items/player_item.rb +66 -0
- data/lib/openhab/core/items/proxy.rb +59 -0
- data/lib/openhab/core/items/registry.rb +66 -0
- data/lib/openhab/core/items/rollershutter_item.rb +68 -0
- data/lib/openhab/core/items/semantics/enumerable.rb +152 -0
- data/lib/openhab/core/items/semantics.rb +476 -0
- data/lib/openhab/core/items/state_storage.rb +53 -0
- data/lib/openhab/core/items/string_item.rb +28 -0
- data/lib/openhab/core/items/switch_item.rb +78 -0
- data/lib/openhab/core/items.rb +114 -0
- data/lib/openhab/core/lazy_array.rb +52 -0
- data/lib/openhab/core/profile_factory.rb +118 -0
- data/lib/openhab/core/script_handling.rb +55 -0
- data/lib/openhab/core/things/channel.rb +48 -0
- data/lib/openhab/core/things/channel_uid.rb +51 -0
- data/lib/openhab/core/things/item_channel_link.rb +33 -0
- data/lib/openhab/core/things/profile_callback.rb +52 -0
- data/lib/openhab/core/things/proxy.rb +69 -0
- data/lib/openhab/core/things/registry.rb +46 -0
- data/lib/openhab/core/things/thing.rb +194 -0
- data/lib/openhab/core/things.rb +22 -0
- data/lib/openhab/core/timer.rb +128 -0
- data/lib/openhab/core/types/comparable_type.rb +23 -0
- data/lib/openhab/core/types/date_time_type.rb +259 -0
- data/lib/openhab/core/types/decimal_type.rb +192 -0
- data/lib/openhab/core/types/hsb_type.rb +183 -0
- data/lib/openhab/core/types/increase_decrease_type.rb +34 -0
- data/lib/openhab/core/types/next_previous_type.rb +34 -0
- data/lib/openhab/core/types/numeric_type.rb +52 -0
- data/lib/openhab/core/types/on_off_type.rb +46 -0
- data/lib/openhab/core/types/open_closed_type.rb +41 -0
- data/lib/openhab/core/types/percent_type.rb +95 -0
- data/lib/openhab/core/types/play_pause_type.rb +38 -0
- data/lib/openhab/core/types/point_type.rb +117 -0
- data/lib/openhab/core/types/quantity_type.rb +327 -0
- data/lib/openhab/core/types/raw_type.rb +26 -0
- data/lib/openhab/core/types/refresh_type.rb +27 -0
- data/lib/openhab/core/types/rewind_fastforward_type.rb +38 -0
- data/lib/openhab/core/types/stop_move_type.rb +34 -0
- data/lib/openhab/core/types/string_type.rb +76 -0
- data/lib/openhab/core/types/type.rb +117 -0
- data/lib/openhab/core/types/un_def_type.rb +38 -0
- data/lib/openhab/core/types/up_down_type.rb +50 -0
- data/lib/openhab/core/types.rb +69 -0
- data/lib/openhab/core/uid.rb +36 -0
- data/lib/openhab/core.rb +85 -0
- data/lib/openhab/core_ext/java/duration.rb +115 -0
- data/lib/openhab/core_ext/java/local_date.rb +93 -0
- data/lib/openhab/core_ext/java/local_time.rb +106 -0
- data/lib/openhab/core_ext/java/month.rb +59 -0
- data/lib/openhab/core_ext/java/month_day.rb +105 -0
- data/lib/openhab/core_ext/java/period.rb +103 -0
- data/lib/openhab/core_ext/java/temporal_amount.rb +34 -0
- data/lib/openhab/core_ext/java/time.rb +58 -0
- data/lib/openhab/core_ext/java/unit.rb +15 -0
- data/lib/openhab/core_ext/java/zoned_date_time.rb +116 -0
- data/lib/openhab/core_ext/ruby/array.rb +21 -0
- data/lib/openhab/core_ext/ruby/class.rb +15 -0
- data/lib/openhab/core_ext/ruby/date.rb +89 -0
- data/lib/openhab/core_ext/ruby/numeric.rb +190 -0
- data/lib/openhab/core_ext/ruby/range.rb +70 -0
- data/lib/openhab/core_ext/ruby/time.rb +104 -0
- data/lib/openhab/core_ext.rb +18 -0
- data/lib/openhab/dsl/events/watch_event.rb +18 -0
- data/lib/openhab/dsl/events.rb +9 -0
- data/lib/openhab/dsl/gems.rb +3 -0
- data/lib/openhab/dsl/items/builder.rb +618 -0
- data/lib/openhab/dsl/items/ensure.rb +93 -0
- data/lib/openhab/dsl/items/timed_command.rb +236 -0
- data/lib/openhab/dsl/rules/automation_rule.rb +308 -0
- data/lib/openhab/dsl/rules/builder.rb +1373 -0
- data/lib/openhab/dsl/rules/guard.rb +115 -0
- data/lib/openhab/dsl/rules/name_inference.rb +160 -0
- data/lib/openhab/dsl/rules/property.rb +76 -0
- data/lib/openhab/dsl/rules/rule_triggers.rb +96 -0
- data/lib/openhab/dsl/rules/terse.rb +63 -0
- data/lib/openhab/dsl/rules/triggers/changed.rb +169 -0
- data/lib/openhab/dsl/rules/triggers/channel.rb +57 -0
- data/lib/openhab/dsl/rules/triggers/command.rb +107 -0
- data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +161 -0
- data/lib/openhab/dsl/rules/triggers/conditions/proc.rb +164 -0
- data/lib/openhab/dsl/rules/triggers/cron/cron.rb +195 -0
- data/lib/openhab/dsl/rules/triggers/cron/cron_handler.rb +127 -0
- data/lib/openhab/dsl/rules/triggers/trigger.rb +56 -0
- data/lib/openhab/dsl/rules/triggers/updated.rb +130 -0
- data/lib/openhab/dsl/rules/triggers/watch/watch.rb +55 -0
- data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +155 -0
- data/lib/openhab/dsl/rules/triggers.rb +12 -0
- data/lib/openhab/dsl/rules.rb +29 -0
- data/lib/openhab/dsl/script_handling.rb +55 -0
- data/lib/openhab/dsl/things/builder.rb +263 -0
- data/lib/openhab/dsl/thread_local.rb +48 -0
- data/lib/openhab/dsl/timer_manager.rb +191 -0
- data/lib/openhab/dsl/version.rb +9 -0
- data/lib/openhab/dsl.rb +686 -0
- data/lib/openhab/log.rb +348 -0
- data/lib/openhab/osgi.rb +70 -0
- data/lib/openhab/rspec/configuration.rb +56 -0
- data/lib/openhab/rspec/example_group.rb +90 -0
- data/lib/openhab/rspec/helpers.rb +439 -0
- data/lib/openhab/rspec/hooks.rb +93 -0
- data/lib/openhab/rspec/jruby.rb +46 -0
- data/lib/openhab/rspec/karaf.rb +811 -0
- data/lib/openhab/rspec/mocks/bundle_install_support.rb +25 -0
- data/lib/openhab/rspec/mocks/bundle_resolver.rb +30 -0
- data/lib/openhab/rspec/mocks/event_admin.rb +146 -0
- data/lib/openhab/rspec/mocks/metadata_provider.rb +75 -0
- data/lib/openhab/rspec/mocks/persistence_service.rb +140 -0
- data/lib/openhab/rspec/mocks/safe_caller.rb +40 -0
- data/lib/openhab/rspec/mocks/synchronous_executor.rb +56 -0
- data/lib/openhab/rspec/mocks/thing_handler.rb +76 -0
- data/lib/openhab/rspec/mocks/timer.rb +95 -0
- data/lib/openhab/rspec/openhab/core/actions.rb +26 -0
- data/lib/openhab/rspec/openhab/core/items/proxy.rb +27 -0
- data/lib/openhab/rspec/openhab/core/things/proxy.rb +27 -0
- data/lib/openhab/rspec/shell.rb +31 -0
- data/lib/openhab/rspec/suspend_rules.rb +60 -0
- data/lib/openhab/rspec.rb +17 -0
- data/lib/openhab/yard/cli/stats.rb +23 -0
- data/lib/openhab/yard/code_objects/group_object.rb +17 -0
- data/lib/openhab/yard/code_objects/java/base.rb +31 -0
- data/lib/openhab/yard/code_objects/java/class_object.rb +11 -0
- data/lib/openhab/yard/code_objects/java/field_object.rb +15 -0
- data/lib/openhab/yard/code_objects/java/interface_object.rb +15 -0
- data/lib/openhab/yard/code_objects/java/package_object.rb +11 -0
- data/lib/openhab/yard/code_objects/java/proxy.rb +23 -0
- data/lib/openhab/yard/handlers/jruby/base.rb +49 -0
- data/lib/openhab/yard/handlers/jruby/class_handler.rb +18 -0
- data/lib/openhab/yard/handlers/jruby/constant_handler.rb +18 -0
- data/lib/openhab/yard/handlers/jruby/java_import_handler.rb +27 -0
- data/lib/openhab/yard/handlers/jruby/mixin_handler.rb +23 -0
- data/lib/openhab/yard/html_helper.rb +44 -0
- data/lib/openhab/yard/tags/constant_directive.rb +20 -0
- data/lib/openhab/yard/tags/group_directive.rb +24 -0
- data/lib/openhab/yard/tags/library.rb +3 -0
- data/lib/openhab/yard.rb +32 -0
- metadata +504 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
module Actions
|
6
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
7
|
+
# redefine these to do nothing so that rules won't fail
|
8
|
+
|
9
|
+
module_function
|
10
|
+
|
11
|
+
def notify(msg, email: nil)
|
12
|
+
logger.debug("notify: #{msg}")
|
13
|
+
end
|
14
|
+
|
15
|
+
def say(text, voice: nil, sink: nil, volume: nil)
|
16
|
+
logger.debug("say: #{text}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def play_sound(filename, sink: nil, volume: nil)
|
20
|
+
logger.debug("play_sound: #{filename}")
|
21
|
+
end
|
22
|
+
|
23
|
+
# rubocop:enable Lint/UnusedMethodArgument
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
module Items
|
6
|
+
class Proxy
|
7
|
+
@proxies = {}
|
8
|
+
|
9
|
+
class << self
|
10
|
+
# ensure each item only has a single proxy, so that
|
11
|
+
# expect(item).to receive(:method) works
|
12
|
+
def new(item)
|
13
|
+
return super unless defined?(::RSpec) && ::RSpec.current_example&.example_group&.consistent_proxies?
|
14
|
+
|
15
|
+
@proxies.fetch(item.name) do
|
16
|
+
@proxies[item.name] = super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def reset_cache
|
21
|
+
@proxies = {}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module Core
|
5
|
+
module Things
|
6
|
+
class Proxy
|
7
|
+
@proxies = {}
|
8
|
+
|
9
|
+
class << self
|
10
|
+
# ensure each item only has a single proxy, so that
|
11
|
+
# expect(item).to receive(:method) works
|
12
|
+
def new(thing)
|
13
|
+
return super unless defined?(::RSpec) && ::RSpec.current_example&.example_group&.consistent_proxies?
|
14
|
+
|
15
|
+
@proxies.fetch(thing.uid.to_s) do
|
16
|
+
@proxies[thing.uid.to_s] = super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def reset_cache
|
21
|
+
@proxies = {}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module RSpec
|
5
|
+
# based on https://stackoverflow.com/questions/1197224/source-shell-script-into-environment-within-a-ruby-script#19826329
|
6
|
+
# @!visibility private
|
7
|
+
module Shell
|
8
|
+
module_function
|
9
|
+
|
10
|
+
# Read in the bash environment, after an optional command.
|
11
|
+
# Returns Array of key/value pairs.
|
12
|
+
def shell_env(cmd = nil)
|
13
|
+
cmd = "#{cmd} > /dev/null; " if cmd
|
14
|
+
env = `#{cmd}printenv -0`
|
15
|
+
env.split("\0").map { |l| l.split("=", 2) }
|
16
|
+
end
|
17
|
+
|
18
|
+
# Source a given file, and compare environment before and after.
|
19
|
+
# Returns Hash of any keys that have changed.
|
20
|
+
def shell_source(file)
|
21
|
+
(shell_env(". #{File.realpath(file)}") - shell_env).to_h
|
22
|
+
end
|
23
|
+
|
24
|
+
# Find variables changed as a result of sourcing the given file,
|
25
|
+
# and update in ENV.
|
26
|
+
def source_env_from(file)
|
27
|
+
shell_source(file).each { |k, v| ENV[k] = v }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module RSpec
|
5
|
+
# @!visibility private
|
6
|
+
module SuspendRules
|
7
|
+
# I'd prefer to prepend a module, but I can't because of
|
8
|
+
# https://github.com/jruby/jruby/issues/6966#issuecomment-1172983776
|
9
|
+
class ::OpenHAB::DSL::Rules::AutomationRule # rubocop:disable Style/ClassAndModuleChildren
|
10
|
+
def execute(mod = nil, inputs = nil)
|
11
|
+
if SuspendRules.suspended?
|
12
|
+
logger.trace("Skipping execution of #{uid} because rules are suspended.")
|
13
|
+
return
|
14
|
+
end
|
15
|
+
|
16
|
+
# super
|
17
|
+
::OpenHAB::DSL::ThreadLocal.thread_local(**@thread_locals) do
|
18
|
+
logger.trace { "Execute called with mod (#{mod&.to_string}) and inputs (#{inputs.inspect})" }
|
19
|
+
logger.trace { "Event details #{inputs["event"].inspect}" } if inputs&.key?("event")
|
20
|
+
trigger_conditions(inputs).process(mod: mod, inputs: inputs) do
|
21
|
+
process_queue(create_queue(inputs), mod, inputs)
|
22
|
+
end
|
23
|
+
rescue Exception => e
|
24
|
+
@run_context.logger.log_exception(e)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
# private_constant :AutomationRule
|
29
|
+
# DSL::Rules::AutomationRule.prepend(AutomationRule)
|
30
|
+
|
31
|
+
module DSL
|
32
|
+
def after(*)
|
33
|
+
return if SuspendRules.suspended?
|
34
|
+
|
35
|
+
super
|
36
|
+
end
|
37
|
+
end
|
38
|
+
private_constant :DSL
|
39
|
+
OpenHAB::DSL.prepend(DSL)
|
40
|
+
|
41
|
+
@suspended = false
|
42
|
+
|
43
|
+
class << self
|
44
|
+
# @!visibility private
|
45
|
+
def suspend_rules
|
46
|
+
old_suspended = @suspended
|
47
|
+
@suspended = true
|
48
|
+
yield
|
49
|
+
ensure
|
50
|
+
@suspended = old_suspended
|
51
|
+
end
|
52
|
+
|
53
|
+
# @!visibility private
|
54
|
+
def suspended?
|
55
|
+
@suspended
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
unless RUBY_ENGINE == "jruby" &&
|
4
|
+
Gem::Version.new(RUBY_ENGINE_VERSION) >= Gem::Version.new("9.3.8.0")
|
5
|
+
raise Gem::RubyVersionMismatch, "openhab-jrubyscripting requires JRuby 9.3.8.0 or newer"
|
6
|
+
end
|
7
|
+
|
8
|
+
require "jruby"
|
9
|
+
|
10
|
+
require "diff/lcs"
|
11
|
+
|
12
|
+
require "openhab/log"
|
13
|
+
|
14
|
+
require_relative "rspec/configuration"
|
15
|
+
require_relative "rspec/helpers"
|
16
|
+
require_relative "rspec/karaf"
|
17
|
+
require_relative "rspec/hooks"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module YARD
|
5
|
+
module CLI
|
6
|
+
module Stats
|
7
|
+
::YARD::CLI::Stats.prepend(self)
|
8
|
+
|
9
|
+
def stats_for_constants
|
10
|
+
objs = all_objects.select { |m| m.type == :constant }
|
11
|
+
undoc = objs.find_all do |m|
|
12
|
+
# allow constants that are simple aliases
|
13
|
+
# to not have additional documentation
|
14
|
+
m.docstring.blank? && m.target.nil?
|
15
|
+
end
|
16
|
+
@undoc_list |= undoc if @undoc_list
|
17
|
+
|
18
|
+
output "Constants", objs.size, undoc.size
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YARD
|
4
|
+
module CodeObjects
|
5
|
+
module Java
|
6
|
+
#
|
7
|
+
# Represents a java.lang.Class
|
8
|
+
#
|
9
|
+
# Which might be a class, an enum, or an interface
|
10
|
+
module Base
|
11
|
+
module ClassMethods
|
12
|
+
def new(name)
|
13
|
+
super(:root, name)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.included(klass)
|
18
|
+
klass.singleton_class.include(ClassMethods)
|
19
|
+
end
|
20
|
+
|
21
|
+
def visibility
|
22
|
+
:private
|
23
|
+
end
|
24
|
+
|
25
|
+
def simple_name
|
26
|
+
name.to_s.split(".").last
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YARD
|
4
|
+
module CodeObjects
|
5
|
+
module Java
|
6
|
+
module Proxy
|
7
|
+
CodeObjects::Proxy.prepend(self)
|
8
|
+
|
9
|
+
def initialize(namespace, name, type = nil)
|
10
|
+
if name.match?(/^([a-zA-Z_$][a-zA-Z\d_$]*\.)+/)
|
11
|
+
@namespace = Registry.root
|
12
|
+
@name = name.to_sym
|
13
|
+
@obj = nil
|
14
|
+
@imethod = nil
|
15
|
+
self.type = type
|
16
|
+
return
|
17
|
+
end
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YARD
|
4
|
+
module Handlers
|
5
|
+
module JRuby
|
6
|
+
module Base
|
7
|
+
class << self
|
8
|
+
def infer_java_class(klass, inferred_type = nil, comments = nil, statement = nil)
|
9
|
+
components = klass.split(".")
|
10
|
+
class_first_char = components.last[0]
|
11
|
+
is_field = components.last == components.last.upcase
|
12
|
+
is_package = !is_field && class_first_char != class_first_char.upcase
|
13
|
+
|
14
|
+
javadocs = YARD::Config.options.dig(:jruby, "javadocs") || {}
|
15
|
+
|
16
|
+
href_base = javadocs.find { |package, _href| klass == package || klass.start_with?("#{package}.") }&.last
|
17
|
+
return unless href_base
|
18
|
+
|
19
|
+
inferred_type = CodeObjects::Java::FieldObject if is_field
|
20
|
+
inferred_type = CodeObjects::Java::PackageObject if is_package
|
21
|
+
if inferred_type.nil?
|
22
|
+
docstring = Docstring.parser.parse(comments || statement&.comments).to_docstring
|
23
|
+
inferred_type = if docstring.has_tag?(:interface)
|
24
|
+
CodeObjects::Java::InterfaceObject
|
25
|
+
else
|
26
|
+
CodeObjects::Java::ClassObject
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
inferred_type.new(klass) do |o|
|
31
|
+
o.source = statement if statement
|
32
|
+
suffix = "/package-summary" if is_package
|
33
|
+
field = "##{components.pop}" if is_field
|
34
|
+
link = "#{href_base}#{components.join("/")}#{suffix}.html#{field}"
|
35
|
+
o.docstring.add_tag(Tags::Tag.new(:see, klass, nil, link)) unless o.docstring.has_tag?(:see)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def infer_java_class(statement, inferred_type = nil, comments = nil)
|
41
|
+
return unless statement.is_a?(Parser::Ruby::AstNode)
|
42
|
+
return unless statement.type == :call
|
43
|
+
|
44
|
+
Base.infer_java_class(statement.source, inferred_type, comments, statement)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YARD
|
4
|
+
module Handlers
|
5
|
+
module JRuby
|
6
|
+
module ClassHandler
|
7
|
+
include Base
|
8
|
+
|
9
|
+
Ruby::ClassHandler.prepend(self)
|
10
|
+
|
11
|
+
def parse_superclass(superclass)
|
12
|
+
infer_java_class(superclass, CodeObjects::Java::ClassObject)&.then { |k| return k }
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YARD
|
4
|
+
module Handlers
|
5
|
+
module JRuby
|
6
|
+
module ConstantHandler
|
7
|
+
include Base
|
8
|
+
|
9
|
+
Ruby::ConstantHandler.prepend(self)
|
10
|
+
|
11
|
+
def process_constant(statement)
|
12
|
+
infer_java_class(statement[1], nil, statement.comments)
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YARD
|
4
|
+
module Handlers
|
5
|
+
module JRuby
|
6
|
+
class JavaImportHandler < Ruby::Base
|
7
|
+
include Base
|
8
|
+
|
9
|
+
handles method_call(:java_import)
|
10
|
+
|
11
|
+
process do
|
12
|
+
statement.parameters(false).each do |klass|
|
13
|
+
# first we auto-create the CodeObject for the class
|
14
|
+
obj = infer_java_class(klass)
|
15
|
+
next unless obj
|
16
|
+
|
17
|
+
# then we create a new constant in the current namespace
|
18
|
+
register CodeObjects::ConstantObject.new(namespace, obj.simple_name) { |o|
|
19
|
+
o.source = statement
|
20
|
+
o.value = klass.source
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module YARD
|
4
|
+
module Handlers
|
5
|
+
module JRuby
|
6
|
+
module MixinHandler
|
7
|
+
include Base
|
8
|
+
|
9
|
+
Ruby::MixinHandler.prepend(self)
|
10
|
+
|
11
|
+
def process_mixin(mixin)
|
12
|
+
if infer_java_class(mixin, CodeObjects::Java::InterfaceObject)
|
13
|
+
# make the Ruby::MixinHandler accept that this is a ref
|
14
|
+
def mixin.ref?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module YARD
|
5
|
+
# @!visibility private
|
6
|
+
module HtmlHelper
|
7
|
+
def html_markup_markdown(text)
|
8
|
+
result = super
|
9
|
+
|
10
|
+
# re-link files in docs/*.md. They're written so they work on github without any
|
11
|
+
# processing
|
12
|
+
result.gsub!(%r{<a href="(?:[A-Za-z0-9_/-]+/)*([A-Za-z0-9_-]+).md(#[A-Za-z0-9_/-]+)?"},
|
13
|
+
"<a href=\"file.\\1.html\\2\"")
|
14
|
+
result
|
15
|
+
end
|
16
|
+
|
17
|
+
# have to completely replace this method. only change is the regex splitting
|
18
|
+
# into parts now allows `.` as part of the identifier
|
19
|
+
# rubocop:disable Style
|
20
|
+
def format_types(typelist, brackets = true)
|
21
|
+
return unless typelist.is_a?(Array)
|
22
|
+
|
23
|
+
list = typelist.map do |type|
|
24
|
+
type = type.gsub(/([<>])/) { h($1) }
|
25
|
+
type = type.gsub(/([\w:.]+)/) { $1 == "lt" || $1 == "gt" ? $1 : linkify($1, $1) }
|
26
|
+
"<tt>" + type + "</tt>"
|
27
|
+
end
|
28
|
+
list.empty? ? "" : (brackets ? "(#{list.join(", ")})" : list.join(", "))
|
29
|
+
end
|
30
|
+
# rubocop:enable Style
|
31
|
+
|
32
|
+
def link_object(obj, title = nil, *)
|
33
|
+
::YARD::Handlers::JRuby::Base.infer_java_class(obj) if obj.is_a?(String)
|
34
|
+
obj = ::YARD::Registry.resolve(object, obj, true, true) if obj.is_a?(String)
|
35
|
+
if obj.is_a?(::YARD::CodeObjects::Java::Base) && (see = obj.docstring.tag(:see))
|
36
|
+
# link to the first see tag
|
37
|
+
return linkify(see.name, title&.to_s || see.text)
|
38
|
+
end
|
39
|
+
|
40
|
+
super
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module YARD
|
5
|
+
module Tags
|
6
|
+
class ConstantDirective < ::YARD::Tags::Directive
|
7
|
+
def call
|
8
|
+
return unless handler
|
9
|
+
|
10
|
+
::YARD::CodeObjects::ConstantObject.new(handler.namespace, tag.name.to_sym) do |obj|
|
11
|
+
obj.value = ""
|
12
|
+
obj.docstring = tag.text
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
::YARD::Tags::Library.define_directive :constant, :with_title_and_text, self
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenHAB
|
4
|
+
module YARD
|
5
|
+
module Tags
|
6
|
+
module GroupDirective
|
7
|
+
::YARD::Tags::GroupDirective.prepend(self)
|
8
|
+
|
9
|
+
def after_parse
|
10
|
+
return if tag.name.empty?
|
11
|
+
return unless handler
|
12
|
+
|
13
|
+
object = CodeObjects::GroupObject.new(handler.namespace, tag.name)
|
14
|
+
handler.extra_state.group = object
|
15
|
+
self.parser = parser.class.new(parser.library)
|
16
|
+
parser.state.inside_directive = true
|
17
|
+
parser.parse(tag.text, object, handler)
|
18
|
+
parser.state.inside_directive = false
|
19
|
+
object.docstring = parser.to_docstring # rubocop:disable Lint/UselessSetterCall
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/openhab/yard.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "byebug"
|
4
|
+
|
5
|
+
Dir[File.expand_path("yard/**/*.rb", __dir__)].sort.each do |f|
|
6
|
+
require f
|
7
|
+
end
|
8
|
+
|
9
|
+
YARD::Templates::Template.extra_includes << ->(opts) { OpenHAB::YARD::HtmlHelper if opts.format == :html }
|
10
|
+
YARD::Templates::Engine.register_template_path File.expand_path("../../templates", __dir__)
|
11
|
+
YARD::Tags::Library.define_tag "Java Interface", :interface
|
12
|
+
|
13
|
+
#
|
14
|
+
# @!parse
|
15
|
+
# # @!visibility private
|
16
|
+
# module Comparable; end
|
17
|
+
#
|
18
|
+
# # @!visibility private
|
19
|
+
# module Forwardable; end
|
20
|
+
#
|
21
|
+
# # @!visibility private
|
22
|
+
# module Singleton; end
|
23
|
+
#
|
24
|
+
# # Extensions to Ruby Numeric
|
25
|
+
# class Numeric; end
|
26
|
+
#
|
27
|
+
# # @!visibility private
|
28
|
+
# class Object; end
|
29
|
+
#
|
30
|
+
# # Extensions to Ruby Range
|
31
|
+
# class Range; end
|
32
|
+
#
|