Java 类org.eclipse.xtext.AbstractRule 实例源码

项目:n4js    文件:CustomN4JSParser.java   
@Override
public void initializeFor(AbstractRule rule) {
    // TODO: GH-61.
    // Remove this function to see test errors in GHOLD-92-LINKING_DIAGNOSTIC_import_missing_B.n4js.xt
    /*
     * Comment by Sebastian: This is a super nasty side effect of some Xpect internals: Xpect uses own injectors
     * thus reflectively creates a new injector for the language. Effectively two injectors for N4JS exist at that
     * time. Both have their own 'singleton'-bindings, their own in-memory gramar representation etc. This is highly
     * problematic since all sorts of assumptions do no longer hold in such a setup. That is, especially the grammar
     * elements are supposed to be singletons and to be comparable by identity. Now we have each grammar element
     * twice in memory. Further there appears to be a blurry boundary between which object is obtain from which of
     * both injectors, so in the end, we face a parser instance that was produced by the real injector being used by
     * objects that were produced by the second injector. To be honest, I wonder wow this can even work. This is a
     * super critical misbehavior of Xpect from my point of view.
     */
    if (super.getEntryRule() == null) {
        super.initializeFor(rule);
    }
}
项目:n4js    文件:TokenTypeRewriter.java   
private static void rewriteKeywords(AbstractRule rule, N4JSKeywords keywords,
        ImmutableMap.Builder<AbstractElement, Integer> builder) {
    for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
        if (obj instanceof Keyword) {
            Keyword keyword = (Keyword) obj;
            Integer type = keywords.getTokenType(keyword);
            if (type != null) {
                if (keyword.eContainer() instanceof EnumLiteralDeclaration) {
                    builder.put((AbstractElement) keyword.eContainer(), type);
                } else {
                    builder.put(keyword, type);
                }
            }
        }
    }
}
项目:n4js    文件:TokenTypeRewriter.java   
private static void rewriteTypeReferences(N4JSGrammarAccess ga,
        ImmutableMap.Builder<AbstractElement, Integer> builder) {
    for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
        for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
            if (obj instanceof Assignment) {
                Assignment assignment = (Assignment) obj;
                AbstractElement terminal = assignment.getTerminal();
                if (terminal instanceof RuleCall) {
                    AbstractRule calledRule = ((RuleCall) terminal).getRule();
                    EClassifier classifier = calledRule.getType().getClassifier();
                    if (classifier instanceof EClass
                            && TypeRefsPackage.Literals.TYPE_REF.isSuperTypeOf((EClass) classifier)) {
                        builder.put(assignment, TYPE_REF_TOKEN);
                    }
                }
            }
        }
    }
}
项目:n4js    文件:TokenTypeRewriter.java   
private static void rewriteIdentifiers(N4JSGrammarAccess ga,
        ImmutableMap.Builder<AbstractElement, Integer> builder) {
    ImmutableSet<AbstractRule> identifierRules = ImmutableSet.of(
            ga.getBindingIdentifierRule(),
            ga.getIdentifierNameRule(),
            ga.getIDENTIFIERRule());
    for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
        for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
            if (obj instanceof Assignment) {
                Assignment assignment = (Assignment) obj;
                AbstractElement terminal = assignment.getTerminal();
                int type = InternalN4JSParser.RULE_IDENTIFIER;
                if (terminal instanceof CrossReference) {
                    terminal = ((CrossReference) terminal).getTerminal();
                    type = IDENTIFIER_REF_TOKEN;
                }
                if (terminal instanceof RuleCall) {
                    AbstractRule calledRule = ((RuleCall) terminal).getRule();
                    if (identifierRules.contains(calledRule)) {
                        builder.put(assignment, type);
                    }
                }
            }
        }
    }
}
项目:n4js    文件:TokenTypeRewriter.java   
private static void rewriteNumberLiterals(N4JSGrammarAccess ga,
        ImmutableMap.Builder<AbstractElement, Integer> builder) {
    for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
        for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
            if (obj instanceof Assignment) {
                Assignment assignment = (Assignment) obj;
                AbstractElement terminal = assignment.getTerminal();
                if (terminal instanceof RuleCall) {
                    AbstractRule calledRule = ((RuleCall) terminal).getRule();
                    EClassifier classifier = calledRule.getType().getClassifier();
                    if (classifier == EcorePackage.Literals.EBIG_DECIMAL) {
                        builder.put(assignment, NUMBER_LITERAL_TOKEN);
                    }
                }
            }
        }
    }
}
项目:n4js    文件:InternalSemicolonInjectingParser.java   
@SuppressWarnings("unchecked")
@Override
protected void registerRules(Grammar grammar) {
    if (ALL_RULES_FIELD != null) {
        try {
            Map<String, AbstractRule> localAllRules = (Map<String, AbstractRule>) ALL_RULES_FIELD.get(this);
            if (allRules == null) {
                super.registerRules(grammar);
                allRules = localAllRules;
            } else {
                localAllRules.putAll(allRules);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else {
        super.registerRules(grammar);
    }
}
项目:xtext-core    文件:OverriddenValueInspectorTest.java   
@Test
public void testUnassignedRule_04() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate metamodel \'foo.sample\'");
  _builder.newLine();
  _builder.append("First : Second (name=ID)? id=INT;");
  _builder.newLine();
  _builder.append("Second: id=INT (name=ID)?;");
  _builder.newLine();
  String grammarAsString = _builder.toString();
  final Grammar grammar = this.getGrammar(grammarAsString);
  AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "First");
  final ParserRule rule = ((ParserRule) _findRuleForName);
  this.validateRule(rule);
  Assert.assertEquals(this.warnings.toString(), 4, this.warnings.size());
}
项目:xtext-core    文件:AntlrGrammarGenUtil.java   
/**
 * @since 2.9
 */
@SuppressWarnings("unchecked")
public static <T extends EObject> T getOriginalElement(T obj) {
    if (obj instanceof AbstractRule) {
        AbstractRule result = RuleWithParameterValues.tryGetOriginalRule((AbstractRule) obj);
        if (result != null)
            return (T) result;
        return obj;
    }
    if (obj instanceof Grammar) {
        OriginalGrammar originalGrammar = OriginalGrammar.findInEmfObject(obj);
        return (T) originalGrammar.getOriginal();
    }
    if (obj instanceof AbstractElement) {
        OriginalElement original = OriginalElement.findInEmfObject(obj);
        return (T) original.getOriginal();
    }
    throw new IllegalArgumentException(String.valueOf(obj));
}
项目:xtext-core    文件:OverriddenValueInspectorTest.java   
@Test
public void testUnorderedGroup_03() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate metamodel \'foo.sample\'");
  _builder.newLine();
  _builder.append("Model : (a = ID & b = STRING)+;");
  _builder.newLine();
  String grammarAsString = _builder.toString();
  final Grammar grammar = this.getGrammar(grammarAsString);
  AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "Model");
  final ParserRule rule = ((ParserRule) _findRuleForName);
  this.validateRule(rule);
  Assert.assertEquals(this.warnings.toString(), 2, this.warnings.size());
}
项目:xtext-extras    文件:GrammarAccess.java   
/**
 * Returns the invocation of an element or rule accessor, including the .getType() call.
 * Example1: getFooRule().getType()
 * Example2: getBarRule().getFooAction().getType()
 */
public String gaTypeAccessor(final TypeRef ele) {
  String _switchResult = null;
  EObject _eContainer = ele.eContainer();
  final EObject cnt = _eContainer;
  boolean _matched = false;
  if (cnt instanceof AbstractElement) {
    _matched=true;
    String _gaRuleElementAccessor = this.gaRuleElementAccessor(((AbstractElement)cnt));
    _switchResult = (_gaRuleElementAccessor + ".getType()");
  }
  if (!_matched) {
    if (cnt instanceof AbstractRule) {
      _matched=true;
      String _gaRuleAccessor = this.gaRuleAccessor(((AbstractRule)cnt));
      _switchResult = (_gaRuleAccessor + ".getType()");
    }
  }
  if (!_matched) {
    String _name = ele.eContainer().eClass().getName();
    String _plus = ("<error: unknown type " + _name);
    _switchResult = (_plus + ">");
  }
  return _switchResult;
}
项目:xtext-extras    文件:Xtext2EcoreTransformerTest.java   
@Test
public void testMultiInheritance_01() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.enumrules.EnumRulesTestLanguage");
  _builder.newLine();
  _builder.append("import \'http://www.eclipse.org/xtext/common/JavaVMTypes\' as types");
  _builder.newLine();
  _builder.append("generate myDsl \"http://example.xtext.org/MyDsl\" as mydsl");
  _builder.newLine();
  _builder.append("Array returns mydsl::Array: componentType=ComponentType componentType=DeclaredType;");
  _builder.newLine();
  _builder.append("DeclaredType returns types::JvmDeclaredType: members+=DeclaredType;");
  _builder.newLine();
  _builder.append("ComponentType returns types::JvmComponentType: \'ignore\';");
  _builder.newLine();
  final String grammarAsString = _builder.toString();
  final XtextResource resource = this.getResourceFromString(grammarAsString);
  EObject _head = IterableExtensions.<EObject>head(resource.getContents());
  final Grammar grammar = ((Grammar) _head);
  EClassifier _classifier = IterableExtensions.<AbstractRule>head(grammar.getRules()).getType().getClassifier();
  EClass array = ((EClass) _classifier);
  Assert.assertEquals("JvmComponentType", this.<EStructuralFeature>feature(array, "componentType").getEType().getName());
}
项目:xtext-extras    文件:Xtext2EcoreTransformerTest.java   
@Test
public void testMultiInheritance_02() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.enumrules.EnumRulesTestLanguage");
  _builder.newLine();
  _builder.append("import \'http://www.eclipse.org/xtext/common/JavaVMTypes\' as types");
  _builder.newLine();
  _builder.append("generate myDsl \"http://example.xtext.org/MyDsl\" as mydsl");
  _builder.newLine();
  _builder.append("Array returns mydsl::Array: componentType=DeclaredType componentType=ComponentType;");
  _builder.newLine();
  _builder.append("DeclaredType returns types::JvmDeclaredType: members+=DeclaredType;");
  _builder.newLine();
  _builder.append("ComponentType returns types::JvmComponentType: \'ignore\';");
  _builder.newLine();
  final String grammarAsString = _builder.toString();
  final XtextResource resource = this.getResourceFromString(grammarAsString);
  EObject _head = IterableExtensions.<EObject>head(resource.getContents());
  final Grammar grammar = ((Grammar) _head);
  EClassifier _classifier = IterableExtensions.<AbstractRule>head(grammar.getRules()).getType().getClassifier();
  EClass array = ((EClass) _classifier);
  Assert.assertEquals("JvmComponentType", this.<EStructuralFeature>feature(array, "componentType").getEType().getName());
}
项目:xtext-core    文件:OverriddenValueInspectorTest.java   
@Test
public void testFragment_05() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate metamodel \'foo.sample\'");
  _builder.newLine();
  _builder.append("First : Named*;");
  _builder.newLine();
  _builder.append("fragment Named: name=ID;");
  _builder.newLine();
  String grammarAsString = _builder.toString();
  final Grammar grammar = this.getGrammar(grammarAsString);
  AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "First");
  final ParserRule rule = ((ParserRule) _findRuleForName);
  this.validateRule(rule);
  Assert.assertEquals(this.warnings.toString(), 1, this.warnings.size());
  AbstractRule _findRuleForName_1 = GrammarUtil.findRuleForName(grammar, "Named");
  final ParserRule fragment = ((ParserRule) _findRuleForName_1);
  this.validateRule(fragment);
  Assert.assertEquals(this.warnings.toString(), 0, this.warnings.size());
}
项目:xtext-core    文件:OverriddenValueInspectorTest.java   
@Test
public void testUnassignedRule_02() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate metamodel \'foo.sample\'");
  _builder.newLine();
  _builder.append("First : Second name=ID;");
  _builder.newLine();
  _builder.append("Second: name=ID;");
  _builder.newLine();
  String grammarAsString = _builder.toString();
  final Grammar grammar = this.getGrammar(grammarAsString);
  AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "First");
  final ParserRule rule = ((ParserRule) _findRuleForName);
  this.validateRule(rule);
  Assert.assertEquals(this.warnings.toString(), 2, this.warnings.size());
}
项目:dsl-devkit    文件:SingleLineCommentDocumentationProvider.java   
/** {@inheritDoc} */
@Override
public List<INode> getDocumentationNodes(final EObject object) {
  ICompositeNode node = NodeModelUtils.getNode(object);
  if (node == null) {
    return ImmutableList.of();
  }

  // get all single line comments before a non hidden leaf node
  List<INode> result = Lists.newArrayList();
  for (ILeafNode leaf : node.getLeafNodes()) {
    if (!leaf.isHidden()) {
      break;
    }
    EObject grammarElement = leaf.getGrammarElement();
    if (grammarElement instanceof AbstractRule && ruleName.equals(((AbstractRule) grammarElement).getName())) {
      String comment = leaf.getText();
      if (getCommentPattern().matcher(comment).matches() && !comment.matches(ignore)) {
        result.add(leaf);
      }
    }
  }

  return result;
}
项目:xtext-core    文件:ConcreteSyntaxConstraintProvider.java   
protected boolean ruleContainsAssignedAction(AbstractRule rule, Set<AbstractRule> visited) {
    if (!visited.add(rule))
        return false;
    TreeIterator<EObject> i = rule.eAllContents();
    while (i.hasNext()) {
        EObject o = i.next();
        if (o instanceof Action && ((Action) o).getFeature() != null)
            return true;
        else if (o instanceof Assignment)
            i.prune();
        else if (o instanceof RuleCall && isParserRule(((RuleCall) o).getRule())) {
            if (ruleContainsAssignedAction(((RuleCall) o).getRule(), visited))
                return true;
        }
    }
    return false;
}
项目:xtext-core    文件:BaseContentAssistParser.java   
protected Collection<FE> getFollowElements(InternalParser parser, AbstractElement entryPoint) {
    String ruleName = getRuleName(entryPoint);
    if (ruleName == null) {
        if (entryPoint instanceof RuleCall) {
            RuleCall call = (RuleCall) entryPoint;
            AbstractRule rule = call.getRule();
            if (rule instanceof ParserRule) {
                ruleName = getRuleNames().getAntlrRuleName(rule);
            }
        }
    }
    if (ruleName == null) {
        throw new IllegalStateException("entryPoint: " + entryPoint);
    }
    return getFollowElements(parser, ruleName);
}
项目:xtext-core    文件:AbstractAntlrGrammarGenerator.java   
protected String _assignmentEbnf(final RuleCall it, final Assignment assignment, final AntlrOptions options, final boolean supportActions) {
  String _switchResult = null;
  AbstractRule _rule = it.getRule();
  final AbstractRule rule = _rule;
  boolean _matched = false;
  if (rule instanceof EnumRule) {
    _matched=true;
  }
  if (!_matched) {
    if (rule instanceof ParserRule) {
      _matched=true;
    }
  }
  if (!_matched) {
    if (rule instanceof TerminalRule) {
      _matched=true;
    }
  }
  if (_matched) {
    _switchResult = this._grammarAccessExtensions.ruleName(rule);
  }
  if (!_matched) {
    throw new IllegalStateException(("assignmentEbnf is not supported for " + rule));
  }
  return _switchResult;
}
项目:xtext-core    文件:OverriddenValueInspectorTest.java   
@Test
public void testFragment_01() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate metamodel \'foo.sample\'");
  _builder.newLine();
  _builder.append("First : name=ID Named;");
  _builder.newLine();
  _builder.append("fragment Named: name=ID;");
  _builder.newLine();
  String grammarAsString = _builder.toString();
  final Grammar grammar = this.getGrammar(grammarAsString);
  AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "First");
  final ParserRule rule = ((ParserRule) _findRuleForName);
  this.validateRule(rule);
  Assert.assertEquals(this.warnings.toString(), 2, this.warnings.size());
  AbstractRule _findRuleForName_1 = GrammarUtil.findRuleForName(grammar, "Named");
  final ParserRule fragment = ((ParserRule) _findRuleForName_1);
  this.validateRule(fragment);
  Assert.assertEquals(this.warnings.toString(), 0, this.warnings.size());
}
项目:xtext-core    文件:OverriddenValueInspectorTest.java   
@Test
public void testBug306281_07() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate metamodel \'foo.sample\'");
  _builder.newLine();
  _builder.append("Model : name=ID (({Binary.left=current} operator = [Model] | {Binary.left=current} operator = [Model]) right=ID)* name=ID;");
  _builder.newLine();
  String grammarAsString = _builder.toString();
  final Grammar grammar = this.getGrammar(grammarAsString);
  AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "Model");
  final ParserRule rule = ((ParserRule) _findRuleForName);
  this.validateRule(rule);
  Assert.assertEquals(this.warnings.toString(), 2, this.warnings.size());
}
项目:xtext-core    文件:Linker.java   
private void ensureLinked(EObject obj, IDiagnosticProducer producer, ICompositeNode node,
        Set<EReference> handledReferences, boolean dontCheckParent) {
    for(INode abstractNode = node.getFirstChild(); abstractNode != null; abstractNode = abstractNode.getNextSibling()) {
        EObject grammarElement = abstractNode.getGrammarElement();
        if (grammarElement instanceof CrossReference) {
            CrossReference ref = (CrossReference) grammarElement;
            producer.setNode(abstractNode);
            ensureIsLinked(obj, abstractNode, ref, handledReferences, producer);
        } else if (grammarElement instanceof RuleCall && abstractNode instanceof ICompositeNode) {
            RuleCall ruleCall = (RuleCall) grammarElement;
            AbstractRule calledRule = ruleCall.getRule();
            if (calledRule instanceof ParserRule && ((ParserRule) calledRule).isFragment()) {
                ensureLinked(obj, producer, (ICompositeNode) abstractNode, handledReferences, true);
            }
        }
    }
    if (!dontCheckParent && shouldCheckParentNode(node)) {
        ensureLinked(obj, producer, node.getParent(), handledReferences, false);
    }
}
项目:dsl-devkit    文件:GrammarElementReferenceImpl.java   
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eUnset(int featureID)
{
  switch (featureID)
  {
    case FormatPackage.GRAMMAR_ELEMENT_REFERENCE__ASSIGNMENT:
      setAssignment((Assignment)null);
      return;
    case FormatPackage.GRAMMAR_ELEMENT_REFERENCE__RULE_CALL:
      setRuleCall((RuleCall)null);
      return;
    case FormatPackage.GRAMMAR_ELEMENT_REFERENCE__SELF:
      setSelf((AbstractRule)null);
      return;
    case FormatPackage.GRAMMAR_ELEMENT_REFERENCE__RULE:
      setRule((AbstractRule)null);
      return;
    case FormatPackage.GRAMMAR_ELEMENT_REFERENCE__KEYWORD:
      setKeyword((Keyword)null);
      return;
  }
  super.eUnset(featureID);
}
项目:xtext-core    文件:OverriddenValueInspectorTest.java   
@Test
public void testAssignedAction_01() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate metamodel \'foo.sample\'");
  _builder.newLine();
  _builder.append("First : Second {First.second=current} second=Second;");
  _builder.newLine();
  _builder.append("Second: name=ID;");
  _builder.newLine();
  String grammarAsString = _builder.toString();
  final Grammar grammar = this.getGrammar(grammarAsString);
  AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "First");
  final ParserRule rule = ((ParserRule) _findRuleForName);
  this.validateRule(rule);
  Assert.assertEquals(this.warnings.toString(), 2, this.warnings.size());
}
项目:xtext-core    文件:OverriddenValueInspectorTest.java   
@Test
public void testOptionalAction_02() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate metamodel \'foo.sample\'");
  _builder.newLine();
  _builder.append("First : Second ({First.second=current} id=INT)* name=ID;");
  _builder.newLine();
  _builder.append("Second: \'keyword\' name=ID;");
  _builder.newLine();
  String grammarAsString = _builder.toString();
  final Grammar grammar = this.getGrammar(grammarAsString);
  AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "First");
  final ParserRule rule = ((ParserRule) _findRuleForName);
  this.validateRule(rule);
  Assert.assertEquals(this.warnings.toString(), 2, this.warnings.size());
}
项目:xtext-core    文件:XtextValidationTest.java   
@Test public void testBug_282852_04() throws Exception {
    Grammar base = XtextFactory.eINSTANCE.createGrammar();
    Grammar child = XtextFactory.eINSTANCE.createGrammar();
    child.getUsedGrammars().add(base);
    AbstractRule ruleFoo = XtextFactory.eINSTANCE.createParserRule();
    ruleFoo.setName("Foo");
    base.getRules().add(ruleFoo);
    AbstractRule subRuleFoo = XtextFactory.eINSTANCE.createParserRule();
    subRuleFoo.setName("foo");
    child.getRules().add(subRuleFoo);

    XtextValidator validator = get(XtextValidator.class);
    configureValidator(validator, this, subRuleFoo);
    validator.checkRuleName(subRuleFoo);
    assertEquals("A rule's name has to be unique even case insensitive. A used grammar contains another rule 'Foo'.", lastMessage);
}
项目:dsl-devkit    文件:GrammarElementReferenceImpl.java   
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eSet(int featureID, Object newValue)
{
  switch (featureID)
  {
    case FormatPackage.GRAMMAR_ELEMENT_REFERENCE__ASSIGNMENT:
      setAssignment((Assignment)newValue);
      return;
    case FormatPackage.GRAMMAR_ELEMENT_REFERENCE__RULE_CALL:
      setRuleCall((RuleCall)newValue);
      return;
    case FormatPackage.GRAMMAR_ELEMENT_REFERENCE__SELF:
      setSelf((AbstractRule)newValue);
      return;
    case FormatPackage.GRAMMAR_ELEMENT_REFERENCE__RULE:
      setRule((AbstractRule)newValue);
      return;
    case FormatPackage.GRAMMAR_ELEMENT_REFERENCE__KEYWORD:
      setKeyword((Keyword)newValue);
      return;
  }
  super.eSet(featureID, newValue);
}
项目:n4js    文件:GrammarLinter.java   
private void printKeywordsOnlyInDatatypeRules() {
    Grammar grammar = grammarAccess.getGrammar();
    ListMultimap<String, Keyword> allKeywords = getAllKeywords(grammar);
    System.out.println("Keywords which do not occur in production rules: ");
    outer: for (Collection<Keyword> chunk : allKeywords.asMap().values()) {
        for (Keyword keyword : chunk) {
            AbstractRule rule = EcoreUtil2.getContainerOfType(keyword, AbstractRule.class);
            if (!GrammarUtil.isDatatypeRule(rule)) {
                continue outer;
            }
        }
        System.out.println("  " + ((List<Keyword>) chunk).get(0).getValue());
    }
    System.out.println();
}
项目:n4js    文件:GrammarPrettyPrinter.java   
@Override
protected String getCrossReferenceNameFromScope(EObject semanticObject, CrossReference crossref,
        EObject target, IScope scope, Acceptor errors) {
    if (target instanceof AbstractRule) {
        return ((AbstractRule) target).getName();
    }
    if (target instanceof ENamedElement) {
        return ((ENamedElement) target).getName();
    }
    return super.getCrossReferenceNameFromScope(semanticObject, crossref, target, scope, errors);
}
项目:n4js    文件:IdentifierDelegateValueConverter.java   
@Override
protected void processElement(AbstractElement element, AbstractRule rule, Builder<String> result) {
    if (element instanceof RuleCall) {
        AbstractRule calledRule = ((RuleCall) element).getRule();
        if (calledRule instanceof TerminalRule) {
            super.processElement(element, rule, result);
        } else {
            processElement(calledRule.getAlternatives(), rule, result);
        }
    } else {
        super.processElement(element, rule, result);
    }
}
项目:n4js    文件:N4JSLinker.java   
/**
 * Installs proxies for all non containment references and only if the node representing the EObject that contains
 * the cross reference has got leaf nodes (as a leaf node represents the cross reference).
 *
 * @param resource
 *            the N4JSResource
 * @param obj
 *            the EObject containing the cross reference
 * @param producer
 *            the error/warning producer
 * @param parentNode
 *            the node representing obj inside the node model
 */
private void installProxies(N4JSResource resource, EObject obj, IDiagnosticProducer producer,
        ICompositeNode parentNode, boolean dontCheckParent) {
    final EClass eClass = obj.eClass();
    if (eClass.getEAllReferences().size() - eClass.getEAllContainments().size() == 0)
        return;

    for (INode node = parentNode.getFirstChild(); node != null; node = node.getNextSibling()) {
        EObject grammarElement = node.getGrammarElement();
        if (grammarElement instanceof CrossReference && hasLeafNodes(node)) {
            producer.setNode(node);
            CrossReference crossReference = (CrossReference) grammarElement;
            final EReference eRef = GrammarUtil.getReference(crossReference, eClass);
            if (eRef == null) {
                ParserRule parserRule = GrammarUtil.containingParserRule(crossReference);
                final String feature = GrammarUtil.containingAssignment(crossReference).getFeature();
                throw new IllegalStateException("Couldn't find EReference for crossreference '" + eClass.getName()
                        + "::" + feature + "' in parser rule '" + parserRule.getName() + "'.");
            }
            createAndSetProxy(resource, obj, node, eRef, crossReference, producer);
            afterCreateAndSetProxy(obj, node, eRef, crossReference, producer);
        } else if (grammarElement instanceof RuleCall && node instanceof ICompositeNode) {
            RuleCall ruleCall = (RuleCall) grammarElement;
            AbstractRule calledRule = ruleCall.getRule();
            if (calledRule instanceof ParserRule && ((ParserRule) calledRule).isFragment()) {
                installProxies(resource, obj, producer, (ICompositeNode) node, true);
            }
        }
    }
    if (!dontCheckParent && shouldCheckParentNode(parentNode)) {
        installProxies(resource, obj, producer, parentNode.getParent(), dontCheckParent);
    }
}
项目:xtext-core    文件:SerializerFragment2.java   
private CharSequence unassignedCalledTokenRuleName(final AbstractRule rule) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("get");
  String _name = rule.getName();
  _builder.append(_name);
  _builder.append("Token");
  return _builder;
}
项目:xtext-core    文件:GrammarAccessFragment2.java   
protected StringConcatenationClient initializer(final AbstractRule it) {
  if (it instanceof EnumRule) {
    return _initializer((EnumRule)it);
  } else if (it instanceof ParserRule) {
    return _initializer((ParserRule)it);
  } else if (it instanceof TerminalRule) {
    return _initializer((TerminalRule)it);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it).toString());
  }
}
项目:xtext-core    文件:GrammarElementTitleSwitch.java   
@Override
public String caseAbstractRule(AbstractRule object) {
    String classifier = object.getType().getClassifier().getName();
    if (object.getName().equals(classifier))
        return object.getName() + ":";
    return object.getName() + " returns " + classifier + ":";
}
项目:xtext-extras    文件:XbaseFormatter2.java   
protected AbstractRule binaryOperationPrecedence(final EObject op) {
  final INode node = this._nodeModelAccess.nodeForFeature(op, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE);
  if (((node != null) && (node.getGrammarElement() instanceof CrossReference))) {
    EObject _grammarElement = node.getGrammarElement();
    final AbstractElement terminal = ((CrossReference) _grammarElement).getTerminal();
    if ((terminal instanceof RuleCall)) {
      return ((RuleCall)terminal).getRule();
    }
  }
  return null;
}
项目:xtext-extras    文件:XbaseIdeContentProposalProvider.java   
@Override
protected void _createProposals(final RuleCall ruleCall, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  AbstractRule _rule = ruleCall.getRule();
  boolean _matched = false;
  ParserRule _xExpressionRule = this._xbaseGrammarAccess.getXExpressionRule();
  if (Objects.equal(_rule, _xExpressionRule)) {
    _matched=true;
    if (((ruleCall.eContainer() instanceof Group) && Objects.equal(GrammarUtil.containingRule(ruleCall).getName(), "XParenthesizedExpression"))) {
      this.createLocalVariableAndImplicitProposals(context.getCurrentModel(), IExpressionScope.Anchor.WITHIN, context, acceptor);
    }
  }
  if (!_matched) {
    super._createProposals(ruleCall, context, acceptor);
  }
}
项目:xtext-core    文件:GrammarAccessExtensions.java   
/**
 * Returns the invocation of an element or rule accessor.
 * Example1: getFooRule()
 * Example2: getBarRule().getFooAction()
 */
public String gaAccessor(final EObject ele) {
  String _switchResult = null;
  boolean _matched = false;
  if (ele instanceof AbstractElement) {
    _matched=true;
    _switchResult = this.gaRuleElementAccessor(((AbstractElement)ele));
  }
  if (!_matched) {
    if (ele instanceof AbstractRule) {
      _matched=true;
      _switchResult = this.gaRuleAccessor(((AbstractRule)ele));
    }
  }
  if (!_matched) {
    if (ele instanceof Parameter) {
      _matched=true;
      _switchResult = this.gaRuleParameterAccessor(((Parameter)ele));
    }
  }
  if (!_matched) {
    String _name = ele.eClass().getName();
    String _plus = ("<error: unknown type " + _name);
    _switchResult = (_plus + ">");
  }
  return _switchResult;
}
项目:xtext-extras    文件:PackratParserGenUtil.java   
public static List<AbstractRule> getConflictingLexerRules(final Keyword keyword, final Grammar grammar) {
    AbstractRule rule = GrammarUtil.findRuleForName(grammar, "ID");
    if (rule != null) {
        // TODO SZ: use interpreter
        final StringWithOffset input = new StringWithOffset(keyword.getValue());
        if (new TerminalsIDConsumer(new MyTerminalConsumerConfiguration(input)).consume() == ConsumeResult.SUCCESS) {
            return Collections.singletonList(rule);
        }
    }
    return Collections.emptyList();
}
项目:xtext-extras    文件:PackratParserGenUtil.java   
public static List<String> getConflictingKeywords(final AbstractElement element, final Grammar grammar) {
    if (element instanceof RuleCall) {
        AbstractRule rule = ((RuleCall) element).getRule();
        if (rule instanceof TerminalRule)
            return getConflictingKeywordsImpl(grammar, (TerminalRule) rule);
    }
    return null;
}
项目:xtext-core    文件:AbstractAntlrGrammarWithActionsGenerator.java   
protected CharSequence compileInitUnorderedGroups(final AbstractRule it, final AntlrOptions options) {
  if (it instanceof ParserRule) {
    return _compileInitUnorderedGroups((ParserRule)it, options);
  } else if (it != null) {
    return _compileInitUnorderedGroups(it, options);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, options).toString());
  }
}
项目:xtext-core    文件:SuperCallScopeTest.java   
@Test
public void testGetAllElements_02() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test.Lang with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate test \'http://test\'");
  _builder.newLine();
  _builder.append("Rule: name=ID;");
  _builder.newLine();
  _builder.append("terminal ID: super;");
  _builder.newLine();
  final String grammarAsString = _builder.toString();
  EObject _model = this.getModel(grammarAsString);
  final Grammar grammar = ((Grammar) _model);
  AbstractRule _last = IterableExtensions.<AbstractRule>last(grammar.getRules());
  final SuperCallScope scope = new SuperCallScope(_last);
  this.assertElementNames(scope.getAllElements(), 
    "Lang.Rule", "test.Lang.Rule", 
    "Lang.ID", "test.Lang.ID", 
    "super", 
    "super.ID", "Terminals.ID", "org.eclipse.xtext.common.Terminals.ID", 
    "super.INT", "Terminals.INT", "org.eclipse.xtext.common.Terminals.INT", 
    "super.STRING", "Terminals.STRING", "org.eclipse.xtext.common.Terminals.STRING", 
    "super.ML_COMMENT", "Terminals.ML_COMMENT", "org.eclipse.xtext.common.Terminals.ML_COMMENT", 
    "super.SL_COMMENT", "Terminals.SL_COMMENT", "org.eclipse.xtext.common.Terminals.SL_COMMENT", 
    "super.WS", "Terminals.WS", "org.eclipse.xtext.common.Terminals.WS", 
    "super.ANY_OTHER", "Terminals.ANY_OTHER", "org.eclipse.xtext.common.Terminals.ANY_OTHER");
}