Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2012-11-21 09:44:46 +0000
committerHenrik Rentz-Reichert2012-11-21 09:44:46 +0000
commitc0e2f108621b51571be3327aa77d32625de7a99a (patch)
tree51c27535f219fde43a733e9bca425212528a41cb
parentdc0682eebdbd0d1d21400a7efbe8ea1dbcb98e88 (diff)
downloadorg.eclipse.etrice-c0e2f108621b51571be3327aa77d32625de7a99a.tar.gz
org.eclipse.etrice-c0e2f108621b51571be3327aa77d32625de7a99a.tar.xz
org.eclipse.etrice-c0e2f108621b51571be3327aa77d32625de7a99a.zip
[core.etmap] validation and quick fixes
-rw-r--r--plugins/org.eclipse.etrice.core.etmap.ui/src/org/eclipse/etrice/core/etmap/ui/quickfix/ETMapQuickfixProvider.java59
-rw-r--r--plugins/org.eclipse.etrice.core.etmap/src/org/eclipse/etrice/core/etmap/validation/ETMapJavaValidator.java57
2 files changed, 113 insertions, 3 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 634587455..7f93d11fe 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
@@ -12,7 +12,15 @@
package org.eclipse.etrice.core.etmap.ui.quickfix;
+import org.eclipse.xtext.ui.editor.model.IXtextDocument;
+import org.eclipse.xtext.ui.editor.model.edit.IModification;
+import org.eclipse.xtext.ui.editor.model.edit.IModificationContext;
import org.eclipse.xtext.ui.editor.quickfix.DefaultQuickfixProvider;
+import org.eclipse.xtext.ui.editor.quickfix.Fix;
+import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor;
+import org.eclipse.xtext.validation.Issue;
+import org.eclipse.etrice.core.etmap.validation.ETMapJavaValidator;
+import org.eclipse.jface.text.BadLocationException;
public class ETMapQuickfixProvider extends DefaultQuickfixProvider {
@@ -27,4 +35,55 @@ public class ETMapQuickfixProvider extends DefaultQuickfixProvider {
// });
// }
+ @Fix(ETMapJavaValidator.DUPLICATE_SUBSYS_MAPPING)
+ public void removeDuplicateSubSysMapping(final Issue issue, IssueResolutionAcceptor acceptor) {
+ acceptor.accept(issue, "Remove duplicate", "remove this mapping", "upcase.png", new IModification() {
+ public void apply(IModificationContext context) throws BadLocationException {
+ IXtextDocument xtextDocument = context.getXtextDocument();
+ xtextDocument.replace(issue.getOffset(), issue.getLength(), "");
+ }
+ });
+ }
+
+ @Fix(ETMapJavaValidator.UNMAPPED_SUBSYS_REFS)
+ public void addMissingSubSysMappings(final Issue issue, IssueResolutionAcceptor acceptor) {
+ acceptor.accept(issue, "Add mappings", "add missing mappings", "upcase.png", new IModification() {
+ public void apply(IModificationContext context) throws BadLocationException {
+ IXtextDocument xtextDocument = context.getXtextDocument();
+ int offset = issue.getOffset()+issue.getLength();
+ String insertion = "\n"+issue.getData()[0];
+ if (issue.getData()[1].equals(ETMapJavaValidator.EMPTY)) {
+ --offset;
+ insertion += "\t\t";
+ }
+ xtextDocument.replace(offset, 0, insertion);
+ }
+ });
+ }
+
+ @Fix(ETMapJavaValidator.DUPLICATE_THREAD_MAPPING)
+ public void removeDuplicateThreadMapping(final Issue issue, IssueResolutionAcceptor acceptor) {
+ acceptor.accept(issue, "Remove duplicate", "remove this mapping", "upcase.png", new IModification() {
+ public void apply(IModificationContext context) throws BadLocationException {
+ IXtextDocument xtextDocument = context.getXtextDocument();
+ xtextDocument.replace(issue.getOffset(), issue.getLength(), "");
+ }
+ });
+ }
+
+ @Fix(ETMapJavaValidator.UNMAPPED_THREAD_REFS)
+ public void addMissingThreadMappings(final Issue issue, IssueResolutionAcceptor acceptor) {
+ acceptor.accept(issue, "Add mappings", "add missing mappings", "upcase.png", new IModification() {
+ public void apply(IModificationContext context) throws BadLocationException {
+ IXtextDocument xtextDocument = context.getXtextDocument();
+ int offset = issue.getOffset()+issue.getLength();
+ String insertion = "\n"+issue.getData()[0];
+ if (issue.getData()[1].equals(ETMapJavaValidator.EMPTY)) {
+ --offset;
+ insertion += "\t\t";
+ }
+ xtextDocument.replace(offset, 0, insertion);
+ }
+ });
+ }
}
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 2f1dc13dd..aff5d0872 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
@@ -15,27 +15,78 @@ package org.eclipse.etrice.core.etmap.validation;
import java.util.HashSet;
import org.eclipse.etrice.core.etmap.eTMap.ETMapPackage;
+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.room.LogicalThread;
+import org.eclipse.etrice.core.room.SubSystemRef;
import org.eclipse.xtext.validation.Check;
public class ETMapJavaValidator extends AbstractETMapJavaValidator {
+ public static final String DUPLICATE_SUBSYS_MAPPING = "ETMapJavaValidator.DulicateSubSysMapping";
+ 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 NOT_EMPTY = "empty";
+ public static final String EMPTY = "not-empty";
+
+ @Check
+ public void checkMapping(Mapping mp) {
+ HashSet<SubSystemRef> mapped = new HashSet<SubSystemRef>();
+ for (SubSystemMapping ssm : mp.getSubsysMappings()) {
+ if (!mapped.add(ssm.getLogicalSubSys())) {
+ int idx = mp.getSubsysMappings().indexOf(ssm);
+ error("duplicate mapping", ETMapPackage.Literals.MAPPING__SUBSYS_MAPPINGS, idx, DUPLICATE_SUBSYS_MAPPING);
+ }
+ }
+
+ StringBuilder msg = new StringBuilder();
+ StringBuilder fix = new StringBuilder();
+ for (SubSystemRef ssr : mp.getLogicalSys().getSubSystems()) {
+ if (!mapped.contains(ssr)) {
+ msg.append("unmapped sub system reference '"+ssr.getName()+"'\n");
+ String nodeRef = mp.getPhysicalSys().getNodeRefs().isEmpty()?
+ "no_node_ref_defined" : mp.getPhysicalSys().getNodeRefs().get(0).getName();
+ fix.append("\t\tSubSystemMapping "+ssr.getName()+" -> "+nodeRef+" {}\n");
+ }
+ }
+ if (msg.length()>0)
+ error(
+ msg.substring(0, msg.length()-2),
+ ETMapPackage.Literals.MAPPING__SUBSYS_MAPPINGS,
+ UNMAPPED_SUBSYS_REFS,
+ fix.toString(),
+ mapped.isEmpty()? EMPTY:NOT_EMPTY);
+ }
+
@Check
public void checkSubSystemMapping(SubSystemMapping ssm) {
HashSet<LogicalThread> mapped = new HashSet<LogicalThread>();
for (ThreadMapping tm : ssm.getThreadMappings()) {
- mapped.add(tm.getLogicalThread());
+ if (!mapped.add(tm.getLogicalThread())) {
+ int idx = ssm.getThreadMappings().indexOf(tm);
+ error("duplicate mapping", ETMapPackage.Literals.SUB_SYSTEM_MAPPING__THREAD_MAPPINGS, idx, DUPLICATE_THREAD_MAPPING);
+ }
}
StringBuilder sb = new StringBuilder();
+ StringBuilder fix = new StringBuilder();
for (LogicalThread lt : ssm.getLogicalSubSys().getType().getThreads()) {
- if (!mapped.contains(lt))
+ if (!mapped.contains(lt)) {
sb.append("unmapped logical thread '"+lt.getName()+"'\n");
+ String pthread = ssm.getNode().getType().getThreads().isEmpty()?
+ "no_physical_thread_defined" : ssm.getNode().getType().getThreads().get(0).getName();
+ fix.append("\t\t\tThreadMapping "+lt.getName()+" -> "+pthread+"\n");
+ }
}
if (sb.length()>0)
- error(sb.substring(0, sb.length()-2), ETMapPackage.Literals.SUB_SYSTEM_MAPPING__THREAD_MAPPINGS);
+ error(
+ sb.substring(0, sb.length()-2),
+ ETMapPackage.Literals.SUB_SYSTEM_MAPPING__THREAD_MAPPINGS,
+ UNMAPPED_THREAD_REFS,
+ fix.toString(),
+ mapped.isEmpty()? EMPTY:NOT_EMPTY);
}
}

Back to the top