Java Features

Code Refactoring

With Codenvy, you can rename classes, variables and fields without breaking the code and changing its functionality. The refactoring feature is available at Edit menu or can be called with Alt+Shift+R hotkey (make sure your hotkeys are properly configured. See: Using Keyboard Shortcuts).

warning Alt+Shift+R hotkey is unavailable in Chrome. Please, use Rename command from the Edit menu.

  • set the cursor on the class, variable or a field you want to rename (Java class in the below example), go to Edit > Refactor menu or use Alt+Shift+R hotkey
  • enter a new name for the class and click on Rename

refactor

  • Codenvy will need a few seconds to rename the class and update project structure. Once the project is updated, the class will have a new name wherever it is used, including Project/Package explorer

refactor_class

You might want to take a quick look at the below video demonstrating convenience of Refactoring in Codenvy.

Code Outline

Code Outline is available for most file types. It opens automatically once the file has been created or opened. To enable/disable Outline click on outline icon on the toolbar or go to View > Outline.

This feature opens a vertical panel on the right presenting an outline of the file’s structure, allowing you to navigate through the file.

For instance, Code Outline for a Java class will show you packages, import declarations and methods. Click on any string in the Outline tab and you will see that the corresponding line code is highlighted. (see screenshot below).

classfileoutline

Here’s another example. This time it’s the pom.xml file of a simple Java Spring project.

pomxml

Error Marking

Error marking – underlining, icons and prompts – will help you fix errors more efficiently. By default, error marking is off. It can be enabled at Project > Show Syntax Error Highlighting.

Non-critical errors are marked with yellow icons bulb placed opposite the lines that contain errors. Wavy underlining is used directly in the editor to draw your attention to exact parts of the code that need editing. In the example below, an unused import statement is emphasized:

error_marking

If you click on this yellow bulb, you will some suggestions to fix the error. You can double click on any of the options or fix the error manually.

error_marking_prompt

Critical errors are marked with bulb_red icons. As long as as you have unresolved critical errors, bulb icons will be invisible to let you focus on those critical error. In addition to bulb_red icons, red wavy underlining is used to mark the problematic portion of your code.

error_syntax

Code Autocompletion

Codenvy supports code auto-completion for Java. The auto-completion command is called by the Ctrl+Space key combination.

The example below demonstrates autocompletion for an import declaration in a Java class file:

autocomplete

While auto-completing, you can view the javadoc by leaving the cursor on the method or class for a few seconds :

autocomplete_vocab

Package Explorer

The Package Explorer view is specific to Java projects. It organizes projects by folders, packages, class files, referenced libraries and other files. The Package Explorer view opens automatically when a Java project is opened/created. To switch off a Package view click on package_explorer icon on the toolbar or go to Window > Show View > Package Explorer

Take a quick look at this video showing the Package Explorer View in action.

Publishing JAR Projects and Managing Project Dependencies

You can create and publish Java libraries (i.e. JAR projects) and re-use them in other Java projects.

  • create a JAR project or open an existing one.
  • go to Project > Build and Publish. This process might take a moment. The result will be displayed in the Output tab (dependency details and download URL of your artifact)

The library is now published and can be used in other projects.

      • open or create a new project
      • get to its pom.xml file
      • add a new dependency (either from the library you have previously created (see the screenshot above) or from any other publicly available libraries), for example:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
      • save the project
      • update the dependency at Project > Update Dependency

Here’s a short video demonstrating how to build and publish Java Libraries and use them in other projects:

Using JRebel

Currently, JRebel is unavailable
JRebel Plugin makes it possible to see code changes without redeploying your application.

When choosing a template for your Java project, you will see the JRebel checkbox.

jrebel

      • Check the box, complete the form, click Finish and open your project.
      • Run your app from Run menu.
      • Make changes to the code, save the project and Update the app from the Run menu.

The JRebel plugin monitors class files and resources to update them almost instantly. No redeployment means time savings.

Here’s a detailed video demonstrating the power of JRebel:
http://www.youtube.com/watch?feature=player_embedded&v=ZO_zVEwtBV4

Clone a Multi Module Project

You can clone a project consisting of more than one module (jar+war packaging, for example) from a remote repo, build and publish the entire project and publish its modules independently. For more details about cloning remote repositories visit Git section of this User Guide.

Once a multi module project is successfully cloned you can:

      • first off, build and publish the entire project
      • build each module separately one by one

multimodule

In the below video you will find some additional information on multi module project support in Codenvy:


Code Folding

With Codenvy, it’s possible to fold and unfold chunks of code in Java class files to have a better code view. See screenshots below:

foldcode

unfold

Folding is automatically applied to comments, imports, methods and nested classes, but it’s also possible to fold code selection manually. To do so, select a chunk of code you want to fold and go to Edit > Fold Selection.

Block Comments

You can add comments in Java class files, with two types of comments currently supported:

      • //sample text, where the compiler ignores any text after from // till the end of line. Go to Edit > Toggle Comment

comments

      • /*sample text*/, where compiler ignores any text between /* tags. Go to Edit > Add Block Comment

block_comments

You can delete block comments at Edit > Remove Block Comment
Up ↑