mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
Code cleanup: Use Java 17 features (#3522)
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
+7
-10
@@ -142,12 +142,12 @@ public class DSLScriptEngine implements javax.script.ScriptEngine {
|
||||
|
||||
private DefaultEvaluationContext createEvaluationContext(Script script, IEvaluationContext specificContext) {
|
||||
IEvaluationContext parentContext = specificContext;
|
||||
if (specificContext == null && script instanceof ScriptImpl) {
|
||||
XExpression xExpression = ((ScriptImpl) script).getXExpression();
|
||||
if (specificContext == null && script instanceof ScriptImpl impl) {
|
||||
XExpression xExpression = impl.getXExpression();
|
||||
if (xExpression != null) {
|
||||
Resource resource = xExpression.eResource();
|
||||
if (resource instanceof XtextResource) {
|
||||
IResourceServiceProvider provider = ((XtextResource) resource).getResourceServiceProvider();
|
||||
if (resource instanceof XtextResource xtextResource) {
|
||||
IResourceServiceProvider provider = xtextResource.getResourceServiceProvider();
|
||||
parentContext = provider.get(IEvaluationContext.class);
|
||||
}
|
||||
}
|
||||
@@ -171,19 +171,16 @@ public class DSLScriptEngine implements javax.script.ScriptEngine {
|
||||
evalContext.newValue(QualifiedName.create("privateCache"), cachePreset.get("privateCache"));
|
||||
// now add specific implicit vars, where we have to map the right content
|
||||
Object value = context.getAttribute(OUTPUT_EVENT);
|
||||
if (value instanceof ChannelTriggeredEvent) {
|
||||
ChannelTriggeredEvent event = (ChannelTriggeredEvent) value;
|
||||
if (value instanceof ChannelTriggeredEvent event) {
|
||||
evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_RECEIVED_EVENT), event.getEvent());
|
||||
evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_TRIGGERING_CHANNEL),
|
||||
event.getChannel().getAsString());
|
||||
}
|
||||
if (value instanceof ItemEvent) {
|
||||
ItemEvent event = (ItemEvent) value;
|
||||
if (value instanceof ItemEvent event) {
|
||||
evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_TRIGGERING_ITEM_NAME),
|
||||
event.getItemName());
|
||||
}
|
||||
if (value instanceof ThingStatusInfoChangedEvent) {
|
||||
ThingStatusInfoChangedEvent event = (ThingStatusInfoChangedEvent) value;
|
||||
if (value instanceof ThingStatusInfoChangedEvent event) {
|
||||
evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_TRIGGERING_THING),
|
||||
event.getThingUID().toString());
|
||||
evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_PREVIOUS_STATUS),
|
||||
|
||||
+6
-6
@@ -54,8 +54,8 @@ public class ScriptImpl implements Script {
|
||||
if (xExpression != null) {
|
||||
Resource resource = xExpression.eResource();
|
||||
IEvaluationContext evaluationContext = null;
|
||||
if (resource instanceof XtextResource) {
|
||||
IResourceServiceProvider provider = ((XtextResource) resource).getResourceServiceProvider();
|
||||
if (resource instanceof XtextResource xtextResource) {
|
||||
IResourceServiceProvider provider = xtextResource.getResourceServiceProvider();
|
||||
evaluationContext = provider.get(IEvaluationContext.class);
|
||||
}
|
||||
return execute(evaluationContext);
|
||||
@@ -69,8 +69,8 @@ public class ScriptImpl implements Script {
|
||||
if (xExpression != null) {
|
||||
Resource resource = xExpression.eResource();
|
||||
IExpressionInterpreter interpreter = null;
|
||||
if (resource instanceof XtextResource) {
|
||||
IResourceServiceProvider provider = ((XtextResource) resource).getResourceServiceProvider();
|
||||
if (resource instanceof XtextResource xtextResource) {
|
||||
IResourceServiceProvider provider = xtextResource.getResourceServiceProvider();
|
||||
interpreter = provider.get(IExpressionInterpreter.class);
|
||||
}
|
||||
if (interpreter == null) {
|
||||
@@ -89,8 +89,8 @@ public class ScriptImpl implements Script {
|
||||
}
|
||||
return result.getResult();
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof ScriptExecutionException) {
|
||||
throw (ScriptExecutionException) e;
|
||||
if (e instanceof ScriptExecutionException exception) {
|
||||
throw exception;
|
||||
} else {
|
||||
throw new ScriptExecutionException(
|
||||
"An error occurred during the script execution: " + e.getMessage(), e);
|
||||
|
||||
Reference in New Issue
Block a user