List of usage examples for javax.lang.model.element Element getEnclosedElements
List<? extends Element> getEnclosedElements();
From source file:cop.raml.utils.example.JsonExample.java
/** * Returns string representation of the given {@code element} when this is enum (i.e. {@link TypeElement#getKind()} == {@link ElementKind#ENUM}). * If enum contains at least one constant, then method returns {@link Object#toString()} for first enum constant. If enum doesn't contain any * constant, then method return name for enum itself. * * @param type not {@code null} enum element type * @return not {@code null} enum element string representation *///from w w w.j a v a 2 s. c o m @NotNull private static String getEnumExample(@NotNull TypeMirror type) { if (!ElementUtils.isEnum(type)) return null; try { Element element = ElementUtils.asElement(type); for (Element parent : element.getEnclosedElements()) if (parent.getKind() == ElementKind.ENUM_CONSTANT) return parent.getSimpleName().toString(); return element.getSimpleName().toString(); } catch (Exception ignored) { return null; } }
From source file:adalid.util.meta.MetaJavaCompiler.java
private static void scanAnalyzedElements(Iterable<? extends Element> elements, String tabs) { for (Element element : elements) { logger.info(tabs + "element" + CL + element.getKind() + SP + element.getSimpleName() + LP + element.getClass() + RP + element); logger.info(tabs + "enclosing element" + CL + element.getEnclosingElement()); if (element instanceof ClassSymbol) { ClassSymbol classSymbol = (ClassSymbol) element; }/*from w ww. java 2 s . c om*/ if (element instanceof MethodSymbol) { MethodSymbol methodSymbol = (MethodSymbol) element; logger.info(tabs + "method symbol" + CL + methodSymbol.getReturnType() + SP + methodSymbol.getSimpleName() + LP + StringUtils.join(methodSymbol.getParameters(), CM) + RP + StringUtils.join(methodSymbol.getThrownTypes(), CM)); } if (element instanceof VarSymbol) { VarSymbol varSymbol = (VarSymbol) element; } List<? extends Element> enclosedElements = element.getEnclosedElements(); if (enclosedElements != null && !enclosedElements.isEmpty()) { logger.info(tabs + "enclosed elements" + CL + StringUtils.join(enclosedElements, CM)); scanAnalyzedElements(enclosedElements, tabs + "\t"); } logger.info(""); } }
From source file:org.mule.devkit.module.generation.NamespaceHandlerGenerator.java
private void registerBeanDefinitionParserForEachProcessor(Element type, Method init) { List<ExecutableElement> executableElements = ElementFilter.methodsIn(type.getEnclosedElements()); for (ExecutableElement executableElement : executableElements) { Processor processor = executableElement.getAnnotation(Processor.class); if (processor == null) continue; registerBeanDefinitionParserForProcessor(init, executableElement); }//from w ww. jav a 2 s . c om }
From source file:org.mule.devkit.module.generation.NamespaceHandlerGenerator.java
private void registerBeanDefinitionParserForEachSource(Element type, Method init) { List<ExecutableElement> executableElements = ElementFilter.methodsIn(type.getEnclosedElements()); for (ExecutableElement executableElement : executableElements) { Source source = executableElement.getAnnotation(Source.class); if (source == null) continue; registerBeanDefinitionParserForSource(init, executableElement); }/*from w w w.ja va 2 s. c o m*/ }
From source file:org.mule.devkit.module.generation.NamespaceHandlerGenerator.java
private void registerBeanDefinitionParserForEachTransformer(Element type, Method init) { List<ExecutableElement> executableElements = ElementFilter.methodsIn(type.getEnclosedElements()); for (ExecutableElement executableElement : executableElements) { Transformer transformer = executableElement.getAnnotation(Transformer.class); if (transformer == null) continue; Invocation registerMuleBeanDefinitionParser = init.body().invoke("registerBeanDefinitionParser"); registerMuleBeanDefinitionParser.arg(ExpressionFactory .lit(context.getNameUtils().uncamel(executableElement.getSimpleName().toString()))); String transformerClassName = context.getNameUtils().generateClassName(executableElement, "Transformer"); transformerClassName = context.getNameUtils().getPackageName(transformerClassName) + ".config." + context.getNameUtils().getClassName(transformerClassName); registerMuleBeanDefinitionParser.arg(ExpressionFactory._new(ref(MessageProcessorDefinitionParser.class)) .arg(ref(transformerClassName).boxify().dotclass())); }/* w w w . j a v a 2 s.c o m*/ }
From source file:cop.raml.utils.ImportScanner.java
public Element getElement(@NotNull TagLink link) { Element classElement = link != TagLink.NULL ? getElement(link.getClassName()) : null; if (classElement == null || link.getParam() == null) return classElement; for (Element paramElement : classElement.getEnclosedElements()) if (link.getParam().equals(paramElement.getSimpleName().toString())) return paramElement; return null;//from ww w. j a va 2 s . c o m }
From source file:com.github.pellaton.springconfigvalidation.SpringConfigurationValidationProcessor.java
private void processElement(Element element) { for (AnnotationMirror annotation : element.getAnnotationMirrors()) { Element annotationTypeElement = annotation.getAnnotationType().asElement(); if (annotationTypeElement.equals(this.configurationTypeElement)) { List<? extends Element> enclosedElements = element.getEnclosedElements(); processClass(element, ElementFilter.constructorsIn(enclosedElements)); } else if (annotationTypeElement.equals(this.beanTypeElement)) { processBeanMethod((ExecutableElement) element); }/*w w w. j a v a2 s.c o m*/ } }
From source file:cop.raml.processor.RestProcessor.java
/** * Retrieves all actual methods from the given {@code classElement} and starts each method sequential processing. * * @param api rest api holder where all results will be stored * @param classElement current class// ww w .j a v a 2 s . c o m */ private void proceedClass(@NotNull RestApi api, @NotNull Element classElement) { Class<? extends Annotation> annotation = restImpl.getRequestMapping(); for (Element methodElement : classElement.getEnclosedElements()) { if (!(methodElement instanceof ExecutableElement)) continue; if (methodElement.getAnnotation(annotation) == null) continue; if (filterRegex != null && !filterRegex.matcher(methodElement.getEnclosingElement().toString()).matches()) continue; ThreadLocalContext.setClassName(((QualifiedNameable) classElement).getQualifiedName().toString()); ThreadLocalContext.setMethodName(methodElement.getSimpleName().toString()); ThreadLocalContext.getImportScanner().setCurrentElement(methodElement); processMethodWithCatchException(api, (ExecutableElement) methodElement); } }
From source file:com.dspot.declex.action.Actions.java
private void createInformationForMethods(Element typeElement, ActionInfo actionInfo, List<String> methodsHandled) { if (methodsHandled == null) { methodsHandled = new LinkedList<>(); }// w w w .j a va 2s. com for (Element elem : typeElement.getEnclosedElements()) { if (elem.getKind() == ElementKind.METHOD) { if (methodsHandled.contains(elem.toString())) continue; final ExecutableElement element = (ExecutableElement) elem; List<ActionMethodParam> params = new LinkedList<>(); for (VariableElement param : element.getParameters()) { List<Annotation> annotations = new LinkedList<>(); for (Class<? extends Annotation> annotation : ACTION_ANNOTATION) { Annotation containedAnnotation = param.getAnnotation(annotation); if (containedAnnotation != null) { annotations.add(containedAnnotation); } } final AbstractJClass paramType = codeModelHelper.elementTypeToJClass(param); ActionMethodParam actionMethodParam = new ActionMethodParam(param.getSimpleName().toString(), paramType, annotations); params.add(actionMethodParam); } List<Annotation> annotations = new LinkedList<>(); for (Class<? extends Annotation> annotation : ACTION_ANNOTATION) { Annotation containedAnnotation = element.getAnnotation(annotation); if (containedAnnotation != null) { annotations.add(containedAnnotation); } } String javaDoc = env.getProcessingEnvironment().getElementUtils().getDocComment(element); final String clazz = element.getReturnType().toString(); actionInfo.addMethod(element.getSimpleName().toString(), clazz, javaDoc, params, annotations); methodsHandled.add(element.toString()); } } List<? extends TypeMirror> superTypes = env.getProcessingEnvironment().getTypeUtils() .directSupertypes(typeElement.asType()); for (TypeMirror type : superTypes) { TypeElement superElement = env.getProcessingEnvironment().getElementUtils() .getTypeElement(type.toString()); if (superElement == null) continue; if (superElement.getKind().equals(ElementKind.INTERFACE)) continue; if (superElement.asType().toString().equals(Object.class.getCanonicalName())) continue; createInformationForMethods(superElement, actionInfo, methodsHandled); } }
From source file:com.github.alexfalappa.nbspringboot.navigator.MappedElementExtractor.java
@Override public List visitClass(final ClassTree node, final Void p) { final List<MappedElement> mappedElements = new ArrayList<>(); if (canceled || node == null) { return mappedElements; }/* w w w . j a va 2 s. c o m*/ final Element clazz = trees.getElement(new TreePath(rootPath, node)); if (clazz == null || (clazz.getAnnotation(Controller.class) == null && clazz.getAnnotation(RestController.class) == null)) { return mappedElements; } final RequestMapping parentRequestMapping = clazz.getAnnotation(RequestMapping.class); final Map<String, List<RequestMethod>> parentUrls = extractTypeLevelMappings(parentRequestMapping); for (Element enclosedElement : clazz.getEnclosedElements()) { if (enclosedElement.getKind() != ElementKind.METHOD) { continue; } final Map<String, List<RequestMethod>> elementUrls = new TreeMap<>(); final RequestMapping requestMapping = enclosedElement.getAnnotation(RequestMapping.class); if (requestMapping != null) { extractMethodLevelMappings(elementUrls, concatValues(requestMapping.value(), requestMapping.path()), requestMapping.method()); } final DeleteMapping deleteMapping = enclosedElement.getAnnotation(DeleteMapping.class); if (deleteMapping != null) { extractMethodLevelMappings(elementUrls, concatValues(deleteMapping.value(), deleteMapping.path()), new RequestMethod[] { RequestMethod.DELETE }); } final GetMapping getMapping = enclosedElement.getAnnotation(GetMapping.class); if (getMapping != null) { extractMethodLevelMappings(elementUrls, concatValues(getMapping.value(), getMapping.path()), new RequestMethod[] { RequestMethod.GET }); } final PatchMapping patchMapping = enclosedElement.getAnnotation(PatchMapping.class); if (patchMapping != null) { extractMethodLevelMappings(elementUrls, concatValues(patchMapping.value(), patchMapping.path()), new RequestMethod[] { RequestMethod.PATCH }); } final PostMapping postMapping = enclosedElement.getAnnotation(PostMapping.class); if (postMapping != null) { extractMethodLevelMappings(elementUrls, concatValues(postMapping.value(), postMapping.path()), new RequestMethod[] { RequestMethod.POST }); } final PutMapping putMapping = enclosedElement.getAnnotation(PutMapping.class); if (putMapping != null) { extractMethodLevelMappings(elementUrls, concatValues(putMapping.value(), putMapping.path()), new RequestMethod[] { RequestMethod.PUT }); } for (Map.Entry<String, List<RequestMethod>> methodLevelMapping : elementUrls.entrySet()) { for (Map.Entry<String, List<RequestMethod>> typeLevelMapping : parentUrls.entrySet()) { final String url = pathMatcher.combine(typeLevelMapping.getKey(), methodLevelMapping.getKey()); final List<RequestMethod> effectiveMethods = new ArrayList<>(); if (methodLevelMapping.getValue().isEmpty()) { effectiveMethods.add(null); } effectiveMethods.addAll(methodLevelMapping.getValue()); if (!typeLevelMapping.getValue().isEmpty()) { effectiveMethods.retainAll(typeLevelMapping.getValue()); } for (RequestMethod effectiveMethod : effectiveMethods) { mappedElements .add(new MappedElement(this.fileObject, enclosedElement, url, effectiveMethod)); } } } } return mappedElements; }