Skip to content

Commit

Permalink
feat!: Immutable Collections Extension added
Browse files Browse the repository at this point in the history
closes #106

BREAKING CHANGE: Extensions API changed
  • Loading branch information
pawellabaj committed Jul 27, 2023
1 parent 3346f94 commit 3123c9a
Show file tree
Hide file tree
Showing 32 changed files with 503 additions and 275 deletions.
2 changes: 1 addition & 1 deletion extensions/immutable-collections-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<properties>
<guava.version>32.1.1-jre</guava.version>

<maven.install.skip>true</maven.install.skip>
<license-maven-plugin.header>${project.basedir}/../../.build/lic-header.txt</license-maven-plugin.header>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ImmutableCollectionsExtensionTest {
"ItemWithMaps",
"ItemWithQueues",
};
private static final String GENERATED_PATH = "pl/com/labaj/autorecord/extension/arice/";
private static final String GENERATED_PATH = "pl/com/labaj/autorecord/testcase/";

static Stream<String> names() {
return Arrays.stream(NAMES);
Expand All @@ -65,7 +65,8 @@ static Stream<String> names() {

@BeforeEach
void setUp() {
compiler = javac().withClasspath(prepareClasspath()).withOptions("-proc:only");
compiler = javac()
.withOptions("-proc:only", "-Xprefer:source");
}

@ParameterizedTest(name = "{0}.java")
Expand All @@ -74,7 +75,7 @@ void shouldGenerateSingleRecord(String name) {
//given
var inputs = List.of(
forResource("in/" + name + ".java"),
forResource("UserCollections.java")
forResource("in/UserCollections.java")
);

var expectedOutput = forResource("out/" + name + "Record.java");
Expand All @@ -99,7 +100,7 @@ void shouldGenerateCorrectAllRecordsTogether() {
.map(name -> forResource("in/" + name + ".java"))
.collect(toCollection(ArrayList::new));

inputs.add(forResource("UserCollections.java"));
inputs.add(forResource("in/UserCollections.java"));

var expectedOutputs = Arrays.stream(NAMES)
.collect(toMap(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.com.labaj.autorecord.extension.arice;
package pl.com.labaj.autorecord.testcase;

/*-
* Copyright © 2023 Auto Record
Expand All @@ -18,6 +18,7 @@

import com.google.common.collect.ImmutableList;
import pl.com.labaj.autorecord.AutoRecord;
import pl.com.labaj.autorecord.testcase.user.UserCollections;

import javax.annotation.Nullable;
import java.util.ArrayList;
Expand All @@ -27,9 +28,8 @@
@AutoRecord
@AutoRecord.Extension(
extensionClass = "pl.com.labaj.autorecord.extension.arice.ImmutableCollectionsExtension",
parameters = {
"pl.com.labaj.autorecord.extension.arice.UserCollections.UserList"
})
parameters = {"pl.com.labaj.autorecord.testcase.user.UserCollections.UserList"}
)
interface ItemWithLists<E> {
List<E> list();
LinkedList<E> linkedList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.com.labaj.autorecord.extension.arice;
package pl.com.labaj.autorecord.testcase;

/*-
* Copyright © 2023 Auto Record
Expand All @@ -18,6 +18,7 @@

import com.google.common.collect.ImmutableList;
import pl.com.labaj.autorecord.AutoRecord;
import pl.com.labaj.autorecord.testcase.user.UserCollections;

import javax.annotation.Nullable;
import java.util.ArrayList;
Expand All @@ -30,9 +31,13 @@ interface ItemWithListsNoUserDefinedCollections<E> {
List<E> list();
LinkedList<E> linkedList();
ArrayList<E> arrayList();
UserCollections.UserList<E> userList();
UserCollections.UserListImpl<E> userListImpl();
ImmutableList<E> immutableList();
@Nullable List<E> nullableList();
@Nullable LinkedList<E> nullableLinkedList();
@Nullable ArrayList<E> nullableArrayList();
@Nullable UserCollections.UserList<E> nullableUserList();
@Nullable UserCollections.UserListImpl<E> nullableUserListImpl();
@Nullable ImmutableList<E> nullableImmutableList();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.com.labaj.autorecord.extension.arice;
package pl.com.labaj.autorecord.testcase;

/*-
* Copyright © 2023 Auto Record
Expand All @@ -18,6 +18,7 @@

import com.google.common.collect.ImmutableMap;
import pl.com.labaj.autorecord.AutoRecord;
import pl.com.labaj.autorecord.testcase.user.UserCollections;

import javax.annotation.Nullable;
import java.util.HashMap;
Expand All @@ -30,10 +31,11 @@
@AutoRecord.Extension(
extensionClass = "pl.com.labaj.autorecord.extension.arice.ImmutableCollectionsExtension",
parameters = {
"pl.com.labaj.autorecord.extension.arice.UserCollections.UserMap",
"pl.com.labaj.autorecord.extension.arice.UserCollections.UserSortedMap",
"pl.com.labaj.autorecord.extension.arice.UserCollections.UserNavigableMap"
})
"pl.com.labaj.autorecord.testcase.user.UserCollections.UserMap",
"pl.com.labaj.autorecord.testcase.user.UserCollections.UserSortedMap",
"pl.com.labaj.autorecord.testcase.user.UserCollections.UserNavigableMap"
}
)
interface ItemWithMaps<K, V> {
Map<K, V> set();
HashMap<K, V> hashMap();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

package pl.com.labaj.autorecord.extension.arice;
package pl.com.labaj.autorecord.testcase;

/*-
* Copyright © 2023 Auto Record
Expand All @@ -16,6 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import pl.com.labaj.autorecord.AutoRecord;

import javax.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.com.labaj.autorecord.extension.arice;
package pl.com.labaj.autorecord.testcase;

/*-
* Copyright © 2023 Auto Record
Expand All @@ -17,6 +17,7 @@
*/

import pl.com.labaj.autorecord.AutoRecord;
import pl.com.labaj.autorecord.testcase.user.UserCollections;

import javax.annotation.Nullable;
import java.util.ArrayDeque;
Expand All @@ -27,16 +28,16 @@
@AutoRecord.Extension(
extensionClass = "pl.com.labaj.autorecord.extension.arice.ImmutableCollectionsExtension",
parameters = {
"pl.com.labaj.autorecord.extension.arice.UserCollections.UserQueue",
"pl.com.labaj.autorecord.extension.arice.UserCollections.UserDeque"
})
"pl.com.labaj.autorecord.testcase.user.UserCollections.UserQueue",
"pl.com.labaj.autorecord.testcase.user.UserCollections.UserDeque"
}
)
interface ItemWithQueues<E> {
Queue<E> queue();
Deque<E> deque();
ArrayDeque<E> arrayDeque();
UserCollections.UserQueue<E> userQueue();
UserCollections.UserDeque<E> userDeque();

UserCollections.UserQueueImpl<E> userQueueImpl();
UserCollections.UserDequeImpl<E> userDequeImpl();
@Nullable Queue<E>nullableQueue();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.com.labaj.autorecord.extension.arice;
package pl.com.labaj.autorecord.testcase;

/*-
* Copyright © 2023 Auto Record
Expand All @@ -18,6 +18,7 @@

import com.google.common.collect.ImmutableSet;
import pl.com.labaj.autorecord.AutoRecord;
import pl.com.labaj.autorecord.testcase.user.UserCollections;

import javax.annotation.Nullable;
import java.util.HashSet;
Expand All @@ -31,11 +32,12 @@
@AutoRecord.Extension(
extensionClass = "pl.com.labaj.autorecord.extension.arice.ImmutableCollectionsExtension",
parameters = {
"pl.com.labaj.autorecord.extension.arice.UserCollections.UserSet",
"pl.com.labaj.autorecord.extension.arice.UserCollections.UserSortedSet",
"pl.com.labaj.autorecord.extension.arice.UserCollections.UserNavigableSet"
})
interface ItemWithSets<E> {
"pl.com.labaj.autorecord.testcase.user.UserCollections.UserSet",
"pl.com.labaj.autorecord.testcase.user.UserCollections.UserSortedSet",
"pl.com.labaj.autorecord.testcase.user.UserCollections.UserNavigableSet"
}
)
interface ItemWithSets<E, M extends Enum<M>> {
Set<E> set();
HashSet<E> hashSet();
LinkedHashSet<E> linkedHashSet();
Expand All @@ -62,6 +64,7 @@ interface ItemWithSets<E> {
@Nullable UserCollections.UserSortedSet<E> nullableUserSortedSet();
@Nullable UserCollections.UserSortedSetImpl<E> nullableUserSortedSetImpl();
@Nullable UserCollections.UserNavigableSet<E> nullableUserNavigableSet();
@Nullable UserCollections.UserNavigableSetImpl<E> nullableUserNavigableSetImpl();
@Nullable
UserCollections.UserNavigableSetImpl<E> nullableUserNavigableSetImpl();
@Nullable ImmutableSet<E> nullableImmutableSet();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.com.labaj.autorecord.extension.arice;
package pl.com.labaj.autorecord.testcase;

/*-
* Copyright © 2023 Auto Record
Expand All @@ -18,6 +18,7 @@

import com.google.common.collect.ImmutableSet;
import pl.com.labaj.autorecord.AutoRecord;
import pl.com.labaj.autorecord.testcase.user.UserCollections;

import javax.annotation.Nullable;
import java.util.HashSet;
Expand All @@ -31,17 +32,72 @@
@AutoRecord.Extension(extensionClass = "pl.com.labaj.autorecord.extension.arice.ImmutableCollectionsExtension")
interface ItemWithSetsNoUserDefinedCollections<E, M extends Enum<M>> {
Set<E> set();

HashSet<E> hashSet();

LinkedHashSet<E> linkedHashSet();

SortedSet<E> sortedSet();

UserCollections.SortedSetImpl<E> sortedSetImpl();

NavigableSet<E> navigableSet();

TreeSet<E> treeSet();

UserCollections.UserSet<E> userSet();

UserCollections.UserSetImpl<E> userSetImpl();

UserCollections.UserSortedSet<E> userSortedSet();

UserCollections.UserSortedSetImpl<E> userSortedSetImpl();

UserCollections.UserNavigableSet<E> userNavigableSet();

UserCollections.UserNavigableSetImpl<E> userNavigableSetImpl();

ImmutableSet<E> immutableSet();
@Nullable Set<E> nullableSet();
@Nullable HashSet<E> nullableHashSet();
@Nullable LinkedHashSet<E> nullableLinkedHashSet();
@Nullable SortedSet<E> nullableSortedSet();
@Nullable NavigableSet<E> nullableNavigableSet();
@Nullable TreeSet<E> nullableTreeSet();
@Nullable ImmutableSet<E> nullableImmutableSet();

@Nullable
Set<E> nullableSet();

@Nullable
HashSet<E> nullableHashSet();

@Nullable
LinkedHashSet<E> nullableLinkedHashSet();

@Nullable
SortedSet<E> nullableSortedSet();

@Nullable
UserCollections.SortedSetImpl<E> nullableSortedSetImpl();

@Nullable
NavigableSet<E> nullableNavigableSet();

@Nullable
TreeSet<E> nullableTreeSet();

@Nullable
UserCollections.UserSet<E> nullableUserSet();

@Nullable
UserCollections.UserSetImpl<E> nullableUserSetImpl();

@Nullable
UserCollections.UserSortedSet<E> nullableUserSortedSet();

@Nullable
UserCollections.UserSortedSetImpl<E> nullableUserSortedSetImpl();

@Nullable
UserCollections.UserNavigableSet<E> nullableUserNavigableSet();

@Nullable
UserCollections.UserNavigableSetImpl<E> nullableUserNavigableSetImpl();

@Nullable
ImmutableSet<E> nullableImmutableSet();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.com.labaj.autorecord.extension.arice;
package pl.com.labaj.autorecord.testcase.user;

/*-
* Copyright © 2023 Auto Record
Expand Down Expand Up @@ -33,25 +33,25 @@
import java.util.SortedSet;
import java.util.TreeSet;

class UserCollections {
public class UserCollections {

interface UserSet<E> extends Set<E> {}
public interface UserSet<E> extends Set<E> {}

interface UserNavigableSet<E> extends NavigableSet<E> {}
public interface UserNavigableSet<E> extends NavigableSet<E> {}

interface UserSortedSet<E> extends SortedSet<E> {}
interface UserList<E> extends List<E> {}
interface UserMap<K, V> extends Map<K, V> {}
public interface UserSortedSet<E> extends SortedSet<E> {}
public interface UserList<E> extends List<E> {}
public interface UserMap<K, V> extends Map<K, V> {}
public interface UserSortedMap<K, V> extends SortedMap<K, V> {}
public interface UserNavigableMap<K, V> extends NavigableMap<K, V> {}
interface UserQueue<E> extends Queue<E> {}
interface UserDeque<E> extends Deque<E> {}
public interface UserQueue<E> extends Queue<E> {}
public interface UserDeque<E> extends Deque<E> {}

static class UserSetImpl<E> extends AbstractSet<E> implements UserSet<E> {
public static class UserSetImpl<E> extends AbstractSet<E> implements UserSet<E> {
@Override public Iterator<E> iterator() {return null;}
@Override public int size() {return 0;}
}
static class SortedSetImpl<E> extends AbstractSet<E> implements SortedSet<E> {
public static class SortedSetImpl<E> extends AbstractSet<E> implements SortedSet<E> {
@Override public Iterator<E> iterator() {return null;}
@Override public int size() {return 0;}
@Override public Comparator<? super E> comparator() {return null;}
Expand All @@ -63,18 +63,18 @@ static class SortedSetImpl<E> extends AbstractSet<E> implements SortedSet<E> {
@Override public E last() {return null;}

}
static class UserSortedSetImpl<E> extends SortedSetImpl<E> implements UserSortedSet<E> {}
static class UserNavigableSetImpl<E> extends TreeSet<E> implements UserNavigableSet<E> {}
static class UserListImpl<E> extends AbstractList<E> implements UserList<E>{
public static class UserSortedSetImpl<E> extends SortedSetImpl<E> implements UserSortedSet<E> {}
public static class UserNavigableSetImpl<E> extends TreeSet<E> implements UserNavigableSet<E> {}
public static class UserListImpl<E> extends AbstractList<E> implements UserList<E>{
@Override public E get(int index) {return null;}
@Override public int size() {return 0;}

}
static class UserMapImpl<K, V> extends AbstractMap<K, V> implements UserMap<K, V> {
public static class UserMapImpl<K, V> extends AbstractMap<K, V> implements UserMap<K, V> {
@Override public Set<Entry<K, V>> entrySet() {return null;}

}
static class UserSortedMapImpl<K, V> extends UserMapImpl<K, V> implements UserSortedMap<K, V> {
public static class UserSortedMapImpl<K, V> extends UserMapImpl<K, V> implements UserSortedMap<K, V> {
@Override public Comparator<? super K> comparator() {return null;}
@Override public SortedMap<K, V> subMap(K fromKey, K toKey) {return null;}
@Override public SortedMap<K, V> headMap(K toKey) {return null;}
Expand All @@ -83,7 +83,7 @@ static class UserSortedMapImpl<K, V> extends UserMapImpl<K, V> implements UserSo
@Override public K lastKey() {return null;}

}
static class UserNavigableMapImpl<K, V> extends UserSortedMapImpl<K,V> implements UserNavigableMap<K,V> {
public static class UserNavigableMapImpl<K, V> extends UserSortedMapImpl<K,V> implements UserNavigableMap<K,V> {
@Override public Entry<K, V> lowerEntry(K key) {return null;}
@Override public K lowerKey(K key) {return null;}
@Override public Entry<K, V> floorEntry(K key) {return null;}
Expand All @@ -104,7 +104,7 @@ static class UserNavigableMapImpl<K, V> extends UserSortedMapImpl<K,V> implement
@Override public NavigableMap<K, V> tailMap(K fromKey, boolean inclusive) {return null;}
}

static class UserQueueImpl<E> extends ArrayDeque<E> implements UserQueue<E> {}
public static class UserQueueImpl<E> extends ArrayDeque<E> implements UserQueue<E> {}

static class UserDequeImpl<E> extends ArrayDeque<E> implements UserDeque<E> {}
public static class UserDequeImpl<E> extends ArrayDeque<E> implements UserDeque<E> {}
}
Loading

0 comments on commit 3123c9a

Please sign in to comment.