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

(-)src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java (+84 lines)
Lines 7675-7678 Link Here
7675
		expectedFullUnitToString,
7675
		expectedFullUnitToString,
7676
		expectedCompletionDietUnitToString, testName);
7676
		expectedCompletionDietUnitToString, testName);
7677
}
7677
}
7678
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=271680
7679
public void test125() {
7680
	String s =
7681
		"public class Test {\n" +
7682
		"}\n";
7683
	
7684
	StringBuffer buf = new StringBuffer();
7685
	for (int i = 0; i < 1000; i++) {
7686
		buf.append("class AClass #\n");
7687
	}
7688
	s+= buf.toString();
7689
7690
	// expectedDietUnitToString
7691
	String expectedDietUnitToString =
7692
		"public class Test {\n" +
7693
		"  public Test() {\n" +
7694
		"  }\n" +
7695
		"}\n";
7696
	buf = new StringBuffer();
7697
	int max = 256;
7698
	for (int i = 0; i < max; i++) {
7699
		String indent = "";
7700
		for (int j = 0; j < i; j++) {
7701
			indent+= "  ";
7702
		}
7703
		buf.append(indent).append("class AClass {\n");
7704
	}
7705
	for (int i = max - 1; i >= 0; i--) {
7706
		String indent = "";
7707
		for (int j = 0; j < i; j++) {
7708
			indent+= "  ";
7709
		}
7710
		buf.append(indent).append("  AClass() {\n");
7711
		buf.append(indent).append("  }\n");
7712
		buf.append(indent).append("}\n");
7713
	}
7714
	
7715
	expectedDietUnitToString += buf.toString();
7716
	
7717
	// expectedDietPlusBodyUnitToString
7718
	String expectedDietPlusBodyUnitToString =
7719
		"public class Test {\n" +
7720
		"  public Test() {\n" +
7721
		"    super();\n" + 
7722
		"  }\n" +
7723
		"}\n";
7724
	buf = new StringBuffer();
7725
	for (int i = 0; i < max; i++) {
7726
		String indent = "";
7727
		for (int j = 0; j < i; j++) {
7728
			indent+= "  ";
7729
		}
7730
		buf.append(indent).append("class AClass {\n");
7731
	}
7732
	for (int i = max - 1; i >= 0; i--) {
7733
		String indent = "";
7734
		for (int j = 0; j < i; j++) {
7735
			indent+= "  ";
7736
		}
7737
		buf.append(indent).append("  AClass() {\n");
7738
		buf.append(indent).append("    super();\n");
7739
		buf.append(indent).append("  }\n");
7740
		buf.append(indent).append("}\n");
7741
	}
7742
	expectedDietPlusBodyUnitToString += buf.toString();
7743
7744
	String expectedDietPlusBodyPlusStatementsRecoveryUnitToString =
7745
		expectedDietPlusBodyUnitToString;
7746
7747
	String expectedFullUnitToString =
7748
		expectedDietUnitToString;
7749
7750
	String expectedCompletionDietUnitToString =
7751
		expectedDietUnitToString;
7752
7753
	String testName = "test";
7754
	checkParse(
7755
		s.toCharArray(),
7756
		expectedDietUnitToString,
7757
		expectedDietPlusBodyUnitToString,
7758
		expectedDietPlusBodyPlusStatementsRecoveryUnitToString,
7759
		expectedFullUnitToString,
7760
		expectedCompletionDietUnitToString, testName);
7761
}
7678
}
7762
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java (-1 / +4 lines)
Lines 19-24 Link Here
19
 *	0  means completion behind the first character
19
 *	0  means completion behind the first character
20
 *  n  means completion behind the n-th character
20
 *  n  means completion behind the n-th character
21
 */
21
 */
22
23
import java.util.HashSet;
24
22
import org.eclipse.jdt.internal.compiler.*;
25
import org.eclipse.jdt.internal.compiler.*;
23
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
26
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
24
import org.eclipse.jdt.internal.compiler.env.*;
27
import org.eclipse.jdt.internal.compiler.env.*;
Lines 1053-1059 Link Here
1053
					condition.sourceStart < recoveredLocalVariable.localDeclaration.sourceStart) {
1056
					condition.sourceStart < recoveredLocalVariable.localDeclaration.sourceStart) {
1054
				this.currentElement.add(statement, 0);
1057
				this.currentElement.add(statement, 0);
1055
1058
1056
				statement = recoveredLocalVariable.updatedStatement();
1059
				statement = recoveredLocalVariable.updatedStatement(0, new HashSet());
1057
1060
1058
				// RecoveredLocalVariable must be removed from its parent because the IfStatement will be added instead
1061
				// RecoveredLocalVariable must be removed from its parent because the IfStatement will be added instead
1059
				RecoveredBlock recoveredBlock =  (RecoveredBlock) recoveredLocalVariable.parent;
1062
				RecoveredBlock recoveredBlock =  (RecoveredBlock) recoveredLocalVariable.parent;
(-)compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredType.java (-11 / +33 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.parser;
11
package org.eclipse.jdt.internal.compiler.parser;
12
12
13
import java.util.HashSet;
14
import java.util.Set;
15
13
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
16
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
14
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
17
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
15
import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration;
18
import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration;
Lines 29-34 Link Here
29
 */
32
 */
30
33
31
public class RecoveredType extends RecoveredStatement implements TerminalTokens {
34
public class RecoveredType extends RecoveredStatement implements TerminalTokens {
35
	public static final int MAX_TYPE_DEPTH = 256;
36
	
32
	public TypeDeclaration typeDeclaration;
37
	public TypeDeclaration typeDeclaration;
33
38
34
	public RecoveredAnnotation[] annotations;
39
	public RecoveredAnnotation[] annotations;
Lines 439-453 Link Here
439
	this.foundOpeningBrace = true;
444
	this.foundOpeningBrace = true;
440
	this.typeDeclaration.bodyStart = bodyStart;
445
	this.typeDeclaration.bodyStart = bodyStart;
441
}
446
}
442
public Statement updatedStatement(){
447
public Statement updatedStatement(int depth, Set knownTypes){
443
448
444
	// ignore closed anonymous type
449
	// ignore closed anonymous type
445
	if ((this.typeDeclaration.bits & ASTNode.IsAnonymousType) != 0 && !this.preserveContent){
450
	if ((this.typeDeclaration.bits & ASTNode.IsAnonymousType) != 0 && !this.preserveContent){
446
		return null;
451
		return null;
447
	}
452
	}
448
453
449
	TypeDeclaration updatedType = updatedTypeDeclaration();
454
	TypeDeclaration updatedType = updatedTypeDeclaration(depth + 1, knownTypes);
450
	if ((updatedType.bits & ASTNode.IsAnonymousType) != 0){
455
	if (updatedType != null && (updatedType.bits & ASTNode.IsAnonymousType) != 0){
451
		/* in presence of an anonymous type, we want the full allocation expression */
456
		/* in presence of an anonymous type, we want the full allocation expression */
452
		QualifiedAllocationExpression allocation = updatedType.allocation;
457
		QualifiedAllocationExpression allocation = updatedType.allocation;
453
458
Lines 458-464 Link Here
458
	}
463
	}
459
	return updatedType;
464
	return updatedType;
460
}
465
}
461
public TypeDeclaration updatedTypeDeclaration(){
466
public TypeDeclaration updatedTypeDeclaration(int depth, Set knownTypes){
467
	if (depth >= MAX_TYPE_DEPTH) return null;
468
469
	if(knownTypes.contains(this.typeDeclaration)) return null;
470
	knownTypes.add(this.typeDeclaration);
471
	
462
	int lastEnd = this.typeDeclaration.bodyStart;
472
	int lastEnd = this.typeDeclaration.bodyStart;
463
	/* update annotations */
473
	/* update annotations */
464
	if (this.modifiers != 0) {
474
	if (this.modifiers != 0) {
Lines 497-508 Link Here
497
			this.memberTypes[this.memberTypeCount - 1].typeDeclaration.declarationSourceEnd = bodyEndValue;
507
			this.memberTypes[this.memberTypeCount - 1].typeDeclaration.declarationSourceEnd = bodyEndValue;
498
			this.memberTypes[this.memberTypeCount - 1].typeDeclaration.bodyEnd =  bodyEndValue;
508
			this.memberTypes[this.memberTypeCount - 1].typeDeclaration.bodyEnd =  bodyEndValue;
499
		}
509
		}
510
		
511
		int updatedCount = 0;
500
		for (int i = 0; i < this.memberTypeCount; i++){
512
		for (int i = 0; i < this.memberTypeCount; i++){
501
			memberTypeDeclarations[existingCount + i] = this.memberTypes[i].updatedTypeDeclaration();
513
			TypeDeclaration updatedTypeDeclaration = this.memberTypes[i].updatedTypeDeclaration(depth + 1, knownTypes);
514
			if (updatedTypeDeclaration != null) {
515
				memberTypeDeclarations[existingCount + (updatedCount++)] = updatedTypeDeclaration;
516
			}
502
		}
517
		}
503
		this.typeDeclaration.memberTypes = memberTypeDeclarations;
518
		if (updatedCount < this.memberTypeCount) {
504
		if(memberTypeDeclarations[memberTypeDeclarations.length - 1].declarationSourceEnd > lastEnd) {
519
			int length = existingCount + updatedCount;
505
			lastEnd = memberTypeDeclarations[memberTypeDeclarations.length - 1].declarationSourceEnd;
520
			System.arraycopy(memberTypeDeclarations, 0, memberTypeDeclarations = new TypeDeclaration[length], 0, length);
521
		}
522
		
523
		if (memberTypeDeclarations.length > 0) { 
524
			this.typeDeclaration.memberTypes = memberTypeDeclarations;
525
			if(memberTypeDeclarations[memberTypeDeclarations.length - 1].declarationSourceEnd > lastEnd) {
526
				lastEnd = memberTypeDeclarations[memberTypeDeclarations.length - 1].declarationSourceEnd;
527
			}
506
		}
528
		}
507
	}
529
	}
508
	/* update fields */
530
	/* update fields */
Lines 519-525 Link Here
519
			this.fields[this.fieldCount - 1].fieldDeclaration.declarationEnd = temp;
541
			this.fields[this.fieldCount - 1].fieldDeclaration.declarationEnd = temp;
520
		}
542
		}
521
		for (int i = 0; i < this.fieldCount; i++){
543
		for (int i = 0; i < this.fieldCount; i++){
522
			fieldDeclarations[existingCount + i] = this.fields[i].updatedFieldDeclaration();
544
			fieldDeclarations[existingCount + i] = this.fields[i].updatedFieldDeclaration(depth, knownTypes);
523
		}
545
		}
524
		this.typeDeclaration.fields = fieldDeclarations;
546
		this.typeDeclaration.fields = fieldDeclarations;
525
		if(fieldDeclarations[fieldDeclarations.length - 1].declarationSourceEnd > lastEnd) {
547
		if(fieldDeclarations[fieldDeclarations.length - 1].declarationSourceEnd > lastEnd) {
Lines 546-552 Link Here
546
			this.methods[this.methodCount - 1].methodDeclaration.bodyEnd = bodyEndValue;
568
			this.methods[this.methodCount - 1].methodDeclaration.bodyEnd = bodyEndValue;
547
		}
569
		}
548
		for (int i = 0; i < this.methodCount; i++){
570
		for (int i = 0; i < this.methodCount; i++){
549
			AbstractMethodDeclaration updatedMethod = this.methods[i].updatedMethodDeclaration();
571
			AbstractMethodDeclaration updatedMethod = this.methods[i].updatedMethodDeclaration(depth, knownTypes);
550
			if (updatedMethod.isConstructor()) hasRecoveredConstructor = true;
572
			if (updatedMethod.isConstructor()) hasRecoveredConstructor = true;
551
			if (updatedMethod.isAbstract()) hasAbstractMethods = true;
573
			if (updatedMethod.isAbstract()) hasAbstractMethods = true;
552
			methodDeclarations[existingCount + i] = updatedMethod;
574
			methodDeclarations[existingCount + i] = updatedMethod;
Lines 731-737 Link Here
731
	return super.updateOnOpeningBrace(braceStart, braceEnd);
753
	return super.updateOnOpeningBrace(braceStart, braceEnd);
732
}
754
}
733
public void updateParseTree(){
755
public void updateParseTree(){
734
	updatedTypeDeclaration();
756
	updatedTypeDeclaration(0, new HashSet());
735
}
757
}
736
/*
758
/*
737
 * Update the declarationSourceEnd of the corresponding parse node
759
 * Update the declarationSourceEnd of the corresponding parse node
(-)compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredMethod.java (-3 / +6 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.parser;
11
package org.eclipse.jdt.internal.compiler.parser;
12
12
13
import java.util.HashSet;
14
import java.util.Set;
15
13
import org.eclipse.jdt.core.compiler.*;
16
import org.eclipse.jdt.core.compiler.*;
14
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
17
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
15
import org.eclipse.jdt.internal.compiler.ast.Annotation;
18
import org.eclipse.jdt.internal.compiler.ast.Annotation;
Lines 329-335 Link Here
329
	this.foundOpeningBrace = true;
332
	this.foundOpeningBrace = true;
330
	this.methodDeclaration.bodyStart = bodyStart;
333
	this.methodDeclaration.bodyStart = bodyStart;
331
}
334
}
332
public AbstractMethodDeclaration updatedMethodDeclaration(){
335
public AbstractMethodDeclaration updatedMethodDeclaration(int depth, Set knownTypes){
333
	/* update annotations */
336
	/* update annotations */
334
	if (this.modifiers != 0) {
337
	if (this.modifiers != 0) {
335
		this.methodDeclaration.modifiers |= this.modifiers;
338
		this.methodDeclaration.modifiers |= this.modifiers;
Lines 356-362 Link Here
356
	}
359
	}
357
360
358
	if (this.methodBody != null){
361
	if (this.methodBody != null){
359
		Block block = this.methodBody.updatedBlock();
362
		Block block = this.methodBody.updatedBlock(depth, knownTypes);
360
		if (block != null){
363
		if (block != null){
361
			this.methodDeclaration.statements = block.statements;
364
			this.methodDeclaration.statements = block.statements;
362
365
Lines 564-570 Link Here
564
	return super.updateOnOpeningBrace(braceStart, braceEnd);
567
	return super.updateOnOpeningBrace(braceStart, braceEnd);
565
}
568
}
566
public void updateParseTree(){
569
public void updateParseTree(){
567
	updatedMethodDeclaration();
570
	updatedMethodDeclaration(0, new HashSet());
568
}
571
}
569
/*
572
/*
570
 * Update the declarationSourceEnd of the corresponding parse node
573
 * Update the declarationSourceEnd of the corresponding parse node
(-)compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredStatement.java (-2 / +5 lines)
Lines 13-18 Link Here
13
/**
13
/**
14
 * Internal statement structure for parsing recovery
14
 * Internal statement structure for parsing recovery
15
 */
15
 */
16
import java.util.HashSet;
17
import java.util.Set;
18
16
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
19
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
17
import org.eclipse.jdt.internal.compiler.ast.Statement;
20
import org.eclipse.jdt.internal.compiler.ast.Statement;
18
21
Lines 38-48 Link Here
38
public String toString(int tab){
41
public String toString(int tab){
39
	return tabString(tab) + "Recovered statement:\n" + this.statement.print(tab + 1, new StringBuffer(10)); //$NON-NLS-1$
42
	return tabString(tab) + "Recovered statement:\n" + this.statement.print(tab + 1, new StringBuffer(10)); //$NON-NLS-1$
40
}
43
}
41
public Statement updatedStatement(){
44
public Statement updatedStatement(int depth, Set knownTypes){
42
	return this.statement;
45
	return this.statement;
43
}
46
}
44
public void updateParseTree(){
47
public void updateParseTree(){
45
	updatedStatement();
48
	updatedStatement(0, new HashSet());
46
}
49
}
47
/*
50
/*
48
 * Update the declarationSourceEnd of the corresponding parse node
51
 * Update the declarationSourceEnd of the corresponding parse node
(-)compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredField.java (-9 / +16 lines)
Lines 13-18 Link Here
13
/**
13
/**
14
 * Internal field structure for parsing recovery
14
 * Internal field structure for parsing recovery
15
 */
15
 */
16
import java.util.HashSet;
17
import java.util.Set;
18
16
import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration;
19
import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration;
17
import org.eclipse.jdt.internal.compiler.ast.Annotation;
20
import org.eclipse.jdt.internal.compiler.ast.Annotation;
18
import org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference;
21
import org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference;
Lines 145-151 Link Here
145
	}
148
	}
146
	return buffer.toString();
149
	return buffer.toString();
147
}
150
}
148
public FieldDeclaration updatedFieldDeclaration(){
151
public FieldDeclaration updatedFieldDeclaration(int depth, Set knownTypes){
149
	/* update annotations */
152
	/* update annotations */
150
	if (this.modifiers != 0) {
153
	if (this.modifiers != 0) {
151
		this.fieldDeclaration.modifiers |= this.modifiers;
154
		this.fieldDeclaration.modifiers |= this.modifiers;
Lines 181-192 Link Here
181
					typeDeclaration.bodyEnd = this.fieldDeclaration.declarationSourceEnd;
184
					typeDeclaration.bodyEnd = this.fieldDeclaration.declarationSourceEnd;
182
				}
185
				}
183
				if (recoveredType.preserveContent){
186
				if (recoveredType.preserveContent){
184
					TypeDeclaration anonymousType = recoveredType.updatedTypeDeclaration();
187
					TypeDeclaration anonymousType = recoveredType.updatedTypeDeclaration(depth + 1, knownTypes);
185
					this.fieldDeclaration.initialization = anonymousType.allocation;
188
					if (anonymousType != null) {
186
					if(this.fieldDeclaration.declarationSourceEnd == 0) {
189
						this.fieldDeclaration.initialization = anonymousType.allocation;
187
						int end = anonymousType.declarationSourceEnd;
190
						if(this.fieldDeclaration.declarationSourceEnd == 0) {
188
						this.fieldDeclaration.declarationSourceEnd = end;
191
							int end = anonymousType.declarationSourceEnd;
189
						this.fieldDeclaration.declarationEnd = end;
192
							this.fieldDeclaration.declarationSourceEnd = end;
193
							this.fieldDeclaration.declarationEnd = end;
194
						}
190
					}
195
					}
191
				}
196
				}
192
			}
197
			}
Lines 200-206 Link Here
200
					typeDeclaration.declarationSourceEnd = this.fieldDeclaration.declarationSourceEnd;
205
					typeDeclaration.declarationSourceEnd = this.fieldDeclaration.declarationSourceEnd;
201
					typeDeclaration.bodyEnd = this.fieldDeclaration.declarationSourceEnd;
206
					typeDeclaration.bodyEnd = this.fieldDeclaration.declarationSourceEnd;
202
				}
207
				}
203
				recoveredType.updatedTypeDeclaration();
208
				// if the enum is recovered then enum constants must be recovered too.
209
				// depth is considered as the same as the depth of the enum
210
				recoveredType.updatedTypeDeclaration(depth, knownTypes);
204
			}
211
			}
205
		}
212
		}
206
	}
213
	}
Lines 254-260 Link Here
254
	return this.parent.updateOnOpeningBrace(braceStart, braceEnd);
261
	return this.parent.updateOnOpeningBrace(braceStart, braceEnd);
255
}
262
}
256
public void updateParseTree(){
263
public void updateParseTree(){
257
	updatedFieldDeclaration();
264
	updatedFieldDeclaration(0, new HashSet());
258
}
265
}
259
/*
266
/*
260
 * Update the declarationSourceEnd of the corresponding parse node
267
 * Update the declarationSourceEnd of the corresponding parse node
(-)compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredUnit.java (-2 / +7 lines)
Lines 13-18 Link Here
13
/**
13
/**
14
 * Internal field structure for parsing recovery
14
 * Internal field structure for parsing recovery
15
 */
15
 */
16
import java.util.HashSet;
17
import java.util.Set;
18
16
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
19
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
17
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
20
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
18
import org.eclipse.jdt.internal.compiler.ast.Block;
21
import org.eclipse.jdt.internal.compiler.ast.Block;
Lines 250-260 Link Here
250
			this.types[this.typeCount - 1].typeDeclaration.declarationSourceEnd = this.unitDeclaration.sourceEnd;
253
			this.types[this.typeCount - 1].typeDeclaration.declarationSourceEnd = this.unitDeclaration.sourceEnd;
251
			this.types[this.typeCount - 1].typeDeclaration.bodyEnd = this.unitDeclaration.sourceEnd;
254
			this.types[this.typeCount - 1].typeDeclaration.bodyEnd = this.unitDeclaration.sourceEnd;
252
		}
255
		}
256
		
257
		Set knownTypes = new HashSet();
253
		int actualCount = existingCount;
258
		int actualCount = existingCount;
254
		for (int i = 0; i < this.typeCount; i++){
259
		for (int i = 0; i < this.typeCount; i++){
255
			TypeDeclaration typeDecl = this.types[i].updatedTypeDeclaration();
260
			TypeDeclaration typeDecl = this.types[i].updatedTypeDeclaration(0, knownTypes);
256
			// filter out local types (12454)
261
			// filter out local types (12454)
257
			if ((typeDecl.bits & ASTNode.IsLocalType) == 0){
262
			if (typeDecl != null && (typeDecl.bits & ASTNode.IsLocalType) == 0){
258
				typeDeclarations[actualCount++] = typeDecl;
263
				typeDeclarations[actualCount++] = typeDecl;
259
			}
264
			}
260
		}
265
		}
(-)compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredInitializer.java (-2 / +4 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.parser;
11
package org.eclipse.jdt.internal.compiler.parser;
12
12
13
import java.util.Set;
14
13
import org.eclipse.jdt.core.compiler.*;
15
import org.eclipse.jdt.core.compiler.*;
14
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
16
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
15
import org.eclipse.jdt.internal.compiler.ast.Block;
17
import org.eclipse.jdt.internal.compiler.ast.Block;
Lines 256-265 Link Here
256
	}
258
	}
257
	return result.toString();
259
	return result.toString();
258
}
260
}
259
public FieldDeclaration updatedFieldDeclaration(){
261
public FieldDeclaration updatedFieldDeclaration(int depth, Set knownTypes){
260
262
261
	if (this.initializerBody != null){
263
	if (this.initializerBody != null){
262
		Block block = this.initializerBody.updatedBlock();
264
		Block block = this.initializerBody.updatedBlock(depth, knownTypes);
263
		if (block != null){
265
		if (block != null){
264
			Initializer initializer = (Initializer) this.fieldDeclaration;
266
			Initializer initializer = (Initializer) this.fieldDeclaration;
265
			initializer.block = block;
267
			initializer.block = block;
(-)compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredLocalVariable.java (-2 / +5 lines)
Lines 13-18 Link Here
13
/**
13
/**
14
 * Internal local variable structure for parsing recovery
14
 * Internal local variable structure for parsing recovery
15
 */
15
 */
16
import java.util.HashSet;
17
import java.util.Set;
18
16
import org.eclipse.jdt.internal.compiler.ast.Annotation;
19
import org.eclipse.jdt.internal.compiler.ast.Annotation;
17
import org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference;
20
import org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference;
18
import org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference;
21
import org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference;
Lines 89-95 Link Here
89
public String toString(int tab) {
92
public String toString(int tab) {
90
	return tabString(tab) + "Recovered local variable:\n" + this.localDeclaration.print(tab + 1, new StringBuffer(10)); //$NON-NLS-1$
93
	return tabString(tab) + "Recovered local variable:\n" + this.localDeclaration.print(tab + 1, new StringBuffer(10)); //$NON-NLS-1$
91
}
94
}
92
public Statement updatedStatement(){
95
public Statement updatedStatement(int depth, Set knownTypes){
93
	/* update annotations */
96
	/* update annotations */
94
	if (this.modifiers != 0) {
97
	if (this.modifiers != 0) {
95
		this.localDeclaration.modifiers |= this.modifiers;
98
		this.localDeclaration.modifiers |= this.modifiers;
Lines 149-155 Link Here
149
	return this.parent.updateOnOpeningBrace(braceStart, braceEnd);
152
	return this.parent.updateOnOpeningBrace(braceStart, braceEnd);
150
}
153
}
151
public void updateParseTree(){
154
public void updateParseTree(){
152
	updatedStatement();
155
	updatedStatement(0, new HashSet());
153
}
156
}
154
/*
157
/*
155
 * Update the declarationSourceEnd of the corresponding parse node
158
 * Update the declarationSourceEnd of the corresponding parse node
(-)compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredBlock.java (-7 / +10 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.parser;
11
package org.eclipse.jdt.internal.compiler.parser;
12
12
13
import java.util.HashSet;
14
import java.util.Set;
15
13
import org.eclipse.jdt.core.compiler.*;
16
import org.eclipse.jdt.core.compiler.*;
14
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
17
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
15
import org.eclipse.jdt.internal.compiler.ast.Argument;
18
import org.eclipse.jdt.internal.compiler.ast.Argument;
Lines 276-282 Link Here
276
/*
279
/*
277
 * Rebuild a block from the nested structure which is in scope
280
 * Rebuild a block from the nested structure which is in scope
278
 */
281
 */
279
public Block updatedBlock(){
282
public Block updatedBlock(int depth, Set knownTypes){
280
283
281
	// if block was not marked to be preserved or empty, then ignore it
284
	// if block was not marked to be preserved or empty, then ignore it
282
	if (!this.preserveContent || this.statementCount == 0) return null;
285
	if (!this.preserveContent || this.statementCount == 0) return null;
Lines 322-328 Link Here
322
325
323
	// only collect the non-null updated statements
326
	// only collect the non-null updated statements
324
	for (int i = 0; i < this.statementCount; i++){
327
	for (int i = 0; i < this.statementCount; i++){
325
		Statement updatedStatement = this.statements[i].updatedStatement();
328
		Statement updatedStatement = this.statements[i].updatedStatement(depth, knownTypes);
326
		if (updatedStatement != null){
329
		if (updatedStatement != null){
327
			updatedStatements[updatedCount++] = updatedStatement;
330
			updatedStatements[updatedCount++] = updatedStatement;
328
331
Lines 366-374 Link Here
366
/*
369
/*
367
 * Rebuild a statement from the nested structure which is in scope
370
 * Rebuild a statement from the nested structure which is in scope
368
 */
371
 */
369
public Statement updatedStatement(){
372
public Statement updatedStatement(int depth, Set knownTypes){
370
373
371
	return updatedBlock();
374
	return updatedBlock(depth, knownTypes);
372
}
375
}
373
/*
376
/*
374
 * A closing brace got consumed, might have closed the current element,
377
 * A closing brace got consumed, might have closed the current element,
Lines 407-418 Link Here
407
 */
410
 */
408
public void updateParseTree(){
411
public void updateParseTree(){
409
412
410
	updatedBlock();
413
	updatedBlock(0, new HashSet());
411
}
414
}
412
/*
415
/*
413
 * Rebuild a flattened block from the nested structure which is in scope
416
 * Rebuild a flattened block from the nested structure which is in scope
414
 */
417
 */
415
public Statement updateStatement(){
418
public Statement updateStatement(int depth, Set knownTypes){
416
419
417
	// if block was closed or empty, then ignore it
420
	// if block was closed or empty, then ignore it
418
	if (this.blockDeclaration.sourceEnd != 0 || this.statementCount == 0) return null;
421
	if (this.blockDeclaration.sourceEnd != 0 || this.statementCount == 0) return null;
Lines 422-428 Link Here
422
425
423
	// only collect the non-null updated statements
426
	// only collect the non-null updated statements
424
	for (int i = 0; i < this.statementCount; i++){
427
	for (int i = 0; i < this.statementCount; i++){
425
		Statement updatedStatement = this.statements[i].updatedStatement();
428
		Statement updatedStatement = this.statements[i].updatedStatement(depth, knownTypes);
426
		if (updatedStatement != null){
429
		if (updatedStatement != null){
427
			updatedStatements[updatedCount++] = updatedStatement;
430
			updatedStatements[updatedCount++] = updatedStatement;
428
		}
431
		}

Return to bug 271680