Search in sources :

Example 1 with WholeIllegalArgumentException

use of org.whole.lang.exceptions.WholeIllegalArgumentException in project whole by wholeplatform.

the class TestsInterpreterVisitor method visit.

@Override
public void visit(TestCase entity) {
    String name = entity.getName().getValue();
    Results results = TestsEntityFactory.instance.createResults();
    printWriter().printf("* %s test case running:\n\n", name);
    try {
        IEntityIterator<BeforeTestCase> beforeIterator = IteratorFactory.<BeforeTestCase>childMatcherIterator().withPattern(BeforeTestCase);
        beforeIterator.reset(entity.getAspects());
        for (BeforeTestCase beforeTestCase : beforeIterator) {
            beforeTestCase.accept(this);
            getResult();
        }
        Tests tests = entity.getTests();
        for (int i = 0; i < tests.wSize(); i++) {
            Test test = tests.get(i);
            if (getBindings().wIsSet("runSingleTest") && getBindings().wGet("runSingleTest") != test)
                continue;
            test.accept(this);
            IntLiteral result = null;
            switch(getResult().wGet(outcome).wEnumValue().getOrdinal()) {
                case OutcomeEnum.ERROR_ord:
                    result = results.getErrors();
                    break;
                case OutcomeEnum.FAILURE_ord:
                    result = results.getFailures();
                    break;
                case OutcomeEnum.SUCCESS_ord:
                    result = results.getSuccesses();
                    break;
                default:
                    throw new WholeIllegalArgumentException("unsupported outcome");
            }
            result.setValue(result.getValue() + 1);
        }
        IEntityIterator<AfterTestCase> afterIterator = IteratorFactory.<AfterTestCase>childMatcherIterator().withPattern(AfterTestCase);
        afterIterator.reset(entity.getAspects());
        for (AfterTestCase afterTestCase : afterIterator) {
            afterTestCase.accept(this);
            getResult();
        }
        boolean testCaseSuccess = results.getErrors().getValue() + results.getFailures().getValue() == 0;
        printWriter().printf("\n* %s test case %s\n", name, testCaseSuccess ? "OK" : "FAILED");
    } catch (OperationCanceledException e) {
        throw e;
    } catch (RuntimeException e) {
        reportError(name, e);
        results.getErrors().setValue(entity.getTests().wSize());
        results.getFailures().setValue(0);
        results.getSuccesses().setValue(0);
    }
    if (EntityUtils.isResolver(entity.getExpectedResults()))
        entity.setExpectedResults(EntityUtils.clone(results));
    if (!Matcher.match(results, entity.getActualResults()))
        entity.setActualResults(results);
    setResult(results);
}
Also used : AfterTestCase(org.whole.lang.tests.model.AfterTestCase) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) Tests(org.whole.lang.tests.model.Tests) Constraint(org.whole.lang.tests.model.Constraint) IWholeRuntimeException(org.whole.lang.exceptions.IWholeRuntimeException) Results(org.whole.lang.tests.model.Results) Test(org.whole.lang.tests.model.Test) BeforeTest(org.whole.lang.tests.model.BeforeTest) AfterTest(org.whole.lang.tests.model.AfterTest) IntLiteral(org.whole.lang.tests.model.IntLiteral) BeforeTestCase(org.whole.lang.tests.model.BeforeTestCase)

Example 2 with WholeIllegalArgumentException

use of org.whole.lang.exceptions.WholeIllegalArgumentException in project whole by wholeplatform.

the class CommonsDataTypePresentationParser method parseFeatureDescriptor.

public static FeatureDescriptor parseFeatureDescriptor(String value) {
    int index = value.indexOf('#');
    if (index > 0) {
        String languageUri = value.substring(0, index);
        ILanguageKit lk = /*= null;
			if (ReflectionFactory.hasLanguageKit(languageUri)) {
    			for (ILanguageKit lk2 : ReflectionFactory.getLanguageKits(true))
    				if (lk2.getName().equalsIgnoreCase(languageUri)) {
    					lk = lk2; 
    					break;
    				}
    		}
    		if (lk == null)
    			lk*/
        ReflectionFactory.getLanguageKit(languageUri);
        FeatureDescriptor fd = lk.getFeatureDescriptorEnum().valueOf(value.substring(index + 1));
        if (fd != null)
            return fd;
    }
    throw new WholeIllegalArgumentException(WholeMessages.no_data_type);
}
Also used : FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 3 with WholeIllegalArgumentException

use of org.whole.lang.exceptions.WholeIllegalArgumentException in project whole by wholeplatform.

the class WorkflowsInterpreterVisitor method getJavaTemplateFactory.

protected ITemplateFactory<CompilationUnit> getJavaTemplateFactory(LoadJavaModel entity) {
    entity.getClassName().accept(this);
    String className = getResultString();
    if (!Matcher.matchImpl(WorkflowsEntityDescriptorEnum.ClassPath, entity.getClassProvider()))
        throw new UnsupportedOperationException("The Eclipse Workspace is not available");
    try {
        return new JavaClassTemplateFactory(Class.forName(className, false, ReflectionFactory.getClassLoader(getBindings())));
    } catch (ClassNotFoundException e) {
        throw new WholeIllegalArgumentException(e).withSourceEntity(entity).withBindings(getBindings());
    }
}
Also used : JavaClassTemplateFactory(org.whole.lang.java.codebase.JavaClassTemplateFactory) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException)

Example 4 with WholeIllegalArgumentException

use of org.whole.lang.exceptions.WholeIllegalArgumentException in project whole by wholeplatform.

the class MathInterpreterVisitor method visit.

@Override
public void visit(Not entity) {
    IEntity result = evaluate(entity.getExpression());
    DataKinds dataKinds = DataTypeUtils.getUnboxedDataKind(result);
    if (dataKinds.isNotAData())
        throw new WholeIllegalArgumentException(WholeMessages.no_data).withSourceEntity(entity).withBindings(getBindings());
    else if (!dataKinds.isBoolean())
        throw new WholeIllegalArgumentException(WholeMessages.illegal_data_conversion).withSourceEntity(entity).withBindings(getBindings());
    else
        setResult(createBooleanLiteral(!result.wBooleanValue()));
}
Also used : IEntity(org.whole.lang.model.IEntity) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) DataKinds(org.whole.lang.reflect.DataKinds)

Example 5 with WholeIllegalArgumentException

use of org.whole.lang.exceptions.WholeIllegalArgumentException in project whole by wholeplatform.

the class MathInterpreterVisitor method visit.

@Override
public void visit(Factorial entity) {
    IEntity result;
    IEntity result1 = evaluate(entity.getExpression());
    long lvalue = DataTypeUtils.toLong(result1);
    if (lvalue < 0l)
        throw new WholeIllegalArgumentException("Underflow error in factorial").withSourceEntity(entity).withBindings(getBindings());
    else if (lvalue < 21l)
        result = createLongLiteral(factorial((int) lvalue));
    else
        result = createBigIntegerLiteral(factorial(java.math.BigInteger.valueOf(lvalue)));
    setResult(result);
}
Also used : IEntity(org.whole.lang.model.IEntity) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException)

Aggregations

WholeIllegalArgumentException (org.whole.lang.exceptions.WholeIllegalArgumentException)32 DataKinds (org.whole.lang.reflect.DataKinds)16 IEntity (org.whole.lang.model.IEntity)15 EnumValue (org.whole.lang.model.EnumValue)3 IBindingManager (org.whole.lang.bindings.IBindingManager)2 IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)2 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)2 ILanguageKit (org.whole.lang.reflect.ILanguageKit)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 DateTimeZone (org.joda.time.DateTimeZone)1 DateTimeParser (org.joda.time.format.DateTimeParser)1 DateTimeParserBucket (org.joda.time.format.DateTimeParserBucket)1 FixedDateTimeZone (org.joda.time.tz.FixedDateTimeZone)1 ITransactionScope (org.whole.lang.bindings.ITransactionScope)1 URLPersistenceProvider (org.whole.lang.codebase.URLPersistenceProvider)1 IEntityFactory (org.whole.lang.factories.IEntityFactory)1 IEntityRegistryProvider (org.whole.lang.factories.IEntityRegistryProvider)1 CompiledPattern (org.whole.lang.grammars.model.CompiledPattern)1 Pattern (org.whole.lang.grammars.model.Pattern)1