Permalink
Browse files

added modified version of method unloadAndClearContentsMethod() that was

lately removed to fix GitHub issue #20 because original fix was not
sufficient (adapters were not removed from root elements)
  • Loading branch information...
1 parent 469c951 commit 4a6c6609bf285df52409b15606297107e00c8032 @mirkoseifert mirkoseifert committed Mar 30, 2013
View
22 ...degen.resource/src/org/emftext/sdk/codegen/resource/generators/TextResourceGenerator.java
@@ -104,6 +104,7 @@ private void addMethods(JavaComposite sc) {
addConstructors(sc);
addDoLoadMethod(sc);
+ addUnloadAndClearContentsMethod(sc);
addProcessTerminationRequestedMethod(sc);
addNotifyDelayedMethod(sc);
addENotifyMethod(sc);
@@ -165,6 +166,23 @@ private void addMethods(JavaComposite sc) {
generatorUtil.addIsLayoutInformationRecordingEnabled(sc, context, "loadOptions");
}
+ private void addUnloadAndClearContentsMethod(JavaComposite sc) {
+ sc.add("protected void unloadAndClearContents() {");
+ sc.add(LIST + "<" + E_OBJECT + "> contentsInternal = getContentsInternal();");
+ sc.addComment("unload the root objects");
+ sc.add("for (" + E_OBJECT + " eObject : contentsInternal) {");
+ sc.add("if (eObject instanceof " + INTERNAL_E_OBJECT + ") {");
+ sc.add("unloaded((" + INTERNAL_E_OBJECT + ") eObject);");
+ sc.add("}");
+ sc.add("}");
+ sc.addComment("unload all children using the super class method");
+ sc.add("unload();");
+ sc.addComment("now we can clear the contents");
+ sc.add("contentsInternal.clear();");
+ sc.add("}");
+ sc.addLineBreak();
+ }
+
private void addRunValidatorsMethods(JavaComposite sc) {
boolean disableEValidators = OptionManager.INSTANCE
.getBooleanOptionValue(concreteSyntax,
@@ -1068,7 +1086,9 @@ private void addDoLoadMethod(JavaComposite sc) {
sc.add("}");
sc.addLineBreak();
sc.add("clearState();");
- sc.add("unload();");
+ sc.add("unloadAndClearContents();");
+ sc.addComment("We must set the load options again since they are deleted by the unload() method.");
+ sc.add("this.loadOptions = options;");
sc.add(E_OBJECT + " root = null;");
sc.add("if (result != null) {");
sc.add("root = result.getRoot();");

0 comments on commit 4a6c660

Please sign in to comment.