Comments (4)
Doesn't work as far back as Eclipse 4.8, so its not a regression from some recent fix.
Moving Object obj;
in eclipse_bug.CurrentTextSelectionCannotBeOpened.somecode()
results in working selection. Same if obj =
is removed.
The SelectionParser
instruction stack seems to be in an inconsistent state. This leads to the following chain of problems.
The code here is setting the contents that are evaluated for the selection:
"Text Viewer Hover Presenter" #237 daemon prio=1 os_prio=0 cpu=42.62ms elapsed=68.08s tid=0x00007fa3b041c4f0 nid=0x417a runnable [0x00007fa374bfe000]
java.lang.Thread.State: RUNNABLE
at org.eclipse.jdt.internal.compiler.parser.RecoveredMethod.updatedMethodDeclaration(RecoveredMethod.java:386)
at org.eclipse.jdt.internal.compiler.parser.RecoveredMethod.updateParseTree(RecoveredMethod.java:602)
at org.eclipse.jdt.internal.compiler.parser.Parser.endParse(Parser.java:11964)
at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:13184)
at org.eclipse.jdt.internal.codeassist.impl.AssistParser.parseBlockStatements(AssistParser.java:2100)
at org.eclipse.jdt.internal.codeassist.impl.AssistParser.parseBlockStatements(AssistParser.java:1940)
at org.eclipse.jdt.internal.codeassist.impl.Engine.parseBlockStatements(Engine.java:349)
at org.eclipse.jdt.internal.codeassist.impl.Engine.parseBlockStatements(Engine.java:312)
at org.eclipse.jdt.internal.codeassist.SelectionEngine.select(SelectionEngine.java:1081)
at org.eclipse.jdt.internal.core.Openable.codeSelect(Openable.java:167)
at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:389)
at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:382)
at org.eclipse.jdt.internal.ui.text.java.hover.AbstractJavaEditorTextHover.getJavaElementsAt(AbstractJavaEditorTextHover.java:121)
at org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover.internalGetHoverInfo(JavadocHover.java:662)
at org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover.getHoverInfo2(JavadocHover.java:658)
at org.eclipse.jdt.internal.ui.text.java.hover.BestMatchHover.getHoverInfo2(BestMatchHover.java:163)
at org.eclipse.jdt.internal.ui.text.java.hover.BestMatchHover.getHoverInfo2(BestMatchHover.java:130)
at org.eclipse.jdt.internal.ui.text.java.hover.JavaEditorTextHoverProxy.getHoverInfo2(JavaEditorTextHoverProxy.java:89)
at org.eclipse.jface.text.TextViewerHoverManager$1.run(TextViewerHoverManager.java:155)
The "good" block is set by AssistParser.buildInitialRecoveryState()
, in the LocalDeclaration
block.
In the broken case Parser.astPtr
is set to -1
and so this code does nothing.
For the working case, the recovery sets the method to:
{
Object obj = new Object() {
public boolean somecode() {
Super sup;
return <SelectOnMessageSend:sup.boolMethod()>;
}
};
}
In the bad case, what is set is:
[<SelectOnMessageSend:sup.boolMethod()>]
This misses the declaration of sup
of type Super
and so eventually leads to creating the ProblemReferenceBinding
for sup
:
"Text Viewer Hover Presenter" #157 daemon prio=1 os_prio=0 cpu=3.63ms elapsed=36.60s tid=0x00007f8526c05570 nid=0x19a69 at breakpoint [0x00007f837c2fd000]
java.lang.Thread.State: RUNNABLE
at org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding.<init>(ProblemReferenceBinding.java:29)
at org.eclipse.jdt.internal.compiler.lookup.Scope.getTypeOrPackage(Scope.java:3564)
at org.eclipse.jdt.internal.compiler.lookup.Scope.getBinding(Scope.java:2291)
at org.eclipse.jdt.internal.compiler.ast.SingleNameReference.resolveType(SingleNameReference.java:1020)
at org.eclipse.jdt.internal.compiler.ast.MessageSend.resolveType(MessageSend.java:739)
at org.eclipse.jdt.internal.codeassist.select.SelectionOnMessageSend.resolveType(SelectionOnMessageSend.java:101)
at org.eclipse.jdt.internal.compiler.ast.Expression.resolve(Expression.java:1113)
at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclaration.java:662)
at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatements(MethodDeclaration.java:388)
at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:571)
at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1506)
at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1631)
at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:668)
at org.eclipse.jdt.internal.codeassist.SelectionEngine.select(SelectionEngine.java:1086)
at org.eclipse.jdt.internal.core.Openable.codeSelect(Openable.java:167)
at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:389)
at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:382)
at org.eclipse.jdt.internal.ui.text.java.hover.AbstractJavaEditorTextHover.getJavaElementsAt(AbstractJavaEditorTextHover.java:121)
at org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover.internalGetHoverInfo(JavadocHover.java:662)
at org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover.getHoverInfo2(JavadocHover.java:658)
at org.eclipse.jdt.internal.ui.text.java.hover.BestMatchHover.getHoverInfo2(BestMatchHover.java:163)
at org.eclipse.jdt.internal.ui.text.java.hover.BestMatchHover.getHoverInfo2(BestMatchHover.java:130)
at org.eclipse.jdt.internal.ui.text.java.hover.JavaEditorTextHoverProxy.getHoverInfo2(JavaEditorTextHoverProxy.java:89)
at org.eclipse.jface.text.TextViewerHoverManager$1.run(TextViewerHoverManager.java:155)
from eclipse.jdt.core.
Comparing those 2 cases seems to be the easiest option:
public boolean somecode(){
new Object(){
public boolean somecode(){
Super sup=new Super();
return sup.boolMethod();
}
};
return false;
}
(selection works)
public boolean somecode(){
obj=new Object(){
public boolean somecode(){
Super sup=new Super();
return sup.boolMethod();
}
};
return false;
}
(selection doesn't work)
At this call, the parser stacks are in the same state:
"ModalContext" #704 prio=6 os_prio=0 cpu=2.64ms elapsed=18.68s tid=0x00007f0dea0e1640 nid=0xe390 at breakpoint [0x00007f0bd7bfe000]
java.lang.Thread.State: RUNNABLE
at org.eclipse.jdt.internal.compiler.parser.Parser.classInstanceCreation(Parser.java:1358)
at org.eclipse.jdt.internal.codeassist.select.SelectionParser.classInstanceCreation(SelectionParser.java:330)
at org.eclipse.jdt.internal.compiler.parser.Parser.consumeClassInstanceCreationExpression(Parser.java:2793)
at org.eclipse.jdt.internal.compiler.parser.Parser.consumeRule(Parser.java:7980)
at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:13156)
at org.eclipse.jdt.internal.codeassist.impl.AssistParser.parseBlockStatements(AssistParser.java:2100)
at org.eclipse.jdt.internal.codeassist.impl.AssistParser.parseBlockStatements(AssistParser.java:1940)
at org.eclipse.jdt.internal.codeassist.impl.Engine.parseBlockStatements(Engine.java:349)
at org.eclipse.jdt.internal.codeassist.impl.Engine.parseBlockStatements(Engine.java:312)
at org.eclipse.jdt.internal.codeassist.SelectionEngine.select(SelectionEngine.java:1081)
at org.eclipse.jdt.internal.core.Openable.codeSelect(Openable.java:167)
at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:389)
at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:382)
at org.eclipse.jdt.internal.ui.actions.SelectionConverter.codeResolve(SelectionConverter.java:270)
at org.eclipse.jdt.internal.ui.actions.SelectionConverter$1CodeResolveRunnable.run(SelectionConverter.java:254)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:122)
Parser.astPtr
is -1
is and Parser.astStack
is:
[
{
public boolean somecode() {
Super sup;
return <SelectOnMessageSend:sup.boolMethod()>;
}
},
public boolean somecode() {
Super sup;
return <SelectOnMessageSend:sup.boolMethod()>;
},
Super sup;,
return <SelectOnMessageSend:sup.boolMethod()>;
]
In the broken selection case, astPtr
is not changed anymore until this code is reached:
"ModalContext" #704 prio=6 os_prio=0 cpu=2.71ms elapsed=151.35s tid=0x00007f0dea0e1640 nid=0xe390 at breakpoint [0x00007f0bd7bfe000]
java.lang.Thread.State: RUNNABLE
at org.eclipse.jdt.internal.codeassist.impl.AssistParser.buildInitialRecoveryState(AssistParser.java:251)
at org.eclipse.jdt.internal.compiler.parser.Parser.resumeOnSyntaxError(Parser.java:14533)
at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:13062)
at org.eclipse.jdt.internal.codeassist.impl.AssistParser.parseBlockStatements(AssistParser.java:2100)
at org.eclipse.jdt.internal.codeassist.impl.AssistParser.parseBlockStatements(AssistParser.java:1940)
at org.eclipse.jdt.internal.codeassist.impl.Engine.parseBlockStatements(Engine.java:349)
at org.eclipse.jdt.internal.codeassist.impl.Engine.parseBlockStatements(Engine.java:312)
at org.eclipse.jdt.internal.codeassist.SelectionEngine.select(SelectionEngine.java:1081)
at org.eclipse.jdt.internal.core.Openable.codeSelect(Openable.java:167)
at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:389)
at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:382)
at org.eclipse.jdt.internal.ui.actions.SelectionConverter.codeResolve(SelectionConverter.java:270)
at org.eclipse.jdt.internal.ui.actions.SelectionConverter$1CodeResolveRunnable.run(SelectionConverter.java:254)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:122)
And so the bad block is set for the selection evaluation.
In the working selection case, there is an extra call that sets astPtr
to 0
(and so AssistParser.buildInitialRecoveryState()
creates the full block for the selection):
"ModalContext" #721 prio=6 os_prio=0 cpu=2.88ms elapsed=63.95s tid=0x00007f0dea0f4970 nid=0xe651 at breakpoint [0x00007f0bd7dfe000]
java.lang.Thread.State: RUNNABLE
at org.eclipse.jdt.internal.compiler.parser.Parser.setAstPtr(Parser.java:14787)
at org.eclipse.jdt.internal.compiler.parser.Parser.pushOnAstStack(Parser.java:13940)
at org.eclipse.jdt.internal.compiler.parser.Parser.consumeExpressionStatement(Parser.java:4290)
at org.eclipse.jdt.internal.compiler.parser.Parser.consumeRule(Parser.java:7604)
at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:13156)
at org.eclipse.jdt.internal.codeassist.impl.AssistParser.parseBlockStatements(AssistParser.java:2100)
at org.eclipse.jdt.internal.codeassist.impl.AssistParser.parseBlockStatements(AssistParser.java:1940)
at org.eclipse.jdt.internal.codeassist.impl.Engine.parseBlockStatements(Engine.java:349)
at org.eclipse.jdt.internal.codeassist.impl.Engine.parseBlockStatements(Engine.java:312)
at org.eclipse.jdt.internal.codeassist.SelectionEngine.select(SelectionEngine.java:1081)
at org.eclipse.jdt.internal.core.Openable.codeSelect(Openable.java:167)
at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:389)
at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:382)
at org.eclipse.jdt.internal.ui.actions.SelectionConverter.codeResolve(SelectionConverter.java:270)
at org.eclipse.jdt.internal.ui.actions.SelectionConverter$1CodeResolveRunnable.run(SelectionConverter.java:254)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:122)
The assignment obj=
is parsed as an expression and is not part of astStack
, apparently:
"ModalContext" #757 prio=6 os_prio=0 cpu=9.62ms elapsed=28.49s tid=0x00007f0deaf13f60 nid=0xecb6 runnable [0x00007f0bd7bfe000]
java.lang.Thread.State: RUNNABLE
at org.eclipse.jdt.internal.compiler.parser.Parser.consumeAssignment(Parser.java:1925)
at org.eclipse.jdt.internal.codeassist.select.SelectionParser.consumeAssignment(SelectionParser.java:961)
at org.eclipse.jdt.internal.compiler.parser.Parser.consumeRule(Parser.java:8296)
at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:13156)
at org.eclipse.jdt.internal.codeassist.impl.AssistParser.parseBlockStatements(AssistParser.java:2100)
at org.eclipse.jdt.internal.codeassist.impl.AssistParser.parseBlockStatements(AssistParser.java:1940)
at org.eclipse.jdt.internal.codeassist.impl.Engine.parseBlockStatements(Engine.java:349)
at org.eclipse.jdt.internal.codeassist.impl.Engine.parseBlockStatements(Engine.java:312)
at org.eclipse.jdt.internal.codeassist.SelectionEngine.select(SelectionEngine.java:1081)
at org.eclipse.jdt.internal.core.Openable.codeSelect(Openable.java:167)
at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:389)
at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:382)
at org.eclipse.jdt.internal.ui.actions.SelectionConverter.codeResolve(SelectionConverter.java:270)
at org.eclipse.jdt.internal.ui.actions.SelectionConverter$1CodeResolveRunnable.run(SelectionConverter.java:254)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:122)
But the codde for expressions in AssistParser.buildInitialRecoveryState()
does nothing with the assignment:
// This is copy of the code that processes astStack early in this method
for (int i = 0; i <= this.expressionPtr; i++, lastNode = node) {
node = this.expressionStack[i];
if (node == null || !(node instanceof InstanceOfExpression)) continue;
I'm guessing we must add handling for expressions here.
from eclipse.jdt.core.
This problem goes away with the commit 8cbe978 that addressed a whole slew of defects
(#1195, #769, #1263, #1360, #1364, #1278, #1288) - I'll release a test case for the snippet from the problem description and close this defect.
For the record, the recovered parse tree now is
public boolean somecode() {
new Object() {
public boolean somecode() {
Super sup;
return <SelectOnMessageSend:sup.boolMethod()>;
}
};
}
from eclipse.jdt.core.
Regression test to verify right behavior here: srikanth-sankaran@574f4bf
from eclipse.jdt.core.
Related Issues (20)
- [Patterns][records] ECJ fails to generate code to deconstruct record in pattern
- [Patterns] Design smell: Pattern classes are far from object oriented
- IllegalArgumentException using newer batch compiler with ast parser HOT 5
- Migration of JDT wiki pages HOT 2
- Missing resource leak warning for FileInputStream HOT 1
- [Sealed classes] Incorrect Reconciler error: The type A that implements a sealed interface I should be a permitted subtype of I
- [Patterns][records] Instanceof with record deconstruction patterns should never be flagged as unnecessary
- [Patterns][records] ECJ fails to reject incompatible pattern types.
- Code format HOT 2
- ECJ produces redundant bytecode for instanceof pattern matching HOT 3
- [Patterns] ECJ generates suspect code for switching over patterns
- IrritantSet needs unsigned right shift for GROUP4 and higher HOT 4
- [Patterns][records][inference] ECJ never computes the upwards projection for var type inference in record patterns HOT 3
- [Patterns][unnamed] Support for identifier '_' for old compile source/target versions HOT 2
- [Patterns][internal] toString() output of AST nodes shows up with modifier sealed for pattern variables
- [Switch][Pattern] Withdraw the internal AST APIs Pattern.suspendVariables & Pattern.resumeVariables
- [Patterns][Unnamed] Wasteful allocation and assignment into unnamed pattern variables.
- [Patterns][internal] High degree of code duplication in instanceof pattern code generation
- [Patterns][Unnamed] VerifyError with unnamed pattern variable in instanceof HOT 1
- CommentRecorderParser sometimes generates ranges that miss Javadoc HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eclipse.jdt.core.