Searching Liferay DXP Source in Dev Studio

In Liferay Dev Studio, you can search through Liferay DXP’s source code to aid in the development of your project. Liferay provides great resources to help with development (e.g., official documentation, docs.liferay.com, sample projects, etc.), but sometimes searching through Liferay’s codebase (i.e., platform and official apps) for patterns is just as useful. For example, if you’re creating an application that extends a class provided in Liferay’s portal-kernel JAR, you can inspect that class and research how it’s used in other areas of Liferay DXP’s codebase.

To do this, you must be developing in a Liferay Workspace. Liferay Workspace is able to provide this functionality by targeting a specific Liferay DXP version, which indexes the configured Liferay DXP source code to provide advanced search. See the Managing the Target Platform in Liferay Workspace tutorial for more information on how this works.

Workspace does not perform portal source indexing by default. You must enable this functionality by adding the following property to your workspace’s gradle.properties file:

target.platform.index.sources=true

In this tutorial, you’ll explore three use cases where advanced search would be useful.

These examples are just a small subset of what you can search in Liferay Dev Studio. See Eclipse’s documentation on Java Search for a comprehensive guide.

Search Class Hierarchy

Inspecting classes that extend a similar superclass can help you find useful patterns and examples for how you can develop your own app. For example, suppose your app extends the MVCPortlet class. You can search classes that extend that same class in Dev Studio. Complete the steps below for a simple example:

  1. Right-click the MVCPortlet declaration.

  2. Select Open Type Hierarchy.

This opens a window that lets you inspect all classes residing in the target platform that extend MVCPortlet.

Figure 1: Browse the Type Hierarchy window and open the provided classes for examples on how to extend a class.

Figure 1: Browse the Type Hierarchy window and open the provided classes for examples on how to extend a class.

Great! Now you can search for all extensions and implementations of a class/interface to aid in your quest for developing the perfect app.

Search Method Declarations

Sometimes you want a search to be more granular, exploring the declarations of a specific method provided by a class/interface. Dev Studio’s advanced search has no limits; Liferay Workspace’s target platform indexing provides method exploration too!

Suppose in the MVCPortlet class you’re extending, you want to search for declarations of its doView method you’re overriding. Here’s how to do it:

  1. Right-click the doView method declaration in your custom app’s class.

  2. Select DeclarationsWorkspace.

Figure 2: All declarations of the method are returned in the Search window.

Figure 2: All declarations of the method are returned in the Search window.

The rendered Search window displays the other occurrences in the target platform where that method was overridden.

Search Annotation References

Annotations used in Liferay DXP’s source code can sometimes be cryptic. You can find out how they can be used in your own application by searching for where these types of annotations exist in Liferay’s target platform.

For example, you may find some documentation on using the @Reference annotation in an OSGi module and implement it in your custom app. It could be useful to reference real world examples in Liferay DXP’s apps to check how it was used elsewhere. You can complete this search like this:

  1. Right-click the @Reference annotation in a class.

  2. Select ReferencesWorkspace.

Figure 3: All matching annotations are displayed in the Search window.

Figure 3: All matching annotations are displayed in the Search window.

The rendered Search window displays the other occurrences in the target platform where that annotation was used.

Excellent! You now have the tools to search the configured target platform specified in your Liferay Workspace!

« Using the Gogo Shell in Dev StudioDebugging Liferay DXP Source in Dev Studio »
この記事は役に立ちましたか?
0人中0人がこの記事が役に立ったと言っています