Maybe something like:<div><br></div><div>private boolean fieldNeedsFQN(String typeName)</div><div> String simpleName = Types.toSimpleName(typeName);</div><div> // This works both with simple as well as with qualified names</div>
<div> Import import = getOrigin().getImport(simpleName);</div><div> if (import != null && !import.getQualifiedName().equals(typeName)) {</div><div> return true;</div><div> }</div><div> return false;</div>
<div>}<br><br><div class="gmail_quote">On Tue, Jul 24, 2012 at 1:14 AM, George Gastaldi <span dir="ltr"><<a href="mailto:gegastaldi@gmail.com" target="_blank">gegastaldi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Ivan,<br>
<br>
Yeah, I have to agree with you, this is something that should be<br>
improved. I also don't like having FQN in field declarations.<br>
But, figuring it out how to avoid name clashes may be harder to<br>
implement than using this strategy.<br>
<div class="HOEnZb"><div class="h5"><br>
Regards,<br>
<br>
George Gastaldi<br>
<br>
2012/7/23 Ivan St. Ivanov <<a href="mailto:ivan.st.ivanov@gmail.com">ivan.st.ivanov@gmail.com</a>>:<br>
> Hi George,<br>
><br>
> Yes, I realized that. So it's up to us to decide which option we take:<br>
><br>
> 1) It is safe to have the fully qualified name in the field declarations,<br>
> but it is kinda ugly<br>
> 2) Declaring the fields with non fully qualified names looks natural (all of<br>
> us use this style), but it may produce class name clashes in one out of 1000<br>
> or more cases. E.g. adding java.util.Date and java.sql.Date to a class.<br>
><br>
> I don't mind to keep it in the current way. But when I show the generated<br>
> classes to the people, they might get the feeling that something does not<br>
> look like in their IDEs.<br>
><br>
> Regards,<br>
> Ivan<br>
><br>
><br>
> On Tue, Jul 24, 2012 at 12:46 AM, George Gastaldi <<a href="mailto:gegastaldi@gmail.com">gegastaldi@gmail.com</a>><br>
> wrote:<br>
>><br>
>> Hi Ivan,<br>
>><br>
>> Using the fully qualified name avoids class name conflicts, so it is<br>
>> much safer to use than to rely on imports only.<br>
>><br>
>> Regards,<br>
>><br>
>> George Gastaldi<br>
>><br>
>> 2012/7/23 Ivan St. Ivanov <<a href="mailto:ivan.st.ivanov@gmail.com">ivan.st.ivanov@gmail.com</a>>:<br>
>> > Hi Lincoln,<br>
>> ><br>
>> > I'm hacking now a solution. Something like:<br>
>> ><br>
>> > if (Types.isArray(simpleName))<br>
>> > {<br>
>> > Name name = ast.newSimpleName(Types.stripArray(simpleName));<br>
>> > Type typeOfArray = ast.newSimpleType(name);<br>
>> > type = ast.newArrayType(typeNoArray);<br>
>> > }<br>
>> ><br>
>> > I'm just trying to find the most suitable place of the above snippet in<br>
>> > the<br>
>> > setType method. Maybe I'll do some refactoring of the existing code.<br>
>> ><br>
>> > I noticed also that the code inside:<br>
>> ><br>
>> > if (!Strings.areEqual(typeName, simpleName) && requiresImport)<br>
>> ><br>
>> > ...should also be touched to support arrays.<br>
>> ><br>
>> > BTW, we have the same issue with generic types as well. So I'm looking<br>
>> > into<br>
>> > them too.<br>
>> ><br>
>> > Cheers,<br>
>> > Ivan<br>
>> ><br>
>> > P.S. Don't you think that we should have the simple name (e.g. File) in<br>
>> > the<br>
>> > field declaration instead of the whole type:<br>
>> ><br>
>> > right now it is:<br>
>> ><br>
>> > import java.io.File;<br>
>> ><br>
>> > public class Test {<br>
>> ><br>
>> > private java.io.File file;<br>
>> ><br>
>> > }<br>
>> ><br>
>> > On Mon, Jul 23, 2012 at 5:53 PM, Lincoln Baxter, III<br>
>> > <<a href="mailto:lincolnbaxter@gmail.com">lincolnbaxter@gmail.com</a>> wrote:<br>
>> >><br>
>> >> Hey Ivan!<br>
>> >><br>
>> >> You're correct, the JDT probably doesn't have a convenient method for<br>
>> >> this<br>
>> >> (it doesn't have much that is convenient,) but what are your proposed<br>
>> >> changes?<br>
>> >><br>
>> >> ~Lincoln<br>
>> >><br>
>> >> On Sat, Jul 21, 2012 at 4:04 PM, Ivan St. Ivanov<br>
>> >> <<a href="mailto:ivan.st.ivanov@gmail.com">ivan.st.ivanov@gmail.com</a>> wrote:<br>
>> >>><br>
>> >>> Hi folks,<br>
>> >>><br>
>> >>> I wonder is it possible to add a field to a JavaClass and to set an<br>
>> >>> array<br>
>> >>> as its type. The setType(String) method does not support arrays yet<br>
>> >>> and I<br>
>> >>> don't want to use the other two variants of this method (taking Class<br>
>> >>> and<br>
>> >>> JavaResource parameters).<br>
>> >>><br>
>> >>> I looked at the mentioned method (setType(String)). And found a<br>
>> >>> suitable<br>
>> >>> place where I could add the support for arrays. However, I'm afraid<br>
>> >>> that<br>
>> >>> JDT's AST class does not have a convenient newArray....() method.<br>
>> >>><br>
>> >>> Or maybe I'm missing something?<br>
>> >>><br>
>> >>> Cheers,<br>
>> >>> Ivan<br>
>> >>><br>
>> >>> _______________________________________________<br>
>> >>> forge-dev mailing list<br>
>> >>> <a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a><br>
>> >>> <a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
>> >>><br>
>> >><br>
>> >><br>
>> >><br>
>> >> --<br>
>> >> Lincoln Baxter, III<br>
>> >> <a href="http://ocpsoft.org" target="_blank">http://ocpsoft.org</a><br>
>> >> "Simpler is better."<br>
>> >><br>
>> >> _______________________________________________<br>
>> >> forge-dev mailing list<br>
>> >> <a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a><br>
>> >> <a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
>> >><br>
>> ><br>
>> ><br>
>> > _______________________________________________<br>
>> > forge-dev mailing list<br>
>> > <a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a><br>
>> > <a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
>> ><br>
>> _______________________________________________<br>
>> forge-dev mailing list<br>
>> <a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a><br>
>> <a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
><br>
><br>
><br>
> _______________________________________________<br>
> forge-dev mailing list<br>
> <a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
><br>
_______________________________________________<br>
forge-dev mailing list<br>
<a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
</div></div></blockquote></div><br></div>