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 code completion and reference resolution for special types #1190

Merged
merged 1 commit into from
Aug 4, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Added dom model for `core-advanced-deployment.xml` [#1187](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1187)
- Added code completion and reference resolution for primitive types [#1188](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1188)
- Added code completion and reference resolution for additional object types [#1189](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1189)
- Added code completion and reference resolution for special types [#1190](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1190)

### Other
- Omit internal IntelliJ API usage in `ProjectBeforeCompilerTask` [#1186](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1186)
Expand Down
11 changes: 0 additions & 11 deletions resources/icons/typeSystem/ci-cd-svgrepo-com.svg

This file was deleted.

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 <hybrisideaplugin@epam.com>
* This file is part of "SAP Commerce Developers Toolset" plugin for IntelliJ IDEA.
* Copyright (C) 2019-2024 EPAM Systems <hybrisideaplugin@epam.com> 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 Down Expand Up @@ -62,6 +62,10 @@ class TSTypeNameMustPointToExistingType : AbstractTSInspection() {

// If type code is Primitive - skip, it is not registered via TS, but available in Service Layer
if (HybrisConstants.TS_PRIMITIVE_TYPES.contains(typeCode)) return
if (typeCode.startsWith("HYBRIS.")) return
if ("java.io.Serializable" == typeCode) return
if ("java.math.BigDecimal" == typeCode) return
if ("java.util.Date" == typeCode) return

val meta = TSMetaModelAccess.getInstance(project).findMetaClassifierByName(typeCode)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ object HybrisIcons {
val COLLECTION = getIcon("/icons/typeSystem/collection.svg")
val PRIMITIVE = HybrisIcons.Types.PRIMITIVE
val OBJECT = HybrisIcons.Types.OBJECT
val SPECIAL = AllIcons.FileTypes.Yaml
}

object Preview {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ object TSLookupElementFactory {
const val GROUP_2 = 2
const val GROUP_3 = 3
const val GROUP_4 = 4
const val GROUP_5 = 5

fun build(
meta: TSGlobalMetaItem,
Expand Down Expand Up @@ -191,6 +192,17 @@ object TSLookupElementFactory {
}
?.let { PrioritizedLookupElement.withGrouping(it, GROUP_4) }

fun buildSpecial(dom: TypeMapping?) = dom
?.let {
val type = it.type.stringValue ?: return@let null
val persistenceType = it.persistenceType.stringValue ?: return@let null

LookupElementBuilder.create(type)
.withTypeText(persistenceType, true)
.withIcon(HybrisIcons.TypeSystem.Types.SPECIAL)
}
?.let { PrioritizedLookupElement.withGrouping(it, GROUP_5) }

fun buildCustomProperty(lookupString: String) = LookupElementBuilder.create(lookupString)
.withIcon(HybrisIcons.TypeSystem.CUSTOM_PROPERTY)
.withCaseSensitivity(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import com.intellij.util.xml.DomManager
import com.intellij.util.xml.stubs.index.DomElementClassIndex
import java.util.*

class PrimitiveTypeConverter : AbstractTSConverterBase<TypeMapping>(TypeMapping::class.java) {
class AdvancedTypeMappingConverter : AbstractTSConverterBase<TypeMapping>(TypeMapping::class.java) {

override fun toString(t: TypeMapping?, context: ConvertContext) = t?.type?.stringValue

Expand All @@ -53,14 +53,14 @@ class PrimitiveTypeConverter : AbstractTSConverterBase<TypeMapping>(TypeMapping:
?: return null
return when {
typeMapping.startsWith("java.") -> TSLookupElementFactory.buildObject(t)
typeMapping.startsWith("HYBRIS.") -> TSLookupElementFactory.buildSpecial(t)
else -> TSLookupElementFactory.buildPrimitive(t)
}
}

private fun getTypeMappings(context: ConvertContext): MutableList<TypeMapping>? = getDatabaseSchema(context.project)
?.typeMappings
?.filterNot { it.type.stringValue?.startsWith("java.lang.") ?: false }
?.filterNot { it.type.stringValue?.startsWith("HYBRIS.") ?: false }
?.toMutableList()

private fun getDatabaseSchema(project: Project): DatabaseSchema? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static class AnyClassifier extends CompositeConverter<DomElement> {

public AnyClassifier() {
super(
new PrimitiveTypeConverter(),
new AdvancedTypeMappingConverter(),
new EnumTypeConverter(),
new ItemTypeConverter(),
new CollectionTypeConverter(),
Expand Down
Loading