Skip to content

Commit

Permalink
Use separate object for code values
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Jun 2, 2024
1 parent 0b9385e commit 83d3aca
Show file tree
Hide file tree
Showing 15 changed files with 817 additions and 349 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.github.sheikah45.fx2j.processor.internal.ObjectNodeProcessor;
import io.github.sheikah45.fx2j.processor.internal.model.ObjectNodeCode;
import io.github.sheikah45.fx2j.processor.internal.resolve.MethodResolver;
import io.github.sheikah45.fx2j.processor.internal.resolve.ResolverContainer;
import io.github.sheikah45.fx2j.processor.internal.resolve.TypeResolver;
import io.github.sheikah45.fx2j.processor.internal.utils.JavaFileUtils;
import io.github.sheikah45.fx2j.processor.internal.utils.StringUtils;
Expand All @@ -42,6 +43,7 @@ public class FxmlProcessor {
public static final String BUILDER_PROVIDED_CONTROLLER_NAME = "builderProvidedController";
public static final String BUILDER_PROVIDED_ROOT_NAME = "builderProvidedRoot";

private final ResolverContainer resolverContainer;
private final TypeResolver typeResolver;
private final MethodResolver methodResolver;
private final String rootPackage;
Expand Down Expand Up @@ -71,8 +73,9 @@ public FxmlProcessor(Path filePath, Path resourceRootPath, String rootPackage, C
.map(FxmlProcessingInstruction.Import::value)
.collect(Collectors.toSet());

typeResolver = new TypeResolver(imports, classLoader);
methodResolver = new MethodResolver(typeResolver);
resolverContainer = ResolverContainer.from(imports, classLoader);
typeResolver = resolverContainer.getTypeResolver();
methodResolver = resolverContainer.getMethodResolver();

controllerClass = fxmlComponents.rootNode()
.content()
Expand All @@ -94,8 +97,8 @@ public FxmlProcessor(Path filePath, Path resourceRootPath, String rootPackage, C
.orElse(Object.class);

Path absoluteResourceRootPath = resourceRootPath.toAbsolutePath();
objectNodeCode = new ObjectNodeProcessor(fxmlComponents.rootNode(), controllerClass, typeResolver,
methodResolver, absoluteFilePath,
objectNodeCode = new ObjectNodeProcessor(fxmlComponents.rootNode(), controllerClass, resolverContainer,
absoluteFilePath,
absoluteResourceRootPath, this.rootPackage).getNodeCode();
rootClass = typeResolver.wrapType(objectNodeCode.nodeClass());

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package io.github.sheikah45.fx2j.processor.internal.model;

import java.util.List;
import java.util.Objects;

public sealed interface CodeValue {

sealed interface ArrayInitialization extends CodeValue {
record Declared(java.lang.reflect.Type componentType, List<CodeValue> values) implements ArrayInitialization {
public Declared {
Objects.requireNonNull(componentType, "componentType cannot be null");
Objects.requireNonNull(values, "values cannot be null");
values = List.copyOf(values);
}
}
record Sized(java.lang.reflect.Type componentType, int size) implements ArrayInitialization {
public Sized {
Objects.requireNonNull(componentType, "componentType cannot be null");
}
}
}
record Null() implements CodeValue {}
record Char(char value) implements CodeValue {}
record Literal(java.lang.String value) implements CodeValue {
public Literal {
Objects.requireNonNull(value, "value cannot be null");
}
}
record String(java.lang.String value) implements CodeValue {
public String {
Objects.requireNonNull(value, "value cannot be null");
}
}
record Type(java.lang.reflect.Type type) implements CodeValue {
public Type {
Objects.requireNonNull(type, "type cannot be null");
}
}
record Enum(java.lang.Enum<?> value) implements CodeValue {
public Enum {
Objects.requireNonNull(value, "value cannot be null");
}
}
record MethodCall(CodeValue receiver, java.lang.String method, List<CodeValue> args) implements CodeValue {
public MethodCall {
Objects.requireNonNull(receiver, "receiver cannot be null");
Objects.requireNonNull(method, "method cannot be null");
Objects.requireNonNull(args, "args cannot be null");
args = List.copyOf(args);
}
}
record FieldAccess(CodeValue receiver, java.lang.String field) implements CodeValue {
public FieldAccess {
Objects.requireNonNull(receiver, "receiver cannot be null");
Objects.requireNonNull(field, "field cannot be null");
}
}
record Assignment(java.lang.reflect.Type type, java.lang.String identifier, CodeValue value) implements CodeValue {
public Assignment {
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(identifier, "identifier cannot be null");
Objects.requireNonNull(value, "value cannot be null");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package io.github.sheikah45.fx2j.processor.internal.model;

import com.squareup.javapoet.CodeBlock;

import java.lang.reflect.Type;
import java.util.List;
import java.util.Objects;

public record ExpressionResult(Type type, String identifier, CodeBlock initializationCode) {}
public record ExpressionResult(Type type, String identifier, List<CodeValue.Assignment> initializers) {
public ExpressionResult {
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(identifier, "identifier cannot be null");
Objects.requireNonNull(initializers, "initializers cannot be null");
initializers = List.copyOf(initializers);
}
}
Loading

0 comments on commit 83d3aca

Please sign in to comment.