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:
-
Right-click the
MVCPortlet
declaration. -
Select Open Type Hierarchy.
This opens a window that lets you inspect all classes residing in the target
platform that extend MVCPortlet
.
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:
-
Right-click the
doView
method declaration in your custom app’s class. -
Select Declarations → Workspace.
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:
-
Right-click the
@Reference
annotation in a class. -
Select References → Workspace.
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!