Strange Structural Search behavior????

I have following code

Map map = new HashMap();
String key = "key";
AppPreferences value = new AppPreferences();
map.put(key, value ); // line 1
map.put(value, value ); // line 2
map.put("key", value ); // line 3
map.put("key", new AppPreferences()); // line 4

I am using following 2 templates

$map$.put($key$, $value$) where map is any subtype of java.util.Map, key is String, value is any subtype of com.abc.AppPreferences

$map$.put($key$, $value$) where map is any subtype of java.util.Map, key any subtype of Object, value is any subtype of com.abc.AppPreferences


I get the following hits:
template1 - matches found - line 1
template 2 - matches found - none

For template 1, I was expecting line 1, 3 and line 4 to match since in line 1,3,4 key is string and value is AppPreferences.

For template 2, I was expecting all 4 lines to match since in all these lines, key is object and value is AppPreferences.

What am I missing? HELP!!!!


7 comments
Comment actions Permalink

Hi,

- You probably have no JDK defined or some other configuration problem.
Template 1 with IDEA 5.1 EAP build 4070 finds occurences in lines of
1,3,4 as expected.
- As for template 2, no matches is a bug, will be fixed shortly

Vinay Moharil wrote:

I have following code

Map map = new HashMap();
String key = "key";
AppPreferences value = new AppPreferences();
map.put(key, value ); // line 1
map.put(value, value ); // line 2
map.put("key", value ); // line 3
map.put("key", new AppPreferences()); // line 4

I am using following 2 templates

$map$.put($key$, $value$) where map is any subtype of java.util.Map, key is String, value is any subtype of com.abc.AppPreferences

$map$.put($key$, $value$) where map is any subtype of java.util.Map, key any subtype of Object, value is any subtype of com.abc.AppPreferences


I get the following hits:
template1 - matches found - line 1
template 2 - matches found - none

For template 1, I was expecting line 1, 3 and line 4 to match since in line 1,3,4 key is string and value is AppPreferences.

For template 2, I was expecting all 4 lines to match since in all these lines, key is object and value is AppPreferences.

What am I missing? HELP!!!!




--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink

I am using jdk150_05 for running intellij and the that is also the project jdk. I am using 4069 - and I am still getting only 1 match for template 1 as I mentioned in my original post. Is this something that is fixed with 150_06 and 4070 combo? I will get 150_06 and give it a shot.

0
Comment actions Permalink

tested with 150_06 and I am still getting the same 1 match for template 1. How can I share my xml file for the template? How can I get yours?

0
Comment actions Permalink

No, I tried to search on following file:
--- cut
import java.util.Map;
import java.util.HashMap;

class A {
{
class AppPreferences {}

Map map = new HashMap();
String key = "key";
AppPreferences value = new AppPreferences();
map.put(key, value ); // line 1
map.put(value, value ); // line 2
map.put("key", value ); // line 3
map.put("key", new AppPreferences()); // line 4
}
}
--- cut
Search pattern as you described, search constraints:
map -> expr type java\.util\.Map within type hierarchy
key -> expr type String
value -> expr type AppPreferences within type hierarchy

Any difference with your config?

Vinay Moharil wrote:

I am using jdk150_05 for running intellij and the that is also the project jdk. I am using 4069 - and I am still getting only 1 match for template 1 as I mentioned in my original post. Is this something that is fixed with 150_06 and 4070 combo? I will get 150_06 and give it a shot.


--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink

Attaching a screen shot using the code you provided

Sorry - it's still not working for me.



Attachment(s):
SS.gif
0
Comment actions Permalink

Template 1 seems to be working on my W2K machine for 4069 and 1.5_04. Does not work on my linux FC3 machine with 4069 and 1.5_06. Have not found anything different yet.

Created a brand new project with just one file with just the code you mentioned and still does not work on FC3 but works on W2K.

0
Comment actions Permalink

Hi Maxim,

I tried 4081 and on windows things are working fine now. The query pulls up correct results for both templates. Thanks for fixing the bug where the key is any subtype of Object.

However the strange behavior continues on linux. I get 3 hits for template 1 and 4 for template 2 on w2k but on FC3, I get only 1 hit for template 1 and 2 for template 2. So there is definite progress on FC3 for template 2 but still not as good as windows.

0

Please sign in to leave a comment.