/** * @since 2.3 */ protected void registerURI(Resource resource) { Map<URI, Resource> map = getURIResourceMap(); if (map != null) { final URI uri = resource.getURI(); if (uri != null) { URI normalized = getURIConverter().normalize(uri); if (!normalized.equals(uri)) { Resource previous = map.put(normalized, resource); if (previous != null && previous != resource) { throw new IllegalStateException("A resource with the normalized URI '"+normalized+"' was already registered. The resource with the URI '"+previous+"' is no longer registered with the normalized form."); } } } Resource previous = map.put(uri, resource); if (previous != null && previous != resource) { throw new IllegalStateException("A different resource with the URI '"+uri+"' was already registered."); } } } /**
protected boolean exists(final URI uri) { ProjectManager _projectManager = this.getProjectManager(uri); XtextResourceSet _resourceSet = null; if (_projectManager!=null) { _resourceSet=_projectManager.getResourceSet(); } final XtextResourceSet rs = _resourceSet; if ((rs == null)) { return false; } return rs.getURIConverter().exists(uri, null); }
public ResourceSet get(IProject project) { XtextResourceSet set = resourceSetProvider.get(); IJavaProject javaProject = JavaCore.create(project); if (javaProject != null && javaProject.exists()) { set.getURIConverter().getURIMap().putAll(computePlatformURIMap(javaProject)); set.setClasspathURIContext(javaProject); set.setClasspathUriResolver(new JdtClasspathUriResolver()); } return set; }
@Override public void notifyChanged(Notification notification) { final Map<URI, Resource> map = getURIResourceMap(); if (map != null && notification.getFeatureID(Resource.class) == Resource.RESOURCE__URI && notification.getNotifier() instanceof Resource) { URI oldOne = (URI) notification.getOldValue(); map.remove(oldOne); if (oldOne != null) { URI oldNormalized = getURIConverter().normalize(oldOne); if (!oldOne.equals(oldNormalized)) map.remove(oldNormalized); } Resource resource = (Resource) notification.getNotifier(); registerURI(resource); } super.notifyChanged(notification); } }
Resource resource = map.get(uri); if (resource == null) { URI normalizedURI = getURIConverter().normalize(uri); resource = map.get(normalizedURI);
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); } }