Skip to content

Commit

Permalink
Add support for the NoLoad annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
JaciBrunning committed Jun 14, 2015
1 parent 904287d commit d45da06
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/main/java/jaci/openrio/toast/core/loader/RobotLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import jaci.openrio.toast.core.ToastConfiguration;
import jaci.openrio.toast.core.io.usb.MassStorageDevice;
import jaci.openrio.toast.core.io.usb.USBMassStorage;
import jaci.openrio.toast.core.loader.annotation.NoLoad;
import jaci.openrio.toast.core.loader.module.ModuleCandidate;
import jaci.openrio.toast.core.loader.module.ModuleContainer;
import jaci.openrio.toast.core.thread.ToastThreadPool;
import jaci.openrio.toast.lib.log.Logger;
import jaci.openrio.toast.lib.module.ToastIterativeModule;
import jaci.openrio.toast.lib.module.ToastModule;
import jaci.openrio.toast.lib.module.ToastStateModule;

import java.io.File;
import java.io.FilenameFilter;
Expand Down Expand Up @@ -346,7 +345,7 @@ public static void postCore() {
static void parseClass(String clazz, ModuleCandidate candidate) {
try {
Class c = Class.forName(clazz);
if (ToastModule.class.isAssignableFrom(c) && isNotDefault(c)) {
if (ToastModule.class.isAssignableFrom(c) && classLoadable(c)) {
ModuleContainer container = new ModuleContainer(c, candidate);
getContainers().add(container);
if (threaded) {
Expand All @@ -361,8 +360,8 @@ static void parseClass(String clazz, ModuleCandidate candidate) {
/**
* Checks if the class is a default class created by Toast. If it is, ignore it as it serves no purpose.
*/
static boolean isNotDefault(Class clazz) {
return !(clazz.equals(ToastModule.class) || clazz.equals(ToastStateModule.class) || clazz.equals(ToastIterativeModule.class));
static boolean classLoadable(Class clazz) {
return !clazz.isAnnotationPresent(NoLoad.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package jaci.openrio.toast.core.loader.annotation;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
* Placing this annotation on a {@link jaci.openrio.toast.lib.module.ToastModule} class will cause the loader to not
* recognize the module as a valid candidate. This is used for ToastModules that are used as abstract classes or designed
* to be extended by other classes. This should be placed above the class definition.
*
* @author Jaci
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface NoLoad { }
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import edu.wpi.first.wpilibj.Timer;
import jaci.openrio.toast.core.StateTracker;
import jaci.openrio.toast.core.loader.annotation.NoLoad;
import jaci.openrio.toast.lib.state.RobotState;
import jaci.openrio.toast.lib.state.StateListener;

Expand All @@ -11,6 +12,7 @@
*
* @author Jaci
*/
@NoLoad
public abstract class ToastIterativeModule extends ToastStateModule {

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/jaci/openrio/toast/lib/module/ToastModule.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jaci.openrio.toast.lib.module;

import jaci.openrio.toast.core.loader.annotation.NoLoad;
import jaci.openrio.toast.core.loader.module.ModuleContainer;

/**
Expand All @@ -8,6 +9,7 @@
*
* @author Jaci
*/
@NoLoad
public abstract class ToastModule {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jaci.openrio.toast.lib.module;

import jaci.openrio.toast.core.StateTracker;
import jaci.openrio.toast.core.loader.annotation.NoLoad;
import jaci.openrio.toast.lib.state.RobotState;
import jaci.openrio.toast.lib.state.StateListener;

Expand All @@ -13,6 +14,7 @@
*
* @author Jaci
*/
@NoLoad
public abstract class ToastStateModule extends ToastModule implements StateListener.Ticker, StateListener.Transition {

/**
Expand Down

0 comments on commit d45da06

Please sign in to comment.