当前位置: 首页>>代码示例>>Java>>正文


Java EcoreUtil2.clone方法代码示例

本文整理汇总了Java中org.eclipse.xtext.EcoreUtil2.clone方法的典型用法代码示例。如果您正苦于以下问题:Java EcoreUtil2.clone方法的具体用法?Java EcoreUtil2.clone怎么用?Java EcoreUtil2.clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.xtext.EcoreUtil2的用法示例。


在下文中一共展示了EcoreUtil2.clone方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deepCopy

import org.eclipse.xtext.EcoreUtil2; //导入方法依赖的package包/类
public Grammar deepCopy(Grammar grammar, ResourceSaveIndicator isSaving) {
	ResourceSet cloneInto = new ResourceSetImpl();
	// substitute the resource factory for ecore-files
	cloneInto
			.getResourceFactoryRegistry()
			.getExtensionToFactoryMap()
			.put(FragmentFakingEcoreResourceFactoryImpl.ECORE_SUFFIX,
					new FragmentFakingEcoreResourceFactoryImpl(isSaving));
	// clone it
	ResourceSet set = EcoreUtil2.clone(cloneInto, grammar.eResource().getResourceSet());
	// get the copy of the grammar and use this one
	Grammar copy = (Grammar) set.getResource(grammar.eResource().getURI(), true).getContents().get(0);
	return copy;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:15,代码来源:GrammarAccessFragment.java

示例2: cloneGrammarIntoNewResourceSet

import org.eclipse.xtext.EcoreUtil2; //导入方法依赖的package包/类
/**
 * Create a clone of the original grammar. The clone will not refer to a node model.
 */
private Grammar cloneGrammarIntoNewResourceSet(Grammar original) {
	Resource originalResource = original.eResource();
	ResourceSet clonedResourceSet = EcoreUtil2.clone(new XtextResourceSet(), originalResource.getResourceSet());
	Resource clonedResource = clonedResourceSet.getResource(originalResource.getURI(), false);
	Grammar clonedGrammar = (Grammar) clonedResource.getContents().get(0);
	return clonedGrammar;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:11,代码来源:EMFGeneratorFragment.java

示例3: cloneGrammarIntoNewResourceSet

import org.eclipse.xtext.EcoreUtil2; //导入方法依赖的package包/类
/**
 * Create a clone of the original grammar. The clone will not refer to a node model.
 */
private Grammar cloneGrammarIntoNewResourceSet(final Grammar original) {
  final Resource originalResource = original.eResource();
  XtextResourceSet _xtextResourceSet = new XtextResourceSet();
  final XtextResourceSet clonedResourceSet = EcoreUtil2.<XtextResourceSet>clone(_xtextResourceSet, originalResource.getResourceSet());
  final Resource clonedResource = clonedResourceSet.getResource(originalResource.getURI(), false);
  EObject _head = IterableExtensions.<EObject>head(clonedResource.getContents());
  return ((Grammar) _head);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:12,代码来源:EMFGeneratorFragment2.java

示例4: writeGrammar

import org.eclipse.xtext.EcoreUtil2; //导入方法依赖的package包/类
protected void writeGrammar() {
  final Wrapper<Boolean> isSaving = Wrapper.<Boolean>wrap(Boolean.valueOf(false));
  final ResourceSet cloneInto = new ResourceSetImpl();
  Map<String, Object> _extensionToFactoryMap = cloneInto.getResourceFactoryRegistry().getExtensionToFactoryMap();
  FragmentFakingEcoreResource.FactoryImpl _factoryImpl = new FragmentFakingEcoreResource.FactoryImpl(isSaving);
  _extensionToFactoryMap.put(
    FragmentFakingEcoreResource.FactoryImpl.ECORE_SUFFIX, _factoryImpl);
  final ResourceSet resourceSet = EcoreUtil2.<ResourceSet>clone(cloneInto, this.getLanguage().getGrammar().eResource().getResourceSet());
  EObject _head = IterableExtensions.<EObject>head(resourceSet.getResource(this.getLanguage().getGrammar().eResource().getURI(), true).getContents());
  final Grammar copy = ((Grammar) _head);
  String _xifexpression = null;
  if ((this.xmlVersion == null)) {
    _xifexpression = GrammarUtil.getClasspathRelativePathToBinGrammar(copy);
  } else {
    String _xblockexpression = null;
    {
      String _simpleName = GrammarAccessFragment2.class.getSimpleName();
      String _plus = ("The property \'xmlVersion\' has been specified for this " + _simpleName);
      String _plus_1 = (_plus + ". Therefore, the grammar is persisted as XMI and not as binary. This can be a performance drawback.");
      GrammarAccessFragment2.LOG.warn(_plus_1);
      _xblockexpression = GrammarUtil.getClasspathRelativePathToXmi(copy);
    }
    _xifexpression = _xblockexpression;
  }
  final String path = _xifexpression;
  final URI uri = this.getProjectConfig().getRuntime().getSrcGen().getURI(path);
  final Resource resource = resourceSet.createResource(uri, ContentHandler.UNSPECIFIED_CONTENT_TYPE);
  HashSet<Grammar> _hashSet = new HashSet<Grammar>();
  this.addAllGrammarsToResource(resource, copy, _hashSet);
  isSaving.set(Boolean.valueOf(true));
  final Map<String, Object> saveOptions = CollectionLiterals.<String, Object>newHashMap();
  if ((resource instanceof XMLResource)) {
    String _elvis = null;
    if (this.xmlVersion != null) {
      _elvis = this.xmlVersion;
    } else {
      _elvis = "1.0";
    }
    ((XMLResource)resource).setXMLVersion(_elvis);
  } else {
    if ((resource instanceof BinaryResourceImpl)) {
      saveOptions.put(BinaryResourceImpl.OPTION_VERSION, BinaryResourceImpl.BinaryIO.Version.VERSION_1_1);
      saveOptions.put(BinaryResourceImpl.OPTION_STYLE_DATA_CONVERTER, Boolean.valueOf(true));
    }
  }
  try {
    resource.save(saveOptions);
  } catch (final Throwable _t) {
    if (_t instanceof IOException) {
      final IOException e = (IOException)_t;
      GrammarAccessFragment2.LOG.error(e.getMessage(), e);
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  } finally {
    isSaving.set(Boolean.valueOf(false));
  }
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:59,代码来源:GrammarAccessFragment2.java


注:本文中的org.eclipse.xtext.EcoreUtil2.clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。