Skip to content

Commit

Permalink
#897 | Customized folding for User Rights permission flags
Browse files Browse the repository at this point in the history
  • Loading branch information
mlytvyn authored Jan 1, 2024
1 parent ad70293 commit fea947a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- Added reference resolution for not quoted value of the `disable.interceptor.beans` [#893](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/893)
- Added reference resolution for not quoted value of the `disable.interceptor.types` [#894](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/894)
- Added reference resolution for not quoted value of the `disable.UniqueAttributesValidator.for.types` [#895](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/895)
- Customized folding for `User Rights` permission flags [#897](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/897)

### `ImpEx` inspection rules
- Inspect type set for `disable.UniqueAttributesValidator.for.types` type modifier [#896](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/896)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA.
* Copyright (C) 2019-2023 EPAM Systems <[email protected]> and contributors
* Copyright (C) 2019-2024 EPAM Systems <[email protected]> and contributors
*
* 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 All @@ -20,6 +20,7 @@

import com.intellij.idea.plugin.hybris.impex.lang.folding.util.ImpExFoldingLinesFilter;
import com.intellij.idea.plugin.hybris.impex.psi.ImpexTypes;
import com.intellij.idea.plugin.hybris.impex.utils.ImpexPsiUtils;
import com.intellij.lang.ASTNode;
import com.intellij.lang.folding.FoldingDescriptor;
import com.intellij.openapi.editor.Document;
Expand All @@ -36,8 +37,6 @@
import java.util.List;
import java.util.Objects;

import static com.intellij.idea.plugin.hybris.impex.utils.ImpexPsiUtils.*;

public class ImpexFoldingLinesBuilder extends AbstractImpExFoldingBuilder {

private static final String LINE_GROUP_NAME = "impex_fold_line";
Expand All @@ -64,16 +63,16 @@ public FoldingDescriptor[] buildFoldRegionsInternal(
final int nextIdx = Math.min(i + 1, size - 1);

final PsiElement element = foldingBlocks.get(i);
if (isHeaderLine(element) || isUserRightsMacros(element)) {
if (ImpexPsiUtils.isHeaderLine(element) || ImpexPsiUtils.isUserRightsMacros(element)) {
startGroupElement = foldingBlocks.get(nextIdx);
if (groupIsNotFresh) {
currentLineGroup = FoldingGroup.newGroup(LINE_GROUP_NAME);
countLinesOnGroup = 0;
groupIsNotFresh = false;
}
} else {
if (nextElementIsHeaderLine(element)
|| nextElementIsUserRightsMacros(element)
if (ImpexPsiUtils.nextElementIsHeaderLine(element)
|| ImpexPsiUtils.nextElementIsUserRightsMacros(element)
|| nextIdx == size) {
if (countLinesOnGroup > 1) {
descriptors.add(new ImpexFoldingDescriptor(
Expand All @@ -82,8 +81,8 @@ public FoldingDescriptor[] buildFoldRegionsInternal(
element.getTextRange().getEndOffset(),
currentLineGroup,
(elm) -> {
final PsiElement prevSibling = getPrevNonWhitespaceElement(elm);
if ((isHeaderLine(prevSibling) || isUserRightsMacros(prevSibling))) {
final PsiElement prevSibling = ImpexPsiUtils.getPrevNonWhitespaceElement(elm);
if ((ImpexPsiUtils.isHeaderLine(prevSibling) || ImpexPsiUtils.isUserRightsMacros(prevSibling))) {
return ";....;....";
}
return "";
Expand All @@ -93,7 +92,7 @@ public FoldingDescriptor[] buildFoldRegionsInternal(
groupIsNotFresh = true;
}
}
if (isImpexValueLine(element)) {
if (ImpexPsiUtils.isImpexValueLine(element)) {
countLinesOnGroup++;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA.
* Copyright (C) 2014-2016 Alexander Bartash <[email protected]>
* Copyright (C) 2019-2023 EPAM Systems <[email protected]> and contributors
* Copyright (C) 2019-2024 EPAM Systems <[email protected]> and contributors
*
* 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 All @@ -20,6 +20,7 @@ package com.intellij.idea.plugin.hybris.impex.lang.folding.util

import com.intellij.idea.plugin.hybris.impex.psi.ImpexAttribute
import com.intellij.idea.plugin.hybris.impex.psi.ImpexParameters
import com.intellij.idea.plugin.hybris.impex.psi.ImpexUserRightsPermissionValue
import com.intellij.idea.plugin.hybris.impex.utils.ImpexPsiUtils
import com.intellij.openapi.components.Service
import com.intellij.psi.PsiElement
Expand All @@ -32,6 +33,7 @@ class ImpExSmartFoldingBlocksFilter : AbstractImpExFoldingFilter() {

private fun isSupportedType(element: PsiElement) = element is ImpexAttribute
|| element is ImpexParameters
|| element is ImpexUserRightsPermissionValue
|| ImpexPsiUtils.isLineBreak(element)

private fun isNotBlankPlaceholder(element: PsiElement) = ImpExSmartFoldingPlaceholderBuilder.getInstance().getPlaceholder(element)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import com.intellij.idea.plugin.hybris.impex.constants.modifier.AttributeModifie
import com.intellij.idea.plugin.hybris.impex.constants.modifier.ImpexModifier
import com.intellij.idea.plugin.hybris.impex.constants.modifier.TypeModifier
import com.intellij.idea.plugin.hybris.impex.lang.folding.ImpexFoldingPlaceholderBuilder
import com.intellij.idea.plugin.hybris.impex.psi.ImpexAttribute
import com.intellij.idea.plugin.hybris.impex.psi.ImpexParameter
import com.intellij.idea.plugin.hybris.impex.psi.ImpexParameters
import com.intellij.idea.plugin.hybris.impex.psi.*
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.Service
import com.intellij.psi.PsiElement
import com.intellij.psi.util.elementType
import com.intellij.psi.util.firstLeaf
import org.apache.commons.lang3.StringUtils
import java.util.regex.Pattern

Expand All @@ -37,6 +37,7 @@ class ImpExSmartFoldingPlaceholderBuilder : ImpexFoldingPlaceholderBuilder {
override fun getPlaceholder(psiElement: PsiElement): String = when (psiElement) {
is ImpexAttribute -> getPlaceholder(psiElement)
is ImpexParameters -> getParametersPlaceholder(psiElement.parameterList)
is ImpexUserRightsPermissionValue -> getPlaceholder(psiElement)
else -> psiElement.text
}

Expand All @@ -57,6 +58,12 @@ class ImpExSmartFoldingPlaceholderBuilder : ImpexFoldingPlaceholderBuilder {
}
}

private fun getPlaceholder(element: ImpexUserRightsPermissionValue) = when (element.firstLeaf.elementType) {
ImpexTypes.PERMISSION_DENIED -> ""
ImpexTypes.PERMISSION_ALLOWED -> ""
else -> StringUtils.EMPTY
}

private fun getPlaceholder(impexAttribute: ImpexAttribute) = with(impexAttribute.anyAttributeName.text) {
when {
quoteAwareStringEquals(this, TypeModifier.DISABLE_INTERCEPTOR_TYPES) -> {
Expand Down

0 comments on commit fea947a

Please sign in to comment.