Skip to main content



      Home
Home » Modeling » UML2 » how to delete class.attribute(property)
how to delete class.attribute(property) [message #473639] Fri, 29 June 2007 13:37 Go to next message
Eclipse UserFriend
Hi All:
I have a class. Some of attribtues are private members, and I'd like to
programtically delete all private members and only keep public
class.members. When running following code, it throws exception
org.eclipse.emf.common.util.BasicEList$EIterator.checkModCou nt. Could any
one help to see what's wrong?

List attList = clz.getAttributes();
ListIterator lstIt = attList.listIterator(attList.size());
while(lstIt.hasPrevious()){
Property prpt = (Property) lstIt.previous();
vk = prpt.getVisibility().getValue();
if (vk == VisibilityKind.PRIVATE){
System.out.println("Destroy property: " + prpt.getQualifiedName());
prpt.destroy();
}
}
Thanks!
JD
Re: how to delete class.attribute(property) [message #473760 is a reply to message #473639] Thu, 05 July 2007 08:36 Go to previous messageGo to next message
Eclipse UserFriend
JD,

This is effectively a concurrent modification exception - you're modifying
the contents of the list of attributes while iterating over it. To work
around this, you can either iterate over the owned attributes instead and
remove each property via the iterator before destroying it, or make a
defensive copy of the attributes list before iterating over it.

Kenn

"JD" <jingdong.li@gmail.com> wrote in message
news:009289687d2f1c3046910ede1e8ba02e$1@www.eclipse.org...
> Hi All:
> I have a class. Some of attribtues are private members, and I'd like to
> programtically delete all private members and only keep public
> class.members. When running following code, it throws exception
> org.eclipse.emf.common.util.BasicEList$EIterator.checkModCou nt. Could any
> one help to see what's wrong?
>
> List attList = clz.getAttributes();
> ListIterator lstIt = attList.listIterator(attList.size());
> while(lstIt.hasPrevious()){
> Property prpt = (Property) lstIt.previous();
> vk = prpt.getVisibility().getValue();
> if (vk == VisibilityKind.PRIVATE){
> System.out.println("Destroy property: " + prpt.getQualifiedName());
> prpt.destroy();
> }
> }
> Thanks!
> JD
>
>
>
Re: how to delete class.attribute(property) [message #473943 is a reply to message #473760] Tue, 10 July 2007 11:07 Go to previous message
Eclipse UserFriend
Thanks Kenn!

JD

Kenn Hussey wrote:

> JD,

> This is effectively a concurrent modification exception - you're modifying
> the contents of the list of attributes while iterating over it. To work
> around this, you can either iterate over the owned attributes instead and
> remove each property via the iterator before destroying it, or make a
> defensive copy of the attributes list before iterating over it.

> Kenn

> "JD" <jingdong.li@gmail.com> wrote in message
> news:009289687d2f1c3046910ede1e8ba02e$1@www.eclipse.org...
>> Hi All:
>> I have a class. Some of attribtues are private members, and I'd like to
>> programtically delete all private members and only keep public
>> class.members. When running following code, it throws exception
>> org.eclipse.emf.common.util.BasicEList$EIterator.checkModCou nt. Could any
>> one help to see what's wrong?
>>
>> List attList = clz.getAttributes();
>> ListIterator lstIt = attList.listIterator(attList.size());
>> while(lstIt.hasPrevious()){
>> Property prpt = (Property) lstIt.previous();
>> vk = prpt.getVisibility().getValue();
>> if (vk == VisibilityKind.PRIVATE){
>> System.out.println("Destroy property: " + prpt.getQualifiedName());
>> prpt.destroy();
>> }
>> }
>> Thanks!
>> JD
>>
>>
>>
Re: how to delete class.attribute(property) [message #622732 is a reply to message #473639] Thu, 05 July 2007 08:36 Go to previous message
Eclipse UserFriend
JD,

This is effectively a concurrent modification exception - you're modifying
the contents of the list of attributes while iterating over it. To work
around this, you can either iterate over the owned attributes instead and
remove each property via the iterator before destroying it, or make a
defensive copy of the attributes list before iterating over it.

Kenn

"JD" <jingdong.li@gmail.com> wrote in message
news:009289687d2f1c3046910ede1e8ba02e$1@www.eclipse.org...
> Hi All:
> I have a class. Some of attribtues are private members, and I'd like to
> programtically delete all private members and only keep public
> class.members. When running following code, it throws exception
> org.eclipse.emf.common.util.BasicEList$EIterator.checkModCou nt. Could any
> one help to see what's wrong?
>
> List attList = clz.getAttributes();
> ListIterator lstIt = attList.listIterator(attList.size());
> while(lstIt.hasPrevious()){
> Property prpt = (Property) lstIt.previous();
> vk = prpt.getVisibility().getValue();
> if (vk == VisibilityKind.PRIVATE){
> System.out.println("Destroy property: " + prpt.getQualifiedName());
> prpt.destroy();
> }
> }
> Thanks!
> JD
>
>
>
Re: how to delete class.attribute(property) [message #623642 is a reply to message #473760] Tue, 10 July 2007 11:07 Go to previous message
Eclipse UserFriend
Thanks Kenn!

JD

Kenn Hussey wrote:

> JD,

> This is effectively a concurrent modification exception - you're modifying
> the contents of the list of attributes while iterating over it. To work
> around this, you can either iterate over the owned attributes instead and
> remove each property via the iterator before destroying it, or make a
> defensive copy of the attributes list before iterating over it.

> Kenn

> "JD" <jingdong.li@gmail.com> wrote in message
> news:009289687d2f1c3046910ede1e8ba02e$1@www.eclipse.org...
>> Hi All:
>> I have a class. Some of attribtues are private members, and I'd like to
>> programtically delete all private members and only keep public
>> class.members. When running following code, it throws exception
>> org.eclipse.emf.common.util.BasicEList$EIterator.checkModCou nt. Could any
>> one help to see what's wrong?
>>
>> List attList = clz.getAttributes();
>> ListIterator lstIt = attList.listIterator(attList.size());
>> while(lstIt.hasPrevious()){
>> Property prpt = (Property) lstIt.previous();
>> vk = prpt.getVisibility().getValue();
>> if (vk == VisibilityKind.PRIVATE){
>> System.out.println("Destroy property: " + prpt.getQualifiedName());
>> prpt.destroy();
>> }
>> }
>> Thanks!
>> JD
>>
>>
>>
Previous Topic:Load and parse UML file
Next Topic:How to add an interface into to list of providedinterfaces of Port?
Goto Forum:
  


Current Time: Fri Jul 04 15:48:56 EDT 2025

Powered by FUDForum. Page generated in 0.06000 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top