X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.commands%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcommands%2Finternal%2Fchecker%2FChecker.java;h=7295e8c30557a75077c2cd0fb8c3311367dad951;hb=0f24ef8821e9401ae8134725b60209f612ae8f7e;hp=7003431760b40a0bbe6b074b550246c9686665a5;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.commands/src/org/simantics/scl/commands/internal/checker/Checker.java b/bundles/org.simantics.scl.commands/src/org/simantics/scl/commands/internal/checker/Checker.java index 700343176..7295e8c30 100644 --- a/bundles/org.simantics.scl.commands/src/org/simantics/scl/commands/internal/checker/Checker.java +++ b/bundles/org.simantics.scl.commands/src/org/simantics/scl/commands/internal/checker/Checker.java @@ -1,60 +1,60 @@ -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); - } - } -} +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); + } + } +}