Class: MergeClasses

Inherits:
Merge
  • Object
show all
Defined in:
lib/xmimerge/merge_classes.rb

Instance Method Summary collapse

Methods inherited from Merge

#check, #check_change_propertie, #merge

Constructor Details

#initialize(from_package, to_package) ⇒ MergeClasses

Returns a new instance of MergeClasses.



10
11
12
13
14
# File 'lib/xmimerge/merge_classes.rb', line 10

def initialize(from_package, to_package)
	super()
	@from_package = from_package
	@to_package = to_package
end

Instance Method Details

#check_changes(from_class) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/xmimerge/merge_classes.rb', line 26

def check_changes(from_class)

	to_class = @to_package.class_by_name(from_class.name)

	@log.info("Checking Class #{from_class.full_name}") if @only_check

	if to_class.nil?
		new_class from_class
	else
		check_existing_class(from_class, to_class)
	end
end

#check_existing_class(from_class, to_class) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/xmimerge/merge_classes.rb', line 88

def check_existing_class(from_class, to_class)
	
	@log.debug("Checking Existing Class: #{from_class.full_name}") if @only_check

	command = "* Class #{from_class.full_name}"
	@commands.add_command_to_buffer(command)	

	# Attributes
	merge = MergeAttribute.new(from_class, to_class)
	@only_check ? merge.check : merge.merge

	# Stereotypes		
	merge = MergeStereotypes.new("Class", from_class, to_class)
	@only_check ? merge.check : merge.merge

	# TaggedValues
	merge = MergeTaggedValues.new("Class", from_class, to_class)
	@only_check ? merge.check : merge.merge

	# TODO

	# Generalization

	# Associations		
	merge = MergeAssociations.new(from_class, to_class)
	@only_check ? merge.check : merge.merge		

	# Operations
	merge = MergeOperations.new(from_class, to_class)
	@only_check ? merge.check : merge.merge

	@commands.remove_if_is_last_command(command)		
end

#check_removedObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/xmimerge/merge_classes.rb', line 39

def check_removed

	@log.debug("Checking Removed Classes on package #{@to_package.full_name}...") if @only_check

	@to_package.classes.each do |to_class|
		
		ok = false
		@from_package.classes.each do |from_class|

			if from_class.full_name == to_class.full_name
				ok = true
				break
			end
		end
		if !ok
			@log.info("Class Removed: #{to_class.full_name}") if @only_check		
			command = "- Class #{to_class.full_name}"
			@commands.add_command_to_buffer(command)
			unless @only_check 
				if @commands.has_command?(command)
					@log.info "[OK] #{command}"
				else
					#@log.info "[NOT] #{command}"
				end
			end
		end
	end			
end

#new_class(from_class) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/xmimerge/merge_classes.rb', line 68

def new_class(from_class)
	@log.debug("New class") if @only_check
	command = "+ Class #{from_class.full_name}"
	@commands.add_command_to_buffer(command)

	unless @only_check 
		if @commands.has_command?(command)
			@to_package.add_xml_class(from_class.xml.to_xml)	
			@log.info "[OK] #{command}"				
		else
			@log.debug "[NOT] #{command}"
		end
	end

	from_class.attributes.each do |from_attribute|
		command = "\t+ Attribute #{from_class.full_name}::#{from_attribute.name}"
		@commands.add_command_to_buffer(command)
	end
end

#verifyObject



16
17
18
19
20
21
22
23
24
# File 'lib/xmimerge/merge_classes.rb', line 16

def verify

	@from_package.classes.each do |from_class|		
		check_changes(from_class)
	end

	check_removed

end