Changeset 66 in default
- Timestamp:
- 05/14/14 10:07:49 (11 years ago)
- Location:
- v2/trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
v2/trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/outline/EbnfOutlineTreeProvider.xtend
r61 r66 10 10 */ 11 11 class EbnfOutlineTreeProvider extends org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider { 12 12 13 13 } -
v2/trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/quickfix/EbnfQuickfixProvider.xtend
r65 r66 20 20 import de.ugoe.cs.swe.bnftools.ebnf.EtsiBnf 21 21 import java.util.ArrayList 22 import org.eclipse.xtext.EcoreUtil2 23 import de.ugoe.cs.swe.bnftools.ebnf.BnfEntry 24 import org.eclipse.emf.ecore.util.EcoreUtil 25 import org.eclipse.emf.common.util.EList 26 import org.eclipse.xtext.resource.IResourceDescriptions 27 import com.google.inject.Inject 28 import de.ugoe.cs.swe.bnftools.ebnf.DefinitionList 29 import de.ugoe.cs.swe.bnftools.ebnf.SingleDefinition 30 import de.ugoe.cs.swe.bnftools.ebnf.util.EbnfAdapterFactory 22 31 23 32 /** … … 28 37 class EbnfQuickfixProvider extends org.eclipse.xtext.ui.editor.quickfix.DefaultQuickfixProvider { 29 38 39 @Inject 40 IResourceDescriptions resourceDescriptions; 41 30 42 //***************************************************************************************** 31 //works 32 @Fix(EbnfValidator.ruleReferencedOneDescription) 33 def void fixInlineRuleReferencedOnce(Issue issue, IssueResolutionAcceptor acceptor) { 34 acceptor.accept( 35 issue, 36 "Inline the rule", 37 "Delete the rule and replace its single reference by the rule's right side", 38 "upcase.png" 39 ) [ element, context | 40 var Rule rule = element as Rule; 41 42 var IXtextDocument xtextDocument = context.getXtextDocument(); 43 var ICompositeNode node = NodeModelUtils.findActualNodeFor(rule); 44 var String nodeText = node.text; 45 var int textLength = nodeText.length - 2; 46 var int offset = node.textRegion.offset; 47 //rename references 48 var ICompositeNode dList = NodeModelUtils.findActualNodeFor(rule.definitionList); 49 var String refText = "(" + dList.text + ")"; 50 var int refLength = rule.name.length; 51 var List<RuleReference> references = EbnfAnalysisUtils.findReferences(rule); 52 //is the reference in the rule itself? 53 var boolean foundRule = false; 54 var EObject r = references.get(0) as EObject; 55 var Rule containingRule = null; 56 while (!foundRule) { 57 r = r.eContainer; 58 if (r instanceof Rule) { 59 containingRule = r as Rule; 60 foundRule = true; 61 } 62 } 63 if (!rule.equals(containingRule)) { 64 for (ruleRef : references) { 65 var ICompositeNode refNode = NodeModelUtils.findActualNodeFor(ruleRef); 66 var int refOffset = refNode.textRegion.offset; 67 68 xtextDocument.replace(refOffset, refLength, refText); 69 if (refOffset < offset) { 70 offset += refText.length - refLength; 43 //works but only in one file 44 @Fix(EbnfValidator.ruleReferencedOneDescription) 45 def void fixInlineRuleReferencedOnce(Issue issue, IssueResolutionAcceptor acceptor) { 46 acceptor.accept( 47 issue, 48 "Inline the rule", 49 "Delete the rule and replace its single reference by the rule's right side", 50 "upcase.png" 51 ) [ element, context | 52 var Rule rule = element as Rule; 53 var IXtextDocument xtextDocument = context.getXtextDocument(); 54 var ICompositeNode node = NodeModelUtils.findActualNodeFor(rule); 55 var String nodeText = node.text; 56 var int textLength = nodeText.length - 2; 57 var int offset = node.textRegion.offset; 58 //rename references 59 var ICompositeNode dList = NodeModelUtils.findActualNodeFor(rule.definitionList); 60 var String refText = "(" + dList.text + ")"; 61 var int refLength = rule.name.length; 62 var List<RuleReference> references = EbnfAnalysisUtils.findReferences(rule); 63 //********************************* 64 //is the reference in the rule itself? 65 var boolean foundRule = false; 66 var EObject r = references.get(0) as EObject; 67 var Rule containingRule = null; 68 while (!foundRule) { 69 r = r.eContainer; 70 if (r instanceof Rule) { 71 containingRule = r as Rule; 72 foundRule = true; 71 73 } 72 74 } 73 } 74 // delete rule 75 xtextDocument.replace(offset, textLength, ""); 76 ] 77 78 } 75 if (!rule.equals(containingRule)) { 76 77 for (ruleRef : references) { 78 var ICompositeNode refNode = NodeModelUtils.findActualNodeFor(ruleRef); 79 var int refOffset = refNode.textRegion.offset; 80 81 xtextDocument.replace(refOffset, refLength, refText); 82 if (refOffset < offset) { 83 offset += refText.length - refLength; 84 } 85 } 86 87 // delete rule 88 } 89 90 xtextDocument.replace(offset, textLength, ""); 91 ] 92 93 } 94 95 // // this is not working by unknown reasons 96 // @Fix(EbnfValidator.ruleReferencedOneDescription) 97 // def void fixInlineRuleReferencedOnce(Issue issue, IssueResolutionAcceptor acceptor) { 98 // acceptor.accept( 99 // issue, 100 // "Inline the rule", 101 // "Delete the rule and replace its single reference by the rule's right side", 102 // "upcase.png" 103 // ) [ element, context | 104 // var Rule rule = element as Rule; 105 // var DefinitionList dlist = rule.definitionList; 106 // var List<Rule> rules=EbnfAnalysisUtils.getAllRules(rule.eContainer().eContainer() as EtsiBnf); 107 // var SingleDefinition sDef = rules.get(1).definitionList.singleDefinition.get(1); 108 // dlist.singleDefinition.add(sDef); 109 // rule.name="bla"; 110 // ] 111 // 112 // } 79 113 80 114 //***************************************************************************************** 81 82 115 // @Fix(EbnfValidator.passthroughRuleDescription) 83 116 // def void fixRemovePassthroughRule(Issue issue, IssueResolutionAcceptor acceptor) { -
v2/trunk/de.ugoe.cs.swe.bnftools.ebnf/src-gen/de/ugoe/cs/swe/bnftools/serializer/EbnfSyntacticSequencer.java
r65 r66 76 76 * Syntax: 77 77 * ( 78 '+' | 79 '[' | 80 ')' | 78 81 '{' | 79 ' +' |80 ' }' |82 ']' | 83 '|' | 81 84 '*' | 82 ')' |83 '|' |84 '[' |85 85 '(' | 86 ' ]'86 '}' 87 87 )* 88 88 */ -
v2/trunk/de.ugoe.cs.swe.bnftools.ebnf/src-gen/de/ugoe/cs/swe/bnftools/validation/AbstractEbnfValidator.java
r65 r66 9 9 import org.eclipse.xtext.validation.ComposedChecks; 10 10 11 @ComposedChecks(validators= {org.eclipse.xtext.validation.ImportUriValidator.class , org.eclipse.xtext.validation.NamesAreUniqueValidator.class})11 @ComposedChecks(validators= {org.eclipse.xtext.validation.ImportUriValidator.class}) 12 12 public class AbstractEbnfValidator extends org.eclipse.xtext.validation.AbstractDeclarativeValidator { 13 13 -
v2/trunk/de.ugoe.cs.swe.bnftools.ebnf/src/de/ugoe/cs/swe/bnftools/GenerateEBNF.mwe2
r65 r66 74 74 fragment = validation.ValidatorFragment auto-inject { 75 75 composedCheck = "org.eclipse.xtext.validation.ImportUriValidator" 76 composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"76 // composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator" 77 77 } 78 78 … … 115 115 116 116 // provides the necessary bindings for java types integration 117 //fragment = types.TypesGeneratorFragment auto-inject {}117 //fragment = types.TypesGeneratorFragment auto-inject {} 118 118 119 119 // generates the required bindings only if the grammar inherits from Xbase -
v2/trunk/de.ugoe.cs.swe.bnftools.ebnf/src/de/ugoe/cs/swe/bnftools/validation/EbnfAnalysisUtils.java
r61 r66 5 5 6 6 import org.eclipse.xtext.EcoreUtil2; 7 import org.eclipse.xtext.resource.IReferenceDescription; 8 import org.eclipse.xtext.resource.IResourceDescription; 9 import org.eclipse.xtext.resource.IResourceDescriptions; 10 7 11 import de.ugoe.cs.swe.bnftools.ebnf.Atom; 8 12 import de.ugoe.cs.swe.bnftools.ebnf.DefinitionList; … … 83 87 return rules; 84 88 } 89 90 //---------------------------------------------------------------------------------------------------- 91 static public List<Rule> findReferences(Rule rule, IResourceDescriptions resourceDescriptions) { 92 List<Rule> ruleReferences = new ArrayList<Rule>(); 93 94 final String ruleURIF = rule.eResource().getURIFragment(rule); 95 96 for (IResourceDescription resourceDescription : resourceDescriptions 97 .getAllResourceDescriptions()) { 98 if (!resourceDescription.getURI().equals(rule.eResource().getURI())) 99 continue; 100 101 for (IReferenceDescription referenceDescription : resourceDescription 102 .getReferenceDescriptions()) { 103 if (ruleURIF.equals(referenceDescription.getTargetEObjectUri() 104 .fragment())) { 105 ruleReferences.add((Rule) rule.eResource().getEObject(referenceDescription.getTargetEObjectUri().fragment())); 106 } 107 108 } 109 } 110 return ruleReferences; 111 } 85 112 } -
v2/trunk/de.ugoe.cs.swe.bnftools.ebnf/src/de/ugoe/cs/swe/bnftools/validation/EbnfValidator.xtend
r65 r66 15 15 import de.ugoe.cs.swe.bnftools.ebnf.SingleDefinition 16 16 import java.util.ArrayList 17 import com.google.inject.Inject 18 import org.eclipse.xtext.resource.IResourceDescriptions 17 19 18 20 //import java.util.HashMap … … 27 29 class EbnfValidator extends AbstractEbnfValidator { 28 30 31 32 @Inject 33 IResourceDescriptions resourceDescriptions; 34 35 29 36 public static final String ruleReferencedOneDescription = "The rule is only referenced by one other rule"; 30 37 public static final String passthroughRuleDescription = "The rule is a passthrough rule"; … … 48 55 return; 49 56 50 var List<Rule Reference> references = EbnfAnalysisUtils.findReferences(rule);51 52 if (references.size ()== 1 && rule.rulenumber != 1) {57 var List<Rule> references = EbnfAnalysisUtils.findReferences(rule,resourceDescriptions); 58 var List<RuleReference> references1 = EbnfAnalysisUtils.findReferences(rule); 59 if (references.size+references1.size == 1 && rule.rulenumber != 1) { 53 60 warning(ruleReferencedOneDescription, EbnfPackage$Literals::RULE__NAME, ruleReferencedOneDescription, 54 61 rule.name); … … 172 179 173 180 var List<RuleReference> references = EbnfAnalysisUtils.findReferences(rule); 174 175 if ((references.size ()== 0) && (rule.getRulenumber() != 1))181 var List<Rule> references1 = EbnfAnalysisUtils.findReferences(rule,resourceDescriptions); 182 if ((references.size+references1.size == 0) && (rule.getRulenumber() != 1)) 176 183 warning(unusedRuleDescription, EbnfPackage$Literals::RULE__NAME, unusedRuleDescription, rule.name); 177 184 } … … 214 221 215 222 var List<RuleReference> references = EbnfAnalysisUtils.findReferences(rule); 216 223 var List<Rule> references1 = EbnfAnalysisUtils.findReferences(rule,resourceDescriptions); 217 224 if (EbnfAnalysisUtils.isPassthroughRule(rule) && rule.rulenumber != 1) { 218 if (references.size ()== 0) {225 if (references.size+references1.size == 0) { 219 226 warning(unreferencedPassthroughRuleDescription, EbnfPackage$Literals::RULE__NAME); 220 227 } else {
Note: See TracChangeset
for help on using the changeset viewer.