Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update infrastructure for changes of full qualfied instance names #811

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

oberlehner
Copy link
Contributor

No description provided.

Copy link

github-actions bot commented Dec 2, 2024

Test Results

   111 files  ±0     111 suites  ±0   50s ⏱️ ±0s
29 162 tests ±0  29 162 ✅ ±0  0 💤 ±0  0 ❌ ±0 
29 163 runs  ±0  29 163 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit c59a4b8. ± Comparison against base commit 7e46e08.

♻️ This comment has been updated with latest results.

@oberlehner oberlehner force-pushed the updateInfra branch 6 times, most recently from 0ec6021 to 797d2c9 Compare December 10, 2024 08:14
@oberlehner oberlehner force-pushed the updateInfra branch 5 times, most recently from 666971a to 2018064 Compare December 17, 2024 10:39
@oberlehner oberlehner force-pushed the updateInfra branch 2 times, most recently from ef4d556 to f64ae37 Compare December 17, 2024 16:00
@oberlehner oberlehner force-pushed the updateInfra branch 5 times, most recently from 281f523 to 1b159c0 Compare January 9, 2025 08:07
@oberlehner oberlehner marked this pull request as ready for review January 9, 2025 11:58
@oberlehner oberlehner requested review from mx990, azoitl and pazi146 January 9, 2025 11:58
@oberlehner oberlehner changed the title Draft for update infra of plant hier Update infrastructure for changes of instance names Jan 9, 2025
@oberlehner oberlehner changed the title Update infrastructure for changes of instance names Update infrastructure for changes of full qualfied instance names Jan 9, 2025
Copy link
Member

@mx990 mx990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may have a simpler solution for handling qualified name changes in the listener:

  1. collect all execute/undo/redo changes in a single list,
  2. when performing the changes, first merge all changes for the same element in order.

This way, we should be able to avoid keeping a separate history for changes in addition to the command stack. What do you think?

import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry;
import org.eclipse.gef.commands.Command;

public abstract class QualNameAffectedCommand extends Command implements ScopedCommand {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest changing this into an interface to make it easier to add to an existing class hierarchy of commands.


protected abstract String getNewQualName();

protected abstract INamedElement getNotifier();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest renaming this to getRenamedElement (or something similar) to make it more clear what is being returned.

Comment on lines +48 to +49
Assert.isTrue(rootContainer instanceof LibraryElement);
if (rootContainer instanceof final LibraryElement element) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe having another instanceof check after an assertion makes little sense. I would suggest removing the assertion.

import org.eclipse.fordiac.ide.model.libraryElement.INamedElement;
import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry;

public abstract class QualNameChangeListener {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extract the implementation into a separeate class and change this into an interface.

listeners.add((QualNameChangeListener) obj);
}
} catch (final Exception e) {
e.printStackTrace();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please properly log the exception (including the contributing plugin).

if (typeEntry != null) {
notifiyCommit(typeEntry);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about POST_FLUSH (e.g., because a reload of the editor)?

}

private static TypeEntry getTypeEntryKeyFromCommandStack(final CommandStack stack) {
final IEditorPart currentActiveEditor = EditorUtils.getCurrentActiveEditor();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this does not handle the case where multiple editors are saved at once (e.g., Save All)? I would suggest adding a dedicated listener instance per editor to keep track of the type entry.

this.element = Objects.requireNonNull(element);
this.name = name;
this.validateName = validateName;
this.oldName = element.getQualifiedName();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The oldName is supposed to be the (unqualified) name of the element and is assigned in execute().

Comment on lines +181 to +191
final String[] split = getOldQualName().split("\\."); //$NON-NLS-1$
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < split.length; i++) {
if (i == split.length - 1) {
sb.append(name);
} else {
sb.append(split[i]);
sb.append("."); //$NON-NLS-1$
}
}
return sb.toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final String[] split = getOldQualName().split("\\."); //$NON-NLS-1$
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < split.length; i++) {
if (i == split.length - 1) {
sb.append(name);
} else {
sb.append(split[i]);
sb.append("."); //$NON-NLS-1$
}
}
return sb.toString();
return getOldQualName().substring(0, getOldQualName().length() - oldName.length()) + name;

@@ -19,7 +19,10 @@ Require-Bundle: org.eclipse.core.resources,
org.eclipse.fordiac.ide.ui,
org.eclipse.fordiac.ide.typemanagement,
org.eclipse.ui.ide,
org.eclipse.ui.views.properties.tabbed
org.eclipse.emf.mwe.core,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need org.eclipse.emf.mwe.core as a dependency?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants