KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > ast > JavadocAllocationExpression


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-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.core.compiler.CharOperation;
14 import org.eclipse.jdt.internal.compiler.ASTVisitor;
15 import org.eclipse.jdt.internal.compiler.impl.Constant;
16 import org.eclipse.jdt.internal.compiler.lookup.*;
17
18 public class JavadocAllocationExpression extends AllocationExpression {
19
20     public int tagSourceStart, tagSourceEnd;
21     public int tagValue, memberStart;
22     public char[][] qualification;
23
24     public JavadocAllocationExpression(int start, int end) {
25         this.sourceStart = start;
26         this.sourceEnd = end;
27         this.bits |= InsideJavadoc;
28     }
29     public JavadocAllocationExpression(long pos) {
30         this((int) (pos >>> 32), (int) pos);
31     }
32
33     TypeBinding internalResolveType(Scope scope) {
34     
35         // Propagate the type checking to the arguments, and check if the constructor is defined.
36
this.constant = Constant.NotAConstant;
37         if (this.type == null) {
38             this.resolvedType = scope.enclosingSourceType();
39         } else if (scope.kind == Scope.CLASS_SCOPE) {
40             this.resolvedType = this.type.resolveType((ClassScope)scope);
41         } else {
42             this.resolvedType = this.type.resolveType((BlockScope)scope, true /* check bounds*/);
43         }
44     
45         // buffering the arguments' types
46
TypeBinding[] argumentTypes = Binding.NO_PARAMETERS;
47         boolean hasTypeVarArgs = false;
48         if (this.arguments != null) {
49             boolean argHasError = false;
50             int length = this.arguments.length;
51             argumentTypes = new TypeBinding[length];
52             for (int i = 0; i < length; i++) {
53                 Expression argument = this.arguments[i];
54                 if (scope.kind == Scope.CLASS_SCOPE) {
55                     argumentTypes[i] = argument.resolveType((ClassScope)scope);
56                 } else {
57                     argumentTypes[i] = argument.resolveType((BlockScope)scope);
58                 }
59                 if (argumentTypes[i] == null) {
60                     argHasError = true;
61                 } else if (!hasTypeVarArgs) {
62                     hasTypeVarArgs = argumentTypes[i].isTypeVariable();
63                 }
64             }
65             if (argHasError) {
66                 return null;
67             }
68         }
69     
70         // check resolved type
71
if (this.resolvedType == null) {
72             return null;
73         }
74         this.resolvedType = scope.environment().convertToRawType(this.type.resolvedType);
75         SourceTypeBinding enclosingType = scope.enclosingSourceType();
76         if (enclosingType == null ? false : enclosingType.isCompatibleWith(this.resolvedType)) {
77             this.bits |= ASTNode.SuperAccess;
78         }
79     
80         ReferenceBinding allocationType = (ReferenceBinding) this.resolvedType;
81         this.binding = scope.getConstructor(allocationType, argumentTypes, this);
82         if (!this.binding.isValidBinding()) {
83             ReferenceBinding enclosingTypeBinding = allocationType;
84             MethodBinding contructorBinding = this.binding;
85             while (!contructorBinding.isValidBinding() && (enclosingTypeBinding.isMemberType() || enclosingTypeBinding.isLocalType())) {
86                 enclosingTypeBinding = enclosingTypeBinding.enclosingType();
87                 contructorBinding = scope.getConstructor(enclosingTypeBinding, argumentTypes, this);
88             }
89             if (contructorBinding.isValidBinding()) {
90                 this.binding = contructorBinding;
91             }
92         }
93         if (!this.binding.isValidBinding()) {
94             // First try to search a method instead
95
MethodBinding methodBinding = scope.getMethod(this.resolvedType, this.resolvedType.sourceName(), argumentTypes, this);
96             if (methodBinding.isValidBinding()) {
97                 this.binding = methodBinding;
98             } else {
99                 if (this.binding.declaringClass == null) {
100                     this.binding.declaringClass = allocationType;
101                 }
102                 scope.problemReporter().javadocInvalidConstructor(this, this.binding, scope.getDeclarationModifiers());
103             }
104             return this.resolvedType;
105         } else if (binding.isVarargs()) {
106             int length = argumentTypes.length;
107             if (!(binding.parameters.length == length && argumentTypes[length-1].isArrayType())) {
108                 MethodBinding problem = new ProblemMethodBinding(this.binding, this.binding.selector, argumentTypes, ProblemReasons.NotFound);
109                 scope.problemReporter().javadocInvalidConstructor(this, problem, scope.getDeclarationModifiers());
110             }
111         } else if (hasTypeVarArgs) {
112             MethodBinding problem = new ProblemMethodBinding(this.binding, this.binding.selector, argumentTypes, ProblemReasons.NotFound);
113             scope.problemReporter().javadocInvalidConstructor(this, problem, scope.getDeclarationModifiers());
114         } else if (this.binding instanceof ParameterizedMethodBinding) {
115             ParameterizedMethodBinding paramMethodBinding = (ParameterizedMethodBinding) this.binding;
116             if (paramMethodBinding.hasSubstitutedParameters()) {
117                 int length = argumentTypes.length;
118                 for (int i=0; i<length; i++) {
119                     if (paramMethodBinding.parameters[i] != argumentTypes[i] &&
120                             paramMethodBinding.parameters[i].erasure() != argumentTypes[i].erasure()) {
121                         MethodBinding problem = new ProblemMethodBinding(this.binding, this.binding.selector, argumentTypes, ProblemReasons.NotFound);
122                         scope.problemReporter().javadocInvalidConstructor(this, problem, scope.getDeclarationModifiers());
123                         break;
124                     }
125                 }
126             }
127         } else if (this.resolvedType.isMemberType()) {
128             int length = qualification.length;
129             if (length > 1) { // accept qualified member class constructor reference => see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=103304
130
ReferenceBinding enclosingTypeBinding = allocationType;
131                 if (type instanceof JavadocQualifiedTypeReference && ((JavadocQualifiedTypeReference)type).tokens.length != length) {
132                     scope.problemReporter().javadocInvalidMemberTypeQualification(this.memberStart+1, this.sourceEnd, scope.getDeclarationModifiers());
133                 } else {
134                     int idx = length;
135                     while (idx > 0 && CharOperation.equals(qualification[--idx], enclosingTypeBinding.sourceName) && (enclosingTypeBinding = enclosingTypeBinding.enclosingType()) != null) {
136                         // verify that each qualification token matches enclosing types
137
}
138                     if (idx > 0 || enclosingTypeBinding != null) {
139                         scope.problemReporter().javadocInvalidMemberTypeQualification(this.memberStart+1, this.sourceEnd, scope.getDeclarationModifiers());
140                     }
141                 }
142             }
143         }
144         if (isMethodUseDeprecated(this.binding, scope, true)) {
145             scope.problemReporter().javadocDeprecatedMethod(this.binding, this, scope.getDeclarationModifiers());
146         }
147         return allocationType;
148     }
149
150     public boolean isSuperAccess() {
151         return (this.bits & ASTNode.SuperAccess) != 0;
152     }
153
154     public TypeBinding resolveType(BlockScope scope) {
155         return internalResolveType(scope);
156     }
157
158     public TypeBinding resolveType(ClassScope scope) {
159         return internalResolveType(scope);
160     }
161     public void traverse(ASTVisitor visitor, BlockScope scope) {
162         if (visitor.visit(this, scope)) {
163             if (this.typeArguments != null) {
164                 for (int i = 0, typeArgumentsLength = this.typeArguments.length; i < typeArgumentsLength; i++) {
165                     this.typeArguments[i].traverse(visitor, scope);
166                 }
167             }
168             if (this.type != null) { // enum constant scenario
169
this.type.traverse(visitor, scope);
170             }
171             if (this.arguments != null) {
172                 for (int i = 0, argumentsLength = this.arguments.length; i < argumentsLength; i++)
173                     this.arguments[i].traverse(visitor, scope);
174             }
175         }
176         visitor.endVisit(this, scope);
177     }
178     public void traverse(ASTVisitor visitor, ClassScope scope) {
179         if (visitor.visit(this, scope)) {
180             if (this.typeArguments != null) {
181                 for (int i = 0, typeArgumentsLength = this.typeArguments.length; i < typeArgumentsLength; i++) {
182                     this.typeArguments[i].traverse(visitor, scope);
183                 }
184             }
185             if (this.type != null) { // enum constant scenario
186
this.type.traverse(visitor, scope);
187             }
188             if (this.arguments != null) {
189                 for (int i = 0, argumentsLength = this.arguments.length; i < argumentsLength; i++)
190                     this.arguments[i].traverse(visitor, scope);
191             }
192         }
193         visitor.endVisit(this, scope);
194     }
195 }
196
Popular Tags