Java 类org.eclipse.xtext.resource.ClasspathUriUtil 实例源码

项目:n4js    文件:BuiltInSchemeRegistrar.java   
@Override
public InputStream createInputStream(URI uri, Map<?, ?> options) throws IOException {
    String[] allSegments = new String[uri.segmentCount() + 1];
    allSegments[0] = "env";
    for (int i = 0; i < uri.segmentCount(); i++) {
        allSegments[i + 1] = uri.segment(i);
    }
    URI classpathURI = URI.createHierarchicalURI(
            ClasspathUriUtil.CLASSPATH_SCHEME,
            uri.authority(),
            uri.device(),
            allSegments,
            uri.query(),
            uri.fragment());
    URI resolvedURI = uriResolver.resolve(classLoader, classpathURI);
    return original.createInputStream(resolvedURI, options);
}
项目:bts    文件:BundleClasspathUriResolver.java   
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;
}
项目:bts    文件:WorkspaceClasspathUriResolver.java   
@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;
}
项目:bts    文件:JdtClasspathUriResolver.java   
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;
}
项目:EASyProducer    文件:ModelUtility.java   
/**
 * Returns the object representation of the actual grammar (and performs a lazy 
 * initialization of {@link #grammar} or {@link #resourceSet} if required).
 * 
 * @return the grammar
 */
protected Grammar getGrammar() {
    if (null == grammar) {
        // the "official" way of getting the grammar is using the GrammarProvider
        // via the injector. However, this uses the wrong resource set so we
        // repeat this code here. Check, whether we shall replace the instance of 
        // the resource set in the injector...
        XtextResourceSet resourceSet = getResourceSet();
        XtextPackage.eINSTANCE.getClass();
        synchronized (ModelUtility.class) { // started with if (null == grammar)
            resourceSet.setClasspathURIContext(getLanguageClassLoader());
            grammar = (Grammar) BaseEPackageAccess.loadGrammarFile(
                ClasspathUriUtil.CLASSPATH_SCHEME + ":/" + getLanguageName().replace('.', '/') + ".xtextbin",
                resourceSet);
        }
    }
    return grammar;
}
项目:dsl-devkit    文件:ClasspathBasedChecks.java   
/**
 * Verifies that a given catalog file has the same name as the name given in the model.
 * Also verifies that the given package exists and that the file is in that package.
 * 
 * @param catalog
 *          a check catalog
 */
@Check
public void checkFileNamingConventions(final CheckCatalog catalog) {
  Resource resource = catalog.eResource();
  URI resourceURI = resource.getURI();
  String packageName = catalog.getPackageName();
  StringBuilder classpathURIBuilder = new StringBuilder(ClasspathUriUtil.CLASSPATH_SCHEME);
  classpathURIBuilder.append(":/");
  if (packageName != null) {
    classpathURIBuilder.append(packageName.replace(DOT, SLASH)).append(SLASH);
  }
  classpathURIBuilder.append(resourceURI.lastSegment());
  URI classpathURI = URI.createURI(classpathURIBuilder.toString());
  URIConverter uriConverter = resource.getResourceSet().getURIConverter();
  try {
    URI normalizedClasspathURI = uriConverter.normalize(classpathURI);
    URI normalizedResourceURI = uriConverter.normalize(resourceURI);
    // Must normalize both URIs... however, pre-Xtext 2.4.3 we only normalized the classpath URI, and it worked?!
    // Just to be sure we don't break anything, leave that earlier behavior in.
    if (!normalizedResourceURI.equals(normalizedClasspathURI) && !resourceURI.equals(normalizedClasspathURI)) {
      reportInvalidPackage(catalog, packageName, null);
    }
  } catch (ClasspathUriResolutionException e) {
    reportInvalidPackage(catalog, packageName, null);
  }
  String catalogName = catalog.getName();
  if (catalogName != null && !equal(resourceURI.trimFileExtension().lastSegment(), catalogName)) {
    error("The catalog '" + (packageName != null ? notNull(packageName) + DOT : "") + catalogName + "' must be defined in its own file", catalog, CheckPackage.Literals.CHECK_CATALOG__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, IssueCodes.WRONG_FILE);
  }
}