Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Stamann committed Apr 10, 2024
2 parents dbb15c7 + 09d4328 commit c3d8292
Show file tree
Hide file tree
Showing 23 changed files with 553 additions and 26 deletions.
2 changes: 1 addition & 1 deletion coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>cute-parent</artifactId>
<version>1.5.1</version>
<version>1.6.0</version>
</parent>

<name>coverage</name>
Expand Down
2 changes: 1 addition & 1 deletion cute/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>cute-parent</artifactId>
<version>1.5.1</version>
<version>1.6.0</version>
</parent>

<name>cute</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -68,6 +70,18 @@ protected List<Element> getAllSubElements(Element elementToScan) {
result.addAll(((ExecutableElement) elementToScan).getParameters());
}

// need to handle record components
if (elementToScan.getKind().name() == "RECORD") {

try {
Method getRecordComponentsMethod = TypeElement.class.getMethod("getRecordComponents");
result.addAll((List<Element>)(getRecordComponentsMethod.invoke(elementToScan)));
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
// Java version < 16 - so just ignore since kind couldn't be of RECORD already - so this can't happen
}

}

for (Element enclosedElement : elementToScan.getEnclosedElements()) {
result.addAll(getAllSubElements(enclosedElement));
}
Expand Down
46 changes: 41 additions & 5 deletions cute/src/main/java/io/toolisticon/cute/CuteApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ public interface BlackBoxTestFinalGivenInterface extends BlackBoxTestSourceFiles
* @param compilerOptions the options to use
* @return the next builder instance
*/
BlackBoxTestFinalGivenInterface andUseCompilerOptions(@FluentApiBackingBeanMapping(value = "compilerOptions") @NotNull String... compilerOptions);
BlackBoxTestFinalGivenInterface andUseCompilerOptions(@FluentApiBackingBeanMapping(value = "compilerOptions", action = MappingAction.ADD) @NotNull String... compilerOptions);

/**
* Defines modules used during compilation.
Expand All @@ -453,7 +453,7 @@ public interface BlackBoxTestFinalGivenInterface extends BlackBoxTestSourceFiles
* @param modules The modules to use during compilation
* @return the next builder instance
*/
BlackBoxTestFinalGivenInterface andUseModules(@FluentApiBackingBeanMapping(value = "modules") @NotNull String... modules);
BlackBoxTestFinalGivenInterface andUseModules(@FluentApiBackingBeanMapping(value = "modules", action = MappingAction.ADD) @NotNull String... modules);

/**
* Traverses to the compilation result validation section.
Expand Down Expand Up @@ -515,7 +515,7 @@ public interface UnitTestGivenInterface {
* @param compilerOptions the options to use
* @return the next builder instance
*/
UnitTestGivenInterface useCompilerOptions(@FluentApiBackingBeanMapping(value = "compilerOptions") @NotNull String... compilerOptions);
UnitTestGivenInterface useCompilerOptions(@FluentApiBackingBeanMapping(value = "compilerOptions",action = MappingAction.ADD) @NotNull String... compilerOptions);

/**
* Defines modules used during compilation.
Expand All @@ -524,7 +524,7 @@ public interface UnitTestGivenInterface {
* @param modules The modules to use during compilation
* @return the next builder instance
*/
UnitTestGivenInterface useModules(@FluentApiBackingBeanMapping(value = "modules") @NotNull String... modules);
UnitTestGivenInterface useModules(@FluentApiBackingBeanMapping(value = "modules", action = MappingAction.ADD) @NotNull String... modules);

/**
* Convenience method to add multiple source files via resource strings.
Expand Down Expand Up @@ -570,7 +570,43 @@ default UnitTestGivenInterface useSourceFile(String className, String content) {
* @param sourceFile the source file
* @return the next fluent interface
*/
UnitTestGivenInterface useSourceFile(@FluentApiBackingBeanMapping(value = "sourceFiles") @NotNull JavaFileObject sourceFile);
UnitTestGivenInterface useSourceFile(@FluentApiBackingBeanMapping(value = "sourceFiles", action = MappingAction.ADD) @NotNull JavaFileObject sourceFile);


/**
* Adds a source files of resource folder.
* Ignores sub-folders.
*
* @param folders the fully qualified name of the class
* @return the next fluent interface
*/
default UnitTestGivenInterface useSourceFilesFromFolders(String ... folders) {


Set<String> files = new HashSet<>();
for (String folder : folders) {
try {

URL folderUrl = getClass().getResource(folder);
if (folderUrl == null) {
throw new IllegalArgumentException("Passed folder '" + folder + "' doesn't exist.");
}

File[] enclosedFiles = (new File(folderUrl.toURI())).listFiles();
if (enclosedFiles == null) {
throw new IllegalArgumentException("Passed folder '" + folder + "' is no folder");
}

files.addAll(Arrays.stream(enclosedFiles).filter(File::isFile).map(e -> folder + (folder.endsWith("/") ? "" : "/") + e.getName()).collect(Collectors.toSet()));


} catch (URISyntaxException e){
// ignore - should not happen
}
}

return useSourceFiles(files.toArray(new String[0]));
}


/**
Expand Down
Loading

0 comments on commit c3d8292

Please sign in to comment.