Bug 140340 - [5.0][templates] foreach template does not work when an Iterable over a static inner class exists
Summary: [5.0][templates] foreach template does not work when an Iterable over a stati...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: All All
: P3 minor (vote)
Target Milestone: 3.3 M5   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-05 07:38 EDT by Hendrik Maryns CLA
Modified: 2007-02-05 11:16 EST (History)
1 user (show)

See Also:


Attachments
A test class showing the problem (312 bytes, text/x-java)
2006-05-05 08:02 EDT, Hendrik Maryns CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Hendrik Maryns CLA 2006-05-05 07:38:47 EDT
I have no clue why this happens, but sometimes, the foreach template just doesn’t work.  I type fore, then Ctrl+Space, and confirm foreach, and nothing happens: fore is still there, the template has not been filled in.  Funny thing is, whenever this happens, the other for templates do work: removing the e, so typing for then Ctrl+space gives four options for for loops, of which the first three work, but foreach doesn’t.

I have tried with comments before or after it, with or without compile errors, with or without whitespace surrounding, it all makes no sense.

A minimal example for the problem is this:
import test_test.TransitionFunction;
public class Test {
	private Object productFunction(TransitionFunction function2) {
		fore
	}

}
where the fore does not work.

I tried transforming this into a usable test function (where you wouldn’t need TransitionFunction), however, the problem ceases to exist then.  Even creating a class TransitionFunction in the default package, or in another package, or in a package containing an underscore, or even removing the import statement, made it work again.  I am stumped.

I will attach the TransitionFunction class, so maybe someone could point to an error there, but that seems highly improbable to me.
Comment 1 Hendrik Maryns CLA 2006-05-05 08:02:56 EDT
Created attachment 40471 [details]
A test class showing the problem

This class file shows the problem.
After much trimming, I found the core of the problem: an iterator over Map.Entry:  If you remove 'Map.' from the Iterable statement, it works fine.
Comment 2 Hendrik Maryns CLA 2006-05-05 08:03:55 EDT
Changed the subject, as that really seems to be the problem.
Comment 3 Tom Hofmann CLA 2006-08-14 12:31:57 EDT
The problem seems to be that the supertype hierarchy for the package visible type does not contain the implemented interface. Moving to jdt-core for comments. 

Given the example code in the attached Java source file, and a super type hierarchy on 'Function' will contain Iterable in its allInterfaces list, but not return Iterable as a super type of Function, nor Function as a sub type of Iterable.


I get the following exception in the log:

Caused by: org.eclipse.jface.text.Assert$AssertionFailedException: Assertion failed: 
	at org.eclipse.jface.text.Assert.isTrue(Assert.java:188)
	at org.eclipse.jface.text.Assert.isTrue(Assert.java:173)
	at org.eclipse.jdt.internal.corext.template.java.CompilationUnitCompletion$TypeParameterResolver.computeTypeParameterBinding(CompilationUnitCompletion.java:454)
	at org.eclipse.jdt.internal.corext.template.java.CompilationUnitCompletion$TypeParameterResolver.computeBinding(CompilationUnitCompletion.java:421)
	at org.eclipse.jdt.internal.corext.template.java.CompilationUnitCompletion$TypeParameterResolver.computeBinding(CompilationUnitCompletion.java:399)
	at org.eclipse.jdt.internal.corext.template.java.CompilationUnitCompletion$LocalVariable.getMemberTypeSignatures(CompilationUnitCompletion.java:246)
	at org.eclipse.jdt.internal.corext.template.java.CompilationUnitCompletion$LocalVariable.getMemberTypeNames(CompilationUnitCompletion.java:272)
	at org.eclipse.jdt.internal.corext.template.java.JavaContextType$AbstractIterableType.resolve(JavaContextType.java:129)
	at org.eclipse.jface.text.templates.TemplateContextType.resolve(TemplateContextType.java:272)
	at org.eclipse.jface.text.templates.TemplateContextType.resolve(TemplateContextType.java:239)
	at org.eclipse.jdt.internal.corext.template.java.JavaContext.evaluate(JavaContext.java:164)
	at org.eclipse.jdt.internal.ui.text.template.contentassist.TemplateProposal.getAdditionalProposalInfo(TemplateProposal.java:391)
	at org.eclipse.jface.text.contentassist.AdditionalInfoController$6.run(AdditionalInfoController.java:162)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:123)
	... 20 more
Comment 4 Jerome Lanneluc CLA 2007-01-11 09:29:11 EST
Changed HierarchyResolver#findSuperInterfaces(...) to check for '<' before checking for '.'
Added regression test TypeHierarchyTests#testGeneric10().
Released for 3.3M5 in HEAD.
Comment 5 Olivier Thomann CLA 2007-02-05 11:16:16 EST
Verified for 3.3M5 using I20070205-0009.