In Liferay Developer 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 a
custom app 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 Developer 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 an search classes that extend that same class in Developer Studio by
right-clicking the MVCPortlet
declaration and selecting 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. Liferay Developer 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’d like to search for declarations of its doView
method you’re overriding. You can do this by right-clicking the doView
method
declaration in your custom app’s class and selecting 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. With the ability to search where these types of annotations reside in Liferay’s target platform, you can find how they could be used in your own app.
For example, you may find some official 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 could search for this by right-clicking the annotation in a
class and selecting 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!