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


Java Processor类代码示例

本文整理汇总了Java中javax.annotation.processing.Processor的典型用法代码示例。如果您正苦于以下问题:Java Processor类的具体用法?Java Processor怎么用?Java Processor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: resolveProcessors

import javax.annotation.processing.Processor; //导入依赖的package包/类
public Collection<? extends Processor> resolveProcessors(boolean onScan) {
    ClassPath[] pps = validatePaths();
    ClassLoader cl;
    boolean isModule = false;
    final ClassLoaderRef cache = classLoaderCache;
    if (cache == null || (cl=cache.get(root)) == null) {
        ClassPath pp = pps[1];
        if (pps[0] != null && !pps[0].entries().isEmpty()) {
            pp = pps[0];
            isModule = true;
        }
        if (pp == null) {
            pp = ClassPath.EMPTY;
        }
        cl = CachingArchiveClassLoader.forClassPath(
                pp,
                new BypassOpenIDEUtilClassLoader(Context.class.getClassLoader()),
                usedRoots);
        classLoaderCache = !DISABLE_CLASSLOADER_CACHE ? new ClassLoaderRef(cl, root, isModule) : null;
    } else {
        isModule = cache.isModule;                    
    }
    Collection<Processor> result = lookupProcessors(cl, onScan, isModule);
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:APTUtils.java

示例2: lookupProcessors

import javax.annotation.processing.Processor; //导入依赖的package包/类
private Collection<Processor> lookupProcessors(ClassLoader cl, boolean onScan, boolean isModule) {
    Iterable<? extends String> processorNames = aptOptions.annotationProcessorsToRun();
    if (processorNames == null) {
        processorNames = getProcessorNames(cl, isModule);
    }
    List<Processor> result = new LinkedList<Processor>();
    for (String name : processorNames) {
        try {
            Class<?> clazz = Class.forName(name, true, cl);
            Object instance = clazz.newInstance();
            if (instance instanceof Processor) {
                result.add((Processor) instance);
            }
        } catch (ThreadDeath td) {
            throw td;
        } catch (Throwable t) {
            LOG.log(Level.FINE, null, t);
        }
    }
    if (!onScan)
        result.addAll(HARDCODED_PROCESSORS.lookupAll(Processor.class));
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:APTUtils.java

示例3: initProcessAnnotations

import javax.annotation.processing.Processor; //导入依赖的package包/类
/**
 * Check if we should process annotations.
 * If so, and if no scanner is yet registered, then set up the DocCommentScanner
 * to catch doc comments, and set keepComments so the parser records them in
 * the compilation unit.
 *
 * @param processors user provided annotation processors to bypass
 * discovery, {@code null} means that no processors were provided
 */
public void initProcessAnnotations(Iterable<? extends Processor> processors) {
    // Process annotations if processing is not disabled and there
    // is at least one Processor available.
    if (options.isSet(PROC, "none")) {
        processAnnotations = false;
    } else if (procEnvImpl == null) {
        procEnvImpl = JavacProcessingEnvironment.instance(context);
        procEnvImpl.setProcessors(processors);
        processAnnotations = procEnvImpl.atLeastOneProcessor();

        if (processAnnotations) {
            options.put("save-parameter-names", "save-parameter-names");
            reader.saveParameterNames = true;
            keepComments = true;
            genEndPos = true;
            if (!taskListener.isEmpty())
                taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));
            deferredDiagnosticHandler = new Log.DeferredDiagnosticHandler(log);
        } else { // free resources
            procEnvImpl.close();
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:33,代码来源:JavaCompiler.java

示例4: getAnnotationProcessors

import javax.annotation.processing.Processor; //导入依赖的package包/类
@Override
public List<PluginInfo<Processor>> getAnnotationProcessors() {
    return Arrays.asList(new PluginInfo<Processor>() {
        @Override
        public String getName() {
            return "test";
        }
        @Override
        public Map<String, String> getOptions() {
            return Collections.singletonMap("testAPKey", "testAPValue");
        }
        @Override
        public Processor getPlugin() {
            return new ProcessorImpl();
        }
    });
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:PlatformProviderTest.java

示例5: compile

import javax.annotation.processing.Processor; //导入依赖的package包/类
static private boolean compile(Iterable<? extends Processor> processors)
{
    JavaCompiler compiler = new EclipseCompiler();
    DiagnosticCollector<JavaFileObject> diagnosticCollector =
            new DiagnosticCollector<JavaFileObject>();
    JavaFileManager fileManager = compiler.getStandardFileManager(diagnosticCollector, Locale.getDefault(), UTF_8);
    JavaCompiler.CompilationTask task = compiler.getTask(
            null,
            fileManager,
            diagnosticCollector,
            ImmutableSet.<String>of(),
            ImmutableSet.of(TestTypesEclipse.class.getCanonicalName()),
            ImmutableSet.<JavaFileObject>of());
    task.setProcessors(processors);
    return task.call();
}
 
开发者ID:wrmsr,项目名称:wava,代码行数:17,代码来源:TestTypesEclipse.java

示例6: compile

import javax.annotation.processing.Processor; //导入依赖的package包/类
/** Convenient JavaCompiler facade returning a ClassLoader with all compiled units. */
static ClassLoader compile(
    ClassLoader parent,
    List<String> options,
    List<Processor> processors,
    List<JavaFileObject> units) {
  JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
  Objects.requireNonNull(compiler, "no system java compiler available - JDK is required!");
  DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
  StandardJavaFileManager sjfm =
      compiler.getStandardFileManager(diagnostics, Locale.getDefault(), StandardCharsets.UTF_8);
  Manager manager = new Manager(sjfm, parent);
  CompilationTask task = compiler.getTask(null, manager, diagnostics, options, null, units);
  if (!processors.isEmpty()) {
    task.setProcessors(processors);
  }
  boolean success = task.call();
  if (!success) {
    throw new RuntimeException("compilation failed! " + diagnostics.getDiagnostics());
  }
  return manager.getClassLoader(StandardLocation.CLASS_PATH);
}
 
开发者ID:sormuras,项目名称:listing,代码行数:23,代码来源:Compilation.java

示例7: createGeneratedClass

import javax.annotation.processing.Processor; //导入依赖的package包/类
/**
 * Assumes the element is valid. It uses the value specified in the annotation, if it has a package. Otherwise uses
 * the element's package.
 * @param element annotated interface, assumed valid
 * @param types   type utility, currently ignored
 * @return a representation of the generated class.
 */
@Override
protected GeneratedType createGeneratedClass(EnrichedTypeElement element, Class<? extends Processor> processorClass,
                                             Types types) {

    final String specifiedClass = element.getAnnotation(getSupportedAnnotation()).value();
    final Pair<String, String> packageAndClassName = extractPackageAndClassName(specifiedClass);
    String packageName = packageAndClassName.getLeft();
    if (packageName == null) {
        final PackageElement elementPackage = element.getPackage();
        packageName = elementPackage.getQualifiedName().toString();
    }
    String className = packageAndClassName.getRight();
    if (className == null) {
        className = element.calculateClassNameWithPrefix(getClassPrefix());
    }
    return new NoopClass(packageName, className, element, processorClass, types);
}
 
开发者ID:pijpijpij,项目名称:Noopetal,代码行数:25,代码来源:NoopProcessingStep.java

示例8: createGeneratedClass

import javax.annotation.processing.Processor; //导入依赖的package包/类
/**
 * Assumes the element is valid. It uses the value specified in the annotation, if it has a package. Otherwise uses
 * the element's package.
 * @param element annotated interface, assumed valid
 * @return a representation of the generated class.
 */
@Override
protected GeneratedType createGeneratedClass(EnrichedTypeElement element, Class<? extends Processor> processorClass,
                                             Types types) {

    final String specifiedClass = element.getAnnotation(getSupportedAnnotation()).value();
    final Pair<String, String> packageAndClassName = extractPackageAndClassName(specifiedClass);
    String packageName = packageAndClassName.getLeft();
    if (packageName == null) {
        final PackageElement elementPackage = element.getPackage();
        packageName = elementPackage.getQualifiedName().toString();
    }
    String className = packageAndClassName.getRight();
    if (className == null) {
        className = element.calculateClassNameWithPrefix(getClassPrefix());
    }
    return new DecorClass(packageName,
                          className,
                          element,
                          processorClass,
                          types,
                          element.getAnnotation(getSupportedAnnotation()).mutable());
}
 
开发者ID:pijpijpij,项目名称:Noopetal,代码行数:29,代码来源:DecorProcessingStep.java

示例9: createGeneratedClass

import javax.annotation.processing.Processor; //导入依赖的package包/类
/**
 * Assumes the element is valid. It uses the value specified in the annotation, if it has a package. Otherwise uses
 * the element's package.
 * @param element annotated interface, assumed valid
 * @param types   type utility, currently ignored
 * @return a representation of the generated class.
 */
@Override
protected GeneratedType createGeneratedClass(EnrichedTypeElement element, Class<? extends Processor> processorClass,
                                             Types types) {

    final String specifiedClass = element.getAnnotation(getSupportedAnnotation()).value();
    final Pair<String, String> packageAndClassName = extractPackageAndClassName(specifiedClass);
    String packageName = packageAndClassName.getLeft();
    if (packageName == null) {
        final PackageElement elementPackage = element.getPackage();
        packageName = elementPackage.getQualifiedName().toString();
    }
    String className = packageAndClassName.getRight();
    if (className == null) {
        className = element.calculateClassNameWithSuffix(getClassSuffix());
    }
    return new FactoryInterface(packageName, className, element, processorClass);
}
 
开发者ID:pijpijpij,项目名称:Noopetal,代码行数:25,代码来源:FactoryProcessingStep.java

示例10: initProcessAnnotations

import javax.annotation.processing.Processor; //导入依赖的package包/类
/**
 * Check if we should process annotations.
 * If so, and if no scanner is yet registered, then set up the DocCommentScanner
 * to catch doc comments, and set keepComments so the parser records them in
 * the compilation unit.
 *
 * @param processors user provided annotation processors to bypass
 * discovery, {@code null} means that no processors were provided
 */
public void initProcessAnnotations(Iterable<? extends Processor> processors) {
    // Process annotations if processing is not disabled and there
    // is at least one Processor available.
    Options options = Options.instance(context);
    if (options.get("-proc:none") != null) {
        processAnnotations = false;
    } else if (procEnvImpl == null) {
        procEnvImpl = new JavacProcessingEnvironment(context, processors);
        processAnnotations = procEnvImpl.atLeastOneProcessor();

        if (processAnnotations) {
            if (context.get(Scanner.Factory.scannerFactoryKey) == null)
                DocCommentScanner.Factory.preRegister(context);
            options.put("save-parameter-names", "save-parameter-names");
            reader.saveParameterNames = true;
            keepComments = true;
            if (taskListener != null)
                taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));


        } else { // free resources
            procEnvImpl.close();
        }
    }
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:35,代码来源:JavaCompiler.java

示例11: compile

import javax.annotation.processing.Processor; //导入依赖的package包/类
static ClassLoader compile(JavaFile java, ClassLoader parent, List<String> options,
    List<Processor> processors) {
  JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
  assert compiler != null : "no system java compiler available - JDK is required!";
  DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
  StandardJavaFileManager sjfm = compiler.getStandardFileManager(
      diagnostics,
      Locale.getDefault(),
      StandardCharsets.UTF_8);
  Manager manager = new Manager(sjfm, parent);
  CompilationTask task = compiler.getTask(
      null, // a writer for additional output from the compiler; use System.err if null
      manager,
      diagnostics,
      options,
      null, // names of classes to be processed by annotation processing, null means no classes
      Collections.singleton(java.toJavaFileObject()));
  if (!processors.isEmpty())
    task.setProcessors(processors);
  boolean success = task.call();
  if (!success)
    throw new RuntimeException("compilation failed" + diagnostics.getDiagnostics());
  return manager.getClassLoader(null);
}
 
开发者ID:sormuras,项目名称:poetry,代码行数:25,代码来源:Poetry.java

示例12: setProcessors

import javax.annotation.processing.Processor; //导入依赖的package包/类
@Override
public void setProcessors(Object[] processors) {
	if (!_isFirstRound) {
		throw new IllegalStateException("setProcessors() cannot be called after processing has begun"); //$NON-NLS-1$
	}
	// Cast all the processors here, rather than failing later.
	// But don't call init() until the processor is actually needed.
	_setProcessors = new ArrayList<Processor>(processors.length);
	for (Object o : processors) {
		Processor p = (Processor)o;
		_setProcessors.add(p);
	}
	_setProcessorIter = _setProcessors.iterator();

	// processors set this way take precedence over anything on the command line 
	_commandLineProcessors = null;
	_commandLineProcessorIter = null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:BatchAnnotationProcessorManager.java

示例13: run

import javax.annotation.processing.Processor; //导入依赖的package包/类
public Result run(
    String[] args,
    JavaFileManager fileManager,
    List<JavaFileObject> javaFileObjects,
    Iterable<? extends Processor> processors) {
  JavaCompiler compiler = new BaseErrorProneJavaCompiler(scannerSupplier);
  try {
    CompilationTask task =
        compiler.getTask(
            errOutput,
            fileManager,
            diagnosticListener,
            ImmutableList.copyOf(args),
            null /*classes*/,
            javaFileObjects);
    if (processors != null) {
      task.setProcessors(processors);
    }
    return task.call() ? Result.OK : Result.ERROR;
  } catch (InvalidCommandLineOptionException e) {
    errOutput.print(e);
    errOutput.flush();
    return Result.CMDERR;
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:26,代码来源:BaseErrorProneCompiler.java

示例14: initProcessAnnotations

import javax.annotation.processing.Processor; //导入依赖的package包/类
/**
 * Check if we should process annotations.
 * If so, and if no scanner is yet registered, then set up the DocCommentScanner
 * to catch doc comments, and set keepComments so the parser records them in
 * the compilation unit.
 *
 * @param processors user provided annotation processors to bypass
 * discovery, {@code null} means that no processors were provided
 */
public void initProcessAnnotations(Iterable<? extends Processor> processors) {
    // Process annotations if processing is not disabled and there
    // is at least one Processor available.
    if (options.isSet(PROC, "none")) {
        processAnnotations = false;
    } else if (procEnvImpl == null) {
        procEnvImpl = new JavacProcessingEnvironment(context, processors);
        processAnnotations = procEnvImpl.atLeastOneProcessor();

        if (processAnnotations) {
            options.put("save-parameter-names", "save-parameter-names");
            reader.saveParameterNames = true;
            keepComments = true;
            genEndPos = true;
            if (taskListener != null)
                taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));
            log.deferDiagnostics = true;
        } else { // free resources
            procEnvImpl.close();
        }
    }
}
 
开发者ID:aducode,项目名称:openjdk-source-code-learn,代码行数:32,代码来源:JavaCompiler.java

示例15: compile

import javax.annotation.processing.Processor; //导入依赖的package包/类
public boolean compile(File... sourceFiles) throws Exception {
  JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
  StandardJavaFileManager fm = compiler.getStandardFileManager(diagnosticListener, null, null);
  if (classOutput == null) {
    classOutput = createTempDir();
  }
  if (sourceOutput == null) {
    sourceOutput = createTempDir();
  }
  fm.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singletonList(classOutput));
  fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singletonList(sourceOutput));
  Iterable<? extends JavaFileObject> fileObjects = fm.getJavaFileObjects(sourceFiles);
  Writer out = new NullWriter();
  JavaCompiler.CompilationTask task = compiler.getTask(out, fm, diagnosticListener, options, null, fileObjects);
  List<Processor> processors = Collections.<Processor>singletonList(processor);
  task.setProcessors(processors);
  try {
    return task.call();
  } catch (RuntimeException e) {
    if (e.getCause() != null && e.getCause() instanceof RuntimeException) {
      throw (RuntimeException)e.getCause();
    } else {
      throw e;
    }
  }
}
 
开发者ID:vert-x3,项目名称:vertx-codegen,代码行数:27,代码来源:Compiler.java


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