View Package Dependencies in Eclipse - java

Is there any way to view package dependencies in Eclipse? I seem to remember a long time ago that it was possible. I have a packageX and want to see what packages refer to it. Ie packageY references it, but not packageZ.
There seem to be some outdated plugins out there, for example Java Dependency Viewer, but the comments for the plugin say 'don't bother'.

If you mean a java package, there is a possibility: You right-click the package in the project explorer, select References → Workspace and get ... a list of almost no results.
Then you go into the search menu (the small triangle ▿ at the top right border of the search view), select "filters" and uncheck the "imports" box. Then all references to your package within your workspace should appear in the view.

Related

Eclipse doesns't show project explorer properly

I'm using eclipse neon. I have created a maven project and create a package com.prueba.account and then I have created many packages inside.
But eclipse shows me all packages as an independent project and without the full path like in the image. Notice that checking package is inside com.prueba.account
Just Click on the Drop Down in Project explorer. All you need is to change Package presentation from Hierarchical to Flat.
Hope it helps !!!!
First of all, welcome to Stack Overflow Gary.
Then to extend on Adyas Answer:
In Eclipse there are two ways to display the package-structure.
Hierarchical :
And Flat:
I personally find the Hierarchical view way more convenient, for when you're working on a bigger project, you often get really long package names which, when in Flat view, might clutter the whole window.
But in the end, it's up to your personal taste.
The way to change between this two modes is to click on the down arrow icon at the top of the Project Explorer and under Package Presentation you can choose between the two.

Extra top-level directory in "Project Files" view of newly-imported IntelliJ IDEA project

I'm a new convert to IntelliJ IDEA after being an Eclipse user for more than a decade. I have a multi-module Gradle+Java project which I have attempted to import, with the structure:
...projects/chatty/core/
...projects/chatty/service/
...projects/chatty/web/
In Eclipse I would create a 'chatty' workspace and import the three projects separately.
What I'm used to (in IDEA speak) is a list of my modules at the top level, with their content directly underneath. For example:
Module Name
- src/main/java/
- - com.craigotis.package
But what I'm seeing is an extra subdirectory:
Which is unsightly and being on a 13" screen, shifts my class names over an extra ~30 pixels unnecessarily.
I found the 'Show Modules' option in the dropdown, but disabling it removes the top-level module, which leaves the rest of my modules looking a bit off:
I would have preferred to see the top-level module remain, while the intermediate core (~/projects/chatty/core) entry removed. As now, my other modules have directory paths instead of simpler names.
This is my layout in the modules area:
Is there a way to 'clean up' my project view? I'd like to see the src/main/java directly under the simply-named module, which is at the top-level.
I may have botched the import/project creation, I'm still translating the terminology in my head as I go.
Edit: The Project View isn't much better - as the src/main/java source directories are not flattened, and by the time I get a class opened the second half of the name is already obscured.

How can SonarQube be used to view results for specific directories (packages) of a project?

I want to investigate how certain rules and issues have been violated in a certain package, however, from what I have seen in the Components-interface in SonarQube, it is only possible to view leaf node-directories and I am interested in viewing the entire folder, including sub-folders and files in that folder.
E.g.
Project
src
package1
subdirectoryone
done
code-a.java
dtwo
code-x.java
dthree
code-i.java
code-1.java
code-2.java
subdirectorytwo
package2
subdirone
subdirtwo
In this example I would like to investigate the issues and rule violations in subdirectoryone including the code files at all levels in the directory.
Is there a way I can do this?
I use something like this:
<sonar.projectName>Some project name (com/your-directory only)</sonar.projectName>
<sonar.exclusions>org/**/*, com/acme/**/*</sonar.exclusions>
<sonar.test.exclusions>org/**/*, com/acme/**/*</sonar.test.exclusions>
<sonar.sources>${project.build.sourceDirectory}/com/your-directory</sonar.sources>
This excludes everything but the code I want to be analyzed (exclusions properties) and define my source dir as ${project.build.sourceDirectory}/com/your-directory (this is where the code I want to be analyzed is)
Then the analysis is run using maven:
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package -Dtest=com/your-directory/**/*Test.java
(note the -Dtest= restriction for the tests)
Some reading: http://docs.sonarqube.org/display/SONAR/Narrowing+the+Focus
In SonarQube 4.5 if you start from the dashboard and click the Issues link you will see all the issues for every module. In the left box below the lists of Severities and Rules is a list of all the modules and sub-modules in your project. If you select from that list it will narrow down the centre and right boxes to just the packages and files within that module. Unfortunately it doesn't filter the rules or severities in the top boxes.
In SonarQube 5.3 if you go to the issues tab you can select the module checkbox on the left side and select from your high runners. Near the top of the page is a hierarchy for the module you selected which you can click on to see the dashboard for that module or sub-module and then click issues for just that part. Then if you want a sub-module that isn't in high runners note that the URL is editable if you are careful and know your target hierarchy.
I haven't found a better way than that yet in 5.3, but after only a few days playing with a recent 5.3 upgrade I am generally liking the UI changes.

How do I treat warnings as errors in specific Java files?

I am working on a Java project that has a lot of compiler warnings. I can't fix all of them at once, but I would like to ensure that each file that becomes warning-free remains warning-free. Is there a way to turn warnings into errors in specific files or packages? I'm interested in generating the errors with either Eclipse or javac.
In your Eclipse, go to Window > Preferences > Java > Compiler > Errors/Warnings:
Here you could switch any Warning entry to Error. Beware some entries may be hidden by expandable panels, so make sure you expand them all.
At the top right corner you can also select "Configure Project Specific Settings.." if you want to apply this configuration to only a project and not to all projects by default. Alternatively, you can achieve the same by right click on the concerned project > Properties > Java Compiler > Errors/Warnings entry.
Hence, this will be applied to either the whole workspace or just a project, but not to specific files or packages, you don't have this granularity in Eclipse.
This should help you to achieve it, although it might become time and effort consuming to keep it clean, but that's another story.
Moreover, from the Problems view you can create a new Problem View, then from its menu (right top corner of the view, as shown by the picture below), you can configure it.
Once created a new Problems View, you can again use the same menu and select the Configure Contents.. entry. From there, you can create a New configuration (see picture below) and define it only for the select element (if you previously selected the concerned class or package), and define whether you want to see any of Errors, Warnings, Info and from which category.
This configuration could help you out to narrow down and filtering errors and warnings on a specific package or class as a complement or as a different solution/approach than the description above.
Final note: I used Eclipse Mars to try it out, but the functionality should be there since many past versions.

How to import existing project into Workplace in Eclipse?

I am trying to follow Eclipse instructions to create a Hello World SWT application. I have the following instruction:
Import the SWT project from the main
menu via File > Import..., and select
Existing Projects into Workspace.
Specify the archive file you
downloaded and click Finish. This will
create the org.eclipse.swt project
which we will need to compile and run
the application.
I have troubles with that. In the "File" menu I see "Import...". When I click the "Import...", I do not see "Existing Project into Workspace". Instead of that I see "Select an import source:" after which I see a text field. After that I see a field with the following folders: General, CVS, Run/Debug, Tasks, Team, XML.
Can anybody help me with that, pleas?
You need to expand General.
If you expand the 'General' node (folder) you will see 'Existing projects into workspace' as an option. Select that and click on Next.
Eclipse has the wonderful search functionality on most of its important screens. Even if you don't know where exactly it is, you can type it and it appears. In this case type "Existing" into the text field above the list and you'll see what you are looking for.

Categories