public static Collection<TreePath> process(CompilationInfo info, AtomicBoolean cancel) { Collection<TreePath> result = (Collection<TreePath>) info.getCachedValue(KEY_CACHE); if (result != null) return result; DetectorVisitor v = new DetectorVisitor(info, cancel); CompilationUnitTree cu = info.getCompilationUnit(); v.scan(cu, null); if (cancel.get()) return null; List<TreePath> allUnusedImports = new ArrayList<TreePath>(); for (TreePath tree : v.getUnusedImports().values()) { if (cancel.get()) { return null; } allUnusedImports.add(tree); } allUnusedImports = Collections.unmodifiableList(allUnusedImports); info.putCachedValue(KEY_CACHE, allUnusedImports, CacheClearPolicy.ON_CHANGE); return allUnusedImports; }
/** * Gets problem context used by standard JSF hints. * Uses cached value if found, otherwise creates a new one which stores into the CompilationInfo. * * @param context Hints API context * @return {@code JsfHintsContext} */ public static JsfHintsContext getOrCacheContext(HintContext context) { Object cached = context.getInfo().getCachedValue(CACHED_CONTEXT); if (cached == null) { LOG.log(Level.FINEST, "HintContext doesn't contain cached JsfHintsContext which is going to be created."); JsfHintsContext newContext = createJsfHintsContext(context); context.getInfo().putCachedValue(CACHED_CONTEXT, newContext, CompilationInfo.CacheClearPolicy.ON_SIGNATURE_CHANGE); return newContext; } else { LOG.log(Level.FINEST, "JsfHintsContext cached value used."); return (JsfHintsContext) cached; } }