[492456] Added support for ignorecase-keywords to the new serializer

Signed-off-by: Christian Dietrich <christian.dietrich@itemis.de>
This commit is contained in:
Christian Dietrich 2016-04-26 16:37:10 +02:00
parent b9544d8c12
commit 32cfbbe196
2 changed files with 37 additions and 0 deletions

View file

@ -51,6 +51,7 @@ import org.eclipse.xtext.xtext.generator.util.SyntheticTerminalDetector
import static extension org.eclipse.xtext.GrammarUtil.*
import static extension org.eclipse.xtext.xtext.generator.model.TypeReference.*
import static extension org.eclipse.xtext.xtext.generator.parser.antlr.AntlrGrammarGenUtil.*
import org.eclipse.xtext.serializer.tokens.IKeywordSerializer
class XtextAntlrGeneratorFragment2 extends AbstractAntlrGeneratorFragment2 {
@ -458,6 +459,7 @@ class XtextAntlrGeneratorFragment2 extends AbstractAntlrGeneratorFragment2 {
if (getOptions().isIgnoreCase()) {
rtBindings
.addTypeToType(ITokenSerializer.IKeywordSerializer.typeRef, IgnoreCaseKeywordSerializer.typeRef)
.addTypeToType(IKeywordSerializer.typeRef, org.eclipse.xtext.serializer.tokens.IgnoreCaseKeywordSerializer.typeRef)
.addTypeToType(AbstractIDValueConverter.typeRef, IgnoreCaseIDValueConverter.typeRef)
}
rtBindings.contributeTo(language.runtimeGenModule)

View file

@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.xtext.serializer.tokens;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.Keyword;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic.Acceptor;
/**
* @author Christian Dietrich - Initial contribution and API
*/
public class IgnoreCaseKeywordSerializer implements IKeywordSerializer {
@Override
public boolean isValid(EObject context, Keyword keyword, Object value, Acceptor errorAcceptor) {
if (value instanceof String) {
return keyword.getValue().equalsIgnoreCase((String) value);
}
return false;
}
@Override
public String serializeAssignedKeyword(EObject context, Keyword keyword, Object value, INode node, Acceptor errorAcceptor) {
if (node != null && node.getGrammarElement() == keyword)
return node.getText();
return keyword.getValue();
}
}