@Override
 public Boolean caseAssignment(Assignment object) {
   if (GrammarUtil.isMultipleAssignment(object)) return Boolean.FALSE;
   checkAssignment(object, object.getFeature());
   if (GrammarUtil.isMultipleCardinality(object)) checkAssignment(object, object.getFeature());
   return Boolean.FALSE;
 }
 @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);
 }
 public String localVar(final Assignment it, final AbstractElement terminal) {
   String _feature = it.getFeature();
   String _plus = ("lv_" + _feature);
   String _plus_1 = (_plus + "_");
   ParserRule _containingParserRule = GrammarUtil.containingParserRule(it);
   List<AbstractElement> _contentsAsList = this.contentsAsList(_containingParserRule);
   int _indexOf = _contentsAsList.indexOf(it);
   String _plus_2 = (_plus_1 + Integer.valueOf(_indexOf));
   String _plus_3 = (_plus_2 + "_");
   List<EObject> _eAllContentsAsList = EcoreUtil2.eAllContentsAsList(it);
   int _indexOf_1 = _eAllContentsAsList.indexOf(terminal);
   return (_plus_3 + Integer.valueOf(_indexOf_1));
 }
 public Set<QualifiedName> getImportedNames(XtextResource resource) {
   XPackage xPackage = getXPackage(resource);
   String packageName = xPackage.getName();
   List<String> implicitPackageImports = newArrayList(packageName, "java.lang");
   Set<QualifiedName> importedNames = newLinkedHashSet();
   Map<String, QualifiedName> implicitAliases = getImplicitAliases();
   for (INode node : XcoreUtil.importableCrossReferences(xPackage)) {
     CrossReference grammarElement = (CrossReference) node.getGrammarElement();
     EObject container = grammarElement.eContainer();
     if (container instanceof Assignment) {
       String name = node.getText().trim();
       if (name.endsWith("::")) {
         name = name.substring(0, name.length() - 2);
       }
       QualifiedName actualQualifiedName = nameConverter.toQualifiedName(name);
       Assignment assignment = (Assignment) container;
       String feature = assignment.getFeature();
       EObject semanticObject = NodeModelUtils.findActualSemanticObjectFor(node);
       EStructuralFeature eStructuralFeature =
           semanticObject.eClass().getEStructuralFeature(feature);
       if (!eStructuralFeature.isMany()) {
         EObject eCrossReference = (EObject) semanticObject.eGet(eStructuralFeature);
         EObject eContainer = eCrossReference.eContainer();
         if (eContainer != xPackage
             && !(eContainer instanceof XPackage
                 && "xcore.lang".equals(((XPackage) eContainer).getName()))
             && !(eContainer instanceof GenPackage
                 && packageName.equals(((GenPackage) eContainer).getQualifiedPackageName()))
             && !(eCrossReference instanceof JvmDeclaredType
                 && implicitPackageImports.contains(
                     ((JvmDeclaredType) eCrossReference).getPackageName()))) {
           QualifiedName fullyQualifiedName = nameProvider.getFullyQualifiedName(eCrossReference);
           if (fullyQualifiedName != null
               && !actualQualifiedName.equals(fullyQualifiedName)
               && !fullyQualifiedName.equals(implicitAliases.get(name))) {
             importedNames.add(fullyQualifiedName);
           }
         }
       } else {
         throw new RuntimeException("Not expecting multi-valued cross references in these models");
       }
     } else {
       throw new RuntimeException(
           "Expecting all cross references to be part of an assignment in these models");
     }
   }
   return importedNames;
 }
Exemple #5
0
 protected EStructuralFeatureAndEObject find(XtextResource resource, int offset) {
   INode leaf =
       NodeModelUtils.findLeafNodeAtOffset(resource.getParseResult().getRootNode(), offset);
   NodeIterator ni = null;
   while (ni == null || ni.hasNext()) {
     INode next = ni == null ? leaf : ni.next();
     if (ni == null) ni = new NodeIterator(leaf);
     EObject object = NodeModelUtils.findActualSemanticObjectFor(next);
     INode current = next;
     do {
       Assignment ass = GrammarUtil.containingAssignment(current.getGrammarElement());
       if (ass != null) {
         EStructuralFeature feat = object.eClass().getEStructuralFeature(ass.getFeature());
         if (feat != null && matches(object, feat)) return create(object, feat);
       }
       current = current.getParent();
     } while (current != null && object == NodeModelUtils.findActualSemanticObjectFor(current));
   }
   throw new RuntimeException("No EStructuralFeature found at offset " + offset);
 }