型号
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
'namespace' name=QualifiedName ';'
statements+=Statement (statements+=Statement)*
;
QualifiedName:
ID ('.' ID)*;
Statement:
(
SystemThread
| FunctionalUseCase
| Action
);
SystemThread :
'thread' name=ID
'{'
('functionals' ':' functionals+=[FunctionalUseCase] (',' functionals+=[FunctionalUseCase])* ';')?
('actions' ':' qualifyingActions+=[Action|QualifiedName] (',' qualifyingActions+=[Action|QualifiedName])* ';')?
'}';
FunctionalUseCase:
'functional' name=ID
'{'
('actions' ':' prerequisite+=[Action|QualifiedName] (',' prerequisite+=[Action|QualifiedName])* ';')?
('functionals' ':' subfunctionals+=[FunctionalUseCase] (',' subfunctionals+=[FunctionalUseCase])* ';')?
'}';
Action :
'action' name=ID
'{'
'}';
摘要
public static void createBigModel()
{
Injector inj = new MyDslStandaloneSetupGenerated().createInjectorAndDoEMFRegistration();
String theFile = "C:/data/big3.mydsl"; // if i chnage to xmi it saves quick
File aFile = new File(theFile);
if(aFile.exists())
{
aFile.delete();
}
XtextResourceSet myResourceSet = inj.getInstance(XtextResourceSet.class);
URI uri = URI.createFileURI(theFile);
Resource resource = myResourceSet.createResource(uri);
org.xtext.example.mydsl.myDsl.Model m = MyDslFactory.eINSTANCE.createModel();
resource.getContents().add(m);
m.setName("myglobals.foo.bar.test1");
Action a1 = MyDslFactory.eINSTANCE.createAction();
a1.setName("a1");
m.getStatements().add(a1);
Map<String,FunctionalUseCase> mfuncs = new HashMap<String,FunctionalUseCase>();
long start = System.currentTimeMillis();
for(int x=0;x<10000;++x)
{
FunctionalUseCase f1 = MyDslFactory.eINSTANCE.createFunctionalUseCase();
f1.setName("f" + x);
f1.getPrerequisite().add(a1);
m.getStatements().add(f1);
mfuncs.put(f1.getName(), f1);
}
for(int x=0;x<10000;++x)
{
SystemThread t1 = MyDslFactory.eINSTANCE.createSystemThread();
t1.setName("thread" + x);
//String fname = "f"+x;
//t1.getFunctionals().add(mfuncs.get(fname));
m.getStatements().add(t1);
}
long end1 = System.currentTimeMillis();
EcoreUtil.resolveAll(resource);
System.out.println("Creation time = " + (end1-start));
try
{
resource.save(null);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
long end2 = System.currentTimeMillis();
System.out.println("Save time = " + (end2-end1));
}