Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2020-06-24 07:14:54 +0000
committerHenrik Rentz-Reichert2020-06-24 07:14:54 +0000
commit605b02f9f248642352d892324f4ce9024cd86e22 (patch)
treef6b2444db79113eaa7a5cb7e23508c911745ff77
parent132df3e2d2abd4c07be39837055fad01306ab629 (diff)
downloadorg.eclipse.etrice-605b02f9f248642352d892324f4ce9024cd86e22.tar.gz
org.eclipse.etrice-605b02f9f248642352d892324f4ce9024cd86e22.tar.xz
org.eclipse.etrice-605b02f9f248642352d892324f4ce9024cd86e22.zip
Bug 564609 - [core] organize imports doesn't consider references of SPPs
Fixed a bug in the computation of used types. Change-Id: I65bc5db255c1206ee297b6ece87c0100775070dd
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/imports/ImportOrganizer.java1
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/imports/RoomOrganizeImportHelper.java46
2 files changed, 45 insertions, 2 deletions
diff --git a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/imports/ImportOrganizer.java b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/imports/ImportOrganizer.java
index 8e14e8ebb..3809fdac4 100644
--- a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/imports/ImportOrganizer.java
+++ b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/imports/ImportOrganizer.java
@@ -42,7 +42,6 @@ import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.util.ReplaceRegion;
import org.eclipse.xtext.xbase.lib.Pair;
-import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.google.inject.Inject;
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/imports/RoomOrganizeImportHelper.java b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/imports/RoomOrganizeImportHelper.java
index eaa492033..a31d414db 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/imports/RoomOrganizeImportHelper.java
+++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/imports/RoomOrganizeImportHelper.java
@@ -14,12 +14,18 @@
package org.eclipse.etrice.core.ui.imports;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.stream.Collectors;
import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.etrice.core.common.base.util.ImportHelpers;
import org.eclipse.etrice.core.common.ui.imports.IOrganizeImportHelper;
@@ -48,6 +54,8 @@ public class RoomOrganizeImportHelper implements IOrganizeImportHelper {
@Override
public Multimap<EClass, EReference> getTypeReferences() {
Multimap<EClass, EReference> result = ArrayListMultimap.create();
+ Map<EClass,List<EClass>> subTypes = new HashMap<>();
+ getSubTypes(RoomPackage.eINSTANCE, subTypes);
RoomPackage.eINSTANCE.getEClassifiers().stream() //
.filter(EClass.class::isInstance) //
.map(EClass.class::cast) //
@@ -57,6 +65,12 @@ public class RoomOrganizeImportHelper implements IOrganizeImportHelper {
.collect(Collectors.toList());
if (!refs.isEmpty()) {
result.putAll(cls, refs);
+ List<EClass> subClasses = subTypes.get(cls);
+ if (subClasses!=null) {
+ for (EClass subClass : subClasses) {
+ result.putAll(subClass, refs);
+ }
+ }
}
});
return result;
@@ -111,4 +125,34 @@ public class RoomOrganizeImportHelper implements IOrganizeImportHelper {
private boolean typeNeedsImport(EClass type) {
return RoomPackage.Literals.ROOM_CLASS.isSuperTypeOf(type);
}
-}
+
+ // copied from org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOModelUtil.java
+ private static void getSubTypes(EPackage ePackage, Map<EClass, List<EClass>> result) {
+ for (EClassifier classifier : ePackage.getEClassifiers()) {
+ if (classifier instanceof EClass) {
+ EClass eClass = (EClass) classifier;
+ getSubType(eClass, EcorePackage.eINSTANCE.getEObject(), result);
+
+ for (EClass eSuperType : eClass.getEAllSuperTypes()) {
+ getSubType(eClass, eSuperType, result);
+ }
+ }
+ }
+ }
+
+ private static void getSubType(EClass eClass, EClass eSuperType, Map<EClass, List<EClass>> result) {
+ if (eSuperType.eIsProxy()) {
+ // OM.LOG.warn("getSubTypes encountered a proxy EClass which will be ignored: "
+ // + eSuperType);
+ return;
+ }
+
+ List<EClass> list = result.get(eSuperType);
+ if (list == null) {
+ list = new ArrayList<>();
+ result.put(eSuperType, list);
+ }
+
+ list.add(eClass);
+ }
+ }

Back to the top