1d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar/*
2d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar * Copyright (C) 2015 The Android Open Source Project
3d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar *
4d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar * Licensed under the Apache License, Version 2.0 (the "License");
5d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar * you may not use this file except in compliance with the License.
6d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar * You may obtain a copy of the License at
7d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar *
8d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar *      http://www.apache.org/licenses/LICENSE-2.0
9d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar *
10d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar * Unless required by applicable law or agreed to in writing, software
11d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar * distributed under the License is distributed on an "AS IS" BASIS,
12d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar * See the License for the specific language governing permissions and
14d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar * limitations under the License.
15d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar */
16d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar
17fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mountpackage android.databinding.tool.expr;
18d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar
19fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mountimport android.databinding.tool.reflection.ModelAnalyzer;
20fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mountimport android.databinding.tool.reflection.ModelClass;
21e52882df6130221462bf07f5f2b52de5c4b0f8deGeorge Mountimport android.databinding.tool.writer.KCode;
22d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar
23d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyarimport java.util.List;
24d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar
25d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyarpublic class GroupExpr extends Expr {
26d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar    public GroupExpr(Expr wrapped) {
27d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar        super(wrapped);
28d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar    }
29d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar
30d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar    @Override
3179fc7f3727815ab35bb1bb2e060bfb7db3176eedGeorge Mount    protected ModelClass resolveType(ModelAnalyzer modelAnalyzer) {
32731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar        return getWrapped().getResolvedType();
33d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar    }
34d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar
35d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar    @Override
36d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar    protected List<Dependency> constructDependencies() {
377920e17f7b501d5792e7e3250e9dbb69eca86adeGeorge Mount        return getWrapped().constructDependencies();
38d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar    }
39d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar
40e52882df6130221462bf07f5f2b52de5c4b0f8deGeorge Mount    @Override
41d3f2b9229472c9dae9bf4ae8b3e2d653b5653b01George Mount    protected KCode generateCode(boolean expand) {
42d3f2b9229472c9dae9bf4ae8b3e2d653b5653b01George Mount        return new KCode().app("(", getWrapped().toCode(expand)).app(")");
43e52882df6130221462bf07f5f2b52de5c4b0f8deGeorge Mount    }
44e52882df6130221462bf07f5f2b52de5c4b0f8deGeorge Mount
45d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar    public Expr getWrapped() {
467920e17f7b501d5792e7e3250e9dbb69eca86adeGeorge Mount        return getChildren().get(0);
47d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar    }
48d3f2b9229472c9dae9bf4ae8b3e2d653b5653b01George Mount
49d3f2b9229472c9dae9bf4ae8b3e2d653b5653b01George Mount    @Override
50d3f2b9229472c9dae9bf4ae8b3e2d653b5653b01George Mount    public KCode toInverseCode(KCode value) {
51d3f2b9229472c9dae9bf4ae8b3e2d653b5653b01George Mount        // Nothing to do here. Other expressions should automatically take care of grouping.
52d3f2b9229472c9dae9bf4ae8b3e2d653b5653b01George Mount        return getWrapped().toInverseCode(value);
53d3f2b9229472c9dae9bf4ae8b3e2d653b5653b01George Mount    }
54d3f2b9229472c9dae9bf4ae8b3e2d653b5653b01George Mount
55d3f2b9229472c9dae9bf4ae8b3e2d653b5653b01George Mount    @Override
56d3f2b9229472c9dae9bf4ae8b3e2d653b5653b01George Mount    public String getInvertibleError() {
57d3f2b9229472c9dae9bf4ae8b3e2d653b5653b01George Mount        return getWrapped().getInvertibleError();
58d3f2b9229472c9dae9bf4ae8b3e2d653b5653b01George Mount    }
59d7af42b29ddf22f0068f7496c5ac6f4f34b543b6Yigit Boyar}
60