Package com.sun.tools.javac.code

Examples of com.sun.tools.javac.code.Scope


            Name name = names.package_info;
            ClassSymbol c = reader.enterClass(name, tree.packge);
            c.flatname = names.fromString(tree.packge + "." + name);
            c.sourcefile = tree.sourcefile;
            c.completer = null;
            c.members_field = new Scope(c);
            tree.packge.package_info = c;
        }
        classEnter(tree.defs, topEnv);
        if (addEnv) {
            todo.append(topEnv);
View Full Code Here


    }

    @Override
    public void visitClassDef(JCClassDecl tree) {
        Symbol owner = env.info.scope.owner;
        Scope enclScope = enterScope(env);
        ClassSymbol c;
        if (owner.kind == PCK) {
            // We are seeing a toplevel class.
            PackageSymbol packge = (PackageSymbol)owner;
            for (Symbol q = packge; q != null && q.kind == PCK; q = q.owner)
                q.flags_field |= EXISTS;
            c = reader.enterClass(tree.name, packge);
            packge.members().enterIfAbsent(c);
            if ((tree.mods.flags & PUBLIC) != 0 && !classNameMatchesFileName(c, env)
                    && !sourceLanguage.isCeylon()) {
                log.error(tree.pos(),
                          "class.public.should.be.in.file", tree.name);
            }
        } else {
            if (!tree.name.isEmpty() &&
                !chk.checkUniqueClassName(tree.pos(), tree.name, enclScope)) {
                result = null;
                return;
            }
            if (owner.kind == TYP) {
                // We are seeing a member class.
                c = reader.enterClass(tree.name, (TypeSymbol)owner);
                if ((owner.flags_field & INTERFACE) != 0) {
                    tree.mods.flags |= PUBLIC | STATIC;
                }
            } else {
                // We are seeing a local class.
                c = reader.defineClass(tree.name, owner);
                c.flatname = chk.localClassName(c);
                if (!c.name.isEmpty())
                    chk.checkTransparentClass(tree.pos(), c, env.info.scope);
            }
        }
        tree.sym = c;

        // Enter class into `compiled' table and enclosing scope.
        if (chk.compiled.get(c.flatname) != null) {
            duplicateClass(tree.pos(), c);
            result = types.createErrorType(tree.name, (TypeSymbol)owner, Type.noType);
            tree.sym = (ClassSymbol)result.tsym;
            return;
        }
        chk.compiled.put(c.flatname, c);
        // CEYLON(stef): don't add anonymous classes to the environment
        if(tree.name.length() != 0)
            enclScope.enter(c);

        // Set up an environment for class block and store in `typeEnvs'
        // table, to be retrieved later in memberEnter and attribution.
        Env<AttrContext> localEnv = classEnv(tree, env);
        typeEnvs.put(c, localEnv);

        // Fill out class fields.
        c.completer = memberEnter;
        c.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, c, tree);
        c.sourcefile = env.toplevel.sourcefile;
        c.members_field = new Scope(c);

        // Ceylon: this is code that used to sit in Attr.visitClassDef() but it would be set
        // after this method is called, and this method needs this flag further down to
        // determine the enclosing type
        if(sourceLanguage.isCeylon()){
View Full Code Here

        if (ctype.tag != CLASS) {
            return erroneousMapping;
        }

        Pair<Scope, Scope> mapping =
                new Pair<Scope, Scope>(ctype.tsym.members(), new Scope(ctype.tsym));

        //for each constructor in the original scope, create a synthetic constructor
        //whose return type is the type of the class in which the constructor is
        //declared, and insert it into the new scope.
        for (Scope.Entry e = mapping.fst.lookup(names.init);
View Full Code Here

    }

    /* Added for Ceylon, required by the ExpressionTransformer */
    @Override
    public void visitLetExpr(LetExpr tree) {
        Scope scope;
        if (env.info.scope.owner.kind == Kinds.VAR) {
            // for field initialisers we must access the parent scope, otherwise we get
            // a DelegateScope which doesn't allow us to declare new variables
            scope = env.info.scope.next;
        }else
            scope = env.info.scope;
        if (scope instanceof DelegatedScope) {
            throw new AssertionError("Broken use of LetExpr");
        }
       
        // make a new environment which captures the current one
        Env<AttrContext> localEnv =
                env.dup(tree, env.info.dup(scope.dup()));

        // Field initialisers have not been entered yet, so we need to do it now:
        if (localEnv.info.scope.owner.kind == Kinds.TYP) {
            memberEnter.memberEnter(tree, localEnv);
            annotate.flush();
View Full Code Here

        void setupPackage() {
            Name name = names.fromString("p" + (++nextPackageSerial));
            int count = rgen.nextInt(MAX_SETUP_PACKAGE_COUNT);
            log("setup: creating package " + name + " with " + count + " entries");
            PackageSymbol p = new PackageSymbol(name, symtab.rootPackage);
            p.members_field = new Scope(p);
            for (int i = 0; i < count; i++) {
                String outer = name + "c" + i;
                String suffix = random(null, "$Entry", "$Entry2");
                ClassSymbol c1 = createClass(names.fromString(outer), p);
//                log("setup: created " + c1);
View Full Code Here

                importAll = null;
            }
            starImportModel = new Model();

            for (Symbol imp: imports) {
                Scope members = imp.members();
                if (importAll != null) {
//                    log("importAll", members);
                    importAll.invoke(starImportScope, members);
                } else {
                    Scope fromScope = members;
                    Scope toScope = starImportScope;
                    // The following lines are taken from MemberEnter.importAll,
                    // before the use of StarImportScope.importAll.
                    for (Scope.Entry e = fromScope.elems; e != null; e = e.sibling) {
                        if (e.sym.kind == TYP && !toScope.includes(e.sym))
                            toScope.enter(e.sym, fromScope);
                    }
                }

                for (Scope.Entry e = members.elems; e != null; e = e.sibling) {
                    starImportModel.enter(e.sym);
View Full Code Here

            }
        }

        ClassSymbol createClass(Name name, Symbol owner) {
            ClassSymbol sym = new ClassSymbol(0, name, owner);
            sym.members_field = new Scope(sym);
            if (owner != symtab.unnamedPackage)
                owner.members().enter(sym);
            return sym;
        }
View Full Code Here

        JavacFileManager.preRegister(context); // required by ClassReader which is required by Symtab
        names = Names.instance(context);       // Name.Table impls tied to an instance of Names
        symtab = Symtab.instance(context);

        // determine hashMask for an empty scope
        Scope emptyScope = new Scope(symtab.unnamedPackage); // any owner will do
        Field sHashMask = Scope.class.getDeclaredField("hashMask");
        sHashMask.setAccessible(true);
        scopeHashMask = sHashMask.getInt(emptyScope);
        log("scopeHashMask: " + scopeHashMask);

        // 1. determine the Name.hashCode of "Entry", and therefore the index of
        // Entry in an empty scope.  i.e. name.hashCode() & Scope.hashMask
        Name entry = names.fromString("Entry");

        // 2. create names of the form *$Entry until we find a name with a
        // hashcode which yields the same index as Entry in an empty scope.
        // Since Name.hashCode is a function of position (and not content) it
        // should work to create successively longer names until one with the
        // desired characteristics is found.
        Name outerName;
        Name innerName;
        StringBuilder sb = new StringBuilder("C");
        int i = 0;
        do {
            sb.append(Integer.toString(i % 10));
            innerName = names.fromString(sb + "$Entry");
        } while (!clash(entry, innerName) && (++i) < MAX_TRIES);

        if (clash(entry, innerName)) {
            log("Detected expected hash collision for " + entry + " and " + innerName
                    + " after " + i + " tries");
        } else {
            throw new Exception("No potential collision found after " + i + " tries");
        }

        outerName = names.fromString(sb.toString());

        /*
         * Now we can set up the scenario.
         */

        // 3. Create a nested class named Entry
        ClassSymbol cc = createClass(names.fromString("C"), symtab.unnamedPackage);
        ClassSymbol ce = createClass(entry, cc);

        // 4. Create a package containing a nested class using the name from 2
        PackageSymbol p = new PackageSymbol(names.fromString("p"), symtab.rootPackage);
        p.members_field = new Scope(p);
        ClassSymbol inner = createClass(innerName, p);
        // we'll need this later when we "rename" cn
        ClassSymbol outer = createClass(outerName, p);

        // 5. Create a star-import scope
        log ("createStarImportScope");

        // if StarImportScope exists, use it, otherwise, for testing legacy code,
        // fall back on ImportScope
        Scope starImportScope;
        Method importAll;
        PackageSymbol pkg = new PackageSymbol(names.fromString("pkg"), symtab.rootPackage);
        try {
            Class<?> c = Class.forName("com.sun.tools.javac.code.Scope$StarImportScope");
            Constructor ctor = c.getDeclaredConstructor(new Class[] { Symbol.class });
            importAll = c.getDeclaredMethod("importAll", new Class[] { Scope.class });
            starImportScope = (Scope) ctor.newInstance(new Object[] { pkg });
        } catch (ClassNotFoundException e) {
            starImportScope = new ImportScope(pkg);
            importAll = null;
        }

        dump("initial", starImportScope);

        // 6. Insert the contents of the package from 4.
        Scope p_members = p.members();
        if (importAll != null) {
            importAll.invoke(starImportScope, p_members);
        } else {
            Scope fromScope = p_members;
            Scope toScope = starImportScope;
            // The following lines are taken from MemberEnter.importAll,
            // before the use of StarImportScope.importAll.
            for (Scope.Entry e = fromScope.elems; e != null; e = e.sibling) {
                if (e.sym.kind == TYP && !toScope.includes(e.sym))
                    toScope.enter(e.sym, fromScope);
            }
        }

        dump("imported p", starImportScope);

View Full Code Here

    /**
     * Create a class symbol, init the members scope, and add it to owner's scope.
     */
    ClassSymbol createClass(Name name, Symbol owner) {
        ClassSymbol sym = new ClassSymbol(0, name, owner);
        sym.members_field = new Scope(sym);
        if (owner != symtab.unnamedPackage)
            owner.members().enter(sym);
        return sym;
    }
View Full Code Here

        /**
         * Create a scope containing a given number of synthetic symbols
         */
        Scope createScope(int nelems) {
            Scope s = new Scope(symtab.noSymbol);
            for (int i = 0 ; i < nelems ; i++) {
                Symbol sym = new TypeSymbol(0, names.fromString("s" + i), null, null);
                s.enter(sym);
                elems = elems.prepend(sym);
                List<Symbol> shadowed = shadowedMap.get(sym.name);
                if (shadowed == null) {
                    shadowed = List.nil();
                }
View Full Code Here

TOP

Related Classes of com.sun.tools.javac.code.Scope

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.