Java Code Examples for com.sun.tools.javac.code.Flags#AUTOMATIC_MODULE

The following examples show how to use com.sun.tools.javac.code.Flags#AUTOMATIC_MODULE . 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 6 votes vote down vote up
private void completeAutomaticModule(ModuleSymbol msym) throws CompletionFailure {
    ListBuffer<Directive> directives = new ListBuffer<>();

    directives.addAll(msym.directives);

    ListBuffer<RequiresDirective> requires = new ListBuffer<>();

    for (ModuleSymbol ms : allModules()) {
        if (ms == syms.unnamedModule || ms == msym)
            continue;
        Set<RequiresFlag> flags = (ms.flags_field & Flags.AUTOMATIC_MODULE) != 0 ?
                EnumSet.of(RequiresFlag.TRANSITIVE) : EnumSet.noneOf(RequiresFlag.class);
        RequiresDirective d = new RequiresDirective(ms, flags);
        directives.add(d);
        requires.add(d);
    }

    RequiresDirective requiresUnnamed = new RequiresDirective(syms.unnamedModule);
    directives.add(requiresUnnamed);
    requires.add(requiresUnnamed);

    msym.requires = requires.toList();
    msym.directives = directives.toList();
}
 
Example 2
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void completeAutomaticModule(ModuleSymbol msym) throws CompletionFailure {
    ListBuffer<Directive> directives = new ListBuffer<>();

    directives.addAll(msym.directives);

    ListBuffer<RequiresDirective> requires = new ListBuffer<>();

    for (ModuleSymbol ms : allModules()) {
        if (ms == syms.unnamedModule || ms == msym)
            continue;
        Set<RequiresFlag> flags = (ms.flags_field & Flags.AUTOMATIC_MODULE) != 0 ?
                EnumSet.of(RequiresFlag.TRANSITIVE) : EnumSet.noneOf(RequiresFlag.class);
        RequiresDirective d = new RequiresDirective(ms, flags);
        directives.add(d);
        requires.add(d);
    }

    RequiresDirective requiresUnnamed = new RequiresDirective(syms.unnamedModule);
    directives.add(requiresUnnamed);
    requires.add(requiresUnnamed);

    msym.requires = requires.toList();
    msym.directives = directives.toList();
}
 
Example 3
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void checkModuleRequires(final DiagnosticPosition pos, final RequiresDirective rd) {
    if ((rd.module.flags() & Flags.AUTOMATIC_MODULE) != 0) {
        deferredLintHandler.report(() -> {
            if (rd.isTransitive() && lint.isEnabled(LintCategory.REQUIRES_TRANSITIVE_AUTOMATIC)) {
                log.warning(pos, Warnings.RequiresTransitiveAutomatic);
            } else if (lint.isEnabled(LintCategory.REQUIRES_AUTOMATIC)) {
                log.warning(pos, Warnings.RequiresAutomatic);
            }
        });
    }
}
 
Example 4
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void complete(Symbol sym) throws CompletionFailure {
    ModuleSymbol msym = moduleFinder.findModule((ModuleSymbol) sym);

    if (msym.kind == ERR) {
        //make sure the module is initialized:
        msym.directives = List.nil();
        msym.exports = List.nil();
        msym.provides = List.nil();
        msym.requires = List.nil();
        msym.uses = List.nil();
    } else if ((msym.flags_field & Flags.AUTOMATIC_MODULE) != 0) {
        setupAutomaticModule(msym);
    } else {
        msym.module_info.complete();
    }

    // If module-info comes from a .java file, the underlying
    // call of classFinder.fillIn will have called through the
    // source completer, to Enter, and then to Modules.enter,
    // which will call completeModule.
    // But, if module-info comes from a .class file, the underlying
    // call of classFinder.fillIn will just call ClassReader to read
    // the .class file, and so we call completeModule here.
    if (msym.module_info.classfile == null || msym.module_info.classfile.getKind() == Kind.CLASS) {
        completeModule(msym);
    }
}
 
Example 5
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void complete(Symbol sym) throws CompletionFailure {
    ModuleSymbol msym = moduleFinder.findModule((ModuleSymbol) sym);

    if (msym.kind == ERR) {
        //make sure the module is initialized:
        msym.directives = List.nil();
        msym.exports = List.nil();
        msym.provides = List.nil();
        msym.requires = List.nil();
        msym.uses = List.nil();
    } else if ((msym.flags_field & Flags.AUTOMATIC_MODULE) != 0) {
        setupAutomaticModule(msym);
    } else {
        msym.module_info.complete();
    }

    // If module-info comes from a .java file, the underlying
    // call of classFinder.fillIn will have called through the
    // source completer, to Enter, and then to Modules.enter,
    // which will call completeModule.
    // But, if module-info comes from a .class file, the underlying
    // call of classFinder.fillIn will just call ClassReader to read
    // the .class file, and so we call completeModule here.
    if (msym.module_info.classfile == null || msym.module_info.classfile.getKind() == Kind.CLASS) {
        completeModule(msym);
    }
}
 
Example 6
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private Set<ModuleSymbol> computeTransitiveClosure(Set<? extends ModuleSymbol> base,
                                                   Set<? extends ModuleSymbol> rootModules,
                                                   Set<ModuleSymbol> observable) {
    List<ModuleSymbol> primaryTodo = List.nil();
    List<ModuleSymbol> secondaryTodo = List.nil();

    for (ModuleSymbol ms : base) {
        if (rootModules.contains(ms)) {
            primaryTodo = primaryTodo.prepend(ms);
        } else {
            secondaryTodo = secondaryTodo.prepend(ms);
        }
    }

    Set<ModuleSymbol> result = new LinkedHashSet<>();
    result.add(syms.java_base);

    while (primaryTodo.nonEmpty() || secondaryTodo.nonEmpty()) {
        try {
            ModuleSymbol current;
            boolean isPrimaryTodo;
            if (primaryTodo.nonEmpty()) {
                current = primaryTodo.head;
                primaryTodo = primaryTodo.tail;
                isPrimaryTodo = true;
            } else {
                current = secondaryTodo.head;
                secondaryTodo = secondaryTodo.tail;
                isPrimaryTodo = false;
            }
            if (observable != null && !observable.contains(current))
                continue;
            if (!result.add(current) || current == syms.unnamedModule || ((current.flags_field & Flags.AUTOMATIC_MODULE) != 0))
                continue;
            current.complete();
            if (current.kind == ERR && (isPrimaryTodo || base.contains(current)) && warnedMissing.add(current)) {
                log.error(Errors.ModuleNotFound(current));
            }
            for (RequiresDirective rd : current.requires) {
                if (rd.module == syms.java_base) continue;
                if ((rd.isTransitive() && isPrimaryTodo) || rootModules.contains(current)) {
                    primaryTodo = primaryTodo.prepend(rd.module);
                } else {
                    secondaryTodo = secondaryTodo.prepend(rd.module);
                }
            }
        } catch (CompletionFailure ex) {
            chk.completionError(null, ex);
        }
    }

    return result;
}
 
Example 7
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private Set<ModuleSymbol> computeTransitiveClosure(Set<? extends ModuleSymbol> base,
                                                   Set<? extends ModuleSymbol> rootModules,
                                                   Set<ModuleSymbol> observable) {
    List<ModuleSymbol> primaryTodo = List.nil();
    List<ModuleSymbol> secondaryTodo = List.nil();

    for (ModuleSymbol ms : base) {
        if (rootModules.contains(ms)) {
            primaryTodo = primaryTodo.prepend(ms);
        } else {
            secondaryTodo = secondaryTodo.prepend(ms);
        }
    }

    Set<ModuleSymbol> result = new LinkedHashSet<>();
    result.add(syms.java_base);

    while (primaryTodo.nonEmpty() || secondaryTodo.nonEmpty()) {
        ModuleSymbol current;
        boolean isPrimaryTodo;
        if (primaryTodo.nonEmpty()) {
            current = primaryTodo.head;
            primaryTodo = primaryTodo.tail;
            isPrimaryTodo = true;
        } else {
            current = secondaryTodo.head;
            secondaryTodo = secondaryTodo.tail;
            isPrimaryTodo = false;
        }
        if (observable != null && !observable.contains(current))
            continue;
        if (!result.add(current) || current == syms.unnamedModule || ((current.flags_field & Flags.AUTOMATIC_MODULE) != 0))
            continue;
        current.complete();
        if (current.kind == ERR && (isPrimaryTodo || base.contains(current)) && warnedMissing.add(current)) {
            log.error(Errors.ModuleNotFound(current));
        }
        for (RequiresDirective rd : current.requires) {
            if (rd.module == syms.java_base) continue;
            if ((rd.isTransitive() && isPrimaryTodo) || rootModules.contains(current)) {
                primaryTodo = primaryTodo.prepend(rd.module);
            } else {
                secondaryTodo = secondaryTodo.prepend(rd.module);
            }
        }
    }

    return result;
}