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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.compiler.ast;
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;
20 public class TypeParameter extends AbstractVariableDeclaration {
22 public TypeVariableBinding binding;
23 public TypeReference[] bounds;
26 * @see org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration#getKind()
28 public int getKind() {
29 return TYPE_PARAMETER;
32 public void checkBounds(Scope scope) {
34 if (this.type != null) {
35 this.type.checkBounds(scope);
37 if (this.bounds != null) {
38 for (int i = 0, length = this.bounds.length; i < length; i++) {
39 this.bounds[i].checkBounds(scope);
44 public void resolve(ClassScope scope) {
45 // TODO (philippe) add warning for detecting variable name collisions
49 * @see org.eclipse.jdt.internal.compiler.ast.AstNode#print(int, java.lang.StringBuffer)
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);
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);
66 public void generateCode(BlockScope currentScope, CodeStream codeStream) {
70 public void traverse(ASTVisitor visitor, BlockScope scope) {
71 if (visitor.visit(this, scope)) {
73 type.traverse(visitor, scope);
76 int boundsLength = this.bounds.length;
77 for (int i = 0; i < boundsLength; i++) {
78 this.bounds[i].traverse(visitor, scope);
82 visitor.endVisit(this, scope);
85 public void traverse(ASTVisitor visitor, ClassScope scope) {
86 if (visitor.visit(this, scope)) {
88 type.traverse(visitor, scope);
91 int boundsLength = this.bounds.length;
92 for (int i = 0; i < boundsLength; i++) {
93 this.bounds[i].traverse(visitor, scope);
97 visitor.endVisit(this, scope);