Module: RGen::MetamodelBuilder::MMBase::SingletonAddOn

Included in:
RGen::MetamodelBuilder::MMBase
Defined in:
lib/emf/rgen_ext.rb

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



86
87
88
# File 'lib/emf/rgen_ext.rb', line 86

def ==(other)
  eql? other
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/emf/rgen_ext.rb', line 57

def eql?(other)
  # it should ignore relations which has as opposite a containement
  return false unless self.shallow_eql?(other)
  self.class.ecore.eAllReferences.each do |ref|
    self_value = self.get(ref)
    other_value = other.get(ref)
    to_ignore = ref.getEOpposite and ref.getEOpposite.containment
    unless to_ignore
      if ref.containment
        return false unless self_value == other_value
      else
        if (self_value.is_a? Array) or (other_value.is_a? Array)
          return false unless self_value.count==other_value.count
          for i in 0..(self_value.count-1)
            return false unless self_value[i].shallow_eql?(other_value[i])
          end
        else  
          if self_value==nil
            return false unless other_value==nil
          else
            return false unless self_value.shallow_eql?(other_value)
          end
        end
      end
    end           
  end
  true
end

#get(attr_or_ref) ⇒ Object



90
91
92
93
# File 'lib/emf/rgen_ext.rb', line 90

def get(attr_or_ref)
  getter = (attr_or_ref.name).to_sym
  send getter
end

#shallow_eql?(other) ⇒ Boolean

It does not check references, it is needed to avoid infinite recursion

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/emf/rgen_ext.rb', line 43

def shallow_eql?(other)
  return false if other==nil
  return false unless self.class==other.class
  self.class.ecore.eAllAttributes.each do |attrib|
    if attrib.name != 'dynamic' # I have to understand this...
      self_value = self.get(attrib)
      other_value = other.get(attrib)
      #puts "returning false on #{attrib.name}" unless self_value.eql?(other_value)
      return false unless self_value == other_value
    end
  end
  true
end