Search in sources :

Example 1 with Abort

use of com.sun.tools.javac.util.Abort in project ceylon-compiler by ceylon.

the class JavadocTool method getRootDocImpl.

public RootDocImpl getRootDocImpl(String doclocale, String encoding, ModifierFilter filter, List<String> javaNames, List<String[]> options, boolean breakiterator, List<String> subPackages, List<String> excludedPackages, boolean docClasses, boolean legacyDoclet, boolean quiet) throws IOException {
    docenv = DocEnv.instance(context);
    docenv.showAccess = filter;
    docenv.quiet = quiet;
    docenv.breakiterator = breakiterator;
    docenv.setLocale(doclocale);
    docenv.setEncoding(encoding);
    docenv.docClasses = docClasses;
    docenv.legacyDoclet = legacyDoclet;
    reader.sourceCompleter = docClasses ? null : this;
    ListBuffer<String> names = new ListBuffer<String>();
    ListBuffer<JCCompilationUnit> classTrees = new ListBuffer<JCCompilationUnit>();
    ListBuffer<JCCompilationUnit> packTrees = new ListBuffer<JCCompilationUnit>();
    try {
        StandardJavaFileManager fm = (StandardJavaFileManager) docenv.fileManager;
        for (List<String> it = javaNames; it.nonEmpty(); it = it.tail) {
            String name = it.head;
            if (!docClasses && name.endsWith(".java") && new File(name).exists()) {
                JavaFileObject fo = fm.getJavaFileObjects(name).iterator().next();
                docenv.notice("main.Loading_source_file", name);
                JCCompilationUnit tree = parse(fo);
                classTrees.append(tree);
            } else if (isValidPackageName(name)) {
                names = names.append(name);
            } else if (name.endsWith(".java")) {
                docenv.error(null, "main.file_not_found", name);
            } else {
                docenv.error(null, "main.illegal_package_name", name);
            }
        }
        if (!docClasses) {
            // Recursively search given subpackages.  If any packages
            //are found, add them to the list.
            Map<String, List<JavaFileObject>> packageFiles = searchSubPackages(subPackages, names, excludedPackages);
            // Parse the packages
            for (List<String> packs = names.toList(); packs.nonEmpty(); packs = packs.tail) {
                // Parse sources ostensibly belonging to package.
                String packageName = packs.head;
                parsePackageClasses(packageName, packageFiles.get(packageName), packTrees, excludedPackages);
            }
            if (messager.nerrors() != 0)
                return null;
            // Enter symbols for all files
            docenv.notice("main.Building_tree");
            enter.main(classTrees.toList().appendList(packTrees.toList()));
        }
    } catch (Abort ex) {
    }
    if (messager.nerrors() != 0)
        return null;
    if (docClasses)
        return new RootDocImpl(docenv, javaNames, options);
    else
        return new RootDocImpl(docenv, listClasses(classTrees.toList()), names.toList(), options);
}
Also used : JCCompilationUnit(com.sun.tools.javac.tree.JCTree.JCCompilationUnit) ListBuffer(com.sun.tools.javac.util.ListBuffer) JavaFileObject(javax.tools.JavaFileObject) Abort(com.sun.tools.javac.util.Abort) StandardJavaFileManager(javax.tools.StandardJavaFileManager) List(com.sun.tools.javac.util.List) File(java.io.File)

Example 2 with Abort

use of com.sun.tools.javac.util.Abort in project ceylon-compiler by ceylon.

the class CeylonEnter method prepareForTypeChecking.

public void prepareForTypeChecking(List<JCCompilationUnit> trees) {
    if (hasRun)
        throw new RuntimeException("Waaaaa, running twice!!!");
    //By now le language module version should be known (as local)
    //or we should use the default one.
    int numParserErrors = log.nerrors;
    // load the standard modules
    timer.startTask("loadStandardModules");
    compilerDelegate.loadStandardModules(modelLoader);
    timer.endTask();
    // load the modules we are compiling first
    hasRun = true;
    // make sure we don't load the files we are compiling from their class files
    timer.startTask("setupSourceFileObjects");
    compilerDelegate.setupSourceFileObjects(trees, modelLoader);
    timer.endTask();
    // resolve module dependencies
    timer.startTask("verifyModuleDependencyTree");
    compilerDelegate.resolveModuleDependencies(phasedUnits);
    timer.endTask();
    // now load package descriptors
    timer.startTask("loadPackageDescriptors");
    compilerDelegate.loadPackageDescriptors(modelLoader);
    timer.endTask();
    // at this point, abort if we had any errors logged due to module descriptors
    timer.startTask("collectTreeErrors");
    collectTreeErrors(false, false);
    timer.endTask();
    // check if we abort on errors or not
    if (options.get(OptionName.CEYLONCONTINUE) == null) {
        // they can't be re-logged and duplicated later on
        if (log.nerrors - numParserErrors > 0)
            throw new Abort();
    }
}
Also used : Abort(com.sun.tools.javac.util.Abort)

Example 3 with Abort

use of com.sun.tools.javac.util.Abort in project ceylon-compiler by ceylon.

the class LanguageCompiler method addResources.

private void addResources() throws Abort {
    HashSet<String> written = new HashSet<String>();
    try {
        for (JavaFileObject fo : resourceFileObjects) {
            CeyloncFileManager dfm = (CeyloncFileManager) fileManager;
            String jarFileName = JarUtils.toPlatformIndependentPath(dfm.getLocation(CeylonLocation.RESOURCE_PATH), fo.getName());
            if (!written.contains(jarFileName)) {
                dfm.setModule(modelLoader.findModuleForFile(new File(jarFileName)));
                FileObject outFile = dfm.getFileForOutput(StandardLocation.CLASS_OUTPUT, "", jarFileName, null);
                OutputStream out = outFile.openOutputStream();
                try {
                    InputStream in = new FileInputStream(new File(fo.getName()));
                    try {
                        JarUtils.copy(in, out);
                    } finally {
                        in.close();
                    }
                } finally {
                    out.close();
                }
                written.add(jarFileName);
            }
        }
    } catch (IOException ex) {
        throw new Abort(ex);
    }
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Abort(com.sun.tools.javac.util.Abort) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileObject(javax.tools.FileObject) JavaFileObject(javax.tools.JavaFileObject) CeylonFileObject(com.redhat.ceylon.compiler.java.codegen.CeylonFileObject) IOException(java.io.IOException) VirtualFile(com.redhat.ceylon.compiler.typechecker.io.VirtualFile) File(java.io.File) FileInputStream(java.io.FileInputStream) HashSet(java.util.HashSet)

Aggregations

Abort (com.sun.tools.javac.util.Abort)3 File (java.io.File)2 JavaFileObject (javax.tools.JavaFileObject)2 CeylonFileObject (com.redhat.ceylon.compiler.java.codegen.CeylonFileObject)1 VirtualFile (com.redhat.ceylon.compiler.typechecker.io.VirtualFile)1 JCCompilationUnit (com.sun.tools.javac.tree.JCTree.JCCompilationUnit)1 List (com.sun.tools.javac.util.List)1 ListBuffer (com.sun.tools.javac.util.ListBuffer)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 HashSet (java.util.HashSet)1 FileObject (javax.tools.FileObject)1 StandardJavaFileManager (javax.tools.StandardJavaFileManager)1