Skip to content

Commit

Permalink
Additional Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanth-sankaran committed Sep 10, 2023
1 parent 699f3da commit 1062004
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13052,7 +13052,7 @@ protected void parse() {
}
this.stack[this.stateStackTop] = act;
this.unstackedAct = act = actFromTokenOrSynthetic(act);
if (act == ERROR_ACTION || this.restartRecovery) {
if (act == ERROR_ACTION || this.restartRecovery()) {
if (DEBUG_AUTOMATON) {
if (this.restartRecovery) {
System.out.println("Restart - "); //$NON-NLS-1$
Expand Down Expand Up @@ -13237,6 +13237,9 @@ protected void parse() {
this.problemReporter.referenceContext = null; // Null this so we won't escalate problems needlessly (bug 393192)
if (DEBUG) System.out.println("-- EXIT FROM PARSE METHOD --"); //$NON-NLS-1$
}
protected boolean restartRecovery() {
return this.restartRecovery;
}
protected int fetchNextToken() throws InvalidInputException {
return this.scanner.getNextToken();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1201,10 +1201,11 @@ public void testIssue708_2() throws JavaModelException {
" }\n" +
" }\n" +
" case anotherValue ->\n" +
" case \"Test\" ->\n" +
" <SelectOnName:Type.anotherValue>;\n" +
" switch (string) {\n" +
" case \"Test\" ->\n" +
" <SelectOnName:Type.anotherValue>;\n" +
" }\n" +
" }\n" +

" }\n" +
" }\n" +
" }\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public class SelectionParserTest18 extends AbstractSelectionTest {
static {
// TESTS_NUMBERS = new int[] { 53 };
TESTS_NAMES = new String[] { "testBug486264_selectionOnLambda_expectLambdaMethod" };
// TESTS_NAMES = new String[] { "testBug486264_selectionOnLambda_expectLambdaMethod" };
}
public static Test suite() {
return buildMinimalComplianceTestSuite(SelectionParserTest18.class, F_1_8);
Expand Down Expand Up @@ -279,19 +279,17 @@ public void test495912() {
"package xy;\n" +
"public class Test {\n" +
" {\n" +
" {\n" +
" Runnable r = () -> {\n" +
" Integer i;\n" +
" byte b = <SelectOnMessageSend:i.byteValue()>;\n" +
" if (true)\n" +
" {\n" +
" if (false)\n" +
" {\n" +
" }\n" +
" }\n" +
" String s;\n" +
" };\n" +
" }\n" +
" Runnable r = () -> {\n" +
" Integer i;\n" +
" byte b = <SelectOnMessageSend:i.byteValue()>;\n" +
" if (true)\n" +
" {\n" +
" if (false)\n" +
" {\n" +
" }\n" +
" }\n" +
" String s;\n" +
" };\n" +
" }\n" +
" public Test() {\n" +
" }\n" +
Expand Down Expand Up @@ -341,21 +339,19 @@ public void test495912a() {
"package xy;\n" +
"public class Test {\n" +
" {\n" +
" {\n" +
" Runnable r = () -> {\n" +
" Integer i;\n" +
" byte b = <SelectOnMessageSend:i.byteValue()>;\n" +
" if (true)\n" +
" {\n" +
" if (false)\n" +
" {\n" +
" }\n" +
" }\n" +
" for (int i1;; (i1 < 42); i1 ++) \n" +
" Runnable r = () -> {\n" +
" Integer i;\n" +
" byte b = <SelectOnMessageSend:i.byteValue()>;\n" +
" if (true)\n" +
" {\n" +
" if (false)\n" +
" {\n" +
" }\n" +
" }\n" +
" };\n" +
" }\n" +
" for (int i1;; (i1 < 42); i1 ++) \n" +
" {\n" +
" }\n" +
" };\n" +
" }\n" +
" public Test() {\n" +
" }\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.eclipse.jdt.internal.codeassist.select.SelectionNodeFound;
import org.eclipse.jdt.internal.codeassist.select.SelectionOnPackageVisibilityReference;
import org.eclipse.jdt.internal.codeassist.select.SelectionOnImportReference;
import org.eclipse.jdt.internal.codeassist.select.SelectionOnLambdaExpression;
import org.eclipse.jdt.internal.codeassist.select.SelectionOnLocalName;
import org.eclipse.jdt.internal.codeassist.select.SelectionOnMessageSend;
import org.eclipse.jdt.internal.codeassist.select.SelectionOnPackageReference;
Expand Down Expand Up @@ -1283,7 +1284,7 @@ private void selectFrom(Binding binding, CompilationUnitDeclaration parsedUnit,

// when a full lambda expression is selected we will find the paser.assistedNode to represent that
// lambda expression. So we use that state to differentiate hover over "->" vs full lambda expression selection.
if(this.parser.assistNode instanceof LambdaExpression) {
if(this.parser.assistNode instanceof SelectionOnLambdaExpression) {
LambdaExpression lambdaExpr = (LambdaExpression) this.parser.assistNode;
SyntheticMethodBinding methodBinding = new SyntheticMethodBinding(lambdaExpr,
CharOperation.concat(TypeConstants.ANONYMOUS_METHOD, Integer.toString(lambdaExpr.ordinal).toCharArray()), (SourceTypeBinding)lambdaExpr.binding.declaringClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,15 +716,15 @@ protected boolean isAssistParser() {
@Override
protected void consumeBlockStatement() {
super.consumeBlockStatement();
if (triggerRecoveryUponLambdaClosure((Statement) this.astStack[this.astPtr], true) && this.currentElement != null)
this.restartRecovery = true;
// if (triggerRecoveryUponLambdaClosure((Statement) this.astStack[this.astPtr], true) && this.currentElement != null)
// this.restartRecovery = true;
}
@Override
protected void consumeBlockStatements() {
super.consumeBlockStatements();
if (triggerRecoveryUponLambdaClosure((Statement) this.astStack[this.astPtr], true) && this.currentElement != null) {
this.restartRecovery = true;
}
// if (triggerRecoveryUponLambdaClosure((Statement) this.astStack[this.astPtr], true) && this.currentElement != null) {
// this.restartRecovery = true;
// }
}
@Override
protected void consumeBlock() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ private void buildMoreCompletionContext(Expression expression) {
0,
length);
statements[length] = orphan;
this.astPtr = newAstPtr;
boolean exprSwitch = false;
for (Statement s: statements) {
if (s instanceof CaseStatement cs && cs.isExpr) {
Expand Down Expand Up @@ -948,15 +949,21 @@ protected void consumeLambdaExpression() {
if (this.selectionStart == arrowStart || this.selectionStart == arrowEnd) {
if (this.selectionEnd == arrowStart || this.selectionEnd == arrowEnd) {
this.expressionStack[this.expressionPtr] = new SelectionOnLambdaExpression(expression);
this.assistNode = expression;
}
} else if (this.selectionStart == expression.sourceStart && this.selectionEnd == expression.sourceEnd) {
SelectionOnLambdaExpression lambdaExpression = new SelectionOnLambdaExpression(expression);
this.expressionStack[this.expressionPtr] = lambdaExpression;
this.assistNode = lambdaExpression;
this.lastCheckPoint = lambdaExpression.sourceEnd + 1;
}
if (!(this.selectionStart >= expression.sourceStart && this.selectionEnd <= expression.sourceEnd))
popElement(K_LAMBDA_EXPRESSION_DELIMITER);

popElement(K_LAMBDA_EXPRESSION_DELIMITER);
if (this.selectionStart >= expression.sourceStart && this.selectionEnd <= expression.sourceEnd) {
if (!isIndirectlyInsideLambdaExpression()) {
this.selectionNodeFoundLevel = 1;
}
}
}
@Override
protected void consumeReferenceExpression(ReferenceExpression referenceExpression) {
Expand Down Expand Up @@ -989,7 +996,7 @@ protected void consumeLocalVariableDeclarationStatement() {
@Override
protected void consumeAssignment() {
super.consumeAssignment();
checkRestartRecovery();
//checkRestartRecovery();
}

@Override
Expand All @@ -1016,9 +1023,9 @@ protected void consumeBlockStatement() {
checkRestartRecovery();
}
protected void checkRestartRecovery() {
if (this.selectionNodeFoundLevel > 0) {
if (--this.selectionNodeFoundLevel == 0)
this.restartRecovery = true;
if (this.selectionNodeFoundLevel == 1) {
this.selectionNodeFoundLevel = 0;
this.restartRecovery = true;
}
}

Expand Down Expand Up @@ -1818,6 +1825,19 @@ protected int resumeAfterRecovery() {
return super.resumeAfterRecovery();
}

@Override
protected boolean restartRecovery() {
boolean ret = requireExtendedRecovery() ?
false :
super.restartRecovery();
return ret;
}

@Override
public boolean requireExtendedRecovery() {
return lastIndexOfElement(K_LAMBDA_EXPRESSION_DELIMITER) >= 0 || this.selectionNodeFoundLevel > 0;
}

public void selectionIdentifierCheck(){
if (checkRecoveredType()) return;
}
Expand Down

0 comments on commit 1062004

Please sign in to comment.