1313/**
1414 * Similarity decisions for container elements.
1515 */
16- public class ContainersSimilaritySwitch extends ContainersSwitch <Boolean > implements ILoggableJavaSwitch , IJavaSimilarityPositionInnerSwitch {
16+ public class ContainersSimilaritySwitch extends ContainersSwitch <Boolean >
17+ implements ILoggableJavaSwitch , IJavaSimilarityPositionInnerSwitch {
1718 private IJavaSimilaritySwitch similaritySwitch ;
1819 private boolean checkStatementPosition ;
1920
@@ -26,112 +27,108 @@ public ISimilarityRequestHandler getSimilarityRequestHandler() {
2627 public boolean shouldCheckStatementPosition () {
2728 return this .checkStatementPosition ;
2829 }
29-
30+
3031 @ Override
3132 public IJavaSimilaritySwitch getContainingSwitch () {
3233 return this .similaritySwitch ;
3334 }
3435
35- public ContainersSimilaritySwitch (IJavaSimilaritySwitch similaritySwitch , boolean checkStatementPosition ) {
36+ public ContainersSimilaritySwitch (IJavaSimilaritySwitch similaritySwitch , boolean checkStatementPosition ) {
3637 this .similaritySwitch = similaritySwitch ;
3738 this .checkStatementPosition = checkStatementPosition ;
3839 }
3940
40- /**
41- * Check the similarity of two CompilationUnits.<br>
42- * Similarity is checked by
43- * <ul>
44- * <li>Comparing their names (including renamings)</li>
45- * <li>Comparing their namespaces' values (including renamings)</li>
46- * </ul>
47- * Note: CompilationUnit names are full qualified. So it is important to apply classifier as
48- * well as package renaming normalizations to them.
49- *
50- * @param unit1
51- * The compilation unit to compare with the compareElement.
52- * @return True/False whether they are similar or not.
53- */
54- @ Override
55- public Boolean caseCompilationUnit (CompilationUnit unit1 ) {
56- this .logMessage ("caseCompilationUnit" );
57-
58- CompilationUnit unit2 = (CompilationUnit ) this .getCompareElement ();
59- this .logComparison (unit1 .getName (), unit2 .getName (), CompilationUnit .class .getSimpleName ());
60-
61- String name1 = this .normalizeCompilationUnit (unit1 .getName ());
62- name1 = this .normalizePackage (name1 );
63- String name2 = unit2 .getName ();
64-
65- this .logResult (name1 .equals (name2 ), "compilation unit name" );
66- if (!name1 .equals (name2 )) {
67- return Boolean .FALSE ;
68- }
69-
70- String namespaceString1 = this .normalizeNamespace (unit1 .getNamespacesAsString ());
71- String namespaceString2 = Strings .nullToEmpty (unit2 .getNamespacesAsString ());
72-
73- this .logResult (namespaceString1 .equals (namespaceString2 ), "compilation unit namespace" );
74-
75- if (!namespaceString1 .equals (namespaceString2 )) {
76- return Boolean .FALSE ;
77- }
78-
79- return Boolean .TRUE ;
80- }
81-
82- /**
83- * Check package similarity.<br>
84- * Similarity is checked by
85- * <ul>
86- * <li>full qualified package path</li>
87- * </ul>
88- *
89- * @param package1
90- * The package to compare with the compare element.
91- * @return True/False if the packages are similar or not.
92- */
93- @ Override
94- public Boolean casePackage (Package package1 ) {
95- this .logMessage ("casePackage" );
96-
97- Package package2 = (Package ) this .getCompareElement ();
98- this .logComparison (package1 , package2 , Package .class .getSimpleName ());
99-
100- String packagePath1 = JaMoPPModelUtil .buildNamespacePath (package1 );
101- packagePath1 = this .normalizeNamespace (packagePath1 );
102- String packagePath2 = JaMoPPModelUtil .buildNamespacePath (package2 );
103-
104- this .logComparison (packagePath1 , packagePath2 , "package namespace" );
105- this .logResult (packagePath1 .equals (packagePath2 ), "package path" );
106-
107- if (!packagePath1 .equals (packagePath2 )) {
108- return Boolean .FALSE ;
109- }
110-
111- return Boolean .TRUE ;
112- }
113-
114- /**
115- * Check module similarity.<br>
116- * Similarity is checked by
117- * <ul>
118- * <li>module names</li>
119- * </ul>
120- *
121- * @param module1 The module to compare with the compare element.
122- * @return True/False if the modules are similar or not.
123- */
124- @ Override
125- public Boolean caseModule (org .emftext .language .java .containers .Module module1 ) {
126- this .logMessage ("caseModule" );
127-
128- org .emftext .language .java .containers .Module module2 =
129- (org .emftext .language .java .containers .Module ) this .getCompareElement ();
130-
131- this .logResult (module1 .getName ().equals (module2 .getName ()), org .emftext .language .java .containers .Module .class .getSimpleName ());
132- if (!module1 .getName ().equals (module2 .getName ())) {
133- return Boolean .FALSE ;
134- }
135- return Boolean .TRUE ;
136- }
41+ /**
42+ * Check the similarity of two CompilationUnits.<br>
43+ * Similarity is checked by
44+ * <ul>
45+ * <li>Comparing their names (including renamings)</li>
46+ * <li>Comparing their namespaces' values (including renamings)</li>
47+ * </ul>
48+ * Note: CompilationUnit names are full qualified. So it is important to apply
49+ * classifier as well as package renaming normalizations to them.
50+ *
51+ * @param unit1 The compilation unit to compare with the compareElement.
52+ * @return True/False whether they are similar or not.
53+ */
54+ @ Override
55+ public Boolean caseCompilationUnit (CompilationUnit unit1 ) {
56+ this .logMessage ("caseCompilationUnit" );
57+
58+ CompilationUnit unit2 = (CompilationUnit ) this .getCompareElement ();
59+
60+ String name1 = Strings .nullToEmpty (unit1 .getName ());
61+ name1 = Strings .nullToEmpty (this .normalizeCompilationUnit (name1 ));
62+ name1 = Strings .nullToEmpty (this .normalizePackage (name1 ));
63+
64+ String name2 = Strings .nullToEmpty (unit2 .getName ());
65+
66+ if (!name1 .equals (name2 )) {
67+ return Boolean .FALSE ;
68+ }
69+
70+ String namespaceString1 = Strings .nullToEmpty (unit1 .getNamespacesAsString ());
71+ String namespaceString2 = Strings .nullToEmpty (unit2 .getNamespacesAsString ());
72+ namespaceString1 = Strings .nullToEmpty (this .normalizeNamespace (namespaceString1 ));
73+
74+ if (!namespaceString1 .equals (namespaceString2 )) {
75+ return Boolean .FALSE ;
76+ }
77+
78+ return Boolean .TRUE ;
79+ }
80+
81+ /**
82+ * Check package similarity.<br>
83+ * Similarity is checked by
84+ * <ul>
85+ * <li>full qualified package path</li>
86+ * </ul>
87+ *
88+ * @param package1 The package to compare with the compare element.
89+ * @return True/False if the packages are similar or not.
90+ */
91+ @ Override
92+ public Boolean casePackage (Package package1 ) {
93+ this .logMessage ("casePackage" );
94+
95+ Package package2 = (Package ) this .getCompareElement ();
96+
97+ String packagePath1 = Strings .nullToEmpty (JaMoPPModelUtil .buildNamespacePath (package1 ));
98+ packagePath1 = Strings .nullToEmpty (this .normalizeNamespace (packagePath1 ));
99+
100+ String packagePath2 = Strings .nullToEmpty (JaMoPPModelUtil .buildNamespacePath (package2 ));
101+
102+ if (!packagePath1 .equals (packagePath2 )) {
103+ return Boolean .FALSE ;
104+ }
105+
106+ return Boolean .TRUE ;
107+ }
108+
109+ /**
110+ * Check module similarity.<br>
111+ * Similarity is checked by
112+ * <ul>
113+ * <li>module names</li>
114+ * </ul>
115+ *
116+ * @param module1 The module to compare with the compare element.
117+ * @return True/False if the modules are similar or not.
118+ */
119+ @ Override
120+ public Boolean caseModule (org .emftext .language .java .containers .Module module1 ) {
121+ this .logMessage ("caseModule" );
122+
123+ org .emftext .language .java .containers .Module module2 = (org .emftext .language .java .containers .Module ) this
124+ .getCompareElement ();
125+
126+ var name1 = Strings .nullToEmpty (module1 .getName ());
127+ var name2 = Strings .nullToEmpty (module2 .getName ());
128+
129+ if (!name1 .equals (name2 )) {
130+ return Boolean .FALSE ;
131+ }
132+ return Boolean .TRUE ;
133+ }
137134}
0 commit comments