Java Code Examples for com.sun.tools.javac.code.Symbol.ModuleSymbol#flags()

The following examples show how to use com.sun.tools.javac.code.Symbol.ModuleSymbol#flags() . 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: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void checkCyclicDependencies(JCModuleDecl mod) {
    for (JCDirective d : mod.directives) {
        JCRequires rd;
        if (!d.hasTag(Tag.REQUIRES) || (rd = (JCRequires) d).directive == null)
            continue;
        Set<ModuleSymbol> nonSyntheticDeps = new HashSet<>();
        List<ModuleSymbol> queue = List.of(rd.directive.module);
        while (queue.nonEmpty()) {
            ModuleSymbol current = queue.head;
            queue = queue.tail;
            if (!nonSyntheticDeps.add(current))
                continue;
            current.complete();
            if ((current.flags() & Flags.ACYCLIC) != 0)
                continue;
            Assert.checkNonNull(current.requires, current::toString);
            for (RequiresDirective dep : current.requires) {
                if (!dep.flags.contains(RequiresFlag.EXTRA))
                    queue = queue.prepend(dep.module);
            }
        }
        if (nonSyntheticDeps.contains(mod.sym)) {
            log.error(rd.moduleName.pos(), Errors.CyclicRequires(rd.directive.module));
        }
        mod.sym.flags_field |= Flags.ACYCLIC;
    }
}
 
Example 2
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void checkCyclicDependencies(JCModuleDecl mod) {
    for (JCDirective d : mod.directives) {
        JCRequires rd;
        if (!d.hasTag(Tag.REQUIRES) || (rd = (JCRequires) d).directive == null)
            continue;
        Set<ModuleSymbol> nonSyntheticDeps = new HashSet<>();
        List<ModuleSymbol> queue = List.of(rd.directive.module);
        while (queue.nonEmpty()) {
            ModuleSymbol current = queue.head;
            queue = queue.tail;
            if (!nonSyntheticDeps.add(current))
                continue;
            current.complete();
            if ((current.flags() & Flags.ACYCLIC) != 0)
                continue;
            Assert.checkNonNull(current.requires, current::toString);
            for (RequiresDirective dep : current.requires) {
                if (!dep.flags.contains(RequiresFlag.EXTRA))
                    queue = queue.prepend(dep.module);
            }
        }
        if (nonSyntheticDeps.contains(mod.sym)) {
            log.error(rd.moduleName.pos(), Errors.CyclicRequires(rd.directive.module));
        }
        mod.sym.flags_field |= Flags.ACYCLIC;
    }
}
 
Example 3
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void initAddExports() {
    if (addExports != null)
        return;

    addExports = new LinkedHashMap<>();
    Set<ModuleSymbol> unknownModules = new HashSet<>();

    if (addExportsOpt == null)
        return;

    Pattern ep = Pattern.compile("([^/]+)/([^=]+)=(.*)");
    for (String s: addExportsOpt.split("\0+")) {
        if (s.isEmpty())
            continue;
        Matcher em = ep.matcher(s);
        if (!em.matches()) {
            continue;
        }

        // Terminology comes from
        //  --add-exports module/package=target,...
        // Compare to
        //  module module { exports package to target, ... }
        String moduleName = em.group(1);
        String packageName = em.group(2);
        String targetNames = em.group(3);

        if (!isValidName(moduleName))
            continue;

        ModuleSymbol msym = syms.enterModule(names.fromString(moduleName));
        if (!isKnownModule(msym, unknownModules))
            continue;

        if (!isValidName(packageName))
            continue;

        if (!allowAccessIntoSystem && (msym.flags() & Flags.SYSTEM_MODULE) != 0) {
            log.error(Errors.AddExportsWithRelease(msym));
            continue;
        }

        PackageSymbol p = syms.enterPackage(msym, names.fromString(packageName));
        p.modle = msym;  // TODO: do we need this?

        List<ModuleSymbol> targetModules = List.nil();
        for (String toModule : targetNames.split("[ ,]+")) {
            ModuleSymbol m;
            if (toModule.equals("ALL-UNNAMED")) {
                m = syms.unnamedModule;
            } else {
                if (!isValidName(toModule))
                    continue;
                m = syms.enterModule(names.fromString(toModule));
                if (!isKnownModule(m, unknownModules))
                    continue;
            }
            targetModules = targetModules.prepend(m);
        }

        Set<ExportsDirective> extra = Maps.computeIfAbsent(addExports,msym, _x -> new LinkedHashSet<>());
        ExportsDirective d = new ExportsDirective(p, targetModules);
        extra.add(d);
    }
}
 
Example 4
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void initAddReads() {
    if (addReads != null)
        return;

    addReads = new LinkedHashMap<>();

    if (addReadsOpt == null)
        return;

    Pattern rp = Pattern.compile("([^=]+)=(.*)");
    for (String s : addReadsOpt.split("\0+")) {
        if (s.isEmpty())
            continue;
        Matcher rm = rp.matcher(s);
        if (!rm.matches()) {
            continue;
        }

        // Terminology comes from
        //  --add-reads source-module=target-module,...
        // Compare to
        //  module source-module { requires target-module; ... }
        String sourceName = rm.group(1);
        String targetNames = rm.group(2);

        if (!isValidName(sourceName))
            continue;

        ModuleSymbol msym = syms.enterModule(names.fromString(sourceName));
        if (!allModules.contains(msym)) {
            if (lintOptions) {
                log.warning(Warnings.ModuleForOptionNotFound(Option.ADD_READS, msym));
            }
            continue;
        }

        if (!allowAccessIntoSystem && (msym.flags() & Flags.SYSTEM_MODULE) != 0) {
            log.error(Errors.AddReadsWithRelease(msym));
            continue;
        }

        for (String targetName : targetNames.split("[ ,]+", -1)) {
            ModuleSymbol targetModule;
            if (targetName.equals("ALL-UNNAMED")) {
                targetModule = syms.unnamedModule;
            } else {
                if (!isValidName(targetName))
                    continue;
                targetModule = syms.enterModule(names.fromString(targetName));
                if (!allModules.contains(targetModule)) {
                    if (lintOptions) {
                        log.warning(LintCategory.OPTIONS, Warnings.ModuleForOptionNotFound(Option.ADD_READS, targetModule));
                    }
                    continue;
                }
            }
            Maps.computeIfAbsent(addReads,msym, m -> new HashSet<>())
                    .add(new RequiresDirective(targetModule, EnumSet.of(RequiresFlag.EXTRA)));
        }
    }
}
 
Example 5
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void initAddExports() {
    if (addExports != null)
        return;

    addExports = new LinkedHashMap<>();
    Set<ModuleSymbol> unknownModules = new HashSet<>();

    if (addExportsOpt == null)
        return;

    Pattern ep = Pattern.compile("([^/]+)/([^=]+)=(.*)");
    for (String s: addExportsOpt.split("\0+")) {
        if (s.isEmpty())
            continue;
        Matcher em = ep.matcher(s);
        if (!em.matches()) {
            continue;
        }

        // Terminology comes from
        //  --add-exports module/package=target,...
        // Compare to
        //  module module { exports package to target, ... }
        String moduleName = em.group(1);
        String packageName = em.group(2);
        String targetNames = em.group(3);

        if (!isValidName(moduleName))
            continue;

        ModuleSymbol msym = syms.enterModule(names.fromString(moduleName));
        if (!isKnownModule(msym, unknownModules))
            continue;

        if (!isValidName(packageName))
            continue;

        if (!allowAccessIntoSystem && (msym.flags() & Flags.SYSTEM_MODULE) != 0) {
            log.error(Errors.AddExportsWithRelease(msym));
            continue;
        }

        PackageSymbol p = syms.enterPackage(msym, names.fromString(packageName));
        p.modle = msym;  // TODO: do we need this?

        List<ModuleSymbol> targetModules = List.nil();
        for (String toModule : targetNames.split("[ ,]+")) {
            ModuleSymbol m;
            if (toModule.equals("ALL-UNNAMED")) {
                m = syms.unnamedModule;
            } else {
                if (!isValidName(toModule))
                    continue;
                m = syms.enterModule(names.fromString(toModule));
                if (!isKnownModule(m, unknownModules))
                    continue;
            }
            targetModules = targetModules.prepend(m);
        }

        Set<ExportsDirective> extra = addExports.computeIfAbsent(msym, _x -> new LinkedHashSet<>());
        ExportsDirective d = new ExportsDirective(p, targetModules);
        extra.add(d);
    }
}
 
Example 6
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void initAddReads() {
    if (addReads != null)
        return;

    addReads = new LinkedHashMap<>();

    if (addReadsOpt == null)
        return;

    Pattern rp = Pattern.compile("([^=]+)=(.*)");
    for (String s : addReadsOpt.split("\0+")) {
        if (s.isEmpty())
            continue;
        Matcher rm = rp.matcher(s);
        if (!rm.matches()) {
            continue;
        }

        // Terminology comes from
        //  --add-reads source-module=target-module,...
        // Compare to
        //  module source-module { requires target-module; ... }
        String sourceName = rm.group(1);
        String targetNames = rm.group(2);

        if (!isValidName(sourceName))
            continue;

        ModuleSymbol msym = syms.enterModule(names.fromString(sourceName));
        if (!allModules.contains(msym)) {
            if (lintOptions) {
                log.warning(Warnings.ModuleForOptionNotFound(Option.ADD_READS, msym));
            }
            continue;
        }

        if (!allowAccessIntoSystem && (msym.flags() & Flags.SYSTEM_MODULE) != 0) {
            log.error(Errors.AddReadsWithRelease(msym));
            continue;
        }

        for (String targetName : targetNames.split("[ ,]+", -1)) {
            ModuleSymbol targetModule;
            if (targetName.equals("ALL-UNNAMED")) {
                targetModule = syms.unnamedModule;
            } else {
                if (!isValidName(targetName))
                    continue;
                targetModule = syms.enterModule(names.fromString(targetName));
                if (!allModules.contains(targetModule)) {
                    if (lintOptions) {
                        log.warning(LintCategory.OPTIONS, Warnings.ModuleForOptionNotFound(Option.ADD_READS, targetModule));
                    }
                    continue;
                }
            }
            addReads.computeIfAbsent(msym, m -> new HashSet<>())
                    .add(new RequiresDirective(targetModule, EnumSet.of(RequiresFlag.EXTRA)));
        }
    }
}