public RecoveredElement add(Block nestedBlockDeclaration,int bracketBalanceValue) { this.pendingTypeParameters = null; resetPendingModifiers(); int mods = ClassFileConstants.AccDefault; if(parser().recoveredStaticInitializerStart != 0) { mods = ClassFileConstants.AccStatic; } return this.add(new Initializer(nestedBlockDeclaration, mods), bracketBalanceValue); } public RecoveredElement add(FieldDeclaration fieldDeclaration, int bracketBalanceValue) {
public RecoveredType(TypeDeclaration typeDeclaration, RecoveredElement parent, int bracketBalance){ super(typeDeclaration, parent, bracketBalance); this.typeDeclaration = typeDeclaration; if(typeDeclaration.allocation != null && typeDeclaration.allocation.type == null) { // an enum constant body can not exist if there is no opening brace this.foundOpeningBrace = true; } else { this.foundOpeningBrace = !bodyStartsAtHeaderEnd(); } this.insideEnumConstantPart = TypeDeclaration.kind(typeDeclaration.modifiers) == TypeDeclaration.ENUM_DECL; if(this.foundOpeningBrace) { this.bracketBalance++; } this.preserveContent = parser().methodRecoveryActivated || parser().statementRecoveryActivated; } public RecoveredElement add(AbstractMethodDeclaration methodDeclaration, int bracketBalanceValue) {
public RecoveredElement updateOnClosingBrace(int braceStart, int braceEnd){ if ((--this.bracketBalance <= 0) && (this.parent != null)){ this.updateSourceEndIfNecessary(braceStart, braceEnd); this.bodyEnd = braceStart - 1; return this.parent; } return this; } /*
int bodyEndValue = bodyEnd(); this.memberTypes[this.memberTypeCount - 1].typeDeclaration.declarationSourceEnd = bodyEndValue; this.memberTypes[this.memberTypeCount - 1].typeDeclaration.bodyEnd = bodyEndValue; TypeDeclaration updatedTypeDeclaration = this.memberTypes[i].updatedTypeDeclaration(depth + 1, knownTypes); if (updatedTypeDeclaration != null) { memberTypeDeclarations[existingCount + (updatedCount++)] = updatedTypeDeclaration; int temp = bodyEnd(); FieldDeclaration fieldDeclaration = this.fields[this.fieldCount - 1].fieldDeclaration; if (temp == 0 && fieldDeclaration.sourceEnd > 0) { int bodyEndValue = bodyEnd(); this.methods[this.methodCount - 1].methodDeclaration.declarationSourceEnd = bodyEndValue; this.methods[this.methodCount - 1].methodDeclaration.bodyEnd = bodyEndValue; hasConstructor = this.typeDeclaration.checkConstructors(parser()); } else { for (int i = 0; i < existingCount; i++){ this.typeDeclaration.createDefaultConstructor(!parser().diet || insideFieldInitializer, true);
public RecoveredElement add(TypeDeclaration typeDeclaration, int bracketBalanceValue, boolean delegatedByParent) { /* do not consider a type starting passed the block end (if set) it must be belonging to an enclosing block */ if (this.blockDeclaration.sourceEnd != 0 && typeDeclaration.declarationSourceStart > this.blockDeclaration.sourceEnd){ resetPendingModifiers(); if (delegatedByParent) return this; //ignore return this.parent.add(typeDeclaration, bracketBalanceValue); } RecoveredType element = new RecoveredType(typeDeclaration, this, bracketBalanceValue); if(this.pendingAnnotationCount > 0) { element.attach( this.pendingAnnotations, this.pendingAnnotationCount, this.pendingModifiers, this.pendingModifersSourceStart); } resetPendingModifiers(); attach(element); if (typeDeclaration.declarationSourceEnd == 0) return element; return this; } public RecoveredElement addAnnotationName(int identifierPtr, int identifierLengthPtr, int annotationStart, int bracketBalanceValue) {
public String toString(int tab) { StringBuffer result = new StringBuffer(tabString(tab)); result.append("Recovered type:\n"); //$NON-NLS-1$ if ((this.typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) { result.append(tabString(tab)); result.append(" "); //$NON-NLS-1$ for (int i = 0; i < this.memberTypeCount; i++) { result.append("\n"); //$NON-NLS-1$ result.append(this.memberTypes[i].toString(tab + 1));
return lastType.add(typeDeclaration, bracketBalanceValue); RecoveredType element = new RecoveredType(typeDeclaration, this, bracketBalanceValue); this.types[this.typeCount++] = element; element.attach( this.pendingAnnotations, this.pendingAnnotationCount,
public String toString(int tab){ StringBuffer buffer = new StringBuffer(tabString(tab)); buffer.append("Recovered field:\n"); //$NON-NLS-1$ this.fieldDeclaration.print(tab + 1, buffer); if (this.annotations != null) { for (int i = 0; i < this.annotationCount; i++) { buffer.append("\n"); //$NON-NLS-1$ buffer.append(this.annotations[i].toString(tab + 1)); } } if (this.anonymousTypes != null) { for (int i = 0; i < this.anonymousTypeCount; i++){ buffer.append("\n"); //$NON-NLS-1$ buffer.append(this.anonymousTypes[i].toString(tab + 1)); } } return buffer.toString(); } public FieldDeclaration updatedFieldDeclaration(int depth, Set<TypeDeclaration> knownTypes){
public RecoveredElement add(FieldDeclaration fieldDeclaration, int bracketBalanceValue) { /* attach it to last type - if any */ if (this.typeCount > 0){ RecoveredType type = this.types[this.typeCount -1]; type.bodyEnd = 0; // reset position type.typeDeclaration.declarationSourceEnd = 0; // reset position type.typeDeclaration.bodyEnd = 0; resetPendingModifiers(); return type.add(fieldDeclaration, bracketBalanceValue); } return this; // ignore } public RecoveredElement add(ImportReference importReference, int bracketBalanceValue) {
@Override public RecoveredElement add(TypeDeclaration typeDeclaration, int bracketBalanceValue) { if (this.alreadyCompletedFieldInitialization || ((typeDeclaration.bits & ASTNode.IsAnonymousType) == 0) || (this.fieldDeclaration.declarationSourceEnd != 0 && typeDeclaration.sourceStart > this.fieldDeclaration.declarationSourceEnd)) { return super.add(typeDeclaration, bracketBalanceValue); } else { // Prepare anonymous type list if (this.anonymousTypes == null) { this.anonymousTypes = new RecoveredType[5]; this.anonymousTypeCount = 0; } else { if (this.anonymousTypeCount == this.anonymousTypes.length) { System.arraycopy( this.anonymousTypes, 0, (this.anonymousTypes = new RecoveredType[2 * this.anonymousTypeCount]), 0, this.anonymousTypeCount); } } // Store type declaration as an anonymous type RecoveredType element = new RecoveredType(typeDeclaration, this, bracketBalanceValue); this.anonymousTypes[this.anonymousTypeCount++] = element; return element; } } public void attach(RecoveredAnnotation[] annots, int annotCount, int mods, int modsSourceStart) {
&& methodDeclaration.declarationSourceStart > this.typeDeclaration.declarationSourceEnd){ this.pendingTypeParameters = null; resetPendingModifiers(); this.pendingModifersSourceStart); resetPendingModifiers();
int bodyEndValue = bodyEnd(); this.memberTypes[this.memberTypeCount - 1].typeDeclaration.declarationSourceEnd = bodyEndValue; this.memberTypes[this.memberTypeCount - 1].typeDeclaration.bodyEnd = bodyEndValue; TypeDeclaration updatedTypeDeclaration = this.memberTypes[i].updatedTypeDeclaration(depth + 1, knownTypes); if (updatedTypeDeclaration != null) { memberTypeDeclarations[existingCount + (updatedCount++)] = updatedTypeDeclaration; int temp = bodyEnd(); this.fields[this.fieldCount - 1].fieldDeclaration.declarationSourceEnd = temp; this.fields[this.fieldCount - 1].fieldDeclaration.declarationEnd = temp; int bodyEndValue = bodyEnd(); this.methods[this.methodCount - 1].methodDeclaration.declarationSourceEnd = bodyEndValue; this.methods[this.methodCount - 1].methodDeclaration.bodyEnd = bodyEndValue; hasConstructor = this.typeDeclaration.checkConstructors(parser()); } else { for (int i = 0; i < existingCount; i++){ this.typeDeclaration.createDefaultConstructor(!parser().diet || insideFieldInitializer, true);
public RecoveredElement add(TypeDeclaration typeDeclaration, int bracketBalanceValue, boolean delegatedByParent) { /* do not consider a type starting passed the block end (if set) it must be belonging to an enclosing block */ if (this.blockDeclaration.sourceEnd != 0 && typeDeclaration.declarationSourceStart > this.blockDeclaration.sourceEnd){ resetPendingModifiers(); if (delegatedByParent) return this; //ignore return this.parent.add(typeDeclaration, bracketBalanceValue); } RecoveredType element = new RecoveredType(typeDeclaration, this, bracketBalanceValue); if(this.pendingAnnotationCount > 0) { element.attach( this.pendingAnnotations, this.pendingAnnotationCount, this.pendingModifiers, this.pendingModifersSourceStart); } resetPendingModifiers(); attach(element); if (typeDeclaration.declarationSourceEnd == 0) return element; return this; } public RecoveredElement addAnnotationName(int identifierPtr, int identifierLengthPtr, int annotationStart, int bracketBalanceValue) {
@Override public String toString(int tab) { StringBuffer result = new StringBuffer(tabString(tab)); result.append("Recovered type:\n"); //$NON-NLS-1$ if ((this.typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) { result.append(tabString(tab)); result.append(" "); //$NON-NLS-1$ for (int i = 0; i < this.memberTypeCount; i++) { result.append("\n"); //$NON-NLS-1$ result.append(this.memberTypes[i].toString(tab + 1));
return lastType.add(typeDeclaration, bracketBalanceValue); RecoveredType element = new RecoveredType(typeDeclaration, this, bracketBalanceValue); this.types[this.typeCount++] = element; element.attach( this.pendingAnnotations, this.pendingAnnotationCount,
public String toString(int tab){ StringBuffer buffer = new StringBuffer(tabString(tab)); buffer.append("Recovered field:\n"); //$NON-NLS-1$ this.fieldDeclaration.print(tab + 1, buffer); if (this.annotations != null) { for (int i = 0; i < this.annotationCount; i++) { buffer.append("\n"); //$NON-NLS-1$ buffer.append(this.annotations[i].toString(tab + 1)); } } if (this.anonymousTypes != null) { for (int i = 0; i < this.anonymousTypeCount; i++){ buffer.append("\n"); //$NON-NLS-1$ buffer.append(this.anonymousTypes[i].toString(tab + 1)); } } return buffer.toString(); } public FieldDeclaration updatedFieldDeclaration(int depth, Set<TypeDeclaration> knownTypes){
public RecoveredElement add(FieldDeclaration fieldDeclaration, int bracketBalanceValue) { /* attach it to last type - if any */ if (this.typeCount > 0){ RecoveredType type = this.types[this.typeCount -1]; type.bodyEnd = 0; // reset position type.typeDeclaration.declarationSourceEnd = 0; // reset position type.typeDeclaration.bodyEnd = 0; resetPendingModifiers(); return type.add(fieldDeclaration, bracketBalanceValue); } return this; // ignore } public RecoveredElement add(ExportsStatement exportReference, int bracketBalanceValue) {
public RecoveredElement add(TypeDeclaration typeDeclaration, int bracketBalanceValue) { if (this.alreadyCompletedFieldInitialization || ((typeDeclaration.bits & ASTNode.IsAnonymousType) == 0) || (this.fieldDeclaration.declarationSourceEnd != 0 && typeDeclaration.sourceStart > this.fieldDeclaration.declarationSourceEnd)) { return super.add(typeDeclaration, bracketBalanceValue); } else { // Prepare anonymous type list if (this.anonymousTypes == null) { this.anonymousTypes = new RecoveredType[5]; this.anonymousTypeCount = 0; } else { if (this.anonymousTypeCount == this.anonymousTypes.length) { System.arraycopy( this.anonymousTypes, 0, (this.anonymousTypes = new RecoveredType[2 * this.anonymousTypeCount]), 0, this.anonymousTypeCount); } } // Store type declaration as an anonymous type RecoveredType element = new RecoveredType(typeDeclaration, this, bracketBalanceValue); this.anonymousTypes[this.anonymousTypeCount++] = element; return element; } } public void attach(RecoveredAnnotation[] annots, int annotCount, int mods, int modsSourceStart) {
&& methodDeclaration.declarationSourceStart > this.typeDeclaration.declarationSourceEnd){ this.pendingTypeParameters = null; resetPendingModifiers(); this.pendingModifersSourceStart); resetPendingModifiers();
@Override public RecoveredElement add(Block nestedBlockDeclaration,int bracketBalanceValue) { this.pendingTypeParameters = null; resetPendingModifiers(); int mods = ClassFileConstants.AccDefault; if(parser().recoveredStaticInitializerStart != 0) { mods = ClassFileConstants.AccStatic; } return this.add(new Initializer(nestedBlockDeclaration, mods), bracketBalanceValue); } @Override