本文整理汇总了Java中org.eclipse.xtext.resource.XtextResourceSet类的典型用法代码示例。如果您正苦于以下问题:Java XtextResourceSet类的具体用法?Java XtextResourceSet怎么用?Java XtextResourceSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XtextResourceSet类属于org.eclipse.xtext.resource包,在下文中一共展示了XtextResourceSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createResourceSet
import org.eclipse.xtext.resource.XtextResourceSet; //导入依赖的package包/类
/**
* Creates the common resource set to use during compilation. Installs a light weight index.
*
* @return the resource set
*/
private ResourceSet createResourceSet() {
// TODO try to reuse code from IN4JSCore.createResourceSet
XtextResourceSet resourceSet = xtextResourceSetProvider.get();
resourceSet.setClasspathURIContext(classLoader);
// Install containerState as adapter.
resourceSet.eAdapters().add(new DelegatingIAllContainerAdapter(rsbAcs));
// Install a lightweight index.
OrderedResourceDescriptionsData index = new OrderedResourceDescriptionsData(Collections.emptyList());
ResourceDescriptionsData.ResourceSetAdapter.installResourceDescriptionsData(resourceSet, index);
return resourceSet;
}
示例2: mergeContent
import org.eclipse.xtext.resource.XtextResourceSet; //导入依赖的package包/类
/**
* Merges the content of two {@link ProjectDescription project description} instances that are representing the
* actual N4JS manifests.
*
* @param fromLocation
* the source location. These attributes and references will be merged to the other one given with the
* {@code toLocation}.
* @param toLocation
* the target location. The project description that has to be updated with the content of the
* {@code fromLocation}.
* @return the merged project description that has been detached from its resource.
*/
public ProjectDescription mergeContent(final URI fromLocation, final URI toLocation) {
final XtextResourceSet fromResourceSet = getResourceSet(fromLocation);
final XtextResourceSet toResourceSet = getResourceSet(toLocation);
if (null == fromResourceSet || null == toResourceSet) {
return null;
}
try {
final Resource from = fromResourceSet.getResource(fromLocation, true);
final Resource to = toResourceSet.getResource(toLocation, true);
return mergeContent(from, to);
} catch (final Exception e) {
LOGGER.error("Error while trying to merge N4JS manifest content. Source URI: " + fromLocation
+ ". Target URI: " + toLocation + ".", e);
}
return null;
}
示例3: loadGexpressionTestFile
import org.eclipse.xtext.resource.XtextResourceSet; //导入依赖的package包/类
public static void loadGexpressionTestFile() {
// Getting the serializer
GExpressionsStandaloneSetup setup = new GExpressionsStandaloneSetup();
Injector injector = setup.createInjectorAndDoEMFRegistration();
GexpressionsPackage.eINSTANCE.eClass();
Serializer serializer = injector.getInstance(Serializer.class);
// Load the model
URI modelURI = URI
.createFileURI("/home/flatombe/thesis/gemoc/git/gemoc-dev/org/eclipse/gemoc/GEL/org.eclipse.gemoc.gel.gexpressions.test/model/test.gexpressions");
XtextResourceSet resSet = injector.getInstance(XtextResourceSet.class);
resSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
Resource resource = resSet.getResource(modelURI, true);
GProgram program = (GProgram) resource.getContents().get(0);
List<GExpression> exps = program.getExpressions();
for (GExpression exp : exps) {
// Serializing
String s = serializer.serialize(exp);
System.out.println(s);
}
}
示例4: convertERDSLtoXMI
import org.eclipse.xtext.resource.XtextResourceSet; //导入依赖的package包/类
public static void convertERDSLtoXMI(String inputM, String outputM) {
Injector injector = new QueryITStandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
URI uri = URI.createURI(inputM);
Resource xtextResource = resourceSet.getResource(uri, true);
EcoreUtil.resolveAll(xtextResource);
Resource xmiResource = resourceSet.createResource(URI.createURI(outputM));
xmiResource.getContents().add(xtextResource.getContents().get(0));
try {
xmiResource.save(null);
System.out.println("Saved " + outputM);
System.out.println("QueryIT file converted successfully to XMI");
System.out.println("-------------------------------------");
} catch (IOException e) {
e.printStackTrace();
}
}
示例5: testSameScopeUseTwice
import org.eclipse.xtext.resource.XtextResourceSet; //导入依赖的package包/类
/**
* Tests that querying the same scope twice doesn't make the resource set grow.
*/
@Test
public void testSameScopeUseTwice() {
XtextResourceSet rs = new XtextResourceSet();
URL url = createURL();
ModelLocation modelLocation = createModelLocation(url);
CatalogFromExtensionPointScope scope = new TestScope(modelLocation, rs);
assertResourceSetEmpty(rs);
Iterable<IEObjectDescription> elements = scope.getAllElements();
assertIterableNotEmpty(elements);
int nofResourcesInMap = rs.getURIResourceMap().size();
int nofResourcesInSet = rs.getResources().size();
elements = scope.getAllElements();
assertIterableNotEmpty(elements);
assertResourceSet(rs, nofResourcesInSet, nofResourcesInMap);
}
示例6: registerReferencedGenModels
import org.eclipse.xtext.resource.XtextResourceSet; //导入依赖的package包/类
/**
* @since 2.0
*/
@Deprecated
protected void registerReferencedGenModels() {
try {
if (getReferencedGenModels() != null && getReferencedGenModels().length() > 0) {
ResourceSet rs = new XtextResourceSet();
GenModelHelper gmh = new GenModelHelper();
for (String uriStr : getReferencedGenModels().split(",")) {
URI uri = URI.createURI(uriStr.trim());
gmh.registerGenModel(rs, uri);
}
}
} catch (ConfigurationException ce) {
throw ce;
} catch (Exception e) {
log.error(e, e);
}
}
示例7: getClassLoader
import org.eclipse.xtext.resource.XtextResourceSet; //导入依赖的package包/类
public ClassLoader getClassLoader(ResourceSet resourceSet) {
if (resourceSet instanceof XtextResourceSet) {
XtextResourceSet xtextResourceSet = (XtextResourceSet) resourceSet;
Object ctx = xtextResourceSet.getClasspathURIContext();
if (ctx != null) {
if (ctx instanceof Class<?>) {
return ((Class<?>)ctx).getClassLoader();
}
if (!(ctx instanceof ClassLoader)) {
return ctx.getClass().getClassLoader();
}
return (ClassLoader) ctx;
}
}
return classLoader;
}
示例8: getResourceFor
import org.eclipse.xtext.resource.XtextResourceSet; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public XtextResource getResourceFor(final InputStream stream) {
try {
XtextResourceSet set = get(XtextResourceSet.class);
XtextResource resource = (XtextResource) set.createResource(URI.createURI("Test." + getFileExtension()));
resource.load(stream, null);
initializeTypeProvider(set);
return resource;
// CHECKSTYLE:OFF
} catch (Exception e) {
// CHECKSTYLE:ON
fail(e.getMessage());
}
return null;
}
示例9: doTest
import org.eclipse.xtext.resource.XtextResourceSet; //导入依赖的package包/类
public void doTest(final URI usedPrimaryURI, final URI initialReferencedURI, final URI usedReferencedURI) {
this.referencedResource.setURI(initialReferencedURI);
final byte[] primaryBytes = this.getBytes(this.primaryResource);
final byte[] referencedBytes = this.getBytes(this.referencedResource);
final XtextResourceSet otherResourceSet = this.getNewResourceSet();
final Resource newPrimaryResource = otherResourceSet.createResource(usedPrimaryURI);
this.load(newPrimaryResource, primaryBytes);
final Resource newReferencedResource = otherResourceSet.createResource(usedReferencedURI);
this.load(newReferencedResource, referencedBytes);
EcoreUtil.resolveAll(otherResourceSet);
int _size = otherResourceSet.getResources().size();
boolean _notEquals = (_size != 2);
if (_notEquals) {
throw new UnexpectedResourcesException(otherResourceSet);
}
final Map<EObject, Collection<EStructuralFeature.Setting>> unresolved = EcoreUtil.UnresolvedProxyCrossReferencer.find(otherResourceSet);
boolean _isEmpty = unresolved.isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
throw new UnexpectedProxiesException(unresolved);
}
}
示例10: exportXMI
import org.eclipse.xtext.resource.XtextResourceSet; //导入依赖的package包/类
private void exportXMI(String inM, String outM) {
// change MyLanguage with your language name
Injector injector = new ODMParameterStandaloneSetupGenerated()
.createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector
.getInstance(XtextResourceSet.class);
// .ext is the extension of the model file
String inputURI =inM;//"tests/movies.odm";
String outputURI =outM;//"tests/movies_dsl_output.xmi";
System.out.println(inputURI+" "+outputURI);
URI uri = URI.createURI(inputURI);
Resource xtextResource = resourceSet.getResource(uri, true);
EcoreUtil.resolveAll(xtextResource);
Resource xmiResource = resourceSet
.createResource(URI.createURI(outputURI));
xmiResource.getContents().add(xtextResource.getContents().get(0));
try {
xmiResource.save(null);
} catch (IOException e) {
e.printStackTrace();
}
}
示例11: getCompleteContent
import org.eclipse.xtext.resource.XtextResourceSet; //导入依赖的package包/类
public static String getCompleteContent(XtextResource xr) throws IOException, UnsupportedEncodingException {
XtextResourceSet resourceSet = (XtextResourceSet) xr.getResourceSet();
URIConverter uriConverter = resourceSet.getURIConverter();
URI uri = xr.getURI();
String encoding = xr.getEncoding();
InputStream inputStream = null;
try {
inputStream = uriConverter.createInputStream(uri);
return getCompleteContent(encoding, inputStream);
} finally {
tryClose(inputStream, null);
}
}
示例12: loadResource
import org.eclipse.xtext.resource.XtextResourceSet; //导入依赖的package包/类
public static Resource loadResource(String string, XtextResourceSet resourceSet) {
URI uri = URI.createURI(string);
Resource resource;
try {
resource = resourceSet.getResource(uri, true);
if (resource == null) {
throw new IllegalArgumentException("Couldn't create resource for URI : " + uri);
}
} catch (Exception e) {
throw new WrappedException(e);
}
EList<EObject> contents = resource.getContents();
if (contents.size() < 1) {
throw new IllegalStateException("loading classpath:" + string + " : Expected at least root element but found "
+ contents.size());
}
return resource;
}
示例13: getContainedURIs
import org.eclipse.xtext.resource.XtextResourceSet; //导入依赖的package包/类
@Override
public Collection<URI> getContainedURIs(String containerHandle) {
if (!HANDLE.equals(containerHandle))
return Collections.emptySet();
if (resourceSet instanceof XtextResourceSet) {
ResourceDescriptionsData descriptionsData = findResourceDescriptionsData(resourceSet);
if (descriptionsData != null) {
return descriptionsData.getAllURIs();
}
return newArrayList(((XtextResourceSet) resourceSet).getNormalizationMap().values());
}
List<URI> uris = Lists.newArrayListWithCapacity(resourceSet.getResources().size());
URIConverter uriConverter = resourceSet.getURIConverter();
for (Resource r : resourceSet.getResources())
uris.add(uriConverter.normalize(r.getURI()));
return uris;
}
示例14: containsURI
import org.eclipse.xtext.resource.XtextResourceSet; //导入依赖的package包/类
@Override
public boolean containsURI(String containerHandle, URI candidateURI) {
if (!HANDLE.equals(containerHandle))
return false;
if (resourceSet instanceof XtextResourceSet) {
ResourceDescriptionsData descriptionsData = findResourceDescriptionsData(resourceSet);
if (descriptionsData != null) {
return descriptionsData.getResourceDescription(candidateURI) != null;
}
Collection<URI> allUris = ((XtextResourceSet) resourceSet).getNormalizationMap().values();
for (URI uri : allUris) {
if (uri.equals(candidateURI)) {
return true;
}
}
return false;
}
URIConverter uriConverter = resourceSet.getURIConverter();
for (Resource r : resourceSet.getResources()) {
URI normalized = uriConverter.normalize(r.getURI());
if (normalized.equals(candidateURI)) {
return true;
}
}
return false;
}
示例15: build
import org.eclipse.xtext.resource.XtextResourceSet; //导入依赖的package包/类
public IncrementalBuilder.Result build(final BuildRequest request, final Function1<? super URI, ? extends IResourceServiceProvider> languages, final IResourceClusteringPolicy clusteringPolicy) {
try {
final XtextResourceSet resourceSet = request.getResourceSet();
ResourceDescriptionsData _copy = request.getState().getResourceDescriptions().copy();
Source2GeneratedMapping _copy_1 = request.getState().getFileMappings().copy();
final IndexState oldState = new IndexState(_copy, _copy_1);
CancelIndicator _cancelIndicator = request.getCancelIndicator();
final BuildContext context = new BuildContext(languages, resourceSet, oldState, clusteringPolicy, _cancelIndicator);
final IncrementalBuilder.InternalStatefulIncrementalBuilder builder = this.provider.get();
builder.context = context;
builder.request = request;
try {
return builder.launch();
} catch (final Throwable _t) {
if (_t instanceof Throwable) {
final Throwable t = (Throwable)_t;
this._operationCanceledManager.propagateIfCancelException(t);
throw t;
} else {
throw Exceptions.sneakyThrow(_t);
}
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}