Changes between Version 1 and Version 2 of Developer


Ignore:
Timestamp:
06/25/14 10:19:13 (10 years ago)
Author:
hkaulbersch
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Developer

    v1 v2  
    55'''The used Features are:''' 
    66 
    7  
    87 * Grammardefinition 
    98 
    10  
    11  
    12  
    139 * Validation 
    1410 
    15  
    1611 * Quickfixing 
    1712 
    18  
    1913 * Generation of content from the BNF 
    2014 
    21  
    2215 * Formatting 
    2316 
    24  
    2517 * Outlining 
    2618 
    27  
    2819 * File import 
    2920 
    30  
    3121 * Deployment as Plugin 
    3222 
    33  
    3423 * Deployment as RCP (Rich Client Platform) 
    3524 
    36  
    37  
    3825'''Grammardefinition:''' 
    3926 
     
    4633!EtsiBnf: 
    4734 
    48 'grammar'name=ID 
    49  
    50 (       type='/__bnf__'?';' 
    51  
    52 (importSection=!ImportSection)? 
    53  
    54 (bnfEntry+=!BnfEntry)+ 
    55  
    56 ) 
    57  
    58 | 
    59  
    60 (       type='/delta'';' 
    61  
    62 (importSection=!ImportSection)? 
    63  
    64 (deltaEntry+=!DeltaEntry)* 
    65  
    66 ) 
    67  
    68 | 
    69  
    70 (       type='/merge'';' 
    71  
    72 (importSection=!ImportSection)? 
    73  
    74 (mergeEntry+=!MergeEntry)* 
    75  
    76 ) 
     35 'grammar'name=ID 
     36 
     37        (       type='/__bnf__'?';' 
     38 
     39                (importSection=!ImportSection)? 
     40 
     41                (bnfEntry+=!BnfEntry)+ 
     42 
     43        ) 
     44 
     45        | 
     46 
     47        (       type='/delta'';' 
     48 
     49                (importSection=!ImportSection)? 
     50 
     51                (deltaEntry+=!DeltaEntry)* 
     52 
     53        ) 
     54 
     55        | 
     56 
     57        (       type='/merge'';' 
     58 
     59                (importSection=!ImportSection)? 
     60 
     61                (mergeEntry+=!MergeEntry)* 
     62 
     63        ) 
    7764 
    7865; 
     
    8067To turn this into a runable application  the .mwe2 file in the same folder must be executed as MWE2 Workflow. 
    8168 
    82 After this the whole project can be executed as an Eclipse Application for testing 
     69After this the whole project can be executed as an Eclipse Application for testing: 
    8370 
    8471'''Validation allows to check for conditions in the BNF-Document:''' 
     
    9279'''defvoid'''checkUnusedRule(Rule rule) { 
    9380 
    94 '''var'''List<!RuleReference> references = !EbnfAnalysisUtils.''findReferences''(rule); 
    95  
    96 '''var'''List<Rule> references1 =       !EbnfAnalysisUtils.''findReferences''(rule,resourceDescriptions); 
    97  
    98 '''if'''((references.size+references1.size ==0) && (rule.getRulenumber() !=1)) 
     81  '''  var'''  List<!RuleReference  > references = !EbnfAnalysisUtils  .''  findReferences''  (rule); 
     82 
     83  '''  var'''  List<Rule> references1 =        !EbnfAnalysisUtils  .''  findReferences''  (rule,resourceDescriptions); 
     84 
     85  '''  if'''  ((references.size+references1.size ==0) && (rule.getRulenumber() !=1)) 
    9986 
    10087warning(''unusedRuleDescription'', !EbnfPackage$Literals::''RULE!__NAME'',''unusedRuleDescription'', rule.name); 
     
    128115@Fix(!EbnfValidator.''unusedRuleDescription'') 
    129116 
    130 '''defvoid'''fixUnusedRule(Issue issue, !IssueResolutionAcceptor acceptor) { 
    131  
    132 acceptor.accept(issue,"Remove unused rule","Delete the unused rule","upcase.png",[ element, context | 
    133  
    134 '''var'''Rule rule = element'''as'''Rule; 
    135  
    136 '''var'''IXtextDocument xtextDocument = context.getXtextDocument(); 
    137  
    138 '''var'''ICompositeNode node = !NodeModelUtils.''findActualNodeFor''(rule); 
    139  
    140 '''varint'''offset = node.textRegion.offset; 
    141  
    142 '''var'''String nodeText = node.text; 
    143  
    144 '''varint'''textLength = nodeText.length -2; 
    145  
    146 xtextDocument.replace(offset, textLength,""); 
    147  
    148 ]) 
    149  
    150 } 
    151  
    152 The @Fix(''String token'') annotation definies that the following method is a quickfix for a validationwarning, with that ''token'' as code parameter: 
    153  
    154 warning(''unusedRuleDescription'', !EbnfPackage$Literals::''RULE!__NAME'',      ''__unusedRuleDescription__'', rule.name); 
     117'''  defvoid'''fixUnusedRule(Issue issue, !IssueResolutionAcceptor acceptor) { 
     118 
     119  acceptor.accept(issue,"Remove unused rule","Delete the unused rule", 
     120 
     121  "upcase.png",[ element, context | 
     122 
     123  '''  var'''  Rule rule = element'''  as'''  Rule; 
     124 
     125  '''  var'''  IXtextDocument xtextDocument = context.getXtextDocument(); 
     126 
     127  '''  var'''  ICompositeNode node = !NodeModelUtils  .''  findActualNodeFor''  (rule); 
     128 
     129  '''  varint'''  offset = node.textRegion.offset; 
     130 
     131  '''  var'''  String nodeText = node.text; 
     132 
     133  '''  varint'''  textLength = nodeText.length -2; 
     134 
     135  xtextDocument.replace(offset, textLength,""); 
     136 
     137  ]) 
     138 
     139} 
     140 
     141The@Fix(''String token'')annotation definies that the following method is a quickfix for a validationwarning, with that''token''as code parameter: 
     142 
     143warning(''unusedRuleDescription'', !EbnfPackage$Literals::''RULE!__NAME'',        ''__unusedRuleDescription__'', rule.name); 
    155144 
    156145@Fix(!EbnfValidator.''__unusedRuleDescription__'') 
     
    158147The accaptor inside applies the changes, via two possible ways: 
    159148 
    160  
    161149 1. Change the Document itself (like the example shows). 
    162150 
    163  
    164151 1. Change the underlying ecoremodel. 
    165152 
    166  
    167  
    168153[[BR]]'''Generation allows to generate other files from a BNF-Document:''' 
    169154 
     
    174159It can be customized in the File  de.ugoe.cs.swe.bnftools.ebnf/de.ugoe.cs.swe.ebnf.generator/!EbnfGenerator.xtend 
    175160 
    176 Where the doGenerate methode defines how the files given by a Resource and a  !IfileSystemAccess should generate a new file. While for every relevant Entity from the  
    177  
    178 BNF a compile Methode handles the generation in the new file, while it calls the compile Methode for every related Entity e.g.: 
     161Where thedoGeneratemethode defines how the files given by a Resource and a !IfileSystemAccess should generate a new file. While for every relevant Entity from the 
     162 
     163BNF a  
     164 
     165compile 
     166 
     167Methode handles the generation in the new file, while it calls the compile Methode for every related Entity e.g.: 
    179168 
    180169'''override''' '''void''' doGenerate(Resource resource, IFileSystemAccess fsa) { 
    181170 
     171  '''  for'''  (e : resource.allContents.''  toIterable''  .''  filter''  (!EtsiBnf  )) { 
     172 
     173  '''  if'''  (e.bnfEntry.size !=0) { 
     174 
     175  fsa.generateFile(e.name +".fo", e.compile) 
     176 
     177  } 
     178 
     179  } 
     180 
     181} 
     182 
     183'''def'''compile(!DefinitionList dList)!'''«'''FOR'''sDef : ist.singleDefinition»«sDef.compile» «'''IF''' !sDef.equals(dList.singleDefinition.''last'')»|«'''ENDIF'''»«'''ENDFOR'''»!''' 
     184 
     185Based on the generated .fo file a PDF-document can be generated for this the class de.ugoe.cs.swe.bnftools.ebnf/de.ugoe.cs.swe.ebnf.generator/foToPDF can be used, either by giving the .fo file and the output URI without Ending or simply the giving the classpath of the file. 
     186 
     187For this the dodoGenerateMethode needed an upgrade to access the filesystem via URIs: 
     188 
     189'''overridevoid'''doGenerate(Resource resource, IFileSystemAccess fsa) { 
     190 
     191'''var'''String workspacePath = !WorkspaceResolver.''getWorkspace''(); 
     192 
    182193'''for'''(e : resource.allContents.''toIterable''.''filter''(!EtsiBnf)) { 
    183194 
    184195'''if'''(e.bnfEntry.size !=0) { 
    185196 
    186 fsa.generateFile(e.name +".fo", e.compile) 
    187  
    188 } 
    189  
    190 } 
    191  
    192 '''def'''compile(!DefinitionList dList)!'''«'''FOR'''sDef : ist.singleDefinition»«sDef.compile» 
    193  
    194         «'''IF''' !sDef.equals(dList.singleDefinition.''last'')»|«'''ENDIF'''»«'''ENDFOR'''»!''' 
    195  
    196 '''Generation of PDF using Apache FOP:''' 
    197  
    198 Based on the generated .fo file a PDF-document can be generated for this the class de.ugoe.cs.swe.bnftools.ebnf/de.ugoe.cs.swe.ebnf.generator/foToPDF can be used, either by giving the .fo file and the output URI without Ending or simply the giving the classpath of the file. 
    199  
    200 For this the dodoGenerateMethode needed an upgrade to access the filesystem via URIs: 
    201  
    202 '''overridevoid'''doGenerate(Resource resource, IFileSystemAccess fsa) { 
    203  
    204 '''var'''String workspacePath = !WorkspaceResolver.''getWorkspace''(); 
    205  
    206 '''for'''(e : resource.allContents.''toIterable''.''filter''(!EtsiBnf)) { 
    207  
    208 '''if'''(e.bnfEntry.size !=0) { 
    209  
    210197fsa.generateFile(e.name +".__fo__", e.compile) 
    211198 
     
    214201'''var'''uri = (fsa'''as'''IFileSystemAccessExtension2).getURI(e.name +".__fo__"); 
    215202 
    216 '''var'''String fullUri = workspacePath + uri.path.substring(10,                                        uri.path.length); 
     203'''var'''String fullUri = workspacePath + uri.path.substring(10,                                         uri.path.length); 
    217204 
    218205'''var'''File file ='''new'''File(fullUri); 
     
    394381ISelection selection = !HandlerUtil.''getCurrentSelection''(event); 
    395382 
    396 '''     if'''(selection'''instanceof'''IStructuredSelection) { 
    397  
    398 IStructuredSelection structuredSelection = (IStructuredSelection)                       selection; 
     383'''        if'''(selection'''instanceof'''IStructuredSelection) { 
     384 
     385IStructuredSelection structuredSelection = (IStructuredSelection)                         selection; 
    399386 
    400387Object firstElement = structuredSelection.getFirstElement(); 
    401388 
    402 '''             if'''(firstElement'''instanceof'''IFile) { 
     389'''                if'''(firstElement'''instanceof'''IFile) { 
    403390 
    404391IFile file = (IFile) firstElement; 
     
    408395IFolder srcGenFolder = project.getFolder("src-gen"); 
    409396 
    410 '''                     if'''(!srcGenFolder.exists()) { 
    411  
    412 '''                     try'''{ 
     397'''                        if'''(!srcGenFolder.exists()) { 
     398 
     399'''                        try'''{ 
    413400 
    414401srcGenFolder.create('''true''','''true''','''new'''!NullProgressMonitor()); 
     
    416403}'''catch'''(!CoreException e) { 
    417404 
    418 '''                             returnnull'''; 
    419  
    420 } 
    421  
    422 } 
    423  
    424 '''             final'''!EclipseResourceFileSystemAccess2 fsa =fileAccessProvider.get(); 
     405'''                                returnnull'''; 
     406 
     407} 
     408 
     409} 
     410 
     411'''                final'''!EclipseResourceFileSystemAccess2 fsa =fileAccessProvider.get(); 
    425412 
    426413fsa.setOutputPath(srcGenFolder.getFullPath().toString()); 
     
    438425} 
    439426 
    440 '''     returnnull'''; 
     427'''        returnnull'''; 
    441428 
    442429}