Skip to content
Snippets Groups Projects

Removing Reflexion

Open François Henri Théron requested to merge ft/RemovingReflexion into main
3 files
+ 22
25
Compare changes
  • Side-by-side
  • Inline
Files
3
package cs214.webapp.server
package cs214.webapp.server
package utils
package utils
import java.lang.reflect.Modifier
import scala.jdk.CollectionConverters.*
import org.reflections.Reflections
/** Finds all apps under the `apps` package. A class extending `StateMachine` is
/** Finds all apps under the `apps` package. A class extending `StateMachine` is * considered to be an app. */
* considered to be an app.
*/
object AppsLoader:
object AppsLoader:
private val APPS_PACKAGE = "apps"
private val APPS_PACKAGE = "apps"
 
private var isSet = false
def loadApps(): List[Class[?]] =
// List that should be overwritten by a real StateMachine list !
val reflections = new Reflections(APPS_PACKAGE)
private var _apps : List[StateMachine[?,?,?]] = List.empty
reflections
.getSubTypesOf(classOf[StateMachine[?, ?, ?]])
private[server] def loadApps(): List[StateMachine[?,?,?]] = _apps
.asScala
.toList
//Sets the app loader to use this list
.filterNot(cls => Modifier.isAbstract(cls.getModifiers) || cls.isInterface())
def setApps(apps : List[StateMachine[?,?,?]]): Unit =
 
if (!isSet) then
 
_apps = apps
 
isSet = true
 
else
 
println("Apps list can't be set twice")
 
\ No newline at end of file
Loading