Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8116323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:47:32+00:00 2026-06-06T03:47:32+00:00

I want to build some statistics on which Java standard library classes (those in

  • 0

I want to build some statistics on which Java standard library classes (those in java.*/javax.*) and methods are used in some Scala source code (and how often).

What would be the most straightforward way to do that? Is there a chance to also cover transitive dependencies, e. g. when some Lift class depends on a Scala standard library method which in turn depends on a Java standard libraries method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T03:47:35+00:00Added an answer on June 6, 2026 at 3:47 am

    I wrote a Scala compiler plugin, which solved this issue for me. It is not pretty but it does its job.

    The main part doing the work looks like this:

    for (tree <- unit.body) {
      tree match {
        case tree@DefDef(mods, name, tparams, vparamss, tpt, rhs)
          if isJavaAndNotAccessor(mods, rhs.symbol) =>
          printJava(rhs, "DefDef")
    
        case tree@ValDef(mods, name, tpt, rhs) =>
          if (isJavaAndNotAccessor(mods, tpt.symbol))
            printJava(tpt, "ValDef")
          tpt.tpe.typeArgs.foreach(t => findAllJavaTypes(t.baseTypeSeq.toList).foreach(sym => printJavaCustom(sym, posWithFallback(sym.pos, tree.pos), "TpeArg")))
    
        case tree@Template(parents, self, body) =>
          parents.foreach(p => findAllJavaTypes(p.tpe.baseTypeSeq.toList).foreach(sym => printJavaCustom(sym, posWithFallback(p.pos, tree.pos), "TpeDef")))
    
        case tree@Select(qual, name) =>
          if (isJavaAndNotJLObjectInit(tree.symbol) && (tree.symbol.isMethod || tree.symbol.isValue || tree.symbol.isStaticMember))
            printJava(tree, "Select")
    
        case _ =>
      }
    }
    
    private def findAllJavaTypes(types: List[Type]): List[Symbol] = {
      def find0(types: List[Type], result: List[Type]): List[Type] =
        if (types == List())
          result
        else
          find0(types.flatMap(_.typeArgs), types.filter(tpe => isJavaAndNotJLObject(tpe.typeSymbol)) ::: result)
    
      find0(types, List()).distinct.map(_.typeSymbol)
    }
    

    Code is hosted here: https://github.com/soc/scala-compilerplugin-javausagecounter

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to build some lists (a, b, c, d) by extending periodically those
What I want to do is build some mini cms which hold pages with
I want to build a service which needs to get this data from some
I want to build some package from source ( e2fsprogs to be more concrete)
So I want to build some automated guidance for our architecture. I found the
Basically I want to build a website based on some original content, the content
I want to build a workspace with subversion, and I followed some tutorials; Install
I want to build a security related application. I would be storing some important
I want to build some libraries into executables that I need to use with
I want to build some GUI where an image is presented, and the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.