/** * Resolve a resource for this application. * * @param path the path of the resource to resolve * @return the resolved resource or null if it cannot be determined * @throws NullPointerException if any argument is null * @throws IllegalArgumentException if the context package is not valid */ public FileObject resolveResource(Path.Absolute path) throws NullPointerException, IllegalArgumentException { return model.processingContext.resolveResourceFromSourcePath(handle, path); }
/** * Resolve a resource for this application. * * @param path the path of the resource to resolve * @return the resolved resource or null if it cannot be determined * @throws NullPointerException if any argument is null * @throws IllegalArgumentException if the context package is not valid */ public FileObject resolveResource(Path.Absolute path) throws NullPointerException, IllegalArgumentException { return model.processingContext.resolveResourceFromSourcePath(handle, path); }
/** * Resolve a resource from the provided context and path. * * @param context the context of the application that will help to resolve the path source code * @param path the path of the resource to resolve * @return the resolved resource or null if it cannot be determined * @throws NullPointerException if any argument is null * @throws IllegalArgumentException if the context package is not valid */ public FileObject resolveResourceFromSourcePath(ElementHandle.Package context, Path.Absolute path) throws NullPointerException, IllegalArgumentException { return resolveResourceFromSourcePath(context, FileKey.newName(path)); }
/** * Resolve a resource from the provided context and path. * * @param context the context of the application that will help to resolve the path source code * @param path the path of the resource to resolve * @return the resolved resource or null if it cannot be determined * @throws NullPointerException if any argument is null * @throws IllegalArgumentException if the context package is not valid */ public FileObject resolveResourceFromSourcePath(ElementHandle.Package context, Path.Absolute path) throws NullPointerException, IllegalArgumentException { return resolveResourceFromSourcePath(context, FileKey.newName(path)); }
public FileObject resolveResourceFromSourcePath(ElementHandle.Package context, FileKey key) throws NullPointerException, IllegalArgumentException { return resolveResourceFromSourcePath(context, Name.parse(key.packageFQN), key.name); }
public FileObject resolveResourceFromSourcePath(ElementHandle.Package context, FileKey key) throws NullPointerException, IllegalArgumentException { return resolveResourceFromSourcePath(context, Name.parse(key.packageFQN), key.name); }
private Properties loadBundle(ProcessingContext context, ElementHandle.Package pkg, String bundleName) { Path.Absolute absolute = pkg.getPackageName().resolve(bundleName + ".properties"); FileObject bundle = context.resolveResourceFromSourcePath(pkg, absolute); if (bundle != null) { try { InputStream in = bundle.openInputStream(); Properties properties = new Properties(); properties.load(in); return properties; } catch (IOException e) { context.log(Level.SEVERE, "Could not load resource bundle", e); } } return null; } // end::loadBundle[]
private Properties loadBundle(ProcessingContext context, ElementHandle.Package pkg, String bundleName) { Path.Absolute absolute = pkg.getPackageName().resolve(bundleName + ".properties"); FileObject bundle = context.resolveResourceFromSourcePath(pkg, absolute); if (bundle != null) { try { InputStream in = bundle.openInputStream(); Properties properties = new Properties(); properties.load(in); return properties; } catch (IOException e) { context.log(Level.SEVERE, "Could not load resource bundle", e); } } return null; } // end::loadBundle[]
public String load(String ref) { try { Path.Absolute path = pkg.resolve(ref); FileObject c = processingContext.resolveResourceFromSourcePath(context, path); if (c != null) { try { return c.getCharContent(true).toString(); } catch (IOException e) { processingContext.info("Could not get content of " + path, e); } } } catch (IllegalArgumentException e) { // Log ? } // return null; } }
public String load(String ref) { try { Path.Absolute path = pkg.resolve(ref); FileObject c = processingContext.resolveResourceFromSourcePath(context, path); if (c != null) { try { return c.getCharContent(true).toString(); } catch (IOException e) { processingContext.info("Could not get content of " + path, e); } } } catch (IllegalArgumentException e) { // Log ? } // return null; } }
FileObject src; try { src = context.resolveResourceFromSourcePath(pkg, qn, path);
FileObject src; try { src = context.resolveResourceFromSourcePath(pkg, qn, path);
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (count++ == 0) { try { ProcessingContext ctx = new ProcessingContext(processingEnv); ElementHandle.Package pkg = ElementHandle.Package.create(ctx.getPackageElement("compiler.dot.foo")); FileObject file = ctx.resolveResourceFromSourcePath(pkg, FileKey.newName("compiler.dot.foo", "a.b.txt")); InputStream in = file.openInputStream(); FileObject o = ctx.createResource(StandardLocation.CLASS_OUTPUT, FileKey.newName("compiler.dot.foo", "a.b.css")); OutputStream out = o.openOutputStream(); Tools.copy(in, out); Tools.safeClose(in); Tools.safeClose(out); } catch (Exception e) { throw failure(e); } } return true; } });
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (count++ == 0) { try { ProcessingContext ctx = new ProcessingContext(processingEnv); ElementHandle.Package pkg = ElementHandle.Package.create(ctx.getPackageElement("compiler.dot.foo")); FileObject file = ctx.resolveResourceFromSourcePath(pkg, FileKey.newName("compiler.dot.foo", "a.b.txt")); InputStream in = file.openInputStream(); FileObject o = ctx.createResource(StandardLocation.CLASS_OUTPUT, FileKey.newName("compiler.dot.foo", "a.b.css")); OutputStream out = o.openOutputStream(); Tools.copy(in, out); Tools.safeClose(in); Tools.safeClose(out); } catch (Exception e) { throw failure(e); } } return true; } });