本文整理汇总了Java中org.eclipse.emf.common.util.URI.lastSegment方法的典型用法代码示例。如果您正苦于以下问题:Java URI.lastSegment方法的具体用法?Java URI.lastSegment怎么用?Java URI.lastSegment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.emf.common.util.URI
的用法示例。
在下文中一共展示了URI.lastSegment方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: takeSnapshotInGraphView
import org.eclipse.emf.common.util.URI; //导入方法依赖的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
}
}
示例2: getN4JSProject
import org.eclipse.emf.common.util.URI; //导入方法依赖的package包/类
@Override
public N4JSEclipseProject getN4JSProject(URI location) {
checkArgument(
location.isPlatformResource() || location.isFile(),
"Expected either platform:/resource or file:/ URI. Was: " + location);
if (location.isPlatformResource() && location.segmentCount() != DIRECT_RESOURCE_IN_PROJECT_SEGMENTCOUNT) {
checkArgument(
DIRECT_RESOURCE_IN_PROJECT_SEGMENTCOUNT == location.segmentCount(),
"Expected 2 segment counts for platform resource URI. Was " + location.segmentCount());
}
final String projectName = location.lastSegment();
final IProject project;
if (location.isFile()) {
project = externalLibraryWorkspace.getProject(projectName);
checkNotNull(project, "Project does not exist in external workspace. URI: " + location);
} else {
project = workspace.getProject(projectName);
}
return doGetN4JSProject(project, location);
}
示例3: getTargetDescription
import org.eclipse.emf.common.util.URI; //导入方法依赖的package包/类
private String getTargetDescription(XtextResource resource, IHyperlink hyperlink) {
final StringBuffer sb = new StringBuffer();
// append hyperlink text. Only consider the element name and ignore the qualified part.
String hyperlinkText = hyperlink.getHyperlinkText();
hyperlinkText = hyperlinkText.substring(hyperlinkText.lastIndexOf('.') + 1);
if (hyperlinkText != null)
sb.append(hyperlinkText);
else
sb.append("<no hyperlink text>");
// append description of target element (path from the element to the root of the AST)
final EObject target = getTarget(resource, hyperlink);
if (target != null) {
// build chain of ancestor AST elements
sb.append(": ");
final int startLen = sb.length();
EObject currTarget = target;
while (currTarget != null) {
if (currTarget instanceof NamedElement || currTarget instanceof IdentifiableElement) {
if (sb.length() > startLen)
sb.append(" in ");
String name = currTarget instanceof NamedElement ? ((NamedElement) currTarget).getName()
: ((IdentifiableElement) currTarget).getName();
if (name == null || name.trim().length() == 0)
name = "<unnamed>";
else
name = "\"" + name + "\"";
sb.append(name + "(" + currTarget.eClass().getName() + ")");
}
currTarget = currTarget.eContainer();
}
// add URI of resource
final URI targetResURI = target.eResource() != null ? target.eResource().getURI() : null;
final String fname = targetResURI != null ? targetResURI.lastSegment() : null;
if (fname != null && fname.trim().length() > 0) {
sb.append(" in file ");
sb.append(fname);
}
}
return sb.toString();
}
示例4: getFolderIterator
import org.eclipse.emf.common.util.URI; //导入方法依赖的package包/类
@Override
public Iterator<URI> getFolderIterator(URI folderLocation) {
ensureInitialized();
final URI findProjectWith = findProjectWith(folderLocation);
if (null != findProjectWith) {
final String projectName = findProjectWith.lastSegment();
final ExternalProject project = getProjectMapping().get(projectName);
if (null != project) {
String projectPath = new File(project.getLocationURI()).getAbsolutePath();
String folderPath = folderLocation.toFileString();
final IContainer container = projectPath.equals(folderPath) ? project
: project.getFolder(folderPath.substring(projectPath.length() + 1));
final Collection<URI> result = Lists.newLinkedList();
try {
container.accept(resource -> {
if (resource instanceof IFile) {
final String path = new File(resource.getLocationURI()).getAbsolutePath();
result.add(URI.createFileURI(path));
}
return true;
});
return unmodifiableIterator(result.iterator());
} catch (CoreException e) {
return unmodifiableIterator(result.iterator());
}
}
}
return emptyIterator();
}
示例5: getNode
import org.eclipse.emf.common.util.URI; //导入方法依赖的package包/类
@Override
public Node getNode(Object element) {
final String type;
final String name;
final String desc;
if (element instanceof Resource) {
// case: Resource
final URI uri = ((Resource) element).getURI();
type = "Resource";
name = uri != null ? uri.lastSegment() : null;
desc = null;
} else if (element instanceof EObject) {
final EObject eobj = (EObject) element;
if (eobj.eIsProxy()) {
// case: proxy
type = "PROXY(" + eobj.eClass().getName() + ")";
name = null;
desc = "proxy URI:\n" + EcoreUtil.getURI(eobj);
} else {
// case: non-proxy EObject
type = eobj.eClass().getName();
name = getName(eobj);
desc = getDescription(eobj);
}
} else {
// case: any POJO
type = element.getClass().getSimpleName();
name = null;
desc = null;
}
final String title = type + (name != null ? " " + name : "");
return new Node(element, title, desc);
}
示例6: removeFileName
import org.eclipse.emf.common.util.URI; //导入方法依赖的package包/类
/**
* return the uri without its last segment
* if the uri doesn't have a last segment (ex: http://spoon ), returns the uri itself
* @param uri
* @return
*/
static public String removeFileName(String uri) {
URI u = URI.createURI(uri);
if(u.lastSegment() != null)
return u.toString().replace(u.lastSegment(), "");
else return uri;
}
示例7: descriptionToNameWithPosition
import org.eclipse.emf.common.util.URI; //导入方法依赖的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;
}
示例8: simpleURIString
import org.eclipse.emf.common.util.URI; //导入方法依赖的package包/类
static String simpleURIString(URI uri) {
if (uri == null)
return "!!null!!";
return uri.lastSegment() + "#" + uri.fragment();
}
示例9: getResource
import org.eclipse.emf.common.util.URI; //导入方法依赖的package包/类
@Override
public IResource getResource(URI location) {
ensureInitialized();
final String path = location.toFileString();
if (null == path) {
return null;
}
final File nestedResource = new File(path);
if (nestedResource.exists()) {
final URI projectLocation = findProjectWith(location);
if (null != projectLocation) {
final String projectName = projectLocation.lastSegment();
final IProject project = getProject(projectName);
if (project instanceof ExternalProject) {
final File projectResource = new File(project.getLocationURI());
if (projectResource.exists() && projectResource.isDirectory()) {
final Path projectPath = projectResource.toPath();
final Path nestedPath = nestedResource.toPath();
if (projectPath.equals(nestedPath)) {
return project;
}
// TODO: project.getFile and project.getFolder don't check whether then given path is a file or
// a folder, and they should not?
final Path relativePath = projectPath.relativize(nestedPath);
final IFile file = project.getFile(relativePath.toString());
if (file.exists())
return file;
final IFolder folder = project.getFolder(relativePath.toString());
if (folder.exists())
return folder;
}
}
}
}
return null;
}