Skip to content

Commit

Permalink
#866 | Incorrect companion object usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mlytvyn authored Dec 23, 2023
1 parent 8d495c3 commit 45995c4
Show file tree
Hide file tree
Showing 80 changed files with 431 additions and 471 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
### `items.xml` enhancements
- Added groups icons in the Structure view [#865](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/865)

### Other
- Incorrect `companion` object usage [#866](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/866)

## [2023.3.2]

### `Project Import` enhancements
Expand Down
2 changes: 1 addition & 1 deletion resources/META-INF/lang/flexibleSearch-dependencies.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<internalFileTemplate name="FlexibleSearch File"/>

<fileType language="FlexibleSearch" extensions="fxs" name="FlexibleSearch file" fieldName="instance"
<fileType language="FlexibleSearch" extensions="fxs" name="FlexibleSearch file" fieldName="INSTANCE"
implementationClass="com.intellij.idea.plugin.hybris.flexibleSearch.file.FlexibleSearchFileType"/>

<!-- Core elements -->
Expand Down
2 changes: 1 addition & 1 deletion resources/META-INF/lang/polyglot-query-dependencies.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<lang.braceMatcher language="Polyglot Query" implementationClass="com.intellij.idea.plugin.hybris.polyglotQuery.lang.PolyglotQueryPairedBraceMatcher"/>
<lang.foldingBuilder language="Polyglot Query" implementationClass="com.intellij.idea.plugin.hybris.polyglotQuery.lang.folding.PolyglotQueryFoldingBuilder"/>

<fileType language="Polyglot Query" extensions="pgq" name="Polyglot Query File" fieldName="instance"
<fileType language="Polyglot Query" extensions="pgq" name="Polyglot Query File" fieldName="INSTANCE"
implementationClass="com.intellij.idea.plugin.hybris.polyglotQuery.file.PolyglotQueryFileType"/>

<lang.parserDefinition language="Polyglot Query"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.idea.plugin.hybris.common.HybrisConstants
import com.intellij.idea.plugin.hybris.common.utils.HybrisI18NBundleUtils
import com.intellij.idea.plugin.hybris.impex.ImpexParserDefinition
import com.intellij.idea.plugin.hybris.impex.psi.*
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiComment
Expand Down Expand Up @@ -53,7 +52,7 @@ private class ConfigProcessorVisitor(private val problemsHolder: ProblemsHolder)
var isExist = false
PsiSearchHelper.getInstance(macroValue.project)
.processElementsWithWord({ element, _ ->
if (element.node.elementType != ImpexParserDefinition.FILE_NODE_TYPE
if (element.node.elementType != HybrisConstants.IMPEX_FILE_NODE_TYPE
&& element.node.elementType != ImpexTypes.LINE_COMMENT) {
isExist = true
}
Expand Down
81 changes: 81 additions & 0 deletions src/com/intellij/idea/plugin/hybris/common/HybrisConstants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@
*/
package com.intellij.idea.plugin.hybris.common

import com.intellij.codeInsight.completion.CompletionUtilCore
import com.intellij.facet.FacetTypeId
import com.intellij.idea.plugin.hybris.facet.YFacet
import com.intellij.idea.plugin.hybris.facet.YFacetType
import com.intellij.idea.plugin.hybris.flexibleSearch.FlexibleSearchLanguage
import com.intellij.idea.plugin.hybris.flexibleSearch.psi.FlexibleSearchTypes
import com.intellij.idea.plugin.hybris.impex.ImpexLanguage
import com.intellij.idea.plugin.hybris.polyglotQuery.psi.PolyglotQueryTypes
import com.intellij.idea.plugin.hybris.project.descriptors.HybrisProjectDescriptor
import com.intellij.idea.plugin.hybris.project.descriptors.ModuleDescriptor
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.io.FileUtilRt
import com.intellij.psi.tree.IFileElementType

object HybrisConstants {

Expand Down Expand Up @@ -605,4 +614,76 @@ object HybrisConstants {
"Undo Reformat Code",
"Auto-Indent Lines"
)

@JvmStatic
val KEY_FINALIZE_PROJECT_IMPORT: Key<Triple<HybrisProjectDescriptor, List<ModuleDescriptor>, Boolean>> = Key.create("hybrisProjectImportFinalize")


const val FXS_DUMMY_IDENTIFIER = CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED
val FXS_SUPPORTED_ELEMENT_TYPES = setOf(
FlexibleSearchTypes.TABLE_ALIAS_NAME,
FlexibleSearchTypes.COLUMN_ALIAS_NAME
)

val IMPEX_FILE_NODE_TYPE = IFileElementType(ImpexLanguage)
val FXS_FILE_NODE_TYPE = IFileElementType(FlexibleSearchLanguage)

val CHARS_UPPERCASE_REGEX = "[A-Z]".toRegex()
val CHARS_LOWERCASE_REGEX = "[a-z]".toRegex()
val PGQ_RESERVED_KEYWORDS = setOf(
PolyglotQueryTypes.AND,
PolyglotQueryTypes.ASC,
PolyglotQueryTypes.BY,
PolyglotQueryTypes.DESC,
PolyglotQueryTypes.GET,
PolyglotQueryTypes.IS,
PolyglotQueryTypes.NOT,
PolyglotQueryTypes.NULL,
PolyglotQueryTypes.OR,
PolyglotQueryTypes.ORDER,
PolyglotQueryTypes.WHERE
)


val FXS_RESERVED_KEYWORDS = setOf(
FlexibleSearchTypes.ALL,
FlexibleSearchTypes.AND,
FlexibleSearchTypes.AS,
FlexibleSearchTypes.ASC,
FlexibleSearchTypes.BETWEEN,
FlexibleSearchTypes.BY,
FlexibleSearchTypes.CASE,
FlexibleSearchTypes.CAST,
FlexibleSearchTypes.DESC,
FlexibleSearchTypes.DISTINCT,
FlexibleSearchTypes.ELSE,
FlexibleSearchTypes.END,
FlexibleSearchTypes.EXISTS,
FlexibleSearchTypes.FROM,
FlexibleSearchTypes.FULL,
FlexibleSearchTypes.GROUP,
FlexibleSearchTypes.HAVING,
FlexibleSearchTypes.IN,
FlexibleSearchTypes.INNER,
FlexibleSearchTypes.INTERVAL,
FlexibleSearchTypes.IS,
FlexibleSearchTypes.JOIN,
FlexibleSearchTypes.LEFT,
FlexibleSearchTypes.LIKE,
FlexibleSearchTypes.LIMIT,
FlexibleSearchTypes.NOT,
FlexibleSearchTypes.NULL,
FlexibleSearchTypes.OFFSET,
FlexibleSearchTypes.ON,
FlexibleSearchTypes.OR,
FlexibleSearchTypes.ORDER,
FlexibleSearchTypes.OUTER,
FlexibleSearchTypes.RIGHT,
FlexibleSearchTypes.SELECT,
FlexibleSearchTypes.THEN,
FlexibleSearchTypes.UNION,
FlexibleSearchTypes.USING,
FlexibleSearchTypes.WHEN,
FlexibleSearchTypes.WHERE,
)
}
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 EPAM Systems <[email protected]>
* Copyright (C) 2019-2023 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,4 +20,4 @@ package com.intellij.idea.plugin.hybris.flexibleSearch
import com.intellij.psi.tree.IElementType
import org.jetbrains.annotations.NonNls

class FlexibleSearchElementType(debugName: @NonNls String) : IElementType(debugName, FlexibleSearchLanguage.INSTANCE)
class FlexibleSearchElementType(debugName: @NonNls String) : IElementType(debugName, FlexibleSearchLanguage)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* This file is part of "hybris integration" plugin for Intellij IDEA.
* 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
*
* 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,12 +21,10 @@ package com.intellij.idea.plugin.hybris.flexibleSearch
import com.intellij.lang.Language
import java.io.Serial

class FlexibleSearchLanguage : Language("FlexibleSearch") {
object FlexibleSearchLanguage : Language("FlexibleSearch") {

companion object {
@Serial
private const val serialVersionUID: Long = 1870292616506709017L
private fun readResolve(): Any = FlexibleSearchLanguage

val INSTANCE: FlexibleSearchLanguage = FlexibleSearchLanguage()
}
@Serial
private const val serialVersionUID: Long = 1870292616506709017L
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* This file is part of "hybris integration" plugin for Intellij IDEA.
* 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
*
* 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 @@ -17,14 +18,14 @@
*/
package com.intellij.idea.plugin.hybris.flexibleSearch

import com.intellij.idea.plugin.hybris.common.HybrisConstants
import com.intellij.idea.plugin.hybris.flexibleSearch.file.FlexibleSearchFile
import com.intellij.idea.plugin.hybris.flexibleSearch.psi.FlexibleSearchTypes
import com.intellij.lang.ASTNode
import com.intellij.lang.ParserDefinition
import com.intellij.openapi.project.Project
import com.intellij.psi.FileViewProvider
import com.intellij.psi.PsiElement
import com.intellij.psi.TokenType
import com.intellij.psi.tree.IFileElementType
import com.intellij.psi.tree.TokenSet

Expand All @@ -35,19 +36,14 @@ class FlexibleSearchParserDefinition : ParserDefinition {
override fun createElement(node: ASTNode): PsiElement = FlexibleSearchTypes.Factory.createElement(node)
override fun createFile(viewProvider: FileViewProvider) = FlexibleSearchFile(viewProvider)

override fun getFileNodeType(): IFileElementType = FILE_NODE_TYPE
override fun getWhitespaceTokens() = WHITE_SPACES
override fun getCommentTokens() = COMMENTS
override fun getStringLiteralElements(): TokenSet = STRING_LITERALS
override fun getFileNodeType(): IFileElementType = HybrisConstants.FXS_FILE_NODE_TYPE
override fun getWhitespaceTokens(): TokenSet = TokenSet.WHITE_SPACE
override fun getCommentTokens() = TokenSet.create(FlexibleSearchTypes.COMMENT, FlexibleSearchTypes.LINE_COMMENT)
override fun getStringLiteralElements(): TokenSet = TokenSet.create(
FlexibleSearchTypes.SINGLE_QUOTE_STRING_LITERAL,
FlexibleSearchTypes.DOUBLE_QUOTE_STRING_LITERAL
)

override fun spaceExistenceTypeBetweenTokens(left: ASTNode, right: ASTNode) = ParserDefinition.SpaceRequirements.MAY

companion object {
val FILE_NODE_TYPE = IFileElementType(FlexibleSearchLanguage.INSTANCE)
val WHITE_SPACES = TokenSet.create(TokenType.WHITE_SPACE)
val COMMENTS = TokenSet.create(FlexibleSearchTypes.COMMENT, FlexibleSearchTypes.LINE_COMMENT)
val STRING_LITERALS = TokenSet.create(
FlexibleSearchTypes.SINGLE_QUOTE_STRING_LITERAL,
FlexibleSearchTypes.DOUBLE_QUOTE_STRING_LITERAL
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.intellij.psi.tree.IElementType
import org.jetbrains.annotations.NonNls
import java.util.regex.Pattern

class FlexibleSearchTokenType(debugName: @NonNls String) : IElementType(debugName, FlexibleSearchLanguage.INSTANCE) {
class FlexibleSearchTokenType(debugName: @NonNls String) : IElementType(debugName, FlexibleSearchLanguage) {

override fun toString() = super.toString()
.takeIf { it.isNotBlank() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package com.intellij.idea.plugin.hybris.flexibleSearch

import com.intellij.idea.plugin.hybris.flexibleSearch.completion.FlexibleSearchCompletionContributor
import com.intellij.idea.plugin.hybris.common.HybrisConstants
import com.intellij.idea.plugin.hybris.flexibleSearch.psi.FlexibleSearchGroupByClause
import com.intellij.idea.plugin.hybris.flexibleSearch.psi.FlexibleSearchOrderClause
import com.intellij.idea.plugin.hybris.flexibleSearch.psi.FlexibleSearchResultColumns
Expand All @@ -45,7 +45,7 @@ object FxSUtils {

fun shouldAddCommaAfterExpression(element: PsiElement, fxsSettings: FlexibleSearchSettings): Boolean {
var addComma = false
if (fxsSettings.completion.injectCommaAfterExpression && element.text == FlexibleSearchCompletionContributor.DUMMY_IDENTIFIER) {
if (fxsSettings.completion.injectCommaAfterExpression && element.text == HybrisConstants.FXS_DUMMY_IDENTIFIER) {
addComma = PsiTreeUtil
.getParentOfType(
element,
Expand All @@ -54,7 +54,7 @@ object FxSUtils {
FlexibleSearchGroupByClause::class.java,
)
?.text
?.substringAfter(FlexibleSearchCompletionContributor.DUMMY_IDENTIFIER)
?.substringAfter(HybrisConstants.FXS_DUMMY_IDENTIFIER)
?.trim()
?.takeUnless { it.startsWith(",") }
?.isNotEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys

class FlexibleSearchExecuteQueryAction : AbstractExecuteAction(
FlexibleSearchFileType.instance.defaultExtension,
FlexibleSearchFileType.defaultExtension,
HybrisConstants.CONSOLE_TITLE_FLEXIBLE_SEARCH
) {

Expand Down
Loading

0 comments on commit 45995c4

Please sign in to comment.