Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added possibility to preview preformatted Flexible Search Queries and copy them to Clipboard #118

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/META-INF/optional-java-dependencies.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<codeInsight.lineMarkerProvider language="JAVA" implementationClass="com.intellij.idea.plugin.hybris.codeInsight.daemon.BSPropertyLineMarkerProvider"/>
<codeInsight.lineMarkerProvider language="JAVA" implementationClass="com.intellij.idea.plugin.hybris.codeInsight.daemon.BSTypeLineMarkerProvider"/>
<codeInsight.lineMarkerProvider language="JAVA" implementationClass="com.intellij.idea.plugin.hybris.codeInsight.daemon.PopulatorLineMarkerProvider"/>
<codeInsight.lineMarkerProvider language="JAVA" implementationClass="com.intellij.idea.plugin.hybris.codeInsight.daemon.FlexibleSearchQueryLineMarkerProvider"/>

<codeInsight.inlayProvider language="JAVA" implementationClass="com.intellij.idea.plugin.hybris.codeInsight.hints.HybrisDynamicAttributeInlayProvider"/>
</extensions>
Expand Down
11 changes: 3 additions & 8 deletions resources/META-INF/optional-lang-dependencies.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,9 @@
<langCodeStyleSettingsProvider
implementation="com.intellij.idea.plugin.hybris.impex.formatting.ImpexLanguageCodeStyleSettingsProvider"/>

<lang.foldingBuilder language="Impex"
implementationClass="com.intellij.idea.plugin.hybris.impex.folding.ImpexFoldingBuilder"/>

<lang.foldingBuilder language="Impex"
implementationClass="com.intellij.idea.plugin.hybris.impex.folding.ImpexFoldingLinesBuilder"/>

<lang.foldingBuilder language="Impex"
implementationClass="com.intellij.idea.plugin.hybris.impex.folding.ImpexMacroFoldingBuilder"/>
<lang.foldingBuilder language="Impex" implementationClass="com.intellij.idea.plugin.hybris.lang.folding.ImpexFoldingBuilder"/>
<lang.foldingBuilder language="Impex" implementationClass="com.intellij.idea.plugin.hybris.lang.folding.ImpexFoldingLinesBuilder"/>
<lang.foldingBuilder language="Impex" implementationClass="com.intellij.idea.plugin.hybris.lang.folding.ImpexMacroFoldingBuilder"/>

<breadcrumbsInfoProvider implementation="com.intellij.idea.plugin.hybris.impex.assistance.ImpexColumnBreadcrumbsProvider"/>

Expand Down
1 change: 1 addition & 0 deletions resources/META-INF/plugin-release-info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<![CDATA[
<ul>
<li> Introduced the Bean System Management - the powerful tool to observe SAP Commerce bean system </li>
<li> Added possibility to preview preformatted Flexible Search Queries and copy them to Clipboard </li>
<li> Added customized Structure View for beans.xml files </li>
<li> Added new beans.xml inspection rules </li>
<li> Added navigation to items.xml Type attributes from generated classes </li>
Expand Down
27 changes: 14 additions & 13 deletions resources/i18n/HybrisBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,20 @@ hybris.editor.gutter.alternativeDefinitions=Alternative definitions
hybris.editor.gutter.alternativeDefinition=Alternative definition
hybris.editor.gutter.spring.bean.definitions=Spring bean definitions
hybris.editor.gutter.spring.bean.definition=Spring bean definition
hybris.editor.gutter.fsq.tooltip=<strong>Preview of the Flexible Search Query</strong> (<i>click to copy</i>)
hybris.editor.gutter.fsq.name=Flexible Search Query preview and copy to Clipboard
hybris.editor.gutter.fsq.notification.title=Flexible Search Query copied to Clipboard
hybris.editor.gutter.bs.enum.value.title=Navigate to the Enum value declaration
hybris.editor.gutter.bs.bean.property.title=Navigate to the Bean property declaration
hybris.editor.gutter.bean.type.navigate.choose.class.title=Choose Bean
hybris.editor.gutter.bean.attribute.navigate.choose.class.title=Choose Attribute
hybris.editor.gutter.item.class.tooltip.navigate.declaration=Navigate to the SAP Commerce item declaration(s)
hybris.editor.gutter.item.attribute.tooltip.navigate.declaration=Navigate to the SAP Commerce attribute declaration(s)
hybris.editor.gutter.navigate.no.matching.beans=No matching beans found
hybris.editor.gutter.navigate.no.matching.attributes=No matching attributes found
hybris.editor.gutter.navigate.no.matching.populators=No matching populators found
hybris.editor.gutter.populator.class.navigate.choose.class.title=Choose Populator
hybris.editor.gutter.populator.class.tooltip.navigate.declaration=Navigate to the SAP Commerce populator

hybris.inspections.ts.AttributeHandlerMustBeSetForDynamicAttribute.key=[y] Attribute handler must be defined for Dynamic Attribute
hybris.inspections.ts.DeploymentTypeCodeMustBeUnique.key=[y] Deployment type code must be unique
Expand Down Expand Up @@ -258,19 +272,6 @@ hybris.project.import.gradle=Configuring Gradle modules
hybris.project.import.data.sources=Configuring Data Sources
hybris.project.import.compiler=Configuring compiler

hybris.gutter.navigate.no.matching.beans=No matching beans found
hybris.gutter.navigate.no.matching.attributes=No matching attributes found
hybris.gutter.bs.enum.value.title=Navigate to the Enum value declaration
hybris.gutter.bs.bean.property.title=Navigate to the Bean property declaration
hybris.gutter.bean.type.navigate.choose.class.title=Choose Bean
hybris.gutter.bean.attribute.navigate.choose.class.title=Choose Attribute
hybris.gutter.item.class.tooltip.navigate.declaration=Navigate to the SAP Commerce item declaration(s)
hybris.gutter.item.attribute.tooltip.navigate.declaration=Navigate to the SAP Commerce attribute declaration(s)

hybris.gutter.navigate.no.matching.populators=No matching populators found
hybris.gutter.populator.class.navigate.choose.class.title=Choose Populator
hybris.gutter.populator.class.tooltip.navigate.declaration=Navigate to the SAP Commerce populator

hybris.module.dependencies.diagram.provider.name=[y] module dependencies

hybris.stats.permission.no=I disagree
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of "hybris integration" plugin for Intellij IDEA.
* Copyright (C) 2014-2016 Alexander Bartash <AlexanderBartash@gmail.com>
* This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA.
* Copyright (C) 2019 EPAM Systems <hybrisideaplugin@epam.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
Expand Down Expand Up @@ -54,7 +54,7 @@ class BSEnumValueLineMarkerProvider : RelatedItemLineMarkerProvider() {
psi: PsiElement
) = NavigationGutterIconBuilder.create(HybrisIcons.ENUM_VALUE)
.setTarget(psi)
.setTooltipText(message("hybris.gutter.bs.enum.value.title"))
.setTooltipText(message("hybris.editor.gutter.bs.enum.value.title"))
.createLineMarkerInfo(dom.nameIdentifier)

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of "hybris integration" plugin for Intellij IDEA.
* Copyright (C) 2014-2016 Alexander Bartash <AlexanderBartash@gmail.com>
* This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA.
* Copyright (C) 2019 EPAM Systems <hybrisideaplugin@epam.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
Expand Down Expand Up @@ -58,7 +58,7 @@ class BSPropertyLineMarkerProvider : RelatedItemLineMarkerProvider() {
psi: PsiElement
) = NavigationGutterIconBuilder.create(HybrisIcons.PROPERTY)
.setTarget(psi)
.setTooltipText(message("hybris.gutter.bs.bean.property.title"))
.setTooltipText(message("hybris.editor.gutter.bs.bean.property.title"))
.createLineMarkerInfo(dom.nameIdentifier)

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of "hybris integration" plugin for Intellij IDEA.
* Copyright (C) 2014-2016 Alexander Bartash <AlexanderBartash@gmail.com>
* This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA.
* Copyright (C) 2019 EPAM Systems <hybrisideaplugin@epam.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
Expand Down Expand Up @@ -58,9 +58,9 @@ class BSTypeLineMarkerProvider : RelatedItemLineMarkerProvider() {
list: Collection<PsiElement>
) = NavigationGutterIconBuilder.create(HybrisIcons.BEAN)
.setTargets(list)
.setEmptyPopupText(message("hybris.gutter.navigate.no.matching.beans"))
.setPopupTitle(message("hybris.gutter.bean.type.navigate.choose.class.title"))
.setTooltipText(message("hybris.gutter.item.class.tooltip.navigate.declaration"))
.setEmptyPopupText(message("hybris.editor.gutter.navigate.no.matching.beans"))
.setPopupTitle(message("hybris.editor.gutter.bean.type.navigate.choose.class.title"))
.setTooltipText(message("hybris.editor.gutter.item.class.tooltip.navigate.declaration"))
.createLineMarkerInfo(psiClass.nameIdentifier!!)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
* This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA.
* Copyright (C) 2019 EPAM Systems <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.intellij.idea.plugin.hybris.codeInsight.daemon

import com.intellij.codeInsight.daemon.LineMarkerInfo
import com.intellij.codeInsight.daemon.LineMarkerProviderDescriptor
import com.intellij.codeInsight.daemon.MergeableLineMarkerInfo
import com.intellij.idea.plugin.hybris.common.services.CommonIdeaService
import com.intellij.idea.plugin.hybris.common.utils.HybrisI18NBundleUtils.message
import com.intellij.idea.plugin.hybris.common.utils.HybrisIcons
import com.intellij.idea.plugin.hybris.notifications.Notifications
import com.intellij.notification.NotificationType
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.editor.markup.GutterIconRenderer
import com.intellij.openapi.editor.markup.MarkupEditorFilter
import com.intellij.openapi.editor.markup.MarkupEditorFilterFactory
import com.intellij.openapi.ide.CopyPasteManager
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiPolyadicExpression
import com.intellij.psi.PsiReference
import com.intellij.psi.PsiVariable
import com.intellij.psi.impl.JavaConstantExpressionEvaluator
import com.intellij.util.Function
import java.awt.datatransfer.StringSelection
import java.util.function.Supplier
import javax.swing.Icon

private val topRegex = "(SELECT )|( UNION )|( DISTINCT )|( ORDER BY )|( LEFT JOIN )|( JOIN )|( FROM )|( WHERE )|( ASC )|( DESC )|( ON )".toRegex(RegexOption.IGNORE_CASE)
private val regexFrom = " FROM ".toRegex(RegexOption.IGNORE_CASE)
private val regexLeftJoin = " LEFT JOIN ".toRegex(RegexOption.IGNORE_CASE)
private val regexWhere = " WHERE ".toRegex(RegexOption.IGNORE_CASE)
private val regexUnit = " UNION ".toRegex(RegexOption.IGNORE_CASE)
private val whitespaceRegex = "\\s+".toRegex()

class FlexibleSearchQueryLineMarkerProvider : LineMarkerProviderDescriptor() {

override fun getName() = message("hybris.editor.gutter.fsq.name")

override fun getLineMarkerInfo(element: PsiElement): LineMarkerInfo<*>? {
if (element !is PsiPolyadicExpression) return null
val parent = element.parent
if (parent !is PsiVariable || parent.nameIdentifier == null) return null
if (!CommonIdeaService.getInstance().isHybrisProject(element.project)) return null

val expression = computeExpression(element)
val formattedExpression = formatExpression(expression)

if (!(expression.contains(topRegex) && expression.contains('{') && expression.contains('}'))) return null

val tooltipProvider = Function { _: PsiElement? ->
"${message("hybris.editor.gutter.fsq.tooltip")}<br><hr>$formattedExpression"
}

return FlexibleSearchQueryLineMarkerInfo(parent.nameIdentifier!!, icon, tooltipProvider, CopyToClipboard(formattedExpression))
}

private fun formatExpression(expression: String): String {
return expression
.replace(regexFrom, "\n FROM ")
.replace(regexLeftJoin, "\n LEFT JOIN ")
.replace(regexWhere, "\n WHERE \n")
.replace(regexUnit, "\n UNION ")
.replace(" ({{ ", " (\n {{\n")
.replace(" ( {{ ", "\n (\n {{\n")
.replace(" )}} ", "\n )\n }}\n")
.replace(" ) }} ", "\n )\n }}\n")
.replace(" }} ", "\n }} \n")
.replace(" {{ ", "\n {{ \n")
}

private fun computeExpression(literalExpression: PsiPolyadicExpression): String {
var computedValue = ""

literalExpression.operands
.forEach { operand ->
if (operand is PsiReference) {
val probableDefinition = operand.resolve()
if (probableDefinition is PsiVariable) {
probableDefinition.initializer?.let { initializer ->
val value = JavaConstantExpressionEvaluator.computeConstantExpression(initializer, true);
if (value is String) {
computedValue += value;
}
}
}
} else {
val value = JavaConstantExpressionEvaluator.computeConstantExpression(operand, true);
if (value is String) {
computedValue += value;
}
}
}
return computedValue
.trim()
.replace("\n", "")
.replace("\t", "")
.replace(whitespaceRegex, " ")
}

internal class CopyToClipboard(val content: String) : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
CopyPasteManager.getInstance().setContents(StringSelection(content))
Notifications.create(NotificationType.INFORMATION, message("hybris.editor.gutter.fsq.notification.title"), content)
.hideAfter(10)
.notify(e.project)
}
}

override fun getIcon() = HybrisIcons.FS_FILE

internal class FlexibleSearchQueryLineMarkerInfo(
element: PsiElement,
icon: Icon,
tooltipProvider: Function<in PsiElement?, String>,
val action: AnAction
) :
MergeableLineMarkerInfo<PsiElement?>(element, element.textRange, icon, tooltipProvider, null, GutterIconRenderer.Alignment.CENTER,
Supplier { tooltipProvider.`fun`(element) }) {

override fun createGutterRenderer(): GutterIconRenderer {
return object : LineMarkerGutterIconRenderer<PsiElement?>(this) {
override fun getClickAction() = action
override fun isNavigateAction() = true
override fun getPopupMenuActions() = null
}
}

override fun getEditorFilter(): MarkupEditorFilter = MarkupEditorFilterFactory.createIsNotDiffFilter()

override fun canMergeWith(info: MergeableLineMarkerInfo<*>) = info is FlexibleSearchQueryLineMarkerInfo && info.getIcon() === icon

override fun getCommonIcon(infos: List<MergeableLineMarkerInfo<*>?>): Icon = icon
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ class PopulatorLineMarkerProvider : RelatedItemLineMarkerProvider() {
NavigationGutterIconBuilder.create(HybrisIcons.GUTTER_POPULATOR)
.setTargets(list)
.setEmptyPopupText(HybrisI18NBundleUtils.message(
"hybris.gutter.navigate.no.matching.populators"
"hybris.editor.gutter.navigate.no.matching.populators"
))
.setPopupTitle(HybrisI18NBundleUtils.message(
"hybris.gutter.populator.class.navigate.choose.class.title"
"hybris.editor.gutter.populator.class.navigate.choose.class.title"
))
.setTooltipText(HybrisI18NBundleUtils.message(
"hybris.gutter.populator.class.tooltip.navigate.declaration"
"hybris.editor.gutter.populator.class.tooltip.navigate.declaration"
))
.createLineMarkerInfo(psiElement)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ protected Optional<RelatedItemLineMarkerInfo<PsiElement>> collectDeclarations(fi

@Override
protected String getTooltipText() {
return HybrisI18NBundleUtils.message("hybris.gutter.item.attribute.tooltip.navigate.declaration");
return HybrisI18NBundleUtils.message("hybris.editor.gutter.item.attribute.tooltip.navigate.declaration");
}

@Override
protected String getPopupTitle() {
return HybrisI18NBundleUtils.message("hybris.gutter.bean.attribute.navigate.choose.class.title");
return HybrisI18NBundleUtils.message("hybris.editor.gutter.bean.attribute.navigate.choose.class.title");
}

@Override
protected String getEmptyPopupText() {
return HybrisI18NBundleUtils.message("hybris.gutter.navigate.no.matching.attributes");
return HybrisI18NBundleUtils.message("hybris.editor.gutter.navigate.no.matching.attributes");
}

private static List<XmlElement> getAttributeElements(final TSGlobalMetaItem meta, final String name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of "hybris integration" plugin for Intellij IDEA.
* Copyright (C) 2014-2016 Alexander Bartash <AlexanderBartash@gmail.com>
* This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA.
* Copyright (C) 2019 EPAM Systems <hybrisideaplugin@epam.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
Expand Down Expand Up @@ -54,7 +54,7 @@ class TSEnumValueLineMarkerProvider : RelatedItemLineMarkerProvider() {
psi: PsiElement
) = NavigationGutterIconBuilder.create(HybrisIcons.ENUM_VALUE)
.setTarget(psi)
.setTooltipText(message("hybris.gutter.bs.enum.value.title"))
.setTooltipText(message("hybris.editor.gutter.bs.enum.value.title"))
.createLineMarkerInfo(dom.nameIdentifier)

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ protected Optional<RelatedItemLineMarkerInfo<PsiElement>> collectDeclarations(

@Override
protected String getTooltipText() {
return HybrisI18NBundleUtils.message("hybris.gutter.item.class.tooltip.navigate.declaration");
return HybrisI18NBundleUtils.message("hybris.editor.gutter.item.class.tooltip.navigate.declaration");
}

@Override
protected String getPopupTitle() {
return HybrisI18NBundleUtils.message("hybris.gutter.bean.type.navigate.choose.class.title");
return HybrisI18NBundleUtils.message("hybris.editor.gutter.bean.type.navigate.choose.class.title");
}

@Override
protected String getEmptyPopupText() {
return HybrisI18NBundleUtils.message("hybris.gutter.navigate.no.matching.beans");
return HybrisI18NBundleUtils.message("hybris.editor.gutter.navigate.no.matching.beans");
}
}
Loading