public AnalysisResult analysis(AnalysisResult result) {
        // 1. Set sub package name by source.metrics
        Class<? extends Metrics> metricsClass = MetricsHolder.find(result.getAggregationFuncStmt().getAggregationFunctionName());
        String metricsClassSimpleName = metricsClass.getSimpleName();

        result.setMetricsClassName(metricsClassSimpleName);

        // Optional for filter
        List<ConditionExpression> expressions = result.getFilters().getFilterExpressionsParserResult();
        if (expressions != null && expressions.size() > 0) {
            for (ConditionExpression expression : expressions) {
                final FilterMatchers.MatcherInfo matcherInfo = FilterMatchers.INSTANCE.find(
                    expression.getExpressionType());

                final String getter = matcherInfo.isBooleanType()
                    ? ClassMethodUtil.toIsMethod(expression.getAttributes())
                    : ClassMethodUtil.toGetMethod(expression.getAttributes());

                final Expression filterExpression = new Expression();
                filterExpression.setExpressionObject(matcherInfo.getMatcher().getName());
                filterExpression.setLeft(TypeCastUtil.withCast(expression.getCastType(), "source." + getter));
                filterExpression.setRight(expression.getValue());
                result.getFilters().addFilterExpressions(filterExpression);
            }
        }

        // 3. Find Entrance method of this metrics
        Class<?> c = metricsClass;
        Method entranceMethod = null;
        SearchEntrance:
        while (!c.equals(Object.class)) {
            for (Method method : c.getMethods()) {
                Entrance annotation = method.getAnnotation(Entrance.class);
                if (annotation != null) {
                    entranceMethod = method;
                    break SearchEntrance;
                }
            }
            c = c.getSuperclass();
        }
        if (entranceMethod == null) {
            throw new IllegalArgumentException("Can't find Entrance method in class: " + metricsClass.getName());
        }
        EntryMethod entryMethod = new EntryMethod();
        result.setEntryMethod(entryMethod);
        entryMethod.setMethodName(entranceMethod.getName());

        // 4. Use parameter's annotation of entrance method to generate aggregation entrance.
        for (Parameter parameter : entranceMethod.getParameters()) {
            Class<?> parameterType = parameter.getType();
            Annotation[] parameterAnnotations = parameter.getAnnotations();
            if (parameterAnnotations == null || parameterAnnotations.length == 0) {
                throw new IllegalArgumentException(
                    "Entrance method:" + entranceMethod + " doesn't include the annotation.");
            }
            Annotation annotation = parameterAnnotations[0];
            if (annotation instanceof SourceFrom) {
                entryMethod.addArg(
                    parameterType,
                    TypeCastUtil.withCast(
                        result.getFrom().getSourceCastType(),
                        "source." + ClassMethodUtil.toGetMethod(result.getFrom().getSourceAttribute())
                    )
                );
            } else if (annotation instanceof ConstOne) {
                entryMethod.addArg(parameterType, "1");
            } else if (annotation instanceof org.apache.skywalking.oap.server.core.analysis.metrics.annotation.Expression) {
                if (isNull(result.getAggregationFuncStmt().getFuncConditionExpressions())
                    || result.getAggregationFuncStmt().getFuncConditionExpressions().isEmpty()) {
                    throw new IllegalArgumentException(
                        "Entrance method:" + entranceMethod + " argument can't find funcParamExpression.");
                } else {
                    ConditionExpression expression = result.getAggregationFuncStmt().getNextFuncConditionExpression();
                    final FilterMatchers.MatcherInfo matcherInfo = FilterMatchers.INSTANCE.find(
                        expression.getExpressionType());

                    final String getter = matcherInfo.isBooleanType()
                        ? ClassMethodUtil.toIsMethod(expression.getAttributes())
                        : ClassMethodUtil.toGetMethod(expression.getAttributes());

                    final Expression argExpression = new Expression();
                    argExpression.setRight(expression.getValue());
                    argExpression.setExpressionObject(matcherInfo.getMatcher().getName());
                    argExpression.setLeft(TypeCastUtil.withCast(expression.getCastType(), "source." + getter));

                    entryMethod.addArg(argExpression);
                }
            } else if (annotation instanceof Arg) {
                entryMethod.addArg(parameterType, result.getAggregationFuncStmt().getNextFuncArg());
            } else {
                throw new IllegalArgumentException(
                    "Entrance method:" + entranceMethod + " doesn't the expected annotation.");
            }
        }

        // 5. Get all column declared in MetricsHolder class.
        c = metricsClass;
        while (!c.equals(Object.class)) {
            for (Field field : c.getDeclaredFields()) {
                Column column = field.getAnnotation(Column.class);
                if (column != null) {
                    result.addPersistentField(
                        field.getName(),
                        column.name(),
                        field.getType());
                }
            }
            c = c.getSuperclass();
        }

        // 6. Based on Source, generate default columns
        List<SourceColumn> columns = SourceColumnsFactory.getColumns(result.getFrom().getSourceName());
        result.setFieldsFromSource(columns);

        result.generateSerializeFields();

        return result;
    }
@Test
    public void shouldUseCorrectMatcher() {

        AnalysisResult result = new AnalysisResult();
        result.getFrom().setSourceName("Endpoint");
        result.getFrom().getSourceAttribute().add("latency");
        result.setMetricsName("EndpointAvg");
        result.getAggregationFuncStmt().setAggregationFunctionName("longAvg");

        DeepAnalysis analysis = new DeepAnalysis();

        result.getFilters().setFilterExpressions(null);
        result.getFilters().setFilterExpressionsParserResult(null);
        result.getFilters().addFilterExpressionsParserResult(new ConditionExpression("booleanMatch", "valid", ""));
        result = analysis.analysis(result);
        assertTrue(result.getFilters().getFilterExpressions().size() > 0);
        assertEquals(BooleanMatch.class.getName(), result.getFilters().getFilterExpressions().get(0).getExpressionObject());
        assertEquals("source.isValid()", result.getFilters().getFilterExpressions().get(0).getLeft());

        result.getFilters().setFilterExpressions(null);
        result.getFilters().setFilterExpressionsParserResult(null);
        result.getFilters().addFilterExpressionsParserResult(new ConditionExpression("stringMatch", "type", ""));
        result = analysis.analysis(result);
        assertTrue(result.getFilters().getFilterExpressions().size() > 0);
        assertEquals(StringMatch.class.getName(), result.getFilters().getFilterExpressions().get(0).getExpressionObject());
        assertEquals("source.getType()", result.getFilters().getFilterExpressions().get(0).getLeft());

        result.getFilters().setFilterExpressions(null);
        result.getFilters().setFilterExpressionsParserResult(null);
        result.getFilters().addFilterExpressionsParserResult(new ConditionExpression("notEqualMatch", "type", ""));
        result = analysis.analysis(result);
        assertTrue(result.getFilters().getFilterExpressions().size() > 0);
        assertEquals(NotEqualMatch.class.getName(), result.getFilters().getFilterExpressions().get(0).getExpressionObject());
        assertEquals("source.getType()", result.getFilters().getFilterExpressions().get(0).getLeft());

        result.getFilters().setFilterExpressions(null);
        result.getFilters().setFilterExpressionsParserResult(null);
        result.getFilters().addFilterExpressionsParserResult(new ConditionExpression("booleanNotEqualMatch", "type", ""));
        result = analysis.analysis(result);
        assertTrue(result.getFilters().getFilterExpressions().size() > 0);
        assertEquals(BooleanNotEqualMatch.class.getName(), result.getFilters().getFilterExpressions().get(0).getExpressionObject());
        assertEquals("source.isType()", result.getFilters().getFilterExpressions().get(0).getLeft());
    }