Java 类org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch 实例源码

项目:xtext-core    文件:SerializerPDA.java   
@Override
public String toString() {
    GrammarElementTitleSwitch fmt = new GrammarElementTitleSwitch().hideCardinality().showQualified()
            .showAssignments();
    switch (type) {
        case ELEMENT:
            return fmt.apply(grammarElement);
        case POP:
            return "<<" + fmt.apply(grammarElement);
        case PUSH:
            return ">>" + fmt.apply(grammarElement);
        case START:
            return "start";
        case STOP:
            return "stop";
    }
    return "";
}
项目:xtext-core    文件:SyntacticSequencerDiagnosticProvider.java   
@Override
public ISerializationDiagnostic createInvalidFollowingAbsorberDiagnostic(ISerializationContext context, EObject semanticObject,
        ISynAbsorberState from, AbstractElement to) {
    GrammarElementTitleSwitch fmt = new GrammarElementTitleSwitch().showAssignments().showQualified();
    String fromName = from.toString(fmt);
    String toName = to == null ? "stop" : fmt.doSwitch(to);

    List<String> targets = Lists.newArrayList();
    for (ISynTransition trans : from.getOutTransitions())
        targets.add(trans.getTarget().toString(fmt));

    StringBuilder msg = new StringBuilder();
    msg.append("State '" + toName + "' may not follow '" + fromName + "'.\n");
    msg.append("Valid followers are: " + Joiner.on(", ").join(targets));

    return new SerializationDiagnostic(INVALID_FOLLOWING_ABSORBER, semanticObject, context,
            grammarAccess.getGrammar(), msg.toString());
}
项目:xtext-core    文件:AbstractFormatter2.java   
public ITextReplacer createCommentReplacer(IComment comment) {
    EObject grammarElement = comment.getGrammarElement();
    if (grammarElement instanceof AbstractRule) {
        String ruleName = ((AbstractRule) grammarElement).getName();
        if (ruleName.startsWith("ML"))
            return new MultilineCommentReplacer(comment, '*');
        if (ruleName.startsWith("SL")) {
            if (comment.getLineRegions().get(0).getIndentation().getLength() > 0)
                return new SinglelineDocCommentReplacer(comment, "//");
            else
                return new SinglelineCodeCommentReplacer(comment, "//");
        }
    }
    String elementName = new GrammarElementTitleSwitch().showQualified().showRule().doSwitch(grammarElement);
    throw new IllegalStateException("No " + ITextReplacer.class.getSimpleName() + " configured for " + elementName);
}
项目:xtext-core    文件:HiddenTokenSequencerTest.java   
@SuppressWarnings("deprecation")
private List<String> getNodeSequence(EObject model) {
    List<String> result = Lists.newArrayList();
    GrammarElementTitleSwitch titleSwitch = new GrammarElementTitleSwitch().showAssignments();
    //      System.out.println(NodeModelUtils.compactDump(NodeModelUtils.findActualNodeFor(model), true));
    org.eclipse.xtext.serializer.sequencer.EmitterNodeIterator ni = 
            new org.eclipse.xtext.serializer.sequencer.EmitterNodeIterator(NodeModelUtils.findActualNodeFor(model), null, true, true);
    while (ni.hasNext()) {
        INode next = ni.next();
        if (next instanceof ILeafNode)
            result.add(titleSwitch.doSwitch(next.getGrammarElement()) + " -> " + next.getText());
        if (next instanceof ICompositeNode)
            result.add(titleSwitch.doSwitch(next.getGrammarElement()));
    }
    return result;
}
项目:xtext-core    文件:ContextTypePDAProviderTest.java   
protected String getParserRule(String body) throws Exception {
    Grammar grammar = (Grammar) getModel(HEADER + body);
    // drawGrammar("pdf/" + getName(), grammar);
    List<String> result = Lists.newArrayList();
    PdaListFormatter<ISerState, RuleCall> formatter = new PdaListFormatter<ISerState, RuleCall>();
    formatter.setStateFormatter(new ToStr());
    formatter.setStackitemFormatter(new GrammarElementTitleSwitch().showAssignments().hideCardinality());
    formatter.sortFollowers();
    IContextTypePDAProvider typePDAProvider = get(IContextTypePDAProvider.class);
    SerializationContextMap<Pda<ISerState, RuleCall>> pdas = typePDAProvider.getContextTypePDAs(grammar);
    for (Entry<Pda<ISerState, RuleCall>> ctx : pdas.sortedCopy().values()) {
        result.add(Joiner.on(", ").join(ctx.getContexts()) + ":");
        result.add("  " + formatter.format(ctx.getValue()).replace("\n", "\n  "));
    }
    return Joiner.on("\n").join(result);
}
项目:xtext-core    文件:ContextPDAProviderTest.java   
protected String getParserRule(String body) throws Exception {
    Grammar grammar = (Grammar) getModel(HEADER + body);
    List<String> result = Lists.newArrayList();
    PdaListFormatter<ISerState, RuleCall> formatter = new PdaListFormatter<ISerState, RuleCall>();
    formatter.setStateFormatter(new ToStr());
    formatter.setStackitemFormatter(new GrammarElementTitleSwitch().showAssignments().hideCardinality());
    formatter.sortFollowers();
    IContextPDAProvider pdaProvider = get(IContextPDAProvider.class);
    SerializationContextMap<Pda<ISerState, RuleCall>> pdas = pdaProvider.getContextPDAs(grammar);
    for (Entry<Pda<ISerState, RuleCall>> ctx : pdas.sortedCopy().values()) {
        result.add(Joiner.on(", ").join(ctx.getContexts()) + ":");
        Pda<ISerState, RuleCall> pda = ctx.getValue();
        result.add("  " + formatter.format(pda).replace("\n", "\n  "));

        // StackTraceElement ele = Thread.currentThread().getStackTrace()[2];
        // String name = getClass().getSimpleName() + "_" + ele.getMethodName() + "_" + ctx.getSecond() + ".pdf";
        // new PdaToDot<ISerState, RuleCall>().draw(pda, "dot/" + name, "-T pdf");
    }
    return Joiner.on("\n").join(result);
}
项目:xtext-core    文件:SyntacticSequencerTest.java   
@SuppressWarnings("deprecation")
private List<String> getNodeSequence(EObject model) {
    List<String> result = Lists.newArrayList();
    GrammarElementTitleSwitch titleSwitch = new GrammarElementTitleSwitch().showAssignments();
    org.eclipse.xtext.serializer.sequencer.EmitterNodeIterator ni = 
            new org.eclipse.xtext.serializer.sequencer.EmitterNodeIterator(NodeModelUtils.findActualNodeFor(model));
    while (ni.hasNext()) {
        INode next = ni.next();
        EObject ele = next.getGrammarElement() instanceof CrossReference ? ((CrossReference) next
                .getGrammarElement()).getTerminal() : next.getGrammarElement();
        if (next instanceof ILeafNode || GrammarUtil.isDatatypeRuleCall(ele))
            result.add(titleSwitch.doSwitch(ele) + " -> " + next.getText().trim());
        else if (next instanceof ICompositeNode)
            result.add(titleSwitch.doSwitch(ele));
    }
    return result;
}
项目:xtext-core    文件:GrammarConstraintProvider.java   
@Override
public String toString() {
    GrammarElementTitleSwitch t2s = new GrammarElementTitleSwitch().hideCardinality().showActionsAsRuleCalls().showAssignments();
    ProductionFormatter<IConstraintElement, AbstractElement> formatter = new ProductionFormatter<IConstraintElement, AbstractElement>();
    formatter.setTokenToString(t2s);
    return formatter.format(new ConstraintElementProduction(getContainingConstraint()), this, true);
}
项目:xtext-core    文件:GrammarAlias.java   
@Override
public String toString() {
    GrammarElementTitleSwitch t2s = new GrammarElementTitleSwitch().showAssignments().hideCardinality();
    Function<Production<AbstractElementAlias, AbstractElement>, String> formatter2 = new ProductionFormatter<AbstractElementAlias, AbstractElement>()
            .setTokenToString(t2s);
    return formatter2.apply(new GrammarAliasAdapter(this));
}
项目:xtext-core    文件:SyntacticSequencerDiagnosticProvider.java   
@Override
public ISerializationDiagnostic createUnexpectedStackStateDiagnostic(EObject semanticObject, RuleCallStack stack,
        RuleCall popped, ISynState toConsume) {
    String poppedStr = popped == null ? "null" : new GrammarElementTitleSwitch().showAssignments().doSwitch(popped);
    StringBuilder buf = new StringBuilder();
    buf.append("Unexpected stack state.\n");
    buf.append("Found on top of the stack: " + poppedStr + "\n");
    buf.append("Expected: " + toConsume + "\n");
    buf.append("Rest of the stack: " + stack + "\n");
    return new SerializationDiagnostic(UNEXPECTED_STACK_TRACE, semanticObject, (ISerializationContext) null,
            grammarAccess.getGrammar(), buf.toString());
}
项目:xtext-core    文件:ContentAssistContextTestHelper.java   
public String firstSetGrammarElementsToString(final ContentAssistContextFactory factory) {
  final int offset = this.document.indexOf(this.cursor);
  Preconditions.checkArgument((offset >= 0), "you forgot to provide a cursor");
  final String doc = this.document.replace(this.cursor, "");
  final XtextResource res = this.parse(doc);
  factory.setPool(Executors.newCachedThreadPool());
  TextRegion _textRegion = new TextRegion(0, 0);
  final ContentAssistContext[] ctxs = factory.create(doc, _textRegion, offset, res);
  final GrammarElementTitleSwitch f = new GrammarElementTitleSwitch().showAssignments().showQualified().showRule();
  StringConcatenation _builder = new StringConcatenation();
  {
    Iterable<Pair<Integer, ContentAssistContext>> _indexed = IterableExtensions.<ContentAssistContext>indexed(((Iterable<? extends ContentAssistContext>)Conversions.doWrapArray(ctxs)));
    for(final Pair<Integer, ContentAssistContext> ctx : _indexed) {
      _builder.append("context");
      Integer _key = ctx.getKey();
      _builder.append(_key);
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      {
        ImmutableList<AbstractElement> _firstSetGrammarElements = ctx.getValue().getFirstSetGrammarElements();
        for(final AbstractElement ele : _firstSetGrammarElements) {
          _builder.append("\t");
          String _name = ele.eClass().getName();
          _builder.append(_name, "\t");
          _builder.append(": ");
          String _apply = f.apply(ele);
          _builder.append(_apply, "\t");
          _builder.newLineIfNotEmpty();
        }
      }
      _builder.append("}");
      _builder.newLine();
    }
  }
  return _builder.toString();
}
项目:xtext-core    文件:FirstSetComputationTest.java   
protected void assertFirstSet(String expectation, AbstractRule rule) {
    RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall();
    ruleCall.setRule(rule);
    List<AbstractElement> firstSet = AntlrGrammarGenUtil.getFirstSet(ruleCall);
    StringBuilder actual = new StringBuilder();
    GrammarElementTitleSwitch stringifier = new GrammarElementTitleSwitch();
    for(int i = 0; i < firstSet.size(); i++) {
        if (i != 0)
            actual.append(", ");
        actual.append(stringifier.apply(firstSet.get(i)));
    }
    assertEquals(expectation, actual.toString());
}
项目:xtext-core    文件:AssignmentFinderTest.java   
private String findAssignments(EObject obj, Object value, AbstractElement... assignments) {
    AbstractElement element = (AbstractElement) NodeModelUtils.getNode(obj).getGrammarElement();
    ISerializationContext ctx = SerializationContext.forChild(null, element, obj);
    Multimap<AbstractElement, ISerializationContext> ass = ArrayListMultimap.create();
    for (AbstractElement e : assignments)
        ass.put(e, ctx);
    List<AbstractElement> found = Lists.newArrayList(finder.findAssignmentsByValue(obj, ass, value, null));
    Collections.sort(found, GrammarElementDeclarationOrder.get(GrammarUtil.getGrammar(assignments[0])));
    return Joiner.on(", ").join(Iterables.transform(found, new GrammarElementTitleSwitch().showAssignments()));
}
项目:xtext-core    文件:GrammarPDAProviderTest.java   
private String toListString(final Pda<ISerState, RuleCall> pda) {
  final GrammarElementTitleSwitch ts = new GrammarElementTitleSwitch().showAssignments().hideCardinality().showQualified();
  final PdaListFormatter<ISerState, RuleCall> formatter = new PdaListFormatter<ISerState, RuleCall>();
  final Function<ISerState, String> _function = (ISerState it) -> {
    String _switchResult = null;
    ISerState.SerStateType _type = it.getType();
    if (_type != null) {
      switch (_type) {
        case START:
          _switchResult = "start";
          break;
        case STOP:
          _switchResult = "stop";
          break;
        default:
          _switchResult = ts.apply(it.getGrammarElement());
          break;
      }
    } else {
      _switchResult = ts.apply(it.getGrammarElement());
    }
    return _switchResult;
  };
  formatter.setStateFormatter(_function);
  formatter.setStackitemFormatter(new GrammarElementTitleSwitch().showAssignments().hideCardinality());
  formatter.sortFollowers();
  String _format = formatter.format(pda);
  return (_format + "\n");
}
项目:xtext-core    文件:RuleCallStack.java   
@Override
public String elementToStr(RuleCall value) {
    if (value == null)
        return "(null)";
    return new GrammarElementTitleSwitch().showAssignments().doSwitch(value);
}
项目:xtext-core    文件:SemanticSequencerNfaProvider.java   
@Override
public String toString() {
    if (assignedGrammarElement == null)
        return "(null)";
    return new GrammarElementTitleSwitch().showQualified().showAssignments().apply(assignedGrammarElement);
}
项目:xtext-core    文件:SyntacticSequencerPDAProvider.java   
@Override
public String toString() {
    return toString(new GrammarElementTitleSwitch().showAssignments().showQualified());
}
项目:xtext-core    文件:AbstractSemanticRegionsFinder.java   
@Override
public String toString() {
    String string = new GrammarElementTitleSwitch().showRule().showQualified().doSwitch(grammarElement);
    return "Predicate[" + string + "]";
}