import eclipse 3.1 M4 compiler
[org.ibex.tool.git] / src / org / eclipse / jdt / internal / compiler / ast / TypeParameter.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-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.BlockScope;
16 import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
17 import org.eclipse.jdt.internal.compiler.lookup.Scope;
18 import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding;
19
20 public class TypeParameter extends AbstractVariableDeclaration {
21
22     public TypeVariableBinding binding;
23         public TypeReference[] bounds;
24
25         /**
26          * @see org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration#getKind()
27          */
28         public int getKind() {
29                 return TYPE_PARAMETER;
30         }
31
32         public void checkBounds(Scope scope) {
33                 
34                 if (this.type != null) {
35                         this.type.checkBounds(scope);
36                 }
37                 if (this.bounds != null) {
38                         for (int i = 0, length = this.bounds.length; i < length; i++) {
39                                 this.bounds[i].checkBounds(scope);
40                         }
41                 }
42         }
43         
44         public void resolve(ClassScope scope) {
45             // TODO (philippe) add warning for detecting variable name collisions
46         }
47
48         /* (non-Javadoc)
49          * @see org.eclipse.jdt.internal.compiler.ast.AstNode#print(int, java.lang.StringBuffer)
50          */
51         public StringBuffer printStatement(int indent, StringBuffer output) {
52                 output.append(this.name);
53                 if (this.type != null) {
54                         output.append(" extends "); //$NON-NLS-1$
55                         this.type.print(0, output);
56                 }
57                 if (this.bounds != null){
58                         for (int i = 0; i < this.bounds.length; i++) {
59                                 output.append(" & "); //$NON-NLS-1$
60                                 this.bounds[i].print(0, output);
61                         }
62                 }
63                 return output;
64         }
65         
66         public void generateCode(BlockScope currentScope, CodeStream codeStream) {
67             // nothing to do
68         }
69         
70         public void traverse(ASTVisitor visitor, BlockScope scope) {
71                 if (visitor.visit(this, scope)) {
72                         if (type != null) {
73                                 type.traverse(visitor, scope);
74                         }
75                         if (bounds != null) {
76                                 int boundsLength = this.bounds.length;
77                                 for (int i = 0; i < boundsLength; i++) {
78                                         this.bounds[i].traverse(visitor, scope);
79                                 }
80                         }
81                 }
82                 visitor.endVisit(this, scope);
83         }
84
85         public void traverse(ASTVisitor visitor, ClassScope scope) {
86                 if (visitor.visit(this, scope)) {
87                         if (type != null) {
88                                 type.traverse(visitor, scope);
89                         }
90                         if (bounds != null) {
91                                 int boundsLength = this.bounds.length;
92                                 for (int i = 0; i < boundsLength; i++) {
93                                         this.bounds[i].traverse(visitor, scope);
94                                 }
95                         }
96                 }
97                 visitor.endVisit(this, scope);
98         }       
99 }