com.sun.tools.javac.code.Symbol.Completer Java Examples

The following examples show how to use com.sun.tools.javac.code.Symbol.Completer. 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 Completer getUnnamedModuleCompleter() {
    moduleFinder.findAllModules();
    return new Symbol.Completer() {
        @Override
        public void complete(Symbol sym) throws CompletionFailure {
            if (inInitModules) {
                sym.completer = this;
                return ;
            }
            ModuleSymbol msym = (ModuleSymbol) sym;
            Set<ModuleSymbol> allModules = new HashSet<>(allModules());
            allModules.remove(syms.unnamedModule);
            for (ModuleSymbol m : allModules) {
                m.complete();
            }
            initVisiblePackages(msym, allModules);
        }

        @Override
        public String toString() {
            return "unnamedModule Completer";
        }
    };
}
 
Example #2
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private Completer getUnnamedModuleCompleter() {
    moduleFinder.findAllModules();
    return new Symbol.Completer() {
        @Override
        public void complete(Symbol sym) throws CompletionFailure {
            if (inInitModules) {
                sym.completer = this;
                return ;
            }
            ModuleSymbol msym = (ModuleSymbol) sym;
            Set<ModuleSymbol> allModules = new HashSet<>(allModules());
            allModules.remove(syms.unnamedModule);
            for (ModuleSymbol m : allModules) {
                m.complete();
            }
            initVisiblePackages(msym, allModules);
        }

        @Override
        public String toString() {
            return "unnamedModule Completer";
        }
    };
}
 
Example #3
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public Completer getUsesProvidesCompleter() {
    return sym -> {
        ModuleSymbol msym = (ModuleSymbol) sym;

        msym.complete();

        Env<AttrContext> env = typeEnvs.get(msym);
        UsesProvidesVisitor v = new UsesProvidesVisitor(msym, env);
        JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
        JCModuleDecl decl = env.toplevel.getModuleDecl();
        DiagnosticPosition prevLintPos = deferredLintHandler.setPos(decl.pos());

        try {
            decl.accept(v);
        } finally {
            log.useSource(prev);
            deferredLintHandler.setPos(prevLintPos);
        }
    };
}
 
Example #4
Source File: Symtab.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void synthesizeEmptyInterfaceIfMissing(final Type type) {
    final Completer completer = type.tsym.completer;
    type.tsym.completer = new Completer() {
        @Override
        public void complete(Symbol sym) throws CompletionFailure {
            try {
                completer.complete(sym);
            } catch (CompletionFailure e) {
                sym.flags_field |= (PUBLIC | INTERFACE);
                ((ClassType) sym.type).supertype_field = objectType;
            }
        }

        @Override
        public boolean isTerminal() {
            return completer.isTerminal();
        }
    };
}
 
Example #5
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Completer getUsesProvidesCompleter() {
    return sym -> {
        ModuleSymbol msym = (ModuleSymbol) sym;

        msym.complete();

        Env<AttrContext> env = typeEnvs.get(msym);
        UsesProvidesVisitor v = new UsesProvidesVisitor(msym, env);
        JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
        JCModuleDecl decl = env.toplevel.getModuleDecl();
        DiagnosticPosition prevLintPos = deferredLintHandler.setPos(decl.pos());

        try {
            decl.accept(v);
        } finally {
            log.useSource(prev);
            deferredLintHandler.setPos(prevLintPos);
        }
    };
}
 
Example #6
Source File: Symtab.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void synthesizeEmptyInterfaceIfMissing(final Type type) {
    final Completer completer = type.tsym.completer;
    type.tsym.completer = new Completer() {
        @Override
        public void complete(Symbol sym) throws CompletionFailure {
            try {
                completer.complete(sym);
            } catch (CompletionFailure e) {
                sym.flags_field |= (PUBLIC | INTERFACE);
                ((ClassType) sym.type).supertype_field = objectType;
            }
        }

        @Override
        public boolean isTerminal() {
            return completer.isTerminal();
        }
    };
}
 
Example #7
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
JCClassDecl makeEmptyClass(long flags, ClassSymbol owner, Name flatname,
        boolean addToDefs) {
    // Create class symbol.
    ClassSymbol c = syms.defineClass(names.empty, owner);
    if (flatname != null) {
        c.flatname = flatname;
    } else {
        c.flatname = chk.localClassName(c);
    }
    c.sourcefile = owner.sourcefile;
    c.completer = Completer.NULL_COMPLETER;
    c.members_field = WriteableScope.create(c);
    c.flags_field = flags;
    ClassType ctype = (ClassType) c.type;
    ctype.supertype_field = syms.objectType;
    ctype.interfaces_field = List.nil();

    JCClassDecl odef = classDef(owner);

    // Enter class symbol in owner scope and compiled table.
    enterSynthetic(odef.pos(), c, owner.members());
    chk.putCompiled(c);

    // Create class definition tree.
    JCClassDecl cdef = make.ClassDef(
        make.Modifiers(flags), names.empty,
        List.nil(),
        null, List.nil(), List.nil());
    cdef.sym = c;
    cdef.type = c.type;

    // Append class definition tree to owner's definitions.
    if (addToDefs) odef.defs = odef.defs.prepend(cdef);
    return cdef;
}
 
Example #8
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Completer getSourceCompleter(JCCompilationUnit tree) {
    return new Completer() {
        @Override
        public void complete(Symbol sym) throws CompletionFailure {
            ModuleSymbol msym = (ModuleSymbol) sym;
            msym.flags_field |= UNATTRIBUTED;
            ModuleVisitor v = new ModuleVisitor();
            JavaFileObject prev = log.useSource(tree.sourcefile);
            JCModuleDecl moduleDecl = tree.getModuleDecl();
            DiagnosticPosition prevLintPos = deferredLintHandler.setPos(moduleDecl.pos());

            try {
                moduleDecl.accept(v);
                completeModule(msym);
                checkCyclicDependencies(moduleDecl);
            } finally {
                log.useSource(prev);
                deferredLintHandler.setPos(prevLintPos);
                msym.flags_field &= ~UNATTRIBUTED;
            }
        }

        @Override
        public String toString() {
            return "SourceCompleter: " + tree.sourcefile.getName();
        }

    };
}
 
Example #9
Source File: Symtab.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Type enterSyntheticAnnotation(String name) {
    // for now, leave the module null, to prevent problems from synthesizing the
    // existence of a class in any specific module, including noModule
    ClassType type = (ClassType)enterClass(java_base, names.fromString(name)).type;
    ClassSymbol sym = (ClassSymbol)type.tsym;
    sym.completer = Completer.NULL_COMPLETER;
    sym.flags_field = PUBLIC|ACYCLIC|ANNOTATION|INTERFACE;
    sym.erasure_field = type;
    sym.members_field = WriteableScope.create(sym);
    type.typarams_field = List.nil();
    type.allparams_field = List.nil();
    type.supertype_field = annotationType;
    type.interfaces_field = List.nil();
    return type;
}
 
Example #10
Source File: Symtab.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void synthesizeEmptyInterfaceIfMissing(final Type type) {
    final Completer completer = type.tsym.completer;
    if (completer != null) {
        type.tsym.completer = new Completer() {
            public void complete(Symbol sym) throws CompletionFailure {
                try {
                    completer.complete(sym);
                } catch (CompletionFailure e) {
                    sym.flags_field |= (PUBLIC | INTERFACE);
                    ((ClassType) sym.type).supertype_field = objectType;
                }
            }
        };
    }
}
 
Example #11
Source File: Symtab.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public void synthesizeEmptyInterfaceIfMissing(final Type type) {
    final Completer completer = type.tsym.completer;
    if (completer != null) {
        type.tsym.completer = new Completer() {
            public void complete(Symbol sym) throws CompletionFailure {
                try {
                    completer.complete(sym);
                } catch (CompletionFailure e) {
                    sym.flags_field |= (PUBLIC | INTERFACE);
                    ((ClassType) sym.type).supertype_field = objectType;
                }
            }
        };
    }
}
 
Example #12
Source File: ModuleFinder.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void findModuleInfo(ModuleSymbol msym) {
    try {
        JavaFileObject fo;

        fo = getModuleInfoFromLocation(msym.patchOutputLocation, Kind.CLASS);
        fo = preferredFileObject(getModuleInfoFromLocation(msym.patchLocation, Kind.CLASS), fo);
        fo = preferredFileObject(getModuleInfoFromLocation(msym.patchLocation, Kind.SOURCE), fo);

        if (fo == null) {
            fo = getModuleInfoFromLocation(msym.classLocation, Kind.CLASS);
            fo = preferredFileObject(getModuleInfoFromLocation(msym.sourceLocation, Kind.SOURCE), fo);
        }

        if (fo == null) {
            String moduleName = msym.sourceLocation == null && msym.classLocation != null ?
                fileManager.inferModuleName(msym.classLocation) : null;
            if (moduleName != null) {
                msym.module_info.classfile = null;
                msym.flags_field |= Flags.AUTOMATIC_MODULE;
            } else {
                msym.kind = ERR;
            }
        } else {
            msym.module_info.classfile = fo;
            msym.module_info.completer = new Symbol.Completer() {
                @Override
                public void complete(Symbol sym) throws CompletionFailure {
                    classFinder.fillIn(msym.module_info);
                }
                @Override
                public String toString() {
                    return "ModuleInfoCompleter";
                }
            };
        }
    } catch (IOException e) {
        msym.kind = ERR;
    }
}
 
Example #13
Source File: Symtab.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private Type enterSyntheticAnnotation(String name) {
    // for now, leave the module null, to prevent problems from synthesizing the
    // existence of a class in any specific module, including noModule
    ClassType type = (ClassType)enterClass(java_base, names.fromString(name)).type;
    ClassSymbol sym = (ClassSymbol)type.tsym;
    sym.completer = Completer.NULL_COMPLETER;
    sym.flags_field = PUBLIC|ACYCLIC|ANNOTATION|INTERFACE;
    sym.erasure_field = type;
    sym.members_field = WriteableScope.create(sym);
    type.typarams_field = List.nil();
    type.allparams_field = List.nil();
    type.supertype_field = annotationType;
    type.interfaces_field = List.nil();
    return type;
}
 
Example #14
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private Completer getSourceCompleter(JCCompilationUnit tree) {
    return new Completer() {
        @Override
        public void complete(Symbol sym) throws CompletionFailure {
            ModuleSymbol msym = (ModuleSymbol) sym;
            msym.flags_field |= UNATTRIBUTED;
            ModuleVisitor v = new ModuleVisitor();
            JavaFileObject prev = log.useSource(tree.sourcefile);
            JCModuleDecl moduleDecl = tree.getModuleDecl();
            DiagnosticPosition prevLintPos = deferredLintHandler.setPos(moduleDecl.pos());

            try {
                moduleDecl.accept(v);
                completeModule(msym);
                checkCyclicDependencies(moduleDecl);
            } finally {
                log.useSource(prev);
                deferredLintHandler.setPos(prevLintPos);
                msym.flags_field &= ~UNATTRIBUTED;
            }
        }

        @Override
        public String toString() {
            return "SourceCompleter: " + tree.sourcefile.getName();
        }

    };
}
 
Example #15
Source File: ModuleFinder.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void findModuleInfo(ModuleSymbol msym) {
    try {
        JavaFileObject fo;

        fo = getModuleInfoFromLocation(msym.patchOutputLocation, Kind.CLASS);
        fo = preferredFileObject(getModuleInfoFromLocation(msym.patchLocation, Kind.CLASS), fo);
        fo = preferredFileObject(getModuleInfoFromLocation(msym.patchLocation, Kind.SOURCE), fo);

        if (fo == null) {
            fo = getModuleInfoFromLocation(msym.classLocation, Kind.CLASS);
            fo = preferredFileObject(getModuleInfoFromLocation(msym.sourceLocation, Kind.SOURCE), fo);
        }

        if (fo == null) {
            String moduleName = msym.sourceLocation == null && msym.classLocation != null ?
                fileManager.inferModuleName(msym.classLocation) : null;
            if (moduleName != null) {
                msym.module_info.classfile = null;
                msym.flags_field |= Flags.AUTOMATIC_MODULE;
            } else {
                msym.kind = ERR;
            }
        } else {
            msym.module_info.classfile = fo;
            msym.module_info.completer = new Symbol.Completer() {
                @Override
                public void complete(Symbol sym) throws CompletionFailure {
                    classFinder.fillIn(msym.module_info);
                }
                @Override
                public String toString() {
                    return "ModuleInfoCompleter";
                }
            };
        }
    } catch (IOException e) {
        msym.kind = ERR;
    }
}
 
Example #16
Source File: ClassFinder.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Completer getCompleter() {
    return thisCompleter;
}
 
Example #17
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Completer getCompleter() {
    return mainCompleter;
}
 
Example #18
Source File: ModuleFinder.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private ModuleSymbol readModule(JavaFileObject fo) throws IOException {
    Name name;
    switch (fo.getKind()) {
        case SOURCE:
            name = moduleNameFromSourceReader.readModuleName(fo);
            if (name == null) {
                JCDiagnostic diag =
                    diags.fragment("file.does.not.contain.module");
                ClassSymbol errModuleInfo = syms.defineClass(names.module_info, syms.errModule);
                throw new ClassFinder.BadClassFile(errModuleInfo, fo, diag, diags);
            }
            break;
        case CLASS:
            try {
                name = names.fromString(readModuleName(fo));
            } catch (BadClassFile | IOException ex) {
                //fillIn will report proper errors:
                name = names.error;
            }
            break;
        default:
            Assert.error();
            name = names.error;
            break;
    }

    ModuleSymbol msym = syms.enterModule(name);
    msym.module_info.classfile = fo;
    if (fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH) && name != names.error) {
        msym.patchLocation = fileManager.getLocationForModule(StandardLocation.PATCH_MODULE_PATH, name.toString());

        if (msym.patchLocation != null) {
            JavaFileObject patchFO = getModuleInfoFromLocation(StandardLocation.CLASS_OUTPUT, Kind.CLASS);
            patchFO = preferredFileObject(getModuleInfoFromLocation(msym.patchLocation, Kind.CLASS), patchFO);
            patchFO = preferredFileObject(getModuleInfoFromLocation(msym.patchLocation, Kind.SOURCE), patchFO);

            if (patchFO != null) {
                msym.module_info.classfile = patchFO;
            }
        }
    }

    msym.completer = Completer.NULL_COMPLETER;
    classFinder.fillIn(msym.module_info);

    return msym;
}
 
Example #19
Source File: ClassFinder.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public Completer getCompleter() {
    return thisCompleter;
}
 
Example #20
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public Completer getCompleter() {
    return mainCompleter;
}
 
Example #21
Source File: ModuleFinder.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private ModuleSymbol readModule(JavaFileObject fo) throws IOException {
    Name name;
    switch (fo.getKind()) {
        case SOURCE:
            name = moduleNameFromSourceReader.readModuleName(fo);
            if (name == null) {
                JCDiagnostic diag =
                    diags.fragment(Fragments.FileDoesNotContainModule);
                ClassSymbol errModuleInfo = syms.defineClass(names.module_info, syms.errModule);
                throw new ClassFinder.BadClassFile(errModuleInfo, fo, diag, diags);
            }
            break;
        case CLASS:
            try {
                name = names.fromString(readModuleName(fo));
            } catch (BadClassFile | IOException ex) {
                //fillIn will report proper errors:
                name = names.error;
            }
            break;
        default:
            Assert.error();
            name = names.error;
            break;
    }

    ModuleSymbol msym = syms.enterModule(name);
    msym.module_info.classfile = fo;
    if (fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH) && name != names.error) {
        msym.patchLocation = fileManager.getLocationForModule(StandardLocation.PATCH_MODULE_PATH, name.toString());

        if (msym.patchLocation != null) {
            JavaFileObject patchFO = getModuleInfoFromLocation(StandardLocation.CLASS_OUTPUT, Kind.CLASS);
            patchFO = preferredFileObject(getModuleInfoFromLocation(msym.patchLocation, Kind.CLASS), patchFO);
            patchFO = preferredFileObject(getModuleInfoFromLocation(msym.patchLocation, Kind.SOURCE), patchFO);

            if (patchFO != null) {
                msym.module_info.classfile = patchFO;
            }
        }
    }

    msym.completer = Completer.NULL_COMPLETER;
    classFinder.fillIn(msym.module_info);

    return msym;
}