Class: EasySwig::Csharp::CsharpFeatures

Inherits:
Features
  • Object
show all
Defined in:
lib/csharp/csharp_features.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Features

create_instance, #empty?, #infer_native_name

Instance Attribute Details

#directorObject

Returns the value of attribute director.



8
9
10
# File 'lib/csharp/csharp_features.rb', line 8

def director
  @director
end

#immutableObject

Returns the value of attribute immutable.



9
10
11
# File 'lib/csharp/csharp_features.rb', line 9

def immutable
  @immutable
end

#partialObject

Returns the value of attribute partial.



10
11
12
# File 'lib/csharp/csharp_features.rb', line 10

def partial
  @partial
end

#propertiesObject

Returns the value of attribute properties.



6
7
8
# File 'lib/csharp/csharp_features.rb', line 6

def properties
  @properties
end

#structObject

Returns the value of attribute struct.



7
8
9
# File 'lib/csharp/csharp_features.rb', line 7

def struct
  @struct
end

Instance Method Details

#ignore_operator(name) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/csharp/csharp_features.rb', line 52

def ignore_operator(name)
  ['operator+','operator+=', 'operator-',
    'operator-=', 'operator*', 'operator*=',
    'operator/', 'operator/=', 'operator<',
    'operator<=', 'operator>', 'operator>=',
    'operator=', 'operator[]', 'operator==',
    'operator!=', 'operator^', 'operator~',
    'operator%', 'operator&', 'operator|',
    'operator&&', 'operator||', 'operator<<',
    'operator>>'].include?(name)
end

#infer_basename(node) ⇒ Object



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
# File 'lib/csharp/csharp_features.rb', line 23

def infer_basename(node)
  aux = node.target_name.gsub(/_([a-z])/i) { |match|
    $1.upcase
  }
  case node.node_type
    when 'function', 'attribute', 'variable'
      node.basename = aux.gsub(/^([A-Z])/) { |match|
        $1.downcase
      }
    when 'method'
      if node.constructor?
      node.basename =  aux
      else
        node.basename = aux.gsub(/^([A-Z])/) { |match|
          $1.downcase
        }
      end
    when 'class', 'enum'
      node.basename = aux.gsub(/^([a-z])/) { |match|
        $1.upcase
      }
    when 'namespace'
      node.basename = node.target_name.gsub(".", "::")
  else
  super node
  end

end

#infer_target_name(node) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/csharp/csharp_features.rb', line 64

def infer_target_name(node)
  case node.node_type
    when 'method'
      if node.basename.start_with? '~'
        node.target_name = 'Dispose'
      	return
      end
      if @properties
        node.target_name ||= node.setter_for
        node.target_name ||= node.getter_for
        if node.target_name
        	list = []
        	wnode = node.parent.wrapped_node
		list.push(*wnode.methods)
		list.push(*wnode.attributes)             	
        	if list.any? { |m| m.basename.capitalize == node.target_name.capitalize }
          	node.target_name.prepend('_')
          end
        end
      end
      node.target_name ||= node.basename
      node.target_name = node.target_name.gsub(/^(_?)([a-z])/) { |match|
        $2.upcase.prepend $1
      }
    when 'function', 'variable', 'attribute'
      node.target_name ||= node.basename.gsub(/^([a-z])/) { |match|
        $1.upcase
      }
    when 'namespace'
      node.target_name ||= node.basename.gsub("::", ".")
  else
  super node
  end
end

#to_sObject



12
13
14
15
16
17
# File 'lib/csharp/csharp_features.rb', line 12

def to_s
  s = @properties ? 'properties': ''
  s << @struct ? 'struct' : ''
  s << @director ? 'director' : ''
  s << @immutable ? 'immutable' : ''
end

#to_strObject



19
20
21
# File 'lib/csharp/csharp_features.rb', line 19

def to_str
  to_s
end