Skip to content

Commit 861c168

Browse files
chore: spotless
1 parent ee5edee commit 861c168

11 files changed

Lines changed: 124 additions & 84 deletions

File tree

checker/src/main/java/io/github/eisop/runtimeframework/checker/nullness/NullnessContractResolver.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,17 @@ public ValueContract resolve(TargetRef target, ResolutionContext context) {
3333
case TargetRef.MethodReturn methodReturn -> resolveMethodReturn(methodReturn);
3434
case TargetRef.InvokedMethod invokedMethod -> resolveInvokedMethod(invokedMethod, context);
3535
case TargetRef.Field field -> resolveField(field, context);
36-
case TargetRef.ArrayComponent arrayComponent -> resolveArrayComponent(arrayComponent, context);
36+
case TargetRef.ArrayComponent arrayComponent ->
37+
resolveArrayComponent(arrayComponent, context);
3738
case TargetRef.Local local -> resolveLocal(local, context);
3839
case TargetRef.Receiver receiver -> NON_NULL_CONTRACT;
3940
};
4041
}
4142

4243
private ValueContract resolveMethodParameter(TargetRef.MethodParameter target) {
4344
MethodTypeDesc descriptor = target.method().methodTypeSymbol();
44-
String parameterDescriptor = descriptor.parameterList().get(target.parameterIndex()).descriptorString();
45+
String parameterDescriptor =
46+
descriptor.parameterList().get(target.parameterIndex()).descriptorString();
4547
if (!isReferenceDescriptor(parameterDescriptor)) {
4648
return ValueContract.none();
4749
}
@@ -111,7 +113,8 @@ private ValueContract resolveLocal(TargetRef.Local target, ResolutionContext con
111113

112114
private AnnotatedTypeUse arrayComponentTypeUse(
113115
TargetRef.ArrayComponent target, ResolutionContext context) {
114-
AnnotatedTypeUse parentType = arraySourceTypeUse(target.arrayTarget(), target.arrayDescriptor(), context);
116+
AnnotatedTypeUse parentType =
117+
arraySourceTypeUse(target.arrayTarget(), target.arrayDescriptor(), context);
115118
if (parentType == null || !target.arrayDescriptor().startsWith("[")) {
116119
return null;
117120
}
@@ -131,7 +134,8 @@ private AnnotatedTypeUse arrayComponentTypeUse(
131134
remainingTypeAnnotations.add(
132135
new TypeUseAnnotation(typeAnnotation.annotation(), List.copyOf(remainingPath)));
133136
}
134-
return new AnnotatedTypeUse(componentDescriptor, List.copyOf(rootAnnotations), List.copyOf(remainingTypeAnnotations));
137+
return new AnnotatedTypeUse(
138+
componentDescriptor, List.copyOf(rootAnnotations), List.copyOf(remainingTypeAnnotations));
135139
}
136140

137141
private AnnotatedTypeUse arraySourceTypeUse(
@@ -146,14 +150,17 @@ private AnnotatedTypeUse arraySourceTypeUse(
146150
case TargetRef.MethodReturn methodReturn -> methodReturnTypeUse(methodReturn.method());
147151
case TargetRef.InvokedMethod invokedMethod -> invokedMethodTypeUse(invokedMethod, context);
148152
case TargetRef.Field field -> fieldTypeUse(field, context);
149-
case TargetRef.ArrayComponent arrayComponent -> arrayComponentTypeUse(arrayComponent, context);
153+
case TargetRef.ArrayComponent arrayComponent ->
154+
arrayComponentTypeUse(arrayComponent, context);
150155
case TargetRef.Local local -> localTypeUse(local, descriptorHint, context);
151-
case TargetRef.Receiver receiver -> new AnnotatedTypeUse("L" + receiver.ownerInternalName() + ";", List.of(), List.of());
156+
case TargetRef.Receiver receiver ->
157+
new AnnotatedTypeUse("L" + receiver.ownerInternalName() + ";", List.of(), List.of());
152158
};
153159
}
154160

155161
private AnnotatedTypeUse methodParameterTypeUse(MethodModel method, int parameterIndex) {
156-
String descriptor = method.methodTypeSymbol().parameterList().get(parameterIndex).descriptorString();
162+
String descriptor =
163+
method.methodTypeSymbol().parameterList().get(parameterIndex).descriptorString();
157164
List<Annotation> rootAnnotations = new ArrayList<>();
158165
List<TypeUseAnnotation> typeAnnotations = new ArrayList<>();
159166

@@ -171,13 +178,15 @@ private AnnotatedTypeUse methodParameterTypeUse(MethodModel method, int paramete
171178
.ifPresent(
172179
attr -> {
173180
for (TypeAnnotation typeAnnotation : attr.annotations()) {
174-
if (typeAnnotation.targetInfo() instanceof TypeAnnotation.FormalParameterTarget target
181+
if (typeAnnotation.targetInfo()
182+
instanceof TypeAnnotation.FormalParameterTarget target
175183
&& target.formalParameterIndex() == parameterIndex) {
176184
addTypeAnnotation(rootAnnotations, typeAnnotations, typeAnnotation);
177185
}
178186
}
179187
});
180-
return new AnnotatedTypeUse(descriptor, List.copyOf(rootAnnotations), List.copyOf(typeAnnotations));
188+
return new AnnotatedTypeUse(
189+
descriptor, List.copyOf(rootAnnotations), List.copyOf(typeAnnotations));
181190
}
182191

183192
private AnnotatedTypeUse methodReturnTypeUse(MethodModel method) {
@@ -193,12 +202,14 @@ private AnnotatedTypeUse methodReturnTypeUse(MethodModel method) {
193202
.ifPresent(
194203
attr -> {
195204
for (TypeAnnotation typeAnnotation : attr.annotations()) {
196-
if (typeAnnotation.targetInfo().targetType() == TypeAnnotation.TargetType.METHOD_RETURN) {
205+
if (typeAnnotation.targetInfo().targetType()
206+
== TypeAnnotation.TargetType.METHOD_RETURN) {
197207
addTypeAnnotation(rootAnnotations, typeAnnotations, typeAnnotation);
198208
}
199209
}
200210
});
201-
return new AnnotatedTypeUse(descriptor, List.copyOf(rootAnnotations), List.copyOf(typeAnnotations));
211+
return new AnnotatedTypeUse(
212+
descriptor, List.copyOf(rootAnnotations), List.copyOf(typeAnnotations));
202213
}
203214

204215
private AnnotatedTypeUse invokedMethodTypeUse(
@@ -241,7 +252,8 @@ private AnnotatedTypeUse fieldTypeUse(FieldModel field) {
241252
}
242253
}
243254
});
244-
return new AnnotatedTypeUse(descriptor, List.copyOf(rootAnnotations), List.copyOf(typeAnnotations));
255+
return new AnnotatedTypeUse(
256+
descriptor, List.copyOf(rootAnnotations), List.copyOf(typeAnnotations));
245257
}
246258

247259
private AnnotatedTypeUse localTypeUse(

framework/src/main/java/io/github/eisop/runtimeframework/instrumentation/EnforcementInstrumenter.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package io.github.eisop.runtimeframework.instrumentation;
22

33
import io.github.eisop.runtimeframework.filter.ClassInfo;
4-
import io.github.eisop.runtimeframework.planning.EnforcementPlanner;
54
import io.github.eisop.runtimeframework.planning.BridgePlan;
65
import io.github.eisop.runtimeframework.planning.ClassContext;
6+
import io.github.eisop.runtimeframework.planning.EnforcementPlanner;
77
import io.github.eisop.runtimeframework.planning.InstrumentationAction;
88
import io.github.eisop.runtimeframework.planning.StrategyBackedEnforcementPlanner;
99
import io.github.eisop.runtimeframework.planning.ValueAccess;
@@ -106,8 +106,7 @@ private void emitBridge(ClassBuilder builder, BridgePlan plan) {
106106
});
107107
}
108108

109-
private void emitBridgeActions(
110-
CodeBuilder builder, BridgePlan plan, BridgeActionTiming timing) {
109+
private void emitBridgeActions(CodeBuilder builder, BridgePlan plan, BridgeActionTiming timing) {
111110
for (InstrumentationAction action : plan.actions()) {
112111
if (timing.matches(action)) {
113112
emitBridgeAction(builder, action);
@@ -133,11 +132,7 @@ private void emitValueCheckAction(
133132
}
134133
for (var requirement : action.contract().requirements()) {
135134
propertyEmitter.emitCheck(
136-
builder,
137-
requirement,
138-
action.valueAccess(),
139-
action.attribution(),
140-
action.diagnostic());
135+
builder, requirement, action.valueAccess(), action.attribution(), action.diagnostic());
141136
}
142137
}
143138

@@ -170,7 +165,8 @@ private void emitTopOfStackCheck(
170165
switch (type.slotSize()) {
171166
case 1 -> builder.dup();
172167
case 2 -> builder.dup2();
173-
default -> throw new IllegalStateException("Unsupported stack size for check emission: " + type);
168+
default ->
169+
throw new IllegalStateException("Unsupported stack size for check emission: " + type);
174170
}
175171
action.generator().generateCheck(builder, type, action.diagnostic().displayName());
176172
}

framework/src/main/java/io/github/eisop/runtimeframework/instrumentation/EnforcementTransform.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ private void handleInvoke(CodeBuilder b, InvokeInstruction i, BytecodeLocation l
183183
}
184184
}
185185

186-
private void handleArrayStore(
187-
CodeBuilder b, ArrayStoreInstruction a, BytecodeLocation location) {
186+
private void handleArrayStore(CodeBuilder b, ArrayStoreInstruction a, BytecodeLocation location) {
188187
if (a.opcode() == Opcode.AASTORE) {
189188
FlowEvent.ArrayStore event =
190189
new FlowEvent.ArrayStore(
@@ -256,7 +255,8 @@ public void emitParameterChecks(CodeBuilder builder) {
256255
}
257256
}
258257
if (!events.isEmpty()) {
259-
emitActions(builder, planner.planMethod(methodContext, events), ActionTiming.METHOD_ENTRY, null);
258+
emitActions(
259+
builder, planner.planMethod(methodContext, events), ActionTiming.METHOD_ENTRY, null);
260260
}
261261
}
262262

@@ -299,18 +299,12 @@ private void emitValueCheckAction(
299299
}
300300
for (var requirement : action.contract().requirements()) {
301301
propertyEmitter.emitCheck(
302-
builder,
303-
requirement,
304-
action.valueAccess(),
305-
action.attribution(),
306-
action.diagnostic());
302+
builder, requirement, action.valueAccess(), action.attribution(), action.diagnostic());
307303
}
308304
}
309305

310306
private void emitLegacyCheckAction(
311-
CodeBuilder builder,
312-
InstrumentationAction.LegacyCheckAction action,
313-
FlowEvent event) {
307+
CodeBuilder builder, InstrumentationAction.LegacyCheckAction action, FlowEvent event) {
314308
String diagnosticName = action.diagnostic().displayName();
315309
switch (action.valueAccess()) {
316310
case ValueAccess.LocalSlot localSlot -> {
@@ -343,11 +337,15 @@ private void emitLegacyCheckAction(
343337
}
344338

345339
private void emitTopOfStackCheck(
346-
CodeBuilder builder, TypeKind type, io.github.eisop.runtimeframework.core.CheckGenerator generator, String diagnosticName) {
340+
CodeBuilder builder,
341+
TypeKind type,
342+
io.github.eisop.runtimeframework.core.CheckGenerator generator,
343+
String diagnosticName) {
347344
switch (type.slotSize()) {
348345
case 1 -> builder.dup();
349346
case 2 -> builder.dup2();
350-
default -> throw new IllegalStateException("Unsupported stack size for check emission: " + type);
347+
default ->
348+
throw new IllegalStateException("Unsupported stack size for check emission: " + type);
351349
}
352350
generator.generateCheck(builder, type, diagnosticName);
353351
}

framework/src/main/java/io/github/eisop/runtimeframework/instrumentation/ReferenceValueTracker.java

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import java.lang.classfile.MethodModel;
66
import java.lang.classfile.Opcode;
77
import java.lang.classfile.TypeKind;
8-
import java.lang.classfile.attribute.StackMapFrameInfo;
98
import java.lang.classfile.attribute.CodeAttribute;
9+
import java.lang.classfile.attribute.StackMapFrameInfo;
1010
import java.lang.classfile.constantpool.ClassEntry;
1111
import java.lang.classfile.instruction.ArrayLoadInstruction;
1212
import java.lang.classfile.instruction.ArrayStoreInstruction;
@@ -77,7 +77,8 @@ Optional<TargetRef.ArrayComponent> arrayComponentTarget(int arrayRefDepthFromTop
7777
return Optional.empty();
7878
}
7979

80-
return Optional.of(new TargetRef.ArrayComponent(arrayRef.descriptor(), arrayRef.sourceTarget()));
80+
return Optional.of(
81+
new TargetRef.ArrayComponent(arrayRef.descriptor(), arrayRef.sourceTarget()));
8182
}
8283

8384
void acceptInstruction(java.lang.classfile.Instruction instruction) {
@@ -91,18 +92,25 @@ void acceptInstruction(java.lang.classfile.Instruction instruction) {
9192
case StoreInstruction store -> simulateStore(store);
9293
case ConstantInstruction constant -> simulateConstant(constant);
9394
case FieldInstruction field -> simulateField(field);
94-
case InvokeInstruction invoke -> simulateInvoke(invoke.typeSymbol(), hasReceiver(invoke.opcode()), invokeReturnSource(invoke));
95-
case InvokeDynamicInstruction invokeDynamic -> simulateInvoke(invokeDynamic.typeSymbol(), false, null);
95+
case InvokeInstruction invoke ->
96+
simulateInvoke(
97+
invoke.typeSymbol(), hasReceiver(invoke.opcode()), invokeReturnSource(invoke));
98+
case InvokeDynamicInstruction invokeDynamic ->
99+
simulateInvoke(invokeDynamic.typeSymbol(), false, null);
96100
case ArrayLoadInstruction arrayLoad -> simulateArrayLoad(arrayLoad);
97101
case ArrayStoreInstruction ignored -> simulateArrayStore();
98102
case TypeCheckInstruction typeCheck -> simulateTypeCheck(typeCheck);
99103
case NewObjectInstruction newObject ->
100-
currentState.push(TrackedValue.reference(newObject.className().asSymbol().descriptorString(), null));
101-
case NewReferenceArrayInstruction newReferenceArray -> simulateNewReferenceArray(newReferenceArray);
102-
case NewPrimitiveArrayInstruction newPrimitiveArray -> simulateNewPrimitiveArray(newPrimitiveArray);
104+
currentState.push(
105+
TrackedValue.reference(newObject.className().asSymbol().descriptorString(), null));
106+
case NewReferenceArrayInstruction newReferenceArray ->
107+
simulateNewReferenceArray(newReferenceArray);
108+
case NewPrimitiveArrayInstruction newPrimitiveArray ->
109+
simulateNewPrimitiveArray(newPrimitiveArray);
103110
case NewMultiArrayInstruction newMultiArray -> simulateNewMultiArray(newMultiArray);
104111
case ConvertInstruction convert -> simulateConvert(convert);
105-
case IncrementInstruction increment -> currentState.store(increment.slot(), TrackedValue.primitive(TypeKind.INT));
112+
case IncrementInstruction increment ->
113+
currentState.store(increment.slot(), TrackedValue.primitive(TypeKind.INT));
106114
case OperatorInstruction operator -> simulateOperator(operator);
107115
case StackInstruction stackInstruction -> simulateStack(stackInstruction.opcode());
108116
case BranchInstruction branch -> simulateBranch(branch);
@@ -175,8 +183,7 @@ private void simulateConstant(ConstantInstruction constant) {
175183
private void simulateField(FieldInstruction field) {
176184
String descriptor = field.typeSymbol().descriptorString();
177185
TargetRef.Field sourceTarget =
178-
new TargetRef.Field(
179-
field.owner().asInternalName(), field.name().stringValue(), descriptor);
186+
new TargetRef.Field(field.owner().asInternalName(), field.name().stringValue(), descriptor);
180187

181188
switch (field.opcode()) {
182189
case GETSTATIC -> currentState.push(TrackedValue.fromDescriptor(descriptor, sourceTarget));
@@ -234,7 +241,8 @@ private void simulateTypeCheck(TypeCheckInstruction typeCheck) {
234241
}
235242

236243
if (typeCheck.opcode() == Opcode.CHECKCAST) {
237-
currentState.push(TrackedValue.reference(typeCheck.type().asSymbol().descriptorString(), null));
244+
currentState.push(
245+
TrackedValue.reference(typeCheck.type().asSymbol().descriptorString(), null));
238246
return;
239247
}
240248

@@ -280,8 +288,22 @@ private void simulateOperator(OperatorInstruction operator) {
280288
currentState.pop();
281289
currentState.push(TrackedValue.primitive(operator.typeKind()));
282290
}
283-
case IADD, ISUB, IMUL, IDIV, IREM, IAND, IOR, IXOR, ISHL, ISHR, IUSHR,
284-
FADD, FSUB, FMUL, FDIV, FREM -> {
291+
case IADD,
292+
ISUB,
293+
IMUL,
294+
IDIV,
295+
IREM,
296+
IAND,
297+
IOR,
298+
IXOR,
299+
ISHL,
300+
ISHR,
301+
IUSHR,
302+
FADD,
303+
FSUB,
304+
FMUL,
305+
FDIV,
306+
FREM -> {
285307
currentState.pop();
286308
currentState.pop();
287309
currentState.push(TrackedValue.primitive(operator.typeKind()));
@@ -469,8 +491,14 @@ private void simulateDup2X2() {
469491
private void simulateBranch(BranchInstruction branch) {
470492
switch (branch.opcode()) {
471493
case IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IFNULL, IFNONNULL -> currentState.pop();
472-
case IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE,
473-
IF_ACMPEQ, IF_ACMPNE -> {
494+
case IF_ICMPEQ,
495+
IF_ICMPNE,
496+
IF_ICMPLT,
497+
IF_ICMPGE,
498+
IF_ICMPGT,
499+
IF_ICMPLE,
500+
IF_ACMPEQ,
501+
IF_ACMPNE -> {
474502
currentState.pop();
475503
currentState.pop();
476504
}
@@ -526,7 +554,9 @@ private boolean hasReceiver(Opcode opcode) {
526554
}
527555

528556
private TrackedValue componentValue(TrackedValue arrayRef) {
529-
if (arrayRef == null || arrayRef.descriptor() == null || !arrayRef.descriptor().startsWith("[")) {
557+
if (arrayRef == null
558+
|| arrayRef.descriptor() == null
559+
|| !arrayRef.descriptor().startsWith("[")) {
530560
return TrackedValue.reference(null, null);
531561
}
532562

@@ -607,10 +637,14 @@ private static TrackedValue fromVerificationType(
607637
StackMapFrameInfo.VerificationTypeInfo typeInfo, String ownerInternalName) {
608638
return switch (typeInfo) {
609639
case StackMapFrameInfo.SimpleVerificationTypeInfo.TOP -> null;
610-
case StackMapFrameInfo.SimpleVerificationTypeInfo.INTEGER -> TrackedValue.primitive(TypeKind.INT);
611-
case StackMapFrameInfo.SimpleVerificationTypeInfo.FLOAT -> TrackedValue.primitive(TypeKind.FLOAT);
612-
case StackMapFrameInfo.SimpleVerificationTypeInfo.LONG -> TrackedValue.primitive(TypeKind.LONG);
613-
case StackMapFrameInfo.SimpleVerificationTypeInfo.DOUBLE -> TrackedValue.primitive(TypeKind.DOUBLE);
640+
case StackMapFrameInfo.SimpleVerificationTypeInfo.INTEGER ->
641+
TrackedValue.primitive(TypeKind.INT);
642+
case StackMapFrameInfo.SimpleVerificationTypeInfo.FLOAT ->
643+
TrackedValue.primitive(TypeKind.FLOAT);
644+
case StackMapFrameInfo.SimpleVerificationTypeInfo.LONG ->
645+
TrackedValue.primitive(TypeKind.LONG);
646+
case StackMapFrameInfo.SimpleVerificationTypeInfo.DOUBLE ->
647+
TrackedValue.primitive(TypeKind.DOUBLE);
614648
case StackMapFrameInfo.SimpleVerificationTypeInfo.NULL -> TrackedValue.reference(null, null);
615649
case StackMapFrameInfo.SimpleVerificationTypeInfo.UNINITIALIZED_THIS ->
616650
TrackedValue.reference("L" + ownerInternalName + ";", null);

0 commit comments

Comments
 (0)