Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2013-05-06 05:56:26 -0400
committerHenrik Rentz-Reichert2013-05-06 05:58:26 -0400
commitf66b6409a314363934f9b4e5c7bc484116ec739e (patch)
tree4ad0b69546358b800f2ad87c11071d42d8834d0c
parent8707289bb730be5d3b0661f4141f1cde55790d84 (diff)
downloadorg.eclipse.etrice-f66b6409a314363934f9b4e5c7bc484116ec739e.tar.gz
org.eclipse.etrice-f66b6409a314363934f9b4e5c7bc484116ec739e.tar.xz
org.eclipse.etrice-f66b6409a314363934f9b4e5c7bc484116ec739e.zip
[core.etmap] bug 407266: [core.etmap] add validation and quickfix to imports
https://bugs.eclipse.org/bugs/show_bug.cgi?id=407266
-rw-r--r--plugins/org.eclipse.etrice.core.etmap.ui/src/org/eclipse/etrice/core/etmap/ui/quickfix/ETMapQuickfixProvider.java11
-rw-r--r--plugins/org.eclipse.etrice.core.etmap/src/org/eclipse/etrice/core/etmap/validation/ETMapJavaValidator.java68
2 files changed, 79 insertions, 0 deletions
diff --git a/plugins/org.eclipse.etrice.core.etmap.ui/src/org/eclipse/etrice/core/etmap/ui/quickfix/ETMapQuickfixProvider.java b/plugins/org.eclipse.etrice.core.etmap.ui/src/org/eclipse/etrice/core/etmap/ui/quickfix/ETMapQuickfixProvider.java
index e35b8b3c1..31dd91b70 100644
--- a/plugins/org.eclipse.etrice.core.etmap.ui/src/org/eclipse/etrice/core/etmap/ui/quickfix/ETMapQuickfixProvider.java
+++ b/plugins/org.eclipse.etrice.core.etmap.ui/src/org/eclipse/etrice/core/etmap/ui/quickfix/ETMapQuickfixProvider.java
@@ -75,4 +75,15 @@ public class ETMapQuickfixProvider extends DefaultQuickfixProvider {
}
});
}
+
+ @Fix(ETMapJavaValidator.WRONG_NAMESPACE)
+ public void fixWrongNamespace(final Issue issue, IssueResolutionAcceptor acceptor) {
+ acceptor.accept(issue, "Replace with correct namespace", issue.getData()[0], "add.gif", new IModification() {
+ public void apply(IModificationContext context) throws BadLocationException {
+ IXtextDocument xtextDocument = context.getXtextDocument();
+ String replacement = issue.getData()[0];
+ xtextDocument.replace(issue.getOffset(), issue.getLength(), replacement);
+ }
+ });
+ }
}
diff --git a/plugins/org.eclipse.etrice.core.etmap/src/org/eclipse/etrice/core/etmap/validation/ETMapJavaValidator.java b/plugins/org.eclipse.etrice.core.etmap/src/org/eclipse/etrice/core/etmap/validation/ETMapJavaValidator.java
index aff5d0872..a55dbe679 100644
--- a/plugins/org.eclipse.etrice.core.etmap/src/org/eclipse/etrice/core/etmap/validation/ETMapJavaValidator.java
+++ b/plugins/org.eclipse.etrice.core.etmap/src/org/eclipse/etrice/core/etmap/validation/ETMapJavaValidator.java
@@ -14,14 +14,24 @@ package org.eclipse.etrice.core.etmap.validation;
import java.util.HashSet;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.etrice.core.etmap.eTMap.ETMapPackage;
+import org.eclipse.etrice.core.etmap.eTMap.Import;
import org.eclipse.etrice.core.etmap.eTMap.Mapping;
import org.eclipse.etrice.core.etmap.eTMap.SubSystemMapping;
import org.eclipse.etrice.core.etmap.eTMap.ThreadMapping;
+import org.eclipse.etrice.core.etphys.eTPhys.PhysicalModel;
import org.eclipse.etrice.core.room.LogicalThread;
+import org.eclipse.etrice.core.room.RoomModel;
import org.eclipse.etrice.core.room.SubSystemRef;
+import org.eclipse.xtext.scoping.impl.ImportUriResolver;
import org.eclipse.xtext.validation.Check;
+import com.google.inject.Inject;
+
public class ETMapJavaValidator extends AbstractETMapJavaValidator {
@@ -29,9 +39,12 @@ public class ETMapJavaValidator extends AbstractETMapJavaValidator {
public static final String UNMAPPED_SUBSYS_REFS = "ETMapJavaValidator.UnmappedSubSysRefs";
public static final String DUPLICATE_THREAD_MAPPING = "ETMapJavaValidator.DulicateThreadMapping";
public static final String UNMAPPED_THREAD_REFS = "ETMapJavaValidator.UnmappedThreadRefs";
+ public static final String WRONG_NAMESPACE = "ETMapJavaValidator.WrongNamespace";
public static final String NOT_EMPTY = "empty";
public static final String EMPTY = "not-empty";
+ @Inject ImportUriResolver importUriResolver;
+
@Check
public void checkMapping(Mapping mp) {
HashSet<SubSystemRef> mapped = new HashSet<SubSystemRef>();
@@ -89,4 +102,59 @@ public class ETMapJavaValidator extends AbstractETMapJavaValidator {
fix.toString(),
mapped.isEmpty()? EMPTY:NOT_EMPTY);
}
+
+ @Check
+ public void checkImportedNamespace(Import imp) {
+ if (imp.getImportedNamespace()==null)
+ return;
+
+ if (imp.getImportURI()==null)
+ return;
+
+ String uriString = importUriResolver.resolve(imp);
+
+ URI uri = URI.createURI(uriString);
+ ResourceSet rs = new ResourceSetImpl();
+
+ try {
+ Resource res = rs.getResource(uri, true);
+ if (res==null)
+ return;
+
+ if (res.getContents().isEmpty()) {
+ error("referenced model is empty", ETMapPackage.Literals.IMPORT__IMPORT_URI);
+ return;
+ }
+
+ if (uri.lastSegment().endsWith(".room")) {
+ if (!(res.getContents().get(0) instanceof RoomModel)) {
+ error("referenced model is no ROOM model (but has .room extension)", ETMapPackage.Literals.IMPORT__IMPORT_URI);
+ return;
+ }
+
+ RoomModel model = (RoomModel) res.getContents().get(0);
+ if (!imp.getImportedNamespace().equals(model.getName()+".*")) {
+ error("the imported namespace should be '"+model.getName()+".*'", ETMapPackage.Literals.IMPORT__IMPORTED_NAMESPACE, WRONG_NAMESPACE, model.getName()+".*");
+ }
+ }
+ else if (uri.lastSegment().endsWith(".etphys")) {
+ if (!(res.getContents().get(0) instanceof PhysicalModel)) {
+ error("referenced model is no eTrice physical model (but has .etphys extension)", ETMapPackage.Literals.IMPORT__IMPORT_URI);
+ return;
+ }
+
+ PhysicalModel model = (PhysicalModel) res.getContents().get(0);
+ if (!imp.getImportedNamespace().equals(model.getName()+".*")) {
+ error("the imported namespace should be '"+model.getName()+".*'", ETMapPackage.Literals.IMPORT__IMPORTED_NAMESPACE, WRONG_NAMESPACE, model.getName()+".*");
+ }
+ }
+ else {
+ error("referenced model has unexpected file extension", ETMapPackage.Literals.IMPORT__IMPORT_URI);
+ }
+ }
+ catch (RuntimeException re) {
+ warning("could not load referenced model", ETMapPackage.Literals.IMPORT__IMPORT_URI);
+ return;
+ }
+ }
}

Back to the top