Java Code Examples for javax.tools.JavaFileObject.Kind#CLASS

The following examples show how to use javax.tools.JavaFileObject.Kind#CLASS . 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: DynaFileManager.java    From kan-java with Eclipse Public License 1.0 6 votes vote down vote up
public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException {
    if (Kind.CLASS != kind && Kind.SOURCE != kind)
        throw new IOException("Unsupported output kind: " + kind);
    if (!(location instanceof StandardLocation))
        throw new IOException("Unsupported output location: " + location);
    switch ((StandardLocation) location) {
    case CLASS_OUTPUT:
        return getOrCreateMemFileByClassName(className, this.classes, JavaClassFile.class);
    case SOURCE_OUTPUT:
        return getOrCreateMemFileByClassName(className, this.srcs, JavaSourceFile.class);
    case CLASS_PATH:
    case SOURCE_PATH:
    case ANNOTATION_PROCESSOR_PATH:
    case PLATFORM_CLASS_PATH:
    default:
        throw new IOException("Unsupported output location: " + location);
    }
}
 
Example 2
Source File: BaseFileManager.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public static Kind getKind(String name) {
    if (name.endsWith(Kind.CLASS.extension))
        return Kind.CLASS;
    else if (name.endsWith(Kind.SOURCE.extension))
        return Kind.SOURCE;
    else if (name.endsWith(Kind.HTML.extension))
        return Kind.HTML;
    else
        return Kind.OTHER;
}
 
Example 3
Source File: BaseFileManager.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static Kind getKind(String name) {
    if (name.endsWith(Kind.CLASS.extension))
        return Kind.CLASS;
    else if (name.endsWith(Kind.SOURCE.extension))
        return Kind.SOURCE;
    else if (name.endsWith(Kind.HTML.extension))
        return Kind.HTML;
    else
        return Kind.OTHER;
}
 
Example 4
Source File: BaseFileManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static Kind getKind(String name) {
    if (name.endsWith(Kind.CLASS.extension))
        return Kind.CLASS;
    else if (name.endsWith(Kind.SOURCE.extension))
        return Kind.SOURCE;
    else if (name.endsWith(Kind.HTML.extension))
        return Kind.HTML;
    else
        return Kind.OTHER;
}
 
Example 5
Source File: BaseFileManager.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static Kind getKind(String name) {
    if (name.endsWith(Kind.CLASS.extension))
        return Kind.CLASS;
    else if (name.endsWith(Kind.SOURCE.extension))
        return Kind.SOURCE;
    else if (name.endsWith(Kind.HTML.extension))
        return Kind.HTML;
    else
        return Kind.OTHER;
}
 
Example 6
Source File: InterceptingJavaFileManager.java    From EasyMPermission with MIT License 5 votes vote down vote up
@Override public JavaFileObject getJavaFileForOutput(Location location, String className, final Kind kind, FileObject sibling) throws IOException {
	if (className.startsWith("lombok.dummy.ForceNewRound")) {
		final String name = className.replace(".", "/") + kind.extension;
		return LombokFileObjects.createEmpty(compiler, name, kind);
	}
	JavaFileObject fileObject = fileManager.getJavaFileForOutput(location, className, kind, sibling);
	if (kind != Kind.CLASS) {
		return fileObject;
	}
	return LombokFileObjects.createIntercepting(compiler, fileObject, className, diagnostics);
}
 
Example 7
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitExports(JCExports tree) {
    Iterable<Symbol> packageContent = tree.directive.packge.members().getSymbols();
    List<JavaFileObject> filesToCheck = List.nil();
    boolean packageNotEmpty = false;
    for (Symbol sym : packageContent) {
        if (sym.kind != Kinds.Kind.TYP)
            continue;
        ClassSymbol csym = (ClassSymbol) sym;
        if (sym.completer.isTerminal() ||
            csym.classfile.getKind() == Kind.CLASS) {
            packageNotEmpty = true;
            filesToCheck = List.nil();
            break;
        }
        if (csym.classfile.getKind() == Kind.SOURCE) {
            filesToCheck = filesToCheck.prepend(csym.classfile);
        }
    }
    for (JavaFileObject jfo : filesToCheck) {
        if (findPackageInFile.findPackageNameOf(jfo) == tree.directive.packge.fullname) {
            packageNotEmpty = true;
            break;
        }
    }
    if (!packageNotEmpty) {
        log.error(tree.qualid.pos(), Errors.PackageEmptyOrNotFound(tree.directive.packge));
    }
    msym.directives = msym.directives.prepend(tree.directive);
}
 
Example 8
Source File: DynamicJavaFileManager.java    From oxygen with Apache License 2.0 5 votes vote down vote up
@Override
public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind,
    FileObject sibling) throws IOException {
  if (kind == Kind.CLASS && location == StandardLocation.CLASS_OUTPUT) {
    ByteCode byteCode = byteCodes.get(className);
    if (byteCode == null) {
      byteCode = new ByteCode(className, kind);
      byteCodes.put(className, byteCode);
    }
    return byteCode;
  }
  return super.getJavaFileForOutput(location, className, kind, sibling);
}
 
Example 9
Source File: ToolBox.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a memory file object.
 * @param name binary name of the class to be stored in this file object
 */
MemoryFileObject(Location location, String name, JavaFileObject.Kind kind) {
    super(URI.create("mfm:///" + name.replace('.','/') + kind.extension),
          Kind.CLASS);
    this.location = location;
    this.name = name;
}
 
Example 10
Source File: InMemoryJavaFileManager.java    From toothpick with Apache License 2.0 5 votes vote down vote up
public JavaFileObject getJavaFileForInput(Location location, String className, Kind kind)
    throws IOException {
  if (location == StandardLocation.CLASS_OUTPUT
      && buffers.containsKey(className)
      && kind == Kind.CLASS) {
    final byte[] bytes = buffers.get(className).toByteArray();
    return new SimpleJavaFileObject(URI.create(className), kind) {
      public InputStream openInputStream() {
        return new ByteArrayInputStream(bytes);
      }
    };
  }
  return fileManager.getJavaFileForInput(location, className, kind);
}
 
Example 11
Source File: BaseFileManager.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static Kind getKind(String name) {
    if (name.endsWith(Kind.CLASS.extension))
        return Kind.CLASS;
    else if (name.endsWith(Kind.SOURCE.extension))
        return Kind.SOURCE;
    else if (name.endsWith(Kind.HTML.extension))
        return Kind.HTML;
    else
        return Kind.OTHER;
}
 
Example 12
Source File: ResourceFileJavaFileManager.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void gatherFiles(ResourceFile root, ResourceFile file, List<JavaFileObject> accumulator,
		Set<Kind> kinds, boolean recurse) {
	ResourceFile[] listFiles = file.listFiles();
	for (ResourceFile resourceFile : listFiles) {
		if (resourceFile.isDirectory()) {
			if (recurse) {
				gatherFiles(root, resourceFile, accumulator, kinds, recurse);
			}
		}
		else {
			for (Kind kind : kinds) {
				if (kind == Kind.CLASS) {
					if (resourceFile.getName().endsWith(".class")) {
						accumulator.add(createFileObject(root, resourceFile, kind));
						break;
					}
				}
				else if (kind == Kind.SOURCE) {
					if (resourceFile.getName().endsWith(".java")) {
						accumulator.add(createFileObject(root, resourceFile, kind));
						break;
					}
				}
			}
		}
	}

}
 
Example 13
Source File: MemoryClassLoader.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
Output(String name) {
    super(name, Kind.CLASS);
}
 
Example 14
Source File: MemoryClassLoader.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
Output(String name) {
    super(name, Kind.CLASS);
}
 
Example 15
Source File: MemoryClassLoader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
Output(String name) {
    super(name, Kind.CLASS);
}
 
Example 16
Source File: MemoryFileManager.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a JavaClassInArray object.
 * @param name binary name of the class to be stored in this file object
 */
JavaClassInArray(String name) {
    super(uriFromString("mfm:///" + name.replace('.','/') + Kind.CLASS.extension),
          Kind.CLASS);
    this.name = name;
}
 
Example 17
Source File: MemoryFileManager.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a JavaClassInArray object.
 * @param name binary name of the class to be stored in this file object
 */
JavaClassInArray(String name) {
    super(uriFromString("mfm:///" + name.replace('.','/') + Kind.CLASS.extension),
          Kind.CLASS);
    this.name = name;
}
 
Example 18
Source File: MemoryClassLoader.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
Output(String name) {
    super(name, Kind.CLASS);
}
 
Example 19
Source File: MemoryClassLoader.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
Output(String name) {
    super(name, Kind.CLASS);
}
 
Example 20
Source File: MemoryClassLoader.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
Output(String name) {
    super(name, Kind.CLASS);
}