mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
model.script.StateAndCommandProvider: make methods static (#5401)
This commit is contained in:
-5
@@ -24,7 +24,6 @@ import org.openhab.core.model.script.jvmmodel.ScriptTypeComputer
|
|||||||
import org.openhab.core.model.script.scoping.ActionClassLoader
|
import org.openhab.core.model.script.scoping.ActionClassLoader
|
||||||
import org.openhab.core.model.script.scoping.ScriptImplicitlyImportedTypes
|
import org.openhab.core.model.script.scoping.ScriptImplicitlyImportedTypes
|
||||||
import org.openhab.core.model.script.scoping.ScriptImportSectionNamespaceScopeProvider
|
import org.openhab.core.model.script.scoping.ScriptImportSectionNamespaceScopeProvider
|
||||||
import org.openhab.core.model.script.scoping.StateAndCommandProvider
|
|
||||||
import org.eclipse.xtext.common.types.access.IJvmTypeProvider
|
import org.eclipse.xtext.common.types.access.IJvmTypeProvider
|
||||||
import org.eclipse.xtext.common.types.access.reflect.ReflectionTypeProviderFactory
|
import org.eclipse.xtext.common.types.access.reflect.ReflectionTypeProviderFactory
|
||||||
import org.eclipse.xtext.common.types.access.reflect.ReflectionTypeScopeProvider
|
import org.eclipse.xtext.common.types.access.reflect.ReflectionTypeScopeProvider
|
||||||
@@ -57,10 +56,6 @@ import org.eclipse.xtext.xbase.typesystem.computation.ITypeComputer
|
|||||||
return ScriptImplicitlyImportedTypes
|
return ScriptImplicitlyImportedTypes
|
||||||
}
|
}
|
||||||
|
|
||||||
def Class<StateAndCommandProvider> bindStateAndCommandProvider() {
|
|
||||||
return StateAndCommandProvider
|
|
||||||
}
|
|
||||||
|
|
||||||
override Class<? extends IGenerator> bindIGenerator() {
|
override Class<? extends IGenerator> bindIGenerator() {
|
||||||
return NullGenerator
|
return NullGenerator
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-5
@@ -65,9 +65,6 @@ class RulesJvmModelInferrer extends ScriptJvmModelInferrer {
|
|||||||
@Inject
|
@Inject
|
||||||
ThingRegistry thingRegistry
|
ThingRegistry thingRegistry
|
||||||
|
|
||||||
@Inject
|
|
||||||
StateAndCommandProvider stateAndCommandProvider
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is called for each instance of the first argument's type contained in a resource.
|
* Is called for each instance of the first argument's type contained in a resource.
|
||||||
*
|
*
|
||||||
@@ -90,8 +87,7 @@ class RulesJvmModelInferrer extends ScriptJvmModelInferrer {
|
|||||||
|
|
||||||
val Set<String> fieldNames = newHashSet()
|
val Set<String> fieldNames = newHashSet()
|
||||||
|
|
||||||
val types = stateAndCommandProvider.allTypes
|
StateAndCommandProvider::allTypes.forEach [ type |
|
||||||
types.forEach [ type |
|
|
||||||
val name = type.toString
|
val name = type.toString
|
||||||
if (fieldNames.add(name)) {
|
if (fieldNames.add(name)) {
|
||||||
members += ruleModel.toField(name, typeRef(type.class)) [
|
members += ruleModel.toField(name, typeRef(type.class)) [
|
||||||
|
|||||||
+1
-4
@@ -51,9 +51,6 @@ class ScriptInterpreter extends XbaseInterpreter {
|
|||||||
@Inject
|
@Inject
|
||||||
ItemRegistry itemRegistry
|
ItemRegistry itemRegistry
|
||||||
|
|
||||||
@Inject
|
|
||||||
StateAndCommandProvider stateAndCommandProvider
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
IBatchTypeResolver typeResolver;
|
IBatchTypeResolver typeResolver;
|
||||||
|
|
||||||
@@ -100,7 +97,7 @@ class ScriptInterpreter extends XbaseInterpreter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def protected Type getStateOrCommand(String name) {
|
def protected Type getStateOrCommand(String name) {
|
||||||
for (Type type : stateAndCommandProvider.getAllTypes()) {
|
for (Type type : StateAndCommandProvider::allTypes) {
|
||||||
if (type.toString == name) {
|
if (type.toString == name) {
|
||||||
return type
|
return type
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-5
@@ -98,9 +98,6 @@ class ScriptJvmModelInferrer extends AbstractModelInferrer {
|
|||||||
@Inject
|
@Inject
|
||||||
ItemRegistry itemRegistry
|
ItemRegistry itemRegistry
|
||||||
|
|
||||||
@Inject
|
|
||||||
StateAndCommandProvider stateAndCommandProvider
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is called for each instance of the first argument's type contained in a resource.
|
* Is called for each instance of the first argument's type contained in a resource.
|
||||||
*
|
*
|
||||||
@@ -116,8 +113,7 @@ class ScriptJvmModelInferrer extends AbstractModelInferrer {
|
|||||||
|
|
||||||
val Set<String> fieldNames = newHashSet()
|
val Set<String> fieldNames = newHashSet()
|
||||||
|
|
||||||
val types = stateAndCommandProvider.allTypes
|
StateAndCommandProvider::allTypes.forEach [ type |
|
||||||
types.forEach [ type |
|
|
||||||
val name = type.toString
|
val name = type.toString
|
||||||
if (fieldNames.add(name)) {
|
if (fieldNames.add(name)) {
|
||||||
members += script.toField(name, typeRef(type.class)) [
|
members += script.toField(name, typeRef(type.class)) [
|
||||||
|
|||||||
+3
-6
@@ -29,8 +29,6 @@ import org.openhab.core.types.State;
|
|||||||
import org.openhab.core.types.Type;
|
import org.openhab.core.types.Type;
|
||||||
import org.openhab.core.types.UnDefType;
|
import org.openhab.core.types.UnDefType;
|
||||||
|
|
||||||
import com.google.inject.Singleton;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a class which provides all available states and commands (obviously only the enum-based ones with a fixed
|
* This is a class which provides all available states and commands (obviously only the enum-based ones with a fixed
|
||||||
* name).
|
* name).
|
||||||
@@ -38,7 +36,6 @@ import com.google.inject.Singleton;
|
|||||||
*
|
*
|
||||||
* @author Kai Kreuzer - Initial contribution
|
* @author Kai Kreuzer - Initial contribution
|
||||||
*/
|
*/
|
||||||
@Singleton
|
|
||||||
public class StateAndCommandProvider {
|
public class StateAndCommandProvider {
|
||||||
|
|
||||||
protected static final Set<Command> COMMANDS = new HashSet<>();
|
protected static final Set<Command> COMMANDS = new HashSet<>();
|
||||||
@@ -79,15 +76,15 @@ public class StateAndCommandProvider {
|
|||||||
TYPES.addAll(STATES);
|
TYPES.addAll(STATES);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterable<Type> getAllTypes() {
|
static public Iterable<Type> getAllTypes() {
|
||||||
return TYPES;
|
return TYPES;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterable<Command> getAllCommands() {
|
static public Iterable<Command> getAllCommands() {
|
||||||
return COMMANDS;
|
return COMMANDS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterable<State> getAllStates() {
|
static public Iterable<State> getAllStates() {
|
||||||
return STATES;
|
return STATES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user