Community
Participate
Working Groups
From a plug in environmet, I'm trying to visit all EGL subparts like functions, records,.. for a certain Part (program i this particular case). Here's the code for my class: package be.asist.birep.decompile; import java.util.HashSet; import java.util.Set; import org.eclipse.edt.mof.egl.Element; import org.eclipse.edt.mof.egl.Function; import org.eclipse.edt.mof.egl.Program; import org.eclipse.edt.mof.impl.AbstractVisitor; public class SubPartParser extends AbstractVisitor{ HashSet<Element> subParts = new HashSet<Element>(); boolean visitResultValue = true; public SubPartParser() { } public Set<Element> getSubPartsForPart(Element part) { try { subParts = new HashSet<Element>(); part.accept(this); return subParts; } catch (Exception e) { e.printStackTrace(); } return null; } public boolean visit(Function obj) { subParts.add((Element)obj); return true; } public boolean visit(Program obj) { subParts.add((Element)obj); return true; } } when getSubPartsForPart is called for the Program Part in the attached file, I get a StackOverflowException. From the console: java.lang.StackOverflowError at java.lang.reflect.AccessibleObject.<init>(Unknown Source) at java.lang.reflect.Method.<init>(Unknown Source) at java.lang.reflect.Method.copy(Unknown Source) at java.lang.reflect.ReflectAccess.copyMethod(Unknown Source) at sun.reflect.ReflectionFactory.copyMethod(Unknown Source) at java.lang.Class.copyMethods(Unknown Source) at java.lang.Class.getMethods(Unknown Source) at org.eclipse.edt.mof.impl.AbstractVisitor.primGetMethod(AbstractVisitor.java:148) at org.eclipse.edt.mof.impl.AbstractVisitor.getMethod(AbstractVisitor.java:172) at org.eclipse.edt.mof.impl.AbstractVisitor.getMethod(AbstractVisitor.java:178) at org.eclipse.edt.mof.impl.AbstractVisitor.getMethod(AbstractVisitor.java:178) at org.eclipse.edt.mof.impl.AbstractVisitor.getMethod(AbstractVisitor.java:178) at org.eclipse.edt.mof.impl.AbstractVisitor.getMethod(AbstractVisitor.java:178) at org.eclipse.edt.mof.impl.AbstractVisitor.getMethod(AbstractVisitor.java:178) at org.eclipse.edt.mof.impl.AbstractVisitor.getMethod(AbstractVisitor.java:178) at org.eclipse.edt.mof.impl.AbstractVisitor.getMethod(AbstractVisitor.java:178) at org.eclipse.edt.mof.impl.AbstractVisitor.invokeVisit(AbstractVisitor.java:124) at org.eclipse.edt.mof.impl.AbstractVisitor.primVisit(AbstractVisitor.java:102) at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:206) at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:230) at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208) at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:243) at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208) at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:243) at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208) at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:243) at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208) at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:230) at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208) at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:243) at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208) at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:243) at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208) at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:243) at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208) at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:230) at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208) at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:243) at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208) at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:243) at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208) at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:243) at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208) ....
Bart, Can you attach the EGL file? Thanks, Paul
Bart, It just occurred to me what is probably wrong with your visitor. It is probably going into a loop due to a circular Object reference. The AbstractVisitor class has a built in solution to this problem by turning off the allowRevisit flag. Here is your visitor code with the allowRevisit set to false: package be.asist.birep.decompile; import java.util.HashSet; import java.util.Set; import org.eclipse.edt.mof.egl.Element; import org.eclipse.edt.mof.egl.Function; import org.eclipse.edt.mof.egl.Program; import org.eclipse.edt.mof.impl.AbstractVisitor; public class SubPartParser extends AbstractVisitor{ HashSet<Element> subParts = new HashSet<Element>(); boolean visitResultValue = true; public SubPartParser() { disallowRevisit(); //do not revisit so we dont go into a loop } public Set<Element> getSubPartsForPart(Element part) { try { subParts = new HashSet<Element>(); part.accept(this); return subParts; } catch (Exception e) { e.printStackTrace(); } return null; } public boolean visit(Function obj) { subParts.add((Element)obj); return true; } public boolean visit(Program obj) { subParts.add((Element)obj); return true; } }
Please verify that this problem is fixed in EDT 0.7 GA or any 0.8 build, and close the bug. If you still see a problem, you can reopen the bug with additional information.
Resolved