ArgListExpr.java revision d3f2b9229472c9dae9bf4ae8b3e2d653b5653b01
1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.databinding.tool.expr;
18
19import android.databinding.tool.reflection.ModelAnalyzer;
20import android.databinding.tool.reflection.ModelClass;
21import android.databinding.tool.writer.KCode;
22
23import java.util.List;
24
25/**
26 * This is a special expression that is created when we have an adapter that has multiple
27 * parameters.
28 * <p>
29 * When it is detected, we create a new binding with this argument list expression and merge N
30 * bindings into a new one so that rest of the code generation logic works as expected.
31 */
32public class ArgListExpr extends Expr {
33    private int mId;
34    public ArgListExpr(int id, Iterable<Expr> children) {
35        super(children);
36        mId = id;
37    }
38
39    @Override
40    protected String computeUniqueKey() {
41        return "ArgList[" + mId + "]" + super.computeUniqueKey();
42    }
43
44    @Override
45    protected KCode generateCode(boolean expand) {
46        throw new IllegalStateException("should never try to convert an argument expressions"
47                + " into code");
48    }
49
50    @Override
51    protected ModelClass resolveType(ModelAnalyzer modelAnalyzer) {
52        return modelAnalyzer.findClass(Void.class);
53    }
54
55    @Override
56    protected List<Dependency> constructDependencies() {
57        return super.constructDynamicChildrenDependencies();
58    }
59
60    @Override
61    public boolean canBeEvaluatedToAVariable() {
62        return false;
63    }
64
65    @Override
66    public String getInvertibleError() {
67        return "Merged bindings are not invertible.";
68    }
69}
70