Debian Codegraph @

compiler/src/main/java/android/databinding/tool/expr/BitShiftExpr.java

raw
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
17 package android.databinding.tool.expr;
18
19 import android.databinding.tool.reflection.ModelAnalyzer;
20 import android.databinding.tool.reflection.ModelClass;
21 import android.databinding.tool.writer.KCode;
22
23 import java.util.List;
24
25 public class BitShiftExpr extends Expr {
26 final String mOp;
27 BitShiftExpr(Expr left, String op, Expr right) {
28 super(left, right);
29 mOp = op;
30 }
31
32 @Override
33 protected String computeUniqueKey() {
34 return join(getLeft().getUniqueKey(), mOp, getRight().getUniqueKey());
35 }
36
37 @Override
38 protected ModelClass resolveType(ModelAnalyzer modelAnalyzer) {
39 return getLeft().getResolvedType();
40 }
41
42 @Override
43 protected List<Dependency> constructDependencies() {
44 return constructDynamicChildrenDependencies();
45 }
46
47 public String getOp() {
48 return mOp;
49 }
50
51 public Expr getLeft() {
52 return getChildren().get(0);
53 }
54
55 public Expr getRight() {
56 return getChildren().get(1);
57 }
58
59 @Override
60 protected KCode generateCode() {
61 return new KCode()
62 .app("", getLeft().toCode())
63 .app(getOp())
64 .app("", getRight().toCode());
65 }
66
67 @Override
68 public Expr cloneToModel(ExprModel model) {
69 return model.bitshift(getLeft().cloneToModel(model), mOp, getRight().cloneToModel(model));
70 }
71
72 @Override
73 public String getInvertibleError() {
74 return "Bit shift operators cannot be inverted in two-way binding";
75 }
76
77 @Override
78 public String toString() {
79 return getLeft().toString() + ' ' + mOp + ' ' + getRight().toString();
80 }
81 }