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 Project: EasyMPermission   Author: mobmead   File: Processor.java    License: 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 #2
Source Project: Mixin   Author: SpongePowered   File: AnnotatedMixins.java    License: 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 #3
Source Project: hkt   Author: derive4j   File: HktProcessor.java    License: 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 #4
Source Project: AndServer   Author: yanzhenjie   File: ConfigProcessor.java    License: 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 #5
Source Project: requery   Author: requery   File: AttributeMember.java    License: 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 #6
Source Project: turbine   Author: google   File: ProcessingIntegrationTest.java    License: 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 #7
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: AnnotationParser.java    License: 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 #8
Source Project: AutoLayout-Android   Author: DTHeaven   File: AutoLayoutProcessor.java    License: 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 #9
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 Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: AnnotationParser.java    License: 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 #11
Source Project: RetroFacebook   Author: yongjhih   File: AnnotationOutput.java    License: 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 #12
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: PluginChecker.java    License: 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 #13
Source Project: SimpleWeibo   Author: 8tory   File: RetroWeiboProcessor.java    License: 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 #14
Source Project: vertx-codegen   Author: vert-x3   File: TypeUse.java    License: 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 #15
Source Project: PreferenceRoom   Author: skydoves   File: PreferenceRoomProcessor.java    License: 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 #16
Source Project: jdk8u60   Author: chenghanpeng   File: AnnotationParser.java    License: 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 #17
Source Project: firebase-android-sdk   Author: firebase   File: EncodableProcessor.java    License: 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 #18
Source Project: AndServer   Author: yanzhenjie   File: ConverterProcessor.java    License: 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 #19
Source Project: Scoops   Author: 52inc   File: ScoopsProcesssor.java    License: 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 #20
Source Project: abtestgen   Author: imperial-crystalline-recursion   File: ABTestProcessor.java    License: 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 #21
Source Project: PowerfulRecyclerViewAdapter   Author: simplify20   File: BaseViewGenerator.java    License: 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 #22
Source Project: mnemonic   Author: apache   File: DurableEntityProcessor.java    License: 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();
}
 
Example #23
Source Project: featured   Author: beworker   File: ModelNode.java    License: 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 #24
Source Project: stitch   Author: bambootang   File: ElementCheck.java    License: 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 #25
Source Project: JIMU   Author: mqzhangw   File: AutowiredProcessor.java    License: 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 #26
Source Project: vertx-codegen   Author: vert-x3   File: TypeUse.java    License: 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 #27
Source Project: react-native-GPay   Author: hellochirag   File: ReactPropertyProcessor.java    License: 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 #28
Source Project: AutoBundle   Author: yatatsu   File: AutoBundleProcessor.java    License: 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 #29
Source Project: fragmentargs   Author: sockeqwe   File: ArgProcessor.java    License: 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 #30
Source Project: react-native-GPay   Author: hellochirag   File: ReactModuleSpecProcessor.java    License: 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();
}