Java Code Examples for javax.annotation.processing.ProcessingEnvironment

The following are top voted examples for showing how to use javax.annotation.processing.ProcessingEnvironment. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: data-mediator   File: ElementHandle.java   View source code 6 votes vote down vote up
@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; 
}
 
Example 2
Project: NullAway   File: DataFlow.java   View source code 6 votes vote down vote up
/**
 * 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;
    }
  };
}
 
Example 3
Project: GitHub   File: RequestManagerGenerator.java   View source code 6 votes vote down vote up
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);
}
 
Example 4
Project: immu   File: ImmuCompilerTest.java   View source code 6 votes vote down vote up
@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());
}
 
Example 5
Project: butterknife-parent   File: ButterKnifeProcessor.java   View source code 6 votes vote down vote up
@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) {
  }
}
 
Example 6
Project: immu   File: ImmuObjectElement.java   View source code 6 votes vote down vote up
@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;
}
 
Example 7
Project: OpenJSharp   File: TypeModeler.java   View source code 6 votes vote down vote up
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;
}
 
Example 8
Project: annotation-processor-toolkit   File: AnnotationProcessorWrapper.java   View source code 5 votes vote down vote up
@Override
public void init(ProcessingEnvironment processingEnv) {

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

    wrappedProcessor.init(processingEnv);
}
 
Example 9
Project: easy-plugins   File: UserMarkerAnnotation.java   View source code 5 votes vote down vote up
/**
 * 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();
}
 
Example 10
Project: shoebill   File: ShoebillProcessor.java   View source code 5 votes vote down vote up
@Override
public synchronized void init(ProcessingEnvironment processingEnvironment) {
    super.init(processingEnvironment);

    elementUtils = processingEnvironment.getElementUtils();
    typeUtils = processingEnvironment.getTypeUtils();
    messager = processingEnvironment.getMessager();
    filer = processingEnvironment.getFiler();
}
 
Example 11
Project: EM   File: FragmentAnnotationProcessor.java   View source code 5 votes vote down vote up
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
	super.init(processingEnv);

	this.messager = processingEnv.getMessager();
	this.filer = processingEnv.getFiler();
}
 
Example 12
Project: domino   File: BaseProcessor.java   View source code 5 votes vote down vote up
@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);
}
 
Example 13
Project: JavaGraph   File: JavaGraphProcessor.java   View source code 5 votes vote down vote up
@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();
}
 
Example 14
Project: GitHub   File: RequestOptionsGenerator.java   View source code 5 votes vote down vote up
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);
}
 
Example 15
Project: openjdk-jdk10   File: APHotSpotSignature.java   View source code 5 votes vote down vote up
public TypeMirror getReturnType(ProcessingEnvironment env) {
    if (returnTypeCache == null) {
        if (returnType == null) {
            throw new RuntimeException("Invalid return type.");
        }
        returnTypeCache = lookupType(env, returnType);
    }
    return returnTypeCache;
}
 
Example 16
Project: RNLearn_Project1   File: ReactPropertyProcessor.java   View source code 5 votes vote down vote up
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
  super.init(processingEnv);

  mFiler = processingEnv.getFiler();
  mMessager = processingEnv.getMessager();
  mElements = processingEnv.getElementUtils();
  mTypes = processingEnv.getTypeUtils();
}
 
Example 17
Project: openjdk-jdk10   File: GeneratedPlugin.java   View source code 5 votes vote down vote up
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");
}
 
Example 18
Project: RapidRouter   File: BaseAbstractProcessor.java   View source code 5 votes vote down vote up
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    GlobalEnvironment.init(processingEnv);
    elementUtils = processingEnv.getElementUtils();
    typeUtils = processingEnv.getTypeUtils();
    filer = processingEnv.getFiler();
}
 
Example 19
Project: GitHub   File: ProcessorUtil.java   View source code 5 votes vote down vote up
ProcessorUtil(ProcessingEnvironment processingEnv) {
  this.processingEnv = processingEnv;

  appGlideModuleType =
      processingEnv.getElementUtils().getTypeElement(APP_GLIDE_MODULE_QUALIFIED_NAME);
  libraryGlideModuleType =
      processingEnv.getElementUtils().getTypeElement(LIBRARY_GLIDE_MODULE_QUALIFIED_NAME);
}
 
Example 20
Project: Java-9-Programming-By-Example   File: Aptools.java   View source code 5 votes vote down vote up
@Transition(from = "MethodTool", end = true)
public String getJavadoc() {
  ProcessingEnvironment processingEnv = Environment.get();
  String javaDoc = processingEnv.getElementUtils().getDocComment(methodElement);
  if (javaDoc == null) {
    javaDoc = "";
  }
  return javaDoc;
}
 
Example 21
Project: GitHub   File: RequestManagerFactoryGenerator.java   View source code 5 votes vote down vote up
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);

}
 
Example 22
Project: data-mediator   File: ElementHandle.java   View source code 5 votes vote down vote up
@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; 
}
 
Example 23
Project: GitHub   File: AppModuleProcessor.java   View source code 5 votes vote down vote up
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);
}
 
Example 24
Project: allure-java   File: DescriptionsProcessor.java   View source code 5 votes vote down vote up
@Override
@SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel")
public synchronized void init(final ProcessingEnvironment env) {
    super.init(env);
    filer = env.getFiler();
    elementUtils = env.getElementUtils();
    messager = env.getMessager();
}
 
Example 25
Project: PreferenceRoom   File: PreferenceRoomProcessor.java   View source code 5 votes vote down vote up
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    annotatedEntityMap = new HashMap<>();
    annotatedEntityNameMap = new HashMap<>();
    annotatedComponentList = new ArrayList<>();
    messager = processingEnv.getMessager();
}
 
Example 26
Project: easy-plugins   File: CompletePluginGenerator.java   View source code 5 votes vote down vote up
public static void buildServiceFiles(Element annotationElement,
                                     RoundEnvironment roundEnv,
                                     ProcessingEnvironment procEnv,
                                     ProcessorOutputCollection output) {
    buildFiles(
            PluginAnnotation.createUserMarker(annotationElement, procEnv),
            procEnv,
            roundEnv,
            output,
            false);


}
 
Example 27
Project: openjdk-jdk10   File: GeneratedNodeIntrinsicPlugin.java   View source code 5 votes vote down vote up
@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;
}
 
Example 28
Project: NullAway   File: DataFlow.java   View source code 5 votes vote down vote up
@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;
}
 
Example 29
Project: OpenJSharp   File: TypeMonikerFactory.java   View source code 5 votes vote down vote up
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);
}
 
Example 30
Project: GitHub   File: Processor.java   View source code 5 votes vote down vote up
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;
}
 
Example 31
Project: GitHub   File: JsonAnnotationProcessor.java   View source code 5 votes vote down vote up
@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);
}
 
Example 32
Project: easy-plugins   File: CompletePluginGenerator.java   View source code 5 votes vote down vote up
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;
}
 
Example 33
Project: GitHub   File: RealmProxyMediatorGenerator.java   View source code 5 votes vote down vote up
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));
    }
}
 
Example 34
Project: GitHub   File: RealmProxyClassGenerator.java   View source code 5 votes vote down vote up
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));
}
 
Example 35
Project: jso-builder   File: JSOBuilderProcessor.java   View source code 5 votes vote down vote up
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);

    this.elementUtils = processingEnv.getElementUtils();
    this.messager = processingEnv.getMessager();
}
 
Example 36
Project: RIBs   File: RibProcessor.java   View source code 5 votes vote down vote up
@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));
}
 
Example 37
Project: openjdk-jdk10   File: InjectedDependencies.java   View source code 5 votes vote down vote up
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;
}
 
Example 38
Project: retainer   File: RetainProcessor.java   View source code 5 votes vote down vote up
@Override
public synchronized void init(ProcessingEnvironment processingEnvironment) {
    super.init(processingEnvironment);

    elementUtils = processingEnvironment.getElementUtils();
    messager = processingEnvironment.getMessager();
    filer = processingEnvironment.getFiler();
}
 
Example 39
Project: pl   File: PluginYamlAnnotationProcessor.java   View source code 5 votes vote down vote up
@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");
}
 
Example 40
Project: r-parser   File: ExampleProcessor.java   View source code 5 votes vote down vote up
@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();
}