@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; }
/** * 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; } }; }
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); }
@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()); }
@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) { } }
@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; }
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; }
@Override public void init(ProcessingEnvironment processingEnv) { // get messager messager = processingEnv.getMessager(); wrappedProcessor.init(processingEnv); }
/** * 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(); }
@Override public synchronized void init(ProcessingEnvironment processingEnvironment) { super.init(processingEnvironment); elementUtils = processingEnvironment.getElementUtils(); typeUtils = processingEnvironment.getTypeUtils(); messager = processingEnvironment.getMessager(); filer = processingEnvironment.getFiler(); }
@Override public synchronized void init(ProcessingEnvironment processingEnv) { super.init(processingEnv); this.messager = processingEnv.getMessager(); this.filer = processingEnv.getFiler(); }
@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); }
@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(); }
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); }
public TypeMirror getReturnType(ProcessingEnvironment env) { if (returnTypeCache == null) { if (returnType == null) { throw new RuntimeException("Invalid return type."); } returnTypeCache = lookupType(env, returnType); } return returnTypeCache; }
@Override public synchronized void init(ProcessingEnvironment processingEnv) { super.init(processingEnv); mFiler = processingEnv.getFiler(); mMessager = processingEnv.getMessager(); mElements = processingEnv.getElementUtils(); mTypes = processingEnv.getTypeUtils(); }
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"); }
@Override public synchronized void init(ProcessingEnvironment processingEnv) { super.init(processingEnv); GlobalEnvironment.init(processingEnv); elementUtils = processingEnv.getElementUtils(); typeUtils = processingEnv.getTypeUtils(); filer = processingEnv.getFiler(); }
ProcessorUtil(ProcessingEnvironment processingEnv) { this.processingEnv = processingEnv; appGlideModuleType = processingEnv.getElementUtils().getTypeElement(APP_GLIDE_MODULE_QUALIFIED_NAME); libraryGlideModuleType = processingEnv.getElementUtils().getTypeElement(LIBRARY_GLIDE_MODULE_QUALIFIED_NAME); }
@Transition(from = "MethodTool", end = true) public String getJavadoc() { ProcessingEnvironment processingEnv = Environment.get(); String javaDoc = processingEnv.getElementUtils().getDocComment(methodElement); if (javaDoc == null) { javaDoc = ""; } return javaDoc; }
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); }
@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; }
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); }
@Override @SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel") public synchronized void init(final ProcessingEnvironment env) { super.init(env); filer = env.getFiler(); elementUtils = env.getElementUtils(); messager = env.getMessager(); }
@Override public synchronized void init(ProcessingEnvironment processingEnv) { super.init(processingEnv); annotatedEntityMap = new HashMap<>(); annotatedEntityNameMap = new HashMap<>(); annotatedComponentList = new ArrayList<>(); messager = processingEnv.getMessager(); }
public static void buildServiceFiles(Element annotationElement, RoundEnvironment roundEnv, ProcessingEnvironment procEnv, ProcessorOutputCollection output) { buildFiles( PluginAnnotation.createUserMarker(annotationElement, procEnv), procEnv, roundEnv, output, false); }
@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; }
@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; }
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); }
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; }
@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); }
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; }
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)); } }
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)); }
@Override public synchronized void init(ProcessingEnvironment processingEnv) { super.init(processingEnv); this.elementUtils = processingEnv.getElementUtils(); this.messager = processingEnv.getMessager(); }
@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)); }
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; }
@Override public synchronized void init(ProcessingEnvironment processingEnvironment) { super.init(processingEnvironment); elementUtils = processingEnvironment.getElementUtils(); messager = processingEnvironment.getMessager(); filer = processingEnvironment.getFiler(); }
@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"); }
@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(); }