Skip to content

Commit 062c1ac

Browse files
committed
fix class name generator + interface component view
1 parent 0515e5b commit 062c1ac

6 files changed

Lines changed: 17 additions & 10 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
package com.github.elebras1.flecs;
22

3+
import java.lang.foreign.MemorySegment;
4+
35
public interface ComponentView {
6+
void setMemorySegment(MemorySegment memorySegment);
47
}

src/main/java/com/github/elebras1/flecs/processor/AbstractGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import javax.lang.model.element.TypeElement;
99
import javax.lang.model.element.VariableElement;
1010

11-
import static com.github.elebras1.flecs.processor.ComponentAbstractGenerator.DEFAULT_STRING_SIZE;
11+
import static com.github.elebras1.flecs.processor.ComponentGenerator.DEFAULT_STRING_SIZE;
1212

1313
public abstract class AbstractGenerator implements Generator {
1414

src/main/java/com/github/elebras1/flecs/processor/ComponentAbstractGenerator.java renamed to src/main/java/com/github/elebras1/flecs/processor/ComponentGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.lang.foreign.MemorySegment;
88
import java.util.List;
99

10-
public class ComponentAbstractGenerator extends AbstractGenerator {
10+
public class ComponentGenerator extends AbstractGenerator {
1111

1212
protected static final String LAYOUT_FIELD_CLASS = "com.github.elebras1.flecs.util.LayoutField";
1313
protected static final String COMPONENT_INTERFACE = "com.github.elebras1.flecs.Component";

src/main/java/com/github/elebras1/flecs/processor/ComponentMapGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ public class ComponentMapGenerator {
1414

1515
private static final ClassName COMPONENT_INTERFACE = ClassName.get("com.github.elebras1.flecs", "Component");
1616
private static final String MAP_PACKAGE = "com.github.elebras1.flecs";
17-
private static final String MAP_CLASS_NAME = "ComponentMap";
17+
private static final String MAP_COMPONENT_CLASS_NAME = "ComponentMap";
1818

1919
public JavaFile generateComponentMap(List<TypeElement> components) {
20-
TypeSpec.Builder mapClass = TypeSpec.classBuilder(MAP_CLASS_NAME)
20+
TypeSpec.Builder mapClass = TypeSpec.classBuilder(MAP_COMPONENT_CLASS_NAME)
2121
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
2222
.addField(this.createMapField(components.size()))
2323
.addStaticBlock(this.createStaticInitializer(components))

src/main/java/com/github/elebras1/flecs/processor/ComponentProcessor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public class ComponentProcessor extends AbstractProcessor {
1616
private static final Set<String> SUPPORTED_TYPES = Set.of("byte", "short", "int", "long", "float", "double", "boolean", "byte[]", "short[]", "int[]", "long[]", "float[]", "double[]", "boolean[]", "java.lang.String");
1717
private Messager messager;
1818
private Filer filer;
19-
private ComponentAbstractGenerator componentGenerator;
20-
private ComponentViewAbstractGenerator componentViewGenerator;
19+
private ComponentGenerator componentGenerator;
20+
private ComponentViewGenerator componentViewGenerator;
2121
private ComponentMapGenerator mapGenerator;
2222
private List<TypeElement> processedComponents;
2323
private boolean mapGenerated;
@@ -27,8 +27,8 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
2727
super.init(processingEnv);
2828
this.messager = processingEnv.getMessager();
2929
this.filer = processingEnv.getFiler();
30-
this.componentGenerator = new ComponentAbstractGenerator();
31-
this.componentViewGenerator = new ComponentViewAbstractGenerator();
30+
this.componentGenerator = new ComponentGenerator();
31+
this.componentViewGenerator = new ComponentViewGenerator();
3232
this.mapGenerator = new ComponentMapGenerator();
3333
this.processedComponents = new ArrayList<>();
3434
this.mapGenerated = false;

src/main/java/com/github/elebras1/flecs/processor/ComponentViewAbstractGenerator.java renamed to src/main/java/com/github/elebras1/flecs/processor/ComponentViewGenerator.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
import java.lang.foreign.MemorySegment;
77
import java.util.List;
88

9-
import static com.github.elebras1.flecs.processor.ComponentAbstractGenerator.LAYOUT_FIELD_CLASS;
9+
import static com.github.elebras1.flecs.processor.ComponentGenerator.LAYOUT_FIELD_CLASS;
10+
11+
public class ComponentViewGenerator extends AbstractGenerator {
12+
private static final String COMPONENT_VIEW_INTERFACE = "com.github.elebras1.flecs.ComponentView";
1013

11-
public class ComponentViewAbstractGenerator extends AbstractGenerator {
1214
public JavaFile generate(TypeElement recordElement, List<VariableElement> fields) {
1315
String packageName = this.getPackageName(recordElement);
1416
String recordName = recordElement.getSimpleName().toString();
@@ -18,6 +20,7 @@ public JavaFile generate(TypeElement recordElement, List<VariableElement> fields
1820

1921
TypeSpec componentClass = TypeSpec.classBuilder(componentViewClassName)
2022
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
23+
.addSuperinterface(ClassName.bestGuess(COMPONENT_VIEW_INTERFACE))
2124
.addField(this.createField())
2225
.addMethod(this.createSetterMethod())
2326
.addMethods(this.createMethods(fields, componentReference))
@@ -32,6 +35,7 @@ private FieldSpec createField() {
3235

3336
private MethodSpec createSetterMethod() {
3437
return MethodSpec.methodBuilder("setMemorySegment")
38+
.addAnnotation(Override.class)
3539
.addModifiers(Modifier.PUBLIC)
3640
.addParameter(MemorySegment.class, "memorySegment")
3741
.addJavadoc("Internal API - Do not use.\n")

0 commit comments

Comments
 (0)