1 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 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 if (this.binding != null) { 48 Binding existingType = scope.parent.getBinding(this.name, Binding.TYPE, this, false); 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 69 public StringBuffer printStatement(int indent, StringBuffer output) { 70 output.append(this.name); 71 if (this.type != null) { 72 output.append(" extends "); this.type.print(0, output); 74 } 75 if (this.bounds != null){ 76 for (int i = 0; i < this.bounds.length; i++) { 77 output.append(" & "); this.bounds[i].print(0, output); 79 } 80 } 81 return output; 82 } 83 84 public void generateCode(BlockScope currentScope, CodeStream codeStream) { 85 } 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 |