Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Problem about OCLinEcore(parser error, but it looks fine and I try it manually )
Problem about OCLinEcore [message #806288] Fri, 24 February 2012 19:50 Go to next message
XIAOLIANG  WANG is currently offline XIAOLIANG WANGFriend
Messages: 6
Registered: February 2012
Junior Member
I tried OCLInEcore in a small model. What i am trying to do is split a String into String[] according to a separator. Could anyone help me with the problem?
There is no error showing up. When I track the path, it shows that variables 'string' and 'char' in method 'split' is not valid typed, which causes a parse error.
module _'My.ecore'

{
	class Graph
	{
		property nodes#graph : Node[*] { ordered composes };
		property arrows#graph : Arrow[*] { ordered composes };
	}
	class Arrow extends NameElement
	{
		invariant noteq: source <> target;
		invariant ads: not source.oclIsUndefined() and not target.oclIsUndefined();
		property graph#arrows : Graph[?] { ordered };
		property source#outgoings : Node[1] { ordered };
		property target#incomings : Node[1] { ordered };
	}
	class Node extends NameElement
	{
		invariant x: true;
		property graph#nodes : Graph[?] { ordered };
		property incomings#target : Arrow[*] { ordered };
		property outgoings#source : Arrow[*] { ordered };
	}
	class NameElement
	{
		invariant checkName: checkName;
		attribute name : String[?] { ordered };
		attribute charSequence : String[*] { ordered derived transient unsettable volatile }
		{
			derivation: split(name, '^');
		}
		attribute checkName : Boolean[?] { ordered derived transient unsettable volatile }
		{
			derivation: split(name, '^')->forAll(s : String | isAlpah(s));
		}
		operation isAlpah(string : String[1]) : Boolean[1]
		{
			body:
				let seq : Sequence(String) = Sequence{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'} in charSequence(string.toLower())->forAll(a : String | seq->including(a));
		}
		operation charSequence(string : String[1]) : String[*]
		{
			body:
				let seq : Sequence(Integer) = Sequence{1..string.size()} in seq->collectNested(i : Integer | string.substring(i, i));
		}
		operation index(string : String[1], char : String[1]) : ecore::EInt[1]
		{
			body:
				let seq : Sequence(String) = charSequence(string) in if seq->count(char) > 0 then seq->indexOf(char) else 0 endif;
		}
		operation split(string : String[1], char : String[1]) : String[*]
		{
			body:
				let index : Integer = index(string, char) in if index < 1 then Sequence{string} else let other : Sequence(String) = if index < 2 then Sequence{''} else Sequence{string.substring(1, index - 1)} endif in if index + 1 <= string.size() then other->union(split(string.substring(index + 1, string.size()), char)->asSequence()) else other endif endif;
		}
	}
}
  • Attachment: My.ecore
    (Size: 6.74KB, Downloaded 341 times)
Re: Problem about OCLinEcore [message #806587 is a reply to message #806288] Sat, 25 February 2012 06:26 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Your example has the package declaration missing, presumably a cut and
paste typo.

When I fix this I find a missing

import ecore : 'http://www.eclipse.org/emf/2002/Ecore#/';

and when I add this it parses for me. Using ecore::EInt isn't necessary
and makes the OCL less portable.

You may find the String::characters() operation useful.

For Juno, I've finally got around to adding regex String operations and
confirmed that adding library operations with Java bodies is now easy.

Regards

Ed Willink


On 24/02/2012 19:50, Missing name Mising name wrote:
> I tried OCLInEcore in a small model. What i am trying to do is split a String into String[] according to a separator. Could anyone help me with the problem?
> There is no error showing up. When I track the path, it shows that variables 'string' and 'char' in method 'split' is not valid typed, which causes a parse error.
> module _'My.ecore'
>
> {
> class Graph
> {
> property nodes#graph : Node[*] { ordered composes };
> property arrows#graph : Arrow[*] { ordered composes };
> }
> class Arrow extends NameElement
> {
> invariant noteq: source<> target;
> invariant ads: not source.oclIsUndefined() and not target.oclIsUndefined();
> property graph#arrows : Graph[?] { ordered };
> property source#outgoings : Node[1] { ordered };
> property target#incomings : Node[1] { ordered };
> }
> class Node extends NameElement
> {
> invariant x: true;
> property graph#nodes : Graph[?] { ordered };
> property incomings#target : Arrow[*] { ordered };
> property outgoings#source : Arrow[*] { ordered };
> }
> class NameElement
> {
> invariant checkName: checkName;
> attribute name : String[?] { ordered };
> attribute charSequence : String[*] { ordered derived transient unsettable volatile }
> {
> derivation: split(name, '^');
> }
> attribute checkName : Boolean[?] { ordered derived transient unsettable volatile }
> {
> derivation: split(name, '^')->forAll(s : String | isAlpah(s));
> }
> operation isAlpah(string : String[1]) : Boolean[1]
> {
> body:
> let seq : Sequence(String) = Sequence{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'} in charSequence(string.toLower())->forAll(a : String | seq->including(a));
> }
> operation charSequence(string : String[1]) : String[*]
> {
> body:
> let seq : Sequence(Integer) = Sequence{1..string.size()} in seq->collectNested(i : Integer | string.substring(i, i));
> }
> operation index(string : String[1], char : String[1]) : ecore::EInt[1]
> {
> body:
> let seq : Sequence(String) = charSequence(string) in if seq->count(char)> 0 then seq->indexOf(char) else 0 endif;
> }
> operation split(string : String[1], char : String[1]) : String[*]
> {
> body:
> let index : Integer = index(string, char) in if index< 1 then Sequence{string} else let other : Sequence(String) = if index< 2 then Sequence{''} else Sequence{string.substring(1, index - 1)} endif in if index + 1<= string.size() then other->union(split(string.substring(index + 1, string.size()), char)->asSequence()) else other endif endif;
> }
> }
> }
Re: Problem about OCLinEcore [message #808188 is a reply to message #806587] Mon, 27 February 2012 14:15 Go to previous messageGo to next message
XIAOLIANG  WANG is currently offline XIAOLIANG WANGFriend
Messages: 6
Registered: February 2012
Junior Member
Hi, thank you for your reply.
Yes, the missing import sentence is intentional. Because the forum does not allow me to paste any link right now. I have to move it out.


I change EInt into Integer.

I test index function in Junit. But an exception pops up every time.
public void testIndex__String_String() {
assertTrue(getFixture().index("adb", "w").intValue() == 0);
assertTrue(getFixture().index("ccc", "c").intValue() != 0);
}
I tried to add related plugin into projects, but it seems that does not work at all.
Do I miss something?

org.eclipse.emf.common.util.WrappedException: org.eclipse.core.runtime.CoreException: Plug-in org.eclipse.ocl.examples.xtext.essentialocl.ui was unable to load class org.eclipse.ocl.examples.xtext.essentialocl.ui.EssentialOCLExecutableExtensionFactory.
at org.eclipse.emf.ecore.plugin.RegistryReader$PluginClassDescriptor.createInstance(RegistryReader.java:176)
at org.eclipse.emf.ecore.plugin.RegistryReader$ResourceFactoryDescriptor.createFactory(RegistryReader.java:194)
at org.eclipse.emf.ecore.resource.impl.ResourceFactoryRegistryImpl.convert(ResourceFactoryRegistryImpl.java:99)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$2.delegatedGetFactory(ResourceSetImpl.java:449)
at org.eclipse.emf.ecore.resource.impl.ResourceFactoryRegistryImpl.getFactory(ResourceFactoryRegistryImpl.java:151)
at org.eclipse.emf.ecore.resource.impl.ResourceFactoryRegistryImpl.getFactory(ResourceFactoryRegistryImpl.java:92)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.createResource(ResourceSetImpl.java:422)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.createResource(ResourceSetImpl.java:414)
at org.eclipse.ocl.examples.pivot.utilities.PivotUtil.createXtextResource(PivotUtil.java:359)
at org.eclipse.ocl.examples.pivot.utilities.PivotUtil.resolveSpecification(PivotUtil.java:915)
at org.eclipse.ocl.examples.pivot.delegate.AbstractDelegatedBehavior.getExpressionInOcl(AbstractDelegatedBehavior.java:140)
at org.eclipse.ocl.examples.pivot.delegate.InvocationBehavior.getExpressionInOcl(InvocationBehavior.java:65)
at org.eclipse.ocl.examples.pivot.delegate.OCLInvocationDelegate.dynamicInvoke(OCLInvocationDelegate.java:72)
at core.impl.NameElementImpl.index(NameElementImpl.java:258)
at core.tests.NameElementTest.testIndex__String_String(NameElementTest.java:232)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:243)
at junit.framework.TestSuite.run(TestSuite.java:238)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:62)
at org.eclipse.pde.internal.junit.runtime.CoreTestApplication.run(CoreTestApplication.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.internal.app.EclipseAppContainer.callMethodWithException(EclipseAppContainer.java:587)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:198)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Caused by: org.eclipse.core.runtime.CoreException: Plug-in org.eclipse.ocl.examples.xtext.essentialocl.ui was unable to load class org.eclipse.ocl.examples.xtext.essentialocl.ui.EssentialOCLExecutableExtensionFactory.
at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.throwException(RegistryStrategyOSGI.java:194)
at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:176)
at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:905)
at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:243)
at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:55)
at org.eclipse.emf.ecore.plugin.RegistryReader$PluginClassDescriptor.createInstance(RegistryReader.java:172)
... 52 more
Caused by: org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter$TerminatingClassNotFoundException: An error occurred while automatically activating bundle org.eclipse.ocl.examples.xtext.essentialocl.ui (470).
at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:122)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:462)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:400)
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:476)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.eclipse.osgi.internal.loader.BundleLoader.loadClass(BundleLoader.java:345)
at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:229)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1207)
at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:174)
... 56 more
Caused by: org.osgi.framework.BundleException: Exception in org.eclipse.ocl.examples.xtext.essentialocl.ui.internal.EssentialOCLActivator.start() of bundle org.eclipse.ocl.examples.xtext.essentialocl.ui.
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:734)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:299)
at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:440)
at org.eclipse.osgi.internal.loader.BundleLoader.setLazyTrigger(BundleLoader.java:268)
at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:107)
... 68 more
Caused by: com.google.inject.CreationException: Guice creation errors:

1) No implementation for org.eclipse.ui.IWorkbench was bound.
while locating org.eclipse.ui.IWorkbench
for field at org.eclipse.xtext.ui.editor.GlobalURIEditorOpener.workbench(GlobalURIEditorOpener.java:42)
at org.eclipse.xtext.service.MethodBasedModule.configure(MethodBasedModule.java:55)

1 error
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:354)
at com.google.inject.InjectorBuilder.initializeStatically(InjectorBuilder.java:152)
at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:105)
at com.google.inject.Guice.createInjector(Guice.java:92)
at com.google.inject.Guice.createInjector(Guice.java:69)
at com.google.inject.Guice.createInjector(Guice.java:59)
at org.eclipse.ocl.examples.xtext.essentialocl.ui.internal.EssentialOCLActivator.registerInjectorFor(EssentialOCLActivator.java:47)
at org.eclipse.ocl.examples.xtext.essentialocl.ui.internal.EssentialOCLActivator.start(EssentialOCLActivator.java:38)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
... 74 more

Re: Problem about OCLinEcore [message #808344 is a reply to message #808188] Mon, 27 February 2012 17:22 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
On 27/02/2012 14:15, XIAOLIANG WANG wrote:
>
> I tried to add related plugin into projects, but it seems that does
> not work at all.
> Do I miss something?

> Caused by: com.google.inject.CreationException: Guice creation errors:
>
> 1) No implementation for org.eclipse.ui.IWorkbench was bound.
> while locating org.eclipse.ui.IWorkbench
> for field at
> org.eclipse.xtext.ui.editor.GlobalURIEditorOpener.workbench(GlobalURIEditorOpener.java:42)
> at
> org.eclipse.xtext.service.MethodBasedModule.configure(MethodBasedModule.java:55)
>
> 1 error
> at
> com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:354)
> at
> com.google.inject.InjectorBuilder.initializeStatically(InjectorBuilder.java:152)
Your problem shows a Guice issue.

Unfortunately Google migrated a package from com.google.collect to
com.google.guice and Eclipse projects are gradually catching up. Not all
combinations are permissible.

EXACTLY which versions of Eclipse, Xtext and OCL are you using?

OCL 3.1.2a as well as OCL 3.1.2 was released last week specifically to
accommodate using recent Xtext releases such as 2.2.1 on Indigo rather
than the maintenance releases such as 2.0.2.

Regards

Ed Willink
Re: Problem about OCLinEcore [message #813686 is a reply to message #808344] Mon, 05 March 2012 15:55 Go to previous messageGo to next message
XIAOLIANG  WANG is currently offline XIAOLIANG WANGFriend
Messages: 6
Registered: February 2012
Junior Member
Hi,
Eclipse version : Indigo
OCL version: 3.1.0
XText version: 2.0.1
Right now, I can run the Junit test case. But still have problem when I call recursively in OCL. I trace down the call path and find bug when handling with collect method of Sequence.
operation split(string : String[1], a : String[1]) : String[*]
		{
			body:
				let index : Integer = index(string, a) in if index = 0 then Sequence{string} else let other : Sequence(String) = if index = 1 then Sequence{''} else Sequence{string.substring(1, index - 1)} endif in if index + 1 <= string.size() then other->union(split(string.substring(index + 1, string.size()), a)->asSequence()) else other endif endif;
		}


operation charSequence(string : String[1]) : String[*]
		{
			body:
				let seq : Sequence(Integer) = Sequence{1..string.size()} in seq->collect(i : Integer | string.substring(i, i));
		}


I tried split("adcab", "a"). The first result of invoking charSequence("adcab") is right, but the second invoking charSequence("dcab") returns Sequence{}.

public Value evaluate(EvaluationVisitor evaluationVisitor, CollectionValue sourceVal, LoopExp iteratorExp) {
		ValueFactory valueFactory = evaluationVisitor.getValueFactory();
		TypeManager typeManager = evaluationVisitor.getTypeManager();
		Type sourceType = iteratorExp.getSource().getType();
		boolean isOrdered = typeManager.isOrdered(sourceType);
		CollectionValue.Accumulator accumulatorValue = createAccumulationValue(valueFactory, isOrdered, false);
		return evaluateIteration(new IterationManager<CollectionValue.Accumulator>(evaluationVisitor,
				iteratorExp, sourceVal, accumulatorValue));
	}

I found when evaluateIteration function is called, for the first time, it has right iterator, but for the second, it only has a emtpy iterator.


Or there is no bug at all but somethings I did wrong causes my problem. Wish you can help.
Re: Problem about OCLinEcore [message #813866 is a reply to message #813686] Mon, 05 March 2012 19:57 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

An interesting and surprisingly horrible example.

I couldn't understand your code; it seemed very complicated, so I wrote
it my way; still complicated. I have four "if"'s; you have only three so
I suspect you missed one of the special cases.

package wang : pfx = 'platform:/resource/Wang/model/Wang.ecore'
{
class Wang
{
operation split(string : String, delimiter : String) :
String[*] { ordered !unique }
{
body: self.splitMore(Sequence{}, string, delimiter);
}
operation splitMore(prefixes : String[*] { ordered !unique },
tail : String, delimiter : String) : String[*] { ordered !unique }
{
body:
let startIndex : Integer = tail.indexOf(delimiter) in
if startIndex <= 0
then prefixes->append(tail)
else let newPrefixes : Sequence(String) =
if startIndex > 1
then prefixes->append(tail.substring(1, startIndex
- 1))
else if prefixes->notEmpty()
then prefixes->append('')
else prefixes
endif
endif in
let endIndex : Integer = startIndex +
delimiter.size() in
if endIndex < tail.size()
then
let newTail : String = tail.substring(endIndex,
tail.size()) in
self.splitMore(newPrefixes, newTail, delimiter)
else newPrefixes
endif
endif;
}
}
}

I tested it direct in the Xtext OCL Console after creating a Wang.xmi
with an instance of the Wang class.

Evaluating:
split('abaaba','a')
Results:
'b'
''
'b'

This was with the Juno development stream, for which I improved the
'Invalid variable' diagnostic to identify the variable and the chain of
invalidities; it was hard to debug. Particularly since the Console has
to be restarted after an Ecore edit. Seems ok on 3.7.2 too.

Your example is hard to understand primarily because the formatting got
lost and did not get reconstructed (Ctrl-Shift F helps). I'll see if I
can improve this.

I find recursion easier to manage as a tail recursion on the partial
solution and residual problem as in the example above. One day the OCL
code generator might even recognise tail recursion.

This code is so horrible that I think it's time to promote tokenize()
from the Acceleo library.
(https://bugs.eclipse.org/bugs/show_bug.cgi?id=373289).

Regards

Ed Willink


On 05/03/2012 15:56, XIAOLIANG WANG wrote:
> Hi, Eclipse version : Indigo
> OCL version: 3.1.0
> XText version: 2.0.1
> Right now, I can run the Junit test case. But still have problem when
> I call recursively in OCL. I trace down the call path and find bug
> when handling with collect method of Sequence.
> operation split(string : String[1], a : String[1]) : String[*]
> {
> body:
> let index : Integer = index(string, a) in if index = 0
> then Sequence{string} else let other : Sequence(String) = if index = 1
> then Sequence{''} else Sequence{string.substring(1, index - 1)} endif
> in if index + 1 <= string.size() then
> other->union(split(string.substring(index + 1, string.size()),
> a)->asSequence()) else other endif endif;
> }
>
> operation charSequence(string : String[1]) : String[*]
> {
> body:
> let seq : Sequence(Integer) =
> Sequence{1..string.size()} in seq->collect(i : Integer |
> string.substring(i, i));
> }
>
> I tried split("adcab", "a"). The first result of invoking
> charSequence("adcab") is right, but the second invoking
> charSequence("dcab") returns Sequence{}.
>
> public Value evaluate(EvaluationVisitor evaluationVisitor,
> CollectionValue sourceVal, LoopExp iteratorExp) {
> ValueFactory valueFactory = evaluationVisitor.getValueFactory();
> TypeManager typeManager = evaluationVisitor.getTypeManager();
> Type sourceType = iteratorExp.getSource().getType();
> boolean isOrdered = typeManager.isOrdered(sourceType);
> CollectionValue.Accumulator accumulatorValue =
> createAccumulationValue(valueFactory, isOrdered, false);
> return evaluateIteration(new
> IterationManager<CollectionValue.Accumulator>(evaluationVisitor,
> iteratorExp, sourceVal, accumulatorValue));
> }
> I found when evaluateIteration function is called, for the first time,
> it has right iterator, but for the second, it only has a emtpy iterator.
>
>
> Or there is no bug at all but somethings I did wrong causes my
> problem. Wish you can help.
Re: Problem about OCLinEcore [message #814393 is a reply to message #813866] Tue, 06 March 2012 11:49 Go to previous messageGo to next message
XIAOLIANG  WANG is currently offline XIAOLIANG WANGFriend
Messages: 6
Registered: February 2012
Junior Member
Hi,Edward,
Thank you so much. The problem is solved.
But another problem happens. It is really weird. Is there any dependence between different ocl expression???

Here I give an example:

I define two functions in OCL

operation isAlpah(string : String[1]) : Boolean[1]
{
	body:
		let seq : Sequence(String) = Sequence{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}
		in charSequence(string.toLower())->forAll(a : String | seq->includes(a));
}
operation charSequence(string : String[1]) : String[*]
{
	body:
		let seq : Sequence(Integer) = Sequence{1 .. string.size()}
		in seq->collect(i : Integer | string.substring(i, i));
}


In the java file, the two functions will be following:
/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isAlpah(String string) {
		try {
			return (Boolean)IS_ALPAH_STRING__EINVOCATION_DELEGATE.dynamicInvoke(this, new BasicEList.UnmodifiableEList<Object>(1, new Object[]{string}));
		}
		catch (InvocationTargetException ite) {
			throw new WrappedException(ite);
		}
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	public EList<String> charSequence(String string) {
		try {
			return (EList<String>)CHAR_SEQUENCE_STRING__EINVOCATION_DELEGATE.dynamicInvoke(this, new BasicEList.UnmodifiableEList<Object>(1, new Object[]{string}));
		}
		catch (InvocationTargetException ite) {
			throw new WrappedException(ite);
		}
	}


And then, I have a test case like this:
public void testGetCharSequence() {
		getFixture().setName("sfiefj(^asdfs");
		EList<String> result = getFixture().getCharSequence();
		System.out.println(result);
		assertTrue(result.size() == 2);
		System.out.println(result.get(0));
		assertFalse(getFixture().isAlpah(result.get(0)));
		System.out.println(result.get(1));
		assertTrue(getFixture().isAlpah(result.get(1)));
	}


Right now, I run the test case, it turns out a failure, which is caused by
assertFalse(getFixture().isAlpah(result.get(0)));


After I change the isAlpah function in java file to this, which just print out charSequence result, the test case runs successfully.
	public boolean isAlpah(String string) {
		try {
			for(String iter : charSequence(string)) // these two lines 
				System.out.println(iter);       // are added.
			return (Boolean)IS_ALPAH_STRING__EINVOCATION_DELEGATE.dynamicInvoke(this, new BasicEList.UnmodifiableEList<Object>(1, new Object[]{string}));
		}
		catch (InvocationTargetException ite) {
			throw new WrappedException(ite);
		}
	}

[Updated on: Tue, 06 March 2012 11:51]

Report message to a moderator

Re: Problem about OCLinEcore [message #814417 is a reply to message #814393] Tue, 06 March 2012 12:21 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

There should be no function interactions.

At a quick glance, I suspect that your problem is that an empty string
crashes in one but not the other.

There is a String::characters() function that does what your
charSequence() does.

Regards

Ed Willink

On 06/03/2012 11:49, XIAOLIANG WANG wrote:
> Hi,Edward,
> Thank you so much. The problem is solved.
> But another problem happens. It is really weird. Is there any
> dependence between different ocl expression???
>
> Here I give an example:
>
> I define two functions in OCL
>
> operation isAlpah(string : String[1]) : Boolean[1]
> {
> body:
> let seq : Sequence(String) = Sequence{'a', 'b', 'c', 'd', 'e',
> 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
> 't', 'u', 'v', 'w', 'x', 'y', 'z'}
> in charSequence(string.toLower())->forAll(a : String |
> seq->includes(a));
> }
> operation charSequence(string : String[1]) : String[*]
> {
> body:
> let seq : Sequence(Integer) = Sequence{1 .. string.size()}
> in seq->collect(i : Integer | string.substring(i, i));
> }
>
> In the java file, the two functions will be following:
> /**
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> public boolean isAlpah(String string) {
> try {
> return
> (Boolean)IS_ALPAH_STRING__EINVOCATION_DELEGATE.dynamicInvoke(this, new
> BasicEList.UnmodifiableEList<Object>(1, new Object[]{string}));
> }
> catch (InvocationTargetException ite) {
> throw new WrappedException(ite);
> }
> }
>
> /**
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> @SuppressWarnings("unchecked")
> public EList<String> charSequence(String string) {
> try {
> return
> (EList<String>)CHAR_SEQUENCE_STRING__EINVOCATION_DELEGATE.dynamicInvoke(this,
> new BasicEList.UnmodifiableEList<Object>(1, new Object[]{string}));
> }
> catch (InvocationTargetException ite) {
> throw new WrappedException(ite);
> }
> }
>
> And then, I have a test case like this:
> public void testGetCharSequence() {
> getFixture().setName("sfiefj(^asdfs");
> EList<String> result = getFixture().getCharSequence();
> System.out.println(result);
> assertTrue(result.size() == 2);
> System.out.println(result.get(0));
> assertFalse(getFixture().isAlpah(result.get(0)));
> System.out.println(result.get(1));
> assertTrue(getFixture().isAlpah(result.get(1)));
> }
>
> Right now, I run the test case, it turns out a failure, which is
> caused by assertFalse(getFixture().isAlpah(result.get(0)));
>
> After I change the isAlpah function in java file to this, which just
> print out charSequence result, the test case runs successfully.
> public boolean isAlpah(String string) {
> try {
> for(String iter : charSequence(string))
> System.out.println(iter);
> return
> (Boolean)IS_ALPAH_STRING__EINVOCATION_DELEGATE.dynamicInvoke(this, new
> BasicEList.UnmodifiableEList<Object>(1, new Object[]{string}));
> }
> catch (InvocationTargetException ite) {
> throw new WrappedException(ite);
> }
> }
Re: Problem about OCLinEcore [message #814426 is a reply to message #814417] Tue, 06 March 2012 12:43 Go to previous messageGo to next message
XIAOLIANG  WANG is currently offline XIAOLIANG WANGFriend
Messages: 6
Registered: February 2012
Junior Member
Hi, Edward,
Thank you. The problem is fixed.
Re: Problem about OCLinEcore [message #830115 is a reply to message #814426] Tue, 27 March 2012 07:59 Go to previous messageGo to next message
Lucy Chan is currently offline Lucy ChanFriend
Messages: 29
Registered: March 2012
Junior Member
Hi, my email is chenluxiabc@yahoo.com.cn, nowadays, I'm learning the OCL and I met some problems, I just wonder if I can contact with you about these problems through emails? Thanks advanced.
Re: Problem about OCLinEcore [message #830192 is a reply to message #830115] Tue, 27 March 2012 10:09 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
HI

I'm not clear why you are using this thread in which the reported
problem was resolved.

I provide free answers on this public newsgroup and also to other
Eclipse committers. If you wish to communicate in private we can discuss
consultancy fees.

Regards

Ed Willink

On 27/03/2012 03:59, Lucy Chan wrote:
> Hi, my email is mailto:chenluxiabc@xxxxxxxx.cn, nowadays, I'm
> learning the OCL and I met some problems, I just wonder if I can
> contact with you about these problems through emails? Thanks advanced.
Re: Problem about OCLinEcore [message #831050 is a reply to message #830192] Wed, 28 March 2012 11:57 Go to previous messageGo to next message
Lucy Chan is currently offline Lucy ChanFriend
Messages: 29
Registered: March 2012
Junior Member
I'm just using the EMF to modeling and trying to define specification by OCL. I get the information from the website that the xxx.ecore can be verified by OCL, so I try to implement it.
Re: Problem about OCLinEcore [message #831106 is a reply to message #831050] Wed, 28 March 2012 13:33 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Yes. You should follow the OCLinEcore tutorial in the Help documentation.

Regards

Ed Willink

On 28/03/2012 07:57, Lucy Chan wrote:
> I'm just using the EMF to modeling and trying to define specification
> by OCL. I get the information from the website that the xxx.ecore can
> be verified by OCL, so I try to implement it.
Previous Topic:cast to EFloat?
Next Topic:lack a class "QueryDelegateTextViewer"
Goto Forum:
  


Current Time: Fri Apr 19 02:06:30 GMT 2024

Powered by FUDForum. Page generated in 0.02725 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top