01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.core.ext.typeinfo;
17:
18: /**
19: * Represents the super bound used in {@link JWildcardType}s.
20: */
21: public class JLowerBound extends JBound {
22: /**
23: *
24: */
25: public JLowerBound(JClassType lowerBound) {
26: this (new JClassType[] { lowerBound });
27: }
28:
29: /**
30: *
31: */
32: public JLowerBound(JClassType[] lowerBounds) {
33: super (lowerBounds);
34: }
35:
36: @Override
37: public JLowerBound isLowerBound() {
38: return this ;
39: }
40:
41: @Override
42: public JUpperBound isUpperBound() {
43: return null;
44: }
45:
46: @Override
47: JClassType[] getSubtypes() {
48: return TypeOracle.NO_JCLASSES;
49: }
50:
51: @Override
52: boolean isAssignableFrom(JClassType otherType) {
53: JWildcardType wildcard = otherType.isWildcard();
54: if (wildcard != null) {
55: JBound otherBounds = wildcard.getBounds();
56: if (otherBounds.isUpperBound() != null) {
57: // A lower bound cannot be assigned from an upper bound wildcard type.
58: return false;
59: }
60:
61: otherType = otherBounds.getFirstBound();
62: }
63:
64: /*
65: * Only check the first bound since a lower bound cannot specify multiple
66: * types.
67: */
68: return getFirstBound().isAssignableTo(otherType);
69: }
70:
71: @Override
72: boolean isAssignableTo(JClassType otherType) {
73: JWildcardType wildcard = otherType.isWildcard();
74: if (wildcard != null) {
75: JBound otherBounds = wildcard.getBounds();
76: if (otherBounds.isUpperBound() != null) {
77: // A lower bound cannot be assigned from an upper bound wildcard type.
78: return false;
79: }
80:
81: otherType = otherBounds.getFirstBound();
82: }
83:
84: return getFirstBound().isAssignableFrom(otherType);
85: }
86: }
|