org.eclipse.xtext.xbase.compiler

Class CompilationTestHelper

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class and Description
      static class  CompilationTestHelper.Result
      A result contains information about various aspects of a compiled piece of code.
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static java.lang.String PROJECT_NAME 
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      void assertCompilesTo(java.lang.CharSequence source, java.lang.CharSequence expected)
      Asserts that the expected code is generated for the given source.
      void compile(java.lang.CharSequence source, IAcceptor<CompilationTestHelper.Result> acceptor)
      Parses, validates and compiles the given source.
      void compile(org.eclipse.emf.ecore.resource.ResourceSet resourceSet, IAcceptor<CompilationTestHelper.Result> acceptor)
      Parses, validates and compiles the given source.
      void configureFreshWorkspace()
      creates a fresh temp directory and sets it as the workspace root.
      org.eclipse.emf.common.util.URI copyToWorkspace(java.lang.String workspacefilePath, java.lang.CharSequence contents)
      Physically copies the given files to the currently used worksapce root (a temporary folder).
      protected java.io.File createFreshTempDir() 
      protected java.lang.Iterable<? extends OutputConfiguration> getOutputConfigurations() 
      protected java.lang.String getSourceFolderPath() 
      org.eclipse.emf.ecore.resource.ResourceSet resourceSet(Pair<java.lang.String,? extends java.lang.CharSequence>... resources)
      creates a fresh resource set with the given resources
      void setJavaCompilerClassPath(java.lang.Class<?>... classes)
      Add the class path entries of the given classes to the java compiler's class path.
      org.eclipse.emf.ecore.resource.ResourceSet unLoadedResourceSet(Pair<java.lang.String,? extends java.lang.CharSequence>... resources)
      same as resourceSet(Pair...) but without actually loading the created resources.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CompilationTestHelper

        public CompilationTestHelper()
    • Method Detail

      • configureFreshWorkspace

        public void configureFreshWorkspace()
        creates a fresh temp directory and sets it as the workspace root.
      • getSourceFolderPath

        protected java.lang.String getSourceFolderPath()
      • createFreshTempDir

        protected java.io.File createFreshTempDir()
      • setJavaCompilerClassPath

        public void setJavaCompilerClassPath(java.lang.Class<?>... classes)
        Add the class path entries of the given classes to the java compiler's class path.
      • assertCompilesTo

        public void assertCompilesTo(java.lang.CharSequence source,
                            java.lang.CharSequence expected)
                              throws java.io.IOException
        Asserts that the expected code is generated for the given source. Assumes that
        Parameters:
        source - some valid source code written in the language under test
        expected - the expected Java source code.
        Throws:
        java.io.IOException - if the resource loading fails
      • compile

        public void compile(java.lang.CharSequence source,
                   IAcceptor<CompilationTestHelper.Result> acceptor)
                     throws java.io.IOException
        Parses, validates and compiles the given source. Calls the given acceptor for each resource which is generated from the source.
        Parameters:
        source - some code written in the language under test.
        acceptor - gets called once for each file generated in IGenerator
        Throws:
        java.io.IOException - if the resource loading fails
      • compile

        public void compile(org.eclipse.emf.ecore.resource.ResourceSet resourceSet,
                   IAcceptor<CompilationTestHelper.Result> acceptor)
        Parses, validates and compiles the given source. Calls the given acceptor for each resource which is generated from the source.
        Parameters:
        resourceSet - - the ResourceSet to use
        acceptor - gets called once for each file generated in IGenerator
      • getOutputConfigurations

        protected java.lang.Iterable<? extends OutputConfiguration> getOutputConfigurations()
      • resourceSet

        public org.eclipse.emf.ecore.resource.ResourceSet resourceSet(Pair<java.lang.String,? extends java.lang.CharSequence>... resources)
                                                               throws java.io.IOException
        creates a fresh resource set with the given resources
        Parameters:
        resources - - pairs of file names and their contents
        Returns:
        a ResourceSet, containing the given resources.
        Throws:
        java.io.IOException - if the resource loading fails
      • copyToWorkspace

        public org.eclipse.emf.common.util.URI copyToWorkspace(java.lang.String workspacefilePath,
                                                      java.lang.CharSequence contents)
        Physically copies the given files to the currently used worksapce root (a temporary folder).
        Parameters:
        workspacefilePath - the workspace relative path
        contents - the file contents
      • unLoadedResourceSet

        public org.eclipse.emf.ecore.resource.ResourceSet unLoadedResourceSet(Pair<java.lang.String,? extends java.lang.CharSequence>... resources)
                                                                       throws java.io.IOException
        same as resourceSet(Pair...) but without actually loading the created resources.
        Throws:
        java.io.IOException