コード例 #1
0
 private INode findNode(
     EObject source, boolean sourceFound, INode root, Keyword keyword, int[] index) {
   if (sourceFound && root.getSemanticElement() != source) {
     return null;
   }
   if (root.getSemanticElement() == source) {
     sourceFound = true;
   }
   EObject grammarElement = root.getGrammarElement();
   // .equals or == does not work because sub grammars use their own
   // Modules with custom
   // grammarAccess instance and .equals is not overwritten.
   if (grammarElement instanceof Keyword
       && keyword.getValue().equals(((Keyword) grammarElement).getValue())) {
     if (index[0] != INSIGNIFICANT_INDEX) {
       index[0]--;
     }
     if (index[0] == 0 || index[0] == INSIGNIFICANT_INDEX) {
       return root;
     }
   }
   if (root instanceof ICompositeNode) {
     ICompositeNode node = (ICompositeNode) root;
     for (INode child : node.getChildren()) {
       INode result = findNode(source, sourceFound, child, keyword, index);
       if (result != null) {
         return result;
       }
     }
   }
   return null;
 }
コード例 #2
0
 @Override
 protected List<INode> getLocationNodes(EObject obj) {
   if (obj instanceof XMemberFeatureCall
       || obj instanceof XAssignment
       || obj instanceof XFeatureCall) {
     List<INode> resultNodes = Lists.newArrayList();
     final ICompositeNode startNode = findNodeFor(obj);
     boolean crossRefConsumed = false;
     for (INode child : startNode.getChildren()) {
       if (crossRefConsumed) {
         resultNodes.add(child);
       } else {
         EObject grammarElement = child.getGrammarElement();
         if (grammarElement instanceof CrossReference) {
           // We don't use the grammar access to be more robust against
           // overwriting grammars
           Assignment assignment = GrammarUtil.containingAssignment(grammarElement);
           if (XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE
               .getName()
               .equals(assignment.getFeature())) {
             crossRefConsumed = true;
             resultNodes.add(child);
           }
         }
       }
     }
     if (!resultNodes.isEmpty()) return resultNodes;
   }
   return super.getLocationNodes(obj);
 }