From 140820d14e9ac8c562cb6368b9f839efb4bbecbe Mon Sep 17 00:00:00 2001 From: Qemal Alliu Date: Thu, 23 Jan 2025 14:53:54 +0100 Subject: [PATCH] refactoring --- .../application/handlers/OpenTypeHandler.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/handlers/OpenTypeHandler.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/handlers/OpenTypeHandler.java index 6618bd3c65..e84293628e 100644 --- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/handlers/OpenTypeHandler.java +++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/handlers/OpenTypeHandler.java @@ -44,22 +44,22 @@ public class OpenTypeHandler extends AbstractHandler { public Object execute(final ExecutionEvent event) throws ExecutionException { final IStructuredSelection sel = HandlerUtil.getCurrentStructuredSelection(event); - final EObject type = getTypeFromSelection(sel); + final EObject object = getSelectedObject(sel); - if (type != null) { - openTypeEditor(type); + if (object != null) { + openTypeEditor(object); } return null; } - private static void openTypeEditor(final EObject type) { + private static void openTypeEditor(final EObject object) { final IWorkbench workbench = PlatformUI.getWorkbench(); if (workbench != null) { final IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow(); if (activeWorkbenchWindow != null) { try { - OpenListenerManager.openEditor(type); + OpenListenerManager.openEditor(object); } catch (final Exception e) { FordiacLogHelper.logError(e.getMessage(), e); } @@ -72,10 +72,10 @@ public void setEnabled(final Object evaluationContext) { final ISelection sel = (ISelection) HandlerUtil.getVariable(evaluationContext, ISources.ACTIVE_CURRENT_SELECTION_NAME); - setBaseEnabled(getTypeFromSelection(sel) != null); + setBaseEnabled(getSelectedObject(sel) != null); } - private static EObject getTypeFromSelection(final ISelection sel) { + private static EObject getSelectedObject(final ISelection sel) { if ((sel instanceof final IStructuredSelection structSel) && !sel.isEmpty() && (structSel.size() == 1)) { Object obj = structSel.getFirstElement(); @@ -103,17 +103,17 @@ private static EObject getTypeFromFbn(final FBNetwork fbn) { if (fbn.eContainer() instanceof final UntypedSubApp usa) { EObject element = usa; - final List subApps = new ArrayList<>(); + final List subAppNames = new ArrayList<>(); while (element != null) { if (element instanceof final INamedElement ine) { - subApps.add(ine.getName()); + subAppNames.add(ine.getName()); } if (element.eContainer() instanceof final TypedSubApp tsa) { - subApps.add(tsa.getName()); + subAppNames.add(tsa.getName()); - return getEObjectFromString(subApps, tsa.getType()); + return getUntypedSubApp(subAppNames.reversed(), tsa.getType()); } element = element.eContainer(); @@ -127,20 +127,20 @@ private static EObject getTypeFromFbn(final FBNetwork fbn) { return null; } - private static SubApp getEObjectFromString(final List subApps, final SubAppType type) { + private static SubApp getUntypedSubApp(final List subAppNames, final SubAppType type) { FBNetwork fb = type.getFBNetwork(); - SubApp last = null; + SubApp lastSubapp = null; - for (final String s : subApps.reversed()) { - final SubApp sa = fb.getSubAppNamed(s); + for (final String subAppName : subAppNames) { + final SubApp sa = fb.getSubAppNamed(subAppName); if (sa != null) { - last = sa; + lastSubapp = sa; fb = sa.getSubAppNetwork(); } } - return last; + return lastSubapp; } }