File: resolution_helper.rb

package info (click to toggle)
ruby-rgen 0.10.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,428 kB
  • sloc: ruby: 11,344; xml: 1,368; yacc: 72; makefile: 10
file content (47 lines) | stat: -rw-r--r-- 1,083 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
module RGen
module Instantiator

module ResolutionHelper

# sets the target of an unresolved reference in the model
# returns :type_error if the target is of wrong type, otherwise :success
#
def self.set_uref_target(uref, target)
  refs = uref.element.getGeneric(uref.feature_name)
  if refs.is_a?(Array) 
    index = refs.index(uref.proxy)
    uref.element.removeGeneric(uref.feature_name, uref.proxy)
    begin
      uref.element.addGeneric(uref.feature_name, target, index)
    rescue StandardError => e
      if is_type_error?(e)
        uref.element.addGeneric(uref.feature_name, uref.proxy, index)
        return :type_error
      else
        raise
      end
    end
  else
    begin
      # this will replace the proxy
      uref.element.setGeneric(uref.feature_name, target)
    rescue StandardError => e
      if is_type_error?(e)
        return :type_error
      else
        raise
      end
    end
  end
  :success
end

def self.is_type_error?(e)
  e.message =~ /Can not use a .* where a .* is expected/
end

end

end
end