Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 200847

Summary: [templates] Variable resolver resolves to array of specified type
Product: [Eclipse Project] JDT Reporter: Benno Baumgartner <benno.baumgartner>
Component: TextAssignee: Markus Keller <markus.kell.r>
Status: RESOLVED FIXED QA Contact:
Severity: minor    
Priority: P3 CC: daniel_megert, deepakazad, markus.kell.r
Version: 3.3   
Target Milestone: 3.8 M7   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Benno Baumgartner CLA 2007-08-22 12:50:25 EDT
I20070821-0800

Given:
package test;
public class E01 {
	public void foo() {
		String[] strings= null;
		String string= null;
		out|
	}
	public void out(String s) {}
}

1. Add template 'out' to java context with pattern:
out(${name:var(java.lang.String)});
2. Replace '|' with caret
3. Ctrl-Space, Ctrl-Space
4. Enter
Is:
- string
- strings
is proposed
Should:
- string
is proposed

'var' template variable doc is:
'Evaluates to a field, local variable or parameter visible in the current scope that is a subtype of the given type.'

String[] is not a subtype of String.
Comment 1 Dani Megert CLA 2007-08-23 11:54:47 EDT
This doesn't depend on your work for bug 200801, right?
Comment 2 Benno Baumgartner CLA 2007-08-23 13:08:26 EDT
(In reply to comment #1)
> This doesn't depend on your work for bug 200801, right?
> 

It does not depend on bug 200801. This is a minor bug I found while playing with the templates, it's also in 3.3. I guess the bug is in CompilationUnitCompletion.Variable.isSubtypeOf(String)
Comment 3 Dani Megert CLA 2007-08-24 03:25:42 EDT
patch? ;-)
Comment 4 Benno Baumgartner CLA 2007-08-24 05:11:37 EDT
(In reply to comment #3)
> patch? ;-)
> 

Ooops, this problem is a bit bigger then I thought because a pattern:

out(${name:var(java.lang.String[])});

is not valid template syntax. There is a workaround now:

out(${name:var('java.lang.String[]')});

but we should change the template syntax to write the first one. But fixing this bug can break existing templates, and it's minor...
Comment 5 Benno Baumgartner CLA 2007-08-24 05:14:08 EDT
(In reply to comment #4)
> is not valid template syntax. There is a workaround now:
> 
> out(${name:var('java.lang.String[]')});

To make it clear: With workaround I mean it is now possible to write this template. But evaluating the template above does not resolve 'name' to String arrays.
Comment 6 Markus Keller CLA 2012-04-11 10:45:59 EDT
Fixed with
http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=5cebfb1d709a8016d876757ac33ff278dfcbd43a
and
http://git.eclipse.org/c/platform/eclipse.platform.common.git/commit/?id=1645fa21e2b2453126277a6d41baeeb71cc3b5ca

The doc fix also includes other corrections.


(In reply to comment #4)
I didn't touch the template language syntax, so you have to enclose array types in single quotes. This could still be relaxed later if someone finds time to implement it. This would not break existing templates.
Comment 7 Deepak Azad CLA 2012-04-12 04:22:16 EDT
Markus, the 2 consecutive single quotes on line 1071 in o.e.jdt.ui/plugin.properties cause a chkpii error. (More details on BM)
Comment 8 Dani Megert CLA 2012-04-12 04:43:16 EDT
.