KickJava   Java API By Example, From Geeks To Geeks.

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


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.internal.compiler.ASTVisitor;
14 import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
15 import org.eclipse.jdt.internal.compiler.lookup.Binding;
16 import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
17 import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
18 import org.eclipse.jdt.internal.compiler.lookup.Scope;
19 import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding;
20
21 public class TypeParameter extends AbstractVariableDeclaration {
22
23     public TypeVariableBinding binding;
24     public TypeReference[] bounds;
25
26     /**
27      * @see org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration#getKind()
28      */

29     public int getKind() {
30         return TYPE_PARAMETER;
31     }
32
33     public void checkBounds(Scope scope) {
34         
35         if (this.type != null) {
36             this.type.checkBounds(scope);
37         }
38         if (this.bounds != null) {
39             for (int i = 0, length = this.bounds.length; i < length; i++) {
40                 this.bounds[i].checkBounds(scope);
41             }
42         }
43     }
44     
45     private void internalResolve(Scope scope, boolean staticContext) {
46         // detect variable/type name collisions
47
if (this.binding != null) {
48             Binding existingType = scope.parent.getBinding(this.name, Binding.TYPE, this, false/*do not resolve hidden field*/);
49             if (existingType != null
50                     && this.binding != existingType
51                     && existingType.isValidBinding()
52                     && (existingType.kind() != Binding.TYPE_PARAMETER || !staticContext)) {
53                 scope.problemReporter().typeHiding(this, existingType);
54             }
55         }
56     }
57     
58     public void resolve(BlockScope scope) {
59         internalResolve(scope, scope.methodScope().isStatic);
60     }
61     
62     public void resolve(ClassScope scope) {
63         internalResolve(scope, scope.enclosingSourceType().isStatic());
64     }
65
66     /* (non-Javadoc)
67      * @see org.eclipse.jdt.internal.compiler.ast.AstNode#print(int, java.lang.StringBuffer)
68      */

69     public StringBuffer JavaDoc printStatement(int indent, StringBuffer JavaDoc output) {
70         output.append(this.name);
71         if (this.type != null) {
72             output.append(" extends "); //$NON-NLS-1$
73
this.type.print(0, output);
74         }
75         if (this.bounds != null){
76             for (int i = 0; i < this.bounds.length; i++) {
77                 output.append(" & "); //$NON-NLS-1$
78
this.bounds[i].print(0, output);
79             }
80         }
81         return output;
82     }
83     
84     public void generateCode(BlockScope currentScope, CodeStream codeStream) {
85         // nothing to do
86
}
87     
88     public void traverse(ASTVisitor visitor, BlockScope scope) {
89         if (visitor.visit(this, scope)) {
90             if (type != null) {
91                 type.traverse(visitor, scope);
92             }
93             if (bounds != null) {
94                 int boundsLength = this.bounds.length;
95                 for (int i = 0; i < boundsLength; i++) {
96                     this.bounds[i].traverse(visitor, scope);
97                 }
98             }
99         }
100         visitor.endVisit(this, scope);
101     }
102
103     public void traverse(ASTVisitor visitor, ClassScope scope) {
104         if (visitor.visit(this, scope)) {
105             if (type != null) {
106                 type.traverse(visitor, scope);
107             }
108             if (bounds != null) {
109                 int boundsLength = this.bounds.length;
110                 for (int i = 0; i < boundsLength; i++) {
111                     this.bounds[i].traverse(visitor, scope);
112                 }
113             }
114         }
115         visitor.endVisit(this, scope);
116     }
117 }
118
Popular Tags