Skip to content

Languages: Java

Mykhailo Lytvyn edited this page Jan 3, 2024 · 16 revisions

Advanced Debugger

This feature is based on IntelliJ IDEA Custom Type Renderers.

SAP Commerce Models are not easy to debug due fact that they have only single field ctx which is available in the Debug preview.

This means that every time there is a need to get a value from the SAP Commerce Model’s attribute or relation, one must execute Code Evaluation.

But with the Plugin it is possible to preview all attributes / relations / collections / maps in the Debugger preview for SAP Commerce Models thanks to created on-the-fly custom Java Type Renderers.

For model Item fields which require additional evaluation (such as relations), the Plugin adds lazy evaluation of the values, handled by On-demand flag of the configured custom expression.

How to use

Take a note that the Java Type Renderers are not Project specific.

It means that if multiple SAP Commerce projects sharing the same model Item one has to refresh the Type Renderer beforehand to grab current Project item type details.


Icon is added every time when the Plugin identifies model Item.

During the debug session if the Plugin identifies SAP Commerce model Item, it adds new action [y] Create Type Renderer in the corresponding node.

Screenshot 2023-12-27 at 16 50 11

When clicked new Type Renderer will be created name of [y] <Class_Name> and available via Application Settings Java Type Renderers.

image

If custom Type Renderer is already defined for a model Item, the Plugin will add different action [y] Refresh Type Renderer.

This Action will re-read Item definition in the current Project and re-create custom Type Renderer.

image

In Code Features

Language Injection

Detailed FlexibleSearch language injection covered in the corresponding section of the FlexibleSearch: Language Injection - Java wiki.

If FlexibleSearch specific elements identified in the Java string literals, FlexibleSearch language will be injected accordingly.

Injection is supported for different string literals declared as constants or variables. Injection is NOT supported for method parameters.

  • Simple string: "SELECT {PK} FROM {Product}"
  • Multiline string: """SELECT {PK} FROM {Product}"""
  • Complex string with concatenation: "SELECT {PK} FROM {" + ProductModel._TYPECODE + "}"
image


Gutter pane icon which copies complete & auto-formatted FlexibleSearch to the clipboard and placed on a same line as FlexibleSearch string literal.

image

Inline hint for dynamic attributes

Official documentation for Dynamic Attributes.

Spring Bean reference resolution covered in the corresponding wiki section Spring.

The Plugin supports both declarations of the dynamic handler.

  • via <persistence attributeHandler="..."/>
  • via Spring Bean id of <ItemtypeCode>_<attributeQualifier>AttributeHandler

Dynamic handlers and logic behind may cause unexpected performance degradation. To ensure that Model's dynamic attribute is used on purpose the Plugin adds inline hint for getter and setter methods.

There are two possible types of the hint.

  • dynamic - just an indicator that corresponding method is using dynamic handler behind the scene.
  • dynamic⌝ - indicates that the Spring Bean declared via persistence tag has been resolved, command + click on the hint will open corresponding Spring Bean class.
image

Live Templates

Official JetBrains documentation on Using Live Template.

ysri - injects template code for Spring dependency injection via @Resource annotation.

@Resource(name = "<bean_id>")
private <Bean_Class> <field_name>;
image

log4j2 - injects template code for Log4j2 Logger and takes current class name as an argument for Logger factory.

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
...
private static final Logger LOG = LogManager.getLogger(<Class_Name>.class);
...
image

slf4j - injects template code for SLF4J Logger and takes current class name as an argument for Logger factory.

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
...
private static final Logger LOG = LoggerFactory.getLogger(<Class_Name>.class);
...
image

Generated Models

This feature depends on IntelliJ IDEA Project Index completion, only once Index is ready corresponding references will be resolved and available as navigable icons in the Gutter pane.

Navigate to the Enum or Item declaration in the items.xml from every generated Model class, which resides in the models.jar file or located in the bin/platform/bootstrap/gensrc directory.

If target Type identified new icon will be added to the Gutter pane and will navigate to the declaration on user click.

In case of multiple declarations of the same Type the Plugin will show list of all declarations on corresponding icon click.

Enum

SAP Commerce supports two types of Enums and both are supported by the Plugin.

  • non-dynamic - generates of the Java Enum
  • dynamic - generates special Java Class

If there are multiple declarations click on a Type Gutter Icon will list all of them.

image


Gutter pane icon leads to Enum declaration and placed on a same line as Enum class.
image


Gutter pane icon leads to Enum - value declaration and placed on a same line as Enum class.
image

Item

If there are multiple declarations click on a Type Gutter Icon will list all of them.

Screenshot 2023-12-27 at 12 10 41


Gutter pane icon which leads to Item declaration and placed on a same line as Item class.
image


Gutter pane icon which evaluates Item's interceptors and placed on a same line as field constant name of _TYPECODE.

This feature relies on IntelliJ IDEA Ultimate edition and Spring plugin.

image image


Gutter pane icon leads to Relation declaration and placed on a same line as a field constant of the relation used by the Item.
Value of the constant is taken to identify the Relation by its case-insensitive name.
image


Gutter pane icon leads to Item - ordering attribute declaration.
It is placed on a same line as a field constant of the ordering attribute used by the Item, its value is taken to identify the ordering attribute by its case-insensitive name.
Ordering attribute is a result of the ordered one-2-many relation with ordered flag set to true for many side of the Relation.

image


Gutter pane icon leads to Item - attribute declaration. There are two places in the file where this icon is added.

First of all, it is placed on a same line as a field constant of the attribute used by the Item, its value is taken to identify the attribute by its case-insensitive name.
image

Secondly, it is placed on a same line as a method annotation @Accessor, its parameter's qualifier value is taken to identify the attribute by its case-insensitive name. Both getter and setter methods are supported.
image


Gutter pane icon leads to Relation - source declaration.
Gutter pane icon leads to Relation - target declaration.

Both icons will be added in a same way as Item attribute (at constant field and method levels), the Plugin will distinguish attribute declaration from the relation qualifier on its own.