-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add notification user if block uses in several places
- Loading branch information
1 parent
17a2d61
commit 37226ff
Showing
3 changed files
with
51 additions
and
5 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
31 changes: 31 additions & 0 deletions
31
code/richediting/src/main/kotlin/org/fbme/ide/richediting/utils/fb/FBUsageFinder.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,31 @@ | ||
package org.fbme.ide.richediting.utils.fb | ||
|
||
import jetbrains.mps.findUsages.FindUsagesManager | ||
import jetbrains.mps.project.MPSProject | ||
import org.fbme.ide.iec61499.repository.PlatformElement | ||
import org.fbme.ide.iec61499.repository.PlatformRepositoryProvider | ||
import org.fbme.lib.common.Declaration | ||
import org.jetbrains.mps.openapi.model.SNode | ||
|
||
object FBUsageFinder { | ||
fun findUsages(project: MPSProject, fbBlock: Declaration) | ||
: Map<Declaration, SNode> { | ||
val manager = project.getComponent(FindUsagesManager::class.java) | ||
val platformElement = (fbBlock as PlatformElement) | ||
val nodes = manager.findUsages(project.scope, mutableSetOf(platformElement.node), null) | ||
val repository = PlatformRepositoryProvider.getInstance(project) | ||
|
||
val result: MutableMap<Declaration, SNode> = HashMap() | ||
nodes.mapNotNull { | ||
it.sourceNode.parent | ||
}.forEach { | ||
val declaration = repository.getAdapter(it, Declaration::class.java) | ||
|
||
if (declaration != null) { | ||
result[declaration] = it | ||
} | ||
} | ||
|
||
return result | ||
} | ||
} |