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

Enum values must be all uppercase #1159

Merged
merged 1 commit into from
Jul 13, 2024
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## [2024.2.0]

### `items.xml` inspection rules
- Enum values must be all uppercase [#1159](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1159), see [Java Enum Types](https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html)

### Fixes
- Class initialization must not depend on services [#1158](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1158)

Expand Down
6 changes: 6 additions & 0 deletions resources/META-INF/plugin-inspections.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@
shortName="MandatoryFieldMustHaveInitialValue" level="WEAK WARNING"
implementationClass="com.intellij.idea.plugin.hybris.codeInspection.rule.typeSystem.TSMandatoryFieldMustHaveInitialValue"/>


<localInspection language="XML" enabledByDefault="true" groupPath="SAP Commerce" groupName="[y] Type System"
bundle="i18n.HybrisBundle" key="hybris.inspections.ts.TSEnumValueMustBeUppercase.key"
shortName="TSEnumValueMustBeUppercase" level="WEAK WARNING"
implementationClass="com.intellij.idea.plugin.hybris.codeInspection.rule.typeSystem.TSEnumValueMustBeUppercase"/>

<localInspection language="XML" enabledByDefault="true" groupPath="SAP Commerce" groupName="[y] Type System"
bundle="i18n.HybrisBundle" key="hybris.inspections.ts.ImmutableFieldMustHaveInitialValue.key"
shortName="ImmutableFieldMustHaveInitialValue" level="WEAK WARNING"
Expand Down
2 changes: 2 additions & 0 deletions resources/i18n/HybrisBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ hybris.inspections.fix.ts.TSDeploymentTableNameLengthShouldBeValid.key=[y] Deplo
hybris.inspections.ts.TSQualifierAndModifiersMustNotBeDeclaredForNavigableFalse.key=[y] Qualifier and modifiers must not be declared for navigable false
hybris.inspections.ts.TSOnlyOneSideN2mRelationMustBeNotNavigable.key=[y] Only one side of many-to-many relation must be non-navigable
hybris.inspections.ts.TSQualifierMustExistForNavigablePartInN2MRelation.key=[y] Qualifier must exist for navigable part in many-to-many relation
hybris.inspections.ts.TSEnumValueMustBeUppercase.key=[y] Enum code must be all uppercase
hybris.inspections.fix.ts.TSEnumValueMustBeUppercase.key=[y] Enum ''{0}'' code ''{1}'' must be all uppercase

hybris.inspections.bs.DuplicateBeanDeclaration.key=[y] Bean declaration is duplicated within the same file
hybris.inspections.bs.DuplicateEnumDeclaration.key=[y] Enum declaration is duplicated within the same file
Expand Down
25 changes: 25 additions & 0 deletions resources/inspectionDescriptions/TSEnumValueMustBeUppercase.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
~ This file is part of "SAP Commerce Developers Toolset" plugin for IntelliJ IDEA.
~ 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
~ 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/>.
-->

<html>
<body>
Because they are constants, the names of an enum type's fields are in uppercase letters.

See: <a href="https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html">Enum</a>.
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* This file is part of "SAP Commerce Developers Toolset" plugin for IntelliJ IDEA.
* 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
* 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.codeInspection.rule.typeSystem

import com.intellij.idea.plugin.hybris.codeInspection.fix.xml.XmlUpdateAttributeQuickFix
import com.intellij.idea.plugin.hybris.common.utils.HybrisI18NBundleUtils.message
import com.intellij.idea.plugin.hybris.system.type.model.EnumType
import com.intellij.idea.plugin.hybris.system.type.model.EnumValue
import com.intellij.idea.plugin.hybris.system.type.model.Items
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.text.StringUtil
import com.intellij.util.xml.highlighting.DomElementAnnotationHolder
import com.intellij.util.xml.highlighting.DomHighlightingHelper
import java.util.*

class TSEnumValueMustBeUppercase : AbstractTSInspection() {

override fun inspect(
project: Project,
dom: Items,
holder: DomElementAnnotationHolder,
helper: DomHighlightingHelper,
severity: HighlightSeverity
) {
dom.enumTypes.enumTypes.forEach { enumType ->
enumType.values.forEach { enumValue ->
check(enumType, enumValue, holder, severity)
}
}
}

private fun check(
enumType: EnumType,
enumValue: EnumValue,
holder: DomElementAnnotationHolder,
severity: HighlightSeverity
) {
val enumName = enumType.code.stringValue ?: return
val code = enumValue.code.stringValue ?: return
if (StringUtil.isUpperCase(code)) return

holder.createProblem(
enumValue.code,
severity,
message("hybris.inspections.fix.ts.TSEnumValueMustBeUppercase.key", enumName, code),
XmlUpdateAttributeQuickFix(EnumType.CODE, code.uppercase(Locale.ROOT))
)
}
}
Loading