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.lookup.*; 14 import org.eclipse.jdt.internal.compiler.lookup.BlockScope; 15 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; 16 17 public class JavadocAllocationExpression extends AllocationExpression { 18 19 public int tagSourceStart, tagSourceEnd; 20 public int tagValue; 21 public boolean superAccess = false; 22 JavadocAllocationExpression(long pos)23 public JavadocAllocationExpression(long pos) { 24 this.sourceStart = (int) (pos >>> 32); 25 this.sourceEnd = (int) pos; 26 this.bits |= InsideJavadoc; 27 } 28 29 /* 30 * Resolves type on a Block or Class scope. 31 */ internalResolveType(Scope scope)32 private TypeBinding internalResolveType(Scope scope) { 33 34 // Propagate the type checking to the arguments, and check if the constructor is defined. 35 this.constant = NotAConstant; 36 if (this.type == null) { 37 this.resolvedType = scope.enclosingSourceType(); 38 } else if (scope.kind == Scope.CLASS_SCOPE) { 39 this.resolvedType = this.type.resolveType((ClassScope)scope); 40 } else { 41 this.resolvedType = this.type.resolveType((BlockScope)scope); 42 } 43 44 // buffering the arguments' types 45 TypeBinding[] argumentTypes = NoParameters; 46 if (this.arguments != null) { 47 boolean argHasError = false; 48 int length = this.arguments.length; 49 argumentTypes = new TypeBinding[length]; 50 for (int i = 0; i < length; i++) { 51 Expression argument = this.arguments[i]; 52 if (scope.kind == Scope.CLASS_SCOPE) { 53 argumentTypes[i] = argument.resolveType((ClassScope)scope); 54 } else { 55 argumentTypes[i] = argument.resolveType((BlockScope)scope); 56 } 57 if (argumentTypes[i] == null) { 58 argHasError = true; 59 } 60 } 61 if (argHasError) { 62 return null; 63 } 64 } 65 66 // check resolved type 67 if (this.resolvedType == null) { 68 return null; 69 } 70 this.superAccess = scope.enclosingSourceType().isCompatibleWith(this.resolvedType); 71 72 ReferenceBinding allocationType = (ReferenceBinding) this.resolvedType; 73 this.binding = scope.getConstructor(allocationType, argumentTypes, this); 74 if (!this.binding.isValidBinding()) { 75 MethodBinding methodBinding = scope.getMethod(this.resolvedType, this.resolvedType.sourceName(), argumentTypes, this); 76 if (methodBinding.isValidBinding()) { 77 this.binding = methodBinding; 78 } else { 79 if (this.binding.declaringClass == null) { 80 this.binding.declaringClass = allocationType; 81 } 82 scope.problemReporter().javadocInvalidConstructor(this, this.binding, scope.getDeclarationModifiers()); 83 } 84 return this.resolvedType; 85 } 86 if (isMethodUseDeprecated(this.binding, scope)) { 87 scope.problemReporter().javadocDeprecatedMethod(this.binding, this, scope.getDeclarationModifiers()); 88 } 89 // TODO (frederic) add support for unsafe type operation warning 90 return allocationType; 91 } 92 93 /* (non-Javadoc) 94 * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#isSuperAccess() 95 */ isSuperAccess()96 public boolean isSuperAccess() { 97 return this.superAccess; 98 } 99 100 /* (non-Javadoc) 101 * @see org.eclipse.jdt.internal.compiler.ast.Expression#resolveType(org.eclipse.jdt.internal.compiler.lookup.BlockScope) 102 */ resolveType(BlockScope scope)103 public TypeBinding resolveType(BlockScope scope) { 104 return internalResolveType(scope); 105 } 106 107 /* (non-Javadoc) 108 * @see org.eclipse.jdt.internal.compiler.ast.Expression#resolveType(org.eclipse.jdt.internal.compiler.lookup.BlockScope) 109 */ resolveType(ClassScope scope)110 public TypeBinding resolveType(ClassScope scope) { 111 return internalResolveType(scope); 112 } 113 } 114