KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > ast > Wildcard


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.compiler.ast;
12
13 import org.eclipse.jdt.core.compiler.CharOperation;
14 import org.eclipse.jdt.internal.compiler.ASTVisitor;
15 import org.eclipse.jdt.internal.compiler.lookup.*;
16
17 /**
18  * Node to represent Wildcard
19  */

20 public class Wildcard extends SingleTypeReference {
21
22     public static final int UNBOUND = 0;
23     public static final int EXTENDS = 1;
24     public static final int SUPER = 2;
25     
26     public TypeReference bound;
27     public int kind;
28
29     public Wildcard(int kind) {
30         super(WILDCARD_NAME, 0);
31         this.kind = kind;
32     }
33     
34     public char [][] getParameterizedTypeName() {
35         switch (this.kind) {
36             case Wildcard.UNBOUND :
37                return new char[][] { WILDCARD_NAME };
38             case Wildcard.EXTENDS :
39                 return new char[][] { CharOperation.concat(WILDCARD_NAME, WILDCARD_EXTENDS, CharOperation.concatWith(this.bound.getParameterizedTypeName(), '.')) };
40             default: // SUPER
41
return new char[][] { CharOperation.concat(WILDCARD_NAME, WILDCARD_SUPER, CharOperation.concatWith(this.bound.getParameterizedTypeName(), '.')) };
42         }
43     }
44
45     public char [][] getTypeName() {
46         switch (this.kind) {
47             case Wildcard.UNBOUND :
48                return new char[][] { WILDCARD_NAME };
49             case Wildcard.EXTENDS :
50                 return new char[][] { CharOperation.concat(WILDCARD_NAME, WILDCARD_EXTENDS, CharOperation.concatWith(this.bound.getTypeName(), '.')) };
51             default: // SUPER
52
return new char[][] { CharOperation.concat(WILDCARD_NAME, WILDCARD_SUPER, CharOperation.concatWith(this.bound.getTypeName(), '.')) };
53         }
54     }
55     
56     private TypeBinding internalResolveType(Scope scope, ReferenceBinding genericType, int rank) {
57         TypeBinding boundType = null;
58         if (this.bound != null) {
59             boundType = scope.kind == Scope.CLASS_SCOPE
60                 ? this.bound.resolveType((ClassScope)scope)
61                 : this.bound.resolveType((BlockScope)scope, true /* check bounds*/);
62                         
63             if (boundType == null) {
64                 return null;
65             }
66         }
67         WildcardBinding wildcard = scope.environment().createWildcard(genericType, rank, boundType, null /*no extra bound*/, this.kind);
68         return this.resolvedType = wildcard;
69     }
70     
71     public StringBuffer JavaDoc printExpression(int indent, StringBuffer JavaDoc output){
72         switch (this.kind) {
73             case Wildcard.UNBOUND :
74                 output.append(WILDCARD_NAME);
75                 break;
76             case Wildcard.EXTENDS :
77                 output.append(WILDCARD_NAME).append(WILDCARD_EXTENDS);
78                 this.bound.printExpression(0, output);
79                 break;
80             default: // SUPER
81
output.append(WILDCARD_NAME).append(WILDCARD_SUPER);
82                 this.bound.printExpression(0, output);
83                 break;
84         }
85         return output;
86     }
87     
88     // only invoked for improving resilience when unable to bind generic type from parameterized reference
89
public TypeBinding resolveType(BlockScope scope, boolean checkBounds) {
90         if (this.bound != null) {
91             this.bound.resolveType(scope, checkBounds);
92         }
93         return null;
94     }
95     // only invoked for improving resilience when unable to bind generic type from parameterized reference
96
public TypeBinding resolveType(ClassScope scope) {
97         if (this.bound != null) {
98             this.bound.resolveType(scope);
99         }
100         return null;
101     }
102     public TypeBinding resolveTypeArgument(BlockScope blockScope, ReferenceBinding genericType, int rank) {
103         return internalResolveType(blockScope, genericType, rank);
104     }
105     
106     public TypeBinding resolveTypeArgument(ClassScope classScope, ReferenceBinding genericType, int rank) {
107         return internalResolveType(classScope, genericType, rank);
108     }
109
110     public void traverse(ASTVisitor visitor, BlockScope scope) {
111         if (visitor.visit(this, scope)) {
112             if (this.bound != null) {
113                 this.bound.traverse(visitor, scope);
114             }
115         }
116         visitor.endVisit(this, scope);
117     }
118
119     public void traverse(ASTVisitor visitor, ClassScope scope) {
120         if (visitor.visit(this, scope)) {
121             if (this.bound != null) {
122                 this.bound.traverse(visitor, scope);
123             }
124         }
125         visitor.endVisit(this, scope);
126     }
127 }
128
Popular Tags