Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change PropertyExpression generics to match SkriptLang #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
* @since ALPHA
* @author Olyno, Mwexim
*/
public class ExprAmount extends PropertyExpression<Number, Object> {
public class ExprAmount extends PropertyExpression<Object, Number> {
static {
Parser.getMainRegistration().addPropertyExpression(
ExprAmount.class,
Number.class,
"~objects",
"[1:recursive] (amount|number|size)"
"[1:recursive] (amount|number|size)",
"~objects"
Comment on lines -32 to +33
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the order of the generics is confusing and can easily be changed, but I don't understand why you would change the register methods as well, since they follow the general principle that requires the actual 'patterns' as the last argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

property expressions are mostly used like property of %objects% so that's why Skript has always been the property first than the object types.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. I won't be merging these changes, but feel free, like you said, to make use your own implementation.

);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
* @since ALPHA
* @author Mwexim
*/
public class ExprColorValues extends PropertyExpression<Object, Color> {
public class ExprColorValues extends PropertyExpression<Color, Object> {
static {
Parser.getMainRegistration().addPropertyExpression(
ExprColorValues.class,
Object.class,
"colors",
"(0:hex[adecimal]|1:red|2:green|3:blue|4:alpha) value"
"(0:hex[adecimal]|1:red|2:green|3:blue|4:alpha) value",
"colors"
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
* @since ALPHA
* @author Mwexim
*/
public class ExprDateTimestamp extends PropertyExpression<Number, SkriptDate> {
public class ExprDateTimestamp extends PropertyExpression<SkriptDate, Number> {
static {
Parser.getMainRegistration().addPropertyExpression(
ExprDateTimestamp.class,
Number.class,
"*[date] %date%",
"[1:unix] timestamp"
"[1:unix] timestamp",
"*[date] %date%"
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* @since ALPHA
* @author Romitou
*/
public class ExprLength extends PropertyExpression<Number, String> {
public class ExprLength extends PropertyExpression<String, Number> {
static {
Parser.getMainRegistration().addPropertyExpression(
ExprLength.class,
Number.class,
"string",
"length"
"length",
"string"
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @param <O> The type of the owner of this expression.
* @author Mwexim
*/
public abstract class PropertyExpression<T, O> implements Expression<T> {
public abstract class PropertyExpression<O, T> implements Expression<T> {
public static final String PROPERTY_IDENTIFIER = "property";

private Expression<O> owner;
Expand Down Expand Up @@ -111,11 +111,12 @@ public boolean isGenitive() {
return genitive;
}

public static String[] composePatterns(String owner, String property) {
public static String[] composePatterns(String property, String owner) {
var ownerType = owner.startsWith("*") ? owner.substring(1) : "%" + owner + "%";
return new String[] {
ownerType + "'[s] " + property,
"[the] " + property + " of " + ownerType
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ public <C extends Expression<T>, T> void addExpression(Class<C> c, Class<T> retu
* @param <T> the Expression's return type
* @return an {@link ExpressionRegistrar} to continue the registration process
*/
public <C extends PropertyExpression<T, ?>, T> ExpressionRegistrar<C, T> newPropertyExpression(Class<C> c, Class<T> returnType, String owner, String property) {
return (ExpressionRegistrar<C, T>) newExpression(c, returnType, false, PropertyExpression.composePatterns(owner, property))
public <C extends PropertyExpression<?, T>, T> ExpressionRegistrar<C, T> newPropertyExpression(Class<C> c, Class<T> returnType, String property, String owner) {
return (ExpressionRegistrar<C, T>) newExpression(c, returnType, false, PropertyExpression.composePatterns(property, owner))
.addData(PropertyExpression.PROPERTY_IDENTIFIER, property);
}

Expand All @@ -203,8 +203,8 @@ public <C extends Expression<T>, T> void addExpression(Class<C> c, Class<T> retu
* @param <C> the Expression
* @param <T> the Expression's return type
*/
public <C extends PropertyExpression<T, ?>, T> void addPropertyExpression(Class<C> c, Class<T> returnType, String owner, String property) {
newPropertyExpression(c, returnType, owner, property).register();
public <C extends PropertyExpression<?, T>, T> void addPropertyExpression(Class<C> c, Class<T> returnType, String property, String owner) {
newPropertyExpression(c, returnType, property, owner).register();
}

/**
Expand All @@ -217,8 +217,8 @@ public <C extends Expression<T>, T> void addExpression(Class<C> c, Class<T> retu
* @param <C> the Expression
* @param <T> the Expression's return type
*/
public <C extends PropertyExpression<T, ?>, T> void addPropertyExpression(Class<C> c, Class<T> returnType, int priority, String owner, String property) {
newPropertyExpression(c, returnType, owner, property).setPriority(priority).register();
public <C extends PropertyExpression<?, T>, T> void addPropertyExpression(Class<C> c, Class<T> returnType, int priority, String property, String owner) {
newPropertyExpression(c, returnType, property, owner).setPriority(priority).register();
}

/**
Expand Down
Loading