Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
kashike authored and zml2008 committed Feb 16, 2024
1 parent 567523d commit 7ee6b1e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
32 changes: 16 additions & 16 deletions api/src/main/java/net/kyori/adventure/text/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -1267,67 +1267,67 @@ public interface Component extends ComponentBuilderApplicable, ComponentLike, Ex
* Creates a virtual component.
*
* @param <C> the context type
* @param context the context type
* @param contextType the context type
* @param renderer the renderer
* @return a virtual component
* @since 4.14.0
*/
@Contract(value = "_, _ -> new", pure = true)
static <C> @NotNull VirtualComponent virtual(final @NotNull Class<C> context, final @NotNull VirtualComponentRenderer<C> renderer) {
requireNonNull(context, "context");
static <C> @NotNull VirtualComponent virtual(final @NotNull Class<C> contextType, final @NotNull VirtualComponentRenderer<C> renderer) {
requireNonNull(contextType, "context type");
requireNonNull(renderer, "renderer");
return VirtualComponentImpl.createVirtual(context, renderer);
return VirtualComponentImpl.createVirtual(contextType, renderer);
}

/**
* Creates a virtual component with a value.
*
* @param <C> the context type
* @param context the context type
* @param contextType the context type
* @param renderer the renderer
* @param style the style
* @return a virtual component
* @since 4.14.0
*/
@Contract(value = "_, _, _ -> new", pure = true)
static <C> @NotNull VirtualComponent virtual(final @NotNull Class<C> context, final @NotNull VirtualComponentRenderer<C> renderer, final @NotNull Style style) {
requireNonNull(context, "context");
static <C> @NotNull VirtualComponent virtual(final @NotNull Class<C> contextType, final @NotNull VirtualComponentRenderer<C> renderer, final @NotNull Style style) {
requireNonNull(contextType, "context type");
requireNonNull(renderer, "renderer");
return VirtualComponentImpl.createVirtual(context, renderer, Collections.emptyList(), style);
return VirtualComponentImpl.createVirtual(contextType, renderer, Collections.emptyList(), style);
}

/**
* Creates a virtual component with a value.
*
* @param <C> the context type
* @param context the context type
* @param contextType the context type
* @param renderer the renderer
* @param style the style elements
* @return a virtual component
* @since 4.14.0
*/
@Contract(value = "_, _, _ -> new", pure = true)
static <C> @NotNull VirtualComponent virtual(final @NotNull Class<C> context, final @NotNull VirtualComponentRenderer<C> renderer, final @NotNull StyleBuilderApplicable... style) {
requireNonNull(context, "context");
static <C> @NotNull VirtualComponent virtual(final @NotNull Class<C> contextType, final @NotNull VirtualComponentRenderer<C> renderer, final @NotNull StyleBuilderApplicable... style) {
requireNonNull(contextType, "context type");
requireNonNull(renderer, "renderer");
return VirtualComponentImpl.createVirtual(context, renderer, Collections.emptyList(), Style.style(style));
return VirtualComponentImpl.createVirtual(contextType, renderer, Collections.emptyList(), Style.style(style));
}

/**
* Creates a virtual component with a value.
*
* @param <C> the context type
* @param context the context type
* @param contextType the context type
* @param renderer the renderer
* @param style the style elements
* @return a virtual component
* @since 4.14.0
*/
@Contract(value = "_, _, _ -> new", pure = true)
static <C> @NotNull VirtualComponent virtual(final @NotNull Class<C> context, final @NotNull VirtualComponentRenderer<C> renderer, final @NotNull Iterable<StyleBuilderApplicable> style) {
requireNonNull(context, "context");
static <C> @NotNull VirtualComponent virtual(final @NotNull Class<C> contextType, final @NotNull VirtualComponentRenderer<C> renderer, final @NotNull Iterable<StyleBuilderApplicable> style) {
requireNonNull(contextType, "context type");
requireNonNull(renderer, "renderer");
return VirtualComponentImpl.createVirtual(context, renderer, Collections.emptyList(), Style.style(style));
return VirtualComponentImpl.createVirtual(contextType, renderer, Collections.emptyList(), Style.style(style));
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public interface VirtualComponent extends TextComponent {
* @return the renderer context type
* @since 4.14.0
*/
@NotNull Class<?> context();
@NotNull Class<?> contextType();

/**
* Gets the renderer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,33 @@
import org.jetbrains.annotations.NotNull;

final class VirtualComponentImpl extends TextComponentImpl implements VirtualComponent {
static <C> VirtualComponent createVirtual(final @NotNull Class<C> context, final @NotNull VirtualComponentRenderer<?> renderer) {
return createVirtual(context, renderer, Collections.emptyList(), Style.empty());
static <C> VirtualComponent createVirtual(final @NotNull Class<C> contextType, final @NotNull VirtualComponentRenderer<?> renderer) {
return createVirtual(contextType, renderer, Collections.emptyList(), Style.empty());
}

static <C> VirtualComponent createVirtual(final @NotNull Class<C> context, final @NotNull VirtualComponentRenderer<?> renderer, final List<? extends ComponentLike> children, final Style style) {
static <C> VirtualComponent createVirtual(final @NotNull Class<C> contextType, final @NotNull VirtualComponentRenderer<?> renderer, final List<? extends ComponentLike> children, final Style style) {
final List<Component> filteredChildren = ComponentLike.asComponents(children, IS_NOT_EMPTY);

return new VirtualComponentImpl(filteredChildren, style, "", context, renderer);
return new VirtualComponentImpl(filteredChildren, style, "", contextType, renderer);
}

private final Class<?> context;
private final Class<?> contextType;
private final VirtualComponentRenderer<?> renderer;

private VirtualComponentImpl(final @NotNull List<Component> children, final @NotNull Style style, final @NotNull String content, final @NotNull Class<?> context, final @NotNull VirtualComponentRenderer<?> renderer) {
private VirtualComponentImpl(final @NotNull List<Component> children, final @NotNull Style style, final @NotNull String content, final @NotNull Class<?> contextType, final @NotNull VirtualComponentRenderer<?> renderer) {
super(children, style, content);
this.context = context;
this.contextType = contextType;
this.renderer = renderer;
}

@Override
VirtualComponent create0(final @NotNull List<? extends ComponentLike> children, final @NotNull Style style, final @NotNull String content) {
return new VirtualComponentImpl(ComponentLike.asComponents(children, IS_NOT_EMPTY), style, content, this.context, this.renderer);
return new VirtualComponentImpl(ComponentLike.asComponents(children, IS_NOT_EMPTY), style, content, this.contextType, this.renderer);
}

@Override
public @NotNull Class<?> context() {
return this.context;
public @NotNull Class<?> contextType() {
return this.contextType;
}

@Override
Expand All @@ -74,18 +74,18 @@ VirtualComponent create0(final @NotNull List<? extends ComponentLike> children,
}

static final class BuilderImpl extends TextComponentImpl.BuilderImpl {
private final Class<?> context;
private final Class<?> contextType;
private final VirtualComponentRenderer<?> renderer;

BuilderImpl(final VirtualComponent other) {
super(other);
this.context = other.context();
this.contextType = other.contextType();
this.renderer = other.renderer();
}

@Override
public @NotNull TextComponent build() {
return createVirtual(this.context, this.renderer, this.children, this.buildStyle());
return createVirtual(this.contextType, this.renderer, this.children, this.buildStyle());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public abstract class AbstractComponentRenderer<C> implements ComponentRenderer<
*/
@SuppressWarnings("unchecked")
protected @NotNull Component renderVirtual(final @NotNull VirtualComponent component, final @NotNull C context) {
if (component.context().isInstance(context)) {
if (component.contextType().isInstance(context)) {
return ((VirtualComponentRenderer<C>) component.renderer()).apply(context).asComponent();
}
return component; // will be processed as a TextComponent instead
Expand Down

0 comments on commit 7ee6b1e

Please sign in to comment.