Java Code Examples for org.eclipse.xtext.parser.IEncodingProvider#Runtime

The following examples show how to use org.eclipse.xtext.parser.IEncodingProvider#Runtime . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XtextGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected void initializeEncoding() {
  final IResourceServiceProvider.Registry serviceProviderRegistry = IResourceServiceProvider.Registry.INSTANCE;
  Object _get = serviceProviderRegistry.getExtensionToFactoryMap().get("xtext");
  final IResourceServiceProvider serviceProvider = ((IResourceServiceProvider) _get);
  String _elvis = null;
  if (this.grammarEncoding != null) {
    _elvis = this.grammarEncoding;
  } else {
    String _encoding = this.configuration.getCode().getEncoding();
    _elvis = _encoding;
  }
  final String encoding = _elvis;
  if (((serviceProvider != null) && (encoding != null))) {
    final IEncodingProvider encodingProvider = serviceProvider.<IEncodingProvider>get(IEncodingProvider.class);
    if ((encodingProvider instanceof IEncodingProvider.Runtime)) {
      ((IEncodingProvider.Runtime)encodingProvider).setDefaultEncoding(encoding);
    }
  }
}
 
Example 2
Source File: StandaloneBuilder.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public void fileEncodingSetup(Collection<LanguageAccess> langs, String encoding) {
	for (LanguageAccess lang : langs) {
		IEncodingProvider provider = lang.getEncodingProvider();
		if (provider instanceof IEncodingProvider.Runtime) {
			((IEncodingProvider.Runtime) provider).setDefaultEncoding(encoding);
		} else {
			forceDebugLog("Couldn't set encoding '" + encoding + "' for provider '" + provider
					+ "'. Only subclasses of IEncodingProvider.Runtime are supported.");
		}
	}
}
 
Example 3
Source File: JavaIoFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  try {
    final File tempDir = this.temporaryFolder.newFolder();
    JavaIOFileSystemSupport _javaIOFileSystemSupport = new JavaIOFileSystemSupport();
    final Procedure1<JavaIOFileSystemSupport> _function = (JavaIOFileSystemSupport it) -> {
      final IProjectConfigProvider _function_1 = (ResourceSet it_1) -> {
        File _file = new File(tempDir, "foo");
        FileProjectConfig _fileProjectConfig = new FileProjectConfig(_file);
        final Procedure1<FileProjectConfig> _function_2 = (FileProjectConfig it_2) -> {
          it_2.addSourceFolder("src");
        };
        return ObjectExtensions.<FileProjectConfig>operator_doubleArrow(_fileProjectConfig, _function_2);
      };
      it.setProjectConfigProvider(_function_1);
      IEncodingProvider.Runtime _runtime = new IEncodingProvider.Runtime();
      it.setEncodingProvider(_runtime);
      XtextResourceSet _xtextResourceSet = new XtextResourceSet();
      it.setContext(_xtextResourceSet);
    };
    JavaIOFileSystemSupport _doubleArrow = ObjectExtensions.<JavaIOFileSystemSupport>operator_doubleArrow(_javaIOFileSystemSupport, _function);
    this.fs = _doubleArrow;
    this.createProject("foo");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 4
Source File: JavaIoFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  try {
    final File tempDir = this.temporaryFolder.newFolder();
    JavaIOFileSystemSupport _javaIOFileSystemSupport = new JavaIOFileSystemSupport();
    final Procedure1<JavaIOFileSystemSupport> _function = (JavaIOFileSystemSupport it) -> {
      final IProjectConfigProvider _function_1 = (ResourceSet it_1) -> {
        File _file = new File(tempDir, "foo");
        FileProjectConfig _fileProjectConfig = new FileProjectConfig(_file);
        final Procedure1<FileProjectConfig> _function_2 = (FileProjectConfig it_2) -> {
          it_2.addSourceFolder("src");
        };
        return ObjectExtensions.<FileProjectConfig>operator_doubleArrow(_fileProjectConfig, _function_2);
      };
      it.setProjectConfigProvider(_function_1);
      IEncodingProvider.Runtime _runtime = new IEncodingProvider.Runtime();
      it.setEncodingProvider(_runtime);
      XtextResourceSet _xtextResourceSet = new XtextResourceSet();
      it.setContext(_xtextResourceSet);
    };
    JavaIOFileSystemSupport _doubleArrow = ObjectExtensions.<JavaIOFileSystemSupport>operator_doubleArrow(_javaIOFileSystemSupport, _function);
    this.fs = _doubleArrow;
    this.createProject("foo");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 5
Source File: UnicodeTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
	super.setUp();
	with(UnicodeTestLanguageStandaloneSetup.class);
	IEncodingProvider.Runtime encodingProvider = get(IEncodingProvider.Runtime.class);
	encodingProvider.setDefaultEncoding(getCharsetForTest().name());
}
 
Example 6
Source File: StandaloneBuilderModule.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected Class<? extends IEncodingProvider> bindIEncodingProvider() {
	return IEncodingProvider.Runtime.class;
}
 
Example 7
Source File: DefaultRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.8
 */
public Class<? extends IEncodingProvider.Runtime> bindRuntimeEncodingProvider() {
	return EclipseProjectPropertiesEncodingProvider.class;
}
 
Example 8
Source File: DefaultGeneratorModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public void configureIEncodingProvider(Binder binder) {
	IEncodingProvider.Runtime runtime = new IEncodingProvider.Runtime();
	runtime.setDefaultEncoding(code.getEncoding());
	binder.bind(IEncodingProvider.class).toInstance(runtime);
}