Check duplicate name in the same Scop [message #1046612] |
Mon, 22 April 2013 06:18 |
junior developer 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 #1046849 is a reply to message #1046838] |
Mon, 22 April 2013 13:07 |
junior developer 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 #1048979 is a reply to message #1048964] |
Thu, 25 April 2013 07:40 |
junior developer 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 |
|
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 #1049224 is a reply to message #1049217] |
Thu, 25 April 2013 14:27 |
junior developer 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 #1049408 is a reply to message #1049225] |
Thu, 25 April 2013 20:27 |
junior developer 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) .
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 (
I hope ,I explain my problem.
Thanks for your help &best regards .
|
|
|
|
|
|
|
|
|
|
Re: Check duplicate name in the same Scop [message #1049909 is a reply to message #1049733] |
Fri, 26 April 2013 12:41 |
junior developer 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 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 #1049971 is a reply to message #1049917] |
Fri, 26 April 2013 14:22 |
junior developer 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
@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 #1050911 is a reply to message #1049975] |
Sun, 28 April 2013 00:11 |
junior developer 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 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
|
|
|
|
|
|
|