Java 类org.eclipse.xtext.generator.InMemoryFileSystemAccess 实例源码

项目:xtext-extras    文件:JvmModelGeneratorTest.java   
public String generate(final Resource res, final JvmDeclaredType type) {
  String _xblockexpression = null;
  {
    res.eSetDeliver(false);
    EList<EObject> _contents = res.getContents();
    this.builder.<JvmDeclaredType>operator_add(_contents, type);
    res.eSetDeliver(true);
    final InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
    this.generator.doGenerate(res, fsa);
    Map<String, CharSequence> _files = fsa.getFiles();
    String _replace = type.getIdentifier().replace(".", "/");
    String _plus = (IFileSystemAccess.DEFAULT_OUTPUT + _replace);
    String _plus_1 = (_plus + ".java");
    _xblockexpression = _files.get(_plus_1).toString();
  }
  return _xblockexpression;
}
项目:PHDL    文件:GeneratorTest.java   
@Test
public void testHierarchy1() {
    try {
        String methodName = new Throwable().getStackTrace()[0].getMethodName();
        logger.info(msgpfx + this.getClass().getSimpleName() + "." + methodName);
        String testDir = path + methodName + "/";
        PhdlModel model = parseHelper.parse(PhdlUtils
                .readStringFromFile(testDir + "test" + ExtensionCodes.PHDL_EXT));
        InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
        underTest.doGenerate(model.eResource(), fsa);
        testOutputFileNames(fsa, "top");
        testOutputFiles(fsa, testDir + "golden", "top");
    } catch (Exception e) {
        throw Exceptions.sneakyThrow(e);
    }
}
项目:PHDL    文件:GeneratorTest.java   
@Test
public void testHierarchy2() {
    try {
        String methodName = new Throwable().getStackTrace()[0].getMethodName();
        logger.info(msgpfx + this.getClass().getSimpleName() + "." + methodName);
        String testDir = path + methodName + "/";
        PhdlModel model = parseHelper.parse(PhdlUtils
                .readStringFromFile(testDir + "test" + ExtensionCodes.PHDL_EXT));
        InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
        underTest.doGenerate(model.eResource(), fsa);
        testOutputFileNames(fsa, "top");
        testOutputFiles(fsa, testDir + "golden", "top");
    } catch (Exception e) {
        throw Exceptions.sneakyThrow(e);
    }
}
项目:PHDL    文件:GeneratorTest.java   
@Test
public void testRefDes1() {
    try {
        String methodName = new Throwable().getStackTrace()[0].getMethodName();
        logger.info(msgpfx + this.getClass().getSimpleName() + "." + methodName);
        String testDir = path + methodName + "/";
        PhdlModel model = parseHelper.parse(PhdlUtils
                .readStringFromFile(testDir + "test" + ExtensionCodes.PHDL_EXT));
        InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
        underTest.doGenerate(model.eResource(), fsa);
        testOutputFileNames(fsa, "top");
        testOutputFiles(fsa, testDir + "golden", "top");
    } catch (Exception e) {
        throw Exceptions.sneakyThrow(e);
    }
}
项目:PHDL    文件:GeneratorTest.java   
@Test
public void testRefDes2() {
    try {
        String methodName = new Throwable().getStackTrace()[0].getMethodName();
        logger.info(msgpfx + this.getClass().getSimpleName() + "." + methodName);
        String testDir = path + methodName + "/";
        PhdlModel model = parseHelper.parse(PhdlUtils
                .readStringFromFile(testDir + "test" + ExtensionCodes.PHDL_EXT));
        InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
        underTest.doGenerate(model.eResource(), fsa);
        testOutputFileNames(fsa, "top");
        testOutputFiles(fsa, testDir + "golden", "top");
    } catch (Exception e) {
        throw Exceptions.sneakyThrow(e);
    }
}
项目:PHDL    文件:GeneratorTest.java   
@Test
public void testBoM() {
    try {
        String methodName = new Throwable().getStackTrace()[0].getMethodName();
        logger.info(msgpfx + this.getClass().getSimpleName() + "." + methodName);
        String testDir = path + methodName + "/";
        PhdlModel model = parseHelper.parse(PhdlUtils
                .readStringFromFile(testDir + "test" + ExtensionCodes.PHDL_EXT));
        InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
        underTest.doGenerate(model.eResource(), fsa);
        testOutputFileNames(fsa, "top");
        testOutputFiles(fsa, testDir + "golden", "top");
    } catch (Exception e) {
        throw Exceptions.sneakyThrow(e);
    }
}
项目:PHDL    文件:GeneratorTest.java   
private void testOutputFileNames(InMemoryFileSystemAccess fsa, String path) {
    assertEquals(6, fsa.getFiles().size());
    assertTrue(fsa.getFiles().containsKey(IFileSystemAccess.DEFAULT_OUTPUT + path + ExtensionCodes.PADS_EXT));
    assertTrue(fsa.getFiles().containsKey(IFileSystemAccess.DEFAULT_OUTPUT + path + ExtensionCodes.BOM_EXT));
    assertTrue(fsa.getFiles().containsKey(IFileSystemAccess.DEFAULT_OUTPUT + path + ExtensionCodes.INFO_EXT));
    assertTrue(fsa.getFiles().containsKey(IFileSystemAccess.DEFAULT_OUTPUT + path + ExtensionCodes.REFDES_EXT));
    assertTrue(fsa.getFiles().containsKey(IFileSystemAccess.DEFAULT_OUTPUT + path + ExtensionCodes.EAGLE_EXT));
    assertTrue(fsa.getFiles().containsKey(IFileSystemAccess.DEFAULT_OUTPUT + path + ExtensionCodes.NET_EXT));
}
项目:PHDL    文件:GeneratorTest.java   
private void testOutputFiles(InMemoryFileSystemAccess fsa, String expected, String actual) {
    assertEquals(PhdlUtils.readStringFromFile(expected + ExtensionCodes.PADS_EXT),
            fsa.getFiles().get(IFileSystemAccess.DEFAULT_OUTPUT + actual + ExtensionCodes.PADS_EXT).toString());
    assertEquals(PhdlUtils.readStringFromFile(expected + ExtensionCodes.BOM_EXT),
            fsa.getFiles().get(IFileSystemAccess.DEFAULT_OUTPUT + actual + ExtensionCodes.BOM_EXT).toString());
    assertEquals(PhdlUtils.readStringFromFile(expected + ExtensionCodes.INFO_EXT),
            fsa.getFiles().get(IFileSystemAccess.DEFAULT_OUTPUT + actual + ExtensionCodes.INFO_EXT).toString());
    assertEquals(PhdlUtils.readStringFromFile(expected + ExtensionCodes.REFDES_EXT),
            fsa.getFiles().get(IFileSystemAccess.DEFAULT_OUTPUT + actual + ExtensionCodes.REFDES_EXT).toString());
    assertEquals(PhdlUtils.readStringFromFile(expected + ExtensionCodes.EAGLE_EXT),
            fsa.getFiles().get(IFileSystemAccess.DEFAULT_OUTPUT + actual + ExtensionCodes.EAGLE_EXT).toString());
    assertEquals(PhdlUtils.readStringFromFile(expected + ExtensionCodes.NET_EXT),
            fsa.getFiles().get(IFileSystemAccess.DEFAULT_OUTPUT + actual + ExtensionCodes.NET_EXT).toString());

}
项目:xtext-extras    文件:JvmModelGeneratorTest.java   
@Test
public void bug390290InnerClassMemberImport() {
  try {
    final XExpression expression = this.expression("null");
    final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> {
      final JvmGenericType innerClass = this.builder.toClass(it, "InnerClass");
      final JvmGenericType innerClassString = this.builder.toClass(it, "String");
      EList<JvmMember> _members = it.getMembers();
      this.builder.<JvmGenericType>operator_add(_members, innerClass);
      EList<JvmMember> _members_1 = it.getMembers();
      this.builder.<JvmGenericType>operator_add(_members_1, innerClassString);
      EList<JvmMember> _members_2 = it.getMembers();
      final Procedure1<JvmOperation> _function_1 = (JvmOperation fooMethod) -> {
        EList<JvmFormalParameter> _parameters = fooMethod.getParameters();
        JvmFormalParameter _parameter = this.builder.toParameter(it, "p1", this.references.createTypeRef(innerClass));
        this.builder.<JvmFormalParameter>operator_add(_parameters, _parameter);
        EList<JvmFormalParameter> _parameters_1 = fooMethod.getParameters();
        JvmFormalParameter _parameter_1 = this.builder.toParameter(it, "p2", this.references.createTypeRef(innerClassString));
        this.builder.<JvmFormalParameter>operator_add(_parameters_1, _parameter_1);
        this.builder.setBody(fooMethod, expression);
      };
      JvmOperation _method = this.builder.toMethod(it, "foo", this.references.getTypeForName(String.class, expression), _function_1);
      this.builder.<JvmOperation>operator_add(_members_2, _method);
    };
    final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Outer", _function);
    expression.eResource().eSetDeliver(false);
    EList<EObject> _contents = expression.eResource().getContents();
    this.builder.<JvmGenericType>operator_add(_contents, clazz);
    expression.eResource().eSetDeliver(true);
    final InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
    this.generator.doGenerate(expression.eResource(), fsa);
    Map<String, CharSequence> _files = fsa.getFiles();
    String _replace = clazz.getIdentifier().replace(".", "/");
    String _plus = (IFileSystemAccess.DEFAULT_OUTPUT + _replace);
    String _plus_1 = (_plus + ".java");
    final String code = _files.get(_plus_1).toString();
    Assert.assertFalse(code.contains("import"));
    Assert.assertTrue(code, code.contains("java.lang.String foo"));
    final Class<?> compiledClass = this.javaCompiler.compileToClass(clazz.getIdentifier(), code);
    this.helper.assertNoErrors(IterableExtensions.<EObject>head(expression.eResource().getContents()));
    Assert.assertEquals(2, ((List<Class<?>>)Conversions.doWrapArray(compiledClass.getDeclaredClasses())).size());
    Assert.assertNotNull(compiledClass.getMethod("foo", IterableExtensions.<Class<?>>head(((Iterable<Class<?>>)Conversions.doWrapArray(compiledClass.getDeclaredClasses()))), IterableExtensions.<Class<?>>last(((Iterable<Class<?>>)Conversions.doWrapArray(compiledClass.getDeclaredClasses())))));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}