Skip to content

Commit a7afe92

Browse files
authored
Merge pull request #193 from skapral/issue/192
[#192] Got rid of oo.atom.r
2 parents 25169c7 + bacdd63 commit a7afe92

File tree

98 files changed

+649
-3485
lines changed

Some content is hidden

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

98 files changed

+649
-3485
lines changed

atom-basis/src/main/java/com/pragmaticobjects/oo/atom/codegen/bytebuddy/bt/AssertBuilderTransitionIsNotCorruptingClass.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ public final void check() throws Exception {
5959
assertThatCode(() -> {
6060
final DynamicType.Unloaded<?> make = bt
6161
.transitionResult(subclass, typeDescription)
62-
.value()
63-
.get().make();
62+
.make();
6463
final Class<?> clazz = make.load(new AnonymousClassLoader()).getLoaded();
6564
clazz.getMethods(); // Initiate validation.
6665
}).doesNotThrowAnyException();

atom-basis/src/main/java/com/pragmaticobjects/oo/atom/codegen/bytebuddy/bt/AssertBuilderTransitionToAnnotateAClass.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ public final void check() throws Exception {
6262
final DynamicType.Builder<?> subclass = new ByteBuddy().redefine(type);
6363
final DynamicType.Unloaded<?> make = builderTransition
6464
.transitionResult(subclass, typeDescription)
65-
.value()
66-
.get()
6765
.make();
6866
final Class<?> clazz = make.load(new AnonymousClassLoader()).getLoaded();
6967
assertThat(clazz.getAnnotation(annotation))

atom-basis/src/main/java/com/pragmaticobjects/oo/atom/codegen/bytebuddy/bt/AssertClassToHaveCertainMethodsAfterBuilderTransition.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ public final void check() throws Exception {
7878
final DynamicType.Builder<?> subclass = new ByteBuddy().redefine(clazz);
7979
final DynamicType.Unloaded<?> make = bt
8080
.transitionResult(subclass, typeDescription)
81-
.value()
82-
.get()
8381
.make();
8482
final Class<?> newClazz = make.load(new AnonymousClassLoader()).getLoaded();
8583
assertThat(

atom-basis/src/main/java/com/pragmaticobjects/oo/atom/codegen/bytebuddy/bt/BtAnnotate.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
*/
2424
package com.pragmaticobjects.oo.atom.codegen.bytebuddy.bt;
2525

26-
import com.pragmaticobjects.oo.atom.r.RSuccess;
27-
import com.pragmaticobjects.oo.atom.r.Result;
2826
import net.bytebuddy.description.type.TypeDescription;
2927
import net.bytebuddy.dynamic.DynamicType.Builder;
3028

@@ -48,17 +46,14 @@ public BtAnnotate(Annotation annotation) {
4846
}
4947

5048
@Override
51-
public final Result<Builder<?>> transitionResult(Builder<?> source, TypeDescription type) {
49+
public final Builder<?> transitionResult(Builder<?> source, TypeDescription type) {
5250
boolean annotationPresent = type.getDeclaredAnnotations().isAnnotationPresent(
5351
annotation.annotationType()
5452
);
55-
56-
return new RSuccess<>(
57-
annotationPresent ?
58-
source :
59-
source.annotateType(
60-
annotation
61-
)
62-
);
53+
return annotationPresent ?
54+
source :
55+
source.annotateType(
56+
annotation
57+
);
6358
}
6459
}

atom-basis/src/main/java/com/pragmaticobjects/oo/atom/codegen/bytebuddy/bt/BtConditional.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323
*/
2424
package com.pragmaticobjects.oo.atom.codegen.bytebuddy.bt;
2525

26-
import com.pragmaticobjects.oo.atom.r.Result;
2726
import net.bytebuddy.description.type.TypeDescription;
28-
import net.bytebuddy.dynamic.DynamicType;
27+
import net.bytebuddy.dynamic.DynamicType.Builder;
2928
import net.bytebuddy.matcher.ElementMatcher;
3029

3130
/**
@@ -51,7 +50,7 @@ public BtConditional(ElementMatcher<TypeDescription> matcher, BuilderTransition
5150
}
5251

5352
@Override
54-
public final Result<DynamicType.Builder<?>> transitionResult(DynamicType.Builder<?> source, TypeDescription typeDescription) {
53+
public final Builder<?> transitionResult(Builder<?> source, TypeDescription typeDescription) {
5554
if(matcher.matches(typeDescription)) {
5655
return matchBranch.transitionResult(source, typeDescription);
5756
} else {

atom-basis/src/main/java/com/pragmaticobjects/oo/atom/codegen/bytebuddy/bt/BtFail.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

atom-basis/src/main/java/com/pragmaticobjects/oo/atom/codegen/bytebuddy/bt/BtFallback.java

Lines changed: 0 additions & 58 deletions
This file was deleted.

atom-basis/src/main/java/com/pragmaticobjects/oo/atom/codegen/bytebuddy/bt/BtGenerateMethod.java

Lines changed: 58 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -24,75 +24,17 @@
2424
package com.pragmaticobjects.oo.atom.codegen.bytebuddy.bt;
2525

2626
import com.pragmaticobjects.oo.atom.codegen.bytebuddy.smt.StackManipulationToken;
27-
import com.pragmaticobjects.oo.atom.r.RBind;
28-
import com.pragmaticobjects.oo.atom.r.RSuccess;
29-
import com.pragmaticobjects.oo.atom.r.Result;
3027
import lombok.Generated;
3128
import net.bytebuddy.description.method.MethodDescription;
3229
import net.bytebuddy.description.type.TypeDescription;
3330
import net.bytebuddy.dynamic.DynamicType.Builder;
3431
import net.bytebuddy.dynamic.scaffold.InstrumentedType;
35-
import net.bytebuddy.implementation.Implementation;
36-
import net.bytebuddy.implementation.bytecode.ByteCodeAppender;
3732
import net.bytebuddy.implementation.bytecode.StackManipulation;
3833
import net.bytebuddy.jar.asm.MethodVisitor;
3934
import net.bytebuddy.matcher.ElementMatcher;
4035

4136
import java.lang.annotation.Annotation;
4237

43-
/**
44-
* {@link ByteCodeAppender} for {@link BtGenerateMethod}
45-
*
46-
* @author Kapralov Sergey
47-
*/
48-
class BtGenerateMethodBytecodeAppender implements ByteCodeAppender {
49-
private final StackManipulation sm;
50-
51-
/**
52-
* Ctor.
53-
*
54-
* @param sm {@link ByteCodeAppender}'s {@link StackManipulation}.
55-
*/
56-
public BtGenerateMethodBytecodeAppender(StackManipulation sm) {
57-
this.sm = sm;
58-
}
59-
60-
@Override
61-
public final ByteCodeAppender.Size apply(MethodVisitor mv, Implementation.Context ctx, MethodDescription method) {
62-
StackManipulation.Size size = sm.apply(mv, ctx);
63-
return new ByteCodeAppender.Size(size.getMaximalSize(), method.getStackSize());
64-
}
65-
}
66-
67-
/**
68-
* {@link Implementation} for {@link BtGenerateMethod}
69-
*
70-
* @author Kapralov Sergey
71-
*/
72-
class BtGenerateMethodImplementation implements Implementation {
73-
74-
private final StackManipulation sm;
75-
76-
/**
77-
* Ctor.
78-
*
79-
* @param sm {@link Implementation}'s {@link StackManipulation}.
80-
*/
81-
public BtGenerateMethodImplementation(StackManipulation sm) {
82-
this.sm = sm;
83-
}
84-
85-
@Override
86-
public final ByteCodeAppender appender(Implementation.Target implementationTarget) {
87-
return new BtGenerateMethodBytecodeAppender(sm);
88-
}
89-
90-
@Override
91-
public final InstrumentedType prepare(InstrumentedType instrumentedType) {
92-
return instrumentedType;
93-
}
94-
}
95-
9638
/**
9739
* Transition which generates implementation for a certain declared method.
9840
*
@@ -126,16 +68,12 @@ public BtGenerateMethod(ElementMatcher<? super MethodDescription> elementMatcher
12668
}
12769

12870
@Override
129-
public final Result<Builder<?>> transitionResult(Builder<?> source, TypeDescription typeDescription) {
71+
public final Builder<?> transitionResult(Builder<?> source, TypeDescription typeDescription) {
13072
final StackManipulationToken token = methodBodySmt.token(typeDescription);
131-
return new RBind<>(token, sm -> {
132-
return new RSuccess<>(
133-
source
134-
.method(elementMatcher)
135-
.intercept(new BtGenerateMethodImplementation(sm))
136-
.annotateMethod(new GeneratedInstance())
137-
);
138-
});
73+
return source
74+
.method(elementMatcher)
75+
.intercept(new Implementation(token.stackManipulation()))
76+
.annotateMethod(new GeneratedInstance());
13977
}
14078

14179
/**
@@ -149,4 +87,57 @@ public final Class<? extends Annotation> annotationType() {
14987
return Generated.class;
15088
}
15189
}
90+
91+
/**
92+
* {@link Implementation} for {@link BtGenerateMethod}
93+
*
94+
* @author Kapralov Sergey
95+
*/
96+
private static class Implementation implements net.bytebuddy.implementation.Implementation {
97+
98+
private final StackManipulation sm;
99+
100+
/**
101+
* Ctor.
102+
*
103+
* @param sm {@link Implementation}'s {@link StackManipulation}.
104+
*/
105+
public Implementation(StackManipulation sm) {
106+
this.sm = sm;
107+
}
108+
109+
@Override
110+
public final ByteCodeAppender appender(Implementation.Target implementationTarget) {
111+
return new ByteCodeAppender(sm);
112+
}
113+
114+
@Override
115+
public final InstrumentedType prepare(InstrumentedType instrumentedType) {
116+
return instrumentedType;
117+
}
118+
119+
/**
120+
* {@link ByteCodeAppender} for {@link BtGenerateMethod}
121+
*
122+
* @author Kapralov Sergey
123+
*/
124+
private static class ByteCodeAppender implements net.bytebuddy.implementation.bytecode.ByteCodeAppender {
125+
private final StackManipulation sm;
126+
127+
/**
128+
* Ctor.
129+
*
130+
* @param sm {@link ByteCodeAppender}'s {@link StackManipulation}.
131+
*/
132+
public ByteCodeAppender(StackManipulation sm) {
133+
this.sm = sm;
134+
}
135+
136+
@Override
137+
public final ByteCodeAppender.Size apply(MethodVisitor mv, net.bytebuddy.implementation.Implementation.Context ctx, MethodDescription method) {
138+
StackManipulation.Size size = sm.apply(mv, ctx);
139+
return new ByteCodeAppender.Size(size.getMaximalSize(), method.getStackSize());
140+
}
141+
}
142+
}
152143
}

atom-basis/src/main/java/com/pragmaticobjects/oo/atom/codegen/bytebuddy/bt/BtNop.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@
2323
*/
2424
package com.pragmaticobjects.oo.atom.codegen.bytebuddy.bt;
2525

26-
import com.pragmaticobjects.oo.atom.r.RSuccess;
27-
import com.pragmaticobjects.oo.atom.r.Result;
2826
import net.bytebuddy.description.type.TypeDescription;
29-
import net.bytebuddy.dynamic.DynamicType;
27+
import net.bytebuddy.dynamic.DynamicType.Builder;
3028

3129
/**
3230
* Transition which does nothing.
@@ -35,7 +33,7 @@
3533
*/
3634
public class BtNop implements BuilderTransition {
3735
@Override
38-
public final Result<DynamicType.Builder<?>> transitionResult(DynamicType.Builder<?> source, TypeDescription typeDescription) {
39-
return new RSuccess<>(source);
36+
public final Builder<?> transitionResult(Builder<?> source, TypeDescription typeDescription) {
37+
return source;
4038
}
4139
}

atom-basis/src/main/java/com/pragmaticobjects/oo/atom/codegen/bytebuddy/bt/BtSequence.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
*/
2424
package com.pragmaticobjects.oo.atom.codegen.bytebuddy.bt;
2525

26-
import com.pragmaticobjects.oo.atom.r.RBind;
27-
import com.pragmaticobjects.oo.atom.r.RSuccess;
28-
import com.pragmaticobjects.oo.atom.r.Result;
2926
import io.vavr.collection.List;
3027
import net.bytebuddy.description.type.TypeDescription;
3128
import net.bytebuddy.dynamic.DynamicType.Builder;
@@ -55,14 +52,10 @@ public BtSequence(BuilderTransition... transitions) {
5552
}
5653

5754
@Override
58-
public final Result<Builder<?>> transitionResult(Builder<?> source, TypeDescription typeDescription) {
59-
return transitions.<Result<Builder<?>>>foldLeft(
60-
new RSuccess<>(source),
61-
(state, transition) -> new RBind<>(
62-
state,
63-
new RtFromBuilderTransitionAdapter(transition, typeDescription)
64-
)
55+
public final Builder<?> transitionResult(Builder<?> source, TypeDescription typeDescription) {
56+
return transitions.<Builder<?>>foldLeft(
57+
source,
58+
(state, transition) -> transition.transitionResult(state, typeDescription)
6559
);
6660
}
67-
6861
}

0 commit comments

Comments
 (0)