Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Getting all objects with EGL
Getting all objects with EGL [message #1752677] Thu, 26 January 2017 01:26 Go to next message
C. Santos is currently offline C. SantosFriend
Messages: 32
Registered: September 2015
Member
Hi all,

I'm with a problem in my .egl file. I'm trying to print all objects following the Transitions order. But this is not working.. Can someone help me on this?

for(element in Procedure.allInstances()) {
        var firstElement = getFirstElement(element.executablePart);
	printStatements(firstElement);
	printElementsByTransition(firstElement);
}

operation getFirstElement(object){
	for(element in object) {
		if(element.isStart == true){
			return element;
		}
	}
}

operation Statements getNext() {
  return Transition.all.
  	select(t|t.source = self).
  	collect(t|t.target).
  	flatten();
}

operation printElementsByTransition(object) {
	var i = 0 ;
	var element;
	var x;
	for(transition in Transition.all) {
		if(i = 0) { 
			element = object.getNext();
			i = 1;
		} else{	
			element = element.first().getNext();
		}
		printStatements(element.first());
	}
}

operation printStatements(object) {

	if(not (object == null) ) {
                 out.println(object);
        }
}


Cheers
Re: Getting all objects with EGL [message #1752690 is a reply to message #1752677] Thu, 26 January 2017 08:25 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1590
Registered: July 2009
Location: York, UK
Senior Member

Hi,

Could you please provide a minimal example [1] we can use to reproduce this?

Cheers,
Dimitris

[1] https://www.eclipse.org/epsilon/doc/articles/minimal-examples/
Re: Getting all objects with EGL [message #1752711 is a reply to message #1752690] Thu, 26 January 2017 12:22 Go to previous messageGo to next message
C. Santos is currently offline C. SantosFriend
Messages: 32
Registered: September 2015
Member
Hi,

My Epsilon version is:

index.php/fa/28232/0/

My last version of .emf file is:

@namespace(uri="crystal", prefix="crystal")
package crystal;

@gmf.diagram(foo="bar", rcp="false", onefile="true", diagram.extension="crystal")
class Crystal {
  val Links[*] links;
  val Subprograms[*] subprograms;
}

@gmf.node(figure="rectangle", border.width="1", label.readOnly="true")
abstract class Subprograms {
  @gmf.compartment
  val DataAbstractions[*] declarativePart;

  @gmf.compartment
  val Statements[*] executablePart;
}

@gmf.node(figure="rectangle", border.width="1", label.readOnly="true")
abstract class NamedBlocks extends Subprograms {
  attr String name;
  
  @gmf.compartment
  val DataAbstractions[*] parameters;
}

@gmf.node(label="name", label.text="Procedure", border.color="255,13,13")
class Procedure extends NamedBlocks {
}

@gmf.node(label="name", label.text="Function", border.color="25,191,108")
class Function extends NamedBlocks {

  @gmf.compartment
  val DataAbstractions[1] returnPart;
}

@gmf.node(label="description", label.text="Anonymous Block", border.color="43,106,215", border.style="dash")
class AnonymousBlock extends Subprograms {
  attr String description;
}

@gmf.node(label="name", figure="rectangle", border.width="1", label.icon="true", label.readOnly="true", label.placement="internal")
abstract class DataAbstractions {
  attr String name;
  attr ParameterType type;
}

@gmf.node(label.text="Data Type")
class DataType extends DataAbstractions {
  attr String className = "DataType";
  attr DataTypeOptions options;
  attr int precision;
  attr int scale;
}

@gmf.node(label.text="Collection")
class Collections extends DataAbstractions {
  attr String className = "Collections";
  attr String code;
  attr String typeName;
}

@gmf.node(label.text="Record")
class Records extends DataAbstractions {
  attr String className = "Records";
  attr String code;
  attr String typeName;
}

@gmf.node(label.text="Cursor")
class Cursor extends DataAbstractions {
  attr String className = "Cursor";
  attr String cursorQuery;
}

@gmf.node(label="description", label.icon="true", label.placement="internal")
abstract class Statements {
  attr String description;
  attr boolean isStart;
}

@gmf.node(figure="rectangle")
abstract class CallBlocks extends Statements {
  attr String nameSubroutine;
}

@gmf.node(figure="rectangle")
abstract class CursorOperations extends Statements {
  attr String cursorName;
}

@gmf.node(figure="rectangle")
abstract class SQLOperations extends Statements {
  attr String code;
}

@gmf.node(figure="rectangle")
abstract class IterationStructures extends Statements {

  @gmf.compartment
  val Statements[*] interations_statements;
}

@gmf.node(figure="rectangle")
abstract class ConditionalStructures extends Statements {
}

@gmf.node(figure="rectangle")
abstract class AdditionalOperations extends Statements {
}

@gmf.node(figure="rectangle")
class Expression extends AdditionalOperations {
  attr String className = "Expression";
  attr String value;
}

@gmf.node(figure="rectangle")
class Exception extends AdditionalOperations {
  attr String className = "Exception";
  attr String code;
}

@gmf.node(figure="rectangle")
class If extends ConditionalStructures {
  attr String className = "If";
  attr String condition;

  @gmf.compartment
  val Statements[*] true_statements;

  @gmf.compartment
  val Statements[*] false_statements;
}

@gmf.node(figure="rectangle")
class Case extends ConditionalStructures {
  attr String className = "Case";

  @gmf.compartment
  val Options[*] options;

  @gmf.compartment
  val Statements[*] default_statements;
}

@gmf.node(figure="rectangle", label="description", label.icon="true", label.placement="internal")
class Options {
  attr String className = "Options";
  attr String condition;
  attr String description;

  @gmf.compartment
  val Statements[*] case_statements;
}

@gmf.node(figure="rectangle")
class Insert extends SQLOperations {
  attr String className = "Insert";
}

@gmf.node(figure="rectangle")
class Update extends SQLOperations {
  attr String className = "Update";
}

@gmf.node(figure="rectangle")
class Delete extends SQLOperations {
  attr String className = "Delete";
}

@gmf.node(figure="rectangle")
class Select extends SQLOperations {
  attr String className = "Select";
}

@gmf.node(figure="rectangle")
class While extends IterationStructures {
  attr String className = "While";
  attr String condition;
}

@gmf.node(figure="rectangle")
class For extends IterationStructures {
  attr String className = "For";
  attr String counter;
  attr ForCounter typeCounter;
  attr int lowestNumber;
  attr int highestNumber;
}

@gmf.node(figure="rectangle")
class Loop extends IterationStructures {
  attr String className = "Loop";
  attr String breakCondition;
}

@gmf.node(figure="rectangle")
class Open extends CursorOperations {
  attr String className = "Open";
}

@gmf.node(figure="rectangle")
class Fetch extends CursorOperations {
  attr String className = "Fetch";
  attr String variableName;
}

@gmf.node(figure="rectangle")
class Close extends CursorOperations {
  attr String className = "Close";
}

@gmf.node(figure="rectangle")
class CallProcedure extends CallBlocks {
  attr String className = "CallProcedure";
}

@gmf.node(figure="rectangle")
class CallFunction extends CallBlocks {
  attr String className = "CallFunction";
}

abstract class Links {
  attr String name;
}

@gmf.link(source="source", target="target", incoming="true", target.decoration="arrow", color="0,0,0", width="1", label="name", label.text="Statement Connection", label.icon="true")
class Transition extends Links {
  ref Statements source;
  ref Statements target;
}

@gmf.link(source="source", target="target", incoming="true", target.decoration="arrow", style="dash", color="0,0,0", width="1", label="name", label.text="Case Connection", label.icon="true")
class OptionsTransition extends Links {
  ref Options source;
  ref Options target;
}

enum ParameterType {
  IN = 0;
  OUT = 1;
  IN_OUT = 2;
}

enum ForCounter {
  NORMAL = 0;
  REVERSE = 1;
}

enum DataTypeOptions {
  CHAR = 0;
  NCHAR = 1;
  NVARCHAR2 = 2;
  VARCHAR2 = 3;
  LONG = 4;
  RAW = 5;
  LONG_RAW = 6;
  NUMBER = 7;
  NUMERIC = 8;
  FLOAT = 9;
  DEC = 10;
  DECIMAL = 11;
  INTEGER = 12;
  INT = 13;
  SMALLINT = 14;
  REAL = 15;
  DOUBLE = 16;
  DATE = 17;
  TIMESTAMP_WITH_TIME_ZONE = 18;
  TIMESTAMP_WITH_LOCAL_TIME_ZONE = 19;
  INTERVAL_YEAR_TO_MONTH = 20;
  INTERVAL_DAY_TO_SECOND = 21;
  BFILE = 22;
  BLOB = 23;
  CLOB = 24;
  NCLOB = 25;
  ROWID = 26;
  UROWID = 27;
}


The .egl file to transform my model into text is as follow:

#auto-generated by CrystalCASE

[%

for(element in AnonymousBlock.allInstances()) {
	var firstElement = getFirstElement(element.executablePart);
	printStatements(firstElement);
	printElementsByTransition(firstElement);
}

for(element in Procedure.allInstances()) {
	var firstElement = getFirstElement(element.executablePart);
	printStatements(firstElement);
	printElementsByTransition(firstElement);
}

for(element in Function.allInstances()) {
	
	var firstElement = getFirstElement(element.executablePart);
	printStatements(firstElement);
	printElementsByTransition(firstElement);
}

operation getFirstElement(object){
	for(element in object) {
		if(element.isStart == true){
			return element;
		}
	}
}

operation Statements getNext() {
  return Transition.all.
  	select(t|t.source = self).
  	collect(t|t.target).
  	flatten();
}

operation isEmpty (object) {
   if(object.size > 0){
      return false;
   }
   return true;
}

operation printElementsByTransition(object) {
	var i = 0 ;
	var element;
	var x;
	for(transition in Transition.all) {
		if(i = 0) { 
			element = object.getNext();
			i = 1;
		} else{	
			element = element.first().getNext();
		}
		printStatements(element.first());
	}
}

operation printStatements(object) {

	if(not (object == null) ) {
		out.println(object);		
	}
}
%]


When I launch the gmf editor, I use the attached example named construtoresExemplo.crystal and I tried to transform this model into text. I already know that the problem is when I add a transition inside the compartment of object called "If", but I don't know why. With this informations, Could you try to help me, please?

Cheers
Re: Getting all objects with EGL [message #1752713 is a reply to message #1752711] Thu, 26 January 2017 12:41 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1590
Registered: July 2009
Location: York, UK
Senior Member

Hi,

Your code fails with a null pointer exception at the following statement (at that point elements is an empty sequence and as such elements.first() returns null). This is the expected behaviour.

element = element.first().getNext();


Cheers,
Dimitris
Re: Getting all objects with EGL [message #1752714 is a reply to message #1752713] Thu, 26 January 2017 12:48 Go to previous messageGo to next message
C. Santos is currently offline C. SantosFriend
Messages: 32
Registered: September 2015
Member
Hi,

Yes, I could see this NullPointer. But I don't know how can I change the .egl file to print all elements. how can I know that the sequence is empty?

Cheers
Re: Getting all objects with EGL [message #1752715 is a reply to message #1752714] Thu, 26 January 2017 12:52 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1590
Registered: July 2009
Location: York, UK
Senior Member

Hi,

element.isEmpty() should do the trick (see Table 3.5 in the Epsilon book https://www.eclipse.org/epsilon/doc/book/)

Cheers,
Dimitris
Re: Getting all objects with EGL [message #1752718 is a reply to message #1752715] Thu, 26 January 2017 12:59 Go to previous message
C. Santos is currently offline C. SantosFriend
Messages: 32
Registered: September 2015
Member
Hi,

Thanks, I'll try this.

Cheers
Previous Topic:How to export .model_diagram file into a plug-in ?
Next Topic:Nesting doesnt work
Goto Forum:
  


Current Time: Tue Sep 25 18:34:39 GMT 2018

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

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

Back to the top