diff options
author | Vikas Chandra | 2018-07-24 05:55:07 +0000 |
---|---|---|
committer | Vikas Chandra | 2018-08-16 09:15:01 +0000 |
commit | 7879f2df9b95dd9e68390b59043451d2ddac7ffc (patch) | |
tree | 6d89fdb66292637abd14b57fa0993e47f670ae38 | |
parent | 6432fdd58a28b72dc3736bdded436559d4f912d6 (diff) | |
download | eclipse.jdt.core-7879f2df9b95dd9e68390b59043451d2ddac7ffc.tar.gz eclipse.jdt.core-7879f2df9b95dd9e68390b59043451d2ddac7ffc.tar.xz eclipse.jdt.core-7879f2df9b95dd9e68390b59043451d2ddac7ffc.zip |
Bug 536983 - Code completion fails for variable in single-line foreachI20180816-2000
loop
Change-Id: I8f0201b811fc03addc62636f0ce07a0cd4f4c79e
Signed-off-by: Vikas Chandra <Vikas.Chandra@in.ibm.com>
2 files changed, 40 insertions, 2 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java index 76ed299072..d897ded6f7 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2018 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 @@ -14592,4 +14592,25 @@ public void testBug526590b() throws JavaModelException { requestor.getResults()); } +public void test536983() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/SingleLineForEach.java", + "package test;\n" + + "public class SingleLineForEach {\n" + + " private void meth() { \n" + + " Object[] f= {new Object(), new Object() };\n" + + " for (Object abc : f) abc.\n" + + "}\n" + + "}\n"); + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, true, true, true, true, true); + requestor.allowAllRequiredProposals(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "abc."; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + assertTrue(!requestor.getResults().equals("")); + assertTrue(requestor.getResults().contains("toString(")); +} + } diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java index e216946aec..460654e14d 100644 --- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java +++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java @@ -181,7 +181,8 @@ public class CompletionParser extends AssistParser { private boolean inReferenceExpression; private IProgressMonitor monitor; private int resumeOnSyntaxError = 0; - + private boolean consumedEnhancedFor; + public CompletionParser(ProblemReporter problemReporter, boolean storeExtraSourceEnds) { super(problemReporter); this.reportSyntaxErrorIsRequired = false; @@ -2617,6 +2618,13 @@ protected void consumeEnhancedForStatement() { } } @Override +protected void consumeEnhancedForStatementHeader(){ + this.consumedEnhancedFor = true; + super.consumeEnhancedForStatementHeader(); + +} + +@Override protected void consumeEnhancedForStatementHeaderInit(boolean hasModifiers) { super.consumeEnhancedForStatementHeaderInit(hasModifiers); this.hasUnusedModifiers = false; @@ -3791,6 +3799,8 @@ protected void consumeToken(int token) { int previous = this.previousToken; int prevIdentifierPtr = this.previousIdentifierPtr; + isInsideEnhancedForLoopWithoutBlock(token); + if (isInsideMethod() || isInsideFieldInitialization() || isInsideAnnotation() || isInsideEnumConstantnitialization()) { switch(token) { case TokenNameLPAREN: @@ -4343,6 +4353,13 @@ protected void consumeToken(int token) { } } } +private void isInsideEnhancedForLoopWithoutBlock(int token) { + if( this.consumedEnhancedFor == true && token != TokenNameLBRACE) { + consumeOpenFakeBlock(); + } + this.consumedEnhancedFor = false; + +} @Override protected void consumeInvocationExpression() { // on error, a message send's error reductions will take the expression path rather than the statement path since that is a dead end. super.consumeInvocationExpression(); |