Skip to content

Commit

Permalink
Add TypeUtil.whitelistPackages, so the set of exported models can expand
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Hester committed Jul 2, 2012
1 parent 240727f commit 8dac1cf
Showing 1 changed file with 14 additions and 4 deletions.
Expand Up @@ -21,6 +21,7 @@ import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.lang.reflect._
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl
import scala.collection.mutable.ListBuffer

object TypeUtil {
/**
Expand Down Expand Up @@ -117,10 +118,14 @@ object TypeUtil {
private def checkAndAddConcreteObjectType(classType:Type, list: java.util.List[String]) {
if (classType.getClass.isAssignableFrom(classOf[Class[_]])){
val listType: Class[_] = classType.asInstanceOf[Class[_]]
if (listType.getName.startsWith(WORDNIK_PACKAGES)) list.add(listType.getName)
if (isInterestingPackage(listType.getName)) list.add(listType.getName)
}
}

private def isInterestingPackage(name: String) = {
whitelistPackages.exists { p => name.startsWith(p) }
}

/**
* Get all classes references by a given list of classes. This includes types of method params and fields
*/
Expand Down Expand Up @@ -164,7 +169,7 @@ object TypeUtil {
}
case _ =>
}
if (fieldClass.startsWith(WORDNIK_PACKAGES)) {
if (isInterestingPackage(fieldClass)) {
referencedClasses.add(fieldClass)
}
else {
Expand All @@ -185,7 +190,7 @@ object TypeUtil {
}
case _ =>
}
if (methodReturnClass.startsWith(WORDNIK_PACKAGES)) {
if (isInterestingPackage(methodReturnClass)) {
referencedClasses.add(methodReturnClass)
}
else {
Expand All @@ -209,8 +214,13 @@ object TypeUtil {
}

private final val LOGGER: Logger = LoggerFactory.getLogger(TypeUtil.getClass().getName())
private final val WORDNIK_PACKAGES: String = "com.wordnik."
private final val REFERENCED_CLASSES_CACHE: java.util.Map[String, java.util.Set[String]] = new java.util.HashMap[String, java.util.Set[String]]

/**
* If you'd like to emit models for other namespaces, adjust this sequence in your
* application.
*/
val whitelistPackages = ListBuffer("com.wordnik.")
}


0 comments on commit 8dac1cf

Please sign in to comment.