private void processWatcher ( MethodSpec . Builder createdMethodBuilder , ExecutableElement method ) { Watch watch = method . getAnnotation ( Watch . class ) ; String exposedMethodName = exposeExistingJavaMethodToJs ( method ) ; String watcherTriggerMethodName = addNewMethodToProto ( ) ; MethodSpec . Builder watcherMethodBuilder = MethodSpec . methodBuilder ( watcherTriggerMethodName ) . addModifiers ( Modifier . PUBLIC ) . addAnnotation ( JsMethod . class ) . returns ( Object . class ) ; String [ ] valueSplit = watch . value ( ) . split ( "\\." ) ; String currentExpression = "" ; for ( int i = 0 ; i < valueSplit . length - 1 ; i ++ ) { currentExpression += valueSplit [ i ] ; watcherMethodBuilder . addStatement ( "if ($L == null) return null" , currentExpression ) ; currentExpression += "." ; } watcherMethodBuilder . addStatement ( "return $L" , watch . value ( ) ) ; componentExposedTypeBuilder . addMethod ( watcherMethodBuilder . build ( ) ) ; createdMethodBuilder . addStatement ( "vue().$L(p.$L, p.$L, $T.of($L, $L))" , "$watch" , watcherTriggerMethodName , exposedMethodName , WatchOptions . class , watch . isDeep ( ) , watch . isImmediate ( ) ) ; }
Process a watcher from the Component Class .