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

Add support for grabbing the involved event in SimplePropertyExpression #5309

Closed
Closed
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 @@ -28,34 +28,48 @@

/**
* A base class for property expressions that requires only few overridden methods
*
* @author Peter Güttinger

* @see PropertyExpression
* @see PropertyExpression#register(Class, Class, String, String)
*/
@SuppressWarnings("deprecation") // for backwards compatibility
public abstract class SimplePropertyExpression<F, T> extends PropertyExpression<F, T> implements Converter<F, T> {

@SuppressWarnings({"unchecked", "null"})

private Event event;

@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
setExpr((Expression<? extends F>) exprs[0]);
return true;
}

protected abstract String getPropertyName();

@Override
@Nullable
public abstract T convert(F f);

@Override
protected T[] get(final Event e, final F[] source) {
protected T[] get(Event event, F[] source) {
this.event = event;
return super.get(source, this);
}


/**
* Returns the Event that was used in this expression.
* Will only be null if called in the init method.
*
* @return The Event that was used in this expression.
*/
@Nullable
protected Event getEvent() {
return event;
}

@Override
public String toString(final @Nullable Event e, final boolean debug) {
return "the " + getPropertyName() + " of " + getExpr().toString(e, debug);
public String toString(@Nullable Event event, boolean debug) {
return getPropertyName() + " of " + getExpr().toString(event, debug);
}

}