Java Code Examples for com.sun.tools.javac.code.Scope#Entry

The following examples show how to use com.sun.tools.javac.code.Scope#Entry . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PackageDocImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return a list of all classes contained in this package, including
 * member classes of those classes, and their member classes, etc.
 */
private List<ClassDocImpl> getClasses(boolean filtered) {
    if (allClasses != null && !filtered) {
        return allClasses;
    }
    if (allClassesFiltered != null && filtered) {
        return allClassesFiltered;
    }
    ListBuffer<ClassDocImpl> classes = new ListBuffer<ClassDocImpl>();
    for (Scope.Entry e = sym.members().elems; e != null; e = e.sibling) {
        if (e.sym != null) {
            ClassSymbol s = (ClassSymbol)e.sym;
            ClassDocImpl c = env.getClassDoc(s);
            if (c != null && !c.isSynthetic())
                c.addAllClasses(classes, filtered);
        }
    }
    if (filtered)
        return allClassesFiltered = classes.toList();
    else
        return allClasses = classes.toList();
}
 
Example 2
Source File: SerializedForm.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void computeDefaultSerializableFields(DocEnv env,
                                              ClassSymbol def,
                                              ClassDocImpl cd) {
    for (Scope.Entry e = def.members().elems; e != null; e = e.sibling) {
        if (e.sym != null && e.sym.kind == Kinds.VAR) {
            VarSymbol f = (VarSymbol)e.sym;
            if ((f.flags() & Flags.STATIC) == 0 &&
                (f.flags() & Flags.TRANSIENT) == 0) {
                //### No modifier filtering applied here.
                FieldDocImpl fd = env.getFieldDoc(f);
                //### Add to beginning.
                //### Preserve order used by old 'javadoc'.
                fields.prepend(fd);
            }
        }
    }
}
 
Example 3
Source File: JNIWriter.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private boolean needsHeader(ClassSymbol c, boolean checkNestedClasses) {
    if (c.isLocal() || (c.flags() & Flags.SYNTHETIC) != 0)
        return false;

    for (Scope.Entry i = c.members_field.elems; i != null; i = i.sibling) {
        if (i.sym.kind == Kinds.MTH && (i.sym.flags() & Flags.NATIVE) != 0)
            return true;
        for (Attribute.Compound a: i.sym.getDeclarationAttributes()) {
            if (a.type.tsym == syms.nativeHeaderType.tsym)
                return true;
        }
    }
    if (checkNestedClasses) {
        for (Scope.Entry i = c.members_field.elems; i != null; i = i.sibling) {
            if ((i.sym.kind == Kinds.TYP) && needsHeader(((ClassSymbol) i.sym), true))
                return true;
        }
    }
    return false;
}
 
Example 4
Source File: JNIWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private boolean needsHeader(ClassSymbol c, boolean checkNestedClasses) {
    if (c.isLocal() || (c.flags() & Flags.SYNTHETIC) != 0)
        return false;

    for (Scope.Entry i = c.members_field.elems; i != null; i = i.sibling) {
        if (i.sym.kind == Kinds.MTH && (i.sym.flags() & Flags.NATIVE) != 0)
            return true;
        for (Attribute.Compound a: i.sym.getDeclarationAttributes()) {
            if (a.type.tsym == syms.nativeHeaderType.tsym)
                return true;
        }
    }
    if (checkNestedClasses) {
        for (Scope.Entry i = c.members_field.elems; i != null; i = i.sibling) {
            if ((i.sym.kind == Kinds.TYP) && needsHeader(((ClassSymbol) i.sym), true))
                return true;
        }
    }
    return false;
}
 
Example 5
Source File: PackageDocImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return a list of all classes contained in this package, including
 * member classes of those classes, and their member classes, etc.
 */
private List<ClassDocImpl> getClasses(boolean filtered) {
    if (allClasses != null && !filtered) {
        return allClasses;
    }
    if (allClassesFiltered != null && filtered) {
        return allClassesFiltered;
    }
    ListBuffer<ClassDocImpl> classes = new ListBuffer<ClassDocImpl>();
    for (Scope.Entry e = sym.members().elems; e != null; e = e.sibling) {
        if (e.sym != null) {
            ClassSymbol s = (ClassSymbol)e.sym;
            ClassDocImpl c = env.getClassDoc(s);
            if (c != null && !c.isSynthetic())
                c.addAllClasses(classes, filtered);
        }
    }
    if (filtered)
        return allClassesFiltered = classes.toList();
    else
        return allClasses = classes.toList();
}
 
Example 6
Source File: AnnotationProxyMaker.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a map from element symbols to their values.
 * Includes all elements, whether explicit or defaulted.
 */
private Map<MethodSymbol, Attribute> getAllValues() {
    Map<MethodSymbol, Attribute> res =
        new LinkedHashMap<MethodSymbol, Attribute>();

    // First find the default values.
    ClassSymbol sym = (ClassSymbol) anno.type.tsym;
    for (Scope.Entry e = sym.members().elems; e != null; e = e.sibling) {
        if (e.sym.kind == Kinds.MTH) {
            MethodSymbol m = (MethodSymbol) e.sym;
            Attribute def = m.getDefaultValue();
            if (def != null)
                res.put(m, def);
        }
    }
    // Next find the explicit values, possibly overriding defaults.
    for (Pair<MethodSymbol, Attribute> p : anno.values)
        res.put(p.fst, p.snd);
    return res;
}
 
Example 7
Source File: SerializedForm.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private VarSymbol getDefinedSerializableFields(ClassSymbol def) {
    Names names = def.name.table.names;

    /* SERIALIZABLE_FIELDS can be private,
     * so must lookup by ClassSymbol, not by ClassDocImpl.
     */
    for (Scope.Entry e = def.members().lookup(names.fromString(SERIALIZABLE_FIELDS)); e.scope != null; e = e.next()) {
        if (e.sym.kind == Kinds.VAR) {
            VarSymbol f = (VarSymbol)e.sym;
            if ((f.flags() & Flags.STATIC) != 0 &&
                (f.flags() & Flags.PRIVATE) != 0) {
                return f;
            }
        }
    }
    return null;
}
 
Example 8
Source File: SerializedForm.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private void addMethodIfExist(DocEnv env, ClassSymbol def, String methodName) {
    Names names = def.name.table.names;

    for (Scope.Entry e = def.members().lookup(names.fromString(methodName)); e.scope != null; e = e.next()) {
        if (e.sym.kind == Kinds.MTH) {
            MethodSymbol md = (MethodSymbol)e.sym;
            if ((md.flags() & Flags.STATIC) == 0) {
                /*
                 * WARNING: not robust if unqualifiedMethodName is overloaded
                 *          method. Signature checking could make more robust.
                 * READOBJECT takes a single parameter, java.io.ObjectInputStream.
                 * WRITEOBJECT takes a single parameter, java.io.ObjectOutputStream.
                 */
                methods.append(env.getMethodDoc(md));
            }
        }
    }
}
 
Example 9
Source File: JNIWriter.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private boolean needsHeader(ClassSymbol c, boolean checkNestedClasses) {
    if (c.isLocal() || (c.flags() & Flags.SYNTHETIC) != 0)
        return false;

    for (Scope.Entry i = c.members_field.elems; i != null; i = i.sibling) {
        if (i.sym.kind == Kinds.MTH && (i.sym.flags() & Flags.NATIVE) != 0)
            return true;
        for (Attribute.Compound a: i.sym.getDeclarationAttributes()) {
            if (a.type.tsym == syms.nativeHeaderType.tsym)
                return true;
        }
    }
    if (checkNestedClasses) {
        for (Scope.Entry i = c.members_field.elems; i != null; i = i.sibling) {
            if ((i.sym.kind == Kinds.TYP) && needsHeader(((ClassSymbol) i.sym), true))
                return true;
        }
    }
    return false;
}
 
Example 10
Source File: FilteredMemberList.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Iterator<Symbol> iterator() {
    return new Iterator<Symbol>() {

        /** The next entry to examine, or null if none. */
        private Scope.Entry nextEntry = scope.elems;

        private boolean hasNextForSure = false;

        public boolean hasNext() {
            if (hasNextForSure) {
                return true;
            }
            while (nextEntry != null && unwanted(nextEntry.sym)) {
                nextEntry = nextEntry.sibling;
            }
            hasNextForSure = (nextEntry != null);
            return hasNextForSure;
        }

        public Symbol next() {
            if (hasNext()) {
                Symbol result = nextEntry.sym;
                nextEntry = nextEntry.sibling;
                hasNextForSure = false;
                return result;
            } else {
                throw new NoSuchElementException();
            }
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
 
Example 11
Source File: FilteredMemberList.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public int size() {
    int cnt = 0;
    for (Scope.Entry e = scope.elems; e != null; e = e.sibling) {
        if (!unwanted(e.sym))
            cnt++;
    }
    return cnt;
}
 
Example 12
Source File: FilteredMemberList.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public Iterator<Symbol> iterator() {
    return new Iterator<Symbol>() {

        /** The next entry to examine, or null if none. */
        private Scope.Entry nextEntry = scope.elems;

        private boolean hasNextForSure = false;

        public boolean hasNext() {
            if (hasNextForSure) {
                return true;
            }
            while (nextEntry != null && unwanted(nextEntry.sym)) {
                nextEntry = nextEntry.sibling;
            }
            hasNextForSure = (nextEntry != null);
            return hasNextForSure;
        }

        public Symbol next() {
            if (hasNext()) {
                Symbol result = nextEntry.sym;
                nextEntry = nextEntry.sibling;
                hasNextForSure = false;
                return result;
            } else {
                throw new NoSuchElementException();
            }
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
 
Example 13
Source File: FilteredMemberList.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public int size() {
    int cnt = 0;
    for (Scope.Entry e = scope.elems; e != null; e = e.sibling) {
        if (!unwanted(e.sym))
            cnt++;
    }
    return cnt;
}
 
Example 14
Source File: FilteredMemberList.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public int size() {
    int cnt = 0;
    for (Scope.Entry e = scope.elems; e != null; e = e.sibling) {
        if (!unwanted(e.sym))
            cnt++;
    }
    return cnt;
}
 
Example 15
Source File: FilteredMemberList.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public int size() {
    int cnt = 0;
    for (Scope.Entry e = scope.elems; e != null; e = e.sibling) {
        if (!unwanted(e.sym))
            cnt++;
    }
    return cnt;
}
 
Example 16
Source File: FilteredMemberList.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public Symbol get(int index) {
    for (Scope.Entry e = scope.elems; e != null; e = e.sibling) {
        if (!unwanted(e.sym) && (index-- == 0))
            return e.sym;
    }
    throw new IndexOutOfBoundsException();
}
 
Example 17
Source File: FilteredMemberList.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public Iterator<Symbol> iterator() {
    return new Iterator<Symbol>() {

        /** The next entry to examine, or null if none. */
        private Scope.Entry nextEntry = scope.elems;

        private boolean hasNextForSure = false;

        public boolean hasNext() {
            if (hasNextForSure) {
                return true;
            }
            while (nextEntry != null && unwanted(nextEntry.sym)) {
                nextEntry = nextEntry.sibling;
            }
            hasNextForSure = (nextEntry != null);
            return hasNextForSure;
        }

        public Symbol next() {
            if (hasNext()) {
                Symbol result = nextEntry.sym;
                nextEntry = nextEntry.sibling;
                hasNextForSure = false;
                return result;
            } else {
                throw new NoSuchElementException();
            }
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
 
Example 18
Source File: FilteredMemberList.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public Symbol get(int index) {
    for (Scope.Entry e = scope.elems; e != null; e = e.sibling) {
        if (!unwanted(e.sym) && (index-- == 0))
            return e.sym;
    }
    throw new IndexOutOfBoundsException();
}
 
Example 19
Source File: T6889255.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
void test(String testName, boolean expectNames, String... opts) throws Exception {
    System.err.println("Test " + testName
            + ": expectNames:" + expectNames
            + " javacOpts:" + Arrays.asList(opts));

    File outDir = new File(testName);
    outDir.mkdirs();
    compile(outDir, opts);

    Context ctx = new Context();
    JavacFileManager fm = new JavacFileManager(ctx, true, null);
    fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(outDir));
    ClassReader cr = ClassReader.instance(ctx);
    cr.saveParameterNames = true;
    Names names = Names.instance(ctx);

    Set<String> classes = getTopLevelClasses(outDir);
    Deque<String> work = new LinkedList<String>(classes);
    String classname;
    while ((classname = work.poll()) != null) {
        System.err.println("Checking class " + classname);
        ClassSymbol sym = cr.enterClass(names.table.fromString(classname));
        sym.complete();

        if ((sym.flags() & Flags.INTERFACE) != 0 && !testInterfaces)
            continue;

        for (Scope.Entry e = sym.members_field.elems; e != null; e = e.sibling) {
            System.err.println("Checking member " + e.sym);
            switch (e.sym.kind) {
                case Kinds.TYP: {
                    String name = e.sym.flatName().toString();
                    if (!classes.contains(name)) {
                        classes.add(name);
                        work.add(name);
                    }
                    break;
                }
                case Kinds.MTH:
                    verify((MethodSymbol) e.sym, expectNames);
                    break;
            }

        }
    }
}
 
Example 20
Source File: T6889255.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
void test(String testName, boolean expectNames, String... opts) throws Exception {
    System.err.println("Test " + testName
            + ": expectNames:" + expectNames
            + " javacOpts:" + Arrays.asList(opts));

    File outDir = new File(testName);
    outDir.mkdirs();
    compile(outDir, opts);

    Context ctx = new Context();
    JavacFileManager fm = new JavacFileManager(ctx, true, null);
    fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(outDir));
    ClassReader cr = ClassReader.instance(ctx);
    cr.saveParameterNames = true;
    Names names = Names.instance(ctx);

    Set<String> classes = getTopLevelClasses(outDir);
    Deque<String> work = new LinkedList<String>(classes);
    String classname;
    while ((classname = work.poll()) != null) {
        System.err.println("Checking class " + classname);
        ClassSymbol sym = cr.enterClass(names.table.fromString(classname));
        sym.complete();

        if ((sym.flags() & Flags.INTERFACE) != 0 && !testInterfaces)
            continue;

        for (Scope.Entry e = sym.members_field.elems; e != null; e = e.sibling) {
            System.err.println("Checking member " + e.sym);
            switch (e.sym.kind) {
                case Kinds.TYP: {
                    String name = e.sym.flatName().toString();
                    if (!classes.contains(name)) {
                        classes.add(name);
                        work.add(name);
                    }
                    break;
                }
                case Kinds.MTH:
                    verify((MethodSymbol) e.sym, expectNames);
                    break;
            }

        }
    }
}