-package org.simantics.scl.commands.internal.checker;\r
-\r
-import java.util.Map;\r
-\r
-import org.simantics.scl.compiler.elaboration.modules.SCLValue;\r
-import org.simantics.scl.compiler.top.ValueNotFound;\r
-import org.simantics.scl.compiler.types.Type;\r
-import org.simantics.scl.compiler.types.Types;\r
-import org.simantics.scl.compiler.types.exceptions.MatchException;\r
-import org.simantics.scl.compiler.types.util.MultiFunction;\r
-import org.simantics.scl.osgi.SCLOsgi;\r
-\r
-/**\r
- * Checks given parameters\r
- * \r
- * @author Hannu Niemistö\r
- */\r
-public class Checker {\r
- Object check;\r
- CheckItem item;\r
- \r
- private Checker(Object check, CheckItem item) {\r
- this.check = check;\r
- this.item = item;\r
- }\r
- \r
- public boolean check(Object[] parameters) {\r
- return item.check(check, parameters, 0);\r
- }\r
-\r
- private static CheckItem checkItemForType(Type type) throws MatchException {\r
- if(type == Types.BOOLEAN)\r
- return BooleanCheckItem.INSTANCE;\r
- if(Types.isFunction(type)) {\r
- MultiFunction mfun = Types.matchFunction(type, 1);\r
- return new FunctionCheckItem(mfun.parameterTypes[0], checkItemForType(mfun.returnType));\r
- }\r
- else if(Types.isApply(Types.MAYBE, 1, type)) {\r
- Type componentType = Types.matchApply(Types.MAYBE, type);\r
- return new MaybeCheckItem(checkItemForType(componentType));\r
- }\r
- else\r
- throw new MatchException();\r
- }\r
- \r
- public static Checker create(String name) {\r
- try {\r
- SCLValue checkRef = SCLOsgi.MODULE_REPOSITORY.getValueRef(name);\r
- Object check = SCLOsgi.MODULE_REPOSITORY.getValue(name);\r
- return new Checker(check, checkItemForType(checkRef.getType()));\r
- } catch(ValueNotFound e) {\r
- // If we don't find a check, it always succeeds\r
- return new Checker(Boolean.TRUE, BooleanCheckItem.INSTANCE);\r
- } catch (MatchException e) {\r
- // Should not happens\r
- e.printStackTrace();\r
- return new Checker(Boolean.FALSE, BooleanCheckItem.INSTANCE);\r
- }\r
- }\r
-}\r
+package org.simantics.scl.commands.internal.checker;
+
+import java.util.Map;
+
+import org.simantics.scl.compiler.elaboration.modules.SCLValue;
+import org.simantics.scl.compiler.top.ValueNotFound;
+import org.simantics.scl.compiler.types.Type;
+import org.simantics.scl.compiler.types.Types;
+import org.simantics.scl.compiler.types.exceptions.MatchException;
+import org.simantics.scl.compiler.types.util.MultiFunction;
+import org.simantics.scl.osgi.SCLOsgi;
+
+/**
+ * Checks given parameters
+ *
+ * @author Hannu Niemistö
+ */
+public class Checker {
+ Object check;
+ CheckItem item;
+
+ private Checker(Object check, CheckItem item) {
+ this.check = check;
+ this.item = item;
+ }
+
+ public boolean check(Object[] parameters) {
+ return item.check(check, parameters, 0);
+ }
+
+ private static CheckItem checkItemForType(Type type) throws MatchException {
+ if(type == Types.BOOLEAN)
+ return BooleanCheckItem.INSTANCE;
+ if(Types.isFunction(type)) {
+ MultiFunction mfun = Types.matchFunction(type, 1);
+ return new FunctionCheckItem(mfun.parameterTypes[0], checkItemForType(mfun.returnType));
+ }
+ else if(Types.isApply(Types.MAYBE, 1, type)) {
+ Type componentType = Types.matchApply(Types.MAYBE, type);
+ return new MaybeCheckItem(checkItemForType(componentType));
+ }
+ else
+ throw new MatchException();
+ }
+
+ public static Checker create(String name) {
+ try {
+ SCLValue checkRef = SCLOsgi.MODULE_REPOSITORY.getValueRef(name);
+ Object check = SCLOsgi.MODULE_REPOSITORY.getValue(name);
+ return new Checker(check, checkItemForType(checkRef.getType()));
+ } catch(ValueNotFound e) {
+ // If we don't find a check, it always succeeds
+ return new Checker(Boolean.TRUE, BooleanCheckItem.INSTANCE);
+ } catch (MatchException e) {
+ // Should not happens
+ e.printStackTrace();
+ return new Checker(Boolean.FALSE, BooleanCheckItem.INSTANCE);
+ }
+ }
+}