Java Code Examples for org.eclipse.emf.common.util.URI#fragment()
The following examples show how to use
org.eclipse.emf.common.util.URI#fragment() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QNameURIHandler.java From fixflow with Apache License 2.0 | 6 votes |
/** * Called from the framework during save. We deresolve absolute URIs to relative ones. Then we try to * convert to QName */ @Override public URI deresolve(URI uri) { String fragment = uri.fragment(); if (fragment != null && !fragment.startsWith("/")) // We better don't try to QName XPath references to e.g. XML or WSDL context for now. { String prefix = ""; if (uri.hasPath()) { prefix = xmlHelper.getNsPrefix(uri.trimFragment()); } if (prefix.length() > 0) { return URI.createURI(prefix + ":" + fragment); } else // no prefix, just fragment (i.e. without the '#') return URI.createURI(fragment); } return super.deresolve(uri); }
Example 2
Source File: TestResultsView.java From n4js with Eclipse Public License 1.0 | 6 votes |
private void openTestClass(TestSuite testSuite) { Optional<TestCase> foundTestCase = testSuite.getTestCases().stream().findFirst(); if (foundTestCase.isPresent()) { final URI testCaseURI = foundTestCase.get().getURI(); final URI moduleLocation = testCaseURI.trimFragment(); if (!openErrorIfProblem(moduleLocation)) { String caseFragment = testCaseURI.fragment(); if (caseFragment != null) { int lastAt = caseFragment.lastIndexOf("/@"); if (lastAt >= 0) { // open at class String classFragment = caseFragment.substring(0, lastAt); URI classLocation = moduleLocation.appendFragment(classFragment); uriOpener.open(classLocation, true); } } else { // just open the file uriOpener.open(moduleLocation, true); } } } }
Example 3
Source File: ResourceStorageWritable.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected void writeContents(StorageAwareResource storageAwareResource, OutputStream outputStream) throws IOException { BinaryResourceImpl.EObjectOutputStream out = new BinaryResourceImpl.EObjectOutputStream(outputStream, Collections.emptyMap()) { @Override public void writeURI(URI uri, String fragment) throws IOException { URI fullURI = uri.appendFragment(fragment); URI portableURI = storageAwareResource.getPortableURIs().toPortableURI(storageAwareResource, fullURI); URI uriToWrite = portableURI == null ? fullURI : portableURI; super.writeURI(uriToWrite.trimFragment(), uriToWrite.fragment()); } @Override public void saveEObject(InternalEObject internalEObject, BinaryResourceImpl.EObjectOutputStream.Check check) throws IOException { beforeSaveEObject(internalEObject, this); super.saveEObject(internalEObject, check); handleSaveEObject(internalEObject, this); } }; try { out.saveResource(storageAwareResource); } finally { out.flush(); } }
Example 4
Source File: BundleClasspathUriResolver.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public URI resolve(Object context, URI classpathUri) { if (context instanceof Plugin) { context = ((Plugin) context).getBundle(); } if (!(context instanceof Bundle)) { throw new IllegalArgumentException("Context must implement Bundle"); } Bundle bundle = (Bundle) context; try { if (ClasspathUriUtil.isClasspathUri(classpathUri)) { URI result = findResourceInBundle(bundle, classpathUri); if (classpathUri.fragment() != null) result = result.appendFragment(classpathUri.fragment()); return result; } } catch (Exception exc) { throw new ClasspathUriResolutionException(exc); } return classpathUri; }
Example 5
Source File: WorkspaceClasspathUriResolver.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public URI resolve(Object context, URI classpathUri) { if(!(context instanceof IResource)) { throw new IllegalArgumentException("Context must implement IResource"); } IResource resource = (IResource) context; try { if (ClasspathUriUtil.isClasspathUri(classpathUri)) { IProject project = resource.getProject(); IJavaProject javaProject = JavaCore.create(project); URI result = findResourceInWorkspace(javaProject, classpathUri); if (classpathUri.fragment() != null) result = result.appendFragment(classpathUri.fragment()); return result; } } catch (Exception exc) { throw new ClasspathUriResolutionException(exc); } return classpathUri; }
Example 6
Source File: JdtClasspathUriResolver.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public URI resolve(Object context, URI classpathUri) { if (!(context instanceof IJavaElement)) { throw new IllegalArgumentException("Context must implement IResource"); } javaElement = (IJavaElement) context; try { if (ClasspathUriUtil.isClasspathUri(classpathUri)) { IJavaProject javaProject = javaElement.getJavaProject(); URI result = findResourceInWorkspace(javaProject, classpathUri); if (classpathUri.fragment() != null) result = result.appendFragment(classpathUri.fragment()); return result; } } catch (Exception exc) { throw new ClasspathUriResolutionException(exc); } return classpathUri; }
Example 7
Source File: DiagramEditorProvider.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
protected boolean isAProcessDiagramURI(final URI uri) { final String fragment = uri.fragment(); if (fragment == null) { return true; } else { final EObject eObject = retrieveElementInURIForFragment(uri, fragment); if (eObject instanceof Diagram) { if (((Diagram) eObject).getElement() instanceof MainProcess) { return true; } } } return false; }
Example 8
Source File: InferredModelReferenceFilter.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Checks a model element's URI to determine if it is an inferred model element. * * @param elementURI * the URI to check * @return true if {@code elementURI} is the URI of an inferred model element; false otherwise. */ protected boolean isInferredModelElement(final URI elementURI) { String fragment = elementURI.fragment(); if (fragment.length() > 1) { char firstCharacter = fragment.charAt(1); // Normally, URI fragments of non-inferred elements look like: /0/x/y/z/ // However, there is an exception to this rule, which is WFD that uses a custom FragmentProvider // There, EMF feature names are used and fragments look in the following way: /WfdSource/Wfd/x/y/z // Hence, the first check is needed to handle this case return Character.isDigit(firstCharacter) && firstCharacter != '0'; } return false; }
Example 9
Source File: DirectLinkingPortableURIs.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
@Override public URI toPortableURI(final StorageAwareResource sourceResource, final URI uri) { String fragment = uri.fragment(); if (uriEncoder.isCrossLinkFragment(sourceResource, fragment)) { return uri.trimFragment().appendFragment(UNRESOLVED_LAZY_LINK); } return null; }
Example 10
Source File: TypeURIHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public URI getFullURI(ITypeBinding typeBinding, String method) { SegmentSequence.Builder builder = SegmentSequence.newBuilder(""); URI uri = getFullURI(typeBinding, builder); URI[] uris = COMMON_METHOD_URIS.get(uri.lastSegment()); if (uris != null) { for (URI methodURI : uris) { String fragment = methodURI.fragment(); if (fragment.startsWith(method, fragment.length() - method.length() - 2)) { return methodURI; } } } builder.append(".").append(method).append("()"); return uri.appendFragment(builder.toString()); }
Example 11
Source File: DerivedMemberAwareEditorOpener.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public IEditorPart open(URI uri, IMember member, boolean select) { if (member != null) { URI memberURI = new TypeURIHelper().getFullURI(member); String identifier = memberURI.fragment(); // we decode the qualified name into the uri using query, such that it can be read out in #findEObjectByURI again URI uriWithQuery = uri.appendQuery(identifier); return super.open(uriWithQuery, select); } return open(uri, select); }
Example 12
Source File: EcoreEditorOpener.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override protected void selectAndReveal(IEditorPart openEditor, URI uri, EReference crossReference, int indexInList, boolean select) { if (uri.fragment() != null) { EcoreEditor ecoreEditor = Adapters.adapt(openEditor, EcoreEditor.class); if (ecoreEditor != null) { EObject eObject = ecoreEditor.getEditingDomain().getResourceSet().getEObject(uri, true); ecoreEditor.setSelectionToViewer(Collections.singletonList(eObject)); } } }
Example 13
Source File: BinarySimpleMemberSignature.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public URI getURI() { URI typeURI = type.getURI(); String typeFragment = typeURI.fragment(); if (operation) { return typeURI.appendFragment(typeFragment + "." + String.valueOf(chars) + "()"); } return typeURI.appendFragment(typeFragment + "." + String.valueOf(chars)); }
Example 14
Source File: ScopeProviderAccess.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
/** * Returns a bunch of descriptions most of which are actually {@link IIdentifiableElementDescription describing identifiables}. * The provided iterable is never empty but it may contain a single {@link ErrorDescription error description}. * * @return the available descriptions. */ public Iterable<IEObjectDescription> getCandidateDescriptions(XExpression expression, EReference reference, /* @Nullable */ EObject toBeLinked, IFeatureScopeSession session, IResolvedTypes types) throws IllegalNodeException { if (toBeLinked == null) { return Collections.emptyList(); } if (!toBeLinked.eIsProxy()) { throw new IllegalStateException(expression + " was already linked to " + toBeLinked); } URI uri = EcoreUtil.getURI(toBeLinked); String fragment = uri.fragment(); if (encoder.isCrossLinkFragment(expression.eResource(), fragment)) { INode node = encoder.getNode(expression, fragment); final EClass requiredType = reference.getEReferenceType(); if (requiredType == null) return Collections.emptyList(); final String crossRefString = linkingHelper.getCrossRefNodeAsString(node, true); if (crossRefString != null && !crossRefString.equals("")) { QualifiedName qualifiedLinkName = qualifiedNameConverter.toQualifiedName(crossRefString); if (!qualifiedLinkName.isEmpty()) { final IScope scope = session.getScope(expression, reference, types); Iterable<IEObjectDescription> descriptions = scope.getElements(qualifiedLinkName); if (Iterables.isEmpty(descriptions)) { INode errorNode = getErrorNode(expression, node); if (errorNode != node) { qualifiedLinkName = getErrorName(errorNode); } return Collections.<IEObjectDescription>singletonList(new ErrorDescription(getErrorNode(expression, node), qualifiedLinkName)); } return descriptions; } else { return Collections.<IEObjectDescription>singletonList(new ErrorDescription(null /* followUp problem */)); } } return Collections.emptyList(); } else { throw new IllegalStateException(expression + " uses unsupported uri fragment " + uri); } }
Example 15
Source File: N4JSLanguageSpecificURIEditorOpener.java From n4js with Eclipse Public License 1.0 | 5 votes |
@Override public IEditorPart open(final URI uri, final EReference crossReference, final int indexInList, final boolean select) { String fragment = uri.fragment(); URI trimedFragmentUri = uri.trimFragment(); if (trimedFragmentUri.isFile()) { URI platformUri = URIUtils.tryToPlatformUri(trimedFragmentUri); URI appendedFragmentUri = platformUri.appendFragment(fragment); return super.open(appendedFragmentUri, crossReference, indexInList, select); } return super.open(uri, crossReference, indexInList, select); }
Example 16
Source File: HyperlinkXpectMethod.java From n4js with Eclipse Public License 1.0 | 5 votes |
private EObject getTarget(XtextResource resource, IHyperlink hyperlink) { final ResourceSet resourceSet = resource != null ? resource.getResourceSet() : null; final URI uri = getURI(hyperlink); final EObject target = resourceSet != null && uri != null && uri.fragment() != null ? resourceSet.getEObject(uri, true) : null; if (target instanceof SyntaxRelatedTElement) return ((SyntaxRelatedTElement) target).getAstElement(); return target; }
Example 17
Source File: JvmModelReferenceFilter.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected boolean isInferredJvmElement(URI elementURI) { String fragment = elementURI.fragment(); return !fragment.startsWith("/0") && !fragment.startsWith("//") && !fragment.equals("/"); }
Example 18
Source File: EObjectDescriptionToNameWithPositionMapper.java From n4js with Eclipse Public License 1.0 | 4 votes |
static String simpleURIString(URI uri) { if (uri == null) return "!!null!!"; return uri.lastSegment() + "#" + uri.fragment(); }