Java 类javax.annotation.processing.ProcessingEnvironment 实例源码

项目:data-mediator    文件:ElementHandle.java   
@Override 
protected ExecutableElement doGet(ProcessingEnvironment env) { 
  TypeElement typeElt = env.getElementUtils().getTypeElement(fqn.getName()); 
  if (typeElt != null) { 
    next: 
    for (ExecutableElement executableElement : ElementFilter.methodsIn(typeElt.getEnclosedElements())) {
      if (executableElement.getSimpleName().toString().equals(name)) { 
        List<? extends TypeMirror> parameterTypes = ((ExecutableType)executableElement.asType()).getParameterTypes(); 
        int len = parameterTypes.size(); 
        if (len == this.parameterTypes.size()) { 
          for (int i = 0;i < len;i++) { 
            if (!parameterTypes.get(i).toString().equals(this.parameterTypes.get(i))) { 
              continue next; 
            } 
          } 
          return executableElement; 
        } 
      } 
    } 
  } 
  return null; 
}
项目:NullAway    文件:DataFlow.java   
/**
 * Run the {@code transfer} dataflow analysis over the method, lambda or initializer which is the
 * leaf of the {@code path}.
 *
 * <p>For caching, we make the following assumptions: - if two paths to methods are {@code equal},
 * their control flow graph is the same. - if two transfer functions are {@code equal}, and are
 * run over the same control flow graph, the analysis result is the same. - for all contexts, the
 * analysis result is the same.
 */
private <A extends AbstractValue<A>, S extends Store<S>, T extends TransferFunction<A, S>>
    Result<A, S, T> dataflow(TreePath path, Context context, T transfer) {
  final ProcessingEnvironment env = JavacProcessingEnvironment.instance(context);
  final ControlFlowGraph cfg = cfgCache.getUnchecked(CfgParams.create(path, env));
  final AnalysisParams aparams = AnalysisParams.create(transfer, cfg, env);
  @SuppressWarnings("unchecked")
  final Analysis<A, S, T> analysis = (Analysis<A, S, T>) analysisCache.getUnchecked(aparams);

  return new Result<A, S, T>() {
    @Override
    public Analysis<A, S, T> getAnalysis() {
      return analysis;
    }

    @Override
    public ControlFlowGraph getControlFlowGraph() {
      return cfg;
    }
  };
}
项目:GitHub    文件:RequestManagerGenerator.java   
RequestManagerGenerator(ProcessingEnvironment processingEnv, ProcessorUtil processorUtil) {
  this.processingEnv = processingEnv;
  this.processorUtil = processorUtil;

  Elements elementUtils = processingEnv.getElementUtils();

  requestManagerType = elementUtils.getTypeElement(REQUEST_MANAGER_QUALIFIED_NAME);
  requestManagerClassName = ClassName.get(requestManagerType);

  lifecycleType = elementUtils.getTypeElement(LIFECYCLE_QUALIFIED_NAME);
  requestManagerTreeNodeType =
      elementUtils.getTypeElement(REQUEST_MANAGER_TREE_NODE_QUALIFIED_NAME);

  requestBuilderType =
      elementUtils.getTypeElement(RequestBuilderGenerator.REQUEST_BUILDER_QUALIFIED_NAME);

  glideType = elementUtils.getTypeElement(GLIDE_QUALIFIED_NAME);
}
项目:immu    文件:ImmuCompilerTest.java   
@Test
public void write_withIOException() throws Exception {
  final ProcessingEnvironment env = mock(ProcessingEnvironment.class);
  final Messager messager = mock(Messager.class);
  final Filer filer = mock(Filer.class);

  when(env.getMessager()).thenReturn(messager);
  when(env.getFiler()).thenReturn(filer);

  compiler.init(env);

  final JavaFile javaFile = mock(JavaFile.class);
  doThrow(IOException.class).when(javaFile).writeTo(any(Filer.class));

  compiler.writeSource(javaFile);

  verify(messager, times(1)).printMessage(eq(Diagnostic.Kind.ERROR), any());
}
项目:butterknife-parent    文件:ButterKnifeProcessor.java   
@Override public synchronized void init(ProcessingEnvironment env) {
  super.init(env);

  String sdk = env.getOptions().get(OPTION_SDK_INT);
  if (sdk != null) {
    try {
      this.sdk = Integer.parseInt(sdk);
    } catch (NumberFormatException e) {
      env.getMessager()
          .printMessage(Kind.WARNING, "Unable to parse supplied minSdk option '"
              + sdk
              + "'. Falling back to API 1 support.");
    }
  }

  elementUtils = env.getElementUtils();
  typeUtils = env.getTypeUtils();
  filer = env.getFiler();
  try {
    trees = Trees.instance(processingEnv);
  } catch (IllegalArgumentException ignored) {
  }
}
项目:immu    文件:ImmuObjectElement.java   
@Override
public List<ImmuPredicate.Result> validate(ProcessingEnvironment environment) {
  final List<ImmuPredicate.Result> results = new ArrayList<>();

  results.addAll(runPredicates(environment, this, PREDICATES));

  superProperties(environment)
      .stream()
      .map((p) -> p.validate(environment))
      .forEach(results::addAll);

  properties()
      .stream()
      .map((p) -> p.validate(environment))
      .forEach(results::addAll);

  return results;
}
项目:OpenJSharp    文件:TypeModeler.java   
public static TypeMirror getHolderValueType(TypeMirror type, TypeElement defHolder, ProcessingEnvironment env) {
    TypeElement typeElement = getDeclaration(type);
    if (typeElement == null)
        return null;

    if (isSubElement(typeElement, defHolder)) {
        if (type.getKind().equals(TypeKind.DECLARED)) {
            Collection<? extends TypeMirror> argTypes = ((DeclaredType) type).getTypeArguments();
            if (argTypes.size() == 1) {
                return argTypes.iterator().next();
            } else if (argTypes.isEmpty()) {
                VariableElement member = getValueMember(typeElement);
                if (member != null) {
                    return member.asType();
                }
            }
        }
    }
    return null;
}
项目:annotation-processor-toolkit    文件:AnnotationProcessorWrapper.java   
@Override
public void init(ProcessingEnvironment processingEnv) {

    // get messager
    messager = processingEnv.getMessager();

    wrappedProcessor.init(processingEnv);
}
项目:easy-plugins    文件:UserMarkerAnnotation.java   
/**
 * This constructor is used by the user's generated specialized processor.
 * The info that would normally be given by the use of {@link Service} is provided in
 * {@link MarkerAnnotation}.
 * @param userAnnotationClass The annotation that will annotate user created services.
 * @param info Configuration information.
 * @param procEnv The current processing environment.
 */
UserMarkerAnnotation(TypeElement userAnnotationClass, MarkerAnnotation info, ProcessingEnvironment procEnv) {
    markingAnnotation = userAnnotationClass;
    serviceParentType = procEnv.getElementUtils().getTypeElement(info.getSiName());
    if (serviceParentType == null) {
        throw new IllegalStateException("User service interface class not found! " + info.getSiName());
    }
    serviceBaseName = info.getServiceName();
    individualNameKey = info.getServiceNameFromAnnotation();
    outputPackage = info.getOutputPackage();
}
项目:shoebill    文件:ShoebillProcessor.java   
@Override
public synchronized void init(ProcessingEnvironment processingEnvironment) {
    super.init(processingEnvironment);

    elementUtils = processingEnvironment.getElementUtils();
    typeUtils = processingEnvironment.getTypeUtils();
    messager = processingEnvironment.getMessager();
    filer = processingEnvironment.getFiler();
}
项目:EM    文件:FragmentAnnotationProcessor.java   
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);

    this.messager = processingEnv.getMessager();
    this.filer = processingEnv.getFiler();
}
项目:domino    文件:BaseProcessor.java   
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    this.typeUtils=processingEnv.getTypeUtils();
    this.elementUtils=processingEnv.getElementUtils();
    this.filer=processingEnv.getFiler();
    this.messager=processingEnv.getMessager();
    this.elementFactory=new ElementFactory(elementUtils, typeUtils);
}
项目:JavaGraph    文件:JavaGraphProcessor.java   
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    graph = new ClassGraph();
    types = processingEnv.getTypeUtils();
    messager = processingEnv.getMessager();
    try {
        graphFile = processingEnv.getFiler().createResource(CLASS_OUTPUT, FOLDER, TYPEGRAPH_FILE);
    } catch (IOException e) {
        error("TypeGraph could not be created: %s", e.getMessage());
    }
    graphFile.delete();
}
项目:GitHub    文件:RequestOptionsGenerator.java   
RequestOptionsGenerator(
    ProcessingEnvironment processingEnvironment, ProcessorUtil processorUtil) {
  this.processingEnvironment = processingEnvironment;
  this.processorUtil = processorUtil;

  requestOptionsName = ClassName.get(REQUEST_OPTIONS_PACKAGE_NAME,
      REQUEST_OPTIONS_SIMPLE_NAME);

  requestOptionsType = processingEnvironment.getElementUtils().getTypeElement(
      REQUEST_OPTIONS_QUALIFIED_NAME);
}
项目:openjdk-jdk10    文件:APHotSpotSignature.java   
public TypeMirror getReturnType(ProcessingEnvironment env) {
    if (returnTypeCache == null) {
        if (returnType == null) {
            throw new RuntimeException("Invalid return type.");
        }
        returnTypeCache = lookupType(env, returnType);
    }
    return returnTypeCache;
}
项目:RNLearn_Project1    文件:ReactPropertyProcessor.java   
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
  super.init(processingEnv);

  mFiler = processingEnv.getFiler();
  mMessager = processingEnv.getMessager();
  mElements = processingEnv.getElementUtils();
  mTypes = processingEnv.getTypeUtils();
}
项目:openjdk-jdk10    文件:GeneratedPlugin.java   
public void generate(ProcessingEnvironment env, PrintWriter out) {
    out.printf("    //        class: %s\n", intrinsicMethod.getEnclosingElement());
    out.printf("    //       method: %s\n", intrinsicMethod);
    out.printf("    // generated-by: %s\n", getClass().getName());
    out.printf("    private static final class %s extends GeneratedInvocationPlugin {\n", pluginName);
    out.printf("\n");
    out.printf("        @Override\n");
    out.printf("        public boolean execute(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver, ValueNode[] args) {\n");
    InjectedDependencies deps = createExecute(env, out);
    out.printf("        }\n");

    createPrivateMembers(out, deps);

    out.printf("    }\n");
}
项目:RapidRouter    文件:BaseAbstractProcessor.java   
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    GlobalEnvironment.init(processingEnv);
    elementUtils = processingEnv.getElementUtils();
    typeUtils = processingEnv.getTypeUtils();
    filer = processingEnv.getFiler();
}
项目:GitHub    文件:ProcessorUtil.java   
ProcessorUtil(ProcessingEnvironment processingEnv) {
  this.processingEnv = processingEnv;

  appGlideModuleType =
      processingEnv.getElementUtils().getTypeElement(APP_GLIDE_MODULE_QUALIFIED_NAME);
  libraryGlideModuleType =
      processingEnv.getElementUtils().getTypeElement(LIBRARY_GLIDE_MODULE_QUALIFIED_NAME);
}
项目:Java-9-Programming-By-Example    文件:Aptools.java   
@Transition(from = "MethodTool", end = true)
public String getJavadoc() {
  ProcessingEnvironment processingEnv = Environment.get();
  String javaDoc = processingEnv.getElementUtils().getDocComment(methodElement);
  if (javaDoc == null) {
    javaDoc = "";
  }
  return javaDoc;
}
项目:GitHub    文件:RequestManagerFactoryGenerator.java   
RequestManagerFactoryGenerator(ProcessingEnvironment processingEnv) {
  Elements elementUtils = processingEnv.getElementUtils();
  glideType = elementUtils.getTypeElement(GLIDE_QUALIFIED_NAME);
  lifecycleType = elementUtils.getTypeElement(LIFECYCLE_QUALIFIED_NAME);
  requestManagerTreeNodeType =
      elementUtils.getTypeElement(REQUEST_MANAGER_TREE_NODE_QUALIFIED_NAME);

  requestManagerFactoryInterface =
      elementUtils.getTypeElement(REQUEST_MANAGER_FACTORY_QUALIFIED_NAME);

  TypeElement requestManagerType = elementUtils.getTypeElement(REQUEST_MANAGER_QUALIFIED_NAME);
  requestManagerClassName = ClassName.get(requestManagerType);

}
项目:data-mediator    文件:ElementHandle.java   
@Override 
protected VariableElement doGet(ProcessingEnvironment env) { 
  TypeElement typeElt = env.getElementUtils().getTypeElement(fqn.getName()); 
  if (typeElt != null) { 
    for (VariableElement variableElt : ElementFilter.fieldsIn(typeElt.getEnclosedElements())) { 
      if (variableElt.getSimpleName().contentEquals(name)) { 
        return variableElt; 
      } 
    } 
  } 
  return null; 
}
项目:GitHub    文件:AppModuleProcessor.java   
AppModuleProcessor(ProcessingEnvironment processingEnv, ProcessorUtil processorUtil) {
  this.processingEnv = processingEnv;
  this.processorUtil = processorUtil;

  appModuleGenerator = new AppModuleGenerator(processorUtil);
  requestOptionsGenerator = new RequestOptionsGenerator(processingEnv, processorUtil);
  requestManagerGenerator = new RequestManagerGenerator(processingEnv, processorUtil);
  requestManagerFactoryGenerator = new RequestManagerFactoryGenerator(processingEnv);
  glideGenerator = new GlideGenerator(processingEnv, processorUtil);
  requestBuilderGenerator = new RequestBuilderGenerator(processingEnv, processorUtil);
}
项目:allure-java    文件:DescriptionsProcessor.java   
@Override
@SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel")
public synchronized void init(final ProcessingEnvironment env) {
    super.init(env);
    filer = env.getFiler();
    elementUtils = env.getElementUtils();
    messager = env.getMessager();
}
项目:PreferenceRoom    文件:PreferenceRoomProcessor.java   
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    annotatedEntityMap = new HashMap<>();
    annotatedEntityNameMap = new HashMap<>();
    annotatedComponentList = new ArrayList<>();
    messager = processingEnv.getMessager();
}
项目:easy-plugins    文件:CompletePluginGenerator.java   
public static void buildServiceFiles(Element annotationElement,
                                     RoundEnvironment roundEnv,
                                     ProcessingEnvironment procEnv,
                                     ProcessorOutputCollection output) {
    buildFiles(
            PluginAnnotation.createUserMarker(annotationElement, procEnv),
            procEnv,
            roundEnv,
            output,
            false);


}
项目:openjdk-jdk10    文件:GeneratedNodeIntrinsicPlugin.java   
@Override
protected InjectedDependencies createExecute(ProcessingEnvironment env, PrintWriter out) {
    InjectedDependencies deps = new InjectedDependencies();

    List<? extends VariableElement> params = getParameters();

    int idx = 0;
    for (; idx < params.size(); idx++) {
        VariableElement param = params.get(idx);
        if (param.getAnnotation(InjectedNodeParameter.class) == null) {
            break;
        }

        out.printf("            %s arg%d = %s;\n", param.asType(), idx, deps.use(env, (DeclaredType) param.asType()));
    }

    for (int i = 0; i < signature.length; i++, idx++) {
        if (intrinsicMethod.getParameters().get(i).getAnnotation(ConstantNodeParameter.class) != null) {
            constantArgument(env, out, deps, idx, signature[i], i);
        } else {
            if (signature[i].equals(valueNodeType(env))) {
                out.printf("            ValueNode arg%d = args[%d];\n", idx, i);
            } else {
                out.printf("            %s arg%d = (%s) args[%d];\n", signature[i], idx, signature[i], i);
            }
        }
    }

    factoryCall(env, out, deps, idx);

    return deps;
}
项目:NullAway    文件:DataFlow.java   
@Override
public Analysis<?, ?, ?> load(AnalysisParams key) {
  final ProcessingEnvironment env = key.environment();
  final ControlFlowGraph cfg = key.cfg();
  final TransferFunction<?, ?> transfer = key.transferFunction();

  @SuppressWarnings({"unchecked", "rawtypes"})
  final Analysis<?, ?, ?> analysis = new Analysis(env, transfer);
  analysis.performAnalysis(cfg);
  return analysis;
}
项目:OpenJSharp    文件:TypeMonikerFactory.java   
public TypeMirror create(ProcessingEnvironment apEnv) {
    TypeElement typeDecl = apEnv.getElementUtils().getTypeElement(typeDeclName);
    TypeMirror[] tmpArgs = new TypeMirror[typeArgs.size()];
    int idx = 0;
    for (TypeMoniker moniker : typeArgs)
        tmpArgs[idx++] = moniker.create(apEnv);

    return apEnv.getTypeUtils().getDeclaredType(typeDecl, tmpArgs);
}
项目:GitHub    文件:Processor.java   
public static List<Processor> allProcessors(ProcessingEnvironment processingEnvironment) {
    List<Processor> list = new ArrayList<>();
    list.add(new JsonObjectProcessor(processingEnvironment));
    list.add(new OnJsonParseCompleteProcessor(processingEnvironment));
    list.add(new OnPreSerializeProcessor(processingEnvironment));
    list.add(new JsonFieldProcessor(processingEnvironment));
    return list;
}
项目:GitHub    文件:JsonAnnotationProcessor.java   
@Override
public synchronized void init(ProcessingEnvironment env) {
    super.init(env);

    mElementUtils = env.getElementUtils();
    mTypeUtils = env.getTypeUtils();
    mFiler = env.getFiler();
    mJsonObjectMap = new HashMap<>();
    mProcessors = Processor.allProcessors(processingEnv);
}
项目:easy-plugins    文件:CompletePluginGenerator.java   
private static ProcessorOutputCollection buildFiles(
        UserMarkerAnnotation annotation,
        ProcessingEnvironment procEnv,
        RoundEnvironment roundEnv,
        ProcessorOutputCollection output,
        boolean specialized) {

    for (PluginFileGenerator subGen : generatorList(procEnv, roundEnv, specialized)) {
        subGen.generate(annotation, output);
    }

    return output;
}
项目:GitHub    文件:RealmProxyMediatorGenerator.java   
public RealmProxyMediatorGenerator(ProcessingEnvironment processingEnvironment,
        String className, Set<ClassMetaData> classesToValidate) {
    this.processingEnvironment = processingEnvironment;
    this.className = className;

    for (ClassMetaData metadata : classesToValidate) {
        String simpleName = metadata.getSimpleClassName();
        qualifiedModelClasses.add(metadata.getFullyQualifiedClassName());
        qualifiedProxyClasses.add(REALM_PACKAGE_NAME + "." + getProxyClassName(simpleName));
    }
}
项目:GitHub    文件:RealmProxyClassGenerator.java   
public RealmProxyClassGenerator(ProcessingEnvironment processingEnvironment, TypeMirrors typeMirrors, ClassMetaData metadata) {
    this.processingEnvironment = processingEnvironment;
    this.typeMirrors = typeMirrors;
    this.metadata = metadata;
    this.simpleClassName = metadata.getSimpleClassName();
    this.qualifiedClassName = metadata.getFullyQualifiedClassName();
    this.interfaceName = Utils.getProxyInterfaceName(simpleClassName);
    this.qualifiedGeneratedClassName = String.format(Locale.US, "%s.%s",
            Constants.REALM_PACKAGE_NAME, Utils.getProxyClassName(simpleClassName));

    // See the configuration for the debug build type,
    //  in the realm-library project, for an example of how to set this flag.
    this.suppressWarnings = !"false".equalsIgnoreCase(processingEnvironment.getOptions().get(OPTION_SUPPRESS_WARNINGS));
}
项目:jso-builder    文件:JSOBuilderProcessor.java   
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);

    this.elementUtils = processingEnv.getElementUtils();
    this.messager = processingEnv.getMessager();
}
项目:RIBs    文件:RibProcessor.java   
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
  super.init(processingEnv);
  elementUtils = processingEnv.getElementUtils();
  errorReporter = new ErrorReporter(processingEnv.getMessager());
  typesUtils = processingEnv.getTypeUtils();
  processorPipelines.addAll(getProcessorPipelines(this));
}
项目:openjdk-jdk10    文件:InjectedDependencies.java   
public String use(ProcessingEnvironment env, DeclaredType type) {
    for (WellKnownDependency wellKnown : WellKnownDependency.values()) {
        if (env.getTypeUtils().isAssignable(wellKnown.getType(env), type)) {
            return use(wellKnown);
        }
    }

    String typeName = type.toString();
    Dependency ret = deps.get(typeName);
    if (ret == null) {
        ret = new InjectedDependency("injected" + type.asElement().getSimpleName(), typeName);
        deps.put(typeName, ret);
    }
    return ret.name;
}
项目:retainer    文件:RetainProcessor.java   
@Override
public synchronized void init(ProcessingEnvironment processingEnvironment) {
    super.init(processingEnvironment);

    elementUtils = processingEnvironment.getElementUtils();
    messager = processingEnvironment.getMessager();
    filer = processingEnvironment.getFiler();
}
项目:pl    文件:PluginYamlAnnotationProcessor.java   
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    messager = processingEnv.getMessager();
    this.processingEnv = processingEnv;

    commandType = getTypeByClass("sh.joey.pl.command.JCmd");
    vanillaCommandType = getTypeByClass("org.bukkit.command.CommandExecutor");
    pluginType = getTypeByClass("sh.joey.pl.JPl");
}
项目:r-parser    文件:ExampleProcessor.java   
@Override
public synchronized void init(ProcessingEnvironment env) {
    super.init(env);
    filer = env.getFiler();
    parser = RParser.builder(env)
            .setSupportedAnnotations(SUPPORTED_ANNOTATIONS)
            .setSupportedTypes("layout", "string", "mipmap")
            .build();
}