-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A mapping class for Eclipse configuration that provides a better API.
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
org.scala-ide.sdt.core/src/org/scalaide/core/internal/quickassist/QuickAssistMapping.scala
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,41 @@ | ||
package org.scalaide.core.internal.quickassist | ||
|
||
import org.scalaide.core.quickassist.QuickAssist | ||
import org.scalaide.util.eclipse.EclipseUtils | ||
|
||
object QuickAssistMapping { | ||
|
||
final val QuickAssistId = "org.scala-ide.sdt.core.quickAssists" | ||
|
||
/** | ||
* Returns all existing quick assists mapped to the [[QuickAssistMapping]] | ||
* class. If an error occurred while trying to retrieve information for a | ||
* quick assist, it is filtered out and the error is logged. | ||
*/ | ||
def mappings: Seq[QuickAssistMapping] = { | ||
val elems = EclipseUtils.configElementsForExtension(QuickAssistId) | ||
elems flatMap { e => | ||
EclipseUtils.withSafeRunner(s"Error occurred while trying to retrieve information from extension '$QuickAssistId'") { | ||
QuickAssistMapping(e.getAttribute("id"))(e.createExecutableExtension("class").asInstanceOf[QuickAssist]) | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* A mapping for a quick assist extension that allows easy access to the defined | ||
* configuration. For documentation of the defined fields, see the quick assist | ||
* extension point. | ||
*/ | ||
case class QuickAssistMapping(id: String)(unsafeInstanceAccess: QuickAssist) { | ||
|
||
/** | ||
* Gives access to the actual quick assist instance. Because these instances | ||
* can be defined by third party plugins they need to be executed in a safe | ||
* mode to protect the IDE against corruption. | ||
* | ||
* If an error occurs in `f` `None` is returned, otherwise the result of `f`. | ||
*/ | ||
def withInstance[A](f: QuickAssist => A): Option[A] = | ||
EclipseUtils.withSafeRunner(s"Error occurred while executing quick assist '$id'")(f(unsafeInstanceAccess)) | ||
} |