### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredField.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredField.java,v retrieving revision 1.40 diff -u -r1.40 RecoveredField.java --- compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredField.java 17 Jun 2009 11:04:30 -0000 1.40 +++ compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredField.java 30 Mar 2010 11:15:46 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -207,8 +207,8 @@ TypeDeclaration anonymousType = recoveredType.updatedTypeDeclaration(depth + 1, knownTypes); if (anonymousType != null) { this.fieldDeclaration.initialization = anonymousType.allocation; - if(this.fieldDeclaration.declarationSourceEnd == 0) { - int end = anonymousType.declarationSourceEnd; + int end = anonymousType.declarationSourceEnd; + if (end > this.fieldDeclaration.declarationSourceEnd) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=307337 this.fieldDeclaration.declarationSourceEnd = end; this.fieldDeclaration.declarationEnd = end; } #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/CompletionTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java,v retrieving revision 1.212 diff -u -r1.212 CompletionTests.java --- src/org/eclipse/jdt/core/tests/model/CompletionTests.java 30 Mar 2010 06:36:23 -0000 1.212 +++ src/org/eclipse/jdt/core/tests/model/CompletionTests.java 30 Mar 2010 11:16:04 -0000 @@ -20947,4 +20947,31 @@ "this[KEYWORD]{this, null, null, this, null, replace[" + start1 + ", " + end1 +"], token[" + start1 + ", " + end1 + "], " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}", requestor.getResults()); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=307337 +public void testBug307337() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/TestBug307337.java", + "package test;\n" + + "public class TestBug307337 {\n" + + " Object obj = new Object() {\n" + + " TestBug307337\n" + + " };\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true); + requestor.allowAllRequiredProposals(); + requestor.setRequireExtendedContext(true); + requestor.setComputeEnclosingElement(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "TestBug307337"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "expectedTypesSignatures=null\n" + + "expectedTypesKeys=null\n" + + "enclosingElement= {key=Ltest/TestBug307337$64;} [in obj [in TestBug307337 [in [Working copy] TestBug307337.java [in test [in src [in Completion]]]]]]", + requestor.getContext()); +} }