|
| 1 | +/* |
| 2 | + * Source++, the continuous feedback platform for developers. |
| 3 | + * Copyright (C) 2022-2024 CodeBrig, Inc. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package spp.jetbrains.marker.rs.service |
| 18 | + |
| 19 | +import com.intellij.psi.PsiComment |
| 20 | +import com.intellij.psi.PsiElement |
| 21 | +import com.intellij.psi.impl.source.tree.LeafPsiElement |
| 22 | +import org.rust.lang.core.psi.RsExpr |
| 23 | +import org.rust.lang.core.psi.RsFunction |
| 24 | +import spp.jetbrains.artifact.service.define.IArtifactTypeService |
| 25 | +import spp.protocol.artifact.ArtifactType |
| 26 | + |
| 27 | +/** |
| 28 | + * Used to determine the type of Rust artifacts. |
| 29 | + * |
| 30 | + * @author [Brandon Fergerson](mailto:bfergerson@apache.org) |
| 31 | + */ |
| 32 | +class RustArtifactTypeService : IArtifactTypeService { |
| 33 | + |
| 34 | + override fun getAnnotations(element: PsiElement): List<PsiElement> { |
| 35 | + return emptyList() //todo: implement |
| 36 | + } |
| 37 | + |
| 38 | + override fun getAnnotationOwnerIfAnnotation(element: PsiElement): PsiElement? { |
| 39 | + return null //todo: implement |
| 40 | + } |
| 41 | + |
| 42 | + override fun getAnnotationOwnerIfAnnotation(element: PsiElement, line: Int): PsiElement? { |
| 43 | + return null //todo: implement |
| 44 | + } |
| 45 | + |
| 46 | + override fun isComment(element: PsiElement): Boolean { |
| 47 | + val comment = element is PsiComment |
| 48 | + if (comment) return true |
| 49 | + |
| 50 | + return if (element is LeafPsiElement) { |
| 51 | + isComment(element.parent) |
| 52 | + } else false |
| 53 | + } |
| 54 | + |
| 55 | + override fun getType(element: PsiElement): ArtifactType? { |
| 56 | + return when (element) { |
| 57 | + is RsFunction -> ArtifactType.FUNCTION |
| 58 | + is RsExpr -> ArtifactType.EXPRESSION |
| 59 | + |
| 60 | + else -> null |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + override fun isLiteral(element: PsiElement): Boolean { |
| 65 | + return super.isLiteral(element) //todo: implement |
| 66 | + } |
| 67 | +} |
0 commit comments