Skip to content

Eclipse Settings

Daniel Dietsch edited this page Feb 11, 2022 · 8 revisions

This page collects advanced settings and plugins for Eclipse. Before you use them, make sure you have successfully configured Ultimate in Eclipse because the setup takes some time.

Code analysis plugins

The following plugins help you analyze your code automatically. You can install them via the Eclipse Marketplace (Help -> Eclipse Marketplace...) or just follow the links below and drag the install icon in your Eclipse window.

  1. SonarLint
  2. Checkstyle Plug-in (Note: There are other plugins with the prefix "Checkstyle".)
  3. FindBugs Eclipse Plugin

You have to restart Eclipse afterward. SonarLint synchronizes its rules with our SonarQube server. Checkstyle and FindBugs use local rules, so reports might not always be accurately mirrored without servers. In most cases, the reports should still be valid.

Below are our configuration suggestions.

SonarLint

Instructions for SonarLint for Eclipse 4.1, March 2019.

Server configuration

  • Go to Window -> Show View -> Other..., type SonarLint Bindings, and select it.
  • Find the new SonarLint Bindings view in your workspace and select Connect to a SonarQube server... (only displayed when you did not already connect to some server. Alternatively you can right-click inside the SonarLint Bindings view and select New Server connection...).
  • Select SonarQube.
  • Use the following URL: https://sonar.sopranium.de.
  • Select Username + Password (or generate a personal token if you have an SSO account).
    • Username: ultimate
    • Password: ultimate
  • Keep the connection name sonar.sopranium.de.

Project binding configuration

  • In the Project Explorer view or Package Explorer view, mark the projects you want to work with. If you want to work with all projects, mark them as follows.
    • Mark all projects in your Ultimate workspace.
    • Unmark all projects that already have Sonar bindings.
    • Unmark non-Java projects like Servers, BA_*, Web*.
    • Unmark all test projects (end in Test).
  • Right-click on the marked projects and select SonarLint -> Bind to SonarQube or SonarCloud....
    • Keep the pre-selected server sonar.sopranium.de and click Next >
    • Enter de.uni_freiburg.informatik.ultimate:mavenparent and click Finish.

Other settings

You may want to deactivate sending anonymous data: Window -> Preferences -> SonarLint -> Miscellaneous -> Share anonymous SonarLint statistics

Deactivating automatic analysis

If you want to deactivate the automatic analysis of all files, you have to right-click a project in the Package/Project Explorer, go to SonarLint, and uncheck Run SonarLint automatically. This creates a folder .settings in the respective project folder. Instead of manually setting this option for all projects that you want to exclude, you can copy this folder to the respective project folders. Linux users may want to use this script which creates the folder in all projects.

If you deactivate automatic analysis, you may want to set a shortcut key for manual analysis of the currently opened source file. See the description below for how to set shortcut keys - the name of the setting is Analyze.

Usage

  • SonarLint automatically analyzes your files (during build, when you save, etc.) unless you deactivated it. To manually run an analysis, right-click a project, package, or source file in the Package/Project Explorer and select SonarLint -> Analyze (or use the shortcut key if you have configured it).
  • The analysis results are shown in a separate view called SonarLint Report. The view should open whenever an analysis terminates, but you can also find it under Window -> Show View -> Other... after typing SonarLint Report.
  • You can right-click a line in the SonarLint Report view and select Rule description. This opens another view with more explanations.

Ignoring a SonarLint rule

In certain cases, it may be necessary to tell SonarLint that it should ignore a rule because it is justified in this particular case. You can use the annotation @SuppressWarnings("<ruleid>") or @SuppressWarnings({"<ruleid1>", "<ruleid2>",...}) for this purpose. The suppressed warning will still show up as violation of rule S1309, but this rule has just information level and serves as reminder for all the places where warnings were ignored.

Eclipse will per default also issue a warning about an unknown warning type. To configure Eclipse to ignore those unknown warning types, go to Window -> Preferences -> Java -> Compiler -> Errors/Warnings -> Annotations and change Unhandled token in '@SuppressWarnings' from Warning to Ignore.

Checkstyle

Configuration

Go to Window -> Preferences -> Checkstyle

  • New -> External Configuration File -> Enter some name (e.g., Ultimate) and the location of this configuration file.
  • Set the new configuration as default (Set as Default).
  • Eclipse asks you to do a full rebuild afterward.

Usage

  • You have to start the analysis manually. Right-click a project, package, source file, or the currently opened source file and select Checkstyle -> Check Code with Checkstyle.
  • To see the results, go to Window -> Show View -> Other..., type Checkstyle violations, and select it.
  • You can double-click or right-click a violation type to see all occurrences.
  • To clear the logs, right-click the respective files and select Checkstyle -> Clear Checkstyle violations.

FindBugs

Configuration

Go to Window -> Preferences -> Java -> FindBugs

  • Reporter Configuration: Activate Malicious code vulnerability and Security
  • Plugins and misc. Settings: Deactivate FindBugs Communal ... and FindBugs Cloud ...
  • Detector configuration: Activate all detectors except CheckExpectedWarnings, EmptyZipFileEntry, and PublicSemaphores

Usage

  • You have to start the analysis manually. Right-click a project, package, source file, or the currently opened source file and select Find Bugs -> Find Bugs.
  • To see the results, go to Window -> Show View -> Other..., type Bug report, and select it.
  • You can right-click a bug report and select Show Bug Info for more information.
  • To clear the logs, right-click the respective files and select Find Bugs -> Clear Bug Markers.

Eclipse settings

  • Eclipse creates its own .gitignore files per project by default. Since we use a global .gitignore file for Ultimate in the root directory of the repository, those generated .gitignore files might interfere with our global ignores if they are accidentally pushed. Go to Window -> Preferences -> Team -> Git -> Projects and uncheck Automatically ignore derived resources by adding them to .gitignore.

  • You may want to deactivate automatic building. This option is found under Project -> Build Automatically.

  • Use the Package Explorer instead of the Project Explorer. It allows you to select all projects at once and refresh (Ctrl+A, F5) even if you have closed projects in the selection. You find it under Window -> Show View.

  • If you want to set the default user name that is predefined, e.g., when you create a new class documentation, edit your eclipse.ini file in the installation folder of Eclipse. Adapt the following line and insert it after -vmargs:

    -Duser.name=John Doe ([email protected])

    You can also set the amount of memory dedicated to Eclipse in this file. The changes only apply after you restart Eclipse.

  • You may want to change or set shortcut keys. Go to Window -> Preferences -> General -> Keys, choose the respective action, click the free space next to Binding, and enter the key combination. Existing assignments have to be deleted first (Backspace).

  • To activate Java source view (for built-in classes) you need to download the sources (e.g., under Linux there are usually packages called java-1.8.0-openjdk-src or similar). Then go to Window -> Preferences -> Java -> Installed JREs, double-click your Java version, select rt.jar, click Attach Sources, and choose the path to the source file src.zip. Under Linux this file is usually situated in /usr/lib/jvm/java-1.8.0-openjdk-***/. Eclipse may automatically find the file.

  • Eclipse supports automatic code formatting. If you want to use it, we recommend to use this code formatter template to avoid reformatting all the code in a different style. For setting up the formatter, go to Window -> Preferences -> Java -> Code Style -> Formatter, click Import, and choose the file. You can then format the currently opened source file through Source -> Format or by using the shortcut key Ctrl+Shift+F.

  • To speed up the start, you can deactivate plugins in Window -> Preferences -> General -> Startup & Shutdown. There you can also set the option Refresh workspace on startup.

  • To shrink package names in the Package Explorer, go to Window -> Preferences -> Java -> Appearance, check the option for Compress all ..., and enter some pattern, e.g., 2. for two-letter abbreviations.

  • Eclipse supports helpful automatic actions when you save a file. Go to Window -> Preferences -> Java -> Editor -> Save Actions and enable the feature. We suggest to use at least Organize imports and Additional actions. See the following screenshot for the full list that we recommend.

    picture currently not available

  • Set the print margin to 120 symbols. Go to Window -> Preferences -> General -> Editors -> Text Editors, check Show print margin, and set the number to 120.

  • If you want to use a dictionary, go to Window -> Preferences -> General -> Editors -> Text Editors -> Spelling and choose the path.

  • If you want to change code annotations (e.g., yellow underlining of warnings), go to Window -> Preferences -> General -> Editors -> Text Editors -> Annotations and choose your settings.

  • The Java compiler has many warnings that can help you detect bugs early during development. To activate those warnings, go to Window -> Preferences -> Java -> Compiler -> Errors/Warnings and select those that you prefer. See the following screenshot for the full list that we recommend.

    picture currently not available

Clone this wiki locally