微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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(),"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(),"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(),"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(),"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(),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);
  }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。