Changeset 17 in default for trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/utils/Utils.java
- Timestamp:
- 10/22/10 16:48:56 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/utils/Utils.java ¶
r5 r17 4 4 import java.util.List; 5 5 6 import org.eclipse.emf.common.util.EList;7 6 import org.eclipse.emf.ecore.EObject; 8 7 import org.eclipse.jface.text.BadLocationException; … … 22 21 import com.google.common.collect.Iterables; 23 22 23 import de.ugoe.cs.swe.bnftools.ebnf.BnfEntry; 24 import de.ugoe.cs.swe.bnftools.ebnf.DeltaEntry; 24 25 import de.ugoe.cs.swe.bnftools.ebnf.EtsiBnf; 26 import de.ugoe.cs.swe.bnftools.ebnf.MergeEntry; 25 27 import de.ugoe.cs.swe.bnftools.ebnf.Rule; 26 28 … … 29 31 static public NodeAdapter findNodeFromSelection( 30 32 final XtextEditor xtextEditor, ITextSelection mySelection) { 31 NodeAdapter node = null;32 33 if ((xtextEditor == null) || (xtextEditor.getDocument() == null)) 33 34 return null; 34 35 EtsiBnf root = (EtsiBnf) xtextEditor.getDocument().readOnly( 35 36 new RootEObjectFinder()); 36 EList<Rule> rules = root.getRule(); 37 for (int i = 0; i < rules.size(); i++) { 38 node = NodeUtil.getNodeAdapter(rules.get(i)); 39 if ((node.getParserNode().getOffset() <= mySelection.getOffset()) 40 && (mySelection.getOffset() <= node.getParserNode() 41 .getOffset() 42 + node.getParserNode().getLength())) { 43 return node; 37 38 NodeAdapter resultNode = null; 39 if (root.getBnfEntry() != null) { 40 System.out.println("bnf grammar!"); 41 for (int i=0; i < root.getBnfEntry().size(); i++) { 42 BnfEntry entry = root.getBnfEntry().get(i); 43 if (entry.getRule() != null) { 44 resultNode = findNodeInRule(entry.getRule(), mySelection); 45 if (resultNode != null) 46 return resultNode; 47 } 48 } 49 } else if (root.getDeltaEntry() != null) { 50 for (int i=0; i < root.getDeltaEntry().size(); i++) { 51 DeltaEntry entry = root.getDeltaEntry().get(i); 52 if (entry.getRule() != null) { 53 resultNode = findNodeInRule(entry.getRule(), mySelection); 54 if (resultNode != null) 55 return resultNode; 56 } 57 } 58 } else if (root.getMergeEntry() != null) { 59 for (int i=0; i < root.getMergeEntry().size(); i++) { 60 MergeEntry entry = root.getMergeEntry().get(i); 61 if (entry.getMergeRule() != null) { 62 // TODO: doesn't work here... 63 // resultNode = findNodeInRule(entry.getgetRule(), mySelection); 64 // if (resultNode != null) 65 // return resultNode; 66 } 44 67 } 45 68 } 69 70 return resultNode; 71 } 72 73 // -------------------------------------------------------------------------------- 74 75 static private NodeAdapter findNodeInRule(Rule rule, ITextSelection mySelection) { 76 NodeAdapter node = NodeUtil.getNodeAdapter(rule); 77 if ((node.getParserNode().getOffset() <= mySelection.getOffset()) 78 && (mySelection.getOffset() <= node.getParserNode() 79 .getOffset() 80 + node.getParserNode().getLength())) { 81 return node; 82 } 83 46 84 return null; 47 85 }
Note: See TracChangeset
for help on using the changeset viewer.