Java Code Examples for org.eclipse.emf.common.util.URI#appendFragment()
The following examples show how to use
org.eclipse.emf.common.util.URI#appendFragment() .
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: URIUtils.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** Converts any emf file URI to an accessible platform local URI. Otherwise returns given URI. */ public static URI tryToPlatformUri(URI fileUri) { if (fileUri.isFile()) { java.net.URI jnUri = java.net.URI.create(fileUri.toString()); IFile[] platformFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(jnUri); if (platformFiles.length > 0 && platformFiles[0].isAccessible()) { IFile localTargetFile = platformFiles[0]; URI uri = URIUtils.convert(localTargetFile); if (fileUri.hasFragment()) { uri = uri.appendFragment(fileUri.fragment()); } return uri; } } return fileUri; }
Example 2
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 3
Source File: ClasspathTypeProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
private JvmType findTypeByClass(BinaryClass clazz) { try { IndexedJvmTypeAccess indexedJvmTypeAccess = getIndexedJvmTypeAccess(); URI resourceURI = clazz.getResourceURI(); if (indexedJvmTypeAccess != null) { URI proxyURI = resourceURI.appendFragment(clazz.getURIFragment()); EObject candidate = indexedJvmTypeAccess.getIndexedJvmType(proxyURI, getResourceSet()); if (candidate instanceof JvmType) return (JvmType) candidate; } TypeResource result = (TypeResource) getResourceSet().getResource(resourceURI, true); return findTypeByClass(clazz, result); } catch(UnknownNestedTypeException e) { return null; } }
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: ApiCompareView.java From n4js with Eclipse Public License 1.0 | 5 votes |
private void showInEditor(EObject eobj) { final Resource res = eobj.eResource(); final URI uriBase = res.getURI(); final String frag = res.getURIFragment(eobj); final URI uri = uriBase.appendFragment(frag); uriOpener.open(uri, true); }
Example 8
Source File: EcoreUtil2.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public static URI getFragmentPathURI(final EObject object) { Resource resource = object.eResource(); if(resource != null) { String fragment = getFragmentPath(object); URI resourceURI = getPlatformResourceOrNormalizedURI(resource); return resourceURI.appendFragment(fragment); } else { return getPlatformResourceOrNormalizedURI(object); } }
Example 9
Source File: BaseEPackageAccess.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public static EPackage loadEcoreFile(ClassLoader loader, String string) { URI uri = URI.createURI(string); if (!uri.hasFragment()) uri = uri.appendFragment("/"); URI normalized = new ClassloaderClasspathUriResolver().resolve(loader, uri); return (EPackage) new ResourceSetImpl().getEObject(normalized, true); }
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: TypeURIHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public URI getFullURI(IVariableBinding binding) { SegmentSequence.Builder builder = SegmentSequence.newBuilder(""); URI uri = getFullURI(binding.getDeclaringClass(), builder); builder.append("."); builder.append(binding.getName()); return uri.appendFragment(builder.toString()); }
Example 12
Source File: JdtTypeProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private JvmType findObjectTypeInIndex(/* @NonNull */ String signature, /* @NonNull */ URI resourceURI) throws UnknownNestedTypeException { IndexedJvmTypeAccess indexedJvmTypeAccess = getIndexedJvmTypeAccess(); if (indexedJvmTypeAccess != null) { URI proxyURI = resourceURI.appendFragment(typeUriHelper.getFragment(signature)); EObject candidate = indexedJvmTypeAccess.getIndexedJvmType(proxyURI, getResourceSet(), true); if (candidate instanceof JvmType) { return (JvmType) candidate; } } return null; }
Example 13
Source File: EObjectDescriptionImpl.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public URI getEObjectURI() { EObject container = eContainer(); if (container instanceof IResourceDescription) { URI resourceURI = ((IResourceDescription) container).getURI(); if (eObjectURI == null || !eObjectURI.trimFragment().equals(resourceURI)) { eObjectURI = resourceURI.appendFragment(getFragment()); } return eObjectURI; } return null; }
Example 14
Source File: ClassloaderClasspathUriResolver.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public URI findResourceOnClasspath(ClassLoader classLoader, URI classpathUri) throws URISyntaxException { String pathAsString = classpathUri.path(); if (classpathUri.hasAbsolutePath()) { pathAsString = pathAsString.substring(1); } URL resource = classLoader.getResource(pathAsString); if (resource==null) throw new FileNotFoundOnClasspathException("Couldn't find resource on classpath. URI was '"+classpathUri+"'"); URI fileUri = URI.createURI(resource.toString(),true); return fileUri.appendFragment(classpathUri.fragment()); }
Example 15
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 16
Source File: LazyLinker.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected EObject createProxy(EObject obj, INode node, EReference eRef) { final Resource resource = obj.eResource(); if (resource == null) throw new IllegalStateException("object must be contained in a resource"); final URI uri = resource.getURI(); final URI encodedLink = uri.appendFragment(encoder.encode(obj, eRef, node)); EClass referenceType = getProxyType(obj, eRef); final EObject proxy = EcoreUtil.create(referenceType); ((InternalEObject) proxy).eSetProxyURI(encodedLink); return proxy; }
Example 17
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 18
Source File: N4JSMarkerResolutionGenerator.java From n4js with Eclipse Public License 1.0 | 5 votes |
private boolean isSameProblem(IMarker marker) { URI myUriToProblem = issue.getUriToProblem(); String code = issueUtil.getCode(marker); if (code != null && code.equals(org.eclipse.n4js.validation.IssueCodes.NON_EXISTING_PROJECT)) { myUriToProblem = myUriToProblem.appendFragment(Integer.toString(marker.hashCode())); } return myUriToProblem != null && myUriToProblem.equals(issueUtil.getUriToProblem(marker)); }
Example 19
Source File: N4JSLinker.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** * Creates the proxy with a custom encoded URI format (starting with "|"). The object used to produce the encoded * URI are collected as tuple inside {@link N4JSResource}. Then the node text is checked if it is convertible to a * valid value. If there is a {@link BadEscapementException} is thrown then there is either a warning or an error * produced via the diagnosticProducer. * * * @param resource * the N4JSResource * @param obj * the EObject containing the cross reference * @param node * the node representing the EObject * @param eRef * the cross reference in the domain model * @param xref * the cross reference in the node model * @param diagnosticProducer * to produce errors or warnings * @return the created proxy */ private EObject createProxy(N4JSResource resource, EObject obj, INode node, EReference eRef, CrossReference xref, IDiagnosticProducer diagnosticProducer) { final URI uri = resource.getURI(); /* * as otherwise with 0 the EObjectDescription created for Script would be fetched */ final int fragmentNumber = resource.addLazyProxyInformation(obj, eRef, node); final URI encodedLink = uri.appendFragment("|" + fragmentNumber); EClass referenceType = findInstantiableCompatible(eRef.getEReferenceType()); final EObject proxy = EcoreUtil.create(referenceType); ((InternalEObject) proxy).eSetProxyURI(encodedLink); AbstractElement terminal = xref.getTerminal(); if (!(terminal instanceof RuleCall)) { throw new IllegalArgumentException(String.valueOf(xref)); } AbstractRule rule = ((RuleCall) terminal).getRule(); try { String tokenText = NodeModelUtils.getTokenText(node); Object value = valueConverterService.toValue(tokenText, rule.getName(), node); if (obj instanceof IdentifierRef && value instanceof String) { ((IdentifierRef) obj).setIdAsText((String) value); } else if (obj instanceof ParameterizedTypeRef && value instanceof String) { ((ParameterizedTypeRef) obj).setDeclaredTypeAsText((String) value); } else if (obj instanceof LabelRef && value instanceof String) { ((LabelRef) obj).setLabelAsText((String) value); } else if (obj instanceof ParameterizedPropertyAccessExpression && value instanceof String) { ((ParameterizedPropertyAccessExpression) obj).setPropertyAsText((String) value); } else if (obj instanceof ImportDeclaration && value instanceof String) { ((ImportDeclaration) obj).setModuleSpecifierAsText((String) value); } else if (obj instanceof NamedImportSpecifier && value instanceof String) { ((NamedImportSpecifier) obj).setImportedElementAsText((String) value); } else if ((obj instanceof JSXPropertyAttribute) && (value instanceof String)) { ((JSXPropertyAttribute) obj).setPropertyAsText((String) value); } else { setOtherElementAsText(tokenText, obj, value); } } catch (BadEscapementException e) { diagnosticProducer.addDiagnostic(new DiagnosticMessage(e.getMessage(), e.getSeverity(), e.getIssueCode(), Strings.EMPTY_ARRAY)); } catch (N4JSValueConverterException vce) { diagnosticProducer.addDiagnostic(new DiagnosticMessage(vce.getMessage(), vce.getSeverity(), vce.getIssueCode(), Strings.EMPTY_ARRAY)); } catch (N4JSValueConverterWithValueException vcwve) { diagnosticProducer.addDiagnostic(new DiagnosticMessage(vcwve.getMessage(), vcwve.getSeverity(), vcwve.getIssueCode(), Strings.EMPTY_ARRAY)); } return proxy; }
Example 20
Source File: SerializableReferenceDescription.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public void updateResourceURI(URI newURI, URI oldURI) { sourceEObjectUri = newURI.appendFragment(sourceEObjectUri.fragment()); if (targetEObjectUri.trimFragment().equals(oldURI)) targetEObjectUri = newURI.appendFragment(targetEObjectUri.fragment()); }