本文整理汇总了Java中org.eclipse.emf.ecore.resource.Resource.getURI方法的典型用法代码示例。如果您正苦于以下问题:Java Resource.getURI方法的具体用法?Java Resource.getURI怎么用?Java Resource.getURI使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.emf.ecore.resource.Resource
的用法示例。
在下文中一共展示了Resource.getURI方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testLoadingBuiltInTypes
import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
@SuppressWarnings("javadoc")
@Test
public void testLoadingBuiltInTypes() {
BuiltInTypeScope scope = BuiltInTypeScope.get(resourceSet);
IEObjectDescription anyType = scope.getSingleElement(QualifiedName.create("any"));
Assert.assertNotNull(anyType);
String s = "";
for (Resource resource : resourceSet.getResources()) {
if (resource.getErrors().size() > 0) {
for (Diagnostic d : resource.getErrors()) {
s += "\n " + d.getMessage() + " at " + resource.getURI() + ":" + d.getLine();
}
}
}
Assert.assertEquals("Resources definine built-in types must have no error."
, "", s);
}
示例2: takeSnapshotInGraphView
import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
/**
* Add a snapshot of the current state of 'root' to the {@code ASTGraphView}. Does nothing if in headless mode or
* the {@code ASTGraphView} is not installed or unavailable for some other reason. May be invoked from non-UI
* threads.
* <p>
* A copy of all required information is taken on the invoking thread before this method returns, so it is safe to
* change 'root' or its contents right after this method returns.
* <p>
* If 'root' is a {@link Resource} or an {@link EObject} contained in a {@code Resource}, then the name of the
* (containing) resource will be appended to the label.
*
* @param label
* the label for the new graph or <code>null</code>.
* @param root
* the root object to create the graph from; must be a {@link ResourceSet}, {@link Resource}, or
* {@link EObject}.
* @throws IllegalArgumentException
* if 'root' is <code>null</code> or of incorrect type.
*/
public static final void takeSnapshotInGraphView(String label, Object root) {
if (!(root instanceof ResourceSet || root instanceof Resource || root instanceof EObject))
throw new IllegalArgumentException("root must be a ResourceSet, Resource, or EObject");
// append name of root's containing resource to label (if any)
final Resource resource = root instanceof Resource ? (Resource) root
: (root instanceof EObject ? ((EObject) root).eResource() : null);
final URI uri = resource != null ? resource.getURI() : null;
final String name = uri != null ? uri.lastSegment() : null;
if (name != null)
label = label + " (" + name + ")";
// send request to ASTGraphView
try {
// we don't want a dependency on the debug bundle where ASTGraphView is located, so use reflection
final Bundle testViewBundle = Platform.getBundle("org.eclipse.n4js.smith.graph");
final Class<?> testViewClass = testViewBundle.loadClass("org.eclipse.n4js.smith.graph.ASTGraphView");
final Method m = testViewClass.getMethod("show", String.class, Object.class);
m.invoke(null, label, root);
} catch (Throwable e) {
// ignore
}
}
示例3: loadResources
import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
/**
* Load all resources of the given marked project.
*
* @param markedProject
* the project to load
* @param recorder
* the progress recorder
* @throws N4JSCompileErrorException
* if an error occurs while loading the resources
*/
private void loadResources(MarkedProject markedProject, N4ProgressStateRecorder recorder)
throws N4JSCompileErrorException {
if (logger.isCreateDebugOutput()) {
logger.debug("Loading resources for project " + markedProject.project.getProjectId());
}
for (Resource resource : markedProject.resources) {
try {
if (logger.isCreateDebugOutput()) {
logger.debug(" Loading resource " + resource.getURI());
}
resource.load(Collections.EMPTY_MAP);
} catch (IOException e) {
recorder.markLoadResourceFailed(resource);
String message = "Cannot load resource=" + resource.getURI();
if (!isKeepOnCompiling()) {
throw new N4JSCompileErrorException(message, markedProject.project.getProjectId(), e);
}
logger.warn(message);
}
}
}
示例4: indexResource
import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
/**
* Install the given resource's description into the given index. Raw JavaScript files will not be indexed. Note
* that when this method is called for the given resource, it is not yet fully processed and therefore the
* serialized type model is not added to the index.
* <p>
* This is due to the fact that we keep a common resource set for all projects that contains the resources of all
* projects with unprocessed dependencies, unlike in the IDE case where we have one resource set per open document
* and load the type models from the index.
* </p>
* <p>
* Since the type models are available in the resource set as long as they may still be referenced, they need not be
* serialized and stored into the index.
* </p>
*
* @param resource
* the resource to be indexed
* @param index
* the index to add the given resource to
*/
private void indexResource(Resource resource, ResourceDescriptionsData index) {
if (!shouldIndexResource(resource))
return;
final URI uri = resource.getURI();
IResourceServiceProvider serviceProvider = IResourceServiceProvider.Registry.INSTANCE
.getResourceServiceProvider(uri);
if (serviceProvider != null) {
if (logger.isCreateDebugOutput()) {
logger.debug(" Indexing resource " + uri);
}
IResourceDescription.Manager resourceDescriptionManager = serviceProvider.getResourceDescriptionManager();
IResourceDescription resourceDescription = resourceDescriptionManager.getResourceDescription(resource);
if (resourceDescription != null) {
index.addDescription(uri, resourceDescription);
}
}
}
示例5: shouldIndexResource
import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
/**
* Indicates whether or not the given resource should be indexed.
*
* @param resource
* the resource to be indexed
* @return <code>true</code> if the given resource should be indexed and <code>false</code> otherwise
*/
private boolean shouldIndexResource(Resource resource) {
final URI uri = resource.getURI();
final ResourceType resourceType = ResourceType.getResourceType(uri);
// We only want to index raw JS files if they are contained in an N4JS source container.
switch (resourceType) {
case JS:
return n4jsCore.findN4JSSourceContainer(uri).isPresent();
case JSX:
return n4jsCore.findN4JSSourceContainer(uri).isPresent();
case UNKOWN:
return false;
default:
return true;
}
}
示例6:
import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
/**
* Removes all non-N4 resources from the given resource set without sending any notification about the removal. This
* specific resource set cleaning is required to avoid the accidental removal of the resources holding the built-in
* types. For more details reference: IDEBUG-491.
*
* @param resourceSet
* the resource set to clean. Optional, can be {@code null}. If {@code null} this method has no effect.
*/
/* default */static void clearResourceSet(final ResourceSet resourceSet) {
boolean wasDeliver = resourceSet.eDeliver();
try {
resourceSet.eSetDeliver(false);
for (final Iterator<Resource> itr = resourceSet.getResources().iterator(); itr.hasNext(); /**/) {
final Resource resource = itr.next();
final URI uri = resource.getURI();
if (!isN4Scheme(uri)) {
itr.remove();
} else {
LOGGER.info("Intentionally skipping the removal of N4 resource: " + uri);
}
}
} finally {
resourceSet.eSetDeliver(wasDeliver);
}
}
示例7: fileExtensionPredicate
import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
/**
* This method check if the extension of the resource file associated with
* the Sirius session is provided by viewpoint specifier.
*
* @return True if the current page can be used with the current resource.
* @generated
*/
protected boolean fileExtensionPredicate() {
final EObject rootSemanticModel = ActivityExplorerManager.INSTANCE.getRootSemanticModel();
final Resource eResource = rootSemanticModel.eResource();
if (null == eResource)
return false;
final URI resourceURI = eResource.getURI();
if (null == resourceURI)
return false;
final List<String> allowedFileExtensions = Arrays.asList("fileExtension");
final String fileExtension = resourceURI.fileExtension().toLowerCase();
return allowedFileExtensions.contains(fileExtension);
}
示例8: collectTransitivelyDependentResources
import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
private List<Resource> collectTransitivelyDependentResources(XtextResource resource,
Set<URI> deltaURIs) {
List<Resource> result = Lists.newArrayList();
ResourceSet resourceSet = resource.getResourceSet();
for (Resource candidate : resourceSet.getResources()) {
if (candidate != resource) {
URI uri = candidate.getURI();
if (deltaURIs.contains(uri)) {
// the candidate is contained in the delta list
// schedule it for unloading
result.add(candidate);
} else if (candidate instanceof N4JSResource) {
// the candidate does depend on one of the changed resources
// schedule it for unloading
if (canLoadFromDescriptionHelper.dependsOnAny(candidate, deltaURIs)) {
result.add(candidate);
}
}
}
}
return result;
}
示例9: resolveUri
import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
@Override
public String resolveUri ( final String uri )
{
final Resource r = this.symbol.eResource ();
if ( r == null )
{
return uri;
}
final URI u = r.getURI ();
if ( u == null )
{
return uri;
}
logger.debug ( "Resolve - base: {}, uri: {}", u, uri );
return URI.createURI ( uri ).resolve ( u ).toString ();
}
示例10: getIFile
import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
/**
* Getting an IFile from an EMF Resource
*
* @param eObject
* @return
*/
public static IFile getIFile(Resource res) {
URI uri = res.getURI();
String filePath = uri.toPlatformString(true);
IFile ifile = ResourcesPlugin.getWorkspace().getRoot()
.getFile(new Path(filePath));
return ifile;
}
示例11: getServiceForContext
import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
/**
* Same as {@link #getServiceForContext(URI, Class)}, but accepts any {@link EObject} contained in an Xtext language
* resource. Returns <code>null</code> if the given context object is not contained in a {@link Resource}.
*/
public static <T> Optional<T> getServiceForContext(EObject context, Class<T> serviceType) {
Objects.requireNonNull(context);
Objects.requireNonNull(serviceType);
final Resource res = context.eResource();
final URI uri = res != null ? res.getURI() : null;
return uri != null ? getServiceForContext(uri, serviceType) : Optional.empty();
}
示例12: createMarker
import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
@Override
public void createMarker(Resource res, String message, Severity severity) {
final int severityEclipse;
switch (severity) {
case INFO:
severityEclipse = IMarker.SEVERITY_INFO;
break;
case WARNING:
severityEclipse = IMarker.SEVERITY_WARNING;
break;
default:
severityEclipse = IMarker.SEVERITY_ERROR;
break;
}
try {
IMarker marker = toIFile(res).createMarker(MARKER__ORG_ECLIPSE_IDE_N4JS_UI_COMPILER_ERROR);
marker.setAttribute(IMarker.MESSAGE, message);
marker.setAttribute(IMarker.SEVERITY, severityEclipse);
marker.setAttribute(IMarker.LINE_NUMBER, 1);
} catch (CoreException e) {
LOGGER.error(e.getStatus());
String resInfo = "";
if (res != null) {
if (res.getURI() != null) {
resInfo = "on resource with uri=" + res.getURI();
} else {
resInfo = "on resource=" + res;
}
}
throw new RuntimeException("Cannot create error marker with message='" + message + "' " + resInfo + ".", e);
}
}
示例13: isInSourceFolder
import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
private boolean isInSourceFolder(Resource resource) {
URI uri = resource.getURI();
Optional<? extends IN4JSSourceContainer> sourceContainerOpt = eclipseCore.findN4JSSourceContainer(uri);
if (sourceContainerOpt.isPresent()) {
IN4JSSourceContainer sourceContainer = sourceContainerOpt.get();
return !sourceContainer.isLibrary() && !sourceContainer.isExternal();
}
return false;
}
示例14: getSourceName
import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
@Override
public String getSourceName ()
{
final Resource r = this.symbol.eResource ();
if ( r != null && r.getURI () == null )
{
return r.getURI ().toString ();
}
else
{
return "<unknown>";
}
}
示例15: descriptionToNameWithPosition
import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
/**
* Returns a string with name and position of the described object. The position is specified by line number (if
* possible, otherwise the uri fragment of the proxy is used). If the object is a {@link SyntaxRelatedTElement}, a
* "T" is used as a prefix of the line number.
*
* The following examples shows different mappings, depending on the described object:
* <table>
* <tr>
* <th>Mapping</th>
* <th>Described Object</th>
* </tr>
* <tr>
* <td><code>bar - 42</code></td>
* <td>Some element "bar", located in same resource on line 42</td>
* </tr>
* <tr>
* <td><code>foo - T23</code></td>
* <td>A type "foo" (or other syntax related element, a function is a type) which syntax related element (from which
* the type is build) is located in same file on line 23</td>
* </tr>
* <tr>
* <td><code>Infinity - global.n4ts:3</code></td>
* <td>An element "Infinity", located in another resource "global.n4ts" on line 3.</td>
* </tr>
* <tr>
* <td><code>decodeURI - global.n4ts:11</code></td>
* <td>An element "decodeURI", located in another resource "global.n4ts" on line 11. Although the element may be a
* type, there is no syntax related element because "n4ts" directly describes types.</td>
* </tr>
* </table>
*
* @param currentURI
* the current resource's URI, if described object is in same resource, resource name is omitted
* @param desc
* the object descriptor
*/
public static String descriptionToNameWithPosition(URI currentURI, boolean withLineNumber,
IEObjectDescription desc) {
String name = desc.getName().toString();
EObject eobj = desc.getEObjectOrProxy();
if (eobj == null) {
return "No EObject or proxy for " + name + " at URI " + desc.getEObjectURI();
}
String location = "";
if (eobj instanceof SyntaxRelatedTElement) {
EObject syntaxElement = ((SyntaxRelatedTElement) eobj).getAstElement();
if (syntaxElement != null) {
location += "T";
eobj = syntaxElement;
}
}
Resource eobjRes = eobj.eResource();
URI uri = eobjRes == null ? null : eobjRes.getURI();
if (uri != currentURI && uri != null) {
location = uri.lastSegment();
if (eobj.eIsProxy() || withLineNumber) {
location += ":";
}
}
if (eobj.eIsProxy()) {
URI proxyUri = desc.getEObjectURI();
location += "proxy:" + simpleURIString(proxyUri);
} else if (withLineNumber) {
INode node = NodeModelUtils.findActualNodeFor(eobj);
if (node == null) {
location += "no node:" + simpleURIString(desc.getEObjectURI());
} else {
location += node.getStartLine();
}
}
return name + SEPARATOR + location;
}