2424import de .danielbechler .diff .selector .ElementSelector ;
2525import de .danielbechler .util .Assert ;
2626
27- import java .util .Collection ;
2827import java .util .Collection ;
2928import java .util .HashMap ;
3029import java .util .LinkedList ;
3534import static de .danielbechler .diff .inclusion .Inclusion .INCLUDED ;
3635import static java .util .Arrays .asList ;
3736
38- /**
39- *
40- */
4137public class InclusionService implements InclusionConfigurer , IsIgnoredResolver
4238{
4339 private final CategoryResolver categoryResolver ;
@@ -86,15 +82,18 @@ private boolean isExcluded(final DiffNode node)
8682 }
8783 }
8884 // Patched : Check if there are exclusions before browsing all excluded elements
89- if (hasExclusions ()) {
90- if (isExcludedByPath (node ) || isExcludedByCategory (node )) {
85+ if (hasExclusions ())
86+ {
87+ if (isExcludedByPath (node ) || isExcludedByCategory (node ))
88+ {
9189 return true ;
92- } else if (isExcludedByType (node ) || isExcludedByPropertyName (node )) {
90+ }
91+ else if (isExcludedByType (node ) || isExcludedByPropertyName (node ))
92+ {
9393 return true ;
9494 }
9595 }
9696 return false ;
97-
9897 }
9998
10099 private boolean isIncluded (final DiffNode node )
@@ -109,108 +108,129 @@ private boolean isIncluded(final DiffNode node)
109108 {
110109 return true ;
111110 }
112- }
111+ }
113112 // Patched : Check if there are inclusions before browsing all included elements
114- if (hasInclusions ()) {
115- if (node .isRootNode ()) {
113+ if (hasInclusions ())
114+ {
115+ if (node .isRootNode ())
116+ {
116117 return true ;
117- } else if (isIncludedByPath (node ) || isIncludedByCategory (node )) {
118+ }
119+ else if (isIncludedByPath (node ) || isIncludedByCategory (node ))
120+ {
118121 return true ;
119- } else if (isIncludedByType (node ) || isIncludedByPropertyName (node )) {
122+ }
123+ else if (isIncludedByType (node ) || isIncludedByPropertyName (node ))
124+ {
120125 return true ;
121126 }
122127 return false ;
123128 }
124129 return true ;
125130 }
126131
127- private boolean hasInclusions () {
128- // Patched : Now return if inclusions have been configured
129- return nodePathInclusion || categoryInclusion || typeInclusion || propertyNameInclusion ;
130- }
131-
132- private boolean hasExclusions () {
132+ private boolean hasExclusions ()
133+ {
133134 // Patched (New method) : Now return if exclusions have been configured
134135 return nodePathExclusion || categoryExclusion || typeExclusion || propertyNameExclusion ;
135136 }
136137
137- private boolean isIncludedByPath (final DiffNode node )
138+ private boolean isExcludedByPath (final DiffNode node )
138139 {
139- // Patched : First check if nodePath inclusions have been configured
140- if (nodePathInclusion && nodeInclusions .getNodeForPath (node .getPath ()).isIncluded ()) {
141- return true ;
140+ // Patched : First check if node path exclusions have been configured
141+ if (nodePathExclusion )
142+ {
143+ final InclusionNode valueNode = nodeInclusions .getNodeForPath (node .getPath ());
144+ if (valueNode .isExcluded () && !valueNode .containsValue (INCLUDED ))
145+ {
146+ return true ;
147+ }
142148 }
143149 return false ;
144150 }
145151
146- private boolean isIncludedByCategory (final DiffNode node )
152+ private boolean isExcludedByCategory (final DiffNode node )
147153 {
148- // Patched : First check if category inclusions have been configured
149- if (categoryInclusion && hasCategoryWithInclusion (node , INCLUDED )) {
154+ // Patched : First check if category exclusions have been configured
155+ if (categoryExclusion && hasCategoryWithInclusion (node , EXCLUDED ))
156+ {
150157 return true ;
151158 }
152159 return false ;
153160 }
154161
155- private boolean isIncludedByType (final DiffNode node )
162+ private boolean isExcludedByType (final DiffNode node )
156163 {
157- // Patched : First check if type inclusions have been configured
158- if (typeInclusion && typeInclusions .get (node .getValueType ()) == INCLUDED ) {
159- return true ;
164+ // Patched : First check if type exclusions have been configured
165+ if (typeExclusion && node .getValueType () != null )
166+ {
167+ return typeInclusions .get (node .getValueType ()) == EXCLUDED ;
160168 }
161169 return false ;
162170 }
163171
164- private boolean isIncludedByPropertyName (final DiffNode node )
172+ private boolean isExcludedByPropertyName (final DiffNode node )
165173 {
166- // Patched : First check if property name inclusions have been configured
167- if (propertyNameInclusion ) {
168- if (isIncludedByOwnPropertyName (node )) {
169- return true ;
170- } else if (isIncludedByParentPropertyName (node )) {
171- return true ;
174+ // Patched : First check if property name exclusions have been configured
175+ if (propertyNameExclusion )
176+ {
177+ final String propertyName = node .getPropertyName ();
178+ if (propertyName != null )
179+ {
180+ return propertyNameInclusions .get (propertyName ) == EXCLUDED ;
172181 }
173182 }
174183 return false ;
175184 }
176185
177- private boolean isExcludedByPath ( final DiffNode node )
186+ private boolean hasInclusions ( )
178187 {
179- // Patched : First check if node path exclusions have been configured
180- if (nodePathExclusion ) {
181- final InclusionNode valueNode = nodeInclusions .getNodeForPath (node .getPath ());
182- if (valueNode .isExcluded () && !valueNode .containsValue (INCLUDED )) {
183- return true ;
184- }
188+ // Patched : Now return if inclusions have been configured
189+ return nodePathInclusion || categoryInclusion || typeInclusion || propertyNameInclusion ;
190+ }
191+
192+ private boolean isIncludedByPath (final DiffNode node )
193+ {
194+ // Patched : First check if nodePath inclusions have been configured
195+ if (nodePathInclusion && nodeInclusions .getNodeForPath (node .getPath ()).isIncluded ())
196+ {
197+ return true ;
185198 }
186199 return false ;
187200 }
188201
189- private boolean isExcludedByCategory (final DiffNode node )
202+ private boolean isIncludedByCategory (final DiffNode node )
190203 {
191- // Patched : First check if category exclusions have been configured
192- if (categoryExclusion && hasCategoryWithInclusion (node , EXCLUDED )) {
204+ // Patched : First check if category inclusions have been configured
205+ if (categoryInclusion && hasCategoryWithInclusion (node , INCLUDED ))
206+ {
193207 return true ;
194208 }
195209 return false ;
196210 }
197211
198- private boolean isExcludedByType (final DiffNode node )
212+ private boolean isIncludedByType (final DiffNode node )
199213 {
200- // Patched : First check if type exclusions have been configured
201- if (typeExclusion && node .getValueType () != null ) {
202- return typeInclusions .get (node .getValueType ()) == EXCLUDED ;
214+ // Patched : First check if type inclusions have been configured
215+ if (typeInclusion && typeInclusions .get (node .getValueType ()) == INCLUDED )
216+ {
217+ return true ;
203218 }
204219 return false ;
205220 }
206221
207- private boolean isExcludedByPropertyName (final DiffNode node )
222+ private boolean isIncludedByPropertyName (final DiffNode node )
208223 {
209- // Patched : First check if property name exclusions have been configured
210- if (propertyNameExclusion ) {
211- final String propertyName = node .getPropertyName ();
212- if (propertyName != null ) {
213- return propertyNameInclusions .get (propertyName ) == EXCLUDED ;
224+ // Patched : First check if property name inclusions have been configured
225+ if (propertyNameInclusion )
226+ {
227+ if (isIncludedByOwnPropertyName (node ))
228+ {
229+ return true ;
230+ }
231+ else if (isIncludedByParentPropertyName (node ))
232+ {
233+ return true ;
214234 }
215235 }
216236 return false ;
0 commit comments