本文整理汇总了Java中javax.annotation.processing.Messager类的典型用法代码示例。如果您正苦于以下问题:Java Messager类的具体用法?Java Messager怎么用?Java Messager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Messager类属于javax.annotation.processing包,在下文中一共展示了Messager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: collectSubscribers
import javax.annotation.processing.Messager; //导入依赖的package包/类
private void collectSubscribers(Set<? extends TypeElement> annotations, RoundEnvironment env, Messager messager) {
for (TypeElement annotation : annotations) {
Set<? extends Element> elements = env.getElementsAnnotatedWith(annotation);
for (Element element : elements) {
if (element instanceof ExecutableElement) {
ExecutableElement method = (ExecutableElement) element;
if (checkHasNoErrors(method, messager)) {
TypeElement classElement = (TypeElement) method.getEnclosingElement();
methodsByClass.putElement(classElement, method);
}
} else {
messager.printMessage(Diagnostic.Kind.ERROR, "@Subscribe is only valid for methods", element);
}
}
}
}
示例2: generateConstructorBuilder
import javax.annotation.processing.Messager; //导入依赖的package包/类
private static MethodSpec.Builder generateConstructorBuilder(
HashMap<String, BarricadeResponseSet> values, Messager messager) {
MethodSpec.Builder methodBuilder = MethodSpec.constructorBuilder().addModifiers(PUBLIC);
methodBuilder.addStatement("configs = new HashMap<>()");
for (Map.Entry<String, BarricadeResponseSet> entry : values.entrySet()) {
BarricadeResponseSet barricadeResponseSet = entry.getValue();
String listName = "barricadeResponsesFor" + entry.getKey();
methodBuilder.addStatement("$T<$T> " + listName + " = new $T<>()", List.class,
BarricadeResponse.class, ArrayList.class);
for (BarricadeResponse barricadeResponse : barricadeResponseSet.responses) {
methodBuilder.addStatement(listName + ".add(new $T($L, $S, $S))", BarricadeResponse.class,
barricadeResponse.statusCode, barricadeResponse.responseFileName,
barricadeResponse.contentType);
}
methodBuilder.addStatement(
"configs.put($S, new $T(" + listName + ", " + barricadeResponseSet.defaultIndex + "))",
entry.getKey(), TYPE_BARRICADE_RESPONSE_SET);
}
return methodBuilder;
}
示例3: writeInto
import javax.annotation.processing.Messager; //导入依赖的package包/类
public void writeInto(final Filer pFiler, final Messager pMessager) {
// prepare generated class
final GeneratedClass lGeneratedClass = new GeneratedClass(mEnclosingClass, mMethods);
final TypeSpec lTypeSpecGeneratedClass = lGeneratedClass.buildTypeSpec();
final String lPackageName = lGeneratedClass.packageName();
// create generated class to a file
try {
JavaFile.builder(lPackageName, lTypeSpecGeneratedClass)
.build()
.writeTo(pFiler);
} catch (IOException pE) {
logError(pMessager, mEnclosingClass, "error while writing generated class");
}
}
示例4: parse
import javax.annotation.processing.Messager; //导入依赖的package包/类
public static Spec parse(Element element, ProcessingEnvironment processingEnv) {
Messager messager = processingEnv.getMessager();
if (element.getKind() != ElementKind.INTERFACE) {
messager.printMessage(
Diagnostic.Kind.ERROR, "@DataEnum can only be used on interfaces.", element);
return null;
}
TypeElement dataEnum = (TypeElement) element;
List<TypeVariableName> typeVariableNames = new ArrayList<>();
for (TypeParameterElement typeParameterElement : dataEnum.getTypeParameters()) {
typeVariableNames.add(TypeVariableName.get(typeParameterElement));
}
List<Value> values = ValuesParser.parse(dataEnum, processingEnv);
if (values == null) {
return null;
}
ClassName enumInterface = ClassName.get(dataEnum);
return new Spec(enumInterface, typeVariableNames, values);
}
示例5: parseBeanMethod
import javax.annotation.processing.Messager; //导入依赖的package包/类
private boolean parseBeanMethod(ExecutableElement beanMethod, String[] beanNames, Messager messager) {
boolean valid = true;
if (beanNames.length == 0) {
valid = false;
messager.printMessage(Kind.ERROR, "All @Bean annotations must define at least one name for a bean.", beanMethod);
}
if (beanMethod.getReturnType().getKind() != TypeKind.DECLARED) {
valid = false;
messager.printMessage(Kind.ERROR, "@Bean methods must return an Object", beanMethod);
}
if (!beanMethod.getModifiers().contains(Modifier.PUBLIC)) {
valid = false;
messager.printMessage(Kind.ERROR, "@Bean methods must be marked public", beanMethod);
}
List<Modifier> illegalModifiers = getIllegalModifiers(beanMethod.getModifiers(), DISALLOWED_ON_METHOD);
if (illegalModifiers.size() != 0) {
valid = false;
messager.printMessage(Kind.ERROR, "Illegal modifiers found on spring @Bean method: "
+ illegalModifiers.stream().map(m -> m.name()).collect(Collectors.joining(", ")),
beanMethod);
}
return valid;
}
示例6: process
import javax.annotation.processing.Messager; //导入依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (processingEnv.getElementUtils().getModuleElement("m1x") == null) {
throw new AssertionError("No m1x module found.");
}
Messager messager = processingEnv.getMessager();
for (TypeElement clazz : ElementFilter.typesIn(roundEnv.getRootElements())) {
for (VariableElement field : ElementFilter.fieldsIn(clazz.getEnclosedElements())) {
messager.printMessage(Kind.NOTE, "field: " + field.getSimpleName());
}
}
return false;
}
示例7: init
import javax.annotation.processing.Messager; //导入依赖的package包/类
@Before
public void init() {
Messager messenger = mock(Messager.class);
this.annotationValue = mock(AnnotationValue.class);
this.annotationTypeMirror = mock(TypeMirror.class);
this.executableElement = mock(ExecutableElement.class);
this.annotationElement = mock(TypeElement.class);
when(this.annotationElement.asType()).thenReturn(this.annotationTypeMirror);
this.elementUtils = mock(Elements.class);
when(this.elementUtils.getTypeElement(any())).thenReturn(this.annotationElement);
this.processingEnv = mock(ProcessingEnvironment.class);
when(processingEnv.getMessager()).thenReturn(messenger);
when(processingEnv.getElementUtils()).thenReturn(this.elementUtils);
// finally....
this.testee = new TSModuleHandler(processingEnv);
}
示例8: instance
import javax.annotation.processing.Messager; //导入依赖的package包/类
static Settings instance(Messager messager, Map<String,String> options) {
String targetDirStr = options.getOrDefault(TARGET_DIR_KEY, "");
if (targetDirStr.equals("")) {
return illegalInstance("initialization failed; no "+TARGET_DIR_KEY+"; options are "+options);
}
String onDirExistsStr = options.get(DIR_EXISTS_BEHAVIOR_KEY);
AlreadyExistsBehavior targetDirExistsBehavior = AlreadyExistsBehavior.OVERWRITE;
if (onDirExistsStr != null) {
try {
targetDirExistsBehavior = AlreadyExistsBehavior.valueOf(onDirExistsStr);
}
catch (IllegalArgumentException ex) {
return handleBadDirExistsBehavior(messager, onDirExistsStr);
}
}
EgLanguage language = EgLanguage.valueOf(options.getOrDefault(TARGET_LANGUAGE_KEY, "JAVA"));
boolean failOnUnsupported = booleanOption(options.get(FAIL_ON_UNSUPPORTED_KEY), true);
boolean selfTest = booleanOption(options.get(SELF_TEST_KEY), false);
return new Settings(language, new File(targetDirStr), targetDirExistsBehavior, failOnUnsupported, selfTest);
}
示例9: write_withIOException
import javax.annotation.processing.Messager; //导入依赖的package包/类
@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());
}
示例10: BindingManager
import javax.annotation.processing.Messager; //导入依赖的package包/类
/**
* Initialize with the given details from the annotation processing enviornment
*/
public BindingManager(Elements elementUtils, Filer filer, Messager messager, Types typeUtils) {
this.elementUtils = elementUtils;
this.filer = filer;
this.messager = messager;
this.typeUtils = typeUtils;
this.typeBuilderMap = new HashMap<>();
stringTypeMirror = getType("java.lang.String");
listTypeMirror = getType("java.util.List");
mapTypeMirror = getType("java.util.Map");
charSequenceTypeMirror = getType("java.lang.CharSequence");
parcellableTypeMirror = getType("android.os.Parcelable");
try {
parcelClass = Class.forName("org.parceler.Parcel");
} catch (ClassNotFoundException ignored) {
}
}
示例11: provideDescriptorInventory
import javax.annotation.processing.Messager; //导入依赖的package包/类
@Provides @Singleton @Named(DESCRIPTOR_KEY)
static Inventory provideDescriptorInventory(@Named(DESCRIPTOR_KEY) final TypeElement descriptorElement,
final ClassName outputClassName, final Types types, final Elements elements, final Trees trees,
final Messager messager, @Named(TEMPLATE_KEY) Inventory templateInventory,
final ImmutableSet<TypeElement> typesToReceiveAnnotations) {
return new Inventory(descriptorElement, outputClassName, types, elements, trees, messager, true,
templateInventory.rawTypeNameSubstitutions(), typesToReceiveAnnotations);
}
示例12: init
import javax.annotation.processing.Messager; //导入依赖的package包/类
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
final Types typeUtils = processingEnv.getTypeUtils();
final Elements elementUtils = processingEnv.getElementUtils();
final Filer filer = processingEnv.getFiler();
final Messager messager = processingEnv.getMessager();
this.processorUtil = new ProcessorUtil(elementUtils, messager);
this.implementationCreator = new ImplementationCreator(typeUtils, elementUtils, filer, this.processorUtil);
this.simpleDeserializerCreator = new SimpleDeserializerCreator(typeUtils, elementUtils, filer, this.processorUtil);
this.complexDeserializerCreator = new ComplexDeserializerCreator(typeUtils, elementUtils, filer, this.processorUtil);
this.setupCreator = new SetupCreator(filer, this.processorUtil);
}
示例13: getParamTypeMirror
import javax.annotation.processing.Messager; //导入依赖的package包/类
private TypeMirror getParamTypeMirror(VariableElement param, Messager messager) {
TypeMirror typeMirror = param.asType();
// Check for generic type
if (typeMirror instanceof TypeVariable) {
TypeMirror upperBound = ((TypeVariable) typeMirror).getUpperBound();
if (upperBound instanceof DeclaredType) {
if (messager != null) {
messager.printMessage(Diagnostic.Kind.NOTE, "Using upper bound type " + upperBound +
" for generic parameter", param);
}
typeMirror = upperBound;
}
}
return typeMirror;
}
示例14: init
import javax.annotation.processing.Messager; //导入依赖的package包/类
@Before
public void init() {
mMock = Mockito.mock(ProcessingEnvironment.class);
mMessagerMock = Mockito.mock(Messager.class);
Mockito.when(mMock.getMessager()).thenReturn(mMessagerMock);
}
示例15: process
import javax.annotation.processing.Messager; //导入依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
Messager messager = processingEnv.getMessager();
for (Element e : roundEnv.getRootElements()) {
messager.printMessage(WARNING, WRN_NO_SOURCE);
messager.printMessage(WARNING, WRN_WITH_SOURCE, e);
messager.printMessage(WARNING, WRN_NO_SOURCE);
}
return false;
}