Java 类org.eclipse.xtext.parser.IEncodingProvider 实例源码

项目:xtext-extras    文件:JavaSourceLanguageRuntimeModule.java   
@Override
protected void configure() {
  this.<Resource.Factory>bind(Resource.Factory.class).to(JavaResource.Factory.class);
  this.<IResourceValidator>bind(IResourceValidator.class).toInstance(IResourceValidator.NULL);
  this.<IGenerator>bind(IGenerator.class).to(IGenerator.NullGenerator.class);
  this.<IEncodingProvider>bind(IEncodingProvider.class).to(IEncodingProvider.Runtime.class);
  this.<IResourceServiceProvider>bind(IResourceServiceProvider.class).to(JavaResourceServiceProvider.class);
  this.<IContainer.Manager>bind(IContainer.Manager.class).to(SimpleResourceDescriptionsBasedContainerManager.class);
  this.<IResourceDescription.Manager>bind(IResourceDescription.Manager.class).to(JavaResourceDescriptionManager.class);
  this.<IQualifiedNameProvider>bind(IQualifiedNameProvider.class).to(JvmIdentifiableQualifiedNameProvider.class);
  this.<String>bind(String.class).annotatedWith(Names.named(Constants.FILE_EXTENSIONS)).toInstance("java");
  this.<String>bind(String.class).annotatedWith(Names.named(Constants.LANGUAGE_NAME)).toInstance("org.eclipse.xtext.java.Java");
  this.<IJvmTypeProvider.Factory>bind(IJvmTypeProvider.Factory.class).to(ClasspathTypeProviderFactory.class);
  this.<ClassLoader>bind(ClassLoader.class).toInstance(JavaSourceLanguageRuntimeModule.class.getClassLoader());
  this.<IReferableElementsUnloader>bind(IReferableElementsUnloader.class).to(IReferableElementsUnloader.GenericUnloader.class);
  final IResourceDescriptionsProvider _function = (ResourceSet it) -> {
    return ChunkedResourceDescriptions.findInEmfObject(it);
  };
  this.<IResourceDescriptionsProvider>bind(IResourceDescriptionsProvider.class).toInstance(_function);
}
项目:xtext-core    文件:XtextGenerator.java   
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);
    }
  }
}
项目:xtext-core    文件:ChangeConverter.java   
protected String getCharset(final Resource resource) {
  String _xblockexpression = null;
  {
    final IEncodingProvider xtextEncodingProvider = this.registry.getResourceServiceProvider(resource.getURI()).<IEncodingProvider>get(IEncodingProvider.class);
    String _xifexpression = null;
    if ((xtextEncodingProvider != null)) {
      return xtextEncodingProvider.getEncoding(resource.getURI());
    } else {
      String _xifexpression_1 = null;
      if ((resource instanceof XMLResource)) {
        _xifexpression_1 = ((XMLResource)resource).getEncoding();
      } else {
        _xifexpression_1 = Charset.defaultCharset().toString();
      }
      _xifexpression = _xifexpression_1;
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
项目:statecharts    文件:SCTXtextIntegrationModule.java   
@Override
public void configure(Binder binder) {
    binder.bind(IResourceValidator.class).to(SCTResourceValidatorImpl.class);
    binder.bind(String.class).annotatedWith(Names.named(Constants.FILE_EXTENSIONS)).toInstance("sct");
    binder.bind(IEncodingProvider.class).to(IEncodingProvider.Runtime.class);
    binder.bind(IQualifiedNameProvider.class).to(StextNameProvider.class);
    binder.bind(org.eclipse.jface.viewers.ILabelProvider.class)
            .annotatedWith(org.eclipse.xtext.ui.resource.ResourceServiceDescriptionLabelProvider.class)
            .to(DefaultDescriptionLabelProvider.class);
    binder.bind(IDefaultResourceDescriptionStrategy.class).to(SCTResourceDescriptionStrategy.class);

    binder.bind(MarkerCreator.class).to(SCTMarkerCreator.class);
    binder.bind(MarkerTypeProvider.class).to(SCTMarkerTypeProvider.class);
    binder.bind(IDiagnosticConverter.class).to(SCTDiagnosticConverterImpl.class);
    binder.bind(IURIEditorOpener.class).annotatedWith(LanguageSpecific.class).to(SCTFileEditorOpener.class);

    binder.bind(IMarkerContributor.class).to(TaskMarkerContributor.class);
    binder.bind(ITaskFinder.class).to(DomainSpecificTaskFinder.class);
    binder.bind(TaskMarkerCreator.class).to(SCTTaskMarkerCreator.class);
    binder.bind(TaskMarkerTypeProvider.class).to(SCTTaskMarkerTypeProvider.class);
}
项目:xtext-extras    文件:StandaloneBuilderModule.java   
@Override
protected void configure() {
  this.<IResourceDescriptions>bind(IResourceDescriptions.class).annotatedWith(Names.named(ResourceDescriptionsProvider.NAMED_BUILDER_SCOPE)).to(ResourceSetBasedResourceDescriptions.class);
  this.<IResourceDescriptions>bind(IResourceDescriptions.class).annotatedWith(Names.named(ResourceDescriptionsProvider.LIVE_SCOPE)).to(ResourceSetBasedResourceDescriptions.class);
  this.<IResourceDescriptions>bind(IResourceDescriptions.class).annotatedWith(Names.named(ResourceDescriptionsProvider.PERSISTED_DESCRIPTIONS)).to(ResourceSetBasedResourceDescriptions.class);
  this.<IResourceDescriptions>bind(IResourceDescriptions.class).to(ResourceSetBasedResourceDescriptions.class);
  this.<IIssueHandler>bind(IIssueHandler.class).to(this.bindIIssueHandler());
  this.<AbstractFileSystemAccess>bind(AbstractFileSystemAccess.class).to(this.bindJavaIoFileSystemAccess());
  this.<IJavaCompiler>bind(IJavaCompiler.class).to(this.bindIJavaCompiler());
  this.<IEncodingProvider>bind(IEncodingProvider.class).to(this.bindIEncodingProvider());
}
项目:xtext-extras    文件:StandaloneBuilder.java   
public void fileEncodingSetup(final Collection<LanguageAccess> langs, final String encoding) {
  for (final LanguageAccess lang : langs) {
    IEncodingProvider _encodingProvider = lang.getEncodingProvider();
    final IEncodingProvider provider = _encodingProvider;
    boolean _matched = false;
    if (provider instanceof IEncodingProvider.Runtime) {
      _matched=true;
      ((IEncodingProvider.Runtime)provider).setDefaultEncoding(encoding);
    }
    if (!_matched) {
      this.forceDebugLog((((("Couldn\'t set encoding \'" + encoding) + "\' for provider \'") + provider) + 
        "\'. Only subclasses of IEncodingProvider.Runtime are supported."));
    }
  }
}
项目:xtext-core    文件:JavaIoFileSystemAccess.java   
/**
 * @since 2.4
 */
public JavaIoFileSystemAccess(IResourceServiceProvider.Registry registry, IEncodingProvider encodingProvider,
        TraceFileNameProvider traceFileNameProvider, TraceRegionSerializer traceRegionSerializer) {
    this.registry = registry;
    this.encodingProvider = encodingProvider;
    this.traceFileNameProvider = traceFileNameProvider;
    this.traceSerializer = traceRegionSerializer;
}
项目:xtext-core    文件:DefaultGeneratorModule.java   
public void configureIEncodingProvider(final Binder binder) {
  AnnotatedBindingBuilder<IEncodingProvider> _bind = binder.<IEncodingProvider>bind(IEncodingProvider.class);
  IEncodingProvider.Runtime _runtime = new IEncodingProvider.Runtime();
  final Procedure1<IEncodingProvider.Runtime> _function = (IEncodingProvider.Runtime it) -> {
    it.setDefaultEncoding(this.code.getEncoding());
  };
  IEncodingProvider.Runtime _doubleArrow = ObjectExtensions.<IEncodingProvider.Runtime>operator_doubleArrow(_runtime, _function);
  _bind.toInstance(_doubleArrow);
}
项目:xtext-core    文件:JavaIoFileSystemAccessTest.java   
@Test
public void testEncoding() throws Exception {
    File file = null;
    FileInputStream fileInputStream = null;
    try {
        JavaIoFileSystemAccess fileSystemAccess = new JavaIoFileSystemAccess(
                IResourceServiceProvider.Registry.INSTANCE, new IEncodingProvider() {
                    @Override
                    public String getEncoding(URI uri) {
                        return "ISO-8859-1";
                    }
                });
        File tmpDir = configureFileSystemAccess(fileSystemAccess);
        String contents = "g�rkenbr�d";
        fileSystemAccess.generateFile("test.txt", contents);
        file = new File(tmpDir, "test.txt");
        assertTrue(file.exists());
        fileInputStream = new FileInputStream(file);
        byte[] buffer = new byte[512];
        int read = fileInputStream.read(buffer);
        String utfString = new String(buffer, 0, read, "UTF-8");
        assertFalse(equal(contents, utfString));
        String isoString = new String(buffer, 0, read, "ISO-8859-1");
        assertEquals(contents, isoString);
    } finally {
        if (fileInputStream != null)
            fileInputStream.close();
        if (file != null)
            file.delete();
    }
}
项目:xtext-core    文件:JavaIoFileSystemAccessTest.java   
@Test
public void testTraceIsCreated() throws Exception {
    File file = null;
    try {

        JavaIoFileSystemAccess fileSystemAccess = new JavaIoFileSystemAccess(
                IResourceServiceProvider.Registry.INSTANCE, new IEncodingProvider.Runtime(),
                new TraceFileNameProvider(), new TraceRegionSerializer());

        File tmpDir = configureFileSystemAccess(fileSystemAccess);
        SourceRelativeURI uri = new SourceRelativeURI(URI.createURI("foo/bar"));
        CharSequenceTraceWrapper wrapper = new CharSequenceTraceWrapper();
        fileSystemAccess.generateFile("tmp/X", wrapper.wrapWithTraceData("XX", uri, 0, 10, 0, 1));

        file = new File(tmpDir, "tmp/X");
        assertTrue(file.exists());
        assertTrue(file.isFile());
        assertEquals("XX", fileSystemAccess.readTextFile("tmp/X"));

        file = new File(tmpDir, "tmp/.X._trace");
        assertTrue(file.exists());
        assertTrue(file.isFile());

    } finally {
        if (file != null)
            file.delete();
    }
}
项目:xtext-core    文件:UnicodeTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    with(UnicodeTestLanguageStandaloneSetup.class);
    IEncodingProvider.Runtime encodingProvider = get(IEncodingProvider.Runtime.class);
    encodingProvider.setDefaultEncoding(getCharsetForTest().name());
}
项目:xtext-extras    文件:LanguageAccess.java   
public IEncodingProvider getEncodingProvider() {
    return resourceServiceProvider.get(Runtime.class);
}
项目:xtext-extras    文件:StandaloneBuilderModule.java   
protected Class<? extends IEncodingProvider> bindIEncodingProvider() {
  return IEncodingProvider.Runtime.class;
}
项目:xtext-extras    文件:JavaResourceServiceProvider.java   
@Override
public IEncodingProvider getEncodingProvider() {
  return this.<IEncodingProvider>get(IEncodingProvider.class);
}
项目:xtext-core    文件:JavaIoFileSystemAccess.java   
/**
 * @since 2.3
 */
public JavaIoFileSystemAccess(IResourceServiceProvider.Registry registry, IEncodingProvider encodingProvider) {
    this.registry = registry;
    this.encodingProvider = encodingProvider;
}
项目:xtext-core    文件:GenericResourceServiceProvider.java   
@Override
public IEncodingProvider getEncodingProvider() {
    return encodingProvider;
}
项目:xtext-core    文件:AbstractGenericResourceRuntimeModule.java   
public Class<? extends IEncodingProvider> bindIEncodingProvider() {
    return XMLEncodingProvider.class;
}
项目:xtext-core    文件:DefaultResourceServiceProvider.java   
@Override
public IEncodingProvider getEncodingProvider() {
    return encodingProvider;
}
项目:xtext-core    文件:DefaultRuntimeModule.java   
public void configureRuntimeEncodingProvider(Binder binder) {
    binder.bind(IEncodingProvider.class).annotatedWith(DispatchingProvider.Runtime.class).to(IEncodingProvider.Runtime.class);
}
项目:xtext-core    文件:DefaultRuntimeModule.java   
/**
 * @since 2.8
 */
public Class<? extends IEncodingProvider.Runtime> bindRuntimeEncodingProvider() {
    return EclipseProjectPropertiesEncodingProvider.class;
}
项目:xtext-core    文件:DefaultRuntimeModule.java   
public Class<? extends Provider<IEncodingProvider>> provideIEncodingProvider() {
    return IEncodingProviderDispatcher.class;
}
项目:xtext-core    文件:URIBasedFileSystemAccess.java   
@Pure
public IEncodingProvider getEncodingProvider() {
  return this.encodingProvider;
}
项目:xtext-core    文件:URIBasedFileSystemAccess.java   
public void setEncodingProvider(final IEncodingProvider encodingProvider) {
  this.encodingProvider = encodingProvider;
}
项目:xtext-core    文件:IncrementalBuilder.java   
protected URIBasedFileSystemAccess createFileSystemAccess(final IResourceServiceProvider serviceProvider, final Resource resource) {
  URIBasedFileSystemAccess _xblockexpression = null;
  {
    final IProjectConfigProvider projectConfigProvider = serviceProvider.<IProjectConfigProvider>get(IProjectConfigProvider.class);
    IProjectConfig _projectConfig = null;
    if (projectConfigProvider!=null) {
      _projectConfig=projectConfigProvider.getProjectConfig(resource.getResourceSet());
    }
    final IProjectConfig projectConfig = _projectConfig;
    ISourceFolder _findSourceFolderContaining = null;
    if (projectConfig!=null) {
      _findSourceFolderContaining=projectConfig.findSourceFolderContaining(resource.getURI());
    }
    final ISourceFolder sourceFolder = _findSourceFolderContaining;
    URIBasedFileSystemAccess _uRIBasedFileSystemAccess = new URIBasedFileSystemAccess();
    final Procedure1<URIBasedFileSystemAccess> _function = (URIBasedFileSystemAccess it) -> {
      final IContextualOutputConfigurationProvider outputConfigProvider = serviceProvider.<IContextualOutputConfigurationProvider>get(IContextualOutputConfigurationProvider.class);
      final Function1<OutputConfiguration, String> _function_1 = (OutputConfiguration it_1) -> {
        return it_1.getName();
      };
      it.setOutputConfigurations(IterableExtensions.<String, OutputConfiguration>toMap(outputConfigProvider.getOutputConfigurations(resource), _function_1));
      it.setPostProcessor(serviceProvider.<IFilePostProcessor>get(IFilePostProcessor.class));
      final IEncodingProvider newEncodingProvider = serviceProvider.<IEncodingProvider>get(IEncodingProvider.class);
      if ((newEncodingProvider != null)) {
        it.setEncodingProvider(newEncodingProvider);
      }
      it.setTraceFileNameProvider(serviceProvider.<TraceFileNameProvider>get(TraceFileNameProvider.class));
      it.setTraceRegionSerializer(serviceProvider.<TraceRegionSerializer>get(TraceRegionSerializer.class));
      it.setGenerateTraces(true);
      it.setBaseDir(this.request.getBaseDir());
      String _name = null;
      if (sourceFolder!=null) {
        _name=sourceFolder.getName();
      }
      it.setCurrentSource(_name);
      it.setConverter(resource.getResourceSet().getURIConverter());
    };
    _xblockexpression = ObjectExtensions.<URIBasedFileSystemAccess>operator_doubleArrow(_uRIBasedFileSystemAccess, _function);
  }
  return _xblockexpression;
}
项目:xtext-core    文件:CommandRegistryTest.java   
public IEncodingProvider getEncodingProvider() {
  return this.noImpl.getEncodingProvider();
}
项目:xtext-core    文件:JavaIoFileSystemAccessTest.java   
@Test
public void testDirsAndFilesAreCreated() throws Exception {
    File dir = null;
    File textFile = null;
    File binFile = null;
    try {
        JavaIoFileSystemAccess fileSystemAccess = new JavaIoFileSystemAccess(
                IResourceServiceProvider.Registry.INSTANCE, new IEncodingProvider.Runtime());

        File tmpDir = configureFileSystemAccess(fileSystemAccess);
        fileSystemAccess.generateFile("tmp/X", "XX");
        fileSystemAccess.generateFile("tmp/Y", new StringInputStream("\1\2\3"));

        dir = new File(tmpDir, "tmp");
        assertTrue(dir.exists());
        assertTrue(dir.isDirectory());

        textFile = new File(dir, "X");
        assertTrue(textFile.exists());
        assertTrue(textFile.isFile());
        assertEquals("XX", fileSystemAccess.readTextFile("tmp/X"));

        binFile = new File(dir, "Y");
        assertTrue(binFile.exists());
        assertFalse(fileSystemAccess.isFile("tmp", IFileSystemAccess.DEFAULT_OUTPUT)); // isFile evaluates to false for directories
        assertTrue(fileSystemAccess.isFile("tmp/Y", IFileSystemAccess.DEFAULT_OUTPUT));
        assertTrue(binFile.isFile());
        InputStream stream = fileSystemAccess.readBinaryFile("tmp/Y");
        try {
            assertEquals("\1\2\3", new String(ByteStreams.toByteArray(stream)));
        } finally {
            stream.close();
        }

    } finally {
        try {
            if (textFile != null)
                textFile.delete();
        } finally {
            try {
                if (binFile != null)
                    binFile.delete();
            } finally {
                if (dir != null)
                    dir.delete();
            }
        }
    }
}
项目:bts    文件:EgyDslUiModule.java   
public Class<? extends IEncodingProvider> bindIEncodingProvider() {
    return BTSEncodingProvider.class;
}
项目:bts    文件:DefaultResourceUIServiceProvider.java   
public IEncodingProvider getEncodingProvider() {
    return encodingProvider;
}
项目:bts    文件:DefaultUiModule.java   
public void configureUiEncodingProvider(Binder binder) {
    binder.bind(IEncodingProvider.class).annotatedWith(DispatchingProvider.Ui.class)
            .to(WorkspaceEncodingProvider.class);
}
项目:bts    文件:DefaultRefactoringDocumentProvider.java   
protected IEncodingProvider getEncodingProvider(URI resourceURI) {
    return globalServiceProvider.findService(
            resourceURI, IEncodingProvider.class);
}
项目:bts    文件:DefaultRefactoringDocumentProvider.java   
public FileDocument(URI resourceURI, IFile file, IEncodingProvider encodingProvider) {
    super(resourceURI);
    this.file = file;
    this.encodingProvider = encodingProvider;
}
项目:bts    文件:DefaultRefactoringDocumentProvider.java   
public RedirectedFileDocument(URI resourceURI, IFile file, IFile redirectedFile, 
        IEncodingProvider encodingProvider) {
    super(resourceURI, file, encodingProvider);
    this.redirectedFile = redirectedFile;
}
项目:gama    文件:GamlUiModule.java   
@Override
public void configureUiEncodingProvider(final Binder binder) {
    binder.bind(IEncodingProvider.class).annotatedWith(DispatchingProvider.Ui.class).to(GamlEncodingProvider.class);
}
项目:gama    文件:GamlRuntimeModule.java   
@Override
public void configureRuntimeEncodingProvider(final Binder binder) {
    binder.bind(IEncodingProvider.class).annotatedWith(DispatchingProvider.Runtime.class)
            .to(GamlEncodingProvider.class);
}
项目:SensIDL    文件:GenerationHandler.java   
/**
 * Start the Code generator
 * 
 * @param path
 *            the path where the files will be saves
 * @param modelPath
 *            the path to the model form with the code will be generated
 * @param language
 *            the language in which the Code will be generated
 * @return true if the code was generated
 * @throws NoSidlFileException
 *             Throws this Exception when the given file is not a sidl file
 * @throws FileNotFoundException
 *             Throws this Exception when there is no file at the given path
 * 
 */
public static boolean generate(String path, String modelPath, String language, Resource sensidlmodel)
        throws NoSidlFileException, FileNotFoundException {
    setGenerationLanguage(language);
    Injector injector = new SensidlStandaloneSetup().createInjectorAndDoEMFRegistration();

    // get resource
    Resource resource = null;
    if (sensidlmodel != null) {
        resource = sensidlmodel;
    } else {
        ResourceSet rs = new ResourceSetImpl();
        File file = new File(modelPath);

        // Exception handling for not existing input files
        if (!file.exists()) {
            throw new FileNotFoundException("File not found");
        }
        // Exception handling for input files in the wrong format
        if (!FilenameUtils.getExtension(modelPath).equals("sidl")) {
            throw new NoSidlFileException("No SIDL file found");
        }

        resource = rs.getResource(URI.createURI(file.toURI().toString()), true);
    }
    // Use the JavaIoFileSystemAccess and set the path
    final JavaIoFileSystemAccess fsa = new JavaIoFileSystemAccess();
    fsa.setOutputPath(path);

    generator = injector.getInstance(SensidlGenerator.class); // set up the
    // generator
    generator.setGenerationLanguage(generationLanguage);

    // inject fsa
    Guice.createInjector(new AbstractGenericModule() {
        @SuppressWarnings("unused")
        public Class<? extends IEncodingProvider> bindIEncodingProvider() {
            return IEncodingProvider.Runtime.class;
        }
    }).injectMembers(fsa);

    // generate
    generator.doGenerate(resource, fsa);

    return true;

}
项目:xtext-core    文件:IResourceServiceProvider.java   
IEncodingProvider getEncodingProvider();