当前位置: 首页>>代码示例>>Java>>正文


Java Filer.createResource方法代码示例

本文整理汇总了Java中javax.annotation.processing.Filer.createResource方法的典型用法代码示例。如果您正苦于以下问题:Java Filer.createResource方法的具体用法?Java Filer.createResource怎么用?Java Filer.createResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.annotation.processing.Filer的用法示例。


在下文中一共展示了Filer.createResource方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeServices

import javax.annotation.processing.Filer; //导入方法依赖的package包/类
private void writeServices() {
    for (Map.Entry<Filer,Map<String,SortedSet<ServiceLoaderLine>>> outputFiles : outputFilesByProcessor.entrySet()) {
        Filer filer = outputFiles.getKey();
        for (Map.Entry<String,SortedSet<ServiceLoaderLine>> entry : outputFiles.getValue().entrySet()) {
            try {
                FileObject out = filer.createResource(StandardLocation.CLASS_OUTPUT, "", entry.getKey(),
                        originatingElementsByProcessor.get(filer).get(entry.getKey()).toArray(new Element[0]));
                OutputStream os = out.openOutputStream();
                try {
                    PrintWriter w = new PrintWriter(new OutputStreamWriter(os, "UTF-8"));
                    for (ServiceLoaderLine line : entry.getValue()) {
                        line.write(w);
                    }
                    w.flush();
                    w.close();
                } finally {
                    os.close();
                }
            } catch (IOException x) {
                processingEnv.getMessager().printMessage(Kind.ERROR, "Failed to write to " + entry.getKey() + ": " + x.toString());
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:AbstractServiceProviderProcessor.java

示例2: doWithOriAndPrintWriter

import javax.annotation.processing.Filer; //导入方法依赖的package包/类
public static void doWithOriAndPrintWriter(Filer filer, JavaFileManager.Location location, String relativePath, String filename, BiConsumer<String, PrintWriter> consumer){
    try {
        FileObject resource = filer.getResource(location, relativePath, filename);
        String data;
        try{
            CharSequence cs = resource.getCharContent(false);
            data = cs.toString();
            resource.delete();
        }catch (FileNotFoundException ignored){
            data = "";
        }
        resource = filer.createResource(location, relativePath, filename);

        try(OutputStream outputStream = resource.openOutputStream()){
            consumer.accept(data,new PrintWriter(outputStream));
        }
    } catch (IOException e) {
        note("do with resource file failed"+relativePath+filename+" Exception: " + e.toString());
    }
}
 
开发者ID:zoeminghong,项目名称:pndaox,代码行数:21,代码来源:ResourceHelper.java

示例3: writeServiceNames

import javax.annotation.processing.Filer; //导入方法依赖的package包/类
default void writeServiceNames(Class<?> serviceClass, Filer filer, List<String> generatedClassNames) throws IOException {
    String resourceFile = "META-INF/services/" + serviceClass.getName();
    FileObject existingFile = filer.getResource(StandardLocation.CLASS_OUTPUT, "", resourceFile);
    List<String> lines = new ArrayList<>();
    try (Reader reader = existingFile.openReader(false)) {
        try (BufferedReader bufferedReader = new BufferedReader(reader)) {
            lines.addAll(bufferedReader.lines().collect(Collectors.toList()));
        }
    } catch (IOException e) {
        // Just ignore because reading from a non-existing file and there is no way to detect its existence
        // than open the input stream/reader.
    }

    lines.addAll(generatedClassNames);

    FileObject newFile = filer.createResource(StandardLocation.CLASS_OUTPUT, "", resourceFile);
    try (Writer writer = newFile.openWriter()) {
        try (BufferedWriter bufferedWriter = new BufferedWriter(writer)) {
            for (String line : lines) {
                bufferedWriter.write(line);
                bufferedWriter.newLine();
            }
        }
    }
}
 
开发者ID:egopulse,项目名称:java-code-gen,代码行数:26,代码来源:Generator.java

示例4: init

import javax.annotation.processing.Filer; //导入方法依赖的package包/类
@Override
public synchronized void init(ProcessingEnvironment processingEnv)
{
    //Creating necesary objects for annotations procesing.
    super.init(processingEnv);
    Messager messager = processingEnv.getMessager();
    try
    {
        Filer filer = processingEnv.getFiler();
        //Creating output file
        FileObject fobj = filer.createResource(StandardLocation.CLASS_OUTPUT, "", CONTROLS_RESOURCE_FILE);
        writer = fobj.openWriter();
    }
    catch (IOException e)
    {
        messager.printMessage(Diagnostic.Kind.ERROR, e.getMessage());
        LOG.severe(e.getMessage());
    }
}
 
开发者ID:touwolf,项目名称:bridje-framework,代码行数:20,代码来源:ControlProcessor.java

示例5: init

import javax.annotation.processing.Filer; //导入方法依赖的package包/类
@Override
public synchronized void init(ProcessingEnvironment processingEnv)
{
    //Creating necessary objects for annotations processing.
    super.init(processingEnv);
    Messager messager = processingEnv.getMessager();
    try
    {
        Filer filer = processingEnv.getFiler();
        //Creating output file
        FileObject fobj = filer.createResource(StandardLocation.CLASS_OUTPUT, "", getFileName());
        writer = fobj.openWriter();
    }
    catch (IOException e)
    {
        messager.printMessage(Diagnostic.Kind.ERROR, e.getMessage());
        LOG.severe(e.getMessage());
    }
}
 
开发者ID:touwolf,项目名称:bridje-framework,代码行数:20,代码来源:ClassListPropertyFile.java

示例6: writeResource

import javax.annotation.processing.Filer; //导入方法依赖的package包/类
/**
 * Write <query>.sql to resources folder
 *
 * @param queryDesc information on query
 */
private void writeResource(QueryDesc queryDesc) {
    Filer filer = processingEnv.getFiler();
    try {
        FileObject o = filer.createResource(StandardLocation.CLASS_OUTPUT,
                queryDesc.getPackageName() + ".sql", queryDesc.getMethodNameFirstUpper() + ".sql");
        Writer w = o.openWriter();
        w.append(queryDesc.getQuery());
        w.flush();
        w.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:nds842,项目名称:sql-first-mapper,代码行数:19,代码来源:DaoWriter.java

示例7: findRootProjectHolder

import javax.annotation.processing.Filer; //导入方法依赖的package包/类
/**
 * We use a dirty trick to find the AndroidManifest.xml file, since it's not
 * available in the classpath. The idea is quite simple : create a fake
 * class file, retrieve its URI, and start going up in parent folders to
 * find the AndroidManifest.xml file. Any better solution will be
 * appreciated.
 */
public Option<FileHolder> findRootProjectHolder() {
	Filer filer = processingEnv.getFiler();

	FileObject dummySourceFile;
	try {
		dummySourceFile = filer.createResource(StandardLocation.SOURCE_OUTPUT, "com", "dummy" + System.currentTimeMillis());
	} catch (IOException ignored) {
		return Option.absent();
	}
	String dummySourceFilePath = dummySourceFile.toUri().toString();

	if (dummySourceFilePath.startsWith("file:")) {
		if (!dummySourceFilePath.startsWith("file://")) {
			dummySourceFilePath = "file://" + dummySourceFilePath.substring("file:".length());
		}
	} else {
		dummySourceFilePath = "file://" + dummySourceFilePath;
	}

	URI cleanURI;
	try {
		cleanURI = new URI(dummySourceFilePath);
	} catch (URISyntaxException e) {
		return Option.absent();
	}
	try {
		File dummyFile = new File(cleanURI);
		File sourcesGenerationFolder = dummyFile.getParentFile();
		File projectRoot = sourcesGenerationFolder.getParentFile();

		return Option.of(new FileHolder(dummySourceFilePath, sourcesGenerationFolder, projectRoot));
	}catch(IllegalArgumentException ex){
		return Option.absent();
	}
}
 
开发者ID:davityle,项目名称:ngAndroid,代码行数:43,代码来源:FileHelper.java

示例8: process

import javax.annotation.processing.Filer; //导入方法依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment env) {
    Filer filer = processingEnv.getFiler();

    for (TypeElement typeElement : annotations) {
        for (Element element : env.getElementsAnnotatedWith(typeElement)) {
            Resourcecify resourcecify = element.getAnnotation(Resourcecify.class);
            if (resourcecify == null) {
                continue;
            }

            if (element instanceof Symbol.ClassSymbol) {
                Symbol.ClassSymbol s = (Symbol.ClassSymbol) element;
                try {
                    String packageName = getPackageName(s);

                    JavaFileObject source = s.sourcefile;
                    File sourceFile = new File(source.getName()).getAbsoluteFile();
                    String sourceFileName = sourceFile.getName();

                    FileObject target = filer.createResource(StandardLocation.CLASS_OUTPUT, packageName, sourceFileName, s);
                    IOUtils.copy(source, target);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }


        }
    }
    return false;
}
 
开发者ID:sundrio,项目名称:sundrio,代码行数:33,代码来源:ResourcecifyProcessor.java

示例9: createLogFile

import javax.annotation.processing.Filer; //导入方法依赖的package包/类
private static FileObject createLogFile(ProcessingEnvironment pe) throws IOException {
    final Filer filer = pe.getFiler();

    return filer.createResource(StandardLocation.SOURCE_OUTPUT, "", "aidl2.log");
}
 
开发者ID:chdir,项目名称:aidl2,代码行数:6,代码来源:Logger.java

示例10: createResource

import javax.annotation.processing.Filer; //导入方法依赖的package包/类
private FileObject createResource(final Filer filer, final String path) throws Exception {
    return filer.createResource(CLASS_OUTPUT, StringUtils.EMPTY, path);
}
 
开发者ID:vbauer,项目名称:jackdaw,代码行数:4,代码来源:JServiceCodeGenerator.java


注:本文中的javax.annotation.processing.Filer.createResource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。