List of usage examples for javax.lang.model.util ElementFilter typesIn
public static Set<TypeElement> typesIn(Set<? extends Element> elements)
From source file:org.mule.module.extension.internal.capability.xml.schema.AnnotationProcessorUtils.java
/** * Returns the {@link TypeElement}s in the * {@code roundEnvironment} which are annotated * with {@code annotationType}//from w w w . j a v a 2s . com * * @param annotationType the type of the {@link Annotation} * @param roundEnvironment the current {@link RoundEnvironment} * @return a {@link Set} with the {@link TypeElement}s annotated with {@code annotationType} */ public static Set<TypeElement> getTypeElementsAnnotatedWith(Class<? extends Annotation> annotationType, RoundEnvironment roundEnvironment) { return ElementFilter.typesIn(roundEnvironment.getElementsAnnotatedWith(annotationType)); }
From source file:com.thoratou.exact.processors.ExactProcessor.java
private void readAnnotations(RoundEnvironment roundEnv, HashMap<String, ArrayList<Item>> itemMap, HashMap<String, ArrayList<ExtensionItem>> extItemMap) throws Exception { //retrieve all classes with @ExactNode annotation for (TypeElement typeElement : ElementFilter.typesIn(roundEnv.getElementsAnnotatedWith(ExactNode.class))) { Name qualifiedName = typeElement.getQualifiedName(); String className = qualifiedName.toString(); logger.info("Exact class : " + className); classMap.put(className, typeElement); for (ExecutableElement methodElement : ElementFilter.methodsIn(typeElement.getEnclosedElements())) { {//from w w w .j a v a2 s. c om ExactPath annotation = methodElement.getAnnotation(ExactPath.class); if (annotation != null) { String methodName = methodElement.getSimpleName().toString(); String returnType = methodElement.getReturnType().toString(); String xPathString = annotation.value(); logger.info( "Exact method : " + methodName + " , " + annotation.value() + " , " + returnType); XPathParser parser = new XPathParser(xPathString); XPathPathExpr xPathPathExpr = parser.parse(); logger.info("XPath value = " + xPathPathExpr.toString()); Item item = new Item(); item.setxPathPathExpr(xPathPathExpr); item.setMethodName(methodName); item.setReturnType(returnType); if (itemMap.containsKey(className)) { ArrayList<Item> items = itemMap.get(className); items.add(item); } else { ArrayList<Item> items = new ArrayList<Item>(); items.add(item); itemMap.put(className, items); } methodMap.put(new Pair<String, String>(className, methodName), methodElement); } } { ExactExtension annotation = methodElement.getAnnotation(ExactExtension.class); if (annotation != null) { String methodName = methodElement.getSimpleName().toString(); String returnType = methodElement.getReturnType().toString(); String name = annotation.name(); String element = annotation.element(); String filter = annotation.filter(); logger.info("Exact extension : " + methodName + " , " + returnType + " , " + name + " , " + element + " , " + filter); XPathParser elementParser = new XPathParser(element); XPathPathExpr elementXPathPathExpr = elementParser.parse(); logger.info("XPath element = " + elementXPathPathExpr.toString()); XPathParser filterParser = new XPathParser(filter); XPathPathExpr filterXPathPathExpr = filterParser.parse(); logger.info("XPath filter = " + filterXPathPathExpr.toString()); ExtensionItem item = new ExtensionItem(); item.setName(name); item.setElement(elementXPathPathExpr); item.setFilter(filterXPathPathExpr); item.setMethodName(methodName); item.setReturnType(returnType); if (extItemMap.containsKey(className)) { ArrayList<ExtensionItem> items = extItemMap.get(className); items.add(item); } else { ArrayList<ExtensionItem> items = new ArrayList<ExtensionItem>(); items.add(item); extItemMap.put(className, items); } } } } } }
From source file:auto.parse.processor.AutoParseProcessor.java
private void process(RoundEnvironment roundEnv) { Collection<? extends Element> annotatedElements = roundEnv.getElementsAnnotatedWith(AutoParse.class); Collection<? extends TypeElement> types = ElementFilter.typesIn(annotatedElements); for (TypeElement type : types) { try {// w w w.j a va 2s . c o m processType(type); } catch (CompileException e) { // We abandoned this type, but continue with the next. } catch (RuntimeException e) { // Don't propagate this exception, which will confusingly crash the compiler. reportError("@AutoParse processor threw an exception: " + e, type); } } }
From source file:org.mule.devkit.utils.NameUtils.java
public String generateClassName(ExecutableElement executableElement, String append) { TypeElement parentClass = ElementFilter.typesIn(Arrays.asList(executableElement.getEnclosingElement())) .get(0);// ww w . j ava 2 s .c om String packageName = getPackageName(getBinaryName(parentClass)); String className = StringUtils.capitalize(executableElement.getSimpleName().toString()) + append; return packageName + "." + className; }
From source file:org.mule.devkit.utils.NameUtils.java
public String generateClassName(ExecutableElement executableElement, String extraPackage, String append) { TypeElement parentClass = ElementFilter.typesIn(Arrays.asList(executableElement.getEnclosingElement())) .get(0);//w w w . j a v a 2 s .c om String packageName = getPackageName(elements.getBinaryName(parentClass).toString()); String className = StringUtils.capitalize(executableElement.getSimpleName().toString()) + append; return packageName + extraPackage + "." + className; }
From source file:org.mule.devkit.utils.NameUtils.java
public String generateClassNameInPackage(Element element, String className) { Element enclosingElement = element.getEnclosingElement(); String packageName;//www . j a va 2 s. co m if (enclosingElement.getKind() == ElementKind.CLASS) { packageName = getPackageName(getBinaryName((TypeElement) enclosingElement)); } else if (enclosingElement.getEnclosingElement() != null) { TypeElement parentClass = ElementFilter.typesIn(Arrays.asList(enclosingElement.getEnclosingElement())) .get(0); packageName = getPackageName(getBinaryName(parentClass)); } else { // inner enum or parametrized type DeclaredType declaredType = (DeclaredType) element.asType(); packageName = getPackageName(declaredType.toString()); } return packageName + "." + className; }
From source file:org.mule.devkit.module.generation.JaxbTransformerGenerator.java
private DefinedClass getJaxbTransformerClass(ExecutableElement executableElement, VariableElement variable) { DeclaredType declaredType = (DeclaredType) variable.asType(); XmlType xmlType = declaredType.asElement().getAnnotation(XmlType.class); TypeElement parentClass = ElementFilter.typesIn(Arrays.asList(executableElement.getEnclosingElement())) .get(0);//from w ww. j av a 2s . co m String packageName = context.getNameUtils() .getPackageName(context.getElementsUtils().getBinaryName(parentClass).toString()) + ".config"; Package pkg = context.getCodeModel()._package(packageName); DefinedClass jaxbTransformer = pkg._class(StringUtils.capitalize(xmlType.name()) + "JaxbTransformer", AbstractTransformer.class, new Class<?>[] { DiscoverableTransformer.class }); return jaxbTransformer; }