Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
90 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/kotlin/org/rust/lang/core/resolve/RsCachedImplItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Use of this source code is governed by the MIT license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
|
||
package org.rust.lang.core.resolve | ||
|
||
import com.intellij.openapi.project.Project | ||
import org.rust.lang.core.psi.RsImplItem | ||
import org.rust.lang.core.psi.RsMembers | ||
import org.rust.lang.core.psi.RsTraitItem | ||
import org.rust.lang.core.psi.RsTraitRef | ||
import org.rust.lang.core.psi.ext.RsMod | ||
import org.rust.lang.core.psi.ext.resolveToBoundTrait | ||
import org.rust.lang.core.resolve.ref.ResolveCacheDependency | ||
import org.rust.lang.core.resolve.ref.RsResolveCache | ||
import org.rust.lang.core.types.BoundElement | ||
import org.rust.lang.core.types.ty.Ty | ||
import org.rust.lang.core.types.type | ||
|
||
class RsCachedImplItem( | ||
val impl: RsImplItem, | ||
val crateRoot: RsMod? = impl.crateRoot, | ||
val traitRef: RsTraitRef? = impl.traitRef, | ||
val membres: RsMembers? = impl.members | ||
) { | ||
val implementedTrait: BoundElement<RsTraitItem>? by lazy(LazyThreadSafetyMode.PUBLICATION) { traitRef?.resolveToBoundTrait() } | ||
val type: Ty? by lazy(LazyThreadSafetyMode.PUBLICATION) { impl.typeReference?.type } | ||
|
||
companion object { | ||
fun resolve(project: Project, impl: RsImplItem): RsCachedImplItem { | ||
return RsResolveCache.getInstance(project) | ||
.resolveWithCaching(impl, ResolveCacheDependency.LOCAL_AND_RUST_STRUCTURE, Resolver)!! | ||
} | ||
|
||
private object Resolver : (RsImplItem) -> RsCachedImplItem { | ||
override fun invoke(impl: RsImplItem): RsCachedImplItem { | ||
return RsCachedImplItem(impl) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters