private GuardedBySymbolResolver( ClassSymbol enclosingClass, CompilationUnitTree compilationUnit, Context context, Tree leaf) { this.compilationUnit = (JCCompilationUnit) compilationUnit; this.enclosingClass = enclosingClass; this.context = context; this.types = Types.instance(context); this.decl = leaf; }
public Types types() { return Types.instance(context); }
public Types getTypes() { return Types.instance(context); }
public Types types() { return Types.instance(context); }
AccessPathNullnessPropagation( Nullness defaultAssumption, Predicate<MethodInvocationNode> methodReturnsNonNull, Context context, Config config, Handler handler) { this.defaultAssumption = defaultAssumption; this.methodReturnsNonNull = methodReturnsNonNull; this.context = context; this.types = Types.instance(context); this.config = config; this.handler = handler; }
private static Type getUpperBound(Type type, VisitorState state) { return ASTHelpers.getUpperBound(type.tsym.type, Types.instance(state.context)); }
static boolean equivalentExprs(Unifier unifier, JCExpression expr1, JCExpression expr2) { return expr1.type != null && expr2.type != null && Types.instance(unifier.getContext()).isSameType(expr2.type, expr1.type) && expr2.toString().equals(expr1.toString()); }
/** Creates a {@link GuardedByExpression} from a string, given the resolution context. */ static Optional<GuardedByExpression> bindString(String string, GuardedBySymbolResolver resolver) { try { return Optional.of( bind( GuardedByUtils.parseString(string, resolver.context()), BinderContext.of( resolver, resolver.enclosingClass(), Types.instance(resolver.context()), Names.instance(resolver.context())))); } catch (IllegalGuardedBy expected) { return Optional.empty(); } }
@Override public Description matchMethod(MethodTree tree, VisitorState state) { ClassTree enclosingClazz = ASTHelpers.findEnclosingNode(state.getPath(), ClassTree.class); if (tree.getModifiers().getFlags().contains(Modifier.DEFAULT) && IS_FUNCTIONAL_INTERFACE.matches(enclosingClazz, state)) { Types types = Types.instance(state.context); Set<Symbol> functionalSuperInterfaceSams = enclosingClazz.getImplementsClause().stream() .filter(t -> IS_FUNCTIONAL_INTERFACE.matches(t, state)) .map(ASTHelpers::getSymbol) .map(TypeSymbol.class::cast) .map(types::findDescriptorSymbol) // TypeSymbol to single abstract method of the type .collect(toImmutableSet()); // We designate an override of a superinterface SAM "behavior preserving" if it just // calls the SAM of this interface. Symbol thisInterfaceSam = types.findDescriptorSymbol(ASTHelpers.getSymbol(enclosingClazz)); // relatively crude: doesn't verify that the same args are passed in the same order // so it can get false positives for behavior-preservingness (false negatives for the check) TreeVisitor<Boolean, VisitorState> behaviorPreserving = new BehaviorPreservingChecker(thisInterfaceSam); if (!Collections.disjoint( ASTHelpers.findSuperMethods(ASTHelpers.getSymbol(tree), types), functionalSuperInterfaceSams) && !tree.accept(behaviorPreserving, state)) { return describeMatch(tree); } } return Description.NO_MATCH; }
/** * Refines the receiver of a method invocation to type non-null after successful invocation, and * refines the value of the expression as a whole to non-null if applicable (e.g., if the method * returns a primitive type). * * <p>NOTE: This transfer makes the unsound assumption that fields reachable via the actual params * of this method invocation are not mutated by the callee. To be sound with respect to escaping * mutable references in general, we would have to set to top (i.e. NULLABLE) any tracked access * path that could contain an alias of an actual parameter of this invocation. */ @Override Nullness visitMethodInvocation( MethodInvocationNode node, Updates thenUpdates, Updates elseUpdates, Updates bothUpdates) { ClassAndMethod callee = tryGetMethodSymbol(node.getTree(), Types.instance(context)); if (callee != null && !callee.isStatic) { setNonnullIfTrackable(bothUpdates, node.getTarget().getReceiver()); } setUnconditionalArgumentNullness(bothUpdates, node.getArguments(), callee); setConditionalArgumentNullness( thenUpdates, elseUpdates, node.getArguments(), callee, Types.instance(context), Symtab.instance(context)); return returnValueNullness(node, callee); }
/** * Creates a new overload scanner. */ public OverloadScanner(TranspilationHandler logHandler, JSweetContext context) { super(logHandler, context, null); this.types = Types.instance(context); }
ty = trueTy; } else { ty = Types.instance(unifier.getContext()).lub(trueTy, falseTy);
Types types = Types.instance(state.context); Symtab symtab = Symtab.instance(state.context);
/** * Creates a new scanner. * * @param logHandler * the handler for reporting messages * @param context * the JSweet transpilation context * @param compilationUnit * the compilation to be scanned */ public AbstractTreeScanner(TranspilationHandler logHandler, JSweetContext context, JCCompilationUnit compilationUnit) { this.logHandler = logHandler; this.context = context; this.context.symtab = Symtab.instance(context); this.context.names = Names.instance(context); this.context.types = Types.instance(context); this.context.modelTypes = com.sun.tools.javac.model.JavacTypes.instance(context); this.setCompilationUnit(compilationUnit); }
/** * Creates a new compilation environment with the given options and * classpath. */ public static JavaCompilationEnvironment create(JSweetOptions jsweetOptions, String classPath) { JSweetContext context = new JSweetContext(jsweetOptions); Options options = Options.instance(context); options.put(Option.CLASSPATH, classPath); options.put(Option.XLINT, "path"); context.put(Log.outKey, new PrintWriter(System.out)); // options.put(Option.XLINT_CUSTOM.text + "-" + // LintCategory.OPTIONS.option, "true"); // options.remove(Option.XLINT_CUSTOM.text + // LintCategory.OPTIONS.option); options.put(Option.XLINT_CUSTOM.text + "-" + LintCategory.OVERRIDES.option, "true"); JavacFileManager.preRegister(context); JavaFileManager fileManager = context.get(JavaFileManager.class); Log log = Log.instance(context); log.emitWarnings = false; log.suppressNotes = true; Types javacTypes = Types.instance(context); JavaCompiler compiler = JavaCompiler.instance(context); compiler.attrParseOnly = true; compiler.verbose = false; compiler.genEndPos = true; compiler.keepComments = true; Names names = Names.instance(context); Symtab symtab = Symtab.instance(context); return new JavaCompilationEnvironment(fileManager, compiler, options, context, log, javacTypes, names, symtab); }
static boolean equivalentExprs(Unifier unifier, JCExpression expr1, JCExpression expr2) { return expr1.type != null && expr2.type != null && Types.instance(unifier.getContext()).isSameType(expr2.type, expr1.type) && expr2.toString().equals(expr1.toString()); }
/** Create a tree maker with null toplevel and NOPOS as initial position. */ protected TreeMaker(Context context) { context.put(treeMakerKey, this); this.pos = Position.NOPOS; this.toplevel = null; this.names = Name.Table.instance(context); this.syms = Symtab.instance(context); this.types = Types.instance(context); }
protected Infer(Context context) { context.put(inferKey, this); syms = Symtab.instance(context); types = Types.instance(context); rs = Resolve.instance(context); chk = Check.instance(context); }
protected ElementsService(Context context) { context.put(KEY, this); jctypes = com.sun.tools.javac.code.Types.instance(context); names = Names.instance(context); types = JavacTypes.instance(context); allowDefaultMethods = Source.instance(context).allowDefaultMethods(); }
protected Annotate(Context context) { context.put(annotateKey, this); attr = Attr.instance(context); make = TreeMaker.instance(context); log = Log.instance(context); syms = Symtab.instance(context); names = Names.instance(context); rs = Resolve.instance(context); types = Types.instance(context); cfolder = ConstFold.instance(context); chk = Check.instance(context); }