Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 577508 - Fixing regression #38

Merged
merged 1 commit into from Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2020 IBM Corporation and others.
* Copyright (c) 2000, 2022 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -1980,9 +1980,7 @@ public void test45() {
" public X() {\n"+
" }\n"+
" void foo() {\n"+
" if ((x instanceof <SelectOnType:Object> s))\n" +
" {\n" +
" }\n" +
" <SelectOnType:Object> s;\n" +
" }\n"+
"}\n";
String expectedReplacedSource = "Object";
Expand Down
Expand Up @@ -25,7 +25,7 @@ public class ResolveTests12To15 extends AbstractJavaModelTests {
ICompilationUnit wc = null;

static {
// TESTS_NAMES = new String[] { "testBug577508_3" };
// TESTS_NAMES = new String[] { "testBug577508_4" };
// TESTS_NUMBERS = new int[] { 124 };
// TESTS_RANGE = new int[] { 16, -1 };
}
Expand Down Expand Up @@ -884,4 +884,36 @@ public void testBug577508_3() throws JavaModelException {
elements
);
}
public void testBug577508_4() throws JavaModelException {
this.wc = getWorkingCopy("/Resolve15/src/X.java",
"public class X {\n"
+ " static public void main (String[] args) {\n"
+ " Object[] objects = new Object[3];\n"
+ " for (Object object : objects) \n"
+ " if (object instanceof String string && !(object instanceof Runnable)) \n"
+ " System.out.println(); // Open Declaration fails here if you remove the braces from the for loop.\n"
+ " System.out.println(); // Open Declaration always fails here.\n"
+ "}\n"
+ "}");
String str = this.wc.getSource();
String selection = "println";
int start = str.indexOf(selection);
int length = selection.length();
IJavaElement[] elements = this.wc.codeSelect(start, length);
assertElementsEqual(
"Unexpected elements",
"println(java.lang.String) [in PrintStream [in PrintStream.class [in java.io [in "+ getExternalPath() + "jclMin14.jar]]]]",
elements
);

str = this.wc.getSource();
start = str.lastIndexOf(selection);
length = selection.length();
elements = this.wc.codeSelect(start, length);
assertElementsEqual(
"Unexpected elements",
"println(java.lang.String) [in PrintStream [in PrintStream.class [in java.io [in "+ getExternalPath() + "jclMin14.jar]]]]",
elements
);
}
}
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.codeassist.impl.AssistParser;
import org.eclipse.jdt.internal.compiler.CompilationResult;
import org.eclipse.jdt.internal.compiler.ast.AND_AND_Expression;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration;
import org.eclipse.jdt.internal.compiler.ast.AllocationExpression;
Expand All @@ -42,6 +43,7 @@
import org.eclipse.jdt.internal.compiler.ast.FieldReference;
import org.eclipse.jdt.internal.compiler.ast.GuardedPattern;
import org.eclipse.jdt.internal.compiler.ast.ImportReference;
import org.eclipse.jdt.internal.compiler.ast.InstanceOfExpression;
import org.eclipse.jdt.internal.compiler.ast.LambdaExpression;
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
import org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation;
Expand Down Expand Up @@ -817,10 +819,34 @@ protected void consumeInsideCastExpressionWithQualifiedGenerics() {
pushOnElementStack(K_CAST_STATEMENT);
}
@Override
protected Expression consumePatternInsideInstanceof(Pattern pattern) {
Expression exp = super.consumePatternInsideInstanceof(pattern);
pushOnPatternStack(pattern); // Push it back again.
return exp;
protected void consumeInstanceOfExpression() {
if (indexOfAssistIdentifier() < 0) {
super.consumeInstanceOfExpression();
int length = this.expressionLengthPtr >= 0 ?
this.expressionLengthStack[this.expressionLengthPtr] : 0;
if (length > 0) {
Expression exp = this.expressionStack[this.expressionPtr];
LocalDeclaration local = null;
if (exp instanceof InstanceOfExpression) {
local = ((InstanceOfExpression) exp).elementVariable;
} else if (exp instanceof AND_AND_Expression) {
InstanceOfExpression insExpr = (InstanceOfExpression) ((AND_AND_Expression) exp).left;
local = insExpr.elementVariable;
}
if (local != null) {
pushOnAstStack(local);
if (!this.diet) {
this.restartRecovery = true;
this.lastIgnoredToken = -1;
}
}
}
} else {
getTypeReference(this.intStack[this.intPtr--]);
this.isOrphanCompletionNode = true;
this.restartRecovery = true;
this.lastIgnoredToken = -1;
}
}
@Override
protected void consumeInstanceOfExpressionWithName() {
Expand Down