Skip to content

Commit

Permalink
Issue #264: Skip imports of classes in same package
Browse files Browse the repository at this point in the history
  • Loading branch information
hypfvieh committed Aug 25, 2024
1 parent e14a1e4 commit c41f5c2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ The library will remain open source and MIT licensed and can still be used, fork
##### Changes in 5.1.1 (not released yet):
- Added new Helper class `VariantBuilder` to allow creating Variants which contain Maps or Collections without messing with the required DBus type arguments
- Fixed wrong/missing increment when resolving nested structs or deeply nested objects in `Marshalling.getDBusType` ([#265](https://github.com/hypfvieh/dbus-java/issues/265))
- Fixed wrong import when generating Tuple containing Struct ([#264](https://github.com/hypfvieh/dbus-java/issues/264))

##### Changes in 5.1.0 (2024-08-01):
- Use Junit BOM thanks to [spannm](https://github.com/spannm) ([PR#248](https://github.com/hypfvieh/dbus-java/issues/248))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ private List<String> createClassFileContent(boolean _staticClass, Set<String> _o
content.addAll(2, allImports.stream()
.filter(l -> !l.startsWith("java.lang.")) // do not include imports for 'java.lang'
.filter(l -> !l.replaceFirst("(.+)\\..+", "$1").equals(getPackageName())) // do not add imports for classes in same package
.filter(l -> l.contains(".")) // no dots in name means this is only a class name so we are in same package and don't need to import
.map(l -> "import " + l + ";")
.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,9 @@ void testCreateStructNames() throws Exception {

/* For https://github.com/hypfvieh/dbus-java/issues/264 */
String presetUnitFilesTupleContent = analyze.get(new File("org/freedesktop/systemd1/PresetUnitFilesTuple.java"));
assertEquals("import org.freedesktop.systemd1.PresetUnitFilesChangesStruct;", presetUnitFilesTupleContent
assertTrue(presetUnitFilesTupleContent
.lines()
.filter(s -> s.contains("PresetUnitFilesChangesStruct"))
.findFirst()
.orElseThrow());
.noneMatch(s -> s.contains("import PresetUnitFilesChangesStruct")),
"Did not expect an import for a class of same package");
}
}

0 comments on commit c41f5c2

Please sign in to comment.