Java 类org.eclipse.xtext.parsetree.reconstr.ITokenSerializer 实例源码

项目:xtext-extras    文件:AntlrGeneratorFragment.java   
@Override
public Set<Binding> getGuiceBindingsRt(Grammar grammar) {
    BindFactory factory = new BindFactory()
        .addTypeToType(IParser.class.getName(),getFragmentHelper().getParserClassName(grammar))
        .addTypeToType(ITokenToStringConverter.class.getName(),AntlrTokenToStringConverter.class.getName())
        .addTypeToType(IAntlrTokenFileProvider.class.getName(),getFragmentHelper().getAntlrTokenFileProviderClassName(grammar))
        .addTypeToType(Lexer.class.getName(), getFragmentHelper().getLexerClassName(grammar))
        .addTypeToProviderInstance(getFragmentHelper().getLexerClassName(grammar), "org.eclipse.xtext.parser.antlr.LexerProvider.create(" + getFragmentHelper().getLexerClassName(grammar) + ".class)")
        .addConfiguredBinding("RuntimeLexer",
                "binder.bind(" + Lexer.class.getName() + ".class)"+
                ".annotatedWith(com.google.inject.name.Names.named(" +
                "org.eclipse.xtext.parser.antlr.LexerBindings.RUNTIME" +
                ")).to(" + getFragmentHelper().getLexerClassName(grammar) +".class)")
        .addTypeToType(ITokenDefProvider.class.getName(),AntlrTokenDefProvider.class.getName());
    if (containsUnorderedGroup(grammar))
        factory = factory.addTypeToType(IUnorderedGroupHelper.class.getName(), UnorderedGroupHelper.class.getName());
    if (getOptions().isIgnoreCase()) {
        factory = factory
            .addTypeToType(ITokenSerializer.IKeywordSerializer.class.getName(), IgnoreCaseKeywordSerializer.class.getName())
            .addTypeToType(AbstractIDValueConverter.class.getName(), IgnoreCaseIDValueConverter.class.getName());
    }
    return factory.getBindings();
}
项目:xtext-core    文件:CrossReferenceSerializer.java   
@Override
public String serializeCrossRef(EObject context, CrossReference grammarElement, final EObject target, INode node) {
    final EReference ref = GrammarUtil.getReference(grammarElement, context.eClass());
    String text = null;
    if (node != null) {
        List<EObject> objects = linkingService.getLinkedObjects(context, ref, node);
        if (Iterables.any(objects, new Predicate<EObject>() {
            private final URI targetURI = EcoreUtil.getURI(target);
            @Override
            public boolean apply(EObject input) {
                return input == target || EcoreUtil.getURI(input).equals(targetURI);
            }
        }))
            return ITokenSerializer.KEEP_VALUE_FROM_NODE_MODEL;
    }
    text = getUnconvertedLinkText(target, ref, context);
    if (text != null)
        return getConvertedValue(text, grammarElement);
    if (node != null) {
        return linkingHelper.getCrossRefNodeAsString(node, false);
    }
    return null;
}
项目:xtext-core    文件:CrossRefTest.java   
@Test public void testSerializingProxiedCrossReference() throws Exception {
    XtextResource r = getResourceFromString("type TypeA extends ^TypeB type TypeB ");
    Main model = (Main) r.getContents().get(0);

    Type type = model.getTypes().get(0);
    Type superType = type.getExtends();

    CrossRefLinkingService linkingService = (CrossRefLinkingService) get(ILinkingService.class);
    InternalEObject typeProxy = (InternalEObject) LangATestLanguageFactory.eINSTANCE.createType();
    typeProxy.eSetProxyURI(EcoreUtil.getURI(superType));
    linkingService.returnOnceForGetLinkedObjects(typeProxy);

    INode node = getCrossReferenceNode(type, GrammarUtil.getReference(grammar.getTypeAccess().getExtendsTypeCrossReference_2_1_0()), superType);
    String linkText = crossRefSerializer.serializeCrossRef(type, grammar.getTypeAccess().getExtendsTypeCrossReference_2_1_0(), superType, node);
    assertEquals(ITokenSerializer.KEEP_VALUE_FROM_NODE_MODEL, linkText);
}
项目:xtext-core    文件:AbstractParseTreeConstructor.java   
public final String serialize(INode node) {
    String result = serializeInternal(node);
    if (result != ITokenSerializer.KEEP_VALUE_FROM_NODE_MODEL)
        return result;
    if (node == null)
        throw new UnsupportedOperationException(
                "Can not keep value from Node Model when there is no Node Model. Context:" + this);
    else
        return tokenUtil.serializeNode(node);
}
项目:xtext-core    文件:EnumLiteralSerializer.java   
@Override
public String serializeAssignedEnumLiteral(EObject context, RuleCall ruleCall, Object value, INode node) {
    Keyword nodeLit = getLiteral(node);
    Keyword modelLit = getLiteral(context, ruleCall, value);
    if (nodeLit != null && nodeLit.equals(modelLit))
        return ITokenSerializer.KEEP_VALUE_FROM_NODE_MODEL;
    return modelLit.getValue();
}
项目:xtext-core    文件:ValueSerializer.java   
@Override
public String serializeAssignedValue(EObject context, RuleCall ruleCall, Object value, INode node) {
    if (node != null) {
        Object converted = converter.toValue(serialize(node), ruleCall.getRule().getName(), node);
        if (converted != null && converted.equals(value))
            return ITokenSerializer.KEEP_VALUE_FROM_NODE_MODEL;
    }
    return converter.toString(value, ruleCall.getRule().getName());
}
项目:xtext-core    文件:ValueSerializer.java   
@Override
public String serializeUnassignedValue(EObject context, RuleCall ruleCall, INode node) {
    String r = serializeUnassignedValueByRuleCall(ruleCall, context, node);
    if (r != null)
        return r;
    r = serializeUnassignedValueByRule(ruleCall.getRule(), context, node);
    if (r != null)
        return r;
    if (node != null)
        return ITokenSerializer.KEEP_VALUE_FROM_NODE_MODEL;
    throw new IllegalArgumentException("Could not determine the value for the unassigned rulecall of rule "
            + ruleCall.getRule().getName() + " from within rule " + GrammarUtil.containingRule(ruleCall).getName()
            + ". You might want to implement " + IValueSerializer.class.getName()
            + ".serializeUnassignedValue() or modify your implementation to handle this rulecall.");
}
项目:xtext-core    文件:CrossRefTest.java   
@Test public void testNonDefaultLinkText() throws Exception {
    XtextResource r = getResourceFromString("type TypeA extends ^TypeB type TypeB");
    Main model = (Main) r.getContents().get(0);
    assertEquals(2, model.getTypes().size());

    Type type = model.getTypes().get(0);
    assertEquals("TypeA", type.getName());
    Type superType = type.getExtends();
    assertEquals("TypeB", superType.getName());
    INode node = getCrossReferenceNode(type, GrammarUtil.getReference(grammar.getTypeAccess().getExtendsTypeCrossReference_2_1_0()), superType);
    String linkText = crossRefSerializer.serializeCrossRef(type, grammar.getTypeAccess().getExtendsTypeCrossReference_2_1_0(), superType, node);
    assertTrue(ITokenSerializer.KEEP_VALUE_FROM_NODE_MODEL == linkText);
}
项目:antlr4ide    文件:AntlrGeneratorFragmentWithCustomLexer.java   
@Override
public Set<Binding> getGuiceBindingsRt(final Grammar grammar) {
  BindFactory factory = new BindFactory()
      .addTypeToType(IParser.class.getName(), getFragmentHelper().getParserClassName(grammar))
      .addTypeToType(ITokenToStringConverter.class.getName(),
          AntlrTokenToStringConverter.class.getName())
      .addTypeToType(IAntlrTokenFileProvider.class.getName(),
          getFragmentHelper().getAntlrTokenFileProviderClassName(grammar))
      .addTypeToType(Lexer.class.getName(), getFragmentHelper().getLexerClassName(grammar))
      .addTypeToProviderInstance(
          getFragmentHelper().getLexerClassName(grammar),
          "org.eclipse.xtext.parser.antlr.LexerProvider.create("
              + getFragmentHelper().getLexerClassName(grammar) + ".class)")
      .addConfiguredBinding("RuntimeLexer",
          "binder.bind(" + Lexer.class.getName() + ".class)" +
              ".annotatedWith(com.google.inject.name.Names.named(" +
              "org.eclipse.xtext.parser.antlr.LexerBindings.RUNTIME" +
              ")).to(" + getFragmentHelper().getLexerClassName(grammar) + ".class)")
      .addTypeToType(ITokenDefProvider.class.getName(), AntlrTokenDefProvider.class.getName());
  if (containsUnorderedGroup(grammar)) {
    factory = factory.addTypeToType(IUnorderedGroupHelper.class.getName(),
        UnorderedGroupHelper.class.getName());
  }
  if (getOptions().isIgnoreCase()) {
    factory = factory
        .addTypeToType(ITokenSerializer.IKeywordSerializer.class.getName(),
            IgnoreCaseKeywordSerializer.class.getName())
        .addTypeToType(AbstractIDValueConverter.class.getName(),
            IgnoreCaseIDValueConverter.class.getName());
  }
  return factory.getBindings();
}
项目:xtext-core    文件:AbstractKeywordSerializer.java   
@Override
public String serializeAssignedKeyword(EObject context, Keyword keyword, Object value, INode node) {
    if (node != null && node.getGrammarElement() == keyword)
        return ITokenSerializer.KEEP_VALUE_FROM_NODE_MODEL;
    return keyword.getValue();
}
项目:xtext-core    文件:AbstractKeywordSerializer.java   
@Override
public String serializeUnassignedKeyword(EObject context, Keyword keyword, INode node) {
    if (node != null && node.getGrammarElement() == keyword)
        return ITokenSerializer.KEEP_VALUE_FROM_NODE_MODEL;
    return keyword.getValue();
}
项目:xtext-core    文件:AbstractBug299237TestLanguageRuntimeModule.java   
public Class<? extends ITokenSerializer.IKeywordSerializer> bindITokenSerializer$IKeywordSerializer() {
    return IgnoreCaseKeywordSerializer.class;
}
项目:xtext-core    文件:AbstractBug301935ExTestLanguageRuntimeModule.java   
public Class<? extends ITokenSerializer.IKeywordSerializer> bindITokenSerializer$IKeywordSerializer() {
    return IgnoreCaseKeywordSerializer.class;
}
项目:xtext-core    文件:AbstractIgnoreCaseLexerTestLanguageRuntimeModule.java   
public Class<? extends ITokenSerializer.IKeywordSerializer> bindITokenSerializer$IKeywordSerializer() {
    return IgnoreCaseKeywordSerializer.class;
}