score:4
Accepted answer
Looking at the source code, the problem seems to be that it doesn't follow the interfaces hierarchy. If you do that, you find all instances:
package foo
import java.io.File
import org.clapper.classutil.{ClassFinder, ClassInfo}
object Main extends App {
val jar = new File("target/scala-2.11/class_test_2.11-0.1.0.jar")
val finder = ClassFinder(jar :: Nil)
val classes = ClassFinder.classInfoMap(finder.getClasses().iterator)
val impl = find("foo.NamedEntity", classes)
impl.foreach(println)
def find(ancestor: String, classes: Map[String, ClassInfo]): List[ClassInfo] =
classes.get(ancestor).fold(List.empty[ClassInfo]) { ancestorInfo =>
val ancestorName = ancestorInfo.name
def compare(info: ClassInfo): Boolean =
info.name == ancestorName ||
(info.superClassName :: info.interfaces).exists {
n => classes.get(n).exists(compare)
}
val it = classes.valuesIterator
it.filter { info => info.isConcrete && compare(info) } .toList
}
}
score:3
ClassUtil now contains this functionality (v1.4.0, maybe also in earlier versions):
val finder = ClassFinder()
val impl = ClassFinder.concreteSubclasses("foo.NamedEntity", finder.getClasses())
Source: stackoverflow.com
Related Query
- Get all the classes that implements a trait in Scala using reflection
- How do I get all the keys that are stored in the Cassandra 2.0.1 column family with scala using hector?
- How to use scala reflection API to get all contained classes
- scala: how to create a generic type which is subtype of all the number classes in scala so that it can include compare method
- Scala - how to get the 'type' for a field using reflection api
- Scala runtime reflections get all the members of a specific type even for inner classes
- Get private field in Scala trait using Java reflection
- How do I use Scala reflection to find all subclasses of a trait (without using third-party tools)?
- Instantiating all classes that extend trait in Scala
- Get All the instance subclass of trait using Google Guice
- Scala accessing members of runtime types using reflection of a class that extends a trait
- How to get the declaring class / trait using Scala reflection?
- How to get all the children and sub-children of XML file using Scala
- Scala Reflection to get the types of all fields of an object
- Can I use Java reflection to get the value of a member that has been added with a Scala macro annotation?
- Is there a way for a Scala base class to get informed when all the derived classes have been constructed? (guess not)
- How to get all S3ObjectSummary from an S3 bucket using scala and the aws-java-sdk?
- How to get the properties values those that are defined in the shell (bash) script file using Scala 2.11 code?
- Enhance java classes using traits, how to declare inside trait the java fields?
- Using Scala 2.10 reflection how can I list the values of Enumeration?
- Get the row corresponding to the latest timestamp in a Spark Dataset using Scala
- Scala Reflection - Loading or finding classes based on trait
- Using shapeless scala to merge the fields of two different case classes
- How can I get all object vals and subobject vals using reflection in Scala?
- Get the companion object instance of a inner modul with the Scala reflection API
- How do I get the runtime Class of a parameterized Type in a Scala trait
- Scala function that sorts a Seq using the mapping of a generic function
- get all the class names in a package with scala
- Get values of all variables in a case class without using reflection
- List all classes in object using reflection
More Query from same tag
- How in Flink CEP can we detect a pattern that last a period of time?
- Having trouble converted a scala case class to json JObject when it contains an field of type Enumeration
- elasticsearch 1.6 elasticsearch command and code is not working in jdk11
- How to Assign values to a List of Lists in scala using loops?
- Scala infix notation for generics
- Is there a .NET equivalent of Scala's Try?
- Play Framework 2.0. Upgrade bonecp
- Extracting both tuple & individual values in list using pattern matching
- What is the most accurate way to convert org.joda.time.LocalDateTime to java.time.LocalDateTime in scala?
- Auto fixing warnings reported by ScalaStyle
- Scala map list element to a value calculated from previous elements
- Create mapping from string to class type in scala
- Scala: Tail recursive power function
- train simple neural network with deeplearning4j
- find the indices of top n elements in an Array in Scala
- Scala: Building a complex hierarchy of traits and classes
- Folding Curried Functions in Scala
- Spark out of memory when reducing by key
- Cached Spark RDD ( read from Sequence File) has invalid entries, how do i fix this?
- MultipleMatchesException while using react webjar
- How can I find out the Scala supported SBT version
- Dynamic ElasticSearch mapping using Elastic4s
- How to specify credentials for repository with sbt from maven?
- Accessing Java Field annotation from scala
- scala List map vs mapConserve
- Embed a image to eclipse and display it with scala
- Mocking time for Scala Deadline during unit testing
- Scala Parser Combinator: recursion
- rearrange order of spark columns
- Ensure that a scala parent class has a formatter associated with it