Automated way to find number of usages? - java

Are there any open source tools that automate the functionality of finding the number of usages of a Java API? I can figure out this information for one class at a time in my IDE. I want to use this information to create a rudimentary report on the speed of adoption of a particular library. I would create a daily report on the number of usages of dozens of classes, and I would report on several code bases.

I'd go with one of those tools for analyzing dependencies in Java code. Let it work on your source tree, a package or a single class and see if you can export the results to XML or something like that. I've used Dependency Finder in a project about two years ago and I think it should do what you want. Not sure about the export to XML, though.

In Eclipse you can right click on a method name or class and go to the References menu and from there you can choose the scope of where you want to search for classes that reference that item.
Is that what you need?

I'm going to try Macker. Its style is to report references to configured classes as errors, but that's fine. It can be run from an automated build. Thanks Robert.

Related

Is there a way to use external libraries in IntelliJ without downloading their .jars?

I am trying to write a standalone Java application in IntelliJ using edu.stanford.nlp.trees.GrammaticalStructure. Therefore, I have imported the module:
import edu.stanford.nlp.trees.GrammaticalStructure;
Currently, Intellij doesn't recognize this and many others of the imported external libraries (cannot resolve the symbols) and is also not able to automatically download/import them.
Is there a way to use the GrammaticalStructure class without having to download the entire Stanford CoreNLP .jar and adding it to the project as a library? This question applies to other dependencies as well, since I want to use other external libraries but avoid including their .jar files as much as possible (to minimize the size of the final application, given that it will be standalone). Unfortunately, all the solutions I have found proposed exactly that.
Apologies if I have overlooked some basic setting or setup steps, it has been a while since I have worked with Java.
Any help is greatly appreciated.
If you want to use it means you want to execute the code in them. How is the runtime supposed to execute code that is does not have? How is the compiler supposed to know how the code is defined (e.g. what the classes look like)? This is simply impossible. If you want to use the code you have to provide it to the compiler as well as the runtime.
If you just dont want to include all of that code into your application, you need either access to the sources and just pick the class you need or you need some kind of JAR minimizer as #CrazyCoder suggested.

File structure in netbeans

I'm trying to understand the file structure in Netbeans.
For example: I want to create a new class. I do so by right clicking the navigation bar, and get prompted to name my new class. A warning appears with the words "It is highly recommended that you do not place Java classes in the default package"
So,
What does go in the "default package"?
What goes in the Test Packages and Test Libraries folders?
If I have some text files or some such thing for my program to read, where should they go?
I'm taking some online courses on Java, but these sort of nuances aren't covered in the classes. I want to start doing it right, right now, so I don't have to untangle all of my files later on down the road.
You should refresh your understanding by reading the tutorial.
The default package is a package that gets created for your project. It's OK to organize your files under the default package, but if your work is somewhat serious, you're going to want to place them under a named (and therefore non-default) package, like com.myorganization.myproject as per the tutorial. NetBeans will also allow you to refactor (rename) an existing package. Left click, hit F2 and supply a new name.
Test packages and libraries used to test your project go in the Test Packages and Test Libraries directories. It sounds like you're a ways off from testing with frameworks like JUnit, however, so you needn't concern yourself with those things just yet.
If you have arbitrary data files, you can really put them wherever you can find them later. If you're working with Android, for example, you'd have a /res directory just under your project root with resources like images, icons, data files, etc. You can create your own resources directory, or you can be lazy and dump them directly in the project root. Wherever you put them, you have to make sure you call them correctly using absolute or relative paths.
If you're using online courses, especially if you're paying for them, use the resources they provide, like live tutors or their forums. This kind of fundamental/tutorial help is a bit below the threshold for Stack Overflow.

What is the best way to save small java programs in NetBeans as far as doing many exercises?

I am planning to do all the exercises from a introduction to java textbook and was wondering how to save each program individually in the IDE NetBeans. Is making a Project for each exercises necessary. I would like to be able to put these problems in order by chapter. Having them in Netbeans would be a great help down the road but if its impossible I was thinking I could always write the program in Netbeans and just save the java and class file in a separate folder.
Thanks for the quick responses I'll be gone for a while to reply to anymore responses.
It is not a necessity to create a project for each exercise. I'm assuming that your exercises are most likely to be single file programs. In that case, you can just use shift + F6 to run the current open file.
You can create a single project, and add different packages/folders in that project. Then you can use your main class to call some sort of class in each package, to start every exercise.
When I worked on tens of exercises while completing AP Course, I always created a new project for all of them. I suggest doing so for the following reasons:
It takes 20s max to create a new project.
It makes your projects nicely organized.
You don't need to change the main method every time you want to run an old project.
It is not very easy to save or load .java file in NetBeans
Making a netbeans project is required, except if these exercices are quite simple and only exist out of one class. Then you can combine multiple excercises in one project as seperate classes.
If you are learning Object Oriented Programming then you will need multiple classes for one exercise I suppose. Then I can recommend you to use 'Project Groups' to arrange exercises by chapter (each chapter is a seperate Project Group). You can find the project groups menu under the file-tab.

Own eclipse plugin - sharing data between plugins

I would like to write small eclipse plugin for code estimation. At start I would like to use results shown in "problems" tab (warnings and errors) instead of writing next, own tool for code analysis. The question is:
Is it possible to use data from one plugin in another?
I would be greatful for any examples or links to tutorials.
Thank you in advance :)
The objects in the Problems view are called 'markers' and are represented by the org.eclipse.core.resources.IMarker interface.
You get the markers defined on a file, folder or project by calling the findMarkers method on the IResource. You can ask for all types of marker or just specific types.

Structural comparison of two ASTs in Eclipse

I am working on an incremental builder for Java code in Eclipse. Eclipse provides a ResourceDelta that tells me which resources have changed since the last build. However, I would like to have more detailed information, e.g. what methods or what field definitions changed. There seems to be functionality similar to what I want in the "compare with -> each other" view. However, this code is quite disconnected from the build engine and seems incompatible with ResourceDeltas. What would be a good way to figure out what I want? The best solution I can see is to compare two ASTs, but I also could not find any built-in support for that.
JavaCore does supply this information via the IElementChangedListener and IJavaElementDelta interfaces. Here's a quick code sample to get you started:
JavaCore.addElementChangedListener(new MyJavaElementChangeReporter(), ElementChangedEvent.POST_RECONCILE);
More details available in Manipulating Java code from the JDT Plug-in Developer Guide.

Categories