Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2010 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2011 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 105-111
Link Here
|
105 |
} |
105 |
} |
106 |
} |
106 |
} |
107 |
} |
107 |
} |
108 |
boolean hasGenericError = false; |
|
|
109 |
ReferenceBinding currentType; |
108 |
ReferenceBinding currentType; |
110 |
this.bits |= ASTNode.DidResolve; |
109 |
this.bits |= ASTNode.DidResolve; |
111 |
if (enclosingType == null) { |
110 |
if (enclosingType == null) { |
Lines 113-119
Link Here
|
113 |
if (this.resolvedType.isValidBinding()) { |
112 |
if (this.resolvedType.isValidBinding()) { |
114 |
currentType = (ReferenceBinding) this.resolvedType; |
113 |
currentType = (ReferenceBinding) this.resolvedType; |
115 |
} else { |
114 |
} else { |
116 |
hasGenericError = true; |
|
|
117 |
reportInvalidType(scope); |
115 |
reportInvalidType(scope); |
118 |
switch (this.resolvedType.problemId()) { |
116 |
switch (this.resolvedType.problemId()) { |
119 |
case ProblemReasons.NotFound : |
117 |
case ProblemReasons.NotFound : |
Lines 127-142
Link Here
|
127 |
//$FALL-THROUGH$ - unable to complete type binding, but still resolve type arguments |
125 |
//$FALL-THROUGH$ - unable to complete type binding, but still resolve type arguments |
128 |
default : |
126 |
default : |
129 |
boolean isClassScope = scope.kind == Scope.CLASS_SCOPE; |
127 |
boolean isClassScope = scope.kind == Scope.CLASS_SCOPE; |
130 |
int argLength = this.typeArguments.length; |
128 |
int argLength = this.typeArguments.length; |
131 |
for (int i = 0; i < argLength; i++) { |
129 |
for (int i = 0; i < argLength; i++) { |
132 |
TypeReference typeArgument = this.typeArguments[i]; |
130 |
TypeReference typeArgument = this.typeArguments[i]; |
133 |
if (isClassScope) { |
131 |
if (isClassScope) { |
134 |
typeArgument.resolveType((ClassScope) scope); |
132 |
typeArgument.resolveType((ClassScope) scope); |
135 |
} else { |
133 |
} else { |
136 |
typeArgument.resolveType((BlockScope) scope, checkBounds); |
134 |
typeArgument.resolveType((BlockScope) scope, checkBounds); |
|
|
135 |
} |
137 |
} |
136 |
} |
138 |
} |
137 |
createArrayType(scope); |
139 |
return null; |
138 |
return null; |
140 |
} |
139 |
} |
141 |
// be resilient, still attempt resolving arguments |
140 |
// be resilient, still attempt resolving arguments |
142 |
} |
141 |
} |
Lines 150-157
Link Here
|
150 |
} else { // resolving member type (relatively to enclosingType) |
149 |
} else { // resolving member type (relatively to enclosingType) |
151 |
this.resolvedType = currentType = scope.getMemberType(this.token, enclosingType); |
150 |
this.resolvedType = currentType = scope.getMemberType(this.token, enclosingType); |
152 |
if (!this.resolvedType.isValidBinding()) { |
151 |
if (!this.resolvedType.isValidBinding()) { |
153 |
hasGenericError = true; |
|
|
154 |
scope.problemReporter().invalidEnclosingType(this, currentType, enclosingType); |
152 |
scope.problemReporter().invalidEnclosingType(this, currentType, enclosingType); |
|
|
153 |
createArrayType(scope); |
155 |
return null; |
154 |
return null; |
156 |
} |
155 |
} |
157 |
if (isTypeUseDeprecated(currentType, scope)) |
156 |
if (isTypeUseDeprecated(currentType, scope)) |
Lines 163-196
Link Here
|
163 |
} |
162 |
} |
164 |
|
163 |
|
165 |
// check generic and arity |
164 |
// check generic and arity |
166 |
boolean isClassScope = scope.kind == Scope.CLASS_SCOPE; |
165 |
boolean isClassScope = scope.kind == Scope.CLASS_SCOPE; |
167 |
TypeReference keep = null; |
166 |
TypeReference keep = null; |
168 |
if (isClassScope) { |
167 |
if (isClassScope) { |
169 |
keep = ((ClassScope) scope).superTypeReference; |
168 |
keep = ((ClassScope) scope).superTypeReference; |
170 |
((ClassScope) scope).superTypeReference = null; |
169 |
((ClassScope) scope).superTypeReference = null; |
171 |
} |
170 |
} |
172 |
int argLength = this.typeArguments.length; |
171 |
int argLength = this.typeArguments.length; |
173 |
TypeBinding[] argTypes = new TypeBinding[argLength]; |
172 |
TypeBinding[] argTypes = new TypeBinding[argLength]; |
174 |
boolean argHasError = false; |
173 |
boolean argHasError = false; |
175 |
ReferenceBinding currentOriginal = (ReferenceBinding)currentType.original(); |
174 |
ReferenceBinding currentOriginal = (ReferenceBinding)currentType.original(); |
176 |
for (int i = 0; i < argLength; i++) { |
175 |
for (int i = 0; i < argLength; i++) { |
177 |
TypeReference typeArgument = this.typeArguments[i]; |
176 |
TypeReference typeArgument = this.typeArguments[i]; |
178 |
TypeBinding argType = isClassScope |
177 |
TypeBinding argType = isClassScope |
179 |
? typeArgument.resolveTypeArgument((ClassScope) scope, currentOriginal, i) |
178 |
? typeArgument.resolveTypeArgument((ClassScope) scope, currentOriginal, i) |
180 |
: typeArgument.resolveTypeArgument((BlockScope) scope, currentOriginal, i); |
179 |
: typeArgument.resolveTypeArgument((BlockScope) scope, currentOriginal, i); |
181 |
if (argType == null) { |
180 |
if (argType == null) { |
182 |
argHasError = true; |
181 |
argHasError = true; |
183 |
} else { |
182 |
} else { |
184 |
argTypes[i] = argType; |
183 |
argTypes[i] = argType; |
185 |
} |
184 |
} |
186 |
} |
185 |
} |
187 |
if (argHasError) { |
186 |
if (argHasError) { |
|
|
187 |
createArrayType(scope); |
188 |
return null; |
188 |
return null; |
189 |
} |
189 |
} |
190 |
if (isClassScope) { |
190 |
if (isClassScope) { |
191 |
((ClassScope) scope).superTypeReference = keep; |
191 |
((ClassScope) scope).superTypeReference = keep; |
192 |
if (((ClassScope) scope).detectHierarchyCycle(currentOriginal, this)) |
192 |
if (((ClassScope) scope).detectHierarchyCycle(currentOriginal, this)) { |
|
|
193 |
createArrayType(scope); |
193 |
return null; |
194 |
return null; |
|
|
195 |
} |
194 |
} |
196 |
} |
195 |
|
197 |
|
196 |
TypeVariableBinding[] typeVariables = currentOriginal.typeVariables(); |
198 |
TypeVariableBinding[] typeVariables = currentOriginal.typeVariables(); |
Lines 200-205
Link Here
|
200 |
if (isCompliant15) { // below 1.5, already reported as syntax error |
202 |
if (isCompliant15) { // below 1.5, already reported as syntax error |
201 |
this.resolvedType = currentType; |
203 |
this.resolvedType = currentType; |
202 |
scope.problemReporter().nonGenericTypeCannotBeParameterized(0, this, currentType, argTypes); |
204 |
scope.problemReporter().nonGenericTypeCannotBeParameterized(0, this, currentType, argTypes); |
|
|
205 |
createArrayType(scope); |
203 |
return null; |
206 |
return null; |
204 |
} |
207 |
} |
205 |
} |
208 |
} |
Lines 212-242
Link Here
|
212 |
scope.problemReporter().tooManyDimensions(this); |
215 |
scope.problemReporter().tooManyDimensions(this); |
213 |
type = scope.createArrayType(type, this.dimensions); |
216 |
type = scope.createArrayType(type, this.dimensions); |
214 |
} |
217 |
} |
215 |
if (hasGenericError) |
|
|
216 |
return type; |
217 |
return this.resolvedType = type; |
218 |
return this.resolvedType = type; |
218 |
} |
219 |
} |
219 |
// if missing generic type, and compliance >= 1.5, then will rebuild a parameterized binding |
220 |
// if missing generic type, and compliance >= 1.5, then will rebuild a parameterized binding |
220 |
} else if (argLength != typeVariables.length) { // check arity |
221 |
} else if (argLength != typeVariables.length) { // check arity |
221 |
scope.problemReporter().incorrectArityForParameterizedType(this, currentType, argTypes); |
222 |
scope.problemReporter().incorrectArityForParameterizedType(this, currentType, argTypes); |
|
|
223 |
createArrayType(scope); |
222 |
return null; |
224 |
return null; |
223 |
} else if (!currentType.isStatic()) { |
225 |
} else if (!currentType.isStatic()) { |
224 |
ReferenceBinding actualEnclosing = currentType.enclosingType(); |
226 |
ReferenceBinding actualEnclosing = currentType.enclosingType(); |
225 |
if (actualEnclosing != null && actualEnclosing.isRawType()){ |
227 |
if (actualEnclosing != null && actualEnclosing.isRawType()){ |
226 |
scope.problemReporter().rawMemberTypeCannotBeParameterized( |
228 |
scope.problemReporter().rawMemberTypeCannotBeParameterized( |
227 |
this, scope.environment().createRawType(currentOriginal, actualEnclosing), argTypes); |
229 |
this, scope.environment().createRawType(currentOriginal, actualEnclosing), argTypes); |
|
|
230 |
createArrayType(scope); |
228 |
return null; |
231 |
return null; |
229 |
} |
232 |
} |
230 |
} |
233 |
} |
231 |
|
234 |
|
232 |
ParameterizedTypeBinding parameterizedType = scope.environment().createParameterizedType(currentOriginal, argTypes, enclosingType); |
235 |
ParameterizedTypeBinding parameterizedType = scope.environment().createParameterizedType(currentOriginal, argTypes, enclosingType); |
233 |
// check argument type compatibility |
236 |
// check argument type compatibility |
234 |
if (checkBounds) // otherwise will do it in Scope.connectTypeVariables() or generic method resolution |
237 |
if (checkBounds) {// otherwise will do it in Scope.connectTypeVariables() or generic method resolution |
235 |
parameterizedType.boundCheck(scope, this.typeArguments); |
238 |
parameterizedType.boundCheck(scope, this.typeArguments); |
236 |
else |
239 |
} else { |
237 |
scope.deferBoundCheck(this); |
240 |
scope.deferBoundCheck(this); |
238 |
if (isTypeUseDeprecated(parameterizedType, scope)) |
241 |
} |
|
|
242 |
if (isTypeUseDeprecated(parameterizedType, scope)) { |
239 |
reportDeprecatedType(parameterizedType, scope); |
243 |
reportDeprecatedType(parameterizedType, scope); |
|
|
244 |
} |
240 |
|
245 |
|
241 |
TypeBinding type = parameterizedType; |
246 |
TypeBinding type = parameterizedType; |
242 |
// array type ? |
247 |
// array type ? |
Lines 245-255
Link Here
|
245 |
scope.problemReporter().tooManyDimensions(this); |
250 |
scope.problemReporter().tooManyDimensions(this); |
246 |
type = scope.createArrayType(type, this.dimensions); |
251 |
type = scope.createArrayType(type, this.dimensions); |
247 |
} |
252 |
} |
248 |
if (hasGenericError) { |
|
|
249 |
return type; |
250 |
} |
251 |
return this.resolvedType = type; |
253 |
return this.resolvedType = type; |
252 |
} |
254 |
} |
|
|
255 |
private void createArrayType(Scope scope) { |
256 |
if (this.dimensions > 0) { |
257 |
if (this.dimensions > 255) { |
258 |
scope.problemReporter().tooManyDimensions(this); |
259 |
} |
260 |
this.resolvedType = scope.createArrayType(this.resolvedType, this.dimensions); |
261 |
} |
262 |
} |
253 |
|
263 |
|
254 |
public StringBuffer printExpression(int indent, StringBuffer output){ |
264 |
public StringBuffer printExpression(int indent, StringBuffer output){ |
255 |
output.append(this.token); |
265 |
output.append(this.token); |