-
Notifications
You must be signed in to change notification settings - Fork 1
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
Review - Do Not Merge! #2
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ class ScapsAdapter(indexDir: String) extends StrictLogging { | |
|
||
private def searchEngine = { | ||
val conf = Settings.fromApplicationConf.modIndex { index => index.copy(indexDir = indexDir) } | ||
SearchEngine(conf).get | ||
SearchEngine(conf).get // Error Handling? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wie macht man das Error Handling an dieser Stelle? try-catch block oder gibt es eine elegantere Lösung? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ich würde es sicher loggen, eventuell muss man dem User auch den Fehler melden? |
||
} | ||
|
||
def indexProject(classPath: Seq[String], projectSourceUnits: Seq[ICompilationUnit]): Unit = projectSourceUnits match { | ||
|
@@ -55,11 +55,12 @@ class ScapsAdapter(indexDir: String) extends StrictLogging { | |
def indexFinalize = searchEngine.finalizeIndex.get | ||
|
||
def search(searchQuery: String): Seq[Result[ValueDef]] = { | ||
searchEngine.search(searchQuery, Set()).get.getOrElse(List()) | ||
searchEngine.search(searchQuery, Set.empty).get.getOrElse(Seq.empty) // Könnte man auch so schreiben, aber eure Variante ist auch ok. | ||
} | ||
|
||
private def indexDefinitions(extractionStream: Stream[ExtractionError \/ Definition]): Unit = { | ||
|
||
// Lohnt sich diese Methode? | ||
def handleExtractionErrors(extractionStream: Stream[ExtractionError \/ Definition]): Stream[Definition] = | ||
ExtractionError.logErrors(extractionStream, logger.info(_)) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,11 +44,12 @@ class ScapsIndexService(private val scapsAdapter: ScapsAdapter) extends StrictLo | |
resolvedClassPath.map(_.getPath.toString).toList | ||
} | ||
|
||
// Sehr lange Zeile.. | ||
def returnElements(classPath: Option[List[String]], projectSourceFragmentRoots: Option[List[IPackageFragmentRoot]], librarySourceRootFiles: Option[List[File]]): (List[String], List[IPackageFragmentRoot], List[File]) = { | ||
(classPath.getOrElse(List[String]()), projectSourceFragmentRoots.getOrElse(List[IPackageFragmentRoot]()), librarySourceRootFiles.getOrElse(List[File]())) | ||
(classPath.getOrElse(List.empty), projectSourceFragmentRoots.getOrElse(List.empty), librarySourceRootFiles.getOrElse(List.empty)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Könnte man alternativ so machen, muss man aber nicht, je nach Präferenz. Vorteil ist, dass man den Typ nicht angeben muss. |
||
} | ||
|
||
val collectedElements = scapsWorkingSet.getElements.toList.map(_ match { | ||
val (classPaths, projectSourceFragmentRoots, librarySourceRootFiles) = scapsWorkingSet.getElements.toList.map { | ||
case javaProject: IJavaProject => | ||
val classPath = extractClassPath(javaProject) | ||
val projectSourceFragmentRoots = javaProject.getAllPackageFragmentRoots.filter(_.getKind == IPackageFragmentRoot.K_SOURCE).toList | ||
|
@@ -70,9 +71,9 @@ class ScapsIndexService(private val scapsAdapter: ScapsAdapter) extends StrictLo | |
case unknownTyp => | ||
logger.info("type not supported: " + unknownTyp.getClass) | ||
returnElements(None, None, None) | ||
}).unzip3 | ||
}.unzip3 | ||
|
||
(collectedElements._1.flatten.distinct, collectedElements._2.flatten.distinct, collectedElements._3.flatten.distinct) | ||
(classPaths.flatten.distinct, projectSourceFragmentRoots.flatten.distinct, librarySourceRootFiles.flatten.distinct) | ||
} | ||
|
||
private def indexProjectTask(monitor: IProgressMonitor, classPath: List[String], projectSourceFragmentRoots: List[IPackageFragmentRoot]): Unit = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,15 +24,17 @@ import org.eclipse.core.resources.ResourcesPlugin | |
|
||
object ScapsService { | ||
|
||
val pluginPreferences = InstanceScope.INSTANCE.getNode(ScapsPlugin.PLUGIN_ID) | ||
val indexRootDir = ResourcesPlugin.getWorkspace.getRoot.getLocation.toString + ScapsPlugin.INDEX_RELATIVE_ROOT_DIR | ||
private val pluginPreferences = InstanceScope.INSTANCE.getNode(ScapsPlugin.PLUGIN_ID) | ||
private val indexRootDir = ResourcesPlugin.getWorkspace.getRoot.getLocation.toString + ScapsPlugin.INDEX_RELATIVE_ROOT_DIR | ||
|
||
val PROPERTY_INDEXER_RUNNING = "indexRunning" | ||
|
||
val PROPERTY_SEARCH_ON_FIRST_INDEX = "searchOnFirstIndex" | ||
val FIRST_INDEX_DIR = "first" | ||
val SECOND_INDEX_DIR = "second" | ||
|
||
// Könnte es hier zu Threading-Problemen kommen? Race condition, etc.? | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wäre möglich, wenn der Indexer zb. "ganz" schnell zweimal gestartet wird. Wäre hier ein Semaphor angebracht oder gibt es bessere Scala Möglichkeiten? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Die Primitiven die Scala bietet sind gleich wie bei Java; Semaphor wäre möglich, aber auch synchronized (das ist allerdings kein Keyword in Scala, sondern einfach eine Methode, also this.synchronized { ... }). |
||
private def isSearchOnFirstIndex = pluginPreferences.getBoolean(PROPERTY_SEARCH_ON_FIRST_INDEX, true) | ||
private def searchIndexDir = if (isSearchOnFirstIndex) FIRST_INDEX_DIR else SECOND_INDEX_DIR | ||
private def indexingIndexDir = if (isSearchOnFirstIndex) SECOND_INDEX_DIR else FIRST_INDEX_DIR | ||
|
@@ -52,6 +54,7 @@ object ScapsService { | |
pluginPreferences.getBoolean(PROPERTY_INDEXER_RUNNING, false) | ||
} | ||
|
||
// Entspricht nicht den Scala-Namenskonventionen. Wie wärs mit createSearchService und createIndexService? | ||
def SEARCH = { | ||
val indexDir = indexRootDir + searchIndexDir | ||
val scapsAdapter = new ScapsAdapter(indexDir) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,12 @@ import scaps.api.ValueDef | |
import scaps.eclipse.core.services.ScapsSearchService | ||
|
||
object SearchUCHandler { | ||
// Wozu? | ||
private def INSTANCE = new SearchUCHandler(ScapsService.SEARCH) | ||
def apply(): SearchUCHandler = INSTANCE | ||
} | ||
|
||
class SearchUCHandler(private val scapsSearchService: ScapsSearchService) { | ||
class SearchUCHandler(scapsSearchService: ScapsSearchService) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wieso hast du hier das "private val" entfernt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Konstruktorparameter in normalen Klassen sind eigentlich dasselbe wie private vals, also nur innerhalb der Klasse sichtbare Variablen. |
||
|
||
def apply(searchQuery: String): Seq[Result[ValueDef]] = scapsSearchService(searchQuery) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Das einzige wozu dieser von uns gebraucht wird ist Zeile 24: ScapsService.setIndexerRunning(false)
Wird dieser sonst vom Plugin nicht benötigt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nein den brauchts eigentlich nicht, wenn die Zeile 24 also anders gelöst werden kann könnte die Klasse entfernt werden.