本文整理汇总了Java中javax.annotation.processing.RoundEnvironment.getElementsAnnotatedWith方法的典型用法代码示例。如果您正苦于以下问题:Java RoundEnvironment.getElementsAnnotatedWith方法的具体用法?Java RoundEnvironment.getElementsAnnotatedWith怎么用?Java RoundEnvironment.getElementsAnnotatedWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.annotation.processing.RoundEnvironment
的用法示例。
在下文中一共展示了RoundEnvironment.getElementsAnnotatedWith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findMethodsWithSpyglassAnnotations
import javax.annotation.processing.RoundEnvironment; //导入方法依赖的package包/类
private Set<ExecutableElement> findMethodsWithSpyglassAnnotations(final RoundEnvironment roundEnvironment) {
final Set<ExecutableElement> methods = new HashSet<>();
for (final Class<? extends Annotation> annoType : SUPPORTED_ANNOTATIONS) {
for (final Element foundElement : roundEnvironment.getElementsAnnotatedWith(annoType)) {
if (foundElement.getKind() == ElementKind.METHOD) {
methods.add((ExecutableElement) foundElement);
} else if (foundElement.getKind() == ElementKind.PARAMETER) {
methods.add((ExecutableElement) foundElement.getEnclosingElement());
} else {
throw new RuntimeException("A Spyglass annotation was somehow applied to an illegal element type.");
}
}
}
return methods;
}
示例2: processRound
import javax.annotation.processing.RoundEnvironment; //导入方法依赖的package包/类
private void processRound(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
loop: for (TypeElement annotation : annotations) {
for (Element element : roundEnv.getElementsAnnotatedWith(annotation)) {
switch (element.getAnnotation(RuntimeExtension.class).value()) {
case FRAMEWORK:
entry = "Fragment-Host: system.bundle; extension:=framework";
break loop;
case BOOTCLASSPATH:
entry = "Fragment-Host: system.bundle; extension:=bootclasspath";
break loop;
}
}
}
try {
generateFile();
} catch (IOException e) {
messager.printMessage(Kind.ERROR, "IOException while generating file with contracts! " + e.getMessage());
e.printStackTrace();
}
}
示例3: process
import javax.annotation.processing.RoundEnvironment; //导入方法依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> set,
RoundEnvironment roundEnvironment) {
Set<? extends Element> elements = roundEnvironment.getElementsAnnotatedWith(Interceptor.class);
if (elements == null || elements.isEmpty()) {
return false;
}
if (moduleName == null || moduleName.length() == 0) {
logger.error("<-- option_module_name is not set for modules -->");
return false;
}
Set<Element> verifyElements = new HashSet<>();
verifyElements(verifyElements, elements);
generateInterceptorTables(moduleName, verifyElements);
return true;
}
示例4: getMethodToFieldNameMap
import javax.annotation.processing.RoundEnvironment; //导入方法依赖的package包/类
private Map<ExecutableElement, String> getMethodToFieldNameMap(RoundEnvironment roundEnvironment) {
final Map<ExecutableElement, String> methodToFieldNameMap = new HashMap<>();
for (Element byElement : roundEnvironment.getElementsAnnotatedWith(By.class)) {
if (byElement.getKind() != ElementKind.FIELD) {
continue;
}
VariableElement byField = (VariableElement) byElement;
for (Element element : typeUtils.asElement(byField.asType()).getEnclosedElements()) {
if (element.getKind() != ElementKind.METHOD) {
continue;
}
ExecutableElement method = (ExecutableElement) element;
methodToFieldNameMap.put(method, byField.getSimpleName().toString());
}
}
return methodToFieldNameMap;
}
示例5: incrementalProcess
import javax.annotation.processing.RoundEnvironment; //导入方法依赖的package包/类
@Override
public boolean incrementalProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (TypeElement annotation : annotations) {
System.out.println("Processing annotation:" + annotation);
}
if (isProcessingDone) {
return false;
}
// generates a class with a constant that contains the name of all classes containing an annotation.
Set<? extends Element> annotatedElements = roundEnv.getElementsAnnotatedWith(Annotation1.class);
Map<String, Set<? extends Element>> mapGeneratedFileNameToOriginatingElements = processElements(annotatedElements);
generateFiles(incrementalProcessingEnvironment.getFiler(), mapGeneratedFileNameToOriginatingElements);
isProcessingDone = true;
return false;
}
示例6: prepareGlobalConfig
import javax.annotation.processing.RoundEnvironment; //导入方法依赖的package包/类
/**
* Prepare global config
*
* @param roundEnv annotation processor environment
*/
private Element prepareGlobalConfig(RoundEnvironment roundEnv) {
Element sqlFirstApcConfigElement = null;
//TODO read with filer for the case of partial compilation
Set<? extends Element> annotatedElements = roundEnv.getElementsAnnotatedWith(SqlFirstApcConfig.class);
for (Element element : annotatedElements) {
if (sqlFirstApcConfigElement == null) {
sqlFirstApcConfigElement = element;
} else {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "SqlFirstApcConfig annotation must be declared only once ", element);
}
}
return sqlFirstApcConfigElement;
}
示例7: process
import javax.annotation.processing.RoundEnvironment; //导入方法依赖的package包/类
/***
*
* Annotation Processing
*
*
* Step1: Find All Annotation Class
* Step2: Check if the Annotation class meets the conditions
* Step3: Generate Java Code
*
* @param set
* @param roundEnvironment
* @return
*/
@Override
public boolean process(Set<? extends TypeElement> set,
RoundEnvironment roundEnvironment) {
if (set == null || set.isEmpty()) {
return false;
}
if (moduleName == null || moduleName.length() == 0) {
logger.error("OPTION ModuleName is not set!!!");
return false;
} else {
//Find All Annotation Class
Set<? extends Element> rootElements = roundEnvironment.getElementsAnnotatedWith(Route.class);
if (rootElements == null || rootElements.isEmpty()) {
logger.error("No Route Annotation class exist!!!");
return false;
}
String validModuleName = moduleName.replace(".", "_")
.replace("-", "_");
return findAnnotationClassWithModuleName(validModuleName, rootElements);
}
}
示例8: process
import javax.annotation.processing.RoundEnvironment; //导入方法依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
writeStaticJavaFiles();
getMigrators(roundEnv);
getDatabaseName(roundEnv);
for (Element element : roundEnv.getElementsAnnotatedWith(Model.class)) {
models.add(element);
generateColumnEnums(element);
generateEntityProxies(element);
generateCursorHelperFiles(element);
generateModelDaoFiles(element);
}
resolveDependencies();
writeJavaFiles();
return true;
}
示例9: processLimitJSON
import javax.annotation.processing.RoundEnvironment; //导入方法依赖的package包/类
private void processLimitJSON(RoundEnvironment roundEnv) {
for (Element element : roundEnv.getElementsAnnotatedWith(LIMITJSON.class)) {
LJSONTypeElement ljsonElement = LJSONTypeElement.create(elements, element);
processorHelper.setLimitJSONTypeElements(ljsonElement);
processorHelper.i("---------------------" + ljsonElement.toString());
//
TypeElement typeElement = (TypeElement) element;
Element a = typeElement.getEnclosingElement();
processorHelper.i("LJSON ++" + a + " " + element.getKind().name());
List<? extends Element> param = typeElement.getEnclosedElements();
for (Element p : param) {
if (p instanceof VariableElement) {
processorHelper.i("LJSON ........" + p.getSimpleName() + " " + p.asType().toString());
}
}
}
}
示例10: handleProcess
import javax.annotation.processing.RoundEnvironment; //导入方法依赖的package包/类
@Override
protected boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) throws LayerGenerationException {
if (roundEnv.processingOver()) {
return false;
}
for (Element e : roundEnv.getElementsAnnotatedWith(ServicesTabNodeRegistration.class)) {
ServicesTabNodeRegistration reg = e.getAnnotation(ServicesTabNodeRegistration.class);
File f = layer(e).
instanceFile("UI/Runtime", null, Node.class).
stringvalue("iconResource", reg.iconResource()).
stringvalue("name", reg.name()).
methodvalue("instanceCreate", "org.openide.nodes.NodeOp", "factory").
bundlevalue("displayName", reg.displayName()).
instanceAttribute("original", Node.class);
if (!"".equals(reg.shortDescription())) {
f.bundlevalue("shortDescription", reg.shortDescription());
}
f.position(reg.position());
f.write();
}
return true;
}
示例11: process
import javax.annotation.processing.RoundEnvironment; //导入方法依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnvironment) {
try {
HashMap<String, BarricadeResponseSet> configs = new HashMap<>();
// Iterate over all @Barricade annotated elements
for (Element annotatedElement : roundEnvironment.getElementsAnnotatedWith(Barricade.class)) {
Barricade barricade = annotatedElement.getAnnotation(Barricade.class);
messager.printMessage(NOTE, "[Barricade] Processing endpoint: " + barricade.endpoint());
List<BarricadeResponse> responses = new ArrayList<>(barricade.responses().length);
int defaultIndex = 0;
for (int i = 0; i < barricade.responses().length; i++) {
Response option = barricade.responses()[i];
responses.add(new BarricadeResponse(option));
if (option.isDefault()) {
defaultIndex = i;
}
}
configs.put(barricade.endpoint(), new BarricadeResponseSet(responses, defaultIndex));
}
// This method is called multiple times, but we want to generate code only once
if (!configs.isEmpty()) {
generateCode(configs);
}
} catch (Exception e) {
messager.printMessage(ERROR, "Couldn't process class:" + e.getMessage());
}
return true;
}
示例12: process
import javax.annotation.processing.RoundEnvironment; //导入方法依赖的package包/类
@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment env) {
final Set<? extends Element> elements = env.getElementsAnnotatedWith(Description.class);
elements.forEach(el -> {
if (!el.getAnnotation(Description.class).useJavaDoc()) {
return;
}
final String docs = elementUtils.getDocComment(el);
final List<String> typeParams = ((ExecutableElement) el).getParameters().stream()
.map(param -> param.asType().toString()).collect(Collectors.toList());
final String name = el.getSimpleName().toString();
final String hash = generateMethodSignatureHash(name, typeParams);
try {
final FileObject file = filer.createResource(StandardLocation.CLASS_OUTPUT,
"allureDescriptions", hash);
try (Writer writer = file.openWriter()) {
writer.write(docs);
}
} catch (IOException e) {
messager.printMessage(Diagnostic.Kind.WARNING,
"Unable to create resource from docs comment of method " + name + typeParams);
}
});
return true;
}
示例13: process
import javax.annotation.processing.RoundEnvironment; //导入方法依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnvironment) {
Filer filer = processingEnv.getFiler();
Messager messager = processingEnv.getMessager();
for (Element element : roundEnvironment.getElementsAnnotatedWith(DataEnum.class)) {
try {
Spec spec = SpecParser.parse(element, processingEnv);
if (spec == null) {
continue;
}
OutputSpec outputSpec = OutputSpecFactory.create(spec);
TypeSpec outputTypeSpec = SpecTypeFactory.create(outputSpec);
JavaFile.Builder javaFileBuilder =
JavaFile.builder(outputSpec.outputClass().packageName(), outputTypeSpec);
if (needsCheckNotNull(spec)) {
javaFileBuilder.addStaticImport(DataenumUtils.class, "checkNotNull");
}
if (needsNullSafeEquals(spec)) {
javaFileBuilder.addStaticImport(DataenumUtils.class, "equal");
}
JavaFile javaFile = javaFileBuilder.build();
javaFile.writeTo(filer);
} catch (IOException | ParserException e) {
messager.printMessage(Diagnostic.Kind.ERROR, e.getMessage());
}
}
return false;
}
示例14: process
import javax.annotation.processing.RoundEnvironment; //导入方法依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment round)
{
for (TypeElement annotation : annotations) {
for (Element element : round.getElementsAnnotatedWith(annotation)) {
if (element instanceof TypeElement) {
log(NOTE, "Extracting Javadoc metadata for " + element);
extract((TypeElement) element);
}
}
}
return false;
}
示例15: checkInjectors
import javax.annotation.processing.RoundEnvironment; //导入方法依赖的package包/类
private void checkInjectors(final RoundEnvironment roundEnv, Class<? extends Annotation> clazz, AnnotationRule annotationRule) {
for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(clazz)) {
annotationRule.checkAnnotation(annotatedElement);
}
String errorStack = annotationRule.getErrorStack();
if (errorStack != null && errorStack.length() > 0) {
getMessager().printMessage(Diagnostic.Kind.ERROR, errorStack);
}
}