Search in sources :

Example 1 with Location

use of javax.tools.JavaFileManager.Location in project ceylon-compiler by ceylon.

the class JavadocTool method parsePackageClasses.

/**
 * search all directories in path for subdirectory name. Add all
 * .java files found in such a directory to args.
 */
private void parsePackageClasses(String name, Iterable<JavaFileObject> files, ListBuffer<JCCompilationUnit> trees, List<String> excludedPackages) throws IOException {
    if (excludedPackages.contains(name)) {
        return;
    }
    boolean hasFiles = false;
    docenv.notice("main.Loading_source_files_for_package", name);
    if (files == null) {
        Location location = docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH) ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH;
        ListBuffer<JavaFileObject> lb = new ListBuffer<JavaFileObject>();
        for (JavaFileObject fo : docenv.fileManager.list(location, name, EnumSet.of(JavaFileObject.Kind.SOURCE), false)) {
            String binaryName = docenv.fileManager.inferBinaryName(location, fo);
            String simpleName = getSimpleName(binaryName);
            if (isValidClassName(simpleName)) {
                lb.append(fo);
            }
        }
        files = lb.toList();
    }
    for (JavaFileObject fo : files) {
        // messager.notice("main.Loading_source_file", fn);
        trees.append(parse(fo));
        hasFiles = true;
    }
    if (!hasFiles) {
        messager.warning(null, "main.no_source_files_for_package", name.replace(File.separatorChar, '.'));
    }
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ListBuffer(com.sun.tools.javac.util.ListBuffer) StandardLocation(javax.tools.StandardLocation) Location(javax.tools.JavaFileManager.Location)

Example 2 with Location

use of javax.tools.JavaFileManager.Location in project ceylon-compiler by ceylon.

the class JavacFiler method createSourceOrClassFile.

private JavaFileObject createSourceOrClassFile(boolean isSourceFile, String name) throws IOException {
    if (lint) {
        int periodIndex = name.lastIndexOf(".");
        if (periodIndex != -1) {
            String base = name.substring(periodIndex);
            String extn = (isSourceFile ? ".java" : ".class");
            if (base.equals(extn))
                log.warning("proc.suspicious.class.name", name, extn);
        }
    }
    checkNameAndExistence(name, isSourceFile);
    Location loc = (isSourceFile ? SOURCE_OUTPUT : CLASS_OUTPUT);
    JavaFileObject.Kind kind = (isSourceFile ? JavaFileObject.Kind.SOURCE : JavaFileObject.Kind.CLASS);
    JavaFileObject fileObject = fileManager.getJavaFileForOutput(loc, name, kind, null);
    checkFileReopening(fileObject, true);
    if (lastRound)
        log.warning("proc.file.create.last.round", name);
    if (isSourceFile)
        aggregateGeneratedSourceNames.add(name);
    else
        aggregateGeneratedClassNames.add(name);
    openTypeNames.add(name);
    return new FilerOutputJavaFileObject(name, fileObject);
}
Also used : Lint(com.sun.tools.javac.code.Lint) Location(javax.tools.JavaFileManager.Location)

Example 3 with Location

use of javax.tools.JavaFileManager.Location in project ceylon-compiler by ceylon.

the class SourceWriter method readSource.

private String readSource(ClassFile cf) {
    if (fileManager == null)
        return null;
    Location location;
    if (fileManager.hasLocation((StandardLocation.SOURCE_PATH)))
        location = StandardLocation.SOURCE_PATH;
    else
        location = StandardLocation.CLASS_PATH;
    // InnerClasses and EnclosingMethod attributes.
    try {
        String className = cf.getName();
        SourceFile_attribute sf = (SourceFile_attribute) cf.attributes.get(Attribute.SourceFile);
        if (sf == null) {
            report(messages.getMessage("err.no.SourceFile.attribute"));
            return null;
        }
        String sourceFile = sf.getSourceFile(cf.constant_pool);
        String fileBase = sourceFile.endsWith(".java") ? sourceFile.substring(0, sourceFile.length() - 5) : sourceFile;
        int sep = className.lastIndexOf("/");
        String pkgName = (sep == -1 ? "" : className.substring(0, sep + 1));
        String topClassName = (pkgName + fileBase).replace('/', '.');
        JavaFileObject fo = fileManager.getJavaFileForInput(location, topClassName, JavaFileObject.Kind.SOURCE);
        if (fo == null) {
            report(messages.getMessage("err.source.file.not.found"));
            return null;
        }
        return fo.getCharContent(true).toString();
    } catch (ConstantPoolException e) {
        report(e);
        return null;
    } catch (IOException e) {
        report(e.getLocalizedMessage());
        return null;
    }
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ConstantPoolException(com.sun.tools.classfile.ConstantPoolException) IOException(java.io.IOException) StandardLocation(javax.tools.StandardLocation) Location(javax.tools.JavaFileManager.Location) SourceFile_attribute(com.sun.tools.classfile.SourceFile_attribute)

Example 4 with Location

use of javax.tools.JavaFileManager.Location in project ceylon by eclipse.

the class T6397104 method test.

void test(boolean hasLocation, File siblingFile, String relName, String expectedPath) throws Exception {
    StandardJavaFileManager fm;
    if (hasLocation) {
        for (Location location : StandardLocation.values()) {
            fm = tool.getStandardFileManager(null, null, null);
            fm.setLocation(location, Arrays.asList(new File(".")));
            test(fm, location, siblingFile, relName, expectedPath);
        }
    } else {
        fm = tool.getStandardFileManager(null, null, null);
        test(fm, CLASS_OUTPUT, siblingFile, relName, expectedPath);
    }
}
Also used : File(java.io.File) Location(javax.tools.JavaFileManager.Location)

Example 5 with Location

use of javax.tools.JavaFileManager.Location in project ceylon-compiler by ceylon.

the class T6397104 method test.

void test(boolean hasLocation, File siblingFile, String relName, String expectedPath) throws Exception {
    StandardJavaFileManager fm;
    if (hasLocation) {
        for (Location location : StandardLocation.values()) {
            fm = tool.getStandardFileManager(null, null, null);
            fm.setLocation(location, Arrays.asList(new File(".")));
            test(fm, location, siblingFile, relName, expectedPath);
        }
    } else {
        fm = tool.getStandardFileManager(null, null, null);
        test(fm, CLASS_OUTPUT, siblingFile, relName, expectedPath);
    }
}
Also used : File(java.io.File) Location(javax.tools.JavaFileManager.Location)

Aggregations

Location (javax.tools.JavaFileManager.Location)7 File (java.io.File)4 StandardLocation (javax.tools.StandardLocation)4 JavaFileObject (javax.tools.JavaFileObject)3 IOException (java.io.IOException)2 StandardJavaFileManager (javax.tools.StandardJavaFileManager)2 ConstantPoolException (com.sun.tools.classfile.ConstantPoolException)1 SourceFile_attribute (com.sun.tools.classfile.SourceFile_attribute)1 JavacTaskImpl (com.sun.tools.javac.api.JavacTaskImpl)1 Attribute (com.sun.tools.javac.code.Attribute)1 Lint (com.sun.tools.javac.code.Lint)1 Symtab (com.sun.tools.javac.code.Symtab)1 ClassReader (com.sun.tools.javac.jvm.ClassReader)1 ClassWriter (com.sun.tools.javac.jvm.ClassWriter)1 Pool (com.sun.tools.javac.jvm.Pool)1 JavacProcessingEnvironment (com.sun.tools.javac.processing.JavacProcessingEnvironment)1 ListBuffer (com.sun.tools.javac.util.ListBuffer)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1