-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement directive alphabetic sorting (#74)
* Add class which provides methods to sort directives * Add test for the import sorting * Update import handling in the file structure * Improve directive structure to allow sorting * Update directive writing * Move directive tests to another directory * Improve directive sorting and storing to minimize generation issues * Add new test which tests the directive ordering at a test class * Add override generation for functions * Add documentation * Improve documentation * File ends now with an empty line * Add write support for relative directives * Move relative directive generation * Remove print statement * Add generation of export directives (#75) * Add support for export directives * Add variable to store the export directive objects * Implement cast options * Add ExportDirectiveTest class * Remove unused import * Add file test with export directive
- Loading branch information
1 parent
c2fec16
commit 57238fe
Showing
16 changed files
with
443 additions
and
82 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
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
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
76 changes: 76 additions & 0 deletions
76
src/main/kotlin/net/theevilreaper/dartpoet/util/DirectiveOrdere.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,76 @@ | ||
package net.theevilreaper.dartpoet.util | ||
|
||
import net.theevilreaper.dartpoet.directive.BaseDirective | ||
import net.theevilreaper.dartpoet.directive.Directive | ||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* Object responsible for sorting and ordering directives. | ||
* | ||
* This utility object provides functions to sort lists of directives either in alphabetical order based on | ||
* their raw paths or based on a specified subtype of [Directive]. It is designed to work with instances of | ||
* classes that inherit from [Directive]. | ||
* | ||
* @since 1.0.0 | ||
* @version 1.0.0 | ||
* @author theEvilReaper | ||
*/ | ||
internal object DirectiveOrdering { | ||
|
||
/** | ||
* Sorts a list of directives in alphabetical order based on their raw paths. | ||
* | ||
* This function takes a list of directives, where each directive is a subtype of [BaseDirective], | ||
* and sorts them in ascending alphabetical order according to their raw paths. | ||
* | ||
* @param directives the list of directives to be sorted | ||
* @return a new list containing the sorted directives | ||
*/ | ||
internal inline fun <reified T : Directive> sortDirectives(directives: List<T>): List<T> { | ||
if (directives.isEmpty()) return emptyList() | ||
return directives.sortedBy { it.getRawPath() }.toImmutableList() | ||
} | ||
|
||
/** | ||
* Sorts a list of directives based on a specified subtype of [Directive]. | ||
* | ||
* This function filters the given list of directives to include only instances of the specified | ||
* subtype [T], compares them based on their raw paths, and returns a new list sorted in ascending order. | ||
* | ||
* @param directiveInstance the class type representing the specific subtype [T] to filter the directives | ||
* @param directives the list of directives to be sorted | ||
* @return a new list containing the sorted directives of the specified subtype [T] | ||
*/ | ||
internal inline fun <reified T : Directive> sortDirectives( | ||
directiveInstance: KClass<T>, | ||
directives: List<Directive> | ||
): List<Directive> { | ||
if (directives.isEmpty()) return emptyList() | ||
return directives.filter { it::class == directiveInstance }.sortedBy { it.getRawPath() }.toImmutableList() | ||
} | ||
|
||
/** | ||
* Sorts a list of directives based on a specified subtype of [Directive] and a predicate. | ||
* | ||
* This function filters the given list of directives to include only instances of the specified | ||
* subtype [T], compares them based on their raw paths, and returns a new list sorted in ascending order. | ||
* The predicate is used to filter the directives based on their raw paths. | ||
* | ||
* @param directiveInstance the class type representing the specific subtype [T] to filter the directives | ||
* @param directives the list of directives to be sorted | ||
* @param predicate the predicate used to filter the directives | ||
* @return a new list containing the sorted directives of the specified subtype [T] | ||
*/ | ||
internal inline fun <reified T : Directive> sortDirectives( | ||
directiveInstance: KClass<T>, | ||
directives: List<Directive>, | ||
crossinline predicate: (String) -> Boolean | ||
): List<Directive> { | ||
if (directives.isEmpty()) return emptyList() | ||
return directives | ||
.filter { it::class == directiveInstance } | ||
.sortedBy { it.getRawPath() } | ||
.filter { predicate(it.asString()) } | ||
.toImmutableList() | ||
} | ||
} |
Oops, something went wrong.