Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Create Qualifiedname
Create Qualifiedname [message #1064045] Mon, 17 June 2013 11:50 Go to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Hi all ,
My grammar is below :

I want to all name start with Method.but method is recursive. so My qualified name start with first Method name and go on .My code is below :I can write M.M1.F.text BUT,I receive an error for this name:couldn't resolve reference.

public QualifiedName qualifiedName ( Function object) {
		String qualifiedName = "";
		ArrayList<String> names = new ArrayList<String>();
		Method w = (Method) object.eContainer();
		System.out.println(w);
		
	if(w.eContainer() !=null &&  w.eContainer() instanceof Web){
			 Web w1 =(Web) w.eContainer();
	 qualifiedName =  w1.getName().concat(".").concat(w.getName()) ;
			
	return QualifiedName.create(w1.getName().concat(".").concat(w.getName()),object.getName()) ;
			
			}else 
				return QualifiedName.create(w1.getName(),object.getName()) ;
		
		
	}





Context returns Context:
	'context'
	name=QualifiedName
	'{'
	
	 app=Application
	'}';
	
ContextUnit returns ContentextUnit:
	Context | Application | Collection | Method | Function | Type | Field ;

Application returns WebApplication:
	'Application'
	name=QualifiedName
	'{'
	
	collection+=Collection (collection+=Collection)*
	'}';

Collection returns Collection:
	'Collection'
	name=QualifiedName
	'{'
	
	 ownmethod=Method
	'}';

Method returns Method:
	'method'
	name=QualifiedName
	'{'
	
	
	(list+=Function (list+=Function)*)?
	(ownmethod+=Method (ownmethod+=Method)*)?
	'}';

Function returns Function:
	'function'
	name=QualifiedName
	'{'
	
    (type+=Type (type+=Type)*)?
	(ownedView+=View (ownedView+=View)*)?
	'}';

View returns View:
	'View'
	name=QualifiedName
	'{'
	
	'type' '=' type= STRING
	('fields' '=' ownedViewField+=ViewField (','ownedViewField+=ViewField)*)?
	'}';
ViewField returns ViewField:
(field= [Field|QualifiedName]);

Type returns Type:
	'type'
	name=QualifiedName
	'{'
	
	('parent' '=' parentType=[Type|QualifiedName])?
	'fields' '{'
	(ownedField+=Field (ownedField+=Field)*)?
	
	'}'
	'}';
	
	
	

Field returns Field:
	LookUp| TextField ;




LookUp returns LookUp:
	'LookUp'
	name=QualifiedName
	'{'
		
		('type' '=' type=[Type|QualifiedName])
	 	('showField' '=' showField =[Field|QualifiedName])
	'}';
	
TextField returns TextField:
	'Text' name=QualifiedName '{'
		
		'displayName' '=' displayName=STRING
		'property''=' property=STRING
		
	'}';


QualifiedName : 
	ID('.'ID)*
;






best regards
Re: Create Qualifiedname [message #1064074 is a reply to message #1064045] Mon, 17 June 2013 13:42 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
Hi,

why do you talk about web when this is about methods. so what about
(pseudo code)

public QualifiedName qualifiedName ( Method m) {
  if (eContainer of m instanceof Method) then concat(qualifiedName(eContainer of m), m.name) 
  else m.name as QualifiedName 

}
Re: Create Qualifiedname [message #1064161 is a reply to message #1064074] Mon, 17 June 2013 21:34 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Hi Christian,

I write this code :but my result is :type T {
parent = M.M1.M2.F. :(Sad
I don t get Type Sad M.M1.M2.F.T (I am wanted)
Could you help me .How can I solved this:(
Application A {
Collection collection {
method M {
method M1{
Method M2{
function F {
type T {
parent = M.M1.M2.F.
fields {
Text text {

displayName = "displayName" property = "Property"
}
Text created {
displayName = "displayName" property = "Property"
}


public QualifiedName qualifiedName( EObject object) {
		String qualifiedName = "";
		
		ArrayList<String> names = new ArrayList<String>();
		while (object.eContainer() != null && !(object.eContainer() instanceof Collection)) {
			if (object.eContainer() instanceof ContextUnit)
			names.add(((ContextUnit) object.eContainer()).getName());
			System.out.println("namessss"+names);
			object=  object.eContainer();
			System.out.println("objecttttttttttttttt"+  object);
		}
		
		for (int i = names.size() - 1; i >= 0; i--) {
			qualifiedName += names.get(i) + ".";
			System.out.println("xxxxxxxxxxxxxxxx"+qualifiedName);
		}
		return QualifiedName.create(qualifiedName );



Best regards
Re: Create Qualifiedname [message #1064163 is a reply to message #1064161] Mon, 17 June 2013 22:01 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
Hi sorry do what I suggested otherwise I cannot help

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Create Qualifiedname [message #1064180 is a reply to message #1064074] Tue, 18 June 2013 06:47 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member

Hi Christian,

I tried this pseudo code but not work Sad so I tried other my posted code .in addition,
Method is recorsive ( there are one more than Method).so I used While .

Christian Dietrich wrote on Mon, 17 June 2013 09:42
Hi,

why do you talk about web when this is about methods. so what about
(pseudo code)

public QualifiedName qualifiedName ( Method m) {
  if (eContainer of m instanceof Method) then concat(qualifiedName(eContainer of m), m.name) 
  else m.name as QualifiedName 

}

Re: Create Qualifiedname [message #1064184 is a reply to message #1064180] Tue, 18 June 2013 06:57 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
My code can handle all of this

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Create Qualifiedname [message #1064356 is a reply to message #1064184] Tue, 18 June 2013 20:47 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Hi Christian,

I ask one question.I customize my qualifiedname.I use this code
I shared it before.
I customize qualifiednameprovider :it is below.

BUT I take an error .parent = M.M1.M2.F.T (or M.M1.M2.F.T2) :I take error couldn't resolve reference for all names.I do not know really.Why receive this error.
in addition ,I tried your pseudo code but not successful.

Collection collection {
method M {
method M1{
Method M2{
function F {
type T {
parent = M.M1.M2.F.T or M.M1.M2.F.T2
type T2{



public QualifiedName qualifiedName( EObject object) {
String qualifiedName = QualifiedNameUtil.returnQualifiedNameOfElement(object)+ ((ContextUnit)object).getName();
		
		return QualifiedName.create(qualifiedName);
	}




public class QualifiedNameUtil {
	public static String returnQualifiedNameOfElement(EObject object) {
		String qualifiedName = "";
		ArrayList<String> names = new ArrayList<String>();
		while (object.eContainer() != null && !(object.eContainer() instanceof Collection)) {
			if (object.eContainer() instanceof ContextUnit)
				names.add(((ContextUnit) object.eContainer()).getName());
				object = object.eContainer();
		}

		for (int i = names.size() - 1; i >= 0; i--) {
			qualifiedName += names.get(i) + ".";
		}
		
		return qualifiedName;
	}
}



Best Regrads
Re: Create Qualifiedname [message #1064380 is a reply to message #1064356] Wed, 19 June 2013 04:22 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
Hi,

i still do not understand how you are working. you post makes ZERO sense for me. maybe you need someone doing the job for you.
the code you posted has nothing todo with the topic of this thread.

here some more formal Pseudo Code
public class MyQNP extends DefaultDeclarativeQualifiedNameProvider {
	
	@Inject IQualifiedNameConverter c;

	QualifiedName qualifiedName(Method m) {
		if (m.eContainer() instanceof Method) {
			return getFullyQualifiedName(m.eContainer()).append(c.toQualifiedName(m.getName()));
		} else {
			return c.toQualifiedName(m.getName());
		}
	}
}
Re: Create Qualifiedname [message #1064755 is a reply to message #1064380] Thu, 20 June 2013 20:32 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Hi Christian,

I want to ask one question.I remove one element's name from the qualified name.
I am aim :Below grammar :View's ownedField and Lookup's showfield (referenced field) these referenced field name has not Type element name (hence remove referenced field's name :M.M1.M2.F (I want to do onlly for referenced field name)
How can I remove T from M.M1.M2.F.T for referenced field name (Lookup and View)



Christian Dietrich wrote on Wed, 19 June 2013 00:22
Hi,

i still do not understand how you are working. you post makes ZERO sense for me. maybe you need someone doing the job for you.
the code you posted has nothing todo with the topic of this thread.

here some more formal Pseudo Code
public class MyQNP extends DefaultDeclarativeQualifiedNameProvider {
	
	@Inject IQualifiedNameConverter c;

	QualifiedName qualifiedName(Method m) {
		if (m.eContainer() instanceof Method) {
			return getFullyQualifiedName(m.eContainer()).append(c.toQualifiedName(m.getName()));
		} else {
			return c.toQualifiedName(m.getName());
		}
	}
}


best regards & thanks
Re: Create Qualifiedname [message #1064759 is a reply to message #1064755] Thu, 20 June 2013 20:52 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
?
Re: Create Qualifiedname [message #1064894 is a reply to message #1064759] Fri, 21 June 2013 14:20 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Hi Christian ,

I create my qualifiedname .it start with (Method) I shared my grammar.but now My aim is
View and Lookup elements has showField and ownedViewField attribute.Thise attribute has Field (such as :Text ,Lookup).I want to create other qualifiedname for these attribute's fiels name (I remove Type from this referenced fiedls's name)
I load screenshot :and I do yellow my aim (wanted qualifiedname)

Best Regards

Re: Create Qualifiedname [message #1064908 is a reply to message #1064894] Fri, 21 June 2013 15:17 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
The fix the nameprovider (concat grand parents - eContainer.eContainer fullyqualifiedname with the elements name)
i dont know why you did not get the idea yourself.
Re: Create Qualifiedname [message #1064991 is a reply to message #1064908] Sat, 22 June 2013 15:56 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Hi Christian,

My system Requirements Sad I do it all field see in the Function.But I have a one problem Sad

I use NamesareUniqueValidator fo duplicate name .I changed fields name so that I receeive error duplicate name for field because they are in the function .previosuly they are in the Type and I did not receive duplicate name error.How can I solved this problem ?

Best regards
Re: Create Qualifiedname [message #1064993 is a reply to message #1064991] Sat, 22 June 2013 17:12 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
Dont use unique validation.
Re: Create Qualifiedname [message #1064995 is a reply to message #1064993] Sat, 22 June 2013 18:07 Go to previous messageGo to next message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Hi Christian,

I do not understand ,

dont use NamesareUniqueValidator ?

Can I customize NamesareUniqueValidator?
Re: Create Qualifiedname [message #1064996 is a reply to message #1064995] Sat, 22 June 2013 18:09 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
Hi,

if you dont want to check unique names...
you may debug into the uniquenamevalidatorhelper
Re: Create Qualifiedname [message #1064997 is a reply to message #1064996] Sat, 22 June 2013 18:17 Go to previous message
junior developer is currently offline junior developer
Messages: 335
Registered: January 2013
Senior Member
Hi,

I want to check duplicate name.breviously, I check with namesareuniquevalidatorhelper
and I customize getDuplicateNameErrorMessage() .now I changed qualifiedname for field.
they see in the Function.
Previous Topic:LLVM Suport
Next Topic:AutoEditStrategy
Goto Forum:
  


Current Time: Fri Oct 24 14:44:14 GMT 2014

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

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