FtcXtensible/src/main/java/org/ftccommunity/ftcxtensible/AnnotationFtcRegister.java
public static void loadOpModes(OpModeManager register) {
        AnnotationFtcRegister me = new AnnotationFtcRegister();
        me.buildNoCheckList();

        LinkedList<Class> classes = me.buildClassList();
        Class[] classArray = classes.toArray(new Class[classes.size()]);
        ServiceRegister.init(classArray);
        HashMap<String, LinkedList<Class<?>>> opModes = me.findOpModes(classes);
        me.sortOpModeMap(opModes);

        LinkedList<Class<?>> opModesToRegister = new LinkedList<>();
        for (LinkedList<Class<?>> opModeList : me.treeMapify(opModes).values()) {
            for (Class<?> opMode : opModeList) {
                // todo: move this to the appropriate section
                if (opMode.isAnnotationPresent(RobotSdkVersion.class)) {
                    RobotSdkVersion annotation = opMode.getAnnotation(RobotSdkVersion.class);
                    if (annotation.value() != RobotSdkApiLevel.currentVersion()) {
                        if (annotation.strict() ||
                                annotation.compatibleUpTo()
                                        .compareTo(RobotSdkApiLevel.currentVersion()) < 0) {
                            Log.w(TAG, "Skipping OpMode " + getOpModeName(opMode) +
                                    " because of incompatibility");
                            continue;
                        }
                    }
                }

                // todo workaround an the issue of reflectively loading an non-public class

                if (!Modifier.isPublic(opMode.getModifiers())) {
                    RobotLog.setGlobalErrorMsg(getOpModeName(opMode) + " is marked as an OpMode, " +
                            "however it is not public. Please add the keyword 'public' to it");
                }

                opModesToRegister.add(opMode);
            }
        }

        for (Class<?> opMode : opModesToRegister) {
            Log.i(TAG, "Registering " + getOpModeName(opMode));
            final OpModeMeta opModeMeta = generateRegistrationMeta(opMode);
            if (ReflectionUtilities.isParent(opMode, OpMode.class))
                register.register(opModeMeta, (Class) opMode);
            else if (ReflectionUtilities.isParent(opMode, FullOpMode.class))
                register.register(opModeMeta, new FtcOpModeFullOpModeRunner<>((Class<? extends RobotFullOp>) opMode));
            else if (ReflectionUtilities.isParent(opMode, RobotInitStartStopLoop.class))
                register.register(opModeMeta, new FtcOpModeInitStartStopInterfaceRunner<>((Class<? extends RobotInitStartStopLoop>) opMode));
            else if (ReflectionUtilities.isParent(opMode, RobotInitStopLoop.class))
                register.register(opModeMeta, new FtcOpModeStopInitInterfaceRunner<>((Class<? extends RobotInitStopLoop>) opMode));
            else if (ReflectionUtilities.isParent(opMode, RobotLoop.class))
                register.register(opModeMeta, new FtcOpModeInterfaceRunner<>((Class<? extends RobotLoop>) opMode));
            else
                register.register(opModeMeta, new FtcOpModeRunner<>(opMode));
        }

    }
/**
     * This statically loads OpModes via reflection. This is the main method for this procedure
     *
     * @param register the Ftc OpMode Register
     */
This statically loads OpModes via reflection. This is the main method for this procedure
@param register the Ftc OpMode Register
This statically loads OpModes via reflection . This is the main method for this procedure @param register the Ftc OpMode Register
public static void loadOpModes(OpModeManager register) {
        AnnotationFtcRegister me = new AnnotationFtcRegister();
        me.buildNoCheckList();
        LinkedList<Class> classes = me.buildClassList();
        Class[] classArray = classes.toArray(new Class[classes.size()]);
        ServiceRegister.init(classArray);
        HashMap<String, LinkedList<Class<?>>> opModes = me.findOpModes(classes);
        me.sortOpModeMap(opModes);
        LinkedList<Class<?>> opModesToRegister = new LinkedList<>();
        for (LinkedList<Class<?>> opModeList : me.treeMapify(opModes).values()) {
            for (Class<?> opMode : opModeList) {
                if (opMode.isAnnotationPresent(RobotSdkVersion.class)) {
                    RobotSdkVersion annotation = opMode.getAnnotation(RobotSdkVersion.class);
                    if (annotation.value() != RobotSdkApiLevel.currentVersion()) {
                        if (annotation.strict() ||
                                annotation.compatibleUpTo()
                                        .compareTo(RobotSdkApiLevel.currentVersion()) < 0) {
                            Log.w(TAG, "Skipping OpMode " + getOpModeName(opMode) +
                                    " because of incompatibility");
                            continue;
                        }
                    }
                }
                if (!Modifier.isPublic(opMode.getModifiers())) {
                    RobotLog.setGlobalErrorMsg(getOpModeName(opMode) + " is marked as an OpMode, " +
                            "however it is not public. Please add the keyword 'public' to it");
                }
                opModesToRegister.add(opMode);
            }
        }
        for (Class<?> opMode : opModesToRegister) {
            Log.i(TAG, "Registering " + getOpModeName(opMode));
            final OpModeMeta opModeMeta = generateRegistrationMeta(opMode);
            if (ReflectionUtilities.isParent(opMode, OpMode.class))
                register.register(opModeMeta, (Class) opMode);
            else if (ReflectionUtilities.isParent(opMode, FullOpMode.class))
                register.register(opModeMeta, new FtcOpModeFullOpModeRunner<>((Class<? extends RobotFullOp>) opMode));
            else if (ReflectionUtilities.isParent(opMode, RobotInitStartStopLoop.class))
                register.register(opModeMeta, new FtcOpModeInitStartStopInterfaceRunner<>((Class<? extends RobotInitStartStopLoop>) opMode));
            else if (ReflectionUtilities.isParent(opMode, RobotInitStopLoop.class))
                register.register(opModeMeta, new FtcOpModeStopInitInterfaceRunner<>((Class<? extends RobotInitStopLoop>) opMode));
            else if (ReflectionUtilities.isParent(opMode, RobotLoop.class))
                register.register(opModeMeta, new FtcOpModeInterfaceRunner<>((Class<? extends RobotLoop>) opMode));
            else
                register.register(opModeMeta, new FtcOpModeRunner<>(opMode));
        }
    }
public static void loadOpModes ( OpModeManager register ) { AnnotationFtcRegister me = new AnnotationFtcRegister ( ) ; me . buildNoCheckList ( ) ; LinkedList < Class > classes = me . buildClassList ( ) ; Class [ ] classArray = classes . toArray ( new Class [ classes . size ( ) ] ) ; ServiceRegister . init ( classArray ) ; HashMap < String , LinkedList < Class < ? > > > opModes = me . findOpModes ( classes ) ; me . sortOpModeMap ( opModes ) ; LinkedList < Class < ? > > opModesToRegister = new LinkedList < > ( ) ; for ( LinkedList < Class < ? > > opModeList : me . treeMapify ( opModes ) . values ( ) ) { for ( Class < ? > opMode : opModeList ) { if ( opMode . isAnnotationPresent ( RobotSdkVersion . class ) ) { RobotSdkVersion annotation = opMode . getAnnotation ( RobotSdkVersion . class ) ; if ( annotation . value ( ) != RobotSdkApiLevel . currentVersion ( ) ) { if ( annotation . strict ( ) || annotation . compatibleUpTo ( ) . compareTo ( RobotSdkApiLevel . currentVersion ( ) ) < 0 ) { Log . w ( TAG , "Skipping OpMode " + getOpModeName ( opMode ) + " because of incompatibility" ) ; continue ; } } } if ( ! Modifier . isPublic ( opMode . getModifiers ( ) ) ) { RobotLog . setGlobalErrorMsg ( getOpModeName ( opMode ) + " is marked as an OpMode, " + "however it is not public. Please add the keyword 'public' to it" ) ; } opModesToRegister . add ( opMode ) ; } } for ( Class < ? > opMode : opModesToRegister ) { Log . i ( TAG , "Registering " + getOpModeName ( opMode ) ) ; final OpModeMeta opModeMeta = generateRegistrationMeta ( opMode ) ; if ( ReflectionUtilities . isParent ( opMode , OpMode . class ) ) register . register ( opModeMeta , ( Class ) opMode ) ; else if ( ReflectionUtilities . isParent ( opMode , FullOpMode . class ) ) register . register ( opModeMeta , new FtcOpModeFullOpModeRunner < > ( ( Class < ? extends RobotFullOp > ) opMode ) ) ; else if ( ReflectionUtilities . isParent ( opMode , RobotInitStartStopLoop . class ) ) register . register ( opModeMeta , new FtcOpModeInitStartStopInterfaceRunner < > ( ( Class < ? extends RobotInitStartStopLoop > ) opMode ) ) ; else if ( ReflectionUtilities . isParent ( opMode , RobotInitStopLoop . class ) ) register . register ( opModeMeta , new FtcOpModeStopInitInterfaceRunner < > ( ( Class < ? extends RobotInitStopLoop > ) opMode ) ) ; else if ( ReflectionUtilities . isParent ( opMode , RobotLoop . class ) ) register . register ( opModeMeta , new FtcOpModeInterfaceRunner < > ( ( Class < ? extends RobotLoop > ) opMode ) ) ; else register . register ( opModeMeta , new FtcOpModeRunner < > ( opMode ) ) ; } }
This statically loads OpModes via reflection.
This statically loads OpModes via reflection .
// todo: move this to the appropriate section // todo workaround an the issue of reflectively loading an non-public class