private CanBeStaticAnalyzer(Symbol owner, VisitorState state) { this.owner = owner; this.state = state; this.names = Names.instance(state.context); }
public Names names() { return Names.instance(context); }
public Name getName(String nameStr) { return Names.instance(context).fromString(nameStr); }
private Name getName(String name) { return Names.instance(context).fromString(name); }
PlaceholderParamIdent(UVariableDecl param, Context context) { super(Names.instance(context).fromString(param.getName().contents()), null); this.param = checkNotNull(param); } }
/** * Creates a {@link GuardedByExpression} from a bound AST node, or returns {@code * Optional.empty()} if the AST node doesn't correspond to a 'simple' lock expression. */ public static Optional<GuardedByExpression> bindExpression( JCTree.JCExpression exp, VisitorState visitorState) { try { return Optional.of( bind( exp, BinderContext.of( ALREADY_BOUND_RESOLVER, ASTHelpers.getSymbol(visitorState.findEnclosing(ClassTree.class)), visitorState.getTypes(), Names.instance(visitorState.context)))); } catch (IllegalGuardedBy expected) { return Optional.empty(); } }
private Description check(Tree tree, Name simpleName, VisitorState state) { Symtab symtab = state.getSymtab(); PackageSymbol javaLang = symtab.enterPackage(symtab.java_base, Names.instance(state.context).java_lang); Symbol other = getFirst( javaLang.members().getSymbolsByName(simpleName, s -> s.getModifiers().contains(PUBLIC)), null); Symbol symbol = ASTHelpers.getSymbol(tree); if (other == null || other.equals(symbol)) { return NO_MATCH; } return buildDescription(tree) .setMessage(String.format("%s clashes with %s\n", symbol, other)) .build(); } }
@Override public Choice<Unifier> visitIdentifier(IdentifierTree node, Unifier unifier) { Names names = Names.instance(unifier.getContext()); return node.getName().equals(names._super) ? Choice.<Unifier>none() : defaultAction(node, unifier); }
/** 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(); } }
symtab.enterPackage(symtab.java_base, Names.instance(state.context).java_lang);
private static boolean finalNoOverrides(Type type, VisitorState state) { if (type == null) { return false; } // We don't flag use of toString() on non-final objects because sub classes might have a // meaningful toString() override. if (!type.isFinal()) { return false; } Types types = state.getTypes(); Names names = Names.instance(state.context); // find Object.toString MethodSymbol toString = (MethodSymbol) state.getSymtab().objectType.tsym.members().findFirst(names.toString); // We explore the superclasses of the receiver type as well as the interfaces it // implements and we collect all overrides of java.lang.Object.toString(). If one of those // overrides is present, then we don't flag it. return Iterables.isEmpty( types .membersClosure(type, /* skipInterface= */ false) .getSymbolsByName( names.toString, m -> m != toString && m.overrides(toString, type.tsym, types, /* checkResult= */ false))); }
public OptimizedLibraryModels(LibraryModels models, Context context) { Names names = Names.instance(context); failIfNullParams = makeOptimizedIntSetLookup(names, models.failIfNullParameters()); explicitlyNullableParams = makeOptimizedIntSetLookup(names, models.explicitlyNullableParameters()); nonNullParams = makeOptimizedIntSetLookup(names, models.nonNullParameters()); nullImpliesTrueParams = makeOptimizedIntSetLookup(names, models.nullImpliesTrueParameters()); nullableRet = makeOptimizedBoolLookup(names, models.nullableReturns()); nonNullRet = makeOptimizedBoolLookup(names, models.nonNullReturns()); }
/** * 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); }
private CanBeStaticAnalyzer(Symbol owner, VisitorState state) { this.owner = owner; this.state = state; this.names = Names.instance(state.context); }
/** * 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); }
/** 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 = Names.instance(context); this.syms = Symtab.instance(context); this.types = Types.instance(context); }
/** Create a new scanner factory. */ protected ScannerFactory(Context context) { context.put(scannerFactoryKey, this); this.log = Log.instance(context); this.names = Names.instance(context); this.source = Source.instance(context); this.tokens = Tokens.instance(context); }
private PostFlowAnalysis(Context ctx) { log = Log.instance(ctx); types = Types.instance(ctx); enter = Enter.instance(ctx); names = Names.instance(ctx); syms = Symtab.instance(ctx); outerThisStack = List.nil(); }
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 TreeFactory(Context context) { context.put(contextKey, this); model = ASTService.instance(context); names = Names.instance(context); classReader = ClassReader.instance(context); make = com.sun.tools.javac.tree.TreeMaker.instance(context); docMake = com.sun.tools.javac.tree.DocTreeMaker.instance(context); elements = JavacElements.instance(context); types = JavacTypes.instance(context); chs = CommentHandlerService.instance(context); make.toplevel = null; }