@@ -376,26 +376,28 @@ protected List<Member> inherit(List<Member> inheritableMembers) {
376376 return inheritableMembers ;
377377 }
378378
379- public static ElementReference commonAncestor (Collection <ElementReference > classifiers ) {
379+ private static ElementReference commonAncestorImpl (Collection <ElementReferenceImpl > classifiers ) {
380380 while (classifiers .size () > 1 ) {
381381 // Construct the set of all common ancestors of the given classifiers.
382382 boolean isFirst = true ;
383- Set <ElementReference > commonAncestors = new HashSet <ElementReference >();
384- for (ElementReference classifier : classifiers ) {
385- if (classifier == null || classifier . getImpl () .isAny ()) {
386- return classifier ;
383+ Set <ElementReferenceImpl > commonAncestors = new HashSet <ElementReferenceImpl >();
384+ for (ElementReferenceImpl classifier : classifiers ) {
385+ if (classifier .isAny ()) {
386+ return classifier . getSelf () ;
387387 }
388388 // Note: allParents may be cached, so it should not be mutated.
389- Collection <ElementReference > ancestors = classifier .getImpl (). allParents ();
389+ Collection <ElementReference > ancestors = classifier .allParents ();
390390 if (isFirst ) {
391391 commonAncestors .add (classifier );
392- commonAncestors .addAll (ancestors );
392+ for (ElementReference ancestor : ancestors ) {
393+ commonAncestors .add (ancestor .getImpl ());
394+ }
393395 isFirst = false ;
394396 } else {
395397 for (Object object : commonAncestors .toArray ()) {
396- ElementReference commonAncestor = (ElementReference )object ;
397- if (!commonAncestor .getImpl (). equals (classifier ) &&
398- !commonAncestor .getImpl (). isContainedIn (ancestors )) {
398+ ElementReferenceImpl commonAncestor = (ElementReferenceImpl )object ;
399+ if (!commonAncestor .equals (classifier ) &&
400+ !commonAncestor .isContainedIn (ancestors )) {
399401 commonAncestors .remove (commonAncestor );
400402 }
401403 }
@@ -409,28 +411,43 @@ public static ElementReference commonAncestor(Collection<ElementReference> class
409411 // ancestors.
410412 for (Object ancestor : commonAncestors .toArray ()) {
411413 Collection <ElementReference > parents =
412- ((ElementReference )ancestor ). getImpl ( ).parents ();
414+ ((ElementReferenceImpl )ancestor ).parents ();
413415 for (ElementReference parent : parents ) {
414- commonAncestors .remove (parent );
416+ commonAncestors .remove (parent . getImpl () );
415417 }
416418
417419 }
418420
419421 classifiers = commonAncestors ;
420422 }
421- if (classifiers .isEmpty ()) {
422- return any ;
423- } else {
424- return (ElementReference )classifiers .toArray ()[0 ];
423+ for (ElementReferenceImpl classifier : classifiers ) {
424+ return classifier .getSelf ();
425425 }
426+ return any ;
427+ }
428+
429+ public static ElementReference commonAncestor (Collection <ElementReference > classifiers ) {
430+ HashSet <ElementReferenceImpl > classifierSet = new HashSet <ElementReferenceImpl >();
431+ for (ElementReference classifier : classifiers ) {
432+ if (classifier == null ) {
433+ return null ;
434+ } else {
435+ classifierSet .add (classifier .getImpl ());
436+ }
437+ }
438+ return commonAncestorImpl (classifierSet );
426439 }
427440
428441 public static ElementReference commonAncestor (ElementReference ... classifiers ) {
429- HashSet <ElementReference > classifierSet = new HashSet <ElementReference >();
442+ HashSet <ElementReferenceImpl > classifierSet = new HashSet <ElementReferenceImpl >();
430443 for (ElementReference classifier : classifiers ) {
431- classifierSet .add (classifier );
444+ if (classifier == null ) {
445+ return null ;
446+ } else {
447+ classifierSet .add (classifier .getImpl ());
448+ }
432449 }
433- return commonAncestor (classifierSet );
450+ return commonAncestorImpl (classifierSet );
434451 }
435452
436453 @ Override
0 commit comments