Skip to content

Commit ef1bab2

Browse files
authored
chore: uptake mereology across the project (#50)
1 parent 8ad2f9c commit ef1bab2

61 files changed

Lines changed: 1283 additions & 170 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

codemodel-foundation/src/main/java/build/codemodel/foundation/descriptor/AbstractTraitable.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import build.base.marshalling.Unmarshal;
3030
import build.codemodel.foundation.CodeModel;
3131

32+
import java.util.Collection;
33+
import java.util.Collections;
3234
import java.util.Iterator;
3335
import java.util.Objects;
3436
import java.util.Optional;
@@ -120,9 +122,18 @@ protected void destructor(final Marshaller marshaller,
120122

121123
@Override
122124
public <T> Iterator<T> iterator(final Class<T> type) {
123-
return hasTraits()
125+
final var traitIterator = hasTraits()
124126
? getDelegate().iterator(type)
125-
: Iterators.empty();
127+
: Iterators.<T>empty();
128+
final var otherIterator = otherParts().stream()
129+
.filter(type::isInstance)
130+
.map(type::cast)
131+
.iterator();
132+
return Iterators.concat(type, traitIterator, otherIterator);
133+
}
134+
135+
public Collection<?> otherParts() {
136+
return Collections.emptySet();
126137
}
127138

128139
@Override

codemodel-foundation/src/main/java/build/codemodel/foundation/descriptor/CallableDescriptor.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020
* #L%
2121
*/
2222

23-
import build.base.foundation.stream.Streams;
23+
import build.base.mereology.Composite;
2424
import build.codemodel.foundation.CodeModel;
25-
import build.codemodel.foundation.Dependent;
2625
import build.codemodel.foundation.naming.CallableName;
2726
import build.codemodel.foundation.usage.TypeUsage;
2827

@@ -39,7 +38,7 @@
3938
* @since Jan-2024
4039
*/
4140
public interface CallableDescriptor
42-
extends Trait, Dependent, Traitable {
41+
extends Trait, Composite, Traitable {
4342

4443
/**
4544
* Obtains the {@link TypeDescriptor} in which the {@link CallableDescriptor} is defined.
@@ -108,14 +107,4 @@ default Stream<TypeUsage> throwables() {
108107
: Stream.empty();
109108
}
110109

111-
@Override
112-
default Stream<TypeUsage> dependencies() {
113-
return Streams.concat(
114-
Stream.of(returnType()),
115-
formalParameters()
116-
.map(FormalParameterDescriptor::type),
117-
throwables(),
118-
traits(Dependent.class)
119-
.flatMap(Dependent::dependencies));
120-
}
121110
}

codemodel-foundation/src/main/java/build/codemodel/foundation/descriptor/ThrowableDescriptor.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
import build.base.marshalling.Out;
2929
import build.base.marshalling.Unmarshal;
3030
import build.codemodel.foundation.CodeModel;
31-
import build.codemodel.foundation.Dependent;
3231
import build.codemodel.foundation.usage.TypeUsage;
3332

3433
import java.lang.invoke.MethodHandles;
34+
import java.util.Collection;
35+
import java.util.List;
3536
import java.util.Objects;
3637
import java.util.stream.Stream;
3738

@@ -45,7 +46,7 @@
4546
*/
4647
public class ThrowableDescriptor
4748
extends AbstractTraitable
48-
implements Trait, Dependent {
49+
implements Trait {
4950

5051
/**
5152
* The <i>Throwable</i> {@link TypeUsage}.
@@ -108,8 +109,8 @@ public TypeUsage throwable() {
108109
}
109110

110111
@Override
111-
public Stream<TypeUsage> dependencies() {
112-
return Stream.of(throwable());
112+
public Collection<?> otherParts() {
113+
return List.of(throwable());
113114
}
114115

115116
@Override

codemodel-foundation/src/main/java/build/codemodel/foundation/descriptor/TypeDescriptor.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@
2020
* #L%
2121
*/
2222

23-
import build.codemodel.foundation.Dependent;
23+
import build.base.mereology.Composite;
2424
import build.codemodel.foundation.naming.TypeName;
2525
import build.codemodel.foundation.usage.TypeUsage;
2626

27-
import java.util.stream.Stream;
28-
2927
/**
3028
* Provides type information concerning the <i>definition</i> of a type.
3129
*
@@ -35,19 +33,12 @@
3533
* @since Jan-2024
3634
*/
3735
public interface TypeDescriptor
38-
extends Dependent, Traitable {
36+
extends Composite, Traitable {
3937

4038
/**
4139
* The {@link TypeName} for the <i>Type</i>.
4240
*
4341
* @return the {@link TypeName}
4442
*/
4543
TypeName typeName();
46-
47-
@Override
48-
default Stream<TypeUsage> dependencies() {
49-
return traits(Dependent.class)
50-
.flatMap(Dependent::dependencies)
51-
.distinct();
52-
}
5344
}

codemodel-foundation/src/main/java/build/codemodel/foundation/usage/AnnotationTypeUsage.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import build.base.marshalling.Out;
3131
import build.base.marshalling.Unmarshal;
3232
import build.codemodel.foundation.CodeModel;
33-
import build.codemodel.foundation.Dependent;
3433
import build.codemodel.foundation.descriptor.Trait;
3534
import build.codemodel.foundation.descriptor.Traitable;
3635
import build.codemodel.foundation.naming.TypeName;
@@ -49,7 +48,7 @@
4948
*/
5049
public class AnnotationTypeUsage
5150
extends AbstractNamedTypeUsage
52-
implements Trait, Dependent, Comparable<AnnotationTypeUsage> {
51+
implements Trait, Comparable<AnnotationTypeUsage> {
5352

5453
/**
5554
* The {@link AnnotationValue}s.
@@ -124,12 +123,6 @@ public Stream<AnnotationValue> values() {
124123
return this.values.stream();
125124
}
126125

127-
@Override
128-
public Stream<TypeUsage> dependencies() {
129-
return traits(Dependent.class)
130-
.flatMap(Dependent::dependencies);
131-
}
132-
133126
@Override
134127
public boolean equals(final Object object) {
135128
if (this == object) {

codemodel-foundation/src/main/java/build/codemodel/foundation/usage/ArrayTypeUsage.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
*/
2222

2323
import build.base.foundation.Lazy;
24-
import build.base.foundation.stream.Streams;
2524
import build.base.marshalling.Bound;
2625
import build.base.marshalling.Marshal;
2726
import build.base.marshalling.Marshalled;
@@ -30,11 +29,12 @@
3029
import build.base.marshalling.Out;
3130
import build.base.marshalling.Unmarshal;
3231
import build.codemodel.foundation.CodeModel;
33-
import build.codemodel.foundation.Dependent;
3432
import build.codemodel.foundation.descriptor.Trait;
3533
import build.codemodel.foundation.descriptor.Traitable;
3634

3735
import java.lang.invoke.MethodHandles;
36+
import java.util.Collection;
37+
import java.util.List;
3838
import java.util.Objects;
3939
import java.util.stream.Stream;
4040

@@ -110,11 +110,8 @@ public TypeUsage type() {
110110
}
111111

112112
@Override
113-
public Stream<TypeUsage> dependencies() {
114-
return Streams.concat(
115-
Stream.of(type()),
116-
traits(Dependent.class)
117-
.flatMap(Dependent::dependencies));
113+
public Collection<?> otherParts() {
114+
return List.of(type());
118115
}
119116

120117
@Override

codemodel-foundation/src/main/java/build/codemodel/foundation/usage/GenericTypeUsage.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
import build.base.marshalling.Out;
3131
import build.base.marshalling.Unmarshal;
3232
import build.codemodel.foundation.CodeModel;
33-
import build.codemodel.foundation.Dependent;
3433
import build.codemodel.foundation.descriptor.Trait;
3534
import build.codemodel.foundation.descriptor.Traitable;
3635
import build.codemodel.foundation.naming.TypeName;
3736

3837
import java.lang.invoke.MethodHandles;
3938
import java.util.ArrayList;
39+
import java.util.Collection;
4040
import java.util.Objects;
4141
import java.util.Optional;
4242
import java.util.stream.Collectors;
@@ -207,11 +207,8 @@ public static GenericTypeUsage of(final CodeModel codeModel,
207207
}
208208

209209
@Override
210-
public Stream<TypeUsage> dependencies() {
211-
return Streams.concat(
212-
parameters(),
213-
traits(Dependent.class)
214-
.flatMap(Dependent::dependencies));
210+
public Collection<?> otherParts() {
211+
return parameters().collect(Collectors.toList());
215212
}
216213

217214
static {

codemodel-foundation/src/main/java/build/codemodel/foundation/usage/IntersectionTypeUsage.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
import build.base.marshalling.Out;
3131
import build.base.marshalling.Unmarshal;
3232
import build.codemodel.foundation.CodeModel;
33-
import build.codemodel.foundation.Dependent;
3433
import build.codemodel.foundation.descriptor.Trait;
3534
import build.codemodel.foundation.descriptor.Traitable;
3635
import build.codemodel.foundation.descriptor.TypeDescriptor;
3736

3837
import java.lang.invoke.MethodHandles;
3938
import java.util.ArrayList;
39+
import java.util.Collection;
4040
import java.util.stream.Collectors;
4141
import java.util.stream.Stream;
4242

@@ -119,11 +119,8 @@ public Stream<TypeUsage> types() {
119119
}
120120

121121
@Override
122-
public Stream<TypeUsage> dependencies() {
123-
return Streams.concat(
124-
types(),
125-
traits(Dependent.class)
126-
.flatMap(Dependent::dependencies));
122+
public Collection<?> otherParts() {
123+
return types().collect(Collectors.toList());
127124
}
128125

129126
@Override

codemodel-foundation/src/main/java/build/codemodel/foundation/usage/SpecificTypeUsage.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import build.base.marshalling.Out;
2929
import build.base.marshalling.Unmarshal;
3030
import build.codemodel.foundation.CodeModel;
31-
import build.codemodel.foundation.Dependent;
3231
import build.codemodel.foundation.descriptor.Trait;
3332
import build.codemodel.foundation.naming.TypeName;
3433

@@ -97,13 +96,6 @@ public boolean equals(final Object object) {
9796
&& super.equals(other);
9897
}
9998

100-
@Override
101-
public Stream<TypeUsage> dependencies() {
102-
// the direct dependencies are those of the annotations
103-
return traits(Dependent.class)
104-
.flatMap(Dependent::dependencies);
105-
}
106-
10799
/**
108100
* Creates a {@link SpecificTypeUsage}.
109101
*

codemodel-foundation/src/main/java/build/codemodel/foundation/usage/TypeUsage.java

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020
* #L%
2121
*/
2222

23+
import build.base.mereology.Composite;
2324
import build.codemodel.foundation.CodeModel;
24-
import build.codemodel.foundation.Dependent;
2525
import build.codemodel.foundation.descriptor.Traitable;
2626
import build.codemodel.foundation.descriptor.TypeDescriptor;
2727

28-
import java.util.LinkedHashSet;
2928
import java.util.Objects;
3029
import java.util.Optional;
3130
import java.util.stream.Collector;
@@ -39,7 +38,7 @@
3938
* @since Jan-2024
4039
*/
4140
public interface TypeUsage
42-
extends Dependent, Traitable {
41+
extends Composite, Traitable {
4342

4443
/**
4544
* Attempts to obtain an {@link Optional} representation of or the first part of the {@link TypeUsage} assignable
@@ -60,26 +59,11 @@ default <T> Optional<T> as(final Class<T> requiredClass) {
6059
* of the {@link TypeUsage}s on which this {@link TypeUsage} directly and indirectly depends.
6160
*
6261
* @param visitor the {@link TypeUsageVisitor}
63-
* @see #dependencies()
6462
*/
6563
default void visit(final TypeUsageVisitor visitor) {
6664
if (Objects.nonNull(visitor)) {
67-
final var pending = new LinkedHashSet<TypeUsage>();
68-
final var visited = new LinkedHashSet<TypeUsage>();
69-
pending.add(this);
70-
71-
while (!pending.isEmpty()) {
72-
final var next = pending.removeFirst();
73-
74-
if (!visited.contains(next)) {
75-
visitor.visit(next);
76-
visited.add(next);
77-
78-
next.dependencies()
79-
.filter(typeUsage -> !visited.contains(typeUsage) && !pending.contains(typeUsage))
80-
.forEach(pending::add);
81-
}
82-
}
65+
visitor.visit(this);
66+
composition(TypeUsage.class).forEach(visitor::visit);
8367
}
8468
}
8569

@@ -97,7 +81,8 @@ default <A, R> R collect(final Collector<? super TypeUsage, A, R> collector) {
9781
Objects.requireNonNull(collector, "The Collector must not be null");
9882

9983
final var accumulator = collector.supplier().get();
100-
visit(typeUsage -> collector.accumulator().accept(accumulator, typeUsage));
84+
collector.accumulator().accept(accumulator, this);
85+
composition(TypeUsage.class).forEach(u -> collector.accumulator().accept(accumulator, u));
10186
return collector.finisher().apply(accumulator);
10287
}
10388
}

0 commit comments

Comments
 (0)