javax.annotation.processing.ProcessingEnvironment Java Examples

The following examples show how to use javax.annotation.processing.ProcessingEnvironment. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnnotatedMixins.java    From Mixin with MIT License 6 votes vote down vote up
/**
 * Private constructor, get instances using {@link #getMixinsForEnvironment}
 */
private AnnotatedMixins(ProcessingEnvironment processingEnv) {
    this.env = this.detectEnvironment(processingEnv);
    this.processingEnv = processingEnv;
    
    MessageRouter.setMessager(processingEnv.getMessager());

    String pluginVersion = this.checkPluginVersion(this.getOption(SupportedOptions.PLUGIN_VERSION));
    String pluginVersionString = pluginVersion != null ? String.format(" (MixinGradle Version=%s)", pluginVersion) : "";
    this.printMessage(Kind.NOTE, "SpongePowered MIXIN Annotation Processor Version=" + MixinBootstrap.VERSION + pluginVersionString);

    this.targets = this.initTargetMap();
    this.obf = new ObfuscationManager(this);
    this.obf.init();

    this.validators = ImmutableList.<IMixinValidator>of(
        new ParentValidator(this),
        new TargetValidator(this)
    );
    
    this.initTokenCache(this.getOption(SupportedOptions.TOKENS));
}
 
Example #2
Source File: AttributeMember.java    From requery with Apache License 2.0 6 votes vote down vote up
private ElementValidator validateCollectionType(ProcessingEnvironment processingEnvironment) {
    Types types = processingEnvironment.getTypeUtils();
    TypeElement collectionElement = (TypeElement) types.asElement(typeMirror());
    if (collectionElement != null) {
        ElementValidator validator = new ElementValidator(collectionElement, processingEnvironment);
        if (Mirrors.isInstance(types, collectionElement, List.class)) {
            builderClass = ListAttributeBuilder.class;
        } else if (Mirrors.isInstance(types, collectionElement, Set.class)) {
            builderClass = SetAttributeBuilder.class;
        } else if (Mirrors.isInstance(types, collectionElement, Iterable.class)) {
            builderClass = ResultAttributeBuilder.class;
        } else {
            validator.error("Invalid collection type, must be Set, List or Iterable");
        }
        return validator;
    }
    return null;
}
 
Example #3
Source File: ProcessingIntegrationTest.java    From turbine with Apache License 2.0 6 votes vote down vote up
private static void logError(
    ProcessingEnvironment processingEnv,
    RoundEnvironment roundEnv,
    Class<?> processorClass,
    int round) {
  processingEnv
      .getMessager()
      .printMessage(
          Diagnostic.Kind.ERROR,
          String.format(
              "%d: %s {errorRaised=%s, processingOver=%s}",
              round,
              processorClass.getSimpleName(),
              roundEnv.errorRaised(),
              roundEnv.processingOver()));
}
 
Example #4
Source File: Processor.java    From EasyMPermission with MIT License 6 votes vote down vote up
/** {@inheritDoc} */
@Override public void init(ProcessingEnvironment procEnv) {
	super.init(procEnv);
	if (System.getProperty("lombok.disable") != null) {
		lombokDisabled = true;
		return;
	}
	
	this.processingEnv = (JavacProcessingEnvironment) procEnv;
	placePostCompileAndDontMakeForceRoundDummiesHook();
	transformer = new JavacTransformer(procEnv.getMessager());
	trees = Trees.instance(procEnv);
	SortedSet<Long> p = transformer.getPriorities();
	if (p.isEmpty()) {
		this.priorityLevels = new long[] {0L};
		this.priorityLevelsRequiringResolutionReset = new HashSet<Long>();
	} else {
		this.priorityLevels = new long[p.size()];
		int i = 0;
		for (Long prio : p) this.priorityLevels[i++] = prio;
		this.priorityLevelsRequiringResolutionReset = transformer.getPrioritiesRequiringResolutionReset();
	}
}
 
Example #5
Source File: ConfigProcessor.java    From AndServer with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    mFiler = processingEnv.getFiler();
    mElements = processingEnv.getElementUtils();
    mLog = new Logger(processingEnv.getMessager());

    mContext = TypeName.get(mElements.getTypeElement(Constants.CONTEXT_TYPE).asType());
    mCollectionUtils = TypeName.get(mElements.getTypeElement(Constants.COLLECTION_UTIL_TYPE).asType());
    mOnRegisterType = TypeName.get(mElements.getTypeElement(Constants.ON_REGISTER_TYPE).asType());
    mRegisterType = TypeName.get(mElements.getTypeElement(Constants.REGISTER_TYPE).asType());

    mConfig = TypeName.get(mElements.getTypeElement(Constants.CONFIG_TYPE).asType());
    mDelegate = TypeName.get(mElements.getTypeElement(Constants.CONFIG_DELEGATE_TYPE).asType());
    mWebsite = TypeName.get(mElements.getTypeElement(Constants.WEBSITE_TYPE).asType());
    mMultipart = TypeName.get(mElements.getTypeElement(Constants.CONFIG_MULTIPART_TYPE).asType());

    mString = TypeName.get(String.class);
}
 
Example #6
Source File: HktProcessor.java    From hkt with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);

    Types = processingEnv.getTypeUtils();
    Elts = processingEnv.getElementUtils();
    Messager = processingEnv.getMessager();
    JdkSpecificApi = jdkSpecificApi(processingEnv);

    __Elt = Elts.getTypeElement(__.class.getCanonicalName());
    GenCode = new GenCode(Elts, Types, processingEnv.getFiler(), __Elt);

    HktConfigElt = Elts.getTypeElement(HktConfig.class.getName());
    witnessTypeNameConfMethod = unsafeGetExecutableElement(HktConfigElt, "witnessTypeName");
    generateInConfMethod = unsafeGetExecutableElement(HktConfigElt, "generateIn");
    withVisibilityConfMethod = unsafeGetExecutableElement(HktConfigElt, "withVisibility");
    coerceMethodNameConfMethod = unsafeGetExecutableElement(HktConfigElt, "coerceMethodName");
    typeEqMethodNameConfMethod = unsafeGetExecutableElement(HktConfigElt, "typeEqMethodName");
}
 
Example #7
Source File: ScoopsProcesssor.java    From Scoops with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void init(ProcessingEnvironment processingEnvironment) {
    super.init(processingEnvironment);
    filer = processingEnv.getFiler();
    messager = processingEnv.getMessager();
    elementUtils = processingEnv.getElementUtils();
    typeUtils = processingEnv.getTypeUtils();
}
 
Example #8
Source File: EncodableProcessor.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void init(ProcessingEnvironment processingEnvironment) {
  super.init(processingEnvironment);
  elements = processingEnvironment.getElementUtils();
  types = processingEnvironment.getTypeUtils();
  getterFactory = new GetterFactory(types, elements, processingEnvironment.getMessager());
}
 
Example #9
Source File: JavacProcessingEnvironment.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
ProcessorState(Processor p, Log log, Source source, boolean allowModules, ProcessingEnvironment env) {
    processor = p;
    contributed = false;

    try {
        processor.init(env);

        checkSourceVersionCompatibility(source, log);

        supportedAnnotationPatterns = new ArrayList<>();
        for (String importString : processor.getSupportedAnnotationTypes()) {
            supportedAnnotationPatterns.add(importStringToPattern(allowModules,
                                                                  importString,
                                                                  processor,
                                                                  log));
        }

        supportedOptionNames = new ArrayList<>();
        for (String optionName : processor.getSupportedOptions() ) {
            if (checkOptionName(optionName, log))
                supportedOptionNames.add(optionName);
        }

    } catch (ClientCodeException e) {
        throw e;
    } catch (Throwable t) {
        throw new AnnotationProcessingError(t);
    }
}
 
Example #10
Source File: AutoLayoutProcessor.java    From AutoLayout-Android with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    mMessager = processingEnv.getMessager();

    elementUtils = processingEnv.getElementUtils();
    filer = processingEnv.getFiler();
}
 
Example #11
Source File: AnnotationParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    this.processingEnv = processingEnv;
    errorListener = new ErrorReceiverImpl(
            processingEnv.getMessager(),
            processingEnv.getOptions().containsKey(Const.DEBUG_OPTION.getValue())
    );
}
 
Example #12
Source File: ArgProcessor.java    From fragmentargs with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void init(ProcessingEnvironment env) {
    super.init(env);

    Elements elementUtils = env.getElementUtils();
    typeUtils = env.getTypeUtils();
    filer = env.getFiler();

    TYPE_FRAGMENT = elementUtils.getTypeElement("android.app.Fragment");
    TYPE_SUPPORT_FRAGMENT =
            elementUtils.getTypeElement("android.support.v4.app.Fragment");
    TYPE_ANDROIDX_FRAGMENT =
            elementUtils.getTypeElement("androidx.fragment.app.Fragment");
}
 
Example #13
Source File: TypeUse.java    From vertx-codegen with Apache License 2.0 5 votes vote down vote up
private Method getMethod(ProcessingEnvironment env, ExecutableElement methodElt) {
  Method methodRef = Helper.getReflectMethod(Thread.currentThread().getContextClassLoader(), methodElt);
  if (methodRef == null) {
    methodRef = Helper.getReflectMethod(env, methodElt);
  }
  return methodRef;
}
 
Example #14
Source File: ABTestProcessor.java    From abtestgen with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void init(ProcessingEnvironment env) {
  super.init(env);

  filer = env.getFiler();
  elementUtils = env.getElementUtils();
  typeUtils = env.getTypeUtils();
  messager = env.getMessager();
}
 
Example #15
Source File: AutoBundleProcessor.java    From AutoBundle with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    filer = processingEnv.getFiler();
    messager = processingEnv.getMessager();
    elementUtils = processingEnv.getElementUtils();
    typeUtils = processingEnv.getTypeUtils();
}
 
Example #16
Source File: ReactModuleSpecProcessor.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
  super.init(processingEnv);

  mFiler = processingEnv.getFiler();
  mElements = processingEnv.getElementUtils();
  mMessager = processingEnv.getMessager();
  mTypes = processingEnv.getTypeUtils();
}
 
Example #17
Source File: ConverterProcessor.java    From AndServer with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    mFiler = processingEnv.getFiler();
    mElements = processingEnv.getElementUtils();
    mLog = new Logger(processingEnv.getMessager());

    mContext = TypeName.get(mElements.getTypeElement(Constants.CONTEXT_TYPE).asType());
    mOnRegisterType = TypeName.get(mElements.getTypeElement(Constants.ON_REGISTER_TYPE).asType());
    mRegisterType = TypeName.get(mElements.getTypeElement(Constants.REGISTER_TYPE).asType());

    mConverter = TypeName.get(mElements.getTypeElement(Constants.CONVERTER_TYPE).asType());

    mString = TypeName.get(String.class);
}
 
Example #18
Source File: ReactPropertyProcessor.java    From react-native-GPay with MIT License 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 #19
Source File: AnnotationParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    this.processingEnv = processingEnv;
    errorListener = new ErrorReceiverImpl(
            processingEnv.getMessager(),
            processingEnv.getOptions().containsKey(Const.DEBUG_OPTION.getValue())
    );
}
 
Example #20
Source File: AutowiredProcessor.java    From JIMU with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void init(ProcessingEnvironment processingEnvironment) {
    super.init(processingEnvironment);

    mFiler = processingEnv.getFiler();                  // Generate class.
    types = processingEnv.getTypeUtils();            // Get type utils.
    elements = processingEnv.getElementUtils();      // Get class meta.

    typeUtils = new TypeUtils(types, elements);

    logger = new Logger(processingEnv.getMessager());   // Package the log utils.

    logger.info(">>> AutowiredProcessor init. <<<");
}
 
Example #21
Source File: AnnotationOutput.java    From RetroFacebook with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a string representation of the given annotation value, suitable for inclusion in a Java
 * source file as the initializer of a variable of the appropriate type.
 */
String sourceFormForInitializer(
    AnnotationValue annotationValue,
    ProcessingEnvironment processingEnv,
    String memberName,
    Element context) {
  SourceFormVisitor visitor =
      new InitializerSourceFormVisitor(processingEnv, memberName, context);
  StringBuilder sb = new StringBuilder();
  visitor.visit(annotationValue, sb);
  return sb.toString();
}
 
Example #22
Source File: ElementCheck.java    From stitch with Apache License 2.0 5 votes vote down vote up
static void checkExtendsActivityPage(ProcessingEnvironment environment, TypeElement element, TypeElement valueElement) {
    boolean isSuper = isSuperClass(environment, valueElement.getQualifiedName().toString(), "bamboo.component.page.ActivityPage");
    if (!isSuper) {
        StringBuilder sb = new StringBuilder("@Exported error : ");
        sb.append("at ");
        sb.append(element.getQualifiedName());
        sb.append(" @Exported's value ");
        sb.append(valueElement.getQualifiedName());
        sb.append(" must be extends from bamboo.component.page.ActivityPage;");
        throw new IllegalStateException(sb.toString());
    }
}
 
Example #23
Source File: BaseViewGenerator.java    From PowerfulRecyclerViewAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void generate(AbstractModel<T> model, ProcessingEnvironment processingEnv) {
    logger = Logger.getInstance(processingEnv.getMessager());
    processingEnvironment = processingEnv;
    //realModel is initialized by AbstractModel
    realModel = model.getRealModel();
    if (realModel == null) {
        logger.log(Diagnostic.Kind.NOTE, "readModel is null,aborted");
        return;
    }
    //load template
    logger.log(Diagnostic.Kind.NOTE, "load template file...");
    String template = loadTemplate();
    if ("".equals(template)) {
        return;
    }
    //logger.log(Diagnostic.Kind.NOTE, "template file:" + template);
    //create file
    logger.log(Diagnostic.Kind.NOTE, "create source file...");
    JavaFileObject jfo = createFile();
    if (jfo == null) {
        logger.log(Diagnostic.Kind.NOTE, "create java file failed,aborted");
        return;
    }
    //write file
    logger.log(Diagnostic.Kind.NOTE, "write source file...");
    try {
        writeFile(template, jfo.openWriter());
        String sourceFileName = getModelClassName();
        logger.log(Diagnostic.Kind.NOTE, "generate source file successful:" + sourceFileName);
    } catch (IOException e) {
        logger.log(Diagnostic.Kind.ERROR, "create file failed");
        e.printStackTrace();
    }
}
 
Example #24
Source File: PluginChecker.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes the processor by loading the device configuration.
 *
 * {@inheritDoc}
 */
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    try {
        String deviceOption = processingEnv.getOptions().get(DEVICE_OPTION);
        device = (Device) JAXBContext.newInstance(Device.class)
                .createUnmarshaller().unmarshal(new File(deviceOption));
    } catch (JAXBException e) {
        throw new RuntimeException(
                "Please specify device by -Adevice=device.xml\n"
                + e.toString(), e);
    }
}
 
Example #25
Source File: ModelNode.java    From featured with Apache License 2.0 5 votes vote down vote up
public void detectLibraryFeatures(ProcessingEnvironment env, Names names) {
    Collection<FeatureNode> featureNodes = new ArrayList<>(getFeatureNodes());
    for (FeatureNode featureNode : featureNodes) {
        TypeMirror superType = featureNode.getElement().getSuperclass();
        if (superType.getKind() == TypeKind.NONE) {
            continue;
        }

        FeatureNode superNode = findFetureNode(superType, env.getTypeUtils());
        if (superNode != null) {
            // node already exists
            continue;
        }

        TypeMirror featureType = env.getElementUtils().getTypeElement(
                names.getFeatureClassName().toString()).asType();

        if (env.getTypeUtils().isSameType(superType, featureType)) {
            continue;
        }

        if (env.getTypeUtils().isSubtype(superType, featureType)) {
            // create library node
            TypeElement superTypeElement = (TypeElement)
                    env.getTypeUtils().asElement(superType);
            String name = superTypeElement.getQualifiedName().toString();
            FeatureNode node = new FeatureNode(name, superTypeElement, true);
            putFeatureNode(node);
        }
    }
}
 
Example #26
Source File: RetroWeiboProcessor.java    From SimpleWeibo with Apache License 2.0 5 votes vote down vote up
Property(
    String name,
    String identifier,
    ExecutableElement method,
    String type,
    TypeSimplifier typeSimplifier,
    ProcessingEnvironment processingEnv
    ) {
  this.name = name;
  this.identifier = identifier;
  this.method = method;
  this.type = type;
  this.typeSimplifier = typeSimplifier;
  this.processingEnv = processingEnv;
  this.annotations = buildAnnotations(typeSimplifier);
  this.args = formalTypeArgsString(method);
  this.path = buildPath(method);
  this.typeArgs = buildTypeArguments(type);
  this.queries = buildQueries(method);
  this.queryMaps = buildQueryMaps(method);
  this.queryBundles = buildQueryBundles(method);
  this.isGet = buildIsGet(method);
  this.isPost = buildIsPost(method);
  this.isDelete = buildIsDelete(method);
  this.body = buildBody(method);
  this.callbackType = buildCallbackType(method);
  this.callbackArg = buildCallbackArg(method);
  if ("".equals(typeArgs)) typeArgs = callbackType;
  this.permissions = buildPermissions(method);
}
 
Example #27
Source File: TypeUse.java    From vertx-codegen with Apache License 2.0 5 votes vote down vote up
public TypeUse.TypeInternal forParam(ProcessingEnvironment env, ExecutableElement methodElt, int paramIndex) {
  Method methodRef = getMethod(env, methodElt);
  if (methodRef == null) {
    return null;
  }
  AnnotatedType annotated = methodRef.getAnnotatedParameterTypes()[paramIndex];
  return new ReflectType(annotated);
}
 
Example #28
Source File: PreferenceRoomProcessor.java    From PreferenceRoom with Apache License 2.0 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 #29
Source File: AnnotationParser.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    this.processingEnv = processingEnv;
    errorListener = new ErrorReceiverImpl(
            processingEnv.getMessager(),
            processingEnv.getOptions().containsKey(Const.DEBUG_OPTION.getValue())
    );
}
 
Example #30
Source File: DurableEntityProcessor.java    From mnemonic with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
  super.init(processingEnv);
  typeUtils = processingEnv.getTypeUtils();
  elementUtils = processingEnv.getElementUtils();
  filer = processingEnv.getFiler();
  messager = processingEnv.getMessager();
}