Skip to content

Commit

Permalink
Add tests for parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed May 12, 2024
1 parent 0527322 commit c1b0841
Show file tree
Hide file tree
Showing 50 changed files with 951 additions and 160 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion fx2j-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
id("io.github.sheikah45.fx2j.conventions-publish")
id("io.github.sheikah45.fx2j.conventions-library")
id("io.github.sheikah45.fx2j.conventions-javafx")
}

javafx {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,106 @@
package io.github.sheikah45.fx2j.parser;

import io.github.sheikah45.fx2j.parser.utils.StringUtils;

import java.nio.file.Path;
import java.util.Objects;

public sealed interface FxmlAttribute {
sealed interface Property extends FxmlAttribute {
record Instance(String property, Value value) implements Property {
public Instance {
if (StringUtils.isNullOrBlank(property)) {
throw new IllegalArgumentException("property cannot be blank or null");
}
Objects.requireNonNull(value, "value cannot be null");
}
}
record Static(String className, String property, Value value) implements Property {
public Static {
if (StringUtils.isNullOrBlank(className)) {
throw new IllegalArgumentException("className cannot be blank or null");
}
if (StringUtils.isNullOrBlank(property)) {
throw new IllegalArgumentException("property cannot be blank or null");
}
Objects.requireNonNull(value, "value cannot be null");
}
}

sealed interface Value {}
record Instance(String property, Value value) implements Property {}
record Static(String className, String property, Value value) implements Property {}
record Literal(String value) implements Value {}
record Location(Path location) implements Value {}
record Resource(String resource) implements Value {}
record Reference(String variable) implements Value {}
record BindExpression(String expression) implements Value {}

record Empty() implements Value {}
record Literal(String value) implements Value {
public Literal {
if (StringUtils.isNullOrBlank(value)) {
throw new IllegalArgumentException("value cannot be blank or null");
}
}
}
record Location(Path location) implements Value {
public Location {
Objects.requireNonNull(location, "location cannot be null");
}
}
record Resource(String value) implements Value {
public Resource {
if (StringUtils.isNullOrBlank(value)) {
throw new IllegalArgumentException("value cannot be blank or null");
}
}
}
record Reference(String value) implements Value {
public Reference {
if (StringUtils.isNullOrBlank(value)) {
throw new IllegalArgumentException("value cannot be blank or null");
}
}
}
record Expression(String value) implements Value {
public Expression {
if (StringUtils.isNullOrBlank(value)) {
throw new IllegalArgumentException("value cannot be blank or null");
}
}
}
}
record Id(String value) implements FxmlAttribute {
public Id {
if (StringUtils.isNullOrBlank(value)) {
throw new IllegalArgumentException("id cannot be blank or null");
}
}
}
record Controller(String className) implements FxmlAttribute {
public Controller {
if (StringUtils.isNullOrBlank(className)) {
throw new IllegalArgumentException("className cannot be blank or null");
}
}
}
record Controller(String className) implements FxmlAttribute {}
record EventHandler(String eventName, Value value) implements FxmlAttribute {
sealed interface Value {}

record Script(String value) implements Value {}
record Method(String method) implements Value {}
record Reference(String reference) implements Value {}
record Script(String value) implements Value {
public Script {
if (StringUtils.isNullOrBlank(value)) {
throw new IllegalArgumentException("value cannot be blank or null");
}
}
}
record Method(String method) implements Value {
public Method {
if (StringUtils.isNullOrBlank(method)) {
throw new IllegalArgumentException("method cannot be blank or null");
}
}
}
record Reference(String reference) implements Value {
public Reference {
if (StringUtils.isNullOrBlank(reference)) {
throw new IllegalArgumentException("reference cannot be blank or null");
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package io.github.sheikah45.fx2j.parser;

import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.Objects;

public record FxmlComponents(FxmlNode rootNode, Map<String, Set<String>> processingInstructions) {
public record FxmlComponents(FxmlNode rootNode, List<FxmlProcessingInstruction> processingInstructions) {
public FxmlComponents {
processingInstructions = Map.copyOf(processingInstructions);
Objects.requireNonNull(rootNode, "rootNode cannot be null");
Objects.requireNonNull(processingInstructions, "processingInstructions cannot be null");
processingInstructions = List.copyOf(processingInstructions);
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,102 @@
package io.github.sheikah45.fx2j.parser;

import io.github.sheikah45.fx2j.parser.utils.StringUtils;

import java.nio.charset.Charset;
import java.nio.file.Path;
import java.util.Objects;

public sealed interface FxmlElement {
sealed interface Instance extends FxmlElement {
String id();
sealed interface Declaration extends FxmlElement {
record Class(String className) implements Declaration {
public Class {
if (StringUtils.isNullOrBlank(className)) {
throw new IllegalArgumentException("className cannot be blank or null");
}
}
}
record Value(String className, String value) implements Declaration {
public Value {
if (StringUtils.isNullOrBlank(className)) {
throw new IllegalArgumentException("className cannot be blank or null");
}

if (StringUtils.isNullOrBlank(value)) {
throw new IllegalArgumentException("value cannot be blank or null");
}
}
}
record Constant(String className, String value) implements Declaration {
public Constant {
if (StringUtils.isNullOrBlank(className)) {
throw new IllegalArgumentException("className cannot be blank or null");
}

if (StringUtils.isNullOrBlank(value)) {
throw new IllegalArgumentException("value cannot be blank or null");
}
}
}
record Factory(String factoryClassName, String factoryMethod) implements Declaration {
public Factory {
if (StringUtils.isNullOrBlank(factoryClassName)) {
throw new IllegalArgumentException("factoryClassName cannot be blank or null");
}

if (StringUtils.isNullOrBlank(factoryMethod)) {
throw new IllegalArgumentException("factoryMethod cannot be blank or null");
}
}
}
}
sealed interface Property extends FxmlElement {
record Instance(String property) implements Property {
public Instance {
if (StringUtils.isNullOrBlank(property)) {
throw new IllegalArgumentException("property cannot be blank or null");
}
}
}

record Simple(String id, String className) implements Instance {}
record Value(String id, String className, String value) implements Instance {}
record Constant(String id, String className, String constant) implements Instance {}
record Factory(String id, String factoryClassName, String factoryMethod) implements Instance {}
record Static(String className, String property) implements Property {
public Static {
if (StringUtils.isNullOrBlank(className)) {
throw new IllegalArgumentException("className cannot be blank or null");
}
if (StringUtils.isNullOrBlank(property)) {
throw new IllegalArgumentException("property cannot be blank or null");
}
}
}
}
record Include(Path source, Path resources, Charset charset) implements FxmlElement {
public Include {
Objects.requireNonNull(source, "source cannot be null");
Objects.requireNonNull(charset, "charset cannot be null");
}
}
record Copy(String source) implements FxmlElement {
public Copy {
if (StringUtils.isNullOrBlank(source)) {
throw new IllegalArgumentException("source cannot be blank or null");
}
}
}
record Reference(String source) implements FxmlElement {
public Reference {
if (StringUtils.isNullOrBlank(source)) {
throw new IllegalArgumentException("source cannot be blank or null");
}
}
}
record Include(String id, Path source, Path resources, Charset charset) implements FxmlElement {}
record Copy(String id, String source) implements FxmlElement {}
record Reference(String id, String source) implements FxmlElement {}
record Root(String id, String type) implements FxmlElement {}
record Define() implements FxmlElement {}
record Script() implements FxmlElement {}
record Property(String property) implements FxmlElement {}
record StaticProperty(String className, String property) implements FxmlElement {}
record Root(String type) implements FxmlElement {
public Root {
if (StringUtils.isNullOrBlank(type)) {
throw new IllegalArgumentException("type cannot be blank or null");
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
package io.github.sheikah45.fx2j.parser;

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


public record FxmlNode(FxmlElement element,
List<FxmlAttribute> attributes,
String innerText,
List<FxmlNode> children) {}
List<FxmlNode> children) {

public FxmlNode {
Objects.requireNonNull(element, "element cannot be null");
Objects.requireNonNull(attributes, "attributes cannot be null");
Objects.requireNonNull(innerText, "innerText cannot be null");
Objects.requireNonNull(children, "children cannot be null");
attributes = List.copyOf(attributes);
children = List.copyOf(children);
}
}
Loading

0 comments on commit c1b0841

Please sign in to comment.