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

项目:n4js    文件:StableOrderSyntacticSequencerPDAProvider.java   
/**
 * Extracts the grammar from this transition or the NFA if this transition does not point to an
 * {@link AbstractElement}.
 */
private Grammar getGrammar(Nfa<ISynState> nfa) {
    AbstractElement grammarElement = getGrammarElement();
    if (grammarElement == null) {
        grammarElement = nfa.getStart().getGrammarElement();
        if (grammarElement == null) {
            grammarElement = nfa.getStop().getGrammarElement();
            if (grammarElement == null) {
                Iterator<ISynState> iter = nfa.getStart().getFollowers().iterator();
                while (grammarElement == null && iter.hasNext()) {
                    grammarElement = iter.next().getGrammarElement();
                }
            }
        }
    }
    Grammar grammar = GrammarUtil.getGrammar(grammarElement);
    return grammar;
}
项目:n4js    文件:InternalHighlightingParser.java   
@Override
protected void announce(Token start, Token stop, AbstractElement element) {
    if (start != null && start != Token.EOF_TOKEN) {
        if (start == stop) {
            announce(start, element);
        } else {
            CommonToken castedStart = (CommonToken) start;
            if (stop == null) { // possible error condition
                if (start.getTokenIndex() == state.lastErrorIndex) {
                    return;
                }
            }
            CommonToken castedEnd = (CommonToken) stop;
            Integer newType = rewriter.rewrite(castedStart, element);
            if (newType != null && castedEnd != null && castedEnd != Token.EOF_TOKEN) {
                LazyTokenStream castedInput = (LazyTokenStream) this.input;
                for (int i = castedStart.getTokenIndex() + 1; i < castedEnd.getTokenIndex(); i++) {
                    Token token = castedInput.get(i);
                    if (token.getChannel() != Token.HIDDEN_CHANNEL)
                        token.setType(newType);
                }
                castedEnd.setType(newType);
            }
        }
    }
}
项目: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);
                    }
                }
            }
        }
    }
}
项目:xtext-core    文件:TreeConstNFAToDot.java   
@Override
protected Node drawAbstractElementTree(AbstractElement grammarElement, Digraph digraph) {
    Node node = super.drawAbstractElementTree(grammarElement, digraph);
    TreeConstState nfas = nfaProvider.getNFA(grammarElement);

    for (TreeConstTransition outgoing : nfas.getOutgoing())
        digraph.add(drawFollowerEdge(grammarElement, outgoing, false));
    for (TreeConstTransition outgoingAfterReturn : nfas.getOutgoingAfterReturn())
        digraph.add(drawFollowerEdge(grammarElement, outgoingAfterReturn, true));

    if (nfas.getStatusInternal() != Status.ENABLED)
        node.setStyle("dashed");
    if (nfas.isEndState())
        node.put("peripheries", "2");
    setStatusStyle(node, nfas.getStatus());
    node.setLabel(nfas + node.get("label"));
    return node;
}
项目: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    文件:InsertionPointFinder.java   
public IHiddenRegion findInsertionPoint(ISerializationContext ctx, IEObjectRegion obj, AbstractElement ins) {
    ISerState insertionState = findState(ctx, ins);
    Set<AbstractElement> followers = collectAdjacent(insertionState, s -> s.getFollowers());
    Set<AbstractElement> precendents = collectAdjacent(insertionState, s -> s.getPrecedents());
    List<IAstRegion> regions = Lists.newArrayList(obj.getAstRegions());
    if (regions.isEmpty()) {
        return obj.getPreviousHiddenRegion();
    }
    if (followers.contains(regions.get(0).getGrammarElement())) {
        return obj.getPreviousHiddenRegion();
    }
    if (precendents.contains(regions.get(regions.size() - 1).getGrammarElement())) {
        return obj.getNextHiddenRegion();
    }
    for (int i = 0; i < regions.size() - 1; i++) {
        IAstRegion leading = regions.get(i);
        IAstRegion trailing = regions.get(i + 1);
        if (precendents.contains(leading.getGrammarElement()) && followers.contains(trailing.getGrammarElement())) {
            return leading.getNextHiddenRegion();
        }
    }
    return null;
}
项目:dsl-devkit    文件:FixedPartialParsingHelper.java   
protected boolean isInvalidLastChildNode(ICompositeNode candidate, final INode lastChild) {
  if (lastChild != null && lastChild.getSyntaxErrorMessage() != null) {
    EObject lastChildGrammarElement = lastChild.getGrammarElement();
    if (lastChildGrammarElement == null) {
      return true;
    }
    AbstractElement candidateElement = getCandidateElement(candidate.getGrammarElement());
    if (candidateElement != null) {
      if (isCalledBy(lastChildGrammarElement, candidateElement)) {
        while (candidate != null) {
          if (candidateElement != null && hasMandatoryFollowElements(candidateElement)) {
            return true;
          }
          candidate = candidate.getParent();
          if (candidate != null) {
            candidateElement = getCandidateElement(candidate.getGrammarElement());
          }
        }
      }
      return true;
    }
  }
  return false;
}
项目:xtext-core    文件:GrammarPDAProviderTest.java   
private void assertNoLeakedGrammarElements(final Grammar grammar, final Pda<ISerState, RuleCall> pda) {
  final Function1<ISerState, AbstractElement> _function = (ISerState it) -> {
    return it.getGrammarElement();
  };
  Iterable<AbstractElement> _filterNull = IterableExtensions.<AbstractElement>filterNull(IterableExtensions.<ISerState, AbstractElement>map(new NfaUtil().<ISerState>collect(pda), _function));
  for (final AbstractElement ele : _filterNull) {
    {
      final Grammar actual = GrammarUtil.getGrammar(ele);
      if ((actual != grammar)) {
        String _objPath = EmfFormatter.objPath(ele);
        String _plus = ("Element " + _objPath);
        String _plus_1 = (_plus + " leaked!");
        Assert.fail(_plus_1);
      }
    }
  }
}
项目:xtext-core    文件:BacktrackingSemanticSequencer.java   
protected void accept(TraceItem ti, SequenceFeeder feeder) {
    AbstractElement ele = ti.getState().getAssignedGrammarElement();
    if (ti.getState().getFeature().isMany()) {
        if (ele instanceof RuleCall)
            feeder.accept((RuleCall) ele, ti.getValue(), ti.getIndex(), ti.getNode());
        else if (ele instanceof Action)
            feeder.accept((Action) ele, (EObject) ti.getValue(), (ICompositeNode) ti.getNode());
        else if (ele instanceof Keyword)
            feeder.accept((Keyword) ele, ti.getValue(), ti.getIndex(), (ILeafNode) ti.getNode());
    } else {
        if (ele instanceof RuleCall)
            feeder.accept((RuleCall) ele, ti.getValue(), ti.getNode());
        else if (ele instanceof Action)
            feeder.accept((Action) ele, (EObject) ti.getValue(), (ICompositeNode) ti.getNode());
        else if (ele instanceof Keyword)
            feeder.accept((Keyword) ele, ti.getValue(), (ILeafNode) ti.getNode());
    }
}
项目:xtext-core    文件:AbstractAntlrGrammarGenerator.java   
protected String _ebnf2(final Alternatives it, final AntlrOptions options, final boolean supportActions) {
  StringConcatenation _builder = new StringConcatenation();
  {
    EList<AbstractElement> _elements = it.getElements();
    boolean _hasElements = false;
    for(final AbstractElement element : _elements) {
      if (!_hasElements) {
        _hasElements = true;
      } else {
        _builder.appendImmediate("\n    |", "");
      }
      String _ebnf = this.ebnf(element, options, supportActions);
      _builder.append(_ebnf);
    }
  }
  _builder.newLineIfNotEmpty();
  return _builder.toString();
}
项目:xtext-core    文件:RequiredRuleNameComputer.java   
protected String adjustRuleName(String ruleName, Param param) {
    AbstractElement elementToParse = param.elementToParse;
    Set<Parameter> context = getAssignedParameters(elementToParse, param.paramStack);
    if (!context.isEmpty()) {
        ParserRule containingRule = GrammarUtil.containingParserRule(elementToParse);
        String antlrRuleName = ruleNames.getAntlrRuleName(containingRule);
        int len = antlrRuleName.length();
        if (antlrRuleName.startsWith("rule")) {
            len += 2; // rule__XYZ instead of ruleXYZ
        }
        int config = getParameterConfig(context);
        String result = ruleNames.getAntlrRuleName(containingRule, config) + ruleName.substring(len);
        return result;
    }
    return ruleName;
}
项目: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-core    文件:ElementMatcherToDot.java   
protected Edge drawFollowerEdge(AbstractElement grammarElement, MatcherTransition transition, boolean isParent) {
    Edge edge = new Edge(grammarElement, transition.getTarget().getGrammarElement());
    //      if (transition.getPrecedence() > -1)
    //          edge.setLabel(String.valueOf(transition.getPrecedence()));
    List<String> label = Lists.newArrayList();
    if (!transition.getCommonPatterns().isEmpty())
        label.add("{" + toStr(transition.getCommonPatterns()) + "}");
    //      for (Map.Entry<AbstractRule, Set<IElementPattern>> e : transition.getExitPatterns().entrySet())
    //          label.add(e.getKey().getName() + ":{" + Joiner.on(", ").join(e.getValue()).replace("\\n", "\\\\n") + "}");
    for (Map.Entry<MatcherState, Set<IElementPattern>> e : transition.getGuardPatterns().entrySet())
        label.add(GrammarUtil.containingRule(e.getKey().getGrammarElement()).getName() + "-" + e.getKey() + ":{"
                + toStr(e.getValue()) + "}");
    if (label.size() > 0)
        edge.setLabel(Joiner.on("\\n").join(label));
    if (isParent)
        edge.put("arrowtail", "odot");
    if (transition.isRuleCall())
        edge.put("arrowhead", "onormalonormal");
    else
        edge.put("arrowhead", "onormal");
    return edge;
}
项目:xtext-core    文件:XtextLinkerTest.java   
@Test
public void testQualifiedRuleCall_03() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test 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 STRING: super;");
  _builder.newLine();
  _builder.append("terminal super: \'super\';");
  _builder.newLine();
  final String grammarAsString = _builder.toString();
  final XtextResource resource = this.getResourceFromString(grammarAsString);
  EObject _get = resource.getContents().get(0);
  Grammar grammar = ((Grammar) _get);
  AbstractRule _get_1 = grammar.getRules().get(1);
  final TerminalRule string = ((TerminalRule) _get_1);
  AbstractElement _alternatives = string.getAlternatives();
  final RuleCall callToSuper = ((RuleCall) _alternatives);
  Assert.assertEquals(IterableExtensions.<AbstractRule>last(grammar.getRules()), callToSuper.getRule());
}
项目:xtext-core    文件:XtextLinkerTest.java   
@Test
public void testQualifiedRuleCall_02() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test 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 STRING: super;");
  _builder.newLine();
  final String grammarAsString = _builder.toString();
  final XtextResource resource = this.getResourceFromString(grammarAsString);
  EObject _get = resource.getContents().get(0);
  Grammar grammar = ((Grammar) _get);
  AbstractRule _get_1 = grammar.getRules().get(1);
  final TerminalRule string = ((TerminalRule) _get_1);
  AbstractElement _alternatives = string.getAlternatives();
  final RuleCall callToSuper = ((RuleCall) _alternatives);
  Assert.assertEquals(GrammarUtil.findRuleForName(IterableExtensions.<Grammar>head(grammar.getUsedGrammars()), "STRING"), callToSuper.getRule());
}
项目:xtext-core    文件:AbstractAntlrGrammarGenerator.java   
protected String assignmentEbnf(final AbstractElement it, final Assignment assignment, final AntlrOptions options, final boolean supportActions) {
  if (it instanceof Alternatives) {
    return _assignmentEbnf((Alternatives)it, assignment, options, supportActions);
  } else if (it instanceof Group) {
    return _assignmentEbnf((Group)it, assignment, options, supportActions);
  } else if (it instanceof Action) {
    return _assignmentEbnf((Action)it, assignment, options, supportActions);
  } else if (it instanceof Assignment) {
    return _assignmentEbnf((Assignment)it, assignment, options, supportActions);
  } else if (it instanceof CrossReference) {
    return _assignmentEbnf((CrossReference)it, assignment, options, supportActions);
  } else if (it instanceof RuleCall) {
    return _assignmentEbnf((RuleCall)it, assignment, options, supportActions);
  } else if (it != null) {
    return _assignmentEbnf(it, assignment, options, supportActions);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, assignment, options, supportActions).toString());
  }
}
项目:xtext-core    文件:AbstractInternalAntlrParser.java   
@Override
public List<AbstractElement> getMissingMandatoryElements() {
    List<AbstractElement> result = missingMandatoryElements;
    if (result == null) {
        String predicate = getRecognitionException().toString();
        int idx = predicate.indexOf("grammarAccess");
        int lastIdx = predicate.lastIndexOf('(');
        predicate = predicate.substring(idx + "grammarAccess.".length(), lastIdx);
        String ruleMethodGetter = predicate.substring(0, predicate.indexOf('('));
        String elementGetter = predicate.substring(predicate.indexOf('.') + 1);
        IGrammarAccess grammarAccess = getGrammarAccess();
        Object ruleAccess = invokeNoArgMethod(ruleMethodGetter, grammarAccess);
        UnorderedGroup group = (UnorderedGroup) invokeNoArgMethod(elementGetter, ruleAccess);
        List<AbstractElement> missingElements = Lists.newArrayList();
        for(int i = 0; i < group.getElements().size(); i++) {
            AbstractElement element = group.getElements().get(i);
            if (!GrammarUtil.isOptionalCardinality(element) && unorderedGroupHelper.canSelect(group, i)) {
                missingElements.add(element);
            }
        }
        result = ImmutableList.copyOf(missingElements);
        missingMandatoryElements = result;
    }
    return result;
}
项目:pokemon-tcgo-deck-generator    文件:PkmntcgoParser.java   
@Override
protected String getRuleName(AbstractElement element) {
    if (nameMappings == null) {
        nameMappings = new HashMap<AbstractElement, String>() {
            private static final long serialVersionUID = 1L;
            {
                put(grammarAccess.getPokemonAccess().getAlternatives_1(), "rule__Pokemon__Alternatives_1");
                put(grammarAccess.getTrainerAccess().getAlternatives_1(), "rule__Trainer__Alternatives_1");
                put(grammarAccess.getNAMESTRINGAccess().getAlternatives(), "rule__NAMESTRING__Alternatives");
                put(grammarAccess.getDeckAccess().getGroup(), "rule__Deck__Group__0");
                put(grammarAccess.getPokemonAccess().getGroup(), "rule__Pokemon__Group__0");
                put(grammarAccess.getTrainerAccess().getGroup(), "rule__Trainer__Group__0");
                put(grammarAccess.getEnergyAccess().getGroup(), "rule__Energy__Group__0");
                put(grammarAccess.getCardAccess().getGroup(), "rule__Card__Group__0");
                put(grammarAccess.getDecksAccess().getDecksAssignment(), "rule__Decks__DecksAssignment");
                put(grammarAccess.getDeckAccess().getNameAssignment_2(), "rule__Deck__NameAssignment_2");
                put(grammarAccess.getDeckAccess().getPokemonAssignment_4(), "rule__Deck__PokemonAssignment_4");
                put(grammarAccess.getDeckAccess().getTrainerAssignment_5(), "rule__Deck__TrainerAssignment_5");
                put(grammarAccess.getDeckAccess().getEnergyAssignment_6(), "rule__Deck__EnergyAssignment_6");
                put(grammarAccess.getPokemonAccess().getPkmnCardsAssignment_3(), "rule__Pokemon__PkmnCardsAssignment_3");
                put(grammarAccess.getTrainerAccess().getTrainerCardsAssignment_3(), "rule__Trainer__TrainerCardsAssignment_3");
                put(grammarAccess.getEnergyAccess().getEnergyCardsAssignment_3(), "rule__Energy__EnergyCardsAssignment_3");
                put(grammarAccess.getCardAccess().getCountAssignment_0(), "rule__Card__CountAssignment_0");
                put(grammarAccess.getCardAccess().getNameAssignment_1(), "rule__Card__NameAssignment_1");
                put(grammarAccess.getCardAccess().getSetNrAssignment_2(), "rule__Card__SetNrAssignment_2");
                put(grammarAccess.getCardAccess().getSetAssignment_3(), "rule__Card__SetAssignment_3");
            }
        };
    }
    return nameMappings.get(element);
}
项目: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    文件:PatchedFollowElementComputer.java   
@Override
public void computeFollowElements(Collection<FollowElement> followElements,
        final Collection<AbstractElement> result) {
    computeFollowElements(followElements, new IFollowElementAcceptor() {
        @Override
        public void accept(AbstractElement element) {
            result.add(element);
        }
    });
}
项目:n4js    文件:PatchedFollowElementComputer.java   
private boolean isAlternativeWithEmptyPath(AbstractElement abstractElement) {
    if (abstractElement instanceof Alternatives) {
        Alternatives alternatives = (Alternatives) abstractElement;
        for (AbstractElement path : alternatives.getElements()) {
            if (GrammarUtil.isOptionalCardinality(path))
                return true;
        }
    }
    return false;
}
项目:n4js    文件:PatchedRequiredRuleNameComputer.java   
@Override
protected boolean isFiltered(Param param) {
    AbstractElement elementToParse = param.elementToParse;
    while (elementToParse != null) {
        if (isFiltered(elementToParse, param)) {
            return true;
        }
        elementToParse = getEnclosingSingleElementGroup(elementToParse);
    }
    return false;
}
项目:n4js    文件:PatchedRequiredRuleNameComputer.java   
/**
 * Return the containing group if it contains exactly one element.
 */
protected AbstractElement getEnclosingSingleElementGroup(AbstractElement elementToParse) {
    EObject container = elementToParse.eContainer();
    if (container instanceof Group) {
        if (((Group) container).getElements().size() == 1) {
            return (AbstractElement) container;
        }
    }
    return null;
}
项目:n4js    文件:CustomN4JSParser.java   
private AbstractElement unwrapSingleElementGroups(AbstractElement elementToParse) {
    if (elementToParse instanceof Group) {
        List<AbstractElement> elements = ((Group) elementToParse).getElements();
        if (elements.size() == 1) {
            return unwrapSingleElementGroups(elements.get(0));
        }
    }
    return elementToParse;
}
项目:n4js    文件:TokenTypeRewriter.java   
/**
 * Creates a new instance.
 */
@Inject
public TokenTypeRewriter(N4JSGrammarAccess ga) {
    ImmutableMap.Builder<AbstractElement, Integer> builder = ImmutableMap.builder();
    rewriteRegExLiterals(ga, builder);
    rewriteTemplateLiterals(ga, builder);
    rewriteAnnotationReferences(ga, builder);
    rewriteTypeReferences(ga, builder);
    rewriteIdentifiers(ga, builder);
    rewriteEnumLiterals(ga, builder);
    rewriteTypeVariables(ga, builder);
    rewriteNumberLiterals(ga, builder);
    rewriteKeywords(ga, builder);
    this.mapping = builder.build();
}
项目:n4js    文件:TokenTypeRewriter.java   
private static void rewriteAnnotationReferences(N4JSGrammarAccess ga,
        ImmutableMap.Builder<AbstractElement, Integer> builder) {
    builder.put(ga.getAnnotationNoAtSignAccess().getNameAssignment_0(),
            InternalN4JSParser.CommercialAtCommercialAt);
    builder.put(ga.getFunctionTypeExpressionOLDAccess().getThisKeyword_2_1(),
            InternalN4JSParser.CommercialAtCommercialAt);
    builder.put(ga.getPromisifyExpressionAccess().getPromisifyKeyword_0_0_2(),
            InternalN4JSParser.CommercialAtCommercialAt);
}
项目:n4js    文件:N4JSSyntaxValidator.java   
/**
 * Returns nodes which represent keywords and specified in keywords.
 *
 * @param keywords
 *            keywords in natural order used in Arrays#s
 */
protected List<ILeafNode> filterLeafsWithKeywordInsteadOfComma(EObject semanticElement, String stopAtKeyword,
        ICompositeNode node,
        final String... keywords) {
    List<ILeafNode> filteredLeaves = null;
    for (BidiTreeIterator<INode> iter = node.getAsTreeIterable().iterator(); iter.hasNext();) {
        INode child = iter.next();
        EObject childSemElement = child.getSemanticElement();
        if (child != node && childSemElement != null && childSemElement != semanticElement) {
            iter.prune();
        } else if (child instanceof ILeafNode) {
            ILeafNode leaf = (ILeafNode) child;
            EObject grammarElement = leaf.getGrammarElement();
            if (grammarElement instanceof Keyword) {
                String value = ((Keyword) grammarElement).getValue();
                if (stopAtKeyword.equals(value)) {
                    break;
                }
                if (Arrays.binarySearch(keywords, value) >= 0) {
                    if (grammarElement.eContainer() instanceof Alternatives) {
                        AbstractElement first = ((Alternatives) (grammarElement.eContainer())).getElements().get(0);
                        boolean inCommaAlternative = (first instanceof Keyword && ",".equals(((Keyword) first)
                                .getValue()));
                        if (inCommaAlternative) {
                            if (filteredLeaves == null) {
                                filteredLeaves = new ArrayList<>(5);
                            }
                            filteredLeaves.add(leaf);
                        }
                    }
                }
            }
        }
    }
    return filteredLeaves == null ? Collections.emptyList() : filteredLeaves;
}
项目:gemoc-studio    文件:DslParser.java   
@Override
protected String getRuleName(AbstractElement element) {
    if (nameMappings == null) {
        nameMappings = new HashMap<AbstractElement, String>() {
            private static final long serialVersionUID = 1L;
            {
                put(grammarAccess.getWORDAccess().getAlternatives_1_0(), "rule__WORD__Alternatives_1_0");
                put(grammarAccess.getVALUE_WORDAccess().getAlternatives_0(), "rule__VALUE_WORD__Alternatives_0");
                put(grammarAccess.getVALUE_WORDAccess().getAlternatives_1_0(), "rule__VALUE_WORD__Alternatives_1_0");
                put(grammarAccess.getVALUE_WORDAccess().getAlternatives_1_0_0(), "rule__VALUE_WORD__Alternatives_1_0_0");
                put(grammarAccess.getVALUE_WORDAccess().getAlternatives_1_1_0(), "rule__VALUE_WORD__Alternatives_1_1_0");
                put(grammarAccess.getDslAccess().getGroup(), "rule__Dsl__Group__0");
                put(grammarAccess.getEntryAccess().getGroup(), "rule__Entry__Group__0");
                put(grammarAccess.getWORDAccess().getGroup(), "rule__WORD__Group__0");
                put(grammarAccess.getWORDAccess().getGroup_1(), "rule__WORD__Group_1__0");
                put(grammarAccess.getVALUE_WORDAccess().getGroup(), "rule__VALUE_WORD__Group__0");
                put(grammarAccess.getVALUE_WORDAccess().getGroup_1(), "rule__VALUE_WORD__Group_1__0");
                put(grammarAccess.getVALUE_WORDAccess().getGroup_1_1(), "rule__VALUE_WORD__Group_1_1__0");
                put(grammarAccess.getMULTILINEAccess().getGroup(), "rule__MULTILINE__Group__0");
                put(grammarAccess.getMULTILINEAccess().getGroup_1(), "rule__MULTILINE__Group_1__0");
                put(grammarAccess.getDslAccess().getNameAssignment_5(), "rule__Dsl__NameAssignment_5");
                put(grammarAccess.getDslAccess().getEntriesAssignment_8(), "rule__Dsl__EntriesAssignment_8");
                put(grammarAccess.getEntryAccess().getKeyAssignment_1(), "rule__Entry__KeyAssignment_1");
                put(grammarAccess.getEntryAccess().getValueAssignment_5(), "rule__Entry__ValueAssignment_5");
            }
        };
    }
    return nameMappings.get(element);
}
项目:xtext-core    文件:CrossReferenceImpl.java   
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetTerminal(AbstractElement newTerminal, NotificationChain msgs) {
    AbstractElement oldTerminal = terminal;
    terminal = newTerminal;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, XtextPackage.CROSS_REFERENCE__TERMINAL, oldTerminal, newTerminal);
        if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
}
项目:xtext-core    文件:SyntacticSequencerPDAProvider.java   
protected boolean isMandatoryAbsorber(AbstractElement ele) {
    if (ele == null)
        return true;
    if (GrammarUtil.isAssigned(ele))
        return true;
    if (GrammarUtil.isAssignedAction(ele))
        return true;
    //      if (GrammarUtil.isDatatypeRuleCall(ele))
    //          return true;
    return false;
}
项目:xtext-core    文件:NoJdtTestLanguageParser.java   
private static void init(ImmutableMap.Builder<AbstractElement, String> builder, NoJdtTestLanguageGrammarAccess grammarAccess) {
    builder.put(grammarAccess.getGreetingAccess().getGroup(), "rule__Greeting__Group__0");
    builder.put(grammarAccess.getGreetingAccess().getGroup_2(), "rule__Greeting__Group_2__0");
    builder.put(grammarAccess.getModelAccess().getGreetingsAssignment(), "rule__Model__GreetingsAssignment");
    builder.put(grammarAccess.getGreetingAccess().getNameAssignment_1(), "rule__Greeting__NameAssignment_1");
    builder.put(grammarAccess.getGreetingAccess().getOtherAssignment_2_2(), "rule__Greeting__OtherAssignment_2_2");
}
项目:xtext-core    文件:ISyntacticSequencerPDAProvider.java   
public static Predicate<ISynState> element(final AbstractElement ele) {
    return new Predicate<ISynState>() {
        @Override
        public boolean apply(ISynState input) {
            return input.getGrammarElement() == ele;
        }
    };
}
项目:xtext-core    文件:AbstractNFAState.java   
protected void collectAllOutgoingTransitions() {
    if (filter(element))
        outgoing = outgoingRuleCalls = Collections.emptyList();
    else {
        outgoing = new ArrayList<T>();
        outgoingRuleCalls = new ArrayList<T>();
        collectOutgoing(element, Sets.<AbstractElement> newHashSet(), false, null);
        removeDuplicates(outgoing);
        removeDuplicates(outgoingRuleCalls);
    }
}
项目:xtext-core    文件:AssignmentFinder.java   
protected Set<AbstractElement> findValidAssignmentsForCrossRef(EObject semanticObj,
        Iterable<AbstractElement> assignedElements, EObject value, INode node) {
    Set<AbstractElement> result = Sets.newLinkedHashSet();
    for (AbstractElement ass : assignedElements) {
        CrossReference crossref = GrammarUtil.containingCrossReference(ass);
        EReference eref = GrammarUtil.getReference(crossref, semanticObj.eClass());
        if (EcoreUtil2.isAssignableFrom(eref.getEReferenceType(), value.eClass())
                && crossRefSerializer.isValid(semanticObj, crossref, value, node, null))
            result.add(ass);
    }
    return result;
}
项目:xtext-core    文件:TreeConstState.java   
public Status getStatus() {
    if (distances == null) {
        AbstractElement rootEle = containingRule(element).getAlternatives();
        builder.getState(rootEle).initStatus();
    }
    return getStatusInternal();
}
项目:xtext-core    文件:ContentAssistContextFactory.java   
protected Multimap<EObject, AbstractElement> computeCurrentModel(EObject currentModel, INode lastCompleteNode,
        Collection<AbstractElement> followElements) {
    Multimap<EObject, AbstractElement> result = LinkedHashMultimap.create();
    ICompositeNode currentParserNode = NodeModelUtils.getNode(currentModel);
    if (currentParserNode == null) {
        result.putAll(currentModel, followElements);
        return result;
    }
    EObject currentGrammarElement = currentParserNode.getGrammarElement();
    AbstractRule currentRule = getRule(currentGrammarElement);
    for (AbstractElement grammarElement : followElements) {
        AbstractRule rule = currentRule;
        ICompositeNode loopParserNode = currentParserNode;
        EObject loopLastGrammarElement = lastCompleteNode.getGrammarElement();
        while (!canBeCalledAfter(rule, loopLastGrammarElement, lastCompleteNode.getText(), grammarElement) && loopParserNode.getParent() != null) {
            loopLastGrammarElement = loopParserNode.getGrammarElement();
            loopParserNode = loopParserNode.getParent();
            while (loopParserNode.getGrammarElement() == null && loopParserNode.getParent() != null)
                loopParserNode = loopParserNode.getParent();
            EObject loopGrammarElement = loopParserNode.getGrammarElement();
            rule = getRule(loopGrammarElement);
        }
        EObject context = loopParserNode.getSemanticElement();
        result.put(context, grammarElement);
    }
    return result;
}
项目:dsl-devkit    文件:KeywordCollector.java   
/** {@inheritDoc} */
@Override
public Boolean caseGroup(final Group group) {
  for (final AbstractElement element : group.getElements()) {
    if (!doSwitch(element)) {
      return false;
    }
  }
  return true;
}