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 |