Skip to content

Commit

Permalink
Bump Ethylene dependency to latest, bump version to 0.18.0
Browse files Browse the repository at this point in the history
 * Delete ElementPath.java, ElementPathUtils.java, associated test as the functionality is now duplicated by Ethylene's ConfigPath
  • Loading branch information
Steanky committed Mar 21, 2024
1 parent f739b92 commit af74767
Show file tree
Hide file tree
Showing 14 changed files with 174 additions and 1,356 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = "com.github.steanky"
version = "0.17.0"
version = "0.18.0"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.github.steanky.element.core;

import com.github.steanky.element.core.path.ElementPath;
import com.github.steanky.ethylene.core.path.ConfigPath;

/**
* Represents a generic exception thrown by various parts of the Element API. Can have an associated {@link ElementPath}
* Represents a generic exception thrown by various parts of the Element API. Can have an associated {@link ConfigPath}
* and {@link Class} which, respectively, define a path and/or class related to this error.
*/
public class ElementException extends RuntimeException {
Expand All @@ -15,7 +15,7 @@ public class ElementException extends RuntimeException {
/**
* The element path associated with this error.
*/
private ElementPath elementPath;
private ConfigPath configPath;

/**
* Creates a new ElementException with no detail message or cause.
Expand Down Expand Up @@ -64,13 +64,13 @@ public void setElementClass(Class<?> elementClass) {
}

/**
* Sets the {@link ElementPath} associated with this error. This method does nothing if an error path is already set.
* Sets the {@link ConfigPath} associated with this error. This method does nothing if an error path is already set.
*
* @param elementPath the path
* @param configPath the path
*/
public void setElementPath(ElementPath elementPath) {
if (this.elementPath == null) {
this.elementPath = elementPath;
public void setConfigPath(ConfigPath configPath) {
if (this.configPath == null) {
this.configPath = configPath;
}
}

Expand All @@ -88,24 +88,24 @@ public Class<?> elementClass() {
*
* @return the error path
*/
public ElementPath errorPath() {
return elementPath;
public ConfigPath errorPath() {
return configPath;
}

@Override
public String getMessage() {
final String baseMessage = super.getMessage();
final StringBuilder builder = new StringBuilder(baseMessage.length() + 100);
final StringBuilder builder = new StringBuilder(baseMessage.length());
final Class<?> elementClass = this.elementClass;
final ElementPath elementPath = this.elementPath;
final ConfigPath elementPath = this.configPath;

builder.append("\"").append(baseMessage).append("\"");
builder.append('\"').append(baseMessage).append('\"');
if (elementClass != null) {
builder.append(System.lineSeparator()).append("Relevant class: ").append(elementClass);
}

if (elementPath != null) {
builder.append(System.lineSeparator()).append("Data path: '").append(elementPath).append("'");
builder.append(System.lineSeparator()).append("Data path: '").append(elementPath).append('\'');
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.github.steanky.element.core.context.ElementContext;
import com.github.steanky.element.core.dependency.DependencyProvider;
import com.github.steanky.element.core.path.ElementPath;
import com.github.steanky.ethylene.core.path.ConfigPath;
import org.jetbrains.annotations.NotNull;

/**
Expand All @@ -18,12 +18,12 @@ public interface ElementFactory<TData, TElement> {
*
* @param objectData the specific data object used to create this type; may be null if this element does not
* accept any data
* @param dataPath the path of the data used to create this type; will always be non-null even if the
* @param configPath the path of the data used to create this type; will always be non-null even if the
* element accepts no data, because in such cases there is still a type key present
* @param context the element context, potentially used for resolving children
* @param dependencyProvider the provider of dependency objects that are not elements
* @return the element object
*/
@NotNull TElement make(final TData objectData, final @NotNull ElementPath dataPath,
@NotNull TElement make(final TData objectData, final @NotNull ConfigPath configPath,
final @NotNull ElementContext context, final @NotNull DependencyProvider dependencyProvider);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import com.github.steanky.element.core.context.ElementContext;
import com.github.steanky.element.core.dependency.DependencyProvider;
import com.github.steanky.element.core.path.ElementPath;
import org.jetbrains.annotations.NotNull;

import com.github.steanky.ethylene.core.path.ConfigPath;

import java.lang.annotation.*;

/**
Expand All @@ -17,7 +18,7 @@
public @interface Child {
/**
* The path of the child dependency, relative to the configuration object on which it is defined. Syntax is
* interpreted as if by calling {@link ElementPath#of(String)}.
* interpreted as if by calling {@link ConfigPath#of(String)}.
*
* @return the value of this annotation
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import com.github.steanky.element.core.Registry;
import com.github.steanky.element.core.dependency.DependencyProvider;
import com.github.steanky.element.core.key.KeyExtractor;
import com.github.steanky.element.core.path.ElementPath;
import com.github.steanky.ethylene.core.collection.ConfigContainer;
import com.github.steanky.ethylene.core.collection.ConfigNode;
import com.github.steanky.ethylene.core.path.ConfigPath;
import com.github.steanky.ethylene.core.processor.ConfigProcessException;
import com.github.steanky.ethylene.core.processor.ConfigProcessor;
import net.kyori.adventure.key.Key;
Expand All @@ -30,9 +30,9 @@ public class BasicElementContext implements ElementContext {
private final Registry<Boolean> cacheRegistry;
private final KeyExtractor typeKeyExtractor;
private final ConfigContainer rootCopy;
private final Map<ElementPath, DataInfo> dataObjects;
private final Map<ElementPath, Object> elementObjects;
private final Map<ElementPath, Key> typeMap;
private final Map<ConfigPath, DataInfo> dataObjects;
private final Map<ConfigPath, Object> elementObjects;
private final Map<ConfigPath, Key> typeMap;

/**
* Creates a new instance of this class.
Expand Down Expand Up @@ -62,15 +62,21 @@ public BasicElementContext(final @NotNull Registry<ConfigProcessor<?>> processor

@SuppressWarnings("unchecked")
@Override
public <TElement> @NotNull TElement provide(final @NotNull ElementPath path, final @Nullable ConfigNode substitute,
public <TElement> @NotNull TElement provide(final @NotNull ConfigPath path, final @Nullable ConfigNode substitute,
final @NotNull DependencyProvider dependencyProvider, final boolean cache) {
try {
final ElementPath absolutePath = path.toAbsolute();
final ConfigPath absolutePath = path.toAbsolute();

Key objectType = typeMap.get(absolutePath);
final ConfigNode dataNode;
if (objectType == null) {
ConfigNode child = substitute != null ? substitute : absolutePath.followNode(rootCopy);
ConfigNode child;
try {
child = substitute != null ? substitute : rootCopy.atOrThrow(absolutePath).asNodeOrThrow();
}
catch (ConfigProcessException e) {
throw elementException(e, absolutePath, "Configuration error");
}

objectType = typeKeyExtractor.extractKey(child);
typeMap.put(absolutePath, objectType);
Expand All @@ -95,7 +101,7 @@ public BasicElementContext(final @NotNull Registry<ConfigProcessor<?>> processor
if (dataInfo == null) {
try {
final ConfigNode configuration = dataNode != null ? dataNode :
(substitute != null ? substitute : absolutePath.followNode(rootCopy));
(substitute != null ? substitute : rootCopy.atOrThrow(absolutePath).asNodeOrThrow());

final Object data = processorRegistry.contains(objectTypeFinal) ?
processorRegistry.lookup(objectTypeFinal).dataFromElement(configuration) : null;
Expand Down Expand Up @@ -127,7 +133,7 @@ public BasicElementContext(final @NotNull Registry<ConfigProcessor<?>> processor
.make(dataInfo.data, absolutePath, this, dependencyProvider);
}
catch (ElementException exception) {
exception.setElementPath(path);
exception.setConfigPath(path);
exception.fillInStackTrace();
throw exception;
}
Expand Down
Loading

0 comments on commit af74767

Please sign in to comment.