You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by Philip Ogren <ph...@ogren.info> on 2007/06/06 00:28:18 UTC

creating a type called 'Feature'

If you create a type with the name 'Feature' you get compile errors 
because of a namespace conflict with the Feature interface.  I think 
this could be easily fixed by simply removing the import statement in 
the generated code and explicitly providing the fully qualified name for 
the Feature interface when referenced (e.g. 
'org.apache.uima.cas.Feature'). 

Please advise me if I am submitting this to the wrong list.

Thanks,
Philip

Re: creating a type called 'Feature'

Posted by Philip Ogren <ph...@ogren.info>.
I think there is an easier solution.  Use the fully qualified name in 
the generated code when referring to the types defined by the type 
system descriptor file.  That way you can leave the import statements as 
they are.  The generated code for types named 'Feature' and 'Type' can 
each be fixed with three changes to the generated code in the files with 
the suffix "_Type".  (Note that creating a type called "Feature" 
generates error-free code if you don't add any features to the type.) 

Personally, I don't think all possible names for types need to be 
accommodated - and some should be actively discouraged such as "JCas" - 
but this is a moot point with the above solution.

Marshall Schor wrote: 
> The JCasGen code already has a test to check for "reserved" Feature 
> names.  These are typically names that are part of the 
> FeatureStructure interface, starting with get or set.  For instance, 
> there is a getType() - so if you had a feature named "Type", this 
> would conflict.
> The easy fix for this case would be as you suggested: to replace all 
> refs to Feature in the generated code with the fully qualified name, 
> and remove the import.  The downside is that this would make the 
> generated code more un-readable (not that anyone reads it :-).
>
> If we did this for other imported things: JCas, JCasRegistry, CASImpl, 
> FSGenerator, FeatureStructure, TypeImpl,
> Type, FeatureImpl, Annotation_Type, it might make the code look quite 
> hard to read.
> A more complex fix could be to only do this if the defined type was a 
> conflicting name, and then only for that type.
>
> Perhaps you can take a look at the JCasGen code and propose a patch?
>
> -Marshall
>
>

Re: creating a type called 'Feature'

Posted by Marshall Schor <ms...@schor.com>.
Thilo Goetz wrote:
> Philip Ogren wrote:
>   
>> If you create a type with the name 'Feature' you get compile errors
>> because of a namespace conflict with the Feature interface.  I think
>> this could be easily fixed by simply removing the import statement in
>> the generated code and explicitly providing the fully qualified name for
>> the Feature interface when referenced (e.g. 'org.apache.uima.cas.Feature').
>> Please advise me if I am submitting this to the wrong list.
>>
>> Thanks,
>> Philip
>>     
>
> I think your suggestion is a good one.  We'll get similar errors when
> somebody creates types with names like "FeatureStructure" or "Type".
> Marshall, what do you think?
>   
The JCasGen code already has a test to check for "reserved" Feature 
names.  These are typically names that are part of the FeatureStructure 
interface, starting with get or set.  For instance, there is a getType() 
- so if you had a feature named "Type", this would conflict. 

The easy fix for this case would be as you suggested: to replace all 
refs to Feature in the generated code with the fully qualified name, and 
remove the import.  The downside is that this would make the generated 
code more un-readable (not that anyone reads it :-).

If we did this for other imported things: JCas, JCasRegistry, CASImpl, 
FSGenerator, FeatureStructure, TypeImpl,
Type, FeatureImpl, Annotation_Type, it might make the code look quite 
hard to read. 

A more complex fix could be to only do this if the defined type was a 
conflicting name, and then only for that type.

Perhaps you can take a look at the JCasGen code and propose a patch?

-Marshall

Re: creating a type called 'Feature'

Posted by Thilo Goetz <tw...@gmx.de>.
Philip Ogren wrote:
> If you create a type with the name 'Feature' you get compile errors
> because of a namespace conflict with the Feature interface.  I think
> this could be easily fixed by simply removing the import statement in
> the generated code and explicitly providing the fully qualified name for
> the Feature interface when referenced (e.g. 'org.apache.uima.cas.Feature').
> Please advise me if I am submitting this to the wrong list.
> 
> Thanks,
> Philip

I think your suggestion is a good one.  We'll get similar errors when
somebody creates types with names like "FeatureStructure" or "Type".
Marshall, what do you think?

--Thilo