### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java,v retrieving revision 1.210 diff -u -r1.210 CompletionParser.java --- codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 18 Feb 2010 06:50:57 -0000 1.210 +++ codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 29 Mar 2010 13:48:06 -0000 @@ -132,10 +132,6 @@ // a pointer in the expression stack to the qualifier of a invocation int qualifier; - // last modifiers info - int lastModifiers = ClassFileConstants.AccDefault; - int lastModifiersStart = -1; - // used to find if there is unused modifiers when building completion inside a method or an initializer boolean hasUnusedModifiers; Index: codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java,v retrieving revision 1.90 diff -u -r1.90 AssistParser.java --- codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java 22 Jun 2009 14:00:52 -0000 1.90 +++ codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java 29 Mar 2010 13:48:07 -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 @@ -33,7 +33,9 @@ public abstract class AssistParser extends Parser { public ASTNode assistNode; public boolean isOrphanCompletionNode; - + // last modifiers info + protected int lastModifiers = ClassFileConstants.AccDefault; + protected int lastModifiersStart = -1; /* recovery */ int[] blockStarts = new int[30]; @@ -1269,7 +1271,11 @@ //convert bugs into parse error initialize(); - + // set the lastModifiers to reflect the modifiers of the constructor whose + // block statements are being parsed + // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=202634 + this.lastModifiers = cd.modifiers; + this.lastModifiersStart = cd.modifiersSourceStart; // simulate goForConstructorBody except that we don't want to balance brackets because they are not going to be balanced goForBlockStatementsopt(); @@ -1335,7 +1341,11 @@ CompilationUnitDeclaration unit) { initialize(); - + // set the lastModifiers to reflect the modifiers of the initializer whose + // block statements are being parsed + // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=202634 + this.lastModifiers = initializer.modifiers; + this.lastModifiersStart = initializer.modifiersSourceStart; // simulate goForInitializer except that we don't want to balance brackets because they are not going to be balanced goForBlockStatementsopt(); @@ -1392,7 +1402,11 @@ return; initialize(); - + // set the lastModifiers to reflect the modifiers of the method whose + // block statements are being parsed + // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=202634 + this.lastModifiers = md.modifiers; + this.lastModifiersStart = md.modifiersSourceStart; // simulate goForMethodBody except that we don't want to balance brackets because they are not going to be balanced goForBlockStatementsopt(); #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.211 diff -u -r1.211 CompletionTests.java --- src/org/eclipse/jdt/core/tests/model/CompletionTests.java 18 Feb 2010 06:51:07 -0000 1.211 +++ src/org/eclipse/jdt/core/tests/model/CompletionTests.java 29 Mar 2010 13:48:23 -0000 @@ -20766,4 +20766,185 @@ "returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)a).returnZero(), Ltest.CompletionAfterInstanceOf;, ()I, Ltest.CompletionAfterInstanceOf;, returnZero, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}", requestor.getResults()); } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202634 +public void testBug202634a() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n" + + "public class Test {\n" + + " public static void bar(){" + + " System.out.println(\"bar\");\n" + + " }\n" + + " void foo() {\n" + + " sup\n" + + " }\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true); + requestor.allowAllRequiredProposals(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "sup"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + int start1 = str.lastIndexOf("sup"); + int end1 = start1 + "sup".length(); + + assertResults( + "super[KEYWORD]{super, null, null, super, 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=202634 +public void testBug202634b() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n" + + "public class Test {\n" + + " void foo() {\n" + + " sup\n" + + " }\n" + + " public static void bar(){" + + " System.out.println(\"bar\");\n" + + " }\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true); + requestor.allowAllRequiredProposals(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "sup"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + int start1 = str.lastIndexOf("sup"); + int end1 = start1 + "sup".length(); + + assertResults( + "super[KEYWORD]{super, null, null, super, 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=202634 +public void testBug202634c() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n" + + "public class Test {\n" + + " public static void bar(){" + + " System.out.println(\"bar\");\n" + + " }\n" + + " {" + + " sup" + + " }" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true); + requestor.allowAllRequiredProposals(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "sup"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + int start1 = str.lastIndexOf("sup"); + int end1 = start1 + "sup".length(); + + assertResults( + "super[KEYWORD]{super, null, null, super, 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=202634 +public void testBug202634d() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n" + + "public class Test {\n" + + " public static void bar(){" + + " System.out.println(\"bar\");\n" + + " }\n" + + " Test() {" + + " sup" + + " }" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true); + requestor.allowAllRequiredProposals(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "sup"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + int start1 = str.lastIndexOf("sup"); + int end1 = start1 + "sup".length(); + + assertResults( + "super[KEYWORD]{super, null, null, super, null, replace[" + start1 + ", " + end1 +"], token[" + start1 + ", " + end1 + "], " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE+ R_NON_RESTRICTED) + "}\n" + + "super[METHOD_REF]{super(), Ljava.lang.Object;, ()V, super, 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=202634 +public void testBug202634e() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n" + + "public class Test {\n" + + " public static void bar(){" + + " System.out.println(\"bar\");\n" + + " }\n" + + " {" + + " thi" + + " }" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true); + requestor.allowAllRequiredProposals(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "thi"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + int start1 = str.lastIndexOf("thi"); + int end1 = start1 + "thi".length(); + + assertResults( + "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=202634 +public void testBug202634f() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n" + + "public class Test {\n" + + " public static void bar(){" + + " System.out.println(\"bar\");\n" + + " }\n" + + " Test() {" + + " thi" + + " }" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true); + requestor.allowAllRequiredProposals(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "thi"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + int start1 = str.lastIndexOf("thi"); + int end1 = start1 + "thi".length(); + + assertResults( + "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()); +} }