public static ImportPolicy instance(Context context) { ImportPolicy result = context.get(ImportPolicy.class); checkState(result != null, "No ImportPolicy bound in this context"); return result; }
@Nullable private PlaceholderMethod placeholder(@Nullable ExpressionTree expr) { Map<MethodSymbol, PlaceholderMethod> placeholderMethods = context.get(RefasterRuleBuilderScanner.PLACEHOLDER_METHODS_KEY); return (placeholderMethods != null && expr != null) ? placeholderMethods.get(ASTHelpers.getSymbol(expr)) : null; }
private RefasterRuleBuilderScanner(Context context) { this.context = new SubContext(context); if (context.get(PLACEHOLDER_METHODS_KEY) == null) { this.placeholderMethods = new HashMap<>(); context.put(PLACEHOLDER_METHODS_KEY, placeholderMethods); } else { this.placeholderMethods = context.get(PLACEHOLDER_METHODS_KEY); } this.beforeTemplates = new ArrayList<>(); this.afterTemplates = new ArrayList<>(); }
Iterable<UTypeVar> typeVariables(Context context) { ImmutableList<UTypeVar> ruleTypeVars = context.get(RefasterRule.RULE_TYPE_VARS); return Iterables.concat( (ruleTypeVars == null) ? ImmutableList.<UTypeVar>of() : ruleTypeVars, templateTypeVariables()); }
/** * Retrieve an instance of {@link NullnessAnalysis} from the {@code context}. If there is no * {@link NullnessAnalysis} currently in the {@code context}, create one, insert it, and return * it. */ public static NullnessAnalysis instance(Context context) { NullnessAnalysis instance = context.get(NULLNESS_ANALYSIS_KEY); if (instance == null) { instance = new NullnessAnalysis(); context.put(NULLNESS_ANALYSIS_KEY, instance); } return instance; }
/** * Retrieve an instance of {@link TrustingNullnessAnalysis} from the {@code context}. If there is * no {@link TrustingNullnessAnalysis} currently in the {@code context}, create one, insert it, * and return it. */ public static TrustingNullnessAnalysis instance(Context context) { TrustingNullnessAnalysis instance = context.get(TRUSTING_NULLNESS_KEY); if (instance == null) { instance = new TrustingNullnessAnalysis(); context.put(TRUSTING_NULLNESS_KEY, instance); } return instance; }
/** Create a VisitorState object from a compilation unit. */ private VisitorState createVisitorState(Context context, DescriptionListener listener) { ErrorProneOptions options = requireNonNull(context.get(ErrorProneOptions.class)); return VisitorState.createConfiguredForCompilation( context, listener, scanner().severityMap(), options); } }
public static EnclosingEnvironmentNullness instance(Context context) { EnclosingEnvironmentNullness instance = context.get(ENCLOSING_ENVIRONMENT_NULLNESS_ANALYSIS_KEY); if (instance == null) { instance = new EnclosingEnvironmentNullness(); context.put(ENCLOSING_ENVIRONMENT_NULLNESS_ANALYSIS_KEY, instance); } return instance; }
private List<String> getAllImports(Inliner inliner) { List<String> allImports = new ArrayList<>(inliner.getImportsToAdd()); if (inliner.getContext() != null && inliner.getContext().get(JCCompilationUnit.class) != null) { for (JCImport jcImport : inliner.getContext().get(JCCompilationUnit.class).getImports()) { JCFieldAccess qualified = (JCFieldAccess) jcImport.getQualifiedIdentifier(); allImports.add(qualified.toString()); } } return allImports; }
/** * @param context Javac context * @param methodReturnsNonNull predicate determining whether a method is assumed to return NonNull * value * @param config analysis config * @return instance of the analysis */ public static AccessPathNullnessAnalysis instance( Context context, Predicate<MethodInvocationNode> methodReturnsNonNull, Config config, Handler handler) { AccessPathNullnessAnalysis instance = context.get(FIELD_NULLNESS_ANALYSIS_KEY); if (instance == null) { instance = new AccessPathNullnessAnalysis(methodReturnsNonNull, context, config, handler); context.put(FIELD_NULLNESS_ANALYSIS_KEY, instance); } return instance; }
@Override public JCExpression classReference( Inliner inliner, CharSequence topLevelClazz, CharSequence fullyQualifiedClazz) { if (Refaster.class.getName().contentEquals(fullyQualifiedClazz)) { // Special handling to ensure that the pretty-printer always recognizes Refaster references return inliner.maker().Ident(inliner.asName("Refaster")); } String packge = topLevelClazz.toString(); int lastDot = packge.lastIndexOf('.'); packge = (lastDot >= 0) ? packge.substring(0, lastDot) : ""; PackageSymbol currentPackage = inliner.getContext().get(PackageSymbol.class); if (currentPackage == null || !currentPackage.getQualifiedName().contentEquals(packge) || !topLevelClazz.toString().contentEquals(fullyQualifiedClazz)) { // don't import classes from the same package as the class we're refactoring inliner.addImport(fullyQualifiedClazz.toString()); } String simpleName = fullyQualifiedClazz.toString(); simpleName = simpleName.substring(simpleName.lastIndexOf('.') + 1); return inliner.maker().Ident(inliner.asName(simpleName)); }
public static ScannerSupplier loadPlugins(ScannerSupplier scannerSupplier, Context context) { JavaFileManager fileManager = context.get(JavaFileManager.class); // Unlike in annotation processor discovery, we never search CLASS_PATH if // ANNOTATION_PROCESSOR_PATH is unavailable. if (!fileManager.hasLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH)) { return scannerSupplier; } // Use the same classloader that Error Prone was loaded from to avoid classloader skew // when using Error Prone plugins together with the Error Prone javac plugin. JavacProcessingEnvironment processingEnvironment = JavacProcessingEnvironment.instance(context); ClassLoader loader = processingEnvironment.getProcessorClassLoader(); Iterable<BugChecker> extraBugCheckers = ServiceLoader.load(BugChecker.class, loader); if (Iterables.isEmpty(extraBugCheckers)) { return scannerSupplier; } return scannerSupplier.plus( ScannerSupplier.fromBugCheckerClasses( Iterables.transform(extraBugCheckers, BugChecker::getClass))); } }
static VisitorState makeVisitorState(Tree target, Unifier unifier) { Context context = unifier.getContext(); TreePath path = TreePath.getPath(context.get(JCCompilationUnit.class), target); return new VisitorState(context).withPath(path); } }
private Context prepareContext(Context baseContext, JCCompilationUnit compilationUnit) { Context context = new SubContext(baseContext); if (context.get(JavaFileManager.class) == null) { JavacFileManager.preRegister(context); } context.put(JCCompilationUnit.class, compilationUnit); context.put(PackageSymbol.class, compilationUnit.packge); context.put(RULE_TYPE_VARS, typeVariables()); return context; }
/** * adds a listener for attribution. */ private void prepareContext(Context context) { TaskListener otherListener = context.get(TaskListener.class); if (otherListener == null) { context.put(TaskListener.class, listener); } else { // handle cases of multiple listeners context.put(TaskListener.class, (TaskListener)null); TaskListeners listeners = new TaskListeners(); listeners.add(otherListener); listeners.add(listener); context.put(TaskListener.class, listeners); } }
JCCompilationUnit comp = context.get(JCCompilationUnit.class); JCTree parent = TreeInfo.pathFor(leaf, comp).get(1);
context.get(RefasterRuleBuilderScanner.PLACEHOLDER_METHODS_KEY); if (placeholderMethods != null && placeholderMethods.containsKey(ASTHelpers.getSymbol(tree))) { return UPlaceholderExpression.create(
return null; JCCompilationUnit compilationUnit = context.get(JCCompilationUnit.class); for (T beforeTemplate : rule().beforeTemplates()) { matchLoop: