List of usage examples for javax.lang.model.util ElementFilter methodsIn
public static Set<ExecutableElement> methodsIn(Set<? extends Element> elements)
From source file:Main.java
public static List<ExecutableElement> getMethods(TypeElement classDecl) { return ElementFilter.methodsIn(classDecl.getEnclosedElements()); }
From source file:info.archinnov.achilles.internals.parser.UDFParser.java
public static List<UDFSignature> parseFunctionRegistryAndValidateTypes(AptUtils aptUtils, TypeElement elm) { final List<ExecutableElement> methods = ElementFilter.methodsIn(elm.getEnclosedElements()); final Optional<String> keyspace = AnnotationTree.findKeyspaceForFunctionRegistry(aptUtils, elm); final TypeName sourceClass = TypeName.get(aptUtils.erasure(elm)); //Not allow to declare function in system keyspaces if (keyspace.isPresent()) { final String keyspaceName = keyspace.get(); aptUtils.validateFalse(//from www. j av a 2 s . c o m FORBIDDEN_KEYSPACES.contains(keyspaceName) || FORBIDDEN_KEYSPACES.contains(keyspaceName.toLowerCase()), "The provided keyspace '%s' on function registry class '%s' is forbidden because it is a system keyspace", keyspaceName, sourceClass); } aptUtils.validateFalse(keyspace.isPresent() && isBlank(keyspace.get()), "The declared keyspace for function registry '%s' should not be blank", elm.getSimpleName().toString()); return methods.stream().map(method -> { final List<TypeName> parametersType = method.getParameters().stream().map(VariableElement::asType) .map(TypeName::get).collect(toList()); final String methodName = method.getSimpleName().toString(); final List<UDFParamSignature> parameterSignatures = method.getParameters().stream() .map(x -> new UDFParamSignature(TypeName.get(x.asType()).box(), x.getSimpleName().toString())) .collect(toList()); //Validate parameter types for (TypeName param : parametersType) { TypeValidator.validateNativeTypesForFunction(aptUtils, method, param, "argument"); } //Validate return type final TypeMirror returnTypeMirror = method.getReturnType(); aptUtils.validateFalse(returnTypeMirror.getKind() == TypeKind.VOID, "The return type for the method '%s' on class '%s' should not be VOID", method.toString(), elm.getSimpleName().toString()); final TypeName returnType = TypeName.get(returnTypeMirror).box(); TypeValidator.validateNativeTypesForFunction(aptUtils, method, returnType, "return type"); // Validate NOT system function comparing only name lowercase aptUtils.validateFalse(SYSTEM_FUNCTIONS_NAME.contains(methodName.toLowerCase()), "The name of the function '%s' in class '%s' is reserved for system functions", method, sourceClass); return new UDFSignature(keyspace, sourceClass, methodName, returnType, parametersType, parameterSignatures); }).collect(toList()); }
From source file:info.archinnov.achilles.internals.parser.FunctionParser.java
public static List<FunctionSignature> parseFunctionRegistryAndValidateTypes(AptUtils aptUtils, TypeElement elm, GlobalParsingContext context) {/*from w w w. j av a2s . c o m*/ final List<ExecutableElement> methods = ElementFilter.methodsIn(elm.getEnclosedElements()); final Optional<String> keyspace = AnnotationTree.findKeyspaceForFunctionRegistry(aptUtils, elm); final FunctionParamParser paramParser = new FunctionParamParser(aptUtils); final TypeName parentType = TypeName.get(aptUtils.erasure(elm)); //Not allow to declare function in system keyspaces if (keyspace.isPresent()) { final String keyspaceName = keyspace.get(); aptUtils.validateFalse( FORBIDDEN_KEYSPACES.contains(keyspaceName) || FORBIDDEN_KEYSPACES.contains(keyspaceName.toLowerCase()), "The provided keyspace '%s' on function registry class '%s' is forbidden because it is a system keyspace", keyspaceName, parentType); } aptUtils.validateFalse(keyspace.isPresent() && isBlank(keyspace.get()), "The declared keyspace for function registry '%s' should not be blank", elm.getSimpleName().toString()); return methods.stream().map(method -> { final String methodName = method.getSimpleName().toString(); final List<AnnotationTree> annotationTrees = AnnotationTree.buildFromMethodForParam(aptUtils, method); final List<? extends VariableElement> parameters = method.getParameters(); final List<FunctionParamSignature> parameterSignatures = new ArrayList<>(parameters.size()); for (int i = 0; i < parameters.size(); i++) { final VariableElement parameter = parameters.get(i); context.nestedTypesStrategy.validate(aptUtils, annotationTrees.get(i), method.toString(), parentType); final FunctionParamSignature functionParamSignature = paramParser.parseParam(context, annotationTrees.get(i), parentType, methodName, parameter.getSimpleName().toString()); parameterSignatures.add(functionParamSignature); } //Validate return type final TypeMirror returnType = method.getReturnType(); aptUtils.validateFalse(returnType.getKind() == TypeKind.VOID, "The return type for the method '%s' on class '%s' should not be VOID", method.toString(), elm.getSimpleName().toString()); aptUtils.validateFalse(returnType.getKind().isPrimitive(), "Due to internal JDK API limitations, UDF/UDA return types cannot be primitive. " + "Use their Object counterpart instead for method '%s' " + "in function registry '%s'", method.toString(), elm.getQualifiedName()); final FunctionParamSignature returnTypeSignature = paramParser.parseParam(context, AnnotationTree.buildFromMethodForReturnType(aptUtils, method), parentType, methodName, "returnType"); // Validate NOT system function comparing only name lowercase aptUtils.validateFalse(SYSTEM_FUNCTIONS_NAME.contains(methodName.toLowerCase()), "The name of the function '%s' in class '%s' is reserved for system functions", method, parentType); return new FunctionSignature(keyspace, parentType, methodName, returnTypeSignature, parameterSignatures); }).collect(toList()); }
From source file:org.mule.devkit.module.generation.MessageSourceGenerator.java
public void generate(Element typeElement) throws GenerationException { List<ExecutableElement> executableElements = ElementFilter.methodsIn(typeElement.getEnclosedElements()); for (ExecutableElement executableElement : executableElements) { Source source = executableElement.getAnnotation(Source.class); if (source == null) continue; generateMessageSource(typeElement, executableElement); }//from ww w . jav a 2 s . co m }
From source file:org.mule.devkit.module.generation.JaxbTransformerGenerator.java
public void generate(Element type) throws GenerationException { List<ExecutableElement> executableElements = ElementFilter.methodsIn(type.getEnclosedElements()); for (ExecutableElement executableElement : executableElements) { Processor processor = executableElement.getAnnotation(Processor.class); if (processor == null) continue; for (VariableElement variable : executableElement.getParameters()) { if (context.getTypeMirrorUtils().isXmlType(variable.asType())) { // get class DefinedClass jaxbTransformerClass = getJaxbTransformerClass(executableElement, variable); // declare weight FieldVariable weighting = jaxbTransformerClass.field(Modifier.PRIVATE, context.getCodeModel().INT, "weighting", Op.plus(ref(DiscoverableTransformer.class).staticRef("DEFAULT_PRIORITY_WEIGHTING"), ExpressionFactory.lit(1))); // load JAXB context Method loadJaxbContext = generateLoadJaxbContext(jaxbTransformerClass); // declare JAXB context FieldVariable jaxbContext = jaxbTransformerClass.field(Modifier.PRIVATE | Modifier.STATIC, JAXBContext.class, "JAXB_CONTEXT", ExpressionFactory.invoke(loadJaxbContext) .arg(ref(variable.asType()).boxify().dotclass())); //generate constructor generateConstructor(jaxbTransformerClass, executableElement, variable); // doTransform generateDoTransform(jaxbTransformerClass, jaxbContext, variable); // set and get weight generateGetPriorityWeighting(jaxbTransformerClass, weighting); generateSetPriorityWeighting(jaxbTransformerClass, weighting); context.registerAtBoot(jaxbTransformerClass); }//from ww w .jav a 2 s. c o m } } }
From source file:org.leandreck.endpoints.processor.model.EndpointNodeFactory.java
private List<MethodNode> defineMethods(final TypeElement typeElement, final DeclaredType containingType) { final TypeMirror superclass = typeElement.getSuperclass(); final List<MethodNode> superclassMethods; if (DECLARED.equals(superclass.getKind()) && !"java.lang.Object".equals(superclass.toString())) { superclassMethods = defineMethods((TypeElement) ((DeclaredType) superclass).asElement(), containingType);// w ww . j a v a 2s. co m } else { superclassMethods = new ArrayList<>(20); } //Implemented Interfaces: typeElement.getInterfaces().stream() .flatMap( it -> defineMethods((TypeElement) ((DeclaredType) it).asElement(), containingType).stream()) .forEach(superclassMethods::add); //Own enclosed Methods ElementFilter.methodsIn(typeElement.getEnclosedElements()).stream() .map(methodElement -> methodNodeFactory.createMethodNode(methodElement, containingType)) .filter(method -> !method.isIgnored()).forEach(superclassMethods::add); return superclassMethods; }
From source file:org.mule.module.extension.internal.capability.xml.schema.AnnotationProcessorUtils.java
static Map<String, ExecutableElement> getMethodsAnnotatedWith(TypeElement typeElement, Class<? extends Annotation> annotation) { return collectAnnotatedElements(ElementFilter.methodsIn(typeElement.getEnclosedElements()), annotation); }
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 w w .ja v a 2s. c om }
From source file:org.mule.devkit.module.generation.MessageProcessorGenerator.java
public void generate(Element typeElement) throws GenerationException { List<ExecutableElement> executableElements = ElementFilter.methodsIn(typeElement.getEnclosedElements()); for (ExecutableElement executableElement : executableElements) { Processor processor = executableElement.getAnnotation(Processor.class); if (processor == null) continue; generateMessageProcessor(typeElement, executableElement, processor.intercepting()); }//from w w w . ja v a 2s .c o m }
From source file:fr.xebia.extras.selma.codegen.FactoryWrapper.java
private int collectFactoryMethods(TypeElement element, boolean ignoreAbstract) { int factoryMethodCount = 0; final List<ExecutableElement> methods = ElementFilter.methodsIn(element.getEnclosedElements()); for (ExecutableElement method : methods) { MethodWrapper methodWrapper = new MethodWrapper(method, (DeclaredType) element.asType(), context); // We should ignore abstract methods if parsing an abstract mapper class if (ignoreAbstract && methodWrapper.isAbstract()) { continue; }//w w w . j a v a 2s .co m if (isValidFactoryMethod(methodWrapper)) { pushFactoryMethod(element, methodWrapper, ignoreAbstract); factoryMethodCount++; } } return factoryMethodCount; }