Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 126091 Details for
Bug 265365
Generated switch statements can be incorrectly ordered.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Fix for switch class ordering
265365.patch (text/plain), 3.69 KB, created by
Dave Steinberg
on 2009-02-18 18:03:08 EST
(
hide
)
Description:
Fix for switch class ordering
Filename:
MIME Type:
Creator:
Dave Steinberg
Created:
2009-02-18 18:03:08 EST
Size:
3.69 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.emf.codegen.ecore >Index: src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenClassImpl.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenClassImpl.java,v >retrieving revision 1.99 >diff -u -r1.99 GenClassImpl.java >--- src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenClassImpl.java 22 Dec 2008 14:25:18 -0000 1.99 >+++ src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenClassImpl.java 18 Feb 2009 22:59:08 -0000 >@@ -21,13 +21,11 @@ > import java.util.Arrays; > import java.util.Collection; > import java.util.Collections; >-import java.util.HashSet; > import java.util.Iterator; > import java.util.LinkedHashMap; > import java.util.List; > import java.util.Locale; > import java.util.Map; >-import java.util.Set; > > import org.eclipse.emf.codegen.ecore.CodeGenEcorePlugin; > import org.eclipse.emf.codegen.ecore.Generator; >@@ -448,35 +446,64 @@ > } > > public List<GenClass> getSwitchGenClasses() >- { >- // for Ecore or something that explicitly extends it, we need to exclude >- // EObject, which is already handled by the default case >- List<GenClass> result = >- collectGenClasses >- (getEcoreClass().getESuperTypes(), >- new GenClassFilter() >- { >- public boolean accept(GenClass genClass) >- { >- return !genClass.isEObject(); >- } >- }); >- Set<GenClass> resultSet = new HashSet<GenClass>(result); >+ { >+ // Traverse the supertypes to find the maximum depths. >+ // Exclude this class itself, which is handled separately in the template. >+ // >+ Map<EClass, Integer> maxDepths = new LinkedHashMap<EClass, Integer>(); >+ findMaxSuperTypeDepths(maxDepths, getEcoreClass(), 0); >+ maxDepths.remove(getEcoreClass()); > >- for (int i = 0; i < result.size(); i++) >+ // Order the results in a list of lists, indexed by maximum depth. >+ // Exclude EObject, which is handled by the default case. >+ // >+ List<List<GenClass>> ordered = new ArrayList<List<GenClass>>(); >+ int resultSize = 0; >+ for (Map.Entry<EClass, Integer> entry : maxDepths.entrySet()) > { >- GenClass base = result.get(i); >- for (GenClass baseOfBase : base.getBaseGenClasses()) >+ GenClass genClass = findGenClass(entry.getKey()); >+ if (genClass != null && !genClass.isEObject()) > { >- if (!baseOfBase.isEObject() && resultSet.add(baseOfBase)) >+ int depth = entry.getValue(); >+ while (ordered.size() <= depth) > { >- result.add(baseOfBase); >+ ordered.add(new ArrayList<GenClass>()); > } >+ ordered.get(depth).add(genClass); >+ resultSize++; > } > } >+ >+ // Traverse the list of lists to build a final ordered result. >+ // >+ List<GenClass> result = new ArrayList<GenClass>(resultSize); >+ for (List<GenClass> genClasses : ordered) >+ { >+ result.addAll(genClasses); >+ } > return result; > } > >+ private void findMaxSuperTypeDepths(Map<EClass, Integer> maxDepths, EClass eClass, int depth) >+ { >+ Integer existing = maxDepths.get(eClass); >+ if (existing != null) >+ { >+ if (depth > existing) >+ { >+ maxDepths.put(eClass, depth); >+ } >+ } >+ else >+ { >+ maxDepths.put(eClass, depth); >+ for (EClass base : eClass.getESuperTypes()) >+ { >+ findMaxSuperTypeDepths(maxDepths, base, depth + 1); >+ } >+ } >+ } >+ > public GenClass getBaseGenClass() > { > List<EClass> s = getEcoreClass().getESuperTypes();
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 265365
: 126091