Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Check duplicate name in the same Scop
Check duplicate name in the same Scop [message #1046612] Mon, 22 April 2013 06:18 Go to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi all ,

I want to check duplicate file name ,mydocument inside the folder1 ,receive an error for file mydocument in the Folder1.Hence,my problem is :in the same scoping,if there is a dublicate name element ,receive an error.but different scop ,pereviosly file name is used.How can I provide?

Filesystem  Filesystem1  {
	Drive  D{ 
		
	    Folder  Folder1 {   
			File mydocument;  //duplicate  name
			
			File  mydocument //duplicate name
                        archive  =  true  readonly  =  false  ;
			Shortcut  shortcut1  ext  =  DOC  target  = mydocument1; 
			
		}  
		Folder Folder2 {  
			File  mydocument ;  //not duplicate name ,not in the same scop.because,inside the folder2                 
		}  

         Drive C {
                 Folder folder1
                } 





best regards
Re: Check duplicate name in the same Scop [message #1046618 is a reply to message #1046612] Mon, 22 April 2013 06:26 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Ps:My grammar is below :


import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Filesystem returns Filesystem:
'Filesystem' name=ID'{'
(drives+=Drive (drives+=Drive)* )?
(syncs += Sync (syncs +=Sync)* )?
'}';

SyncElement :
Drive|File|Folder
;

Sync returns Sync:
'sync' name=ID 'source' '=' source =[SyncElement|ID] 'target' '=' target =[SyncElement|ID] ';'
;
Drive returns Drive:
{Drive}
'Drive' name=ID '{'
(contents+=Object ( contents+=Object)* )?
'}' ;
Object:
File|Folder
;
File returns File:
'File' name=ID(
('content' '=' content = STRING )?
&('hQualifiedNameden' '=' HQualifiedNameden = EBoolean )?
&('readonly' '=' readonly = EBoolean )?
&('system' '=' system = EBoolean )?
&('archive' '=' archive = EBoolean )?
&('location' '=' location=STRING )?
&('date' '=' date=STRING )?
&('ext' '=' ext = EXT? )?
) ';' |Shortcut
;
EBoolean returns ecore::EBoolean:
'true' | 'false';
enum EXT :
EMPTY|PNG|TXT |JPG |JAVA | C | BAT |BMP |EXE |COM |DOC |PDF|DOCX|XLS|XLSX
;

Folder returns Folder:
'Folder' name=ID'{'
( contents+=Object(contents+=Object)* )?
'}';

Shortcut returns Shortcut:
'Shortcut' name=ID
('content' '=' content = STRING )?
&('hQualifiedNameden' '=' HQualifiedNameden = EBoolean )?
&('readonly' '=' readonly = EBoolean )?
&('system' '=' system = EBoolean )?
&('archive' '=' archive = EBoolean )?
&('location' '=' location=STRING )?
&('date' '=' date=STRING )?
&('ext' '=' ext = EXT? )?
('target' '=' target=[SyncElement|ID]) ';'
;

Re: Check duplicate name in the same Scop [message #1046622 is a reply to message #1046618] Mon, 22 April 2013 06:32 Go to previous messageGo to next message
rohit ahuja is currently offline rohit ahujaFriend
Messages: 27
Registered: February 2013
Junior Member
In the MWE2 flow, u have something like

fragment = validation.JavaValidatorFragment {
// composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
// composedCheck "org.eclipse.xtext.validation.NamesAreUniqueValidator"
}

change it to,(basically uncomment the second line)

fragment = validation.JavaValidatorFragment {
// composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
}

One thing i want to add though, it will check for unique names at all places that you have used 'name=ID'.. So if you dont want that, u need to have a validator instead.
Re: Check duplicate name in the same Scop [message #1046643 is a reply to message #1046622] Mon, 22 April 2013 07:19 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi rohit,

I used a validator but I can not check file name .I must use Qualifiedname instead of name =ID ? or I used nested for in the custom validation.I'm confused

Re: Check duplicate name in the same Scop [message #1046667 is a reply to message #1046643] Mon, 22 April 2013 07:59 Go to previous messageGo to next message
rohit ahuja is currently offline rohit ahujaFriend
Messages: 27
Registered: February 2013
Junior Member
Your example says,

File mydocument; //duplicate name
File mydocument //duplicate name

which is a simple name and not a qualified name, hence your grammar using name=ID is correct.
So the simple change to the MWE2 will solve your problem, no need for any validator.


Not sure exactly whether u are looking for a simple name or a fully qualified name, can u please elaborate?
Re: Check duplicate name in the same Scop [message #1046834 is a reply to message #1046667] Mon, 22 April 2013 12:47 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi ,

MWE2 not solve my problem:( because check duplicate name for all place.if I change
NamesAreUniqueValidator check all duplicate name (file folder drive names must be unique)

folder mydocument //duplicate name
file mydocument

I wanted : I can check duplicate drive name .I wanted to check Folder and File name in the same scop.for this situation ,I must write custom validation.but my problem is scoping Sad

 
Folder  Folder1 {   //in Folder1 scop ,mydocument1 duplicate name
			File mydocument1 ext =BMP;  
			File  mydocument1 archive  =  true  readonly  =  false  ;
			Shortcut  mydocument1 target = Defaultfoldername ;// not error because Shortcut's name   
			   
			
		} 
		Folder  Folder2 {

                        //not an duplicate name because Folder2's scop
		        File mydocument1 ext =BMP;  
			
			File  mydocument2 archive  =  true  readonly  =  false  ;	
		}

 


I hope ,I can explain my problem.
Re: Check duplicate name in the same Scop [message #1046838 is a reply to message #1046834] Mon, 22 April 2013 12:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

how does your grammar look like? what kind of nameprovider do you use.
if you use qualifiednames it should work
out of the box (using NamesAreUniqueValidator)

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Check duplicate name in the same Scop [message #1046849 is a reply to message #1046838] Mon, 22 April 2013 13:07 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian ,
I used name =ID ,and ı used NamesAreUniqueValidatorHelper for change default message ,but my problem is not solved.I wanted to check file name and folder name .
I solved for Drive name must be unique with custom validation :

@Check
		public void CheckDrivenamesareunique(Filesystem f){
			
			Filesystem filesystemlist =EcoreUtil2.getContainerOfType(f, Filesystem.class);
			
			List<Drive> drivelist =filesystemlist.getDrives();
			
			@SuppressWarnings("serial")
			Map<String, Drive> firstOccurrenceOfName = new HashMap <String, Drive>() {};
			System.out.println( firstOccurrenceOfName);
			    //the set of duplicate names
			Set<String> duplicateNames = new HashSet<String>();
			    for (Drive t : drivelist) {
			    	  String name = t.getName();
			        //if the name already occurred we have
			        //a duplicate name and hence an error
			        if (firstOccurrenceOfName.get(name) != null) {
			          duplicateNames.add(name);
			          //note the second parameter t
			          //it is essential difference to the first example
			         error("duplicate Drive name",t,FilesystemPackage.Literals.SYNC_ELEMENT__NAME,-1, DUPLICATE_DRİVE,
			  		       t.getName());	
			        } 
			        //otherwise store the name as first occurrence
			        else {
			          firstOccurrenceOfName.put(name, t);
			         
			        }
			    }
			      //now create the error for the first occurrence of a duplicate name
			     // for (String s : duplicateNames) {
			       // error("Duplicate name " + s,FilesystemPackage.Literals.DRIVE__CONTENTS,INVALID_SYCN 
			        		//); //}
	       }//Checknamesareunique
		



my grammar is below :
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Filesystem returns Filesystem:
'Filesystem' name=ID'{'
(drives+=Drive (drives+=Drive)* )?
(syncs += Sync (syncs +=Sync)* )?
'}';

SyncElement :
Drive|File|Folder	
;

Sync returns Sync:
'sync' name=ID	'source' '=' source =[SyncElement|ID] 'target' '=' target =[SyncElement|ID] ';'
;
Drive returns Drive:
{Drive}
'Drive' name=ID '{'
(contents+=Object ( contents+=Object)* )?
'}' ;
Object:
File|Folder
;
File returns File:
'File' name=ID( 
('content' '=' content = STRING )? 
&('hQualifiedNameden' '=' HQualifiedNameden = EBoolean )? 
&('readonly' '=' readonly = EBoolean )?
&('system' '=' system = EBoolean )?
&('archive' '=' archive = EBoolean )?
&('location' '=' location=STRING )?
&('date' '=' date=STRING )?
&('ext' '=' ext = EXT? )? 
) ';' |Shortcut
;	
EBoolean returns ecore::EBoolean:
'true' | 'false';
enum EXT :
EMPTY|PNG|TXT |JPG |JAVA | C | BAT |BMP |EXE |COM |DOC |PDF|DOCX|XLS|XLSX
;

Folder returns Folder:
'Folder' name=ID'{' 
( contents+=Object(contents+=Object)* )?
'}';

Shortcut returns Shortcut:
'Shortcut' name=ID 
('content' '=' content = STRING )? 
&('hQualifiedNameden' '=' HQualifiedNameden = EBoolean )? 
&('readonly' '=' readonly = EBoolean )?
&('system' '=' system = EBoolean )?
&('archive' '=' archive = EBoolean )?
&('location' '=' location=STRING )?
&('date' '=' date=STRING )?
&('ext' '=' ext = EXT? )? 
('target' '=' target=[SyncElement|ID]) ';'
;

Re: Check duplicate name in the same Scop [message #1047064 is a reply to message #1046849] Mon, 22 April 2013 18:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

i dont get the problem.

the following example model gives me errors on all three levels.

Filesystem
FS
{
Drive D1 {
Folder Fo1 {}
Folder Fo1 {}
}

Drive D1 {
Folder Fo2 {
File Fi1 ;
File Fi1 ;
}
}

Drive D2 {
Folder Fo1 {}
Folder Fo2 {
File Fi1 ;
}
}
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 22 April 2013 18:44]

Report message to a moderator

Re: Check duplicate name in the same Scop [message #1047880 is a reply to message #1047064] Tue, 23 April 2013 19:49 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian ,

I wanted 3 level checked.I showed error case on the program.I checked Drive name ,no problem (Drive D1 ->duplicate name error ) My problem is file and folder name.How can I do Sad I am confused

Filesystem
FS
{
Drive D1 {
[color=red]Folder Fo1 {}//Duplicate name  Fo1
Folder Fo1 {}[/color]
}

Drive D1 {// duplicate name for D1	
Folder Fo2 {
[color=red]File Fi1 ; //duplicate name for Fi1 .such as File Fo2 is not a duplicate name 	
File Fi1 ;[/color]	
}
}
//this section not give an duplicate name error because defined in the D2
Drive D2 {
Folder Fo1 {}
Folder Fo2 {
File Fi1 ;	
}
}
}

Re: Check duplicate name in the same Scop [message #1047910 is a reply to message #1047880] Tue, 23 April 2013 20:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Have a look at clusters in the validationhelper

--
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Check duplicate name in the same Scop [message #1047941 is a reply to message #1047910] Tue, 23 April 2013 21:41 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian ,

Sorry,I can not understand.Which class is used for check duplicate name based scop .I tried this solution in the http://www.eclipse.org/forums/index.php/mv/msg/261440/754503/#msg_754503 link.But my problem is not solved.my other solution is nested for but not succesful:(

Best Regards
Re: Check duplicate name in the same Scop [message #1048183 is a reply to message #1047941] Wed, 24 April 2013 06:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
I was talking about NamesAreUniqueValidatorHelper ()

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Check duplicate name in the same Scop [message #1048192 is a reply to message #1048183] Wed, 24 April 2013 06:36 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian,

NamesAreUniqueValidatorHelper () solved my problem ?

Best Regards
Re: Check duplicate name in the same Scop [message #1048238 is a reply to message #1048192] Wed, 24 April 2013 07:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
It is the point to look at

--
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Check duplicate name in the same Scop [message #1048964 is a reply to message #1048238] Thu, 25 April 2013 07:10 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian,

I can not solved my problem .I tried below code,but check all place.I am confused Sad. I can not found NamesAreUniqueValidatorHelper () example.
@Inject
	ResourceDescriptionsProvider resourceDescriptionsProvider;
	
	@Inject
	IContainer.Manager containerManager;

	@Check(CheckType.NORMAL)
	public void checkGreetingsDuplicate(Greeting greeting) {
		Set<QualifiedName> names = new HashSet<QualifiedName>();
		IResourceDescriptions resourceDescriptions = resourceDescriptionsProvider.getResourceDescriptions(greeting.eResource());
		IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(greeting.eResource().getURI());
		for (IContainer c : containerManager.getVisibleContainers(resourceDescription, resourceDescriptions)) {
			for (IEObjectDescription od : c.getExportedObjectsByType(MyDslPackage.Literals.GREETING)) {
				if (!names.add(od.getQualifiedName())) {
					error("duplicate greeting", MyDslPackage.Literals.GREETING__NAME);
				}
			}
		}



Best regards,
Re: Check duplicate name in the same Scop [message #1048979 is a reply to message #1048964] Thu, 25 April 2013 07:40 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi ,
I must fix below for check duplicate name for same scope? but,I do not understand clusterTypes.Please,Could you help me?I can check same instance same type.but still I check with scop.I must check 3 level.


protected ImmutableSet<EClass> getClusterTypes() {

return ImmutableSet.of(FilesystemPackage.Literals.FILE);
}
private ImmutableSet<EClass> clusterTypes = getClusterTypes();
@Override
protected EClass getAssociatedClusterType(EClass File) {
System.out.println(clusterTypes);
if (clusterTypes .contains(File))
return File;
EList<EClass> superTypes = File.getESuperTypes();
System.out.println(superTypes);
if (superTypes.isEmpty())
return File;
return getAssociatedClusterType(superTypes.get(0));
}

Drive T
	{  
		File file6 ; 
		File file7 ; 
		Folder r9{
			
		}
		Folder File10{  
			File file8;// receive duplicate name error ,in Drive T .
			File file4;    
			
		}
		
		}
		Drive F { 
			Folder file9{
				 
			}
			File file8;// receive duplicate name error but it is in the Drive F so not give an error .
			
		}
		

[Updated on: Thu, 25 April 2013 08:45]

Report message to a moderator

Re: Check duplicate name in the same Scop [message #1049105 is a reply to message #1048979] Thu, 25 April 2013 11:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

i dont get you checking logic:

you want to check only simple names for files and folder?
it does not count in which drive they are contained?

so if you have

drive a {
folder b {
file x1
}
file x2
}
drive c {
folder d {
file x3
}
file x4
}

what should be the names the folders and files should be checked against.
please give me a list


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Check duplicate name in the same Scop [message #1049139 is a reply to message #1049105] Thu, 25 April 2013 12:28 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian,
Again I show wanted to do on the below program.I wanted to do real file system .
file x1 in the drive a and drive c .it is in the different drive.File x3 in the different folder but same drive so not give an error.
I hope,I can explain my problem Sad How can I provide this case .I am confised .
drive a {
folder b {  
[color=red]file x1  //in the dolder b ,there are two same file name,this case duplicate name
file x1 [/color]
}
file x2
}
drive c {
folder d {
file x3
[color=red]file x1[/color]
}
[code]Folder g{
file x3 
}[/code]
file x4 //duplicate name
file x4
}



Thank you&best regards

[Updated on: Thu, 25 April 2013 12:29]

Report message to a moderator

Re: Check duplicate name in the same Scop [message #1049153 is a reply to message #1049139] Thu, 25 April 2013 12:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
So you want the name to be unique regardless the folder?

--
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Check duplicate name in the same Scop [message #1049154 is a reply to message #1049139] Thu, 25 April 2013 12:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Btw which nameprovider do you use? simplenameprovider? Defaultdeclarativenameprovider?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Check duplicate name in the same Scop [message #1049173 is a reply to message #1049154] Thu, 25 April 2013 13:23 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian,

Folder is in the Drive.so when same folder name in the Drive ,receive an duplicate name.but different Drive ,can be happen same name such as

Drive C
{ Folder folder1{}
Folder folder1{} //duplicate name because two same folder name in the same Drive
}
Drive D{

Folder folder1{} //not duplicate error because,in the drive D
}
If I can correct understand,I used simplenameprovider (name =ID for every meta model name)

I do not understand Defaultdeclarativenameprovider but I am not use .


Thanks & best regards
Re: Check duplicate name in the same Scop [message #1049193 is a reply to message #1049173] Thu, 25 April 2013 13:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

what is your binding for IQuulifiedNameprovider (e.g. AbstractMyDslModule)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Check duplicate name in the same Scop [message #1049211 is a reply to message #1049193] Thu, 25 April 2013 14:10 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian,

I do not write own Qualifiednameprovider.
Re: Check duplicate name in the same Scop [message #1049216 is a reply to message #1049211] Thu, 25 April 2013 14:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Still the question: how did you configure xtext in that point. what is in the abstractruntimemodule???????????????

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Check duplicate name in the same Scop [message #1049217 is a reply to message #1049216] Thu, 25 April 2013 14:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Alternatively: if you press Crtl+Shift+F3 and search for Model Elements of Type FIle and Folder(Runtime WS) what are the names displayed for your stuff.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Check duplicate name in the same Scop [message #1049224 is a reply to message #1049217] Thu, 25 April 2013 14:27 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian,

Sorry,QualifiedNamePrivider in the AstractFileSystemruntimeModule.
and My model Elements for file in the attachment.SimpleNameProvider used.

// contributed by org.eclipse.xtext.generator.exporting.SimpleNamesFragment
public Class<? extends org.eclipse.xtext.naming.IQualifiedNameProvider> bindIQualifiedNameProvider() {
return org.eclipse.xtext.naming.SimpleNameProvider.class;
}

[Updated on: Thu, 25 April 2013 14:29]

Report message to a moderator

Re: Check duplicate name in the same Scop [message #1049225 is a reply to message #1049224] Thu, 25 April 2013 14:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
If you use simplenameprovider (you may have changed the workflow) then its clear that simple names are compared.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Check duplicate name in the same Scop [message #1049408 is a reply to message #1049225] Thu, 25 April 2013 20:27 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian,

I think ,I can not understand my problem:( I used simplenameprovider for meta model element.and then I check duplicate name with custom validation.My aim is count of same file name in the Folder and produce an error for duplicate file name .The same way,count of Folders that have same name ,Folders are in the Drive.So I must found Parent (Drive) and then count of folders in this Drive.Such as
Below scenerio1 ,Drive C and Drive D in the Filesystem.
Scenerio 1:
Drive C{
Folder f1{} //duplicate name
Folder f1{}//duplicate name
}
Drive D{
Folder f1 //not duplicate name because Drive D
}
----------------------------------------------------------
Second Scenerio:
Drive D{
Folder f3{
File f3 //not duplicate name
}
Folder f4{
File f3 //not duplicate name because in the Folder f4
}
}
Now I can Check duplicate name for File Folder Drive but I can Checked every duplicate File's name ,Folder's name.I do not wanted below screenshot taht is in the attachment .I explain my problem above :Scenerio 1 and Second Scenerio.

Now I can checkduplicate name with NamesAreUniqueValidationHelper .My code :


protected ImmutableSet<EClass> getClusterTypes() {
		
		return ImmutableSet.of(FilesystemPackage.Literals.DRIVE,FilesystemPackage.Literals.FILE, FilesystemPackage.Literals.FOLDER);
	}
	private ImmutableSet<EClass> clusterTypes = getClusterTypes();
	@Override
	protected EClass getAssociatedClusterType(EClass File) {
		//System.out.println(clusterTypes);
	
		if (clusterTypes .contains(File))
			return File; 
		EList<EClass> superTypes = File.getESuperTypes();
		System.out.println(superTypes);
		if (superTypes.isEmpty())
			return File;
		return getAssociatedClusterType(superTypes.get(0));
	}

	
}



I bind FilesystemNamesAreUniqueValidator in the runtime module :

public Class<? extends INamesAreUniqueValidationHelper> bindINamesAreUniqueValidationHelper() {
return FilesystemNamesAreUniqueValidator.class;

}


Also ,I remove comment line in the NamesareuniqueValidator :

fragment = validation.JavaValidatorFragment {
// composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"

}

------------------------------------------------------------------
My problem is not solved this customization(above method) Sad .
1-use FileSystemJavaValidator?
for example:write code for find parent(such as Folder) ,and count duplicate File name(Childs).
2-use NameAreUniqueValidatorHelper ?
protected EClass getAssociatedClusterType(EClass File) customization.

really ,I am confused Sad(
I hope ,I explain my problem.

Thanks for your help &best regards .







Re: Check duplicate name in the same Scop [message #1049435 is a reply to message #1049408] Thu, 25 April 2013 21:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Why do you use simplenameprovider? and not DefaultDeclarativeQualifiedNameProvider?
if you stick with simplenameprovider dont use namesareuniquevalidator at all.
use a custom validation. The Class EcoreUtil2 might contain helpful methods for traversing


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Check duplicate name in the same Scop [message #1049436 is a reply to message #1049435] Thu, 25 April 2013 21:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
But i recommend to simply use DDQNP.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Check duplicate name in the same Scop [message #1049694 is a reply to message #1049436] Fri, 26 April 2013 07:00 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian,

I examined and tried this example :
http://christiandietrich.wordpress.com/2011/07/16/iqualifiednameproviders-in-xtext-2-0/
but My qualifiednameprovider test program is not work such as this output: (
TestPackage for the package
TestPackage.A and TestPackage.B for the elements

Also .Why do you use Qualifiednameprovider.I do not wanted my program's output such as:

Drive D{
Folder D.folder1 {
File D.folder1.file1 ;
}
}

If I can understand qualifiednameprovider correctly,I must use EcoreUtil2 for traversing the metamodel.

How Can I apply qualifiednameprovider on the my file system domain for check duplicate name(to find elements with the same name) ?

really,I am confused for Qualifiednameprovider Smile

Thanks for your help & best regards
Re: Check duplicate name in the same Scop [message #1049698 is a reply to message #1049694] Fri, 26 April 2013 07:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hääää?

this (parsing) has nothing todo with using a simple or qualified nameprovider.
it just determines how xtext stores the names to the index.
(which is used for the unique validation)

i am not ure what you mean by "output"


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Check duplicate name in the same Scop [message #1049729 is a reply to message #1049698] Fri, 26 April 2013 07:46 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian,

I want to say program instead of output .Output is a program.I hope,I understand Qualifiedname finally.

Thanks for help & best regards

[Updated on: Fri, 26 April 2013 07:48]

Report message to a moderator

Re: Check duplicate name in the same Scop [message #1049733 is a reply to message #1049729] Fri, 26 April 2013 07:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
As said before: the nameprovider does not matter for parsing.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Check duplicate name in the same Scop [message #1049906 is a reply to message #1049733] Fri, 26 April 2013 12:40 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian ,

I write custom validation for duplicate Folder name in the Drive.
Fist :I found all Drive
Second:Found all Folder in the Different Drive .show below :


org.xtext.example.filesystem.filesystem.impl.DriveImpl@7f5bbbcd (name: D)
[org.xtext.example.filesystem.filesystem.impl.FolderImpl@5690ff7b (name: Foldername)]
org.xtext.example.filesystem.filesystem.impl.DriveImpl@5f86d10d (name: F)
[org.xtext.example.filesystem.filesystem.impl.FolderImpl@3de9d7c0 (name: Folder1)]

I Wanted :Below output :Drive D has two Folder (names are Foldername) that has the same name,onlly I must checked this case.İn the Drive ,I wanted to count same name folder.How can I do Sad How I can use function ? ( such as getCurrentObject()).I do two for loop .one Drive other Folder,but I can not count same name folder.
----------------------------------
org.xtext.example.filesystem.filesystem.impl.DriveImpl@4504ac5e (name: D)
[org.xtext.example.filesystem.filesystem.impl.FolderImpl@81ba9a2 (name: Foldername), org.xtext.example.filesystem.filesystem.impl.FolderImpl@501dced6 (name: Foldername)]
org.xtext.example.filesystem.filesystem.impl.DriveImpl@68a2ca98 (name: F)
[org.xtext.example.filesystem.filesystem.impl.FolderImpl@4bfaa2c4 (name: Folder1), org.xtext.example.filesystem.filesystem.impl.FolderImpl@33d418d4 (name: Foldername)]

My code :
@Check
public void foldernamechaeck(Drive driveobject){
Drive Drivelist =EcoreUtil2.getContainerOfType(driveobject, Drive.class);

System.out.println(Drivelist);
List<Folder> folderlist = EcoreUtil2.getAllContentsOfType(Drivelist, Folder.class);

System.out.println(folderlist);

EObject parentdrive = getCurrentObject().eContainer();

//System.out.println( parentdrive);




}//foldernamecheck
Thanks & best regrads
Re: Check duplicate name in the same Scop [message #1049909 is a reply to message #1049733] Fri, 26 April 2013 12:41 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian ,

I write custom validation for duplicate Folder name in the Drive.
Fist :I found all Drive
Second:Found all Folder in the Different Drive .show below :


org.xtext.example.filesystem.filesystem.impl.DriveImpl@7f5bbbcd (name: D)
[org.xtext.example.filesystem.filesystem.impl.FolderImpl@5690ff7b (name: Foldername)]
org.xtext.example.filesystem.filesystem.impl.DriveImpl@5f86d10d (name: F)
[org.xtext.example.filesystem.filesystem.impl.FolderImpl@3de9d7c0 (name: Folder1)]

I Wanted :Below output :Drive D has two Folder (names are Foldername) that has the same name,onlly I must checked this case.İn the Drive ,I wanted to count same name folder.How can I do Sad How I can use function ? ( such as getCurrentObject()).I do two for loop .one Drive other Folder,but I can not count same name folder.
----------------------------------
org.xtext.example.filesystem.filesystem.impl.DriveImpl@4504ac5e[/email] (name: D)
[[email]org.xtext.example.filesystem.filesystem.impl.FolderImpl@81ba9a2[/email] (name: Foldername), org.xtext.example.filesystem.filesystem.impl.FolderImpl@501dced6[/email] (name: Foldername)]
org.xtext.example.filesystem.filesystem.impl.DriveImpl@68a2ca98[/email] (name: F)
org.xtext.example.filesystem.filesystem.impl.FolderImpl@4bfaa2c4[/email] (name: Folder1),
org.xtext.example.filesystem.filesystem.impl.FolderImpl@33d418d4[/email] (name: Foldername)]


My code :
@Check
public void foldernamechaeck(Drive driveobject){
Drive Drivelist =EcoreUtil2.getContainerOfType(driveobject, Drive.class);

System.out.println(Drivelist);
List<Folder> folderlist = EcoreUtil2.getAllContentsOfType(Drivelist, Folder.class);

System.out.println(folderlist);

EObject parentdrive = getCurrentObject().eContainer();

//System.out.println( parentdrive);




}//foldernamecheck
Thanks & best regrads

[Updated on: Fri, 26 April 2013 12:42]

Report message to a moderator

Re: Check duplicate name in the same Scop [message #1049917 is a reply to message #1049906] Fri, 26 April 2013 12:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Simple iterate and add the names to a list. Pure java this is. Still
the question: why don't you simply use DefaultDeclarativeNameProvider

--
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Check duplicate name in the same Scop [message #1049971 is a reply to message #1049917] Fri, 26 April 2013 14:22 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian ,

If I use QualifiedNameProviderprovider ,my problem is solved certainly ?You can give an Example for QualifiedNameProvider.

In addition :

I write a code for duplicate folder:But it give error for every Folder name.My aim is :there arent two folder that has not same name.now I onlly want to check it.not compare folder name Sad

@Check
		public void foldernamechaeck(Filesystem driveobject){
			Filesystem drive =EcoreUtil2.getContainerOfType(driveobject, Filesystem.class);
			System.out.println(drive + "**********");
			List<Drive> drivelist = EcoreUtil2.getAllContentsOfType(drive, Drive.class);
			System.out.println(drivelist);
			List<Folder> folderlist = EcoreUtil2.getAllContentsOfType(drive, Folder.class);
			
			System.out.println(folderlist);
			
			 EObject parentdrive = getCurrentObject().eContainer();
			 
			 int i=0;
			for( Drive d :drivelist)
			{   
				for (Folder f : folderlist){
				
				for(Folder f1 :folderlist){
			if(f.getName() == f1.getName() && i>1){
			error("duplicate File name",f,FilesystemPackage.Literals.SYNC_ELEMENT__NAME,-1, DUPLICATE_FILE,
					   f.getName());
			
			}
					        }//ilk forun
				
				}
				
				i++;	
				}

Re: Check duplicate name in the same Scop [message #1049975 is a reply to message #1049971] Fri, 26 April 2013 14:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Create a new project. Paste the grammar . run it done.

--
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Check duplicate name in the same Scop [message #1050651 is a reply to message #1049975] Sat, 27 April 2013 14:26 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian,

I can solved my problem finally Smile .I used Qualifiednameprovider Smile
in the end ,I understand Qualifiedname .I tried a lots of method(I written custom validation(pure java)for nested Element(Drive->Folder->File))
but my problem have not solved .now I solved my problem for your help.Xtext is a excellent framework Smile

Thanks again & best regards .
Re: Check duplicate name in the same Scop [message #1050652 is a reply to message #1049975] Sat, 27 April 2013 14:27 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian,

I can solved my problem finally .I used Qualifiednameprovider
in the end ,I understand Qualifiedname .I tried a lots of method(I written custom validation(pure java)for nested Element(Drive->Folder->File))
but my problem have not solved .now I solved my problem for your help.Xtext is a excellent framework

Thanks again & best regards .
Re: Check duplicate name in the same Scop [message #1050911 is a reply to message #1049975] Sun, 28 April 2013 00:11 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian,

I use Qualifiednameprovider but I have a problem with crossreference .'sync' name=ID 'source' '=' source =[SyncElement|ID] 'target' '=' target =[SyncElement|ID] ';'

When I enter ctrl-space "after source =" get Drive names (such as D,C,E). my problem is :don t get all of object (File ,Folder,Drive names don t get )
BUT,I added Qualifiedname in the grammar,such as
'sync' name=ID 'source' '=' source =[SyncElement|@ualifiedname] 'target' '=' target =[SyncElement|ID] ';'

Qualifiedname :
ID
'target' '=' target =[SyncElement|ID] : get onlly Drive names For target
source =[SyncElement|@ualifiedname] :get all File Drive and Folder names with "." such as D.folder1 ->I do not wanted this

When I reach Folder and File.but get D.file1 Sad I do not wanted use for Qualifiedname : ID('.'ID)*

I attached program screenshot.

How can I solved Crossreference problem?

-----------------------------------------------------
my grammar :
[size=3]Filesystem returns Filesystem:
   'Filesystem' name=ID'{'
		(drives+=Drive (drives+=Drive)* )?
		(syncs += Sync (syncs +=Sync)* )?
		'}';

 SyncElement  :
 Drive|File|Folder	
;

Sync returns  Sync:
'sync' name=ID	'source' '=' source =[SyncElement|ID] 'target' '=' target =[SyncElement|ID] ';'
;



Drive returns Drive:
	{Drive}
	'Drive' name=ID '{'
	(contents+=Object ( contents+=Object)* )?
	'}' ;
Object:
File|Folder
;
File returns File:
'File' name=ID ( 
	     ('content' '=' content = STRING  )? 
	    &('hidden' '=' Hidden = EBoolean  )? 
	    &('readonly' '=' readonly = EBoolean )?
	    &('system' '=' system = EBoolean  )?
	    &('archive' '=' archive = EBoolean  )?
	    &('location' '=' location=STRING  )?
	    &('date' '='  date=STRING )?
	    &('ext' '=' ext = EXT? )? 
	    ) ';' |Shortcut
	;	
EBoolean returns ecore::EBoolean:
	'true' | 'false';
enum EXT :
EMPTY|PNG|TXT |JPG |JAVA | C | BAT |BMP |EXE |COM |DOC |PDF|DOCX|XLS|XLSX
;

Folder returns Folder:
   'Folder' name=ID'{' 
		( contents+=Object(contents+=Object)* )?
	'}';
 
Shortcut returns Shortcut:
   'Shortcut' name=ID
   		(('content' '=' content = STRING  )? 
	    &('hidden' '=' Hidden = EBoolean  )? 
	    &('readonly' '=' readonly = EBoolean )?
	    &('system' '=' system = EBoolean  )?
	    &('archive' '=' archive = EBoolean  )?
	    &('location' '=' location=STRING  )?
	    &('date' '='  date=STRING )?
	    &('ext' '=' ext = EXT? )? 
	   )('target' '=' target=[SyncElement|ID])  ';'
   ;
[/size]



Best regards,

[Updated on: Sun, 28 April 2013 01:22]

Report message to a moderator

Re: Check duplicate name in the same Scop [message #1051105 is a reply to message #1050911] Sun, 28 April 2013 07:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
1000th answer to this question

xxx=[YYY] is short for xxx=[YYY|ID] => change it to xxx=[YYY|FQN] with FQN: ID ("." ID)*;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Check duplicate name in the same Scop [message #1051214 is a reply to message #1051105] Sun, 28 April 2013 11:59 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian,
I tried xxx=[YYY] is short for xxx=[YYY|ID] => change it to xxx=[YYY|FQN] with FQN: ID ("." ID)*;


I changed it such as :
Sync returns Sync:
'sync' name=ID 'source' '=' source =[SyncElement|Qualifiedname] 'target' '=' target =[SyncElement|Qualifiedname] ';'
;

Qualifiedname :

ID("."ID)*


But get the my cross reference elements such as D.folder1 ,I want to remove "."
show the program:
sync sync1 source=D.folder target =D.folder.file;

I want :
sync sync1 source=folder target =file;

Best regards,
Re: Check duplicate name in the same Scop [message #1051218 is a reply to message #1051214] Sun, 28 April 2013 12:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

what do you do if the same file is in two drives?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Check duplicate name in the same Scop [message #1051219 is a reply to message #1051218] Sun, 28 April 2013 12:01 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Btw there is no fast solution that does both: short/simple names and qualified checks.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Integrate xml file instead of own dsl into xtext framework
Next Topic:References to files
Goto Forum:
  


Current Time: Fri Mar 29 07:54:26 GMT 2024

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

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

Back to the top