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

下面列出了怎么用javax.annotation.processing.ProcessingEnvironment的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: EasyMPermission   文件: Processor.java
/** {@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();
	}
}
 
源代码2 项目: Mixin   文件: AnnotatedMixins.java
/**
 * 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));
}
 
源代码3 项目: hkt   文件: HktProcessor.java
@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");
}
 
源代码4 项目: AndServer   文件: ConfigProcessor.java
@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);
}
 
源代码5 项目: requery   文件: AttributeMember.java
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;
}
 
源代码6 项目: turbine   文件: ProcessingIntegrationTest.java
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()));
}
 
源代码7 项目: openjdk-jdk8u-backup   文件: AnnotationParser.java
@Override
public void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    this.processingEnv = processingEnv;
    errorListener = new ErrorReceiverImpl(
            processingEnv.getMessager(),
            processingEnv.getOptions().containsKey(Const.DEBUG_OPTION.getValue())
    );
}
 
源代码8 项目: AutoLayout-Android   文件: AutoLayoutProcessor.java
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    mMessager = processingEnv.getMessager();

    elementUtils = processingEnv.getElementUtils();
    filer = processingEnv.getFiler();
}
 
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);
    }
}
 
源代码10 项目: openjdk-jdk8u   文件: AnnotationParser.java
@Override
public void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    this.processingEnv = processingEnv;
    errorListener = new ErrorReceiverImpl(
            processingEnv.getMessager(),
            processingEnv.getOptions().containsKey(Const.DEBUG_OPTION.getValue())
    );
}
 
源代码11 项目: RetroFacebook   文件: AnnotationOutput.java
/**
 * 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();
}
 
源代码12 项目: jdk8u-jdk   文件: PluginChecker.java
/**
 * 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);
    }
}
 
源代码13 项目: SimpleWeibo   文件: RetroWeiboProcessor.java
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);
}
 
源代码14 项目: vertx-codegen   文件: TypeUse.java
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);
}
 
源代码15 项目: 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();
}
 
源代码16 项目: jdk8u60   文件: AnnotationParser.java
@Override
public void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    this.processingEnv = processingEnv;
    errorListener = new ErrorReceiverImpl(
            processingEnv.getMessager(),
            processingEnv.getOptions().containsKey(Const.DEBUG_OPTION.getValue())
    );
}
 
源代码17 项目: firebase-android-sdk   文件: EncodableProcessor.java
@Override
public synchronized void init(ProcessingEnvironment processingEnvironment) {
  super.init(processingEnvironment);
  elements = processingEnvironment.getElementUtils();
  types = processingEnvironment.getTypeUtils();
  getterFactory = new GetterFactory(types, elements, processingEnvironment.getMessager());
}
 
源代码18 项目: AndServer   文件: ConverterProcessor.java
@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);
}
 
源代码19 项目: Scoops   文件: ScoopsProcesssor.java
@Override
public synchronized void init(ProcessingEnvironment processingEnvironment) {
    super.init(processingEnvironment);
    filer = processingEnv.getFiler();
    messager = processingEnv.getMessager();
    elementUtils = processingEnv.getElementUtils();
    typeUtils = processingEnv.getTypeUtils();
}
 
源代码20 项目: abtestgen   文件: ABTestProcessor.java
@Override
public synchronized void init(ProcessingEnvironment env) {
  super.init(env);

  filer = env.getFiler();
  elementUtils = env.getElementUtils();
  typeUtils = env.getTypeUtils();
  messager = env.getMessager();
}
 
@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();
    }
}
 
源代码22 项目: mnemonic   文件: DurableEntityProcessor.java
/**
 * {@inheritDoc}
 */
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
  super.init(processingEnv);
  typeUtils = processingEnv.getTypeUtils();
  elementUtils = processingEnv.getElementUtils();
  filer = processingEnv.getFiler();
  messager = processingEnv.getMessager();
}
 
源代码23 项目: featured   文件: ModelNode.java
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);
        }
    }
}
 
源代码24 项目: stitch   文件: ElementCheck.java
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());
    }
}
 
源代码25 项目: JIMU   文件: AutowiredProcessor.java
@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. <<<");
}
 
源代码26 项目: vertx-codegen   文件: TypeUse.java
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;
}
 
源代码27 项目: react-native-GPay   文件: ReactPropertyProcessor.java
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
  super.init(processingEnv);

  mFiler = processingEnv.getFiler();
  mMessager = processingEnv.getMessager();
  mElements = processingEnv.getElementUtils();
  mTypes = processingEnv.getTypeUtils();
}
 
源代码28 项目: AutoBundle   文件: AutoBundleProcessor.java
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    filer = processingEnv.getFiler();
    messager = processingEnv.getMessager();
    elementUtils = processingEnv.getElementUtils();
    typeUtils = processingEnv.getTypeUtils();
}
 
源代码29 项目: fragmentargs   文件: ArgProcessor.java
@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");
}
 
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
  super.init(processingEnv);

  mFiler = processingEnv.getFiler();
  mElements = processingEnv.getElementUtils();
  mMessager = processingEnv.getMessager();
  mTypes = processingEnv.getTypeUtils();
}
 
 类所在包
 同包方法