@@ -493,8 +493,21 @@ private <T> RichOp<T> wrapOp(OpInstance<T> instance, Hints hints)
493493
494494 try {
495495 // find the opWrapper that wraps this type of Op
496- Class <?> wrapper = getWrapperClass (instance .op (), instance .infoTree ()
497- .info ());
496+ OpInfo info = instance .infoTree ().info ();
497+ Class <?> rawType = Types .raw (info .opType ());
498+ Class <?> wrapper = getWrapperClass (rawType , info );
499+ if (wrapper == null ) {
500+ throw new IllegalArgumentException (info .implementationName () +
501+ ": matched op Type " + info .opType ().getClass () +
502+ " does not match a wrappable Op type." );
503+ }
504+ if (!wrapper .equals (rawType )) {
505+ log .warn ("OpInfo" + info .implementationName () +
506+ " could not be wrapped as a " + rawType +
507+ ", so it is instead wrapped as a " + wrapper +
508+ ". If you want it to be wrapped as a " + rawType +
509+ ", then you must define a new OpWrapper for that class!" );
510+ }
498511 // obtain the generic type of the Op w.r.t. the Wrapper class
499512 Type reifiedSuperType = Types .getExactSuperType (instance .getType (),
500513 wrapper );
@@ -513,37 +526,24 @@ private <T> RichOp<T> wrapOp(OpInstance<T> instance, Hints hints)
513526 }
514527 }
515528
516- private Class <?> getWrapperClass (Object op , OpInfo info ) {
517- List <Class <?>> suitableWrappers = wrappers .keySet ().stream ().filter (
518- wrapper -> wrapper .isInstance (op )).collect (Collectors .toList ());
519- List <Class <?>> filteredWrappers = filterWrapperSuperclasses (
520- suitableWrappers );
521- if (filteredWrappers .size () == 0 ) throw new IllegalArgumentException (info
522- .implementationName () + ": matched op Type " + info .opType ().getClass () +
523- " does not match a wrappable Op type." );
524- if (filteredWrappers .size () > 1 ) throw new IllegalArgumentException (
525- "Matched op Type " + info .opType ().getClass () +
526- " matches multiple Op types: " + filteredWrappers );
527- if (!Types .isAssignable (Types .raw (info .opType ()), filteredWrappers .get (0 )))
528- throw new IllegalArgumentException (Types .raw (info .opType ()) +
529- "cannot be wrapped as a " + filteredWrappers .get (0 ));
530- return filteredWrappers .get (0 );
531- }
532-
533- private List <Class <?>> filterWrapperSuperclasses (
534- List <Class <?>> suitableWrappers )
535- {
536- if (suitableWrappers .size () < 2 ) return suitableWrappers ;
537- List <Class <?>> list = new ArrayList <>();
538- for (Class <?> c : suitableWrappers ) {
539- boolean isSuperclass = false ;
540- for (Class <?> other : suitableWrappers ) {
541- if (c .equals (other )) continue ;
542- if (c .isAssignableFrom (other )) isSuperclass = true ;
543- }
544- if (!isSuperclass ) list .add (c );
529+ private Class <?> getWrapperClass (Class <?> opType , OpInfo info ) {
530+ if (opType == null )
531+ return null ;
532+ // Check opType itself
533+ if (wrappers .containsKey (opType ))
534+ return opType ;
535+ // Check superclass of opType
536+ Class <?> wrapperSuperClass = getWrapperClass (opType .getSuperclass (), info );
537+ if (wrapperSuperClass != null )
538+ return wrapperSuperClass ;
539+ // Check interfaces of opType
540+ for (Class <?> iFace : opType .getInterfaces ()) {
541+ Class <?> wrapperIFace = getWrapperClass (iFace , info );
542+ if (wrapperIFace != null )
543+ return wrapperIFace ;
545544 }
546- return list ;
545+ // There is no wrapper
546+ return null ;
547547 }
548548
549549 private List <RichOp <?>> resolveOpDependencies (OpCandidate candidate ,
0 commit comments