Skip to content

Commit

Permalink
Bug 577508 - Fixing regression
Browse files Browse the repository at this point in the history
Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
  • Loading branch information
jarthana committed Apr 25, 2022
1 parent 1555edc commit fcf05f8
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 5 deletions.
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

0 comments on commit fcf05f8

Please sign in to comment.