001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.compiler.ast;
011:
012: import org.eclipse.jdt.internal.compiler.ASTVisitor;
013: import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
014: import org.eclipse.jdt.internal.compiler.lookup.Binding;
015: import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
016: import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
017: import org.eclipse.jdt.internal.compiler.lookup.Scope;
018: import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding;
019:
020: public class TypeParameter extends AbstractVariableDeclaration {
021:
022: public TypeVariableBinding binding;
023: public TypeReference[] bounds;
024:
025: /**
026: * @see org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration#getKind()
027: */
028: public int getKind() {
029: return TYPE_PARAMETER;
030: }
031:
032: public void checkBounds(Scope scope) {
033:
034: if (this .type != null) {
035: this .type.checkBounds(scope);
036: }
037: if (this .bounds != null) {
038: for (int i = 0, length = this .bounds.length; i < length; i++) {
039: this .bounds[i].checkBounds(scope);
040: }
041: }
042: }
043:
044: private void internalResolve(Scope scope, boolean staticContext) {
045: // detect variable/type name collisions
046: if (this .binding != null) {
047: Binding existingType = scope.parent
048: .getBinding(this .name, Binding.TYPE, this , false/*do not resolve hidden field*/);
049: if (existingType != null
050: && this .binding != existingType
051: && existingType.isValidBinding()
052: && (existingType.kind() != Binding.TYPE_PARAMETER || !staticContext)) {
053: scope.problemReporter().typeHiding(this , existingType);
054: }
055: }
056: }
057:
058: public void resolve(BlockScope scope) {
059: internalResolve(scope, scope.methodScope().isStatic);
060: }
061:
062: public void resolve(ClassScope scope) {
063: internalResolve(scope, scope.enclosingSourceType().isStatic());
064: }
065:
066: /* (non-Javadoc)
067: * @see org.eclipse.jdt.internal.compiler.ast.AstNode#print(int, java.lang.StringBuffer)
068: */
069: public StringBuffer printStatement(int indent, StringBuffer output) {
070: output.append(this .name);
071: if (this .type != null) {
072: output.append(" extends "); //$NON-NLS-1$
073: this .type.print(0, output);
074: }
075: if (this .bounds != null) {
076: for (int i = 0; i < this .bounds.length; i++) {
077: output.append(" & "); //$NON-NLS-1$
078: this .bounds[i].print(0, output);
079: }
080: }
081: return output;
082: }
083:
084: public void generateCode(BlockScope currentScope,
085: CodeStream codeStream) {
086: // nothing to do
087: }
088:
089: public void traverse(ASTVisitor visitor, BlockScope scope) {
090: if (visitor.visit(this , scope)) {
091: if (type != null) {
092: type.traverse(visitor, scope);
093: }
094: if (bounds != null) {
095: int boundsLength = this .bounds.length;
096: for (int i = 0; i < boundsLength; i++) {
097: this .bounds[i].traverse(visitor, scope);
098: }
099: }
100: }
101: visitor.endVisit(this , scope);
102: }
103:
104: public void traverse(ASTVisitor visitor, ClassScope scope) {
105: if (visitor.visit(this , scope)) {
106: if (type != null) {
107: type.traverse(visitor, scope);
108: }
109: if (bounds != null) {
110: int boundsLength = this .bounds.length;
111: for (int i = 0; i < boundsLength; i++) {
112: this.bounds[i].traverse(visitor, scope);
113: }
114: }
115: }
116: visitor.endVisit(this, scope);
117: }
118: }
|