improved quick fix
diff --git a/plugins/org.eclipse.mylyn.docs.intent.client.ui/src/org/eclipse/mylyn/docs/intent/client/ui/editor/quickfix/GenerateModelingUnitFix.java b/plugins/org.eclipse.mylyn.docs.intent.client.ui/src/org/eclipse/mylyn/docs/intent/client/ui/editor/quickfix/GenerateModelingUnitFix.java
index 8a1befa..fd38f4e 100644
--- a/plugins/org.eclipse.mylyn.docs.intent.client.ui/src/org/eclipse/mylyn/docs/intent/client/ui/editor/quickfix/GenerateModelingUnitFix.java
+++ b/plugins/org.eclipse.mylyn.docs.intent.client.ui/src/org/eclipse/mylyn/docs/intent/client/ui/editor/quickfix/GenerateModelingUnitFix.java
@@ -51,6 +51,11 @@
private IntentAnnotation syncAnnotation;
/**
+ * The root {@link EObject} to generate.
+ */
+ private EObject root;
+
+ /**
* Default constructor.
*
* @param annotation
@@ -95,13 +100,7 @@
if (target != null) {
// generates the addition
- String workingCopyResourceURI = ((String)syncAnnotation.getAdditionalInformations().toArray()[1])
- .replace("\"", "");
- ResourceSetImpl rs = new ResourceSetImpl();
- Resource workingCopyResource = rs.getResource(URI.createURI(workingCopyResourceURI), true);
- String workingCopyElementURIFragment = ((String)syncAnnotation.getAdditionalInformations()
- .toArray()[4]).replace("\"", "");
- final EObject root = workingCopyResource.getEObject(workingCopyElementURIFragment);
+ final EObject root = getRootEObjectToGenerate();
final ModelingUnit container = (ModelingUnit)target;
final ContributionInstruction contribution = generator.generateContribution(instanciation,
@@ -131,6 +130,24 @@
}
/**
+ * Returns the root EObject to generate.
+ *
+ * @return the root EObject to generate
+ */
+ private EObject getRootEObjectToGenerate() {
+ if (root == null) {
+ String workingCopyResourceURI = ((String)syncAnnotation.getAdditionalInformations().toArray()[1])
+ .replace("\"", "");
+ ResourceSetImpl rs = new ResourceSetImpl();
+ Resource workingCopyResource = rs.getResource(URI.createURI(workingCopyResourceURI), true);
+ String workingCopyElementURIFragment = ((String)syncAnnotation.getAdditionalInformations()
+ .toArray()[4]).replace("\"", "");
+ root = workingCopyResource.getEObject(workingCopyElementURIFragment);
+ }
+ return root;
+ }
+
+ /**
* Retrieves the resource path from an URI. TODO merge, there are similar methods in intent.
*
* @param uri
@@ -172,7 +189,8 @@
* @see org.eclipse.jface.text.contentassist.ICompletionProposal#getDisplayString()
*/
public String getDisplayString() {
- return "Generate missing instructions (experimental)";
+ return "Generate missing " + getRootEObjectToGenerate().eClass().getName()
+ + " element (experimental)";
}
/**
diff --git a/plugins/org.eclipse.mylyn.docs.intent.modelingunit.gen/src/org/eclipse/mylyn/docs/intent/modelingunit/gen/ModelingUnitGenerator.java b/plugins/org.eclipse.mylyn.docs.intent.modelingunit.gen/src/org/eclipse/mylyn/docs/intent/modelingunit/gen/ModelingUnitGenerator.java
index e30d677..d8e2387 100644
--- a/plugins/org.eclipse.mylyn.docs.intent.modelingunit.gen/src/org/eclipse/mylyn/docs/intent/modelingunit/gen/ModelingUnitGenerator.java
+++ b/plugins/org.eclipse.mylyn.docs.intent.modelingunit.gen/src/org/eclipse/mylyn/docs/intent/modelingunit/gen/ModelingUnitGenerator.java
@@ -115,7 +115,6 @@
typeReference.setIntentHref(root.eClass().getName());
typeReference.setResolvedType(root.eClass());
- instanciation.setName(getName(root));
instanciation.setMetaType(typeReference);
for (EStructuralFeature feature : root.eClass().getEAllAttributes()) {
if (feature.isChangeable() && !feature.isDerived()) {
@@ -138,22 +137,6 @@
}
/**
- * Computes the name of any object.
- *
- * @param eo
- * the object
- * @return the name
- */
- private static String getName(EObject eo) {
- for (EAttribute attr : eo.eClass().getEAllAttributes()) {
- if ("name".equals(attr.getName())) {
- return eo.eGet(attr).toString();
- }
- }
- return null;
- }
-
- /**
* Generates the {@link StructuralFeatureAffectation} which build the affectation.
*
* @param object
diff --git a/tests/org.eclipse.mylyn.docs.intent.modelingunit.gen.test/expectedResults/sample.ecore.intent b/tests/org.eclipse.mylyn.docs.intent.modelingunit.gen.test/expectedResults/sample.ecore.intent
index 437d191..d6b7728 100644
--- a/tests/org.eclipse.mylyn.docs.intent.modelingunit.gen.test/expectedResults/sample.ecore.intent
+++ b/tests/org.eclipse.mylyn.docs.intent.modelingunit.gen.test/expectedResults/sample.ecore.intent
@@ -1,7 +1,7 @@
@M
- new EClass c1 {
+ new EClass {
name = "c1";
- eStructuralFeatures += new EAttribute a {
+ eStructuralFeatures += new EAttribute {
name = "a";
}
;}
@@ -9,9 +9,9 @@
@M
- new EClass c2 {
+ new EClass {
name = "c2";
- eStructuralFeatures += new EReference ref {
+ eStructuralFeatures += new EReference {
name = "ref";
}
;}
@@ -19,7 +19,7 @@
@M
- new EPackage p {
+ new EPackage {
name = "p";
nsURI = "p";
nsPrefix = "p";