View | Details | Raw Unified | Return to bug 177194 | Differences between
and this patch

Collapse All | Expand All

(-)eval/org/eclipse/jdt/internal/eval/CodeSnippetMessageSend.java (-7 / +15 lines)
Lines 29-34 Link Here
29
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
29
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
30
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
30
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
31
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
31
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
32
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
32
import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding;
33
import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding;
33
34
34
public class CodeSnippetMessageSend extends MessageSend implements ProblemReasons, EvaluationConstants {
35
public class CodeSnippetMessageSend extends MessageSend implements ProblemReasons, EvaluationConstants {
Lines 70-75 Link Here
70
			}
71
			}
71
		} else {
72
		} else {
72
			this.receiver.generateCode(currentScope, codeStream, !isStatic);
73
			this.receiver.generateCode(currentScope, codeStream, !isStatic);
74
			if (this.receiverGenericCast != null) 
75
				codeStream.checkcast(this.receiverGenericCast);
76
			codeStream.recordPositionsFrom(pc, this.sourceStart);			
73
		}
77
		}
74
		// generate arguments
78
		// generate arguments
75
		generateArguments(binding, arguments, currentScope, codeStream);
79
		generateArguments(binding, arguments, currentScope, codeStream);
Lines 97-102 Link Here
97
			currentScope.problemReporter().needImplementation();
101
			currentScope.problemReporter().needImplementation();
98
		} else {
102
		} else {
99
			this.receiver.generateCode(currentScope, codeStream, !isStatic);
103
			this.receiver.generateCode(currentScope, codeStream, !isStatic);
104
			if (this.receiverGenericCast != null) 
105
				codeStream.checkcast(this.receiverGenericCast);
106
			codeStream.recordPositionsFrom(pc, this.sourceStart);			
100
		}
107
		}
101
		if (isStatic) {
108
		if (isStatic) {
102
			// we need an object on the stack which is ignored for the method invocation
109
			// we need an object on the stack which is ignored for the method invocation
Lines 139-163 Link Here
139
			codeStream.checkcast(this.codegenBinding.returnType);
146
			codeStream.checkcast(this.codegenBinding.returnType);
140
		}
147
		}
141
	}
148
	}
142
	// operation on the returned value
149
	// required cast must occur even if no value is required
150
	if (this.valueCast != null) codeStream.checkcast(this.valueCast);
143
	if (valueRequired){
151
	if (valueRequired){
144
		// implicit conversion if necessary
152
		// implicit conversion if necessary
145
		if (this.valueCast != null) 
146
			codeStream.checkcast(this.valueCast);
147
		codeStream.generateImplicitConversion(implicitConversion);
153
		codeStream.generateImplicitConversion(implicitConversion);
148
	} else {
154
	} else {
149
		// pop return value if any
155
		boolean isUnboxing = (implicitConversion & TypeIds.UNBOXING) != 0;
150
		switch(binding.returnType.id){
156
		// conversion only generated if unboxing
157
		if (isUnboxing) codeStream.generateImplicitConversion(implicitConversion);
158
		switch (isUnboxing ? postConversionType(currentScope).id : this.codegenBinding.returnType.id) {
151
			case T_long :
159
			case T_long :
152
			case T_double :
160
			case T_double :
153
				codeStream.pop2();
161
				codeStream.pop2();
154
				break;
162
				break;
155
			case T_void :
163
			case T_void :
156
				break;
164
				break;
157
			default:
165
			default :
158
				codeStream.pop();
166
				codeStream.pop();
159
		}
167
		}
160
	}
168
	}	
161
	codeStream.recordPositionsFrom(pc, (int)(this.nameSourcePosition >>> 32)); // highlight selector
169
	codeStream.recordPositionsFrom(pc, (int)(this.nameSourcePosition >>> 32)); // highlight selector
162
}
170
}
163
public void manageSyntheticAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo) {
171
public void manageSyntheticAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo) {
(-)compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java (-57 / +51 lines)
Lines 134-140 Link Here
134
	
134
	
135
		switch (bits & RestrictiveFlagMASK) {
135
		switch (bits & RestrictiveFlagMASK) {
136
			case Binding.FIELD : // reading a field
136
			case Binding.FIELD : // reading a field
137
				if (valueRequired) {
137
				if (valueRequired || currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) {
138
					manageSyntheticAccessIfNecessary(currentScope, flowInfo, true /*read-access*/);
138
					manageSyntheticAccessIfNecessary(currentScope, flowInfo, true /*read-access*/);
139
				}
139
				}
140
				FieldBinding fieldBinding = (FieldBinding) binding;
140
				FieldBinding fieldBinding = (FieldBinding) binding;
Lines 334-339 Link Here
334
			if (valueRequired) {
334
			if (valueRequired) {
335
				codeStream.generateConstant(constant, implicitConversion);
335
				codeStream.generateConstant(constant, implicitConversion);
336
			}
336
			}
337
			codeStream.recordPositionsFrom(pc, this.sourceStart);
338
			return;
337
		} else {
339
		} else {
338
			switch (bits & RestrictiveFlagMASK) {
340
			switch (bits & RestrictiveFlagMASK) {
339
				case Binding.FIELD : // reading a field
341
				case Binding.FIELD : // reading a field
Lines 344-358 Link Here
344
						if (valueRequired) {
346
						if (valueRequired) {
345
							codeStream.generateConstant(fieldConstant, implicitConversion);
347
							codeStream.generateConstant(fieldConstant, implicitConversion);
346
						}
348
						}
347
						break;
349
						codeStream.recordPositionsFrom(pc, this.sourceStart);
350
						return;
348
					}
351
					}
349
					if (fieldBinding.isStatic()) {
352
					if (fieldBinding.isStatic()) {
350
						if (!valueRequired) {
353
						if (!valueRequired
351
							// if no valueRequired, still need possible side-effects of <clinit> invocation, if field belongs to different class
354
							// if no valueRequired, still need possible side-effects of <clinit> invocation, if field belongs to different class
352
							if (((FieldBinding)binding).original().declaringClass == this.actualReceiverType.erasure()
355
							&& ((FieldBinding)binding).original().declaringClass == this.actualReceiverType.erasure()
353
									&& ((implicitConversion & TypeIds.UNBOXING) == 0)) {
356
							&& ((implicitConversion & TypeIds.UNBOXING) == 0)
354
								break;
357
							&& this.genericCast == null) {
355
							}
358
							// if no valueRequired, optimize out entire gen
359
							codeStream.recordPositionsFrom(pc, this.sourceStart);
360
							return;
356
						}
361
						}
357
						// managing private access							
362
						// managing private access							
358
						if ((syntheticAccessors == null) || (syntheticAccessors[READ] == null)) {
363
						if ((syntheticAccessors == null) || (syntheticAccessors[READ] == null)) {
Lines 360-386 Link Here
360
						} else {
365
						} else {
361
							codeStream.invokestatic(syntheticAccessors[READ]);
366
							codeStream.invokestatic(syntheticAccessors[READ]);
362
						}
367
						}
363
						if (valueRequired) {
364
							if (this.genericCast != null) codeStream.checkcast(this.genericCast);
365
							codeStream.generateImplicitConversion(implicitConversion);
366
						} else {
367
							if ((implicitConversion & TypeIds.UNBOXING) != 0) {
368
								codeStream.generateImplicitConversion(implicitConversion);
369
							}
370
							// could occur if !valueRequired but static field belongs to different class
371
							switch (fieldBinding.type.id) {
372
								case T_long :
373
								case T_double :
374
									codeStream.pop2();
375
									break;
376
								default :
377
									codeStream.pop();
378
							}
379
						}							
380
					} else {
368
					} else {
381
						if (!valueRequired && ((implicitConversion & TypeIds.UNBOXING) == 0)) {
369
						if (!valueRequired
370
								&& (implicitConversion & TypeIds.UNBOXING) == 0 
371
								&& this.genericCast == null) {
382
							// if no valueRequired, optimize out entire gen
372
							// if no valueRequired, optimize out entire gen
383
							break;
373
							codeStream.recordPositionsFrom(pc, this.sourceStart);
374
							return;
384
						}
375
						}
385
						// managing enclosing instance access
376
						// managing enclosing instance access
386
						if ((bits & DepthMASK) != 0) {
377
						if ((bits & DepthMASK) != 0) {
Lines 396-439 Link Here
396
						} else {
387
						} else {
397
							codeStream.invokestatic(syntheticAccessors[READ]);
388
							codeStream.invokestatic(syntheticAccessors[READ]);
398
						}
389
						}
399
						// managing generic cast
400
						if (this.genericCast != null) codeStream.checkcast(this.genericCast);			
401
						codeStream.generateImplicitConversion(implicitConversion);
402
					}
390
					}
403
					break;
391
					break;
404
				case Binding.LOCAL : // reading a local
392
				case Binding.LOCAL : // reading a local
405
					LocalVariableBinding localBinding = (LocalVariableBinding) this.codegenBinding;
393
					LocalVariableBinding localBinding = (LocalVariableBinding) this.codegenBinding;
406
					if (valueRequired) {
394
					if (!valueRequired && (implicitConversion & TypeIds.UNBOXING) == 0) {
407
						// outer local?
395
						// if no valueRequired, optimize out entire gen
408
						if ((bits & DepthMASK) != 0) {
396
						codeStream.recordPositionsFrom(pc, this.sourceStart);
409
							// outer local can be reached either through a synthetic arg or a synthetic field
397
						return;
410
							VariableBinding[] path = currentScope.getEmulationPath(localBinding);
411
							codeStream.generateOuterAccess(path, this, localBinding, currentScope);
412
						} else {
413
							// regular local variable read
414
							codeStream.load(localBinding);
415
						}
416
						codeStream.generateImplicitConversion(implicitConversion);
417
					} else if ((implicitConversion & TypeIds.UNBOXING) != 0) {
418
419
						// outer local?
420
						if ((bits & DepthMASK) != 0) {
421
							// outer local can be reached either through a synthetic arg or a synthetic field
422
							VariableBinding[] path = currentScope.getEmulationPath(localBinding);
423
							codeStream.generateOuterAccess(path, this, localBinding, currentScope);
424
						} else {
425
							// regular local variable read
426
							codeStream.load(localBinding);
427
						}
428
						codeStream.generateImplicitConversion(implicitConversion);
429
						if ((localBinding.type == TypeBinding.LONG) || (localBinding.type == TypeBinding.DOUBLE)) {
430
							codeStream.pop2();
431
						} else {
432
							codeStream.pop();
433
						}
434
					}
398
					}
399
					// outer local?
400
					if ((bits & DepthMASK) != 0) {
401
						// outer local can be reached either through a synthetic arg or a synthetic field
402
						VariableBinding[] path = currentScope.getEmulationPath(localBinding);
403
						codeStream.generateOuterAccess(path, this, localBinding, currentScope);
404
					} else {
405
						// regular local variable read
406
						codeStream.load(localBinding);
407
					}
408
					break;
409
				default: // type
410
					codeStream.recordPositionsFrom(pc, this.sourceStart);
411
					return;					
435
			}
412
			}
436
		}
413
		}
414
		// required cast must occur even if no value is required
415
		if (this.genericCast != null) codeStream.checkcast(this.genericCast);
416
		if (valueRequired) {
417
			codeStream.generateImplicitConversion(implicitConversion);
418
		} else {
419
			boolean isUnboxing = (implicitConversion & TypeIds.UNBOXING) != 0;
420
			// conversion only generated if unboxing
421
			if (isUnboxing) codeStream.generateImplicitConversion(implicitConversion);
422
			switch (isUnboxing ? postConversionType(currentScope).id : this.resolvedType.id) {
423
				case T_long :
424
				case T_double :
425
					codeStream.pop2();
426
					break;
427
				default :
428
					codeStream.pop();
429
			}
430
		}							
437
		codeStream.recordPositionsFrom(pc, this.sourceStart);
431
		codeStream.recordPositionsFrom(pc, this.sourceStart);
438
	}
432
	}
439
	/*
433
	/*
(-)compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java (-8 / +10 lines)
Lines 188-195 Link Here
188
		codeStream.recordPositionsFrom(pc, this.sourceStart);
188
		codeStream.recordPositionsFrom(pc, this.sourceStart);
189
		return;
189
		return;
190
	}
190
	}
191
	if (valueRequired || (!isThisReceiver && currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4)
191
	if (valueRequired 
192
			|| ((implicitConversion & TypeIds.UNBOXING) != 0)) {
192
			|| (!isThisReceiver && currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4)
193
			|| ((implicitConversion & TypeIds.UNBOXING) != 0)
194
			|| (this.genericCast != null)) {
193
		receiver.generateCode(currentScope, codeStream, !isStatic);
195
		receiver.generateCode(currentScope, codeStream, !isStatic);
194
		pc = codeStream.position;
196
		pc = codeStream.position;
195
		if (this.codegenBinding.declaringClass == null) { // array length
197
		if (this.codegenBinding.declaringClass == null) { // array length
Lines 210-224 Link Here
210
			} else {
212
			} else {
211
				codeStream.invokestatic(syntheticAccessors[READ]);
213
				codeStream.invokestatic(syntheticAccessors[READ]);
212
			}
214
			}
215
			// required cast must occur even if no value is required
216
			if (this.genericCast != null) codeStream.checkcast(this.genericCast);
213
			if (valueRequired) {
217
			if (valueRequired) {
214
				if (this.genericCast != null) codeStream.checkcast(this.genericCast);
215
				codeStream.generateImplicitConversion(implicitConversion);
218
				codeStream.generateImplicitConversion(implicitConversion);
216
			} else {
219
			} else {
217
				if ((implicitConversion & TypeIds.UNBOXING) != 0) {
220
				boolean isUnboxing = (implicitConversion & TypeIds.UNBOXING) != 0;
218
					codeStream.generateImplicitConversion(implicitConversion);
221
				// conversion only generated if unboxing
219
				}
222
				if (isUnboxing) codeStream.generateImplicitConversion(implicitConversion);
220
				// could occur if !valueRequired but compliance >= 1.4
223
				switch (isUnboxing ? postConversionType(currentScope).id : this.codegenBinding.type.id) {
221
				switch (this.codegenBinding.type.id) {
222
					case T_long :
224
					case T_long :
223
					case T_double :
225
					case T_double :
224
						codeStream.pop2();
226
						codeStream.pop2();
(-)compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java (-6 / +7 lines)
Lines 144-165 Link Here
144
	} else {
144
	} else {
145
		codeStream.invokestatic(syntheticAccessor);
145
		codeStream.invokestatic(syntheticAccessor);
146
	}
146
	}
147
	// operation on the returned value
147
	// required cast must occur even if no value is required
148
	if (this.valueCast != null) codeStream.checkcast(this.valueCast);
148
	if (valueRequired){
149
	if (valueRequired){
149
		// implicit conversion if necessary
150
		// implicit conversion if necessary
150
		if (this.valueCast != null) 
151
			codeStream.checkcast(this.valueCast);
152
		codeStream.generateImplicitConversion(implicitConversion);
151
		codeStream.generateImplicitConversion(implicitConversion);
153
	} else {
152
	} else {
154
		// pop return value if any
153
		boolean isUnboxing = (implicitConversion & TypeIds.UNBOXING) != 0;
155
		switch(binding.returnType.id){
154
		// conversion only generated if unboxing
155
		if (isUnboxing) codeStream.generateImplicitConversion(implicitConversion);
156
		switch (isUnboxing ? postConversionType(currentScope).id : this.codegenBinding.returnType.id) {
156
			case T_long :
157
			case T_long :
157
			case T_double :
158
			case T_double :
158
				codeStream.pop2();
159
				codeStream.pop2();
159
				break;
160
				break;
160
			case T_void :
161
			case T_void :
161
				break;
162
				break;
162
			default:
163
			default :
163
				codeStream.pop();
164
				codeStream.pop();
164
		}
165
		}
165
	}
166
	}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ArrayReference.java (-8 / +10 lines)
Lines 95-108 Link Here
95
		if (valueRequired) {
95
		if (valueRequired) {
96
			codeStream.generateImplicitConversion(implicitConversion);
96
			codeStream.generateImplicitConversion(implicitConversion);
97
		} else {
97
		} else {
98
			if ((implicitConversion & TypeIds.UNBOXING) != 0) {
98
			boolean isUnboxing = (implicitConversion & TypeIds.UNBOXING) != 0;
99
				codeStream.generateImplicitConversion(implicitConversion);
99
			// conversion only generated if unboxing
100
			}
100
			if (isUnboxing) codeStream.generateImplicitConversion(implicitConversion);
101
			if (this.resolvedType == TypeBinding.LONG
101
			switch (isUnboxing ? postConversionType(currentScope).id : this.resolvedType.id) {
102
				|| this.resolvedType == TypeBinding.DOUBLE) {
102
				case T_long :
103
				codeStream.pop2();
103
				case T_double :
104
			} else {
104
					codeStream.pop2();
105
				codeStream.pop();
105
					break;
106
				default :
107
					codeStream.pop();
106
			}
108
			}
107
		}
109
		}
108
		codeStream.recordPositionsFrom(pc, this.sourceStart);
110
		codeStream.recordPositionsFrom(pc, this.sourceStart);
(-)compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java (-24 / +19 lines)
Lines 220-226 Link Here
220
		boolean complyTo14 = currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4;
220
		boolean complyTo14 = currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4;
221
		switch (bits & RestrictiveFlagMASK) {
221
		switch (bits & RestrictiveFlagMASK) {
222
			case Binding.FIELD : // reading a field
222
			case Binding.FIELD : // reading a field
223
				if (needValue) {
223
				if (needValue || complyTo14) {
224
					manageSyntheticAccessIfNecessary(currentScope, (FieldBinding) binding, this.actualReceiverType, 0, flowInfo);
224
					manageSyntheticAccessIfNecessary(currentScope, (FieldBinding) binding, this.actualReceiverType, 0, flowInfo);
225
				}
225
				}
226
				if (this.indexOfFirstFieldBinding == 1) { // was an implicit reference to the first field binding
226
				if (this.indexOfFirstFieldBinding == 1) { // was an implicit reference to the first field binding
Lines 266-272 Link Here
266
		if (otherBindings != null) {
266
		if (otherBindings != null) {
267
			for (int i = 0; i < otherBindingsCount; i++) {
267
			for (int i = 0; i < otherBindingsCount; i++) {
268
				needValue = i < otherBindingsCount-1 ? !otherBindings[i+1].isStatic() : valueRequired;
268
				needValue = i < otherBindingsCount-1 ? !otherBindings[i+1].isStatic() : valueRequired;
269
				if (needValue || (i > 0 && complyTo14)) {
269
				if (needValue || complyTo14) {
270
					TypeBinding lastReceiverType = getGenericCast(i);
270
					TypeBinding lastReceiverType = getGenericCast(i);
271
					if (lastReceiverType == null) {
271
					if (lastReceiverType == null) {
272
						if (i == 0) {
272
						if (i == 0) {
Lines 375-385 Link Here
375
			codeStream.generateImplicitConversion(assignment.implicitConversion);
375
			codeStream.generateImplicitConversion(assignment.implicitConversion);
376
		}
376
		}
377
	}
377
	}
378
	public void generateCode(
378
379
		BlockScope currentScope,
379
	public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {		
380
		CodeStream codeStream,
381
		boolean valueRequired) {
382
			
383
		int pc = codeStream.position;
380
		int pc = codeStream.position;
384
		if (constant != Constant.NotAConstant) {
381
		if (constant != Constant.NotAConstant) {
385
			if (valueRequired) {
382
			if (valueRequired) {
Lines 402-409 Link Here
402
					boolean isFirst = lastFieldBinding == this.binding 
399
					boolean isFirst = lastFieldBinding == this.binding 
403
													&& (this.indexOfFirstFieldBinding == 1 || lastFieldBinding.declaringClass == currentScope.enclosingReceiverType())
400
													&& (this.indexOfFirstFieldBinding == 1 || lastFieldBinding.declaringClass == currentScope.enclosingReceiverType())
404
													&& this.otherBindings == null; // could be dup: next.next.next
401
													&& this.otherBindings == null; // could be dup: next.next.next
405
					if (valueRequired  || (!isFirst && currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4)
402
					TypeBinding requiredGenericCast = getGenericCast(this.otherCodegenBindings == null ? 0 : this.otherCodegenBindings.length);
406
							|| ((implicitConversion & TypeIds.UNBOXING) != 0)) {
403
					if (valueRequired  
404
							|| (!isFirst && currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4)
405
							|| ((implicitConversion & TypeIds.UNBOXING) != 0)
406
							|| requiredGenericCast != null) {
407
						int lastFieldPc = codeStream.position;
407
						int lastFieldPc = codeStream.position;
408
						if (lastFieldBinding.declaringClass == null) { // array length
408
						if (lastFieldBinding.declaringClass == null) { // array length
409
							codeStream.arraylength();
409
							codeStream.arraylength();
Lines 427-449 Link Here
427
							} else {
427
							} else {
428
								codeStream.invokestatic(accessor);
428
								codeStream.invokestatic(accessor);
429
							}
429
							}
430
							TypeBinding requiredGenericCast = getGenericCast(this.otherCodegenBindings == null ? 0 : this.otherCodegenBindings.length);
430
							if (requiredGenericCast != null) codeStream.checkcast(requiredGenericCast);
431
							if (valueRequired) {
431
							if (valueRequired) {
432
								if (requiredGenericCast != null) codeStream.checkcast(requiredGenericCast);
433
								codeStream.generateImplicitConversion(implicitConversion);
432
								codeStream.generateImplicitConversion(implicitConversion);
434
							} else {
433
							} else {
435
								if ((implicitConversion & TypeIds.UNBOXING) != 0) {
434
								boolean isUnboxing = (implicitConversion & TypeIds.UNBOXING) != 0;
436
									codeStream.generateImplicitConversion(implicitConversion);
435
								// conversion only generated if unboxing
437
								}
436
								if (isUnboxing) codeStream.generateImplicitConversion(implicitConversion);
438
								// could occur if !valueRequired but compliance >= 1.4
437
								switch (isUnboxing ? postConversionType(currentScope).id : lastFieldBinding.type.id) {
439
								switch (lastFieldBinding.type.id) {
440
									case T_long :
438
									case T_long :
441
									case T_double :
439
									case T_double :
442
										codeStream.pop2();
440
										codeStream.pop2();
443
										break;
441
										break;
444
									default :
442
									default :
445
										codeStream.pop();
443
										codeStream.pop();
446
								}							
444
								}
447
							}
445
							}
448
						}
446
						}
449
						
447
						
Lines 594-600 Link Here
594
				if (lastFieldBinding.constant() != Constant.NotAConstant) {
592
				if (lastFieldBinding.constant() != Constant.NotAConstant) {
595
					break;
593
					break;
596
				}
594
				}
597
				if (needValue && !lastFieldBinding.isStatic()) {
595
				if ((needValue && !lastFieldBinding.isStatic()) || lastGenericCast != null) {
598
					int pc = codeStream.position;
596
					int pc = codeStream.position;
599
					if ((bits & DepthMASK) != 0) {
597
					if ((bits & DepthMASK) != 0) {
600
						ReferenceBinding targetType = currentScope.enclosingSourceType().enclosingTypeAt((bits & DepthMASK) >> DepthSHIFT);
598
						ReferenceBinding targetType = currentScope.enclosingSourceType().enclosingTypeAt((bits & DepthMASK) >> DepthSHIFT);
Lines 647-653 Link Here
647
							codeStream.generateConstant(fieldConstant, 0);
645
							codeStream.generateConstant(fieldConstant, 0);
648
						}
646
						}
649
					} else {
647
					} else {
650
						if (needValue || (i > 0 && complyTo14)) {
648
						if (needValue || (i > 0 && complyTo14) || lastGenericCast != null) {
651
							MethodBinding accessor = syntheticReadAccessors == null ? null : syntheticReadAccessors[i]; 
649
							MethodBinding accessor = syntheticReadAccessors == null ? null : syntheticReadAccessors[i]; 
652
							if (accessor == null) {
650
							if (accessor == null) {
653
								if (lastFieldBinding.isStatic()) {
651
								if (lastFieldBinding.isStatic()) {
Lines 658-668 Link Here
658
							} else {
656
							} else {
659
								codeStream.invokestatic(accessor);
657
								codeStream.invokestatic(accessor);
660
							}
658
							}
661
							if (needValue) {
659
							if (lastGenericCast != null) codeStream.checkcast(lastGenericCast);
662
								if (lastGenericCast != null) codeStream.checkcast(lastGenericCast);
660
							if (!needValue) codeStream.pop();
663
							} else {
664
								codeStream.pop();
665
							}
666
						} else {
661
						} else {
667
							if (this.codegenBinding == lastFieldBinding) {
662
							if (this.codegenBinding == lastFieldBinding) {
668
								if (lastFieldBinding.isStatic()){
663
								if (lastFieldBinding.isStatic()){
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java (+18 lines)
Lines 131-137 Link Here
131
		"The assignment to variable next has no effect\n" + 
131
		"The assignment to variable next has no effect\n" + 
132
		"----------\n");
132
		"----------\n");
133
}
133
}
134
public void test003() {
135
	this.runConformTest(
136
		new String[] {
137
			"X.java",
138
			"public class X {\n" + 
139
			"	int portNumber;\n" + 
140
			"	public static void main(String[] args) {\n" + 
141
			"		X x = new X();\n" + 
142
			"		x.portNumber = Integer.parseInt(\"12\");\n" + 
143
			"		x.run();\n" + 
144
			"	}\n" + 
145
			"	private void run() {\n" + 
146
			"		System.out.println(portNumber);\n" + 
147
			"	}\n" + 
148
			"}", // =================
134
149
150
		},
151
		"12");
152
}
135
// final multiple assignment
153
// final multiple assignment
136
public void test020() {
154
public void test020() {
137
	this.runNegativeTest(
155
	this.runNegativeTest(
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (-33 / +337 lines)
Lines 15129-15148 Link Here
15129
			"     6  dup\n" + 
15129
			"     6  dup\n" + 
15130
			"     7  invokespecial X() [28]\n" + 
15130
			"     7  invokespecial X() [28]\n" + 
15131
			"    10  getfield X.e : XA [29]\n" + 
15131
			"    10  getfield X.e : XA [29]\n" + 
15132
			"    13  pop\n" + 
15132
			"    13  checkcast XAB [31]\n" + 
15133
			"    14  getstatic XAB.CONST : XB [31]\n" + 
15133
			"    16  pop\n" + 
15134
			"    17  invokevirtual java.io.PrintStream.print(java.lang.Object) : void [37]\n" + 
15134
			"    17  getstatic XAB.CONST : XB [33]\n" + 
15135
			"    20  new X [1]\n" + 
15135
			"    20  invokevirtual java.io.PrintStream.print(java.lang.Object) : void [37]\n" + 
15136
			"    23  dup\n" + 
15136
			"    23  new X [1]\n" + 
15137
			"    24  invokespecial X() [28]\n" + 
15137
			"    26  dup\n" + 
15138
			"    27  invokevirtual X.foo() : void [43]\n" + 
15138
			"    27  invokespecial X() [28]\n" + 
15139
			"    30  return\n" + 
15139
			"    30  invokevirtual X.foo() : void [43]\n" + 
15140
			"    33  return\n" + 
15140
			"      Line numbers:\n" + 
15141
			"      Line numbers:\n" + 
15141
			"        [pc: 0, line: 10]\n" + 
15142
			"        [pc: 0, line: 10]\n" + 
15142
			"        [pc: 20, line: 11]\n" + 
15143
			"        [pc: 23, line: 11]\n" + 
15143
			"        [pc: 30, line: 12]\n" + 
15144
			"        [pc: 33, line: 12]\n" + 
15144
			"      Local variable table:\n" + 
15145
			"      Local variable table:\n" + 
15145
			"        [pc: 0, pc: 31] local: args index: 0 type: java.lang.String[]\n" + 
15146
			"        [pc: 0, pc: 34] local: args index: 0 type: java.lang.String[]\n" + 
15146
			"  \n" + 
15147
			"  \n" + 
15147
			"  // Method descriptor #10 ()V\n" + 
15148
			"  // Method descriptor #10 ()V\n" + 
15148
			"  // Stack: 2, Locals: 1\n" + 
15149
			"  // Stack: 2, Locals: 1\n" + 
Lines 15238-15257 Link Here
15238
			"     6  dup\n" + 
15239
			"     6  dup\n" + 
15239
			"     7  invokespecial X() [28]\n" + 
15240
			"     7  invokespecial X() [28]\n" + 
15240
			"    10  invokevirtual X.e() : XA [29]\n" + 
15241
			"    10  invokevirtual X.e() : XA [29]\n" + 
15241
			"    13  pop\n" + 
15242
			"    13  checkcast XAB [31]\n" + 
15242
			"    14  getstatic XAB.CONST : XB [31]\n" + 
15243
			"    16  pop\n" + 
15243
			"    17  invokevirtual java.io.PrintStream.print(java.lang.Object) : void [37]\n" + 
15244
			"    17  getstatic XAB.CONST : XB [33]\n" + 
15244
			"    20  new X [1]\n" + 
15245
			"    20  invokevirtual java.io.PrintStream.print(java.lang.Object) : void [37]\n" + 
15245
			"    23  dup\n" + 
15246
			"    23  new X [1]\n" + 
15246
			"    24  invokespecial X() [28]\n" + 
15247
			"    26  dup\n" + 
15247
			"    27  invokevirtual X.foo() : void [43]\n" + 
15248
			"    27  invokespecial X() [28]\n" + 
15248
			"    30  return\n" + 
15249
			"    30  invokevirtual X.foo() : void [43]\n" + 
15250
			"    33  return\n" + 
15249
			"      Line numbers:\n" + 
15251
			"      Line numbers:\n" + 
15250
			"        [pc: 0, line: 10]\n" + 
15252
			"        [pc: 0, line: 10]\n" + 
15251
			"        [pc: 20, line: 11]\n" + 
15253
			"        [pc: 23, line: 11]\n" + 
15252
			"        [pc: 30, line: 12]\n" + 
15254
			"        [pc: 33, line: 12]\n" + 
15253
			"      Local variable table:\n" + 
15255
			"      Local variable table:\n" + 
15254
			"        [pc: 0, pc: 31] local: args index: 0 type: java.lang.String[]\n" + 
15256
			"        [pc: 0, pc: 34] local: args index: 0 type: java.lang.String[]\n" + 
15255
			"  \n" + 
15257
			"  \n" + 
15256
			"  // Method descriptor #6 ()V\n" + 
15258
			"  // Method descriptor #6 ()V\n" + 
15257
			"  // Stack: 2, Locals: 1\n" + 
15259
			"  // Stack: 2, Locals: 1\n" + 
Lines 15360-15377 Link Here
15360
			"     5  invokespecial X$1(X) [30]\n" + 
15362
			"     5  invokespecial X$1(X) [30]\n" + 
15361
			"     8  invokevirtual X$1.run() : void [33]\n" + 
15363
			"     8  invokevirtual X$1.run() : void [33]\n" + 
15362
			"    11  getstatic java.lang.System.out : java.io.PrintStream [36]\n" + 
15364
			"    11  getstatic java.lang.System.out : java.io.PrintStream [36]\n" + 
15363
			"    14  getstatic XB.CONST : XB [42]\n" + 
15365
			"    14  aload_0 [this]\n" + 
15364
			"    17  invokevirtual java.io.PrintStream.print(java.lang.Object) : void [48]\n" + 
15366
			"    15  getfield X.e : XA [42]\n" + 
15365
			"    20  return\n" + 
15367
			"    18  checkcast XB [44]\n" + 
15368
			"    21  pop\n" + 
15369
			"    22  getstatic XB.CONST : XB [46]\n" + 
15370
			"    25  invokevirtual java.io.PrintStream.print(java.lang.Object) : void [50]\n" + 
15371
			"    28  return\n" + 
15366
			"      Line numbers:\n" + 
15372
			"      Line numbers:\n" + 
15367
			"        [pc: 0, line: 13]\n" + 
15373
			"        [pc: 0, line: 13]\n" + 
15368
			"        [pc: 8, line: 17]\n" + 
15374
			"        [pc: 8, line: 17]\n" + 
15369
			"        [pc: 11, line: 18]\n" + 
15375
			"        [pc: 11, line: 18]\n" + 
15370
			"        [pc: 20, line: 19]\n" + 
15376
			"        [pc: 28, line: 19]\n" + 
15371
			"      Local variable table:\n" + 
15377
			"      Local variable table:\n" + 
15372
			"        [pc: 0, pc: 21] local: this index: 0 type: X\n" + 
15378
			"        [pc: 0, pc: 29] local: this index: 0 type: X\n" + 
15373
			"      Local variable type table:\n" + 
15379
			"      Local variable type table:\n" + 
15374
			"        [pc: 0, pc: 21] local: this index: 0 type: X<E>\n";
15380
			"        [pc: 0, pc: 29] local: this index: 0 type: X<E>\n";
15375
		
15381
		
15376
		try {
15382
		try {
15377
			File f = new File(OUTPUT_DIR + File.separator + "X.class");
15383
			File f = new File(OUTPUT_DIR + File.separator + "X.class");
Lines 33663-33669 Link Here
33663
		"     5  ldc <String \"[B.local_field]\"> [32]\n" + 
33669
		"     5  ldc <String \"[B.local_field]\"> [32]\n" + 
33664
		"     7  invokestatic A.foo(java.lang.String) : Value [17]\n" + 
33670
		"     7  invokestatic A.foo(java.lang.String) : Value [17]\n" + 
33665
		"    10  putfield B.local_field : Value [34]\n" + 
33671
		"    10  putfield B.local_field : Value [34]\n" + 
33666
		"    13  getstatic I.CONST : Value [36]\n" + 
33672
		"    13  getstatic B.CONST : Value [36]\n" + 
33667
		"    16  pop\n" + 
33673
		"    16  pop\n" + 
33668
		"    17  getstatic Value.NAME : java.lang.String [39]\n" + 
33674
		"    17  getstatic Value.NAME : java.lang.String [39]\n" + 
33669
		"    20  pop\n" + 
33675
		"    20  pop\n" + 
Lines 36736-36743 Link Here
36736
		},
36742
		},
36737
		"");		
36743
		"");		
36738
}
36744
}
36739
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176591
36745
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=176591
36740
// ?: cuts assignment context
36746
//?: cuts assignment context
36741
public void test1109() {
36747
public void test1109() {
36742
	this.runNegativeTest(
36748
	this.runNegativeTest(
36743
		new String[] {
36749
		new String[] {
Lines 36763-36770 Link Here
36763
		"Type mismatch: cannot convert from Y<Object> to Y<String>\n" + 
36769
		"Type mismatch: cannot convert from Y<Object> to Y<String>\n" + 
36764
		"----------\n");		
36770
		"----------\n");		
36765
}
36771
}
36766
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176591
36772
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=176591
36767
// variant
36773
//variant
36768
public void test1110() {
36774
public void test1110() {
36769
	this.runConformTest(
36775
	this.runConformTest(
36770
		new String[] {
36776
		new String[] {
Lines 36785-36788 Link Here
36785
		},
36791
		},
36786
		"");		
36792
		"");		
36787
}
36793
}
36794
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194
36795
public void test1111() {
36796
	Map settings = getCompilerOptions();
36797
	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
36798
	this.runConformTest(
36799
		new String[] {
36800
			"X.java",
36801
			"class A<T> {\n" + 
36802
			"        public T foo(Object o) {\n" + 
36803
			"                return (T) o; // should get unchecked warning\n" + 
36804
			"        }\n" + 
36805
			"}\n" + 
36806
			"\n" + 
36807
			"public class X {\n" + 
36808
			"        public static void main(String[] args) {\n" + 
36809
			"                A<X> a = new A<X>();\n" + 
36810
			"                try {\n" + 
36811
			"	                X s = a.foo(new Object());\n" + 
36812
			"                } catch(ClassCastException e) {\n" + 
36813
			"                	System.out.println(\"SUCCESS\");\n" + 
36814
			"                	return;\n" + 
36815
			"                }\n" + 
36816
			"            	System.out.println(\"FAILED\");\n" + 
36817
			"        }\n" + 
36818
			"}\n", // =================
36819
		},
36820
		"SUCCESS",
36821
		null,
36822
		true,
36823
		null,
36824
		settings,
36825
		null);		
36826
}
36827
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation
36828
public void test1112() {
36829
	Map settings = getCompilerOptions();
36830
	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
36831
	this.runConformTest(
36832
		new String[] {
36833
			"X.java",
36834
			"class A<T> {\n" + 
36835
			"        public T foo;\n" +
36836
			"}\n" + 
36837
			"\n" + 
36838
			"public class X {\n" + 
36839
			"        public static void main(String[] args) {\n" + 
36840
			"                A<X> a = new A<X>();\n" + 
36841
			"				 A ua = a;\n" +
36842
			"				 ua.foo = new Object();\n" +
36843
			"                try {\n" + 
36844
			"	                X s = a.foo;\n" + 
36845
			"                } catch(ClassCastException e) {\n" + 
36846
			"                	System.out.println(\"SUCCESS\");\n" + 
36847
			"                	return;\n" + 
36848
			"                }\n" + 
36849
			"            	System.out.println(\"FAILED\");\n" + 
36850
			"        }\n" + 
36851
			"}\n", // =================
36852
		},
36853
		"SUCCESS",
36854
		null,
36855
		true,
36856
		null,
36857
		settings,
36858
		null);		
36859
}
36860
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation
36861
public void test1113() {
36862
	Map settings = getCompilerOptions();
36863
	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
36864
	this.runConformTest(
36865
		new String[] {
36866
			"X.java",
36867
			"class A<T> {\n" + 
36868
			"        public T foo;\n" +
36869
			"}\n" + 
36870
			"\n" + 
36871
			"public class X extends A<X>{\n" + 
36872
			"        public static void main(String[] args) {\n" + 
36873
			"			new X().foo();\n" +
36874
			"		 }\n" +
36875
			" 		 public void foo() {\n" +
36876
			"				 A ua = this;\n" +
36877
			"				 ua.foo = new Object();\n" +
36878
			"                try {\n" + 
36879
			"	                X s = foo;\n" + 
36880
			"                } catch(ClassCastException e) {\n" + 
36881
			"                	System.out.println(\"SUCCESS\");\n" + 
36882
			"                	return;\n" + 
36883
			"                }\n" + 
36884
			"            	System.out.println(\"FAILED\");\n" + 
36885
			"        }\n" + 
36886
			"}\n", // =================
36887
		},
36888
		"SUCCESS",
36889
		null,
36890
		true,
36891
		null,
36892
		settings,
36893
		null);		
36894
}
36895
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation
36896
public void test1114() {
36897
	Map settings = getCompilerOptions();
36898
	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
36899
	this.runConformTest(
36900
		new String[] {
36901
			"X.java",
36902
			"class A<T> {\n" + 
36903
			"        public T foo;\n" +
36904
			"}\n" + 
36905
			"\n" + 
36906
			"public class X extends A<X>{\n" + 
36907
			"        public static void main(String[] args) {\n" + 
36908
			"			new X().foo();\n" +
36909
			"		 }\n" +
36910
			" 		 public void foo() {\n" +
36911
			"				 A ua = this;\n" +
36912
			"				 ua.foo = new Object();\n" +
36913
			"                try {\n" + 
36914
			"	                X s = this.foo;\n" + 
36915
			"                } catch(ClassCastException e) {\n" + 
36916
			"                	System.out.println(\"SUCCESS\");\n" + 
36917
			"                	return;\n" + 
36918
			"                }\n" + 
36919
			"            	System.out.println(\"FAILED\");\n" + 
36920
			"        }\n" + 
36921
			"}\n", // =================
36922
		},
36923
		"SUCCESS",
36924
		null,
36925
		true,
36926
		null,
36927
		settings,
36928
		null);		
36929
}
36930
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation
36931
public void test1115() {
36932
	Map settings = getCompilerOptions();
36933
	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
36934
	this.runConformTest(
36935
		new String[] {
36936
			"X.java",
36937
			"class A<T> {\n" + 
36938
			"        public T foo;\n" +
36939
			"}\n" + 
36940
			"\n" + 
36941
			"public class X {\n" + 
36942
			"		 static X ROOT;\n" +
36943
			"        public static void main(String[] args) {\n" + 
36944
			"                A<X> a = new A<X>();\n" + 
36945
			"				 A ua = a;\n" +
36946
			"				 ua.foo = new Object();\n" +
36947
			"                try {\n" + 
36948
			"	                X s = a.foo.ROOT;\n" + 
36949
			"                } catch(ClassCastException e) {\n" + 
36950
			"                	System.out.println(\"SUCCESS\");\n" + 
36951
			"                	return;\n" + 
36952
			"                }\n" + 
36953
			"            	System.out.println(\"FAILED\");\n" + 
36954
			"        }\n" + 
36955
			"}\n", // =================
36956
		},
36957
		"SUCCESS",
36958
		null,
36959
		true,
36960
		null,
36961
		settings,
36962
		null);		
36963
}
36964
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation
36965
public void test1116() {
36966
	this.runConformTest(
36967
		new String[] {
36968
			"X.java",
36969
			"import java.io.Serializable;\n" + 
36970
			"\n" + 
36971
			"interface I {\n" + 
36972
			"    int CONST = 1;\n" + 
36973
			"}\n" + 
36974
			"\n" + 
36975
			"class Z<T extends Serializable&I> {\n" + 
36976
			"    T c;\n" + 
36977
			"    Z(T c) {\n" + 
36978
			"        this.c = c;\n" + 
36979
			"    }\n" + 
36980
			"    int foo() {\n" + 
36981
			"        return c.CONST;\n" + 
36982
			"    }\n" + 
36983
			"}\n" + 
36984
			"\n" + 
36985
			"public class X implements Serializable, I {\n" + 
36986
			"    public static void main(String argv[]) {\n" + 
36987
			"        Z<X> z = new Z<X>(new X());\n" + 
36988
			"        Z rawz = z;\n" + 
36989
			"        rawz.c = new Serializable(){};\n" + 
36990
			"        try {\n" + 
36991
			"	        z.foo();\n" + 
36992
			"        } catch(ClassCastException e) {\n" + 
36993
			"        	System.out.println(\"SUCCESS\");\n" + 
36994
			"        }\n" + 
36995
			"    }\n" + 
36996
			"}\n", // =================
36997
		},
36998
		"SUCCESS");		
36999
}
37000
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation
37001
public void test1117() {
37002
	Map options = getCompilerOptions();
37003
	options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
37004
	this.runConformTest(
37005
		new String[] {
37006
			"X.java",
37007
			"interface I<T> {\n" + 
37008
			"	Value<String> CONST = null;\n" + 
37009
			"}\n" + 
37010
			"class Value<V> {\n" + 
37011
			"	String NAME = \"VALUE\";\n" + 
37012
			"}\n" + 
37013
			"class B<V> implements I<V> {\n" + 
37014
			"	B(Value<String> param) {\n" + 
37015
			"		Value<String> v0 = CONST;\n" + 
37016
			"		Value<String> v1 = this.CONST;\n" + 
37017
			"		String s2 = CONST.NAME;\n" + 
37018
			"		Value<String> v3 = I.CONST;\n" + 
37019
			"		Value<String> v4 = B.CONST;\n" + 
37020
			"	}\n" + 
37021
			"}\n" + 
37022
			"public class X {\n" + 
37023
			"	public static void main(String[] args) {\n" + 
37024
			"		try {\n" + 
37025
			"			new B<String>(new Value<String>());\n" + 
37026
			"		} catch(NullPointerException e) {\n" + 
37027
			"			System.out.println(\"SUCCESS\");\n" + 
37028
			"		}\n" + 
37029
			"	}\n" + 
37030
			"}\n", // =================
37031
		}, 
37032
		"SUCCESS",
37033
		null,
37034
		false,
37035
		null,
37036
		options,
37037
		null);
37038
	// check the reference to I.CONST is generated as B.CONST, except for v3 still issuing I.CONST
37039
	String expectedOutput = 
37040
		"  // Method descriptor #8 (LValue;)V\n" + 
37041
		"  // Signature: (LValue<Ljava/lang/String;>;)V\n" + 
37042
		"  // Stack: 1, Locals: 2\n" + 
37043
		"  B(Value param);\n" + 
37044
		"     0  aload_0 [this]\n" + 
37045
		"     1  invokespecial java.lang.Object() [12]\n" + 
37046
		"     4  getstatic B.CONST : Value [15]\n" + 
37047
		"     7  pop\n" + 
37048
		"     8  getstatic B.CONST : Value [15]\n" + 
37049
		"    11  pop\n" + 
37050
		"    12  getstatic B.CONST : Value [15]\n" + 
37051
		"    15  getfield Value.NAME : java.lang.String [19]\n" + 
37052
		"    18  pop\n" + 
37053
		"    19  getstatic I.CONST : Value [25]\n" + 
37054
		"    22  pop\n" + 
37055
		"    23  getstatic B.CONST : Value [15]\n" + 
37056
		"    26  pop\n" + 
37057
		"    27  return\n" + 
37058
		"      Line numbers:\n" + 
37059
		"        [pc: 0, line: 8]\n" + 
37060
		"        [pc: 4, line: 9]\n" + 
37061
		"        [pc: 8, line: 10]\n" + 
37062
		"        [pc: 12, line: 11]\n" + 
37063
		"        [pc: 19, line: 12]\n" + 
37064
		"        [pc: 23, line: 13]\n" + 
37065
		"        [pc: 27, line: 14]\n" + 
37066
		"      Local variable table:\n" + 
37067
		"        [pc: 0, pc: 28] local: this index: 0 type: B\n" + 
37068
		"        [pc: 0, pc: 28] local: param index: 1 type: Value\n" + 
37069
		"      Local variable type table:\n" + 
37070
		"        [pc: 0, pc: 28] local: this index: 0 type: B<V>\n" + 
37071
		"        [pc: 0, pc: 28] local: param index: 1 type: Value<java.lang.String>\n";
37072
37073
	try {
37074
		File f = new File(OUTPUT_DIR + File.separator + "B.class");
37075
		byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
37076
		ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
37077
		String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED);
37078
		int index = result.indexOf(expectedOutput);
37079
		if (index == -1 || expectedOutput.length() == 0) {
37080
			System.out.println(Util.displayString(result, 3));
37081
		}
37082
		if (index == -1) {
37083
			assertEquals("Wrong contents", expectedOutput, result);
37084
		}
37085
	} catch (org.eclipse.jdt.core.util.ClassFormatException e) {
37086
		assertTrue(false);
37087
	} catch (IOException e) {
37088
		assertTrue(false);
37089
	}			
37090
}
37091
36788
}
37092
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AutoBoxingTest.java (+367 lines)
Lines 3969-3972 Link Here
3969
		},
3969
		},
3970
		"SUCCESS");
3970
		"SUCCESS");
3971
}
3971
}
3972
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372
3973
public void test135() {
3974
	Map settings = getCompilerOptions();
3975
	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
3976
	this.runConformTest(
3977
		new String[] {
3978
			"X.java",
3979
			"class A<T> {\n" + 
3980
			"        public T foo() { return null; }\n" + 
3981
			"}\n" + 
3982
			"\n" + 
3983
			"public class X {\n" + 
3984
			"        public static void main(String[] args) {\n" + 
3985
			"                A<Long> a = new A<Long>();\n" + 
3986
			"				 A ua = a;\n" + 
3987
			"                try {\n" + 
3988
			"	                long s = a.foo();\n" + 
3989
			"                } catch(NullPointerException e) {\n" + 
3990
			"                	System.out.println(\"SUCCESS\");\n" + 
3991
			"                	return;\n" + 
3992
			"                }\n" + 
3993
			"            	System.out.println(\"FAILED\");\n" + 
3994
			"        }\n" + 
3995
			"}\n", // =================
3996
		},
3997
		"SUCCESS",
3998
		null,
3999
		true,
4000
		null,
4001
		settings,
4002
		null);		
4003
}
4004
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation
4005
public void test136() {
4006
	Map settings = getCompilerOptions();
4007
	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
4008
	this.runConformTest(
4009
		new String[] {
4010
			"X.java",
4011
			"class A<T> {\n" + 
4012
			"        public T foo(Object o) {\n" + 
4013
			"                return (T) o; // should get unchecked warning\n" + 
4014
			"        }\n" + 
4015
			"}\n" + 
4016
			"\n" + 
4017
			"public class X {\n" + 
4018
			"        public static void main(String[] args) {\n" + 
4019
			"                A<Long> a = new A<Long>();\n" + 
4020
			"                try {\n" + 
4021
			"	                long s = a.foo(new Object());\n" + 
4022
			"                } catch(ClassCastException e) {\n" + 
4023
			"                	System.out.println(\"SUCCESS\");\n" + 
4024
			"                	return;\n" + 
4025
			"                }\n" + 
4026
			"            	System.out.println(\"FAILED\");\n" + 
4027
			"        }\n" + 
4028
			"}\n", // =================
4029
		},
4030
		"SUCCESS",
4031
		null,
4032
		true,
4033
		null,
4034
		settings,
4035
		null);		
4036
}
4037
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation
4038
public void test137() {
4039
	Map settings = getCompilerOptions();
4040
	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
4041
	this.runConformTest(
4042
		new String[] {
4043
			"X.java",
4044
			"class A<T> {\n" + 
4045
			"        public T foo;\n" +
4046
			"}\n" + 
4047
			"\n" + 
4048
			"public class X {\n" + 
4049
			"        public static void main(String[] args) {\n" + 
4050
			"                A<Long> a = new A<Long>();\n" + 
4051
			"				 A ua = a;\n" +
4052
			"				 ua.foo = new Object();\n" +
4053
			"                try {\n" + 
4054
			"	                long s = a.foo;\n" + 
4055
			"                } catch(ClassCastException e) {\n" + 
4056
			"                	System.out.println(\"SUCCESS\");\n" + 
4057
			"                	return;\n" + 
4058
			"                }\n" + 
4059
			"            	System.out.println(\"FAILED\");\n" + 
4060
			"        }\n" + 
4061
			"}\n", // =================
4062
		},
4063
		"SUCCESS",
4064
		null,
4065
		true,
4066
		null,
4067
		settings,
4068
		null);		
4069
}
4070
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation
4071
public void test138() {
4072
	Map settings = getCompilerOptions();
4073
	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
4074
	this.runConformTest(
4075
		new String[] {
4076
			"X.java",
4077
			"class A<T> {\n" + 
4078
			"        public T foo;\n" +
4079
			"}\n" + 
4080
			"\n" + 
4081
			"public class X extends A<Long>{\n" + 
4082
			"        public static void main(String[] args) {\n" + 
4083
			"			new X().foo();\n" +
4084
			"		 }\n" +
4085
			" 		 public void foo() {\n" +
4086
			"				 A ua = this;\n" +
4087
			"				 ua.foo = new Object();\n" +
4088
			"                try {\n" + 
4089
			"	                long s = foo;\n" + 
4090
			"                } catch(ClassCastException e) {\n" + 
4091
			"                	System.out.println(\"SUCCESS\");\n" + 
4092
			"                	return;\n" + 
4093
			"                }\n" + 
4094
			"            	System.out.println(\"FAILED\");\n" + 
4095
			"        }\n" + 
4096
			"}\n", // =================
4097
		},
4098
		"SUCCESS",
4099
		null,
4100
		true,
4101
		null,
4102
		settings,
4103
		null);		
4104
}
4105
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation
4106
public void test139() {
4107
	Map settings = getCompilerOptions();
4108
	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
4109
	this.runConformTest(
4110
		new String[] {
4111
			"X.java",
4112
			"class A<T> {\n" + 
4113
			"        public T foo;\n" +
4114
			"}\n" + 
4115
			"\n" + 
4116
			"public class X extends A<Long>{\n" + 
4117
			"        public static void main(String[] args) {\n" + 
4118
			"			new X().foo();\n" +
4119
			"		 }\n" +
4120
			" 		 public void foo() {\n" +
4121
			"				 A ua = this;\n" +
4122
			"				 ua.foo = new Object();\n" +
4123
			"                try {\n" + 
4124
			"	                long s = this.foo;\n" + 
4125
			"                } catch(ClassCastException e) {\n" + 
4126
			"                	System.out.println(\"SUCCESS\");\n" + 
4127
			"                	return;\n" + 
4128
			"                }\n" + 
4129
			"            	System.out.println(\"FAILED\");\n" + 
4130
			"        }\n" + 
4131
			"}\n", // =================
4132
		},
4133
		"SUCCESS",
4134
		null,
4135
		true,
4136
		null,
4137
		settings,
4138
		null);		
4139
}
4140
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation
4141
public void test140() {
4142
	Map settings = getCompilerOptions();
4143
	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
4144
	this.runConformTest(
4145
		new String[] {
4146
			"X.java",
4147
			"class A {\n" + 
4148
			"        long foo() {\n" + 
4149
			"                return 0L;\n" + 
4150
			"        }\n" + 
4151
			"}\n" + 
4152
			"\n" + 
4153
			"public class X {\n" + 
4154
			"        public static void main(String[] args) {\n" + 
4155
			"                A a = new A();\n" + 
4156
			"	             Long s = a.foo();\n" + 
4157
			"                System.out.println(\"SUCCESS\");\n" + 
4158
			"        }\n" + 
4159
			"}\n", // =================
4160
		},
4161
		"SUCCESS",
4162
		null,
4163
		true,
4164
		null,
4165
		settings,
4166
		null);		
4167
}
4168
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation
4169
public void test141() {
4170
	Map settings = getCompilerOptions();
4171
	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
4172
	this.runConformTest(
4173
		new String[] {
4174
			"X.java",
4175
			"class A {\n" + 
4176
			"        long foo = 0L;\n" + 
4177
			"}\n" + 
4178
			"\n" + 
4179
			"public class X {\n" + 
4180
			"        public static void main(String[] args) {\n" + 
4181
			"                A a = new A();\n" + 
4182
			"	             Long s = a.foo;\n" + 
4183
			"                System.out.println(\"SUCCESS\");\n" + 
4184
			"        }\n" + 
4185
			"}\n", // =================
4186
		},
4187
		"SUCCESS",
4188
		null,
4189
		true,
4190
		null,
4191
		settings,
4192
		null);		
4193
}
4194
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation
4195
public void test142() {
4196
	Map settings = getCompilerOptions();
4197
	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
4198
	this.runConformTest(
4199
		new String[] {
4200
			"X.java",
4201
			"class A {\n" + 
4202
			"        long foo = 0L;\n" + 
4203
			"}\n" + 
4204
			"\n" + 
4205
			"public class X extends A {\n" + 
4206
			"        public static void main(String[] args) {\n" + 
4207
			"			new X().bar();\n" +
4208
			"        }\n" + 
4209
			"		void bar() {\n" +
4210
			"	             Long s = foo;\n" + 
4211
			"                System.out.println(\"SUCCESS\");\n" + 
4212
			"        }\n" + 
4213
			"}\n", // =================			
4214
		},
4215
		"SUCCESS",
4216
		null,
4217
		true,
4218
		null,
4219
		settings,
4220
		null);		
4221
}
4222
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation
4223
public void test143() {
4224
	Map settings = getCompilerOptions();
4225
	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
4226
	this.runConformTest(
4227
		new String[] {
4228
			"X.java",
4229
			"class A {\n" + 
4230
			"        long foo = 0L;\n" + 
4231
			"}\n" + 
4232
			"\n" + 
4233
			"public class X extends A {\n" + 
4234
			"        public static void main(String[] args) {\n" + 
4235
			"			new X().bar();\n" +
4236
			"        }\n" + 
4237
			"		void bar() {\n" +
4238
			"	             Long s = this.foo;\n" + 
4239
			"                System.out.println(\"SUCCESS\");\n" + 
4240
			"        }\n" + 
4241
			"}\n", // =================			
4242
		},
4243
		"SUCCESS",
4244
		null,
4245
		true,
4246
		null,
4247
		settings,
4248
		null);		
4249
}
4250
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation
4251
public void test144() {
4252
	Map settings = getCompilerOptions();
4253
	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
4254
	this.runConformTest(
4255
		new String[] {
4256
			"X.java",
4257
			"class A<T> {\n" + 
4258
			"        public T[] foo;\n" +
4259
			"}\n" + 
4260
			"\n" + 
4261
			"public class X extends A<Long>{\n" + 
4262
			"        public static void main(String[] args) {\n" + 
4263
			"			new X().foo();\n" +
4264
			"		 }\n" +
4265
			" 		 public void foo() {\n" +
4266
			"				 A ua = this;\n" +
4267
			"				 ua.foo = new Object[1];\n" +
4268
			"                try {\n" + 
4269
			"	                long s = this.foo[0];\n" + 
4270
			"                } catch(ClassCastException e) {\n" + 
4271
			"                	System.out.println(\"SUCCESS\");\n" + 
4272
			"                	return;\n" + 
4273
			"                }\n" + 
4274
			"            	System.out.println(\"FAILED\");\n" + 
4275
			"        }\n" + 
4276
			"}\n", // =================
4277
		},
4278
		"SUCCESS",
4279
		null,
4280
		true,
4281
		null,
4282
		settings,
4283
		null);		
4284
}
4285
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation
4286
public void test145() {
4287
	Map settings = getCompilerOptions();
4288
	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
4289
	this.runConformTest(
4290
		new String[] {
4291
			"X.java",
4292
			"class A {\n" + 
4293
			"        long[] foo = { 0L };\n" + 
4294
			"}\n" + 
4295
			"\n" + 
4296
			"public class X extends A {\n" + 
4297
			"        public static void main(String[] args) {\n" + 
4298
			"			new X().bar();\n" +
4299
			"        }\n" + 
4300
			"		void bar() {\n" +
4301
			"	             Long s = this.foo[0];\n" + 
4302
			"                System.out.println(\"SUCCESS\");\n" + 
4303
			"        }\n" + 
4304
			"}\n", // =================			
4305
		},
4306
		"SUCCESS",
4307
		null,
4308
		true,
4309
		null,
4310
		settings,
4311
		null);		
4312
}
4313
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation
4314
public void test146() {
4315
	Map settings = getCompilerOptions();
4316
	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
4317
	this.runConformTest(
4318
		new String[] {
4319
			"X.java",
4320
			"class A<T> {\n" + 
4321
			"        public T foo;\n" +
4322
			"}\n" + 
4323
			"\n" + 
4324
			"public class X {\n" + 
4325
			"        public static void main(String[] args) {\n" + 
4326
			"            A<Long> a = new A<Long>();\n" + 
4327
			"	         long s = a.foo.MAX_VALUE;\n" + 
4328
			"            System.out.println(\"SUCCESS\");\n" + 
4329
			"        }\n" + 
4330
			"}\n", // =================
4331
		},
4332
		"SUCCESS",
4333
		null,
4334
		true,
4335
		null,
4336
		settings,
4337
		null);		
4338
}
3972
}
4339
}
(-)Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/InitializationTest.java (-1 / +1 lines)
Lines 5319-5325 Link Here
5319
				"     5  ldc <String \"[B.local_field]\"> [29]\n" + 
5319
				"     5  ldc <String \"[B.local_field]\"> [29]\n" + 
5320
				"     7  invokestatic A.foo(java.lang.String) : Value [15]\n" + 
5320
				"     7  invokestatic A.foo(java.lang.String) : Value [15]\n" + 
5321
				"    10  putfield B.local_field : Value [31]\n" + 
5321
				"    10  putfield B.local_field : Value [31]\n" + 
5322
				"    13  getstatic I.CONST : Value [33]\n" + 
5322
				"    13  getstatic B.CONST : Value [33]\n" + 
5323
				"    16  pop\n" + 
5323
				"    16  pop\n" + 
5324
				"    17  getstatic Value.NAME : java.lang.String [36]\n" + 
5324
				"    17  getstatic Value.NAME : java.lang.String [36]\n" + 
5325
				"    20  pop\n" + 
5325
				"    20  pop\n" + 

Return to bug 177194