public TemplateMethodParser(ProcessorContext context, T template) { this.template = template; this.context = context; this.parser = new MethodSpecParser(template); }
private static List<Parameter> parseParametersOptional(MethodSpec spec, List<? extends VariableElement> types) { List<Parameter> parsedParams = new ArrayList<>(); int typeStartIndex = 0; List<ParameterSpec> specifications = spec.getOptional(); outer: for (int specIndex = 0; specIndex < specifications.size(); specIndex++) { ParameterSpec specification = specifications.get(specIndex); for (int typeIndex = typeStartIndex; typeIndex < types.size(); typeIndex++) { VariableElement variable = types.get(typeIndex); Parameter optionalParam = matchParameter(specification, variable, -1, -1); if (optionalParam != null) { parsedParams.add(optionalParam); typeStartIndex = typeIndex + 1; continue outer; } } } if (typeStartIndex < types.size()) { // not enough types found return null; } return parsedParams; }
public TemplateMethod parse(MethodSpec methodSpecification, ExecutableElement method, AnnotationMirror annotation, int naturalOrder) { if (methodSpecification == null) { return null; } methodSpecification.applyTypeDefinitions("types"); String id = method.getSimpleName().toString(); TypeMirror returnType = method.getReturnType(); return parseImpl(methodSpecification, naturalOrder, id, method, annotation, returnType, method.getParameters()); }
public TemplateMethod parseImpl(MethodSpec methodSpecification, int naturalOrder, String id, ExecutableElement method, AnnotationMirror annotation, TypeMirror returnType, List<? extends VariableElement> parameterTypes) { ParameterSpec returnTypeSpec = methodSpecification.getReturnType(); Parameter returnTypeMirror = matchParameter(returnTypeSpec, new CodeVariableElement(returnType, "returnType"), -1, -1); if (returnTypeMirror == null) { if (isEmitErrors() && method != null) { TemplateMethod invalidMethod = new TemplateMethod(id, naturalOrder, template, methodSpecification, method, annotation, returnTypeMirror, Collections.<Parameter> emptyList()); String expectedReturnType = returnTypeSpec.toSignatureString(true); List<Parameter> parameters = parseParameters(methodSpecification, parameterTypes, isUseVarArgs() && method != null ? method.isVarArgs() : false); if (parameters == null) { if (isEmitErrors() && method != null) { TemplateMethod invalidMethod = new TemplateMethod(id, naturalOrder, template, methodSpecification, method, annotation, returnTypeMirror, Collections.<Parameter> emptyList()); String message = String.format("Method signature %s does not match to the expected signature: \n%s", createActualSignature(method), methodSpecification.toSignatureString(method.getSimpleName().toString())); invalidMethod.addError(message);
while ((specification = nextSpecification(specifications, specificationIndex, specVarArgs)) != null) { VariableElement actualType = nextActualType(types, typeIndex, typeVarArgs); if (actualType == null) { if (spec.isIgnoreAdditionalSpecifications()) { Parameter resolvedParameter = matchParameter(specification, actualType, specVarArgsIndex, typeVarArgsIndex); if (resolvedParameter == null) { return null; while ((variable = nextActualType(types, typeIndex, typeVarArgs)) != null) { Parameter matchedParamter = matchAnnotatedParameter(spec, variable); if (matchedParamter == null) { break;
private E parse(int naturalOrder, ExecutableElement method, AnnotationMirror annotation) { MethodSpec methodSpecification = createSpecification(method, annotation); if (methodSpecification == null) { return null; } TemplateMethod templateMethod = parser.parse(methodSpecification, method, annotation, naturalOrder); if (templateMethod != null) { return create(templateMethod, templateMethod.hasErrors()); } return null; }
if (method.getModifiers().contains(Modifier.PRIVATE) && parser.isEmitErrors()) { parsedMethod.addError("Method annotated with @%s must not be private.", getAnnotationType().getSimpleName()); parsedMethods.add(parsedMethod);
public TemplateMethod parseImpl(MethodSpec methodSpecification, int naturalOrder, String id, ExecutableElement method, AnnotationMirror annotation, TypeMirror returnType, List<? extends VariableElement> parameterTypes) { ParameterSpec returnTypeSpec = methodSpecification.getReturnType(); Parameter returnTypeMirror = matchParameter(returnTypeSpec, new CodeVariableElement(returnType, "returnType"), -1, -1); if (returnTypeMirror == null) { if (isEmitErrors() && method != null) { TemplateMethod invalidMethod = new TemplateMethod(id, naturalOrder, template, methodSpecification, method, annotation, returnTypeMirror, Collections.<Parameter> emptyList()); String expectedReturnType = returnTypeSpec.toSignatureString(true); List<Parameter> parameters = parseParameters(methodSpecification, parameterTypes, isUseVarArgs() && method != null ? method.isVarArgs() : false); if (parameters == null) { if (isEmitErrors() && method != null) { TemplateMethod invalidMethod = new TemplateMethod(id, naturalOrder, template, methodSpecification, method, annotation, returnTypeMirror, Collections.<Parameter> emptyList()); String message = String.format("Method signature %s does not match to the expected signature: \n%s", createActualSignature(method), methodSpecification.toSignatureString(method.getSimpleName().toString())); invalidMethod.addError(message);
while ((specification = nextSpecification(specifications, specificationIndex, specVarArgs)) != null) { VariableElement actualType = nextActualType(types, typeIndex, typeVarArgs); if (actualType == null) { if (spec.isIgnoreAdditionalSpecifications()) { Parameter resolvedParameter = matchParameter(specification, actualType, specVarArgsIndex, typeVarArgsIndex); if (resolvedParameter == null) { return null; while ((variable = nextActualType(types, typeIndex, typeVarArgs)) != null) { Parameter matchedParamter = matchAnnotatedParameter(spec, variable); if (matchedParamter == null) { break;
private E parse(int naturalOrder, ExecutableElement method, AnnotationMirror annotation) { MethodSpec methodSpecification = createSpecification(method, annotation); if (methodSpecification == null) { return null; } TemplateMethod templateMethod = parser.parse(methodSpecification, method, annotation, naturalOrder); if (templateMethod != null) { return create(templateMethod, templateMethod.hasErrors()); } return null; }
if (method.getModifiers().contains(Modifier.PRIVATE) && parser.isEmitErrors()) { parsedMethod.addError("Method annotated with @%s must not be private.", getAnnotationType().getSimpleName()); parsedMethods.add(parsedMethod);
public TemplateMethod parse(MethodSpec methodSpecification, ExecutableElement method, AnnotationMirror annotation, int naturalOrder) { if (methodSpecification == null) { return null; } methodSpecification.applyTypeDefinitions("types"); String id = method.getSimpleName().toString(); TypeMirror returnType = method.getReturnType(); return parseImpl(methodSpecification, naturalOrder, id, method, annotation, returnType, method.getParameters()); }
private static List<Parameter> parseParametersOptional(MethodSpec spec, List<? extends VariableElement> types) { List<Parameter> parsedParams = new ArrayList<>(); int typeStartIndex = 0; List<ParameterSpec> specifications = spec.getOptional(); outer: for (int specIndex = 0; specIndex < specifications.size(); specIndex++) { ParameterSpec specification = specifications.get(specIndex); for (int typeIndex = typeStartIndex; typeIndex < types.size(); typeIndex++) { VariableElement variable = types.get(typeIndex); Parameter optionalParam = matchParameter(specification, variable, -1, -1); if (optionalParam != null) { parsedParams.add(optionalParam); typeStartIndex = typeIndex + 1; continue outer; } } } if (typeStartIndex < types.size()) { // not enough types found return null; } return parsedParams; }
public TemplateMethodParser(ProcessorContext context, T template) { this.template = template; this.context = context; this.parser = new MethodSpecParser(template); }
public final E create(String id, int naturalOrder, ExecutableElement methodMetadata, AnnotationMirror mirror, TypeMirror returnType, List<VariableElement> parameterTypes) { TemplateMethod method = parser.parseImpl(createSpecification(methodMetadata, mirror), naturalOrder, id, methodMetadata, mirror, returnType, parameterTypes); if (method != null) { return create(method, method.hasErrors()); } return null; } }
private static Parameter matchAnnotatedParameter(MethodSpec spec, VariableElement variable) { for (ParameterSpec parameterSpec : spec.getAnnotations()) { if (parameterSpec.matches(variable)) { Parameter matchedParameter = matchParameter(parameterSpec, variable, -1, -1); if (matchedParameter != null) { matchedParameter.setLocalName(variable.getSimpleName().toString()); return matchedParameter; } } } return null; }
public final E create(String id, int naturalOrder, ExecutableElement methodMetadata, AnnotationMirror mirror, TypeMirror returnType, List<VariableElement> parameterTypes) { TemplateMethod method = parser.parseImpl(createSpecification(methodMetadata, mirror), naturalOrder, id, methodMetadata, mirror, returnType, parameterTypes); if (method != null) { return create(method, method.hasErrors()); } return null; } }
private static Parameter matchAnnotatedParameter(MethodSpec spec, VariableElement variable) { for (ParameterSpec parameterSpec : spec.getAnnotations()) { if (parameterSpec.matches(variable)) { Parameter matchedParameter = matchParameter(parameterSpec, variable, -1, -1); if (matchedParameter != null) { matchedParameter.setLocalName(variable.getSimpleName().toString()); return matchedParameter; } } } return null; }