Bug 435571 - ImportReferencesCollector needs to support old AST levels
Summary: ImportReferencesCollector needs to support old AST levels
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 critical (vote)
Target Milestone: 4.4 RC3   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 436198 (view as bug list)
Depends on:
Blocks: 435540
  Show dependency tree
 
Reported: 2014-05-22 17:39 EDT by Markus Keller CLA
Modified: 2014-06-03 00:28 EDT (History)
6 users (show)

See Also:
noopur_gupta: review+
manju656: review+
daniel_megert: review+


Attachments
Fix 1 (2.99 KB, patch)
2014-05-22 18:30 EDT, Markus Keller CLA
no flags Details | Diff
Fix 1 + tests (6.00 KB, patch)
2014-05-23 08:59 EDT, Markus Keller CLA
daniel_megert: review+
manju656: review+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2014-05-22 17:39:57 EDT
ImportReferencesCollector needs to support old AST levels, see bug 435540.

org.eclipse.jdt.ui.actions.OverrideMethodsAction#createRunnable(..) is a legal way to create an AddUnimplementedMethodsOperation, and there's no restriction on the AST level there. Most of JDT UI only uses the latest AST level, but in this case, we have to support older levels as well.

org.eclipse.jst.j2ee.ejb.annotation.model
Error
Thu May 22 19:26:03 EEST 2014
Operation only supported in JLS8 and later AST

java.lang.UnsupportedOperationException: Operation only supported in JLS8 and later AST
	at org.eclipse.jdt.core.dom.ASTNode.unsupportedIn2_3_4(ASTNode.java:1968)
	at org.eclipse.jdt.core.dom.AnnotatableType.annotations(AnnotatableType.java:99)
	at org.eclipse.jdt.internal.corext.codemanipulation.ImportReferencesCollector.visit(ImportReferencesCollector.java:203)
	at org.eclipse.jdt.core.dom.SimpleType.accept0(SimpleType.java:197)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2711)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2782)
	at org.eclipse.jdt.core.dom.TypeDeclaration.accept0(TypeDeclaration.java:469)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2711)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2782)
	at org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:212)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2711)
	at org.eclipse.jdt.internal.corext.codemanipulation.ImportReferencesCollector.collect(ImportReferencesCollector.java:68)
	at org.eclipse.jdt.internal.corext.codemanipulation.ImportReferencesCollector.collect(ImportReferencesCollector.java:62)
	at org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext.getImportedNames(ContextSensitiveImportRewriteContext.java:226)
	at org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext.findInContext(ContextSensitiveImportRewriteContext.java:99)
	at org.eclipse.jdt.core.dom.rewrite.ImportRewrite.internalAddImport(ImportRewrite.java:941)
	at org.eclipse.jdt.core.dom.rewrite.ImportRewrite.addImport(ImportRewrite.java:639)
	at org.eclipse.jdt.internal.corext.codemanipulation.StubUtility2.createThrownExceptions(StubUtility2.java:509)
	at org.eclipse.jdt.internal.corext.codemanipulation.StubUtility2.createImplementationStub(StubUtility2.java:349)
	at org.eclipse.jdt.internal.corext.codemanipulation.StubUtility2.createImplementationStub(StubUtility2.java:315)
	at org.eclipse.jdt.internal.corext.codemanipulation.AddUnimplementedMethodsOperation.run(AddUnimplementedMethodsOperation.java:213)
	at org.eclipse.jst.j2ee.ejb.annotations.internal.classgen.EjbBuilder.createInheritedMethods(EjbBuilder.java:221)
...
Comment 1 Markus Keller CLA 2014-05-22 18:30:36 EDT
Created attachment 243416 [details]
Fix 1

Tentative fix. I think this covers all relevant cases, but the fix needs more testing.
Comment 2 Markus Keller CLA 2014-05-23 08:59:07 EDT
Created attachment 243439 [details]
Fix 1 + tests
Comment 3 Dani Megert CLA 2014-05-23 10:00:58 EDT
Did you check the following locations for similar issues?

org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal.createImportRewrite(CompilationUnit)

org.eclipse.jdt.ui.text.java.IProblemLocation.getCoveringNode(CompilationUnit)

org.eclipse.jdt.ui.text.java.IProblemLocation.getCoveredNode(CompilationUnit)

org.eclipse.jdt.ui.CodeStyleConfiguration.createImportRewrite(CompilationUnit, boolean)

?
Comment 4 Dani Megert CLA 2014-05-23 11:06:10 EDT
Comment on attachment 243439 [details]
Fix 1 + tests

I've code reviewed the fix and it looks good. Also ran /Eclipse ZRH ALL Tests.

For the final review+ I need an positive answer to comment 3.
Comment 5 Markus Keller CLA 2014-05-23 11:09:52 EDT
(In reply to Dani Megert from comment #3)
> Did you check the following locations for similar issues?

Yes, I checked the whole ImportRewrite stuff and referenced classes like ContextSensitiveImportRewriteContext and ScopeAnalyzer (covers location 1 & 4).

The implementations of IProblemLocation.getCover*Node() are harmless as well.

I've also looked through the entry points mentioned in bug 435572 comment 1.

We do have some problems with JLS2 ASTs, that's why the tests only start with JLS3. But these problems have been in before Luna and JLS2 is very outdated. I don't think we should touch more code than necessary at RC3.
Comment 6 Dani Megert CLA 2014-05-23 11:14:19 EDT
(In reply to Markus Keller from comment #5)

Thanks for the complete analysis.
Comment 7 Noopur Gupta CLA 2014-05-26 01:21:35 EDT
Looks good.
Comment 8 Martin Mathew CLA 2014-05-26 05:45:10 EDT
Comment on attachment 243439 [details]
Fix 1 + tests

Fix looks good.
Comment 9 Markus Keller CLA 2014-05-26 11:39:35 EDT
Fixed with http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=28a197ac59da2ad5e3d634328ec686072a2a6f7c

Manju found a compile error for the generic array creation in the test case. I've fixed that and added an assertion that the AddUnimplementedMethodsOperation really fixes all compile problems.
Comment 10 Dani Megert CLA 2014-05-29 14:11:39 EDT
*** Bug 436198 has been marked as a duplicate of this bug. ***
Comment 11 Markus Keller CLA 2014-06-02 10:15:33 EDT
Verified in I20140601-2000 via code inspection and by verifying that AddUnimplementedMethodsTest#testJLS[348]() are running and green in the build.
Comment 12 Konstantin Komissarchik CLA 2014-06-03 00:28:22 EDT
Verified fix on RC3 via Sapphire and Oracle product usecases.