diff options
author | Henrik Rentz-Reichert | 2013-07-11 15:06:12 +0000 |
---|---|---|
committer | Henrik Rentz-Reichert | 2013-07-11 15:06:12 +0000 |
commit | d65e1d1bdd43feadb43261b85aac2d8aef5e089c (patch) | |
tree | b94b955f01b5f12d4eb0368bb2ccb64c4a3b4348 | |
parent | d14e60f6bbe9b82dd610c009306e38699f8b21f3 (diff) | |
download | org.eclipse.etrice-d65e1d1bdd43feadb43261b85aac2d8aef5e089c.tar.gz org.eclipse.etrice-d65e1d1bdd43feadb43261b85aac2d8aef5e089c.tar.xz org.eclipse.etrice-d65e1d1bdd43feadb43261b85aac2d8aef5e089c.zip |
[core.etphys] bug 412775: [core.etphys] formatting for time interval omits unit and produces a syntax error
https://bugs.eclipse.org/bugs/show_bug.cgi?id=412775
11 files changed, 195 insertions, 21 deletions
diff --git a/plugins/org.eclipse.etrice.core.etphys.ui/src/org/eclipse/etrice/core/etphys/ui/quickfix/ETPhysQuickfixProvider.java b/plugins/org.eclipse.etrice.core.etphys.ui/src/org/eclipse/etrice/core/etphys/ui/quickfix/ETPhysQuickfixProvider.java index a7bd3269d..28d1d0ebe 100644 --- a/plugins/org.eclipse.etrice.core.etphys.ui/src/org/eclipse/etrice/core/etphys/ui/quickfix/ETPhysQuickfixProvider.java +++ b/plugins/org.eclipse.etrice.core.etphys.ui/src/org/eclipse/etrice/core/etphys/ui/quickfix/ETPhysQuickfixProvider.java @@ -12,19 +12,43 @@ package org.eclipse.etrice.core.etphys.ui.quickfix; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.etrice.core.etphys.eTPhys.PhysicalThread; +import org.eclipse.etrice.core.etphys.validation.ETPhysJavaValidator; +import org.eclipse.xtext.ui.editor.model.edit.ISemanticModification; 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.ui.editor.model.edit.IModificationContext; +import org.eclipse.xtext.validation.Issue; public class ETPhysQuickfixProvider extends DefaultQuickfixProvider { -// @Fix(MyJavaValidator.INVALID_NAME) -// public void capitalizeName(final Issue issue, IssueResolutionAcceptor acceptor) { -// acceptor.accept(issue, "Capitalize name", "Capitalize the name.", "upcase.png", new IModification() { -// public void apply(IModificationContext context) throws BadLocationException { -// IXtextDocument xtextDocument = context.getXtextDocument(); -// String firstLetter = xtextDocument.get(issue.getOffset(), 1); -// xtextDocument.replace(issue.getOffset(), 1, firstLetter.toUpperCase()); -// } -// }); -// } + @Fix(ETPhysJavaValidator.ADD_TIME_INTERVAL) + public void addTimeInterval(final Issue issue, IssueResolutionAcceptor acceptor) { + acceptor.accept(issue, "Add time interval of 10ms", "interval = 10ms", "add.gif", new ISemanticModification() { + @Override + public void apply(EObject element, IModificationContext context) throws Exception { + PhysicalThread pt = (PhysicalThread) element; + pt.setTime(10000000); + } + }); + } + + @Fix(ETPhysJavaValidator.REMOVE_TIME_INTERVAL) + public void removeTimeInterval(final Issue issue, IssueResolutionAcceptor acceptor) { + acceptor.accept(issue, "Remove time interval", "[interval = ...]", "add.gif", new ISemanticModification() { + @Override + public void apply(EObject element, IModificationContext context) throws Exception { + PhysicalThread pt = (PhysicalThread) element; + + /* made this attribute unsettable - but unsetting and deserializing + * doesn't give the desired result (removing the 'interval = ...' totally) + * but rather sets the time to 0 + */ + pt.unsetTime(); + } + }); + } } diff --git a/plugins/org.eclipse.etrice.core.etphys/src-gen/org/eclipse/etrice/core/etphys/ETPhys.ecore b/plugins/org.eclipse.etrice.core.etphys/src-gen/org/eclipse/etrice/core/etphys/ETPhys.ecore index 041dd0fbc..1c0d23a0c 100644 --- a/plugins/org.eclipse.etrice.core.etphys/src-gen/org/eclipse/etrice/core/etphys/ETPhys.ecore +++ b/plugins/org.eclipse.etrice.core.etphys/src-gen/org/eclipse/etrice/core/etphys/ETPhys.ecore @@ -135,7 +135,8 @@ <details key="documentation" value="<br>This is the execution mode of the thread.
"/>
</eAnnotations>
</eStructuralFeatures>
- <eStructuralFeatures xsi:type="ecore:EAttribute" name="time" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="time" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"
+ unsettable="true"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="prio" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="<br>This is the priority of the thread.
"/>
diff --git a/plugins/org.eclipse.etrice.core.etphys/src-gen/org/eclipse/etrice/core/etphys/eTPhys/PhysicalThread.java b/plugins/org.eclipse.etrice.core.etphys/src-gen/org/eclipse/etrice/core/etphys/eTPhys/PhysicalThread.java index 34776d1f3..5bb60b167 100644 --- a/plugins/org.eclipse.etrice.core.etphys/src-gen/org/eclipse/etrice/core/etphys/eTPhys/PhysicalThread.java +++ b/plugins/org.eclipse.etrice.core.etphys/src-gen/org/eclipse/etrice/core/etphys/eTPhys/PhysicalThread.java @@ -124,9 +124,11 @@ public interface PhysicalThread extends EObject * </p>
* <!-- end-user-doc -->
* @return the value of the '<em>Time</em>' attribute.
+ * @see #isSetTime()
+ * @see #unsetTime()
* @see #setTime(int)
* @see org.eclipse.etrice.core.etphys.eTPhys.ETPhysPackage#getPhysicalThread_Time()
- * @model
+ * @model unsettable="true"
* @generated
*/
int getTime();
@@ -136,12 +138,37 @@ public interface PhysicalThread extends EObject * <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param value the new value of the '<em>Time</em>' attribute.
+ * @see #isSetTime()
+ * @see #unsetTime()
* @see #getTime()
* @generated
*/
void setTime(int value);
/**
+ * Unsets the value of the '{@link org.eclipse.etrice.core.etphys.eTPhys.PhysicalThread#getTime <em>Time</em>}' attribute.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @see #isSetTime()
+ * @see #getTime()
+ * @see #setTime(int)
+ * @generated
+ */
+ void unsetTime();
+
+ /**
+ * Returns whether the value of the '{@link org.eclipse.etrice.core.etphys.eTPhys.PhysicalThread#getTime <em>Time</em>}' attribute is set.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @return whether the value of the '<em>Time</em>' attribute is set.
+ * @see #unsetTime()
+ * @see #getTime()
+ * @see #setTime(int)
+ * @generated
+ */
+ boolean isSetTime();
+
+ /**
* Returns the value of the '<em><b>Prio</b></em>' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
diff --git a/plugins/org.eclipse.etrice.core.etphys/src-gen/org/eclipse/etrice/core/etphys/eTPhys/impl/ETPhysPackageImpl.java b/plugins/org.eclipse.etrice.core.etphys/src-gen/org/eclipse/etrice/core/etphys/eTPhys/impl/ETPhysPackageImpl.java index 818c12913..c58965def 100644 --- a/plugins/org.eclipse.etrice.core.etphys/src-gen/org/eclipse/etrice/core/etphys/eTPhys/impl/ETPhysPackageImpl.java +++ b/plugins/org.eclipse.etrice.core.etphys/src-gen/org/eclipse/etrice/core/etphys/eTPhys/impl/ETPhysPackageImpl.java @@ -716,7 +716,7 @@ public class ETPhysPackageImpl extends EPackageImpl implements ETPhysPackage initEAttribute(getPhysicalThread_Default(), ecorePackage.getEBoolean(), "default", null, 0, 1, PhysicalThread.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getPhysicalThread_Name(), ecorePackage.getEString(), "name", null, 0, 1, PhysicalThread.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getPhysicalThread_Execmode(), this.getExecMode(), "execmode", null, 0, 1, PhysicalThread.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
- initEAttribute(getPhysicalThread_Time(), ecorePackage.getEInt(), "time", null, 0, 1, PhysicalThread.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
+ initEAttribute(getPhysicalThread_Time(), ecorePackage.getEInt(), "time", null, 0, 1, PhysicalThread.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getPhysicalThread_Prio(), ecorePackage.getEInt(), "prio", null, 0, 1, PhysicalThread.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getPhysicalThread_Stacksize(), ecorePackage.getEInt(), "stacksize", null, 0, 1, PhysicalThread.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getPhysicalThread_Msgblocksize(), ecorePackage.getEInt(), "msgblocksize", null, 0, 1, PhysicalThread.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
diff --git a/plugins/org.eclipse.etrice.core.etphys/src-gen/org/eclipse/etrice/core/etphys/eTPhys/impl/PhysicalThreadImpl.java b/plugins/org.eclipse.etrice.core.etphys/src-gen/org/eclipse/etrice/core/etphys/eTPhys/impl/PhysicalThreadImpl.java index e2dedc509..db3fbebfe 100644 --- a/plugins/org.eclipse.etrice.core.etphys/src-gen/org/eclipse/etrice/core/etphys/eTPhys/impl/PhysicalThreadImpl.java +++ b/plugins/org.eclipse.etrice.core.etphys/src-gen/org/eclipse/etrice/core/etphys/eTPhys/impl/PhysicalThreadImpl.java @@ -116,6 +116,15 @@ public class PhysicalThreadImpl extends MinimalEObjectImpl.Container implements protected int time = TIME_EDEFAULT;
/**
+ * This is true if the Time attribute has been set.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ * @ordered
+ */
+ protected boolean timeESet;
+
+ /**
* The default value of the '{@link #getPrio() <em>Prio</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@@ -304,8 +313,35 @@ public class PhysicalThreadImpl extends MinimalEObjectImpl.Container implements {
int oldTime = time;
time = newTime;
+ boolean oldTimeESet = timeESet;
+ timeESet = true;
if (eNotificationRequired())
- eNotify(new ENotificationImpl(this, Notification.SET, ETPhysPackage.PHYSICAL_THREAD__TIME, oldTime, time));
+ eNotify(new ENotificationImpl(this, Notification.SET, ETPhysPackage.PHYSICAL_THREAD__TIME, oldTime, time, !oldTimeESet));
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ */
+ public void unsetTime()
+ {
+ int oldTime = time;
+ boolean oldTimeESet = timeESet;
+ time = TIME_EDEFAULT;
+ timeESet = false;
+ if (eNotificationRequired())
+ eNotify(new ENotificationImpl(this, Notification.UNSET, ETPhysPackage.PHYSICAL_THREAD__TIME, oldTime, TIME_EDEFAULT, oldTimeESet));
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ */
+ public boolean isSetTime()
+ {
+ return timeESet;
}
/**
@@ -488,7 +524,7 @@ public class PhysicalThreadImpl extends MinimalEObjectImpl.Container implements setExecmode(EXECMODE_EDEFAULT);
return;
case ETPhysPackage.PHYSICAL_THREAD__TIME:
- setTime(TIME_EDEFAULT);
+ unsetTime();
return;
case ETPhysPackage.PHYSICAL_THREAD__PRIO:
setPrio(PRIO_EDEFAULT);
@@ -523,7 +559,7 @@ public class PhysicalThreadImpl extends MinimalEObjectImpl.Container implements case ETPhysPackage.PHYSICAL_THREAD__EXECMODE:
return execmode != EXECMODE_EDEFAULT;
case ETPhysPackage.PHYSICAL_THREAD__TIME:
- return time != TIME_EDEFAULT;
+ return isSetTime();
case ETPhysPackage.PHYSICAL_THREAD__PRIO:
return prio != PRIO_EDEFAULT;
case ETPhysPackage.PHYSICAL_THREAD__STACKSIZE:
@@ -554,7 +590,7 @@ public class PhysicalThreadImpl extends MinimalEObjectImpl.Container implements result.append(", execmode: ");
result.append(execmode);
result.append(", time: ");
- result.append(time);
+ if (timeESet) result.append(time); else result.append("<unset>");
result.append(", prio: ");
result.append(prio);
result.append(", stacksize: ");
diff --git a/plugins/org.eclipse.etrice.core.etphys/src/org/eclipse/etrice/core/etphys/converters/TimeConverter.java b/plugins/org.eclipse.etrice.core.etphys/src/org/eclipse/etrice/core/etphys/converters/TimeConverter.java index f52f6678e..c97785c48 100644 --- a/plugins/org.eclipse.etrice.core.etphys/src/org/eclipse/etrice/core/etphys/converters/TimeConverter.java +++ b/plugins/org.eclipse.etrice.core.etphys/src/org/eclipse/etrice/core/etphys/converters/TimeConverter.java @@ -62,5 +62,28 @@ public class TimeConverter extends AbstractLexerBasedConverter<Integer> { }
}
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.xtext.conversion.impl.AbstractLexerBasedConverter#toEscapedString(java.lang.Object)
+ */
+ @Override
+ protected String toEscapedString(Integer value) {
+ if (value%1000==0) {
+ if (value%1000000==0) {
+ if (value%1000000000==0) {
+ return (value/1000000000)+"s";
+ }
+ else {
+ return (value/1000000)+"ms";
+ }
+ }
+ else {
+ return (value/1000)+"us";
+ }
+ }
+ else {
+ return value+"ns";
+ }
+ }
}
diff --git a/plugins/org.eclipse.etrice.core.etphys/src/org/eclipse/etrice/core/etphys/formatting/ETPhysFormatter.java b/plugins/org.eclipse.etrice.core.etphys/src/org/eclipse/etrice/core/etphys/formatting/ETPhysFormatter.java index 6a372aad2..805b255ca 100644 --- a/plugins/org.eclipse.etrice.core.etphys/src/org/eclipse/etrice/core/etphys/formatting/ETPhysFormatter.java +++ b/plugins/org.eclipse.etrice.core.etphys/src/org/eclipse/etrice/core/etphys/formatting/ETPhysFormatter.java @@ -51,7 +51,7 @@ public class ETPhysFormatter extends AbstractDeclarativeFormatter { c.setSpace(" ").between(pair.getFirst(), pair.getSecond()); } - for (Keyword k: f.findKeywords("runtime","priomin", "priomax", "execmode", "prio", "stacksize", "msgblocksize", "msgpoolsize")) { + for (Keyword k: f.findKeywords("runtime","priomin", "priomax", "execmode", "prio", "stacksize", "msgblocksize", "msgpoolsize", "interval")) { c.setLinewrap().before(k); } diff --git a/plugins/org.eclipse.etrice.core.etphys/src/org/eclipse/etrice/core/etphys/postprocessing/ImplPostprocessor.xtend b/plugins/org.eclipse.etrice.core.etphys/src/org/eclipse/etrice/core/etphys/postprocessing/ImplPostprocessor.xtend new file mode 100644 index 000000000..56d40b741 --- /dev/null +++ b/plugins/org.eclipse.etrice.core.etphys/src/org/eclipse/etrice/core/etphys/postprocessing/ImplPostprocessor.xtend @@ -0,0 +1,26 @@ +/*******************************************************************************
+ * Copyright (c) 2013 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.core.etphys.postprocessing
+
+import org.eclipse.xtext.GeneratedMetamodel
+import static extension org.eclipse.etrice.core.postprocessing.PostprocessingHelpers.*
+
+class ImplPostprocessor {
+ def process(GeneratedMetamodel metamodel) {
+ val pckg = metamodel.EPackage
+
+ var pt = pckg.getClass("PhysicalThread")
+ var tm = pt.getAttribute("time")
+ tm.setUnsettable(true)
+ }
+}
\ No newline at end of file diff --git a/plugins/org.eclipse.etrice.core.etphys/src/org/eclipse/etrice/core/etphys/postprocessing/PostprocessorController.java b/plugins/org.eclipse.etrice.core.etphys/src/org/eclipse/etrice/core/etphys/postprocessing/PostprocessorController.java index b6bf950de..0ef84a637 100644 --- a/plugins/org.eclipse.etrice.core.etphys/src/org/eclipse/etrice/core/etphys/postprocessing/PostprocessorController.java +++ b/plugins/org.eclipse.etrice.core.etphys/src/org/eclipse/etrice/core/etphys/postprocessing/PostprocessorController.java @@ -18,5 +18,6 @@ public class PostprocessorController { public static void process(GeneratedMetamodel metamodel){
new DocuPostprocessor().process(metamodel);
+ new ImplPostprocessor().process(metamodel);
}
}
diff --git a/plugins/org.eclipse.etrice.core.etphys/src/org/eclipse/etrice/core/etphys/validation/ETPhysJavaValidator.java b/plugins/org.eclipse.etrice.core.etphys/src/org/eclipse/etrice/core/etphys/validation/ETPhysJavaValidator.java index 5547a8f80..5191dcc02 100644 --- a/plugins/org.eclipse.etrice.core.etphys/src/org/eclipse/etrice/core/etphys/validation/ETPhysJavaValidator.java +++ b/plugins/org.eclipse.etrice.core.etphys/src/org/eclipse/etrice/core/etphys/validation/ETPhysJavaValidator.java @@ -22,6 +22,9 @@ import org.eclipse.xtext.validation.Check; public class ETPhysJavaValidator extends AbstractETPhysJavaValidator { + public static final String ADD_TIME_INTERVAL = "ETPhysJavaValidator.addTimeInterval"; + public static final String REMOVE_TIME_INTERVAL = "ETPhysJavaValidator.removeTimeInterval"; + @Check public void checkThread(PhysicalThread thread) { NodeClass nc = (NodeClass) thread.eContainer(); @@ -34,15 +37,21 @@ public class ETPhysJavaValidator extends AbstractETPhysJavaValidator { if (thread.getExecmode()==ExecMode.BLOCKED) { if (thread.getTime()!=0) - error("no time interval must be specified with blocked execution mode", ETPhysPackage.Literals.PHYSICAL_THREAD__TIME); + error("no time interval must be specified with blocked execution mode", + ETPhysPackage.Literals.PHYSICAL_THREAD__TIME, + REMOVE_TIME_INTERVAL); } else if (thread.getExecmode()==ExecMode.POLLED){ if (thread.getTime()==0) - error("a time interval must be specified with polled execution mode", ETPhysPackage.Literals.PHYSICAL_THREAD__TIME); + error("a time interval must be specified with polled execution mode", + ETPhysPackage.Literals.PHYSICAL_THREAD__TIME, + ADD_TIME_INTERVAL); } else if (thread.getExecmode()==ExecMode.MIXED){ if (thread.getTime()==0) - error("a time interval must be specified with mixed execution mode", ETPhysPackage.Literals.PHYSICAL_THREAD__TIME); + error("a time interval must be specified with mixed execution mode", + ETPhysPackage.Literals.PHYSICAL_THREAD__TIME, + ADD_TIME_INTERVAL); } } diff --git a/plugins/org.eclipse.etrice.core.etphys/xtend-gen/org/eclipse/etrice/core/etphys/postprocessing/ImplPostprocessor.java b/plugins/org.eclipse.etrice.core.etphys/xtend-gen/org/eclipse/etrice/core/etphys/postprocessing/ImplPostprocessor.java new file mode 100644 index 000000000..c79ca6654 --- /dev/null +++ b/plugins/org.eclipse.etrice.core.etphys/xtend-gen/org/eclipse/etrice/core/etphys/postprocessing/ImplPostprocessor.java @@ -0,0 +1,27 @@ +/**
+ * Copyright (c) 2013 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert
+ */
+package org.eclipse.etrice.core.etphys.postprocessing;
+
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.etrice.core.postprocessing.PostprocessingHelpers;
+import org.eclipse.xtext.GeneratedMetamodel;
+
+@SuppressWarnings("all")
+public class ImplPostprocessor {
+ public void process(final GeneratedMetamodel metamodel) {
+ final EPackage pckg = metamodel.getEPackage();
+ EClass pt = PostprocessingHelpers.getClass(pckg, "PhysicalThread");
+ EAttribute tm = PostprocessingHelpers.getAttribute(pt, "time");
+ tm.setUnsettable(true);
+ }
+}
|