
org.eclipse.xtext.conversion.impl.AbstractDeclarativeValueConverterService Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c) 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.conversion.impl;
import static org.eclipse.xtext.GrammarUtil.*;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Set;
import org.apache.log4j.Logger;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EFactory;
import org.eclipse.xtext.AbstractRule;
import org.eclipse.xtext.Grammar;
import org.eclipse.xtext.GrammarUtil;
import org.eclipse.xtext.IGrammarAccess;
import org.eclipse.xtext.ParserRule;
import org.eclipse.xtext.TerminalRule;
import org.eclipse.xtext.conversion.IValueConverter;
import org.eclipse.xtext.conversion.IValueConverterService;
import org.eclipse.xtext.conversion.ValueConverter;
import org.eclipse.xtext.conversion.ValueConverterException;
import org.eclipse.xtext.nodemodel.INode;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.inject.Inject;
/**
* Abstract base implementation for the {@link IValueConverterService}.
*
* All methods that are annotated with {@link ValueConverter @ValueConverter} are
* used to collect the strategies for this language. Furthermore, the {@link EFactory EMF factories}
* are inspected to create converters for data types that have not yet been mapped.
*
* @author Sven Efftinge - Initial contribution and API
*/
public abstract class AbstractDeclarativeValueConverterService extends AbstractValueConverterService {
private static final Logger log = Logger.getLogger(AbstractDeclarativeValueConverterService.class);
private Grammar grammar;
private Map> converters;
@Inject
protected DefaultTerminalConverter.Factory defaultTerminalConverterFactory;
@Inject
public void setGrammar(IGrammarAccess grammarAccess) {
this.grammar = grammarAccess.getGrammar();
}
protected Grammar getGrammar() {
return grammar;
}
public String toString(Object value, String lexerRule) {
return getConverter(lexerRule).toString(value);
}
public Object toValue(String string, String lexerRule, INode node) throws ValueConverterException {
return getConverter(lexerRule).toValue(string, node);
}
@SuppressWarnings("unchecked")
protected IValueConverter
© 2015 - 2025 Weber Informatics LLC | Privacy Policy