本文整理汇总了Java中javax.tools.JavaFileObject.Kind.SOURCE属性的典型用法代码示例。如果您正苦于以下问题:Java Kind.SOURCE属性的具体用法?Java Kind.SOURCE怎么用?Java Kind.SOURCE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.tools.JavaFileObject.Kind
的用法示例。
在下文中一共展示了Kind.SOURCE属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compileDependencyClass
@BeforeClass
public static void compileDependencyClass() throws IOException, ClassNotFoundException {
JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
Assume.assumeNotNull(javaCompiler);
classes = temporaryFolder.newFolder("classes");;
StandardJavaFileManager fileManager = javaCompiler.getStandardFileManager(null, Locale.ROOT, UTF_8);
fileManager.setLocation(StandardLocation.CLASS_OUTPUT, ImmutableList.of(classes));
SimpleJavaFileObject compilationUnit = new SimpleJavaFileObject(URI.create("FooTest.java"), Kind.SOURCE) {
String fooTestSource = Resources.toString(Resources.getResource("com/dremio/exec/compile/FooTest.java"), UTF_8);
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
return fooTestSource;
}
};
CompilationTask task = javaCompiler.getTask(null, fileManager, null, Collections.<String>emptyList(), null, ImmutableList.of(compilationUnit));
assertTrue(task.call());
}
示例2: getKind
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;
}
示例3: visitExports
@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);
}
示例4: verifyLambdaScopeCorrect
private static void verifyLambdaScopeCorrect(final String packageClause) throws Exception {
JavacTool tool = JavacTool.create();
JavaFileObject source = new SimpleJavaFileObject(URI.create("mem://Test.java"), Kind.SOURCE) {
@Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
return packageClause + SOURCE_CODE;
}
@Override public boolean isNameCompatible(String simpleName, Kind kind) {
return !"module-info".equals(simpleName);
}
};
Iterable<? extends JavaFileObject> fos = Collections.singletonList(source);
JavacTask task = tool.getTask(null, null, null, new ArrayList<String>(), null, fos);
final Types types = JavacTypes.instance(((JavacTaskImpl) task).getContext());
final Trees trees = Trees.instance(task);
CompilationUnitTree cu = task.parse().iterator().next();
task.analyze();
new TreePathScanner<Void, Void>() {
@Override public Void visitMemberSelect(MemberSelectTree node, Void p) {
if (node.getIdentifier().contentEquals("correct")) {
TypeMirror xType = trees.getTypeMirror(new TreePath(getCurrentPath(), node.getExpression()));
Scope scope = trees.getScope(getCurrentPath());
for (Element l : scope.getLocalElements()) {
if (!l.getSimpleName().contentEquals("x")) continue;
if (!types.isSameType(xType, l.asType())) {
throw new IllegalStateException("Incorrect variable type in scope: " + l.asType() + "; should be: " + xType);
}
}
}
return super.visitMemberSelect(node, p);
}
}.scan(cu, null);
}
示例5: JavaFileObjectImpl
public JavaFileObjectImpl(final String baseName, final CharSequence source){
super(ClassUtils.toURI(baseName + ClassUtils.JAVA_EXTENSION), Kind.SOURCE);
this.source = source;
}
示例6: apply
@Override
public boolean apply(Kind input) {
return input != Kind.SOURCE;
}
示例7: JavaMemoryFileObject
JavaMemoryFileObject(String name, String code) {
super(URI.create("string:///" + name.replace('.','/') + Kind.SOURCE.extension), Kind.SOURCE);
this.code = code;
}
示例8: Source
Source(String name, String content) {
super(name, Kind.SOURCE);
this.content = content;
}
示例9: list
Iterable<JavaFileObject> list(Location location,
PackageSymbol p,
String packageName,
Set<Kind> kinds) throws IOException {
Iterable<JavaFileObject> listed = fileManager.list(location,
packageName,
EnumSet.allOf(Kind.class),
false);
return () -> new Iterator<JavaFileObject>() {
private final Iterator<JavaFileObject> original = listed.iterator();
private JavaFileObject next;
@Override
public boolean hasNext() {
if (next == null) {
while (original.hasNext()) {
JavaFileObject fo = original.next();
if (fo.getKind() != Kind.CLASS &&
fo.getKind() != Kind.SOURCE &&
!isSigFile(currentLoc, fo)) {
p.flags_field |= Flags.HAS_RESOURCE;
}
if (kinds.contains(fo.getKind())) {
next = fo;
break;
}
}
}
return next != null;
}
@Override
public JavaFileObject next() {
if (!hasNext())
throw new NoSuchElementException();
JavaFileObject result = next;
next = null;
return result;
}
};
}
示例10: getFileKind
public Kind getFileKind(TypeElement te) {
JavaFileObject jfo = ((ClassSymbol)te).outermostClass().classfile;
return jfo == null ? Kind.SOURCE : jfo.getKind();
}
示例11: TestFO
public TestFO(URI uri, String content) {
super(uri, Kind.SOURCE);
this.content = content;
}
示例12: JavaSourceFromString
/**
* Constructs a new JavaSourceFromString.
* @param name the name of the compilation unit represented by this file object
* @param code the source code for the compilation unit represented by this file object
*/
JavaSourceFromString(String name, String code) {
super(uriFromString("mfm:///" + name.replace('.','/') + Kind.SOURCE.extension),
Kind.SOURCE);
this.code = code;
}
示例13: MemoryJavaFileObject
public MemoryJavaFileObject(String className, CharSequence sourceCode) {
super(URI.create("string:///" + className.replace('.','/') + Kind.SOURCE.extension), Kind.SOURCE);
this.className = className;
this.sourceCode = sourceCode;
this.byteCode = new ByteArrayOutputStream();
}