View | Details | Raw Unified | Return to bug 256463
Collapse All | Expand All

(-)batch/org/eclipse/jdt/internal/compiler/batch/messages.properties (+2 lines)
Lines 233-238 Link Here
233
\    -warn:<warnings separated by ,>    enable exactly the listed warnings\n\
233
\    -warn:<warnings separated by ,>    enable exactly the listed warnings\n\
234
\    -warn:+<warnings separated by ,>   enable additional warnings\n\
234
\    -warn:+<warnings separated by ,>   enable additional warnings\n\
235
\    -warn:-<warnings separated by ,>   disable specific warnings\n\
235
\    -warn:-<warnings separated by ,>   disable specific warnings\n\
236
\      allDeadCode          dead code including trivial if(DEBUG) check\n\
236
\      allDeprecation       deprecation including inside deprecated code\n\
237
\      allDeprecation       deprecation including inside deprecated code\n\
237
\      allJavadoc           invalid or missing javadoc\n\
238
\      allJavadoc           invalid or missing javadoc\n\
238
\      assertIdentifier   + ''assert'' used as identifier\n\
239
\      assertIdentifier   + ''assert'' used as identifier\n\
Lines 241-246 Link Here
241
\      compareIdentical   + comparing identical expressions\n\
242
\      compareIdentical   + comparing identical expressions\n\
242
\      conditionAssign      possible accidental boolean assignment\n\
243
\      conditionAssign      possible accidental boolean assignment\n\
243
\      constructorName    + method with constructor name\n\
244
\      constructorName    + method with constructor name\n\
245
\      deadCode             dead code excluding trivial if (DEBUG) check\n\
244
\      dep-ann              missing @Deprecated annotation\n\
246
\      dep-ann              missing @Deprecated annotation\n\
245
\      deprecation        + deprecation outside deprecated code\n\
247
\      deprecation        + deprecation outside deprecated code\n\
246
\      discouraged        + use of types matching a discouraged access rule\n\
248
\      discouraged        + use of types matching a discouraged access rule\n\
(-)batch/org/eclipse/jdt/internal/compiler/batch/Main.java (+11 lines)
Lines 3084-3089 Link Here
3084
					CompilerOptions.OPTION_ReportAssertIdentifier,
3084
					CompilerOptions.OPTION_ReportAssertIdentifier,
3085
					isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
3085
					isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
3086
				return;
3086
				return;
3087
			} else if (token.equals("allDeadCode")) { //$NON-NLS-1$
3088
				this.options.put(
3089
						CompilerOptions.OPTION_ReportDeadCode,
3090
						isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
3091
					this.options.put(
3092
						CompilerOptions.OPTION_ReportDeadCodeInTrivialIfStatement,
3093
						isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
3094
					return;
3087
			}
3095
			}
3088
			break;
3096
			break;
3089
		case 'b' :
3097
		case 'b' :
Lines 3143-3148 Link Here
3143
				this.options.put(
3151
				this.options.put(
3144
					CompilerOptions.OPTION_ReportDeadCode,
3152
					CompilerOptions.OPTION_ReportDeadCode,
3145
					isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
3153
					isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE);
3154
				this.options.put(
3155
					CompilerOptions.OPTION_ReportDeadCodeInTrivialIfStatement,
3156
					CompilerOptions.DISABLED);
3146
				return;
3157
				return;
3147
			}
3158
			}
3148
			break;
3159
			break;
(-)compiler/org/eclipse/jdt/internal/compiler/ast/BinaryExpression.java (-3 / +2 lines)
Lines 56-63 Link Here
56
	this.sourceStart = expression.sourceStart;
56
	this.sourceStart = expression.sourceStart;
57
	this.sourceEnd = expression.sourceEnd;
57
	this.sourceEnd = expression.sourceEnd;
58
}
58
}
59
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext,
59
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
60
		FlowInfo flowInfo) {
61
	// keep implementation in sync with CombinedBinaryExpression#analyseCode
60
	// keep implementation in sync with CombinedBinaryExpression#analyseCode
62
	if (this.resolvedType.id == TypeIds.T_JavaLangString) {
61
	if (this.resolvedType.id == TypeIds.T_JavaLangString) {
63
		return this.right.analyseCode(
62
		return this.right.analyseCode(
Lines 1855-1861 Link Here
1855
	int operator = (this.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT;
1854
	int operator = (this.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT;
1856
	int operatorSignature = OperatorExpression.OperatorSignatures[operator][(leftTypeID << 4) + rightTypeID];
1855
	int operatorSignature = OperatorExpression.OperatorSignatures[operator][(leftTypeID << 4) + rightTypeID];
1857
1856
1858
	this.left.computeConversion(scope, 	TypeBinding.wellKnownType(scope, (operatorSignature >>> 16) & 0x0000F), leftType);
1857
	this.left.computeConversion(scope, TypeBinding.wellKnownType(scope, (operatorSignature >>> 16) & 0x0000F), leftType);
1859
	this.right.computeConversion(scope, TypeBinding.wellKnownType(scope, (operatorSignature >>> 8) & 0x0000F), rightType);
1858
	this.right.computeConversion(scope, TypeBinding.wellKnownType(scope, (operatorSignature >>> 8) & 0x0000F), rightType);
1860
	this.bits |= operatorSignature & 0xF;
1859
	this.bits |= operatorSignature & 0xF;
1861
	switch (operatorSignature & 0xF) { // record the current ReturnTypeID
1860
	switch (operatorSignature & 0xF) { // record the current ReturnTypeID
(-)compiler/org/eclipse/jdt/internal/compiler/ast/EmptyStatement.java (-1 lines)
Lines 30-36 Link Here
30
30
31
	// Report an error if necessary
31
	// Report an error if necessary
32
	public int complainIfUnreachable(FlowInfo flowInfo, BlockScope scope, int complaintLevel) {
32
	public int complainIfUnreachable(FlowInfo flowInfo, BlockScope scope, int complaintLevel) {
33
34
		// before 1.4, empty statements are tolerated anywhere
33
		// before 1.4, empty statements are tolerated anywhere
35
		if (scope.compilerOptions().complianceLevel < ClassFileConstants.JDK1_4) {
34
		if (scope.compilerOptions().complianceLevel < ClassFileConstants.JDK1_4) {
36
			return complaintLevel;
35
			return complaintLevel;
(-)compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java (-178 / +207 lines)
Lines 30-184 Link Here
30
	int elseInitStateIndex = -1;
30
	int elseInitStateIndex = -1;
31
	int mergedInitStateIndex = -1;
31
	int mergedInitStateIndex = -1;
32
32
33
	public IfStatement(Expression condition, Statement thenStatement, 	int sourceStart, int sourceEnd) {
33
public IfStatement(Expression condition, Statement thenStatement, 	int sourceStart, int sourceEnd) {
34
	this.condition = condition;
35
	this.thenStatement = thenStatement;
36
	// remember useful empty statement
37
	if (thenStatement instanceof EmptyStatement) thenStatement.bits |= IsUsefulEmptyStatement;
38
	this.sourceStart = sourceStart;
39
	this.sourceEnd = sourceEnd;
40
}
34
41
35
		this.condition = condition;
42
public IfStatement(Expression condition, Statement thenStatement, Statement elseStatement, int sourceStart, int sourceEnd) {
36
		this.thenStatement = thenStatement;
43
	this.condition = condition;
37
		// remember useful empty statement
44
	this.thenStatement = thenStatement;
38
		if (thenStatement instanceof EmptyStatement) thenStatement.bits |= IsUsefulEmptyStatement;
45
	// remember useful empty statement
39
		this.sourceStart = sourceStart;
46
	if (thenStatement instanceof EmptyStatement) thenStatement.bits |= IsUsefulEmptyStatement;
40
		this.sourceEnd = sourceEnd;
47
	this.elseStatement = elseStatement;
41
	}
48
	if (elseStatement instanceof IfStatement) elseStatement.bits |= IsElseIfStatement;
42
49
	if (elseStatement instanceof EmptyStatement) elseStatement.bits |= IsUsefulEmptyStatement;
43
	public IfStatement(Expression condition, Statement thenStatement, Statement elseStatement, int sourceStart, int sourceEnd) {
50
	this.sourceStart = sourceStart;
44
51
	this.sourceEnd = sourceEnd;
45
		this.condition = condition;
52
}
46
		this.thenStatement = thenStatement;
47
		// remember useful empty statement
48
		if (thenStatement instanceof EmptyStatement) thenStatement.bits |= IsUsefulEmptyStatement;
49
		this.elseStatement = elseStatement;
50
		if (elseStatement instanceof IfStatement) elseStatement.bits |= IsElseIfStatement;
51
		if (elseStatement instanceof EmptyStatement) elseStatement.bits |= IsUsefulEmptyStatement;
52
		this.sourceStart = sourceStart;
53
		this.sourceEnd = sourceEnd;
54
	}
55
56
	public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
57
		// process the condition
58
		FlowInfo conditionFlowInfo = this.condition.analyseCode(currentScope, flowContext, flowInfo);
59
		int initialComplaintLevel = (flowInfo.reachMode() & FlowInfo.UNREACHABLE) != 0 ? Statement.COMPLAINED_FAKE_REACHABLE : Statement.NOT_COMPLAINED;
60
61
		Constant cst = this.condition.optimizedBooleanConstant();
62
		boolean isConditionOptimizedTrue = cst != Constant.NotAConstant && cst.booleanValue() == true;
63
		boolean isConditionOptimizedFalse = cst != Constant.NotAConstant && cst.booleanValue() == false;
64
53
65
		// process the THEN part
54
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
66
		FlowInfo thenFlowInfo = conditionFlowInfo.safeInitsWhenTrue();
55
	// process the condition
56
	FlowInfo conditionFlowInfo = this.condition.analyseCode(currentScope, flowContext, flowInfo);
57
	int initialComplaintLevel = (flowInfo.reachMode() & FlowInfo.UNREACHABLE) != 0 ? Statement.COMPLAINED_FAKE_REACHABLE : Statement.NOT_COMPLAINED;
58
59
	Constant cst = this.condition.optimizedBooleanConstant();
60
	boolean isConditionOptimizedTrue = cst != Constant.NotAConstant && cst.booleanValue() == true;
61
	boolean isConditionOptimizedFalse = cst != Constant.NotAConstant && cst.booleanValue() == false;
62
63
	// process the THEN part
64
	FlowInfo thenFlowInfo = conditionFlowInfo.safeInitsWhenTrue();
65
	if (isConditionOptimizedFalse) {
66
		thenFlowInfo.setReachMode(FlowInfo.UNREACHABLE);
67
	}
68
	FlowInfo elseFlowInfo = conditionFlowInfo.initsWhenFalse();
69
	if (isConditionOptimizedTrue) {
70
		elseFlowInfo.setReachMode(FlowInfo.UNREACHABLE);
71
	}
72
	if (this.thenStatement != null) {
73
		// Save info for code gen
74
		this.thenInitStateIndex = currentScope.methodScope().recordInitializationStates(thenFlowInfo);
67
		if (isConditionOptimizedFalse) {
75
		if (isConditionOptimizedFalse) {
68
			thenFlowInfo.setReachMode(FlowInfo.UNREACHABLE);
76
			if (!isKnowDeadCodePattern(this.condition) || currentScope.compilerOptions().reportDeadCodeInTrivialIfStatement) {
69
		}
77
				this.thenStatement.complainIfUnreachable(thenFlowInfo, currentScope, initialComplaintLevel);
70
		FlowInfo elseFlowInfo = conditionFlowInfo.initsWhenFalse();
71
		if (isConditionOptimizedTrue) {
72
			elseFlowInfo.setReachMode(FlowInfo.UNREACHABLE);
73
		}
74
		if (this.thenStatement != null) {
75
			// Save info for code gen
76
			this.thenInitStateIndex = currentScope.methodScope().recordInitializationStates(thenFlowInfo);
77
			if (this.thenStatement.complainIfUnreachable(thenFlowInfo, currentScope, initialComplaintLevel) < Statement.COMPLAINED_UNREACHABLE) {
78
				thenFlowInfo = this.thenStatement.analyseCode(currentScope, flowContext, thenFlowInfo);
79
			}
78
			}
80
		}
79
		}
81
		// code gen: optimizing the jump around the ELSE part
80
		thenFlowInfo = this.thenStatement.analyseCode(currentScope, flowContext, thenFlowInfo);
82
		if ((thenFlowInfo.tagBits & FlowInfo.UNREACHABLE) != 0) {
81
	}
83
			this.bits |= ASTNode.ThenExit;
82
	// code gen: optimizing the jump around the ELSE part
84
		}
83
	if ((thenFlowInfo.tagBits & FlowInfo.UNREACHABLE) != 0) {
85
84
		this.bits |= ASTNode.ThenExit;
86
		// process the ELSE part
85
	}
87
		if (this.elseStatement != null) {
86
88
		    // signal else clause unnecessarily nested, tolerate else-if code pattern
87
	// process the ELSE part
89
		    if (thenFlowInfo == FlowInfo.DEAD_END
88
	if (this.elseStatement != null) {
90
		            && (this.bits & IsElseIfStatement) == 0 	// else of an else-if
89
	    // signal else clause unnecessarily nested, tolerate else-if code pattern
91
		            && !(this.elseStatement instanceof IfStatement)) {
90
	    if (thenFlowInfo == FlowInfo.DEAD_END
92
		        currentScope.problemReporter().unnecessaryElse(this.elseStatement);
91
	            && (this.bits & IsElseIfStatement) == 0 	// else of an else-if
93
		    }
92
	            && !(this.elseStatement instanceof IfStatement)) {
94
			// Save info for code gen
93
	        currentScope.problemReporter().unnecessaryElse(this.elseStatement);
95
			this.elseInitStateIndex = currentScope.methodScope().recordInitializationStates(elseFlowInfo);
94
	    }
96
			if (this.elseStatement.complainIfUnreachable(elseFlowInfo, currentScope, initialComplaintLevel) < Statement.COMPLAINED_UNREACHABLE) {
95
		// Save info for code gen
97
				elseFlowInfo = this.elseStatement.analyseCode(currentScope, flowContext, elseFlowInfo);
96
		this.elseInitStateIndex = currentScope.methodScope().recordInitializationStates(elseFlowInfo);
97
		if (isConditionOptimizedTrue) {
98
			if (!isKnowDeadCodePattern(this.condition) || currentScope.compilerOptions().reportDeadCodeInTrivialIfStatement) {
99
				this.elseStatement.complainIfUnreachable(elseFlowInfo, currentScope, initialComplaintLevel);
98
			}
100
			}
99
		}
101
		}
102
		elseFlowInfo = this.elseStatement.analyseCode(currentScope, flowContext, elseFlowInfo);
103
	}
104
	// merge THEN & ELSE initializations
105
	FlowInfo mergedInfo = FlowInfo.mergedOptimizedBranches(
106
		thenFlowInfo,
107
		isConditionOptimizedTrue,
108
		elseFlowInfo,
109
		isConditionOptimizedFalse,
110
		true /*if(true){ return; }  fake-reachable(); */);
111
	this.mergedInitStateIndex = currentScope.methodScope().recordInitializationStates(mergedInfo);
112
	return mergedInfo;
113
}
100
114
101
		// merge THEN & ELSE initializations
115
/**
102
		FlowInfo mergedInfo = FlowInfo.mergedOptimizedBranches(
116
 * If code generation
103
			thenFlowInfo,
117
 *
104
			isConditionOptimizedTrue,
118
 * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
105
			elseFlowInfo,
119
 * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
106
			isConditionOptimizedFalse,
120
 */
107
			true /*if(true){ return; }  fake-reachable(); */);
121
public void generateCode(BlockScope currentScope, CodeStream codeStream) {
108
		this.mergedInitStateIndex = currentScope.methodScope().recordInitializationStates(mergedInfo);
122
	if ((this.bits & IsReachable) == 0) {
109
		return mergedInfo;
123
		return;
110
	}
124
	}
111
125
	int pc = codeStream.position;
112
	/**
126
	BranchLabel endifLabel = new BranchLabel(codeStream);
113
	 * If code generation
127
114
	 *
128
	// optimizing the then/else part code gen
115
	 * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
129
	Constant cst;
116
	 * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
130
	boolean hasThenPart =
117
	 */
131
		!(((cst = this.condition.optimizedBooleanConstant()) != Constant.NotAConstant
118
	public void generateCode(BlockScope currentScope, CodeStream codeStream) {
132
				&& cst.booleanValue() == false)
119
133
			|| this.thenStatement == null
120
		if ((this.bits & IsReachable) == 0) {
134
			|| this.thenStatement.isEmptyBlock());
121
			return;
135
	boolean hasElsePart =
122
		}
136
		!((cst != Constant.NotAConstant && cst.booleanValue() == true)
123
		int pc = codeStream.position;
137
			|| this.elseStatement == null
124
		BranchLabel endifLabel = new BranchLabel(codeStream);
138
			|| this.elseStatement.isEmptyBlock());
125
139
	if (hasThenPart) {
126
		// optimizing the then/else part code gen
140
		BranchLabel falseLabel = null;
127
		Constant cst;
141
		// generate boolean condition
128
		boolean hasThenPart =
142
		this.condition.generateOptimizedBoolean(
129
			!(((cst = this.condition.optimizedBooleanConstant()) != Constant.NotAConstant
143
			currentScope,
130
					&& cst.booleanValue() == false)
144
			codeStream,
131
				|| this.thenStatement == null
145
			null,
132
				|| this.thenStatement.isEmptyBlock());
146
			hasElsePart ? (falseLabel = new BranchLabel(codeStream)) : endifLabel,
133
		boolean hasElsePart =
147
			true/*cst == Constant.NotAConstant*/);
134
			!((cst != Constant.NotAConstant && cst.booleanValue() == true)
148
		// May loose some local variable initializations : affecting the local variable attributes
135
				|| this.elseStatement == null
149
		if (this.thenInitStateIndex != -1) {
136
				|| this.elseStatement.isEmptyBlock());
150
			codeStream.removeNotDefinitelyAssignedVariables(currentScope, this.thenInitStateIndex);
137
		if (hasThenPart) {
151
			codeStream.addDefinitelyAssignedVariables(currentScope, this.thenInitStateIndex);
138
			BranchLabel falseLabel = null;
152
		}
139
			// generate boolean condition
153
		// generate then statement
140
			this.condition.generateOptimizedBoolean(
154
		this.thenStatement.generateCode(currentScope, codeStream);
141
				currentScope,
155
		// jump around the else statement
142
				codeStream,
156
		if (hasElsePart) {
143
				null,
157
			if ((this.bits & ASTNode.ThenExit) == 0) {
144
				hasElsePart ? (falseLabel = new BranchLabel(codeStream)) : endifLabel,
158
				this.thenStatement.branchChainTo(endifLabel);
145
				true/*cst == Constant.NotAConstant*/);
159
				int position = codeStream.position;
146
			// May loose some local variable initializations : affecting the local variable attributes
160
				codeStream.goto_(endifLabel);
147
			if (this.thenInitStateIndex != -1) {
161
				//goto is tagged as part of the thenAction block
148
				codeStream.removeNotDefinitelyAssignedVariables(currentScope, this.thenInitStateIndex);
162
				codeStream.updateLastRecordedEndPC((this.thenStatement instanceof Block) ? ((Block) this.thenStatement).scope : currentScope, position);
149
				codeStream.addDefinitelyAssignedVariables(currentScope, this.thenInitStateIndex);
163
				// generate else statement
150
			}
151
			// generate then statement
152
			this.thenStatement.generateCode(currentScope, codeStream);
153
			// jump around the else statement
154
			if (hasElsePart) {
155
				if ((this.bits & ASTNode.ThenExit) == 0) {
156
					this.thenStatement.branchChainTo(endifLabel);
157
					int position = codeStream.position;
158
					codeStream.goto_(endifLabel);
159
					//goto is tagged as part of the thenAction block
160
					codeStream.updateLastRecordedEndPC((this.thenStatement instanceof Block) ? ((Block) this.thenStatement).scope : currentScope, position);
161
					// generate else statement
162
				}
163
				// May loose some local variable initializations : affecting the local variable attributes
164
				if (this.elseInitStateIndex != -1) {
165
					codeStream.removeNotDefinitelyAssignedVariables(
166
						currentScope,
167
						this.elseInitStateIndex);
168
					codeStream.addDefinitelyAssignedVariables(currentScope, this.elseInitStateIndex);
169
				}
170
				if (falseLabel != null) falseLabel.place();
171
				this.elseStatement.generateCode(currentScope, codeStream);
172
			}
164
			}
173
		} else if (hasElsePart) {
174
			// generate boolean condition
175
			this.condition.generateOptimizedBoolean(
176
				currentScope,
177
				codeStream,
178
				endifLabel,
179
				null,
180
				true/*cst == Constant.NotAConstant*/);
181
			// generate else statement
182
			// May loose some local variable initializations : affecting the local variable attributes
165
			// May loose some local variable initializations : affecting the local variable attributes
183
			if (this.elseInitStateIndex != -1) {
166
			if (this.elseInitStateIndex != -1) {
184
				codeStream.removeNotDefinitelyAssignedVariables(
167
				codeStream.removeNotDefinitelyAssignedVariables(
Lines 186-243 Link Here
186
					this.elseInitStateIndex);
169
					this.elseInitStateIndex);
187
				codeStream.addDefinitelyAssignedVariables(currentScope, this.elseInitStateIndex);
170
				codeStream.addDefinitelyAssignedVariables(currentScope, this.elseInitStateIndex);
188
			}
171
			}
172
			if (falseLabel != null) falseLabel.place();
189
			this.elseStatement.generateCode(currentScope, codeStream);
173
			this.elseStatement.generateCode(currentScope, codeStream);
190
		} else {
191
			// generate condition side-effects
192
			this.condition.generateCode(currentScope, codeStream, false);
193
			codeStream.recordPositionsFrom(pc, this.sourceStart);
194
		}
174
		}
175
	} else if (hasElsePart) {
176
		// generate boolean condition
177
		this.condition.generateOptimizedBoolean(
178
			currentScope,
179
			codeStream,
180
			endifLabel,
181
			null,
182
			true/*cst == Constant.NotAConstant*/);
183
		// generate else statement
195
		// May loose some local variable initializations : affecting the local variable attributes
184
		// May loose some local variable initializations : affecting the local variable attributes
196
		if (this.mergedInitStateIndex != -1) {
185
		if (this.elseInitStateIndex != -1) {
197
			codeStream.removeNotDefinitelyAssignedVariables(
186
			codeStream.removeNotDefinitelyAssignedVariables(
198
				currentScope,
187
				currentScope,
199
				this.mergedInitStateIndex);
188
				this.elseInitStateIndex);
200
			codeStream.addDefinitelyAssignedVariables(currentScope, this.mergedInitStateIndex);
189
			codeStream.addDefinitelyAssignedVariables(currentScope, this.elseInitStateIndex);
201
		}
190
		}
202
		endifLabel.place();
191
		this.elseStatement.generateCode(currentScope, codeStream);
192
	} else {
193
		// generate condition side-effects
194
		this.condition.generateCode(currentScope, codeStream, false);
203
		codeStream.recordPositionsFrom(pc, this.sourceStart);
195
		codeStream.recordPositionsFrom(pc, this.sourceStart);
204
	}
196
	}
197
	// May loose some local variable initializations : affecting the local variable attributes
198
	if (this.mergedInitStateIndex != -1) {
199
		codeStream.removeNotDefinitelyAssignedVariables(
200
			currentScope,
201
			this.mergedInitStateIndex);
202
		codeStream.addDefinitelyAssignedVariables(currentScope, this.mergedInitStateIndex);
203
	}
204
	endifLabel.place();
205
	codeStream.recordPositionsFrom(pc, this.sourceStart);
206
}
205
207
206
	public StringBuffer printStatement(int indent, StringBuffer output) {
208
/**
209
 * Answers true if the if is identified as a known coding pattern which
210
 * should be tolerated by dead code analysis.
211
 * e.g. if (DEBUG) print(); // no complaint
212
 * Only invoked when overall condition is known to be optimizeable into false.
213
 */
214
public static boolean isKnowDeadCodePattern(Expression expression) {
215
	// if (!DEBUG) print(); - tolerated
216
	if (expression instanceof UnaryExpression) {
217
		expression = ((UnaryExpression) expression).expression;
218
	}
219
	// if (DEBUG) print(); - tolerated
220
	if (expression instanceof Reference) return true;
221
222
//	if (expression instanceof BinaryExpression) {
223
//		BinaryExpression binary = (BinaryExpression) expression;
224
//		switch ((binary.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT/* operator */) {
225
//			case OperatorIds.AND_AND :
226
//			case OperatorIds.OR_OR :
227
//				break;
228
//			default: 
229
//				// if (DEBUG_LEVEL > 0) print(); - tolerated
230
//				if ((binary.left instanceof Reference) && binary.right.constant != Constant.NotAConstant)
231
//					return true;
232
//				// if (0 < DEBUG_LEVEL) print(); - tolerated
233
//				if ((binary.right instanceof Reference) && binary.left.constant != Constant.NotAConstant)
234
//					return true;
235
//		}
236
//	}
237
	return false;
238
}
207
239
208
		printIndent(indent, output).append("if ("); //$NON-NLS-1$
240
public StringBuffer printStatement(int indent, StringBuffer output) {
209
		this.condition.printExpression(0, output).append(")\n");	//$NON-NLS-1$
241
	printIndent(indent, output).append("if ("); //$NON-NLS-1$
210
		this.thenStatement.printStatement(indent + 2, output);
242
	this.condition.printExpression(0, output).append(")\n");	//$NON-NLS-1$
211
		if (this.elseStatement != null) {
243
	this.thenStatement.printStatement(indent + 2, output);
212
			output.append('\n');
244
	if (this.elseStatement != null) {
213
			printIndent(indent, output);
245
		output.append('\n');
214
			output.append("else\n"); //$NON-NLS-1$
246
		printIndent(indent, output);
215
			this.elseStatement.printStatement(indent + 2, output);
247
		output.append("else\n"); //$NON-NLS-1$
216
		}
248
		this.elseStatement.printStatement(indent + 2, output);
217
		return output;
218
	}
249
	}
250
	return output;
251
}
219
252
220
	public void resolve(BlockScope scope) {
253
public void resolve(BlockScope scope) {
254
	TypeBinding type = this.condition.resolveTypeExpecting(scope, TypeBinding.BOOLEAN);
255
	this.condition.computeConversion(scope, type, type);
256
	if (this.thenStatement != null)
257
		this.thenStatement.resolve(scope);
258
	if (this.elseStatement != null)
259
		this.elseStatement.resolve(scope);
260
}
221
261
222
		TypeBinding type = this.condition.resolveTypeExpecting(scope, TypeBinding.BOOLEAN);
262
public void traverse(ASTVisitor visitor, BlockScope blockScope) {
223
		this.condition.computeConversion(scope, type, type);
263
	if (visitor.visit(this, blockScope)) {
264
		this.condition.traverse(visitor, blockScope);
224
		if (this.thenStatement != null)
265
		if (this.thenStatement != null)
225
			this.thenStatement.resolve(scope);
266
			this.thenStatement.traverse(visitor, blockScope);
226
		if (this.elseStatement != null)
267
		if (this.elseStatement != null)
227
			this.elseStatement.resolve(scope);
268
			this.elseStatement.traverse(visitor, blockScope);
228
	}
229
230
	public void traverse(
231
		ASTVisitor visitor,
232
		BlockScope blockScope) {
233
234
		if (visitor.visit(this, blockScope)) {
235
			this.condition.traverse(visitor, blockScope);
236
			if (this.thenStatement != null)
237
				this.thenStatement.traverse(visitor, blockScope);
238
			if (this.elseStatement != null)
239
				this.elseStatement.traverse(visitor, blockScope);
240
		}
241
		visitor.endVisit(this, blockScope);
242
	}
269
	}
270
	visitor.endVisit(this, blockScope);
271
}
243
}
272
}
(-)model/org/eclipse/jdt/core/JavaCore.java (+13 lines)
Lines 1013-1018 Link Here
1013
	 */
1013
	 */
1014
	public static final String COMPILER_PB_DEAD_CODE = PLUGIN_ID + ".compiler.problem.deadCode"; //$NON-NLS-1$
1014
	public static final String COMPILER_PB_DEAD_CODE = PLUGIN_ID + ".compiler.problem.deadCode"; //$NON-NLS-1$
1015
	/**
1015
	/**
1016
	 * Compiler option ID: Reporting Dead Code Inside Trivial If Statement.
1017
	 * <p>When enabled, the compiler will signal presence of dead code inside trivial IF statement, e.g. <code>if (DEBUG)...</code>..
1018
	 * <p>The severity of the problem is controlled with option {@link #COMPILER_PB_DEAD_CODE}.
1019
	 * <dl>
1020
	 * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.compiler.problem.deadCodeInTrivialIfStatement"</code></dd>
1021
	 * <dt>Possible values:</dt><dd><code>{ "enabled", "disabled" }</code></dd>
1022
	 * <dt>Default:</dt><dd><code>"disabled"</code></dd>	
1023
	 * </dl>
1024
	 * @since 3.5
1025
	 * @category CompilerOptionID
1026
	 */	
1027
	public static final String COMPILER_PB_DEAD_CODE_IN_TRIVIAL_IF_STATEMENT = PLUGIN_ID + ".compiler.problem.deadCodeInTrivialIfStatement"; //$NON-NLS-1$
1028
	/**
1016
	 * Compiler option ID: Reporting Incomplete Enum Switch.
1029
	 * Compiler option ID: Reporting Incomplete Enum Switch.
1017
	 * <p>When enabled, the compiler will issue an error or a warning whenever
1030
	 * <p>When enabled, the compiler will issue an error or a warning whenever
1018
	 *    an enum constant has no corresponding case label in an enum switch
1031
	 *    an enum constant has no corresponding case label in an enum switch
(-)compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java (-26 / +42 lines)
Lines 124-129 Link Here
124
	public static final String OPTION_ReportMissingSynchronizedOnInheritedMethod =  "org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod"; //$NON-NLS-1$
124
	public static final String OPTION_ReportMissingSynchronizedOnInheritedMethod =  "org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod"; //$NON-NLS-1$
125
	public static final String OPTION_ReportMissingHashCodeMethod =  "org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod"; //$NON-NLS-1$
125
	public static final String OPTION_ReportMissingHashCodeMethod =  "org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod"; //$NON-NLS-1$
126
	public static final String OPTION_ReportDeadCode =  "org.eclipse.jdt.core.compiler.problem.deadCode"; //$NON-NLS-1$
126
	public static final String OPTION_ReportDeadCode =  "org.eclipse.jdt.core.compiler.problem.deadCode"; //$NON-NLS-1$
127
	public static final String OPTION_ReportDeadCodeInTrivialIfStatement =  "org.eclipse.jdt.core.compiler.problem.deadCodeInTrivialIfStatement"; //$NON-NLS-1$
127
128
128
	// Backward compatibility
129
	// Backward compatibility
129
	public static final String OPTION_ReportInvalidAnnotation = "org.eclipse.jdt.core.compiler.problem.invalidAnnotation"; //$NON-NLS-1$
130
	public static final String OPTION_ReportInvalidAnnotation = "org.eclipse.jdt.core.compiler.problem.invalidAnnotation"; //$NON-NLS-1$
Lines 292-297 Link Here
292
	public boolean reportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable;
293
	public boolean reportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable;
293
	/** Specify whether should report constructor/setter method parameter hiding */
294
	/** Specify whether should report constructor/setter method parameter hiding */
294
	public boolean reportSpecialParameterHidingField;
295
	public boolean reportSpecialParameterHidingField;
296
	/** Specify whether trivial deadcode pattern is to be reported (e.g. if (DEBUG) ...) */
297
	public boolean reportDeadCodeInTrivialIfStatement;
295
	/** Master flag controlling whether doc comment should be processed */
298
	/** Master flag controlling whether doc comment should be processed */
296
	public boolean docCommentSupport;
299
	public boolean docCommentSupport;
297
	/** Specify if invalid javadoc shall be reported */
300
	/** Specify if invalid javadoc shall be reported */
Lines 354-359 Link Here
354
	};
357
	};
355
358
356
	/**
359
	/**
360
	 * Initializing the compiler options with defaults
361
	 */
362
	public CompilerOptions(){
363
		this(null); // use default options
364
	}
365
366
	/**
367
	 * Initializing the compiler options with external settings
368
	 * @param settings
369
	 */
370
	public CompilerOptions(Map settings){
371
		resetDefaults();
372
		if (settings != null) {
373
			set(settings);
374
		}
375
	}
376
377
	/**
378
	 * @deprecated used to preserve 3.1 and 3.2M4 compatibility of some Compiler constructors
379
	 */
380
	public CompilerOptions(Map settings, boolean parseLiteralExpressionsAsConstants){
381
		this(settings);
382
		this.parseLiteralExpressionsAsConstants = parseLiteralExpressionsAsConstants;
383
	}
384
385
	/**
357
	 * Return the most specific option key controlling this irritant. Note that in some case, some irritant is controlled by
386
	 * Return the most specific option key controlling this irritant. Note that in some case, some irritant is controlled by
358
	 * other master options (e.g. javadoc, deprecation, etc.).
387
	 * other master options (e.g. javadoc, deprecation, etc.).
359
	 * This information is intended for grouping purpose (several problems governed by a rule)
388
	 * This information is intended for grouping purpose (several problems governed by a rule)
Lines 773-804 Link Here
773
		return null;
802
		return null;
774
	}
803
	}
775
804
776
	/**
777
	 * Initializing the compiler options with defaults
778
	 */
779
	public CompilerOptions(){
780
		this(null); // use default options
781
	}
782
783
	/**
784
	 * Initializing the compiler options with external settings
785
	 * @param settings
786
	 */
787
	public CompilerOptions(Map settings){
788
		resetDefaults();
789
		if (settings != null) {
790
			set(settings);
791
		}
792
	}
793
794
	/**
795
	 * @deprecated used to preserve 3.1 and 3.2M4 compatibility of some Compiler constructors
796
	 */
797
	public CompilerOptions(Map settings, boolean parseLiteralExpressionsAsConstants){
798
		this(settings);
799
		this.parseLiteralExpressionsAsConstants = parseLiteralExpressionsAsConstants;
800
	}
801
802
	
805
	
803
	public Map getMap() {
806
	public Map getMap() {
804
		Map optionsMap = new HashMap(30);
807
		Map optionsMap = new HashMap(30);
Lines 899-904 Link Here
899
		optionsMap.put(OPTION_ReportMissingSynchronizedOnInheritedMethod, getSeverityString(MissingSynchronizedModifierInInheritedMethod));
902
		optionsMap.put(OPTION_ReportMissingSynchronizedOnInheritedMethod, getSeverityString(MissingSynchronizedModifierInInheritedMethod));
900
		optionsMap.put(OPTION_ReportMissingHashCodeMethod, getSeverityString(ShouldImplementHashcode));
903
		optionsMap.put(OPTION_ReportMissingHashCodeMethod, getSeverityString(ShouldImplementHashcode));
901
		optionsMap.put(OPTION_ReportDeadCode, getSeverityString(DeadCode));
904
		optionsMap.put(OPTION_ReportDeadCode, getSeverityString(DeadCode));
905
		optionsMap.put(OPTION_ReportDeadCodeInTrivialIfStatement, this.reportDeadCodeInTrivialIfStatement ? ENABLED : DISABLED);
902
		return optionsMap;
906
		return optionsMap;
903
	}
907
	}
904
908
Lines 1031-1036 Link Here
1031
1035
1032
		// enable annotation processing by default only in batch mode
1036
		// enable annotation processing by default only in batch mode
1033
		this.processAnnotations = false;
1037
		this.processAnnotations = false;
1038
		
1039
		// dead code detection
1040
		this.reportDeadCodeInTrivialIfStatement = false;
1041
1034
	}
1042
	}
1035
1043
1036
	public void set(Map optionsMap) {
1044
	public void set(Map optionsMap) {
Lines 1155-1160 Link Here
1155
				this.reportSpecialParameterHidingField = false;
1163
				this.reportSpecialParameterHidingField = false;
1156
			}
1164
			}
1157
		}
1165
		}
1166
		if ((optionValue = optionsMap.get(OPTION_ReportDeadCodeInTrivialIfStatement )) != null) {
1167
			if (ENABLED.equals(optionValue)) {
1168
				this.reportDeadCodeInTrivialIfStatement = true;
1169
			} else if (DISABLED.equals(optionValue)) {
1170
				this.reportDeadCodeInTrivialIfStatement = false;
1171
			}
1172
		}		
1158
		if ((optionValue = optionsMap.get(OPTION_MaxProblemPerUnit)) != null) {
1173
		if ((optionValue = optionsMap.get(OPTION_MaxProblemPerUnit)) != null) {
1159
			if (optionValue instanceof String) {
1174
			if (optionValue instanceof String) {
1160
				String stringValue = (String) optionValue;
1175
				String stringValue = (String) optionValue;
Lines 1469-1474 Link Here
1469
		buf.append("\n\t- missing synchronized on inherited method: ").append(getSeverityString(MissingSynchronizedModifierInInheritedMethod)); //$NON-NLS-1$
1484
		buf.append("\n\t- missing synchronized on inherited method: ").append(getSeverityString(MissingSynchronizedModifierInInheritedMethod)); //$NON-NLS-1$
1470
		buf.append("\n\t- should implement hashCode() method: ").append(getSeverityString(ShouldImplementHashcode)); //$NON-NLS-1$
1485
		buf.append("\n\t- should implement hashCode() method: ").append(getSeverityString(ShouldImplementHashcode)); //$NON-NLS-1$
1471
		buf.append("\n\t- dead code: ").append(getSeverityString(DeadCode)); //$NON-NLS-1$
1486
		buf.append("\n\t- dead code: ").append(getSeverityString(DeadCode)); //$NON-NLS-1$
1487
		buf.append("\n\t- dead code in trivial if statement: ").append(this.reportDeadCodeInTrivialIfStatement ? ENABLED : DISABLED); //$NON-NLS-1$
1472
		return buf.toString();
1488
		return buf.toString();
1473
	}
1489
	}
1474
	
1490
	
(-)Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java (-49 / +14 lines)
Lines 11583-11614 Link Here
11583
		"	             ^^^^^^^^\n" + 
11583
		"	             ^^^^^^^^\n" + 
11584
		"The method doTest() from the type Test is never used locally\n" + 
11584
		"The method doTest() from the type Test is never used locally\n" + 
11585
		"----------\n" + 
11585
		"----------\n" + 
11586
		"2. WARNING in Test.java (at line 5)\n" + 
11586
		"2. WARNING in Test.java (at line 12)\n" + 
11587
		"	if (DEBUG){	\n" + 
11588
		"			time = System.currentTimeMillis();	\n" + 
11589
		"		}	\n" + 
11590
		"	          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
11591
		"Dead code\n" + 
11592
		"----------\n" + 
11593
		"3. WARNING in Test.java (at line 9)\n" + 
11594
		"	if (DEBUG) {	\n" + 
11595
		"			System.out.println(\"Bob takes: \" + (System.currentTimeMillis() - time) + \" ms\");	\n" + 
11596
		"		}	\n" + 
11597
		"	           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
11598
		"Dead code\n" + 
11599
		"----------\n" + 
11600
		"4. WARNING in Test.java (at line 12)\n" + 
11601
		"	int i = 0;	\n" + 
11587
		"	int i = 0;	\n" + 
11602
		"	    ^\n" + 
11588
		"	    ^\n" + 
11603
		"The local variable i is never read\n" + 
11589
		"The local variable i is never read\n" + 
11604
		"----------\n" + 
11605
		"5. WARNING in Test.java (at line 13)\n" + 
11606
		"	if (DEBUG){	\n" + 
11607
		"			int j = 1;	\n" + 
11608
		"			j++;		\n" + 
11609
		"		}	\n" + 
11610
		"	          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
11611
		"Dead code\n" + 
11612
		"----------\n",
11590
		"----------\n",
11613
		null, null, JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings);
11591
		null, null, JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings);
11614
}
11592
}
Lines 11736-11822 Link Here
11736
		"	            ^^^^^^^^^^^\n" + 
11714
		"	            ^^^^^^^^^^^\n" + 
11737
		"Dead code\n" + 
11715
		"Dead code\n" + 
11738
		"----------\n" + 
11716
		"----------\n" + 
11739
		"2. WARNING in X.java (at line 18)\n" + 
11717
		"2. WARNING in X.java (at line 22)\n" + 
11740
		"	if (FALSE) {	\n" + 
11741
		"			doit(obj);	\n" + 
11742
		"		}	\n" + 
11743
		"	           ^^^^^^^^^^^^^^^^^^^^^\n" + 
11744
		"Dead code\n" + 
11745
		"----------\n" + 
11746
		"3. WARNING in X.java (at line 22)\n" + 
11747
		"	if (false) {	\n" + 
11718
		"	if (false) {	\n" + 
11748
		"			doit(obj);	\n" + 
11719
		"			doit(obj);	\n" + 
11749
		"		}	\n" + 
11720
		"		}	\n" + 
11750
		"	           ^^^^^^^^^^^^^^^^^^^^^\n" + 
11721
		"	           ^^^^^^^^^^^^^^^^^^^^^\n" + 
11751
		"Dead code\n" + 
11722
		"Dead code\n" + 
11752
		"----------\n" + 
11723
		"----------\n" + 
11753
		"4. WARNING in X.java (at line 28)\n" + 
11724
		"3. WARNING in X.java (at line 28)\n" + 
11754
		"	Object obj = \"dummy\";	\n" + 
11725
		"	Object obj = \"dummy\";	\n" + 
11755
		"	       ^^^\n" + 
11726
		"	       ^^^\n" + 
11756
		"The local variable obj is never read\n" + 
11727
		"The local variable obj is never read\n" + 
11757
		"----------\n" + 
11728
		"----------\n" + 
11758
		"5. WARNING in X.java (at line 36)\n" + 
11729
		"4. WARNING in X.java (at line 36)\n" + 
11759
		"	if (false) {	\n" + 
11730
		"	if (false) {	\n" + 
11760
		"			doit(obj); //this is DEFINITELY unreachable code, but is not recognized as such	\n" + 
11731
		"			doit(obj); //this is DEFINITELY unreachable code, but is not recognized as such	\n" + 
11761
		"		}	\n" + 
11732
		"		}	\n" + 
11762
		"	           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
11733
		"	           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
11763
		"Dead code\n" + 
11734
		"Dead code\n" + 
11764
		"----------\n" + 
11735
		"----------\n" + 
11765
		"6. WARNING in X.java (at line 40)\n" + 
11736
		"5. ERROR in X.java (at line 44)\n" + 
11766
		"	if (FALSE) {	\n" + 
11767
		"			doit(obj); //this is conditionnally unreachable code, but is not recognized as such	\n" + 
11768
		"		}	\n" + 
11769
		"	           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
11770
		"Dead code\n" + 
11771
		"----------\n" + 
11772
		"7. ERROR in X.java (at line 44)\n" + 
11773
		"	while (false) {	\n" + 
11737
		"	while (false) {	\n" + 
11774
		"			doit(obj); //this is DEFINITELY unreachable code, and is recognized as such, with error	\n" + 
11738
		"			doit(obj); //this is DEFINITELY unreachable code, and is recognized as such, with error	\n" + 
11775
		"		}	\n" + 
11739
		"		}	\n" + 
11776
		"	              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
11740
		"	              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
11777
		"Unreachable code\n" + 
11741
		"Unreachable code\n" + 
11778
		"----------\n" + 
11742
		"----------\n" + 
11779
		"8. ERROR in X.java (at line 48)\n" + 
11743
		"6. ERROR in X.java (at line 48)\n" + 
11780
		"	while (FALSE) {	\n" + 
11744
		"	while (FALSE) {	\n" + 
11781
		"			doit(obj); //this is conditionnally unreachable code, but is recognized as definitely unreacheable code, with error	\n" + 
11745
		"			doit(obj); //this is conditionnally unreachable code, but is recognized as definitely unreacheable code, with error	\n" + 
11782
		"		}	\n" + 
11746
		"		}	\n" + 
11783
		"	              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
11747
		"	              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
11784
		"Unreachable code\n" + 
11748
		"Unreachable code\n" + 
11785
		"----------\n" + 
11749
		"----------\n" + 
11786
		"9. ERROR in X.java (at line 52)\n" + 
11750
		"7. ERROR in X.java (at line 52)\n" + 
11787
		"	for (; false;) {	\n" + 
11751
		"	for (; false;) {	\n" + 
11788
		"			doit(obj); //this is DEFINITELY unreachable code, but is recognized as definitely unreacheable code, with error	\n" + 
11752
		"			doit(obj); //this is DEFINITELY unreachable code, but is recognized as definitely unreacheable code, with error	\n" + 
11789
		"		}	\n" + 
11753
		"		}	\n" + 
11790
		"	               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
11754
		"	               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
11791
		"Unreachable code\n" + 
11755
		"Unreachable code\n" + 
11792
		"----------\n" + 
11756
		"----------\n" + 
11793
		"10. ERROR in X.java (at line 56)\n" + 
11757
		"8. ERROR in X.java (at line 56)\n" + 
11794
		"	for (; FALSE;) {	\n" + 
11758
		"	for (; FALSE;) {	\n" + 
11795
		"			doit(obj); //this is conditionnally unreachable code, but is recognized as definitely unreacheable code, with error 	\n" + 
11759
		"			doit(obj); //this is conditionnally unreachable code, but is recognized as definitely unreacheable code, with error 	\n" + 
11796
		"		}	\n" + 
11760
		"		}	\n" + 
11797
		"	               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
11761
		"	               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
11798
		"Unreachable code\n" + 
11762
		"Unreachable code\n" + 
11799
		"----------\n" + 
11763
		"----------\n" + 
11800
		"11. WARNING in X.java (at line 60)\n" + 
11764
		"9. WARNING in X.java (at line 60)\n" + 
11801
		"	int i = (false ? doit(\"0\") : doit(\"1\"));	\n" + 
11765
		"	int i = (false ? doit(\"0\") : doit(\"1\"));	\n" + 
11802
		"	                 ^^^^^^^^^\n" + 
11766
		"	                 ^^^^^^^^^\n" + 
11803
		"Dead code\n" + 
11767
		"Dead code\n" + 
11804
		"----------\n" + 
11768
		"----------\n" + 
11805
		"12. WARNING in X.java (at line 63)\n" + 
11769
		"10. WARNING in X.java (at line 63)\n" + 
11806
		"	int j = (FALSE ? doit(\"0\") : doit(\"1\"));	\n" + 
11770
		"	int j = (FALSE ? doit(\"0\") : doit(\"1\"));	\n" + 
11807
		"	                 ^^^^^^^^^\n" + 
11771
		"	                 ^^^^^^^^^\n" + 
11808
		"Dead code\n" + 
11772
		"Dead code\n" + 
11809
		"----------\n" + 
11773
		"----------\n" + 
11810
		"13. WARNING in X.java (at line 77)\n" + 
11774
		"11. WARNING in X.java (at line 77)\n" + 
11811
		"	doit(obj); //this is conditionnally unreachable code	\n" + 
11775
		"	doit(obj); //this is conditionnally unreachable code	\n" + 
11812
		"	^^^^^^^^^\n" + 
11776
		"	^^^^^^^^^\n" + 
11813
		"Dead code\n" + 
11777
		"Dead code\n" + 
11814
		"----------\n" + 
11778
		"----------\n" + 
11815
		"14. WARNING in X.java (at line 91)\n" + 
11779
		"12. WARNING in X.java (at line 91)\n" + 
11816
		"	doit(obj); //this is DEFINITELY unreachable code	\n" + 
11780
		"	doit(obj); //this is DEFINITELY unreachable code	\n" + 
11817
		"	^^^^^^^^^\n" + 
11781
		"	^^^^^^^^^\n" + 
11818
		"Dead code\n" + 
11782
		"Dead code\n" + 
11819
		"----------\n",
11783
		"----------\n"
11784
,
11820
		null,
11785
		null,
11821
		true,
11786
		true,
11822
		customOptions);
11787
		customOptions);
(-)src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java (-20 / +71 lines)
Lines 1471-1486 Link Here
1471
			},
1471
			},
1472
		false /* expectingCompilerErrors */,
1472
		false /* expectingCompilerErrors */,
1473
		"----------\n" + 
1473
		"----------\n" + 
1474
		"1. WARNING in X.java (at line 4)\n" + 
1474
		"1. WARNING in X.java (at line 5)\n" + 
1475
		"	if (b) {\n" + 
1476
		"      label: while (bar()) {\n" + 
1477
		"      }\n" + 
1478
		"      return null;\n" + 
1479
		"    }\n" + 
1480
		"	       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
1481
		"Dead code\n" + 
1482
		"----------\n" + 
1483
		"2. WARNING in X.java (at line 5)\n" + 
1484
		"	label: while (bar()) {\n" + 
1475
		"	label: while (bar()) {\n" + 
1485
		"	^^^^^\n" + 
1476
		"	^^^^^\n" + 
1486
		"The label label is never explicitly referenced\n" + 
1477
		"The label label is never explicitly referenced\n" + 
Lines 1518-1533 Link Here
1518
			"}\n"
1509
			"}\n"
1519
			},
1510
			},
1520
		false /* expectingCompilerErrors */,
1511
		false /* expectingCompilerErrors */,
1521
		"----------\n" + 
1512
		"" /* expectedCompilerLog */,
1522
		"1. WARNING in X.java (at line 4)\n" + 
1523
		"	if (b) {\n" + 
1524
		"      while (bar()) {\n" + 
1525
		"      }\n" + 
1526
		"      return null;\n" + 
1527
		"    }\n" + 
1528
		"	       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
1529
		"Dead code\n" + 
1530
		"----------\n" /* expectedCompilerLog */,
1531
		"" /* expectedOutputString */,
1513
		"" /* expectedOutputString */,
1532
		"" /* expectedErrorString */,
1514
		"" /* expectedErrorString */,
1533
		false /* forceExecution */,
1515
		false /* forceExecution */,
Lines 1907-1912 Link Here
1907
		"Unreachable code\n" + 
1889
		"Unreachable code\n" + 
1908
		"----------\n");
1890
		"----------\n");
1909
}
1891
}
1892
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=48399 - variation
1893
public void test060() {
1894
	runNegativeTest(
1895
		new String[] { /* test files */
1896
			"X.java",
1897
			"public class X {\n" + 
1898
			"	static final boolean DEBUG = false;\n" + 
1899
			"	static final int DEBUG_LEVEL = 0;\n" + 
1900
			"	boolean check() { return true; }\n" + 
1901
			"	void foo(boolean b) {\n" + 
1902
			"		if (DEBUG)\n" + 
1903
			"			System.out.println(\"fake reachable1\"); //$NON-NLS-1$\n" + 
1904
			"		if (DEBUG && b)\n" + 
1905
			"			System.out.println(\"fake reachable2\"); //$NON-NLS-1$\n" + 
1906
			"		if (DEBUG && check())\n" + 
1907
			"			System.out.println(\"fake reachable3\"); //$NON-NLS-1$\n" + 
1908
			"		if (b && DEBUG)\n" + 
1909
			"			System.out.println(\"fake reachable4\"); //$NON-NLS-1$\n" + 
1910
			"		if (check() && DEBUG)\n" + 
1911
			"			System.out.println(\"fake reachable5\"); //$NON-NLS-1$\n" + 
1912
			"		if (DEBUG_LEVEL > 1) \n" + 
1913
			"			System.out.println(\"fake reachable6\"); //$NON-NLS-1$\n" + 
1914
			"		return;\n" + 
1915
			"		return;\n" + 
1916
			"	}\n" + 
1917
			"}\n"
1918
		},
1919
		"----------\n" + 
1920
		"1. WARNING in X.java (at line 8)\n" + 
1921
		"	if (DEBUG && b)\n" + 
1922
		"	             ^\n" + 
1923
		"Dead code\n" + 
1924
		"----------\n" + 
1925
		"2. WARNING in X.java (at line 9)\n" + 
1926
		"	System.out.println(\"fake reachable2\"); //$NON-NLS-1$\n" + 
1927
		"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
1928
		"Dead code\n" + 
1929
		"----------\n" + 
1930
		"3. WARNING in X.java (at line 10)\n" + 
1931
		"	if (DEBUG && check())\n" + 
1932
		"	             ^^^^^^^\n" + 
1933
		"Dead code\n" + 
1934
		"----------\n" + 
1935
		"4. WARNING in X.java (at line 11)\n" + 
1936
		"	System.out.println(\"fake reachable3\"); //$NON-NLS-1$\n" + 
1937
		"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
1938
		"Dead code\n" + 
1939
		"----------\n" + 
1940
		"5. WARNING in X.java (at line 13)\n" + 
1941
		"	System.out.println(\"fake reachable4\"); //$NON-NLS-1$\n" + 
1942
		"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
1943
		"Dead code\n" + 
1944
		"----------\n" + 
1945
		"6. WARNING in X.java (at line 15)\n" + 
1946
		"	System.out.println(\"fake reachable5\"); //$NON-NLS-1$\n" + 
1947
		"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
1948
		"Dead code\n" + 
1949
		"----------\n" + 
1950
		"7. WARNING in X.java (at line 17)\n" + 
1951
		"	System.out.println(\"fake reachable6\"); //$NON-NLS-1$\n" + 
1952
		"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
1953
		"Dead code\n" + 
1954
		"----------\n" + 
1955
		"8. ERROR in X.java (at line 19)\n" + 
1956
		"	return;\n" + 
1957
		"	^^^^^^^\n" + 
1958
		"Unreachable code\n" + 
1959
		"----------\n");
1960
}
1910
public static Class testClass() {
1961
public static Class testClass() {
1911
	return FlowAnalysisTest.class;
1962
	return FlowAnalysisTest.class;
1912
}
1963
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java (+3 lines)
Lines 1636-1641 Link Here
1636
        "    -warn:<warnings separated by ,>    enable exactly the listed warnings\n" +
1636
        "    -warn:<warnings separated by ,>    enable exactly the listed warnings\n" +
1637
        "    -warn:+<warnings separated by ,>   enable additional warnings\n" +
1637
        "    -warn:+<warnings separated by ,>   enable additional warnings\n" +
1638
        "    -warn:-<warnings separated by ,>   disable specific warnings\n" +
1638
        "    -warn:-<warnings separated by ,>   disable specific warnings\n" +
1639
        "      allDeadCode          dead code including trivial if(DEBUG) check\n" +
1639
        "      allDeprecation       deprecation including inside deprecated code\n" +
1640
        "      allDeprecation       deprecation including inside deprecated code\n" +
1640
        "      allJavadoc           invalid or missing javadoc\n" +
1641
        "      allJavadoc           invalid or missing javadoc\n" +
1641
        "      assertIdentifier   + ''assert'' used as identifier\n" +
1642
        "      assertIdentifier   + ''assert'' used as identifier\n" +
Lines 1644-1649 Link Here
1644
        "      compareIdentical   + comparing identical expressions\n" +
1645
        "      compareIdentical   + comparing identical expressions\n" +
1645
        "      conditionAssign      possible accidental boolean assignment\n" +
1646
        "      conditionAssign      possible accidental boolean assignment\n" +
1646
        "      constructorName    + method with constructor name\n" +
1647
        "      constructorName    + method with constructor name\n" +
1648
        "      deadCode             dead code excluding trivial if (DEBUG) check\n" +
1647
        "      dep-ann              missing @Deprecated annotation\n" +
1649
        "      dep-ann              missing @Deprecated annotation\n" +
1648
        "      deprecation        + deprecation outside deprecated code\n" +
1650
        "      deprecation        + deprecation outside deprecated code\n" +
1649
        "      discouraged        + use of types matching a discouraged access rule\n" +
1651
        "      discouraged        + use of types matching a discouraged access rule\n" +
Lines 1777-1782 Link Here
1777
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.autoboxing\" value=\"ignore\"/>\n" +
1779
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.autoboxing\" value=\"ignore\"/>\n" +
1778
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.comparingIdentical\" value=\"warning\"/>\n" +
1780
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.comparingIdentical\" value=\"warning\"/>\n" +
1779
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.deadCode\" value=\"ignore\"/>\n" +
1781
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.deadCode\" value=\"ignore\"/>\n" +
1782
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.deadCodeInTrivialIfStatement\" value=\"disabled\"/>\n" +
1780
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.deprecation\" value=\"warning\"/>\n" +
1783
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.deprecation\" value=\"warning\"/>\n" +
1781
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode\" value=\"disabled\"/>\n" +
1784
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode\" value=\"disabled\"/>\n" +
1782
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod\" value=\"disabled\"/>\n" +
1785
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod\" value=\"disabled\"/>\n" +

Return to bug 256463