diff --git a/parent/preferences/CheckstyleConfiguration-strict.xml b/parent/preferences/CheckstyleConfiguration-strict.xml deleted file mode 100644 index f17d6391..00000000 --- a/parent/preferences/CheckstyleConfiguration-strict.xml +++ /dev/null @@ -1,354 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/parent/preferences/CheckstyleConfiguration.xml b/parent/preferences/CheckstyleConfiguration.xml index c706b222..b386c4c3 100644 --- a/parent/preferences/CheckstyleConfiguration.xml +++ b/parent/preferences/CheckstyleConfiguration.xml @@ -194,7 +194,7 @@ - + @@ -227,7 +227,7 @@ - + diff --git a/plugins/org.eclipse.poosl.rotalumisclient/src/org/eclipse/poosl/rotalumisclient/views/ViewHelper.java b/plugins/org.eclipse.poosl.rotalumisclient/src/org/eclipse/poosl/rotalumisclient/views/ViewHelper.java index 550c1fae..6a19f933 100644 --- a/plugins/org.eclipse.poosl.rotalumisclient/src/org/eclipse/poosl/rotalumisclient/views/ViewHelper.java +++ b/plugins/org.eclipse.poosl.rotalumisclient/src/org/eclipse/poosl/rotalumisclient/views/ViewHelper.java @@ -51,8 +51,11 @@ public static IDebugContextService getDebugService(IWorkbenchPart part) { IWorkbenchWindow window = null; try { window = part.getSite().getWorkbenchWindow().getWorkbench().getActiveWorkbenchWindow(); - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Could not get workbench window while getting debugContextService", e.getCause()); + } catch (NullPointerException e) { + // Unlikely, unless for unexpected configuration + LOGGER.log(Level.WARNING, + "Could not get workbench window while getting debugContextService", + e.getCause()); } IDebugContextManager contextManager = DebugUITools.getDebugContextManager(); if (contextManager != null && window != null) { @@ -64,17 +67,20 @@ public static IDebugContextService getDebugService(IWorkbenchPart part) { /** * If the secondID represents the thread it returns true. * - * This method is used by views that have a secondID to determine if they should show information of the thread or - * react to changes in the debug state. Views that have a secondID are dedicated to show only information on a + * This method is used by views that have a secondID to determine if they + * should show information of the thread or + * react to changes in the debug state. Views that have a secondID are + * dedicated to show only information on a * specific thread. *

- * Also see {@link ViewHelper#isTargetID(IDebugTarget, String)} and {@link ViewHelper#getSecondId(PooslThread)} + * Also see {@link ViewHelper#isTargetID(IDebugTarget, String)} and + * {@link ViewHelper#getSecondId(PooslThread)} *

* * @param thread - * The thread that contains new information + * The thread that contains new information * @param secondID - * secondid of the {@link ViewPart} + * secondid of the {@link ViewPart} * @return true if the secondid represents the thread * */ @@ -86,10 +92,13 @@ public static boolean isThreadID(PooslThread thread, String secondID) { /** * If the secondID represents the IDebugTarget it returns true. * - * This method is used by views that have a secondid to determine if they should react to changes in the debug - * state. Views that have a secondid are dedicated to show only information on a specific thread. + * This method is used by views that have a secondid to determine if they + * should react to changes in the debug + * state. Views that have a secondid are dedicated to show only information + * on a specific thread. *

- * Also see {@link ViewHelper#isThreadID(PooslThread, String)} and {@link ViewHelper#getSecondId(PooslThread)} + * Also see {@link ViewHelper#isThreadID(PooslThread, String)} and + * {@link ViewHelper#getSecondId(PooslThread)} *

* * @param target @@ -107,26 +116,33 @@ public static boolean isTargetID(IDebugTarget target, String secondID) { } /** - * Returns the secondID of the given thread. The secondID contains the debugtarget name and thread name. This - * secondID is used by Views that only need to show information on a specific thread. + * Returns the secondID of the given thread. The secondID contains the + * debugtarget name and thread name. This + * secondID is used by Views that only need to show information on a + * specific thread. * * @param thread - * {@link PooslThread} - * @return If the target or thread name could not be retrieved it returns an empty string. + * {@link PooslThread} + * @return If the target or thread name could not be retrieved it returns an + * empty string. */ public static String getSecondId(PooslThread thread) { - ILaunchConfiguration launchConfiguration = thread.getDebugTarget().getLaunch().getLaunchConfiguration(); + ILaunchConfiguration launchConfiguration = thread.getDebugTarget().getLaunch() + .getLaunchConfiguration(); String port = ""; //$NON-NLS-1$ try { - port = launchConfiguration.getAttribute(PooslConstants.CONFIGURATION_ATTRIBUTE_SERVER_PORT, ""); //$NON-NLS-1$ + port = launchConfiguration + .getAttribute(PooslConstants.CONFIGURATION_ATTRIBUTE_SERVER_PORT, ""); //$NON-NLS-1$ } catch (CoreException e) { - LOGGER.log(Level.WARNING, "Rotalumis Port could not be retrieved from the launch configuration.", e); + LOGGER.log(Level.WARNING, + "Rotalumis Port could not be retrieved from the launch configuration.", e); } String id = ""; //$NON-NLS-1$ try { - id = PooslConstants.THREAD_VIEW_ID + port + SECONDID_SPLIT + thread.getDebugTarget().getName() + SECONDID_SPLIT + thread.getName(); + id = PooslConstants.THREAD_VIEW_ID + port + SECONDID_SPLIT + + thread.getDebugTarget().getName() + SECONDID_SPLIT + thread.getName(); } catch (DebugException e) { LOGGER.log(Level.SEVERE, "Thread name could not be read.", e); } @@ -169,38 +185,43 @@ public static String getThreadName(String secondID) { } /** - * If the thread is not yet set, get the thread represented by the secondid using the events source only. Used by - * the separate PETView and Variable view after the model is terminated and restarted. + * If the thread is not yet set, get the thread represented by the secondid + * using the events source only. Used by + * the separate PETView and Variable view after the model is terminated and + * restarted. * * @param thread - * Current {@link PooslThread} + * Current {@link PooslThread} * @param debugEvent - * {@link DebugEvent} that is triggered + * {@link DebugEvent} that is triggered * @param secondID - * {@link String} secondid that represents the thread. + * {@link String} secondid that represents the thread. * @return {@link PooslThread} thread */ - public static PooslThread getThreadFromEvent(PooslThread thread, DebugEvent debugEvent, String secondID) { - if (thread != null && thread.isTerminated()) { - thread = null; + public static PooslThread getThreadFromEvent( + PooslThread thread, DebugEvent debugEvent, String secondID) { + PooslThread result = thread; + if (result != null && result.isTerminated()) { + result = null; } - if (thread == null && secondID != null) { + if (result == null && secondID != null) { if (debugEvent.getSource() instanceof PooslDebugTarget) { try { PooslDebugTarget target = (PooslDebugTarget) debugEvent.getSource(); String targetName = target.getName(); if (targetName.equals(ViewHelper.getDebugTargetName(secondID))) { - thread = PooslDebugHelper.getThreadByName(target.getThreads(), ViewHelper.getThreadName(secondID)); + result = PooslDebugHelper.getThreadByName(target.getThreads(), + ViewHelper.getThreadName(secondID)); } } catch (DebugException e) { LOGGER.log(Level.WARNING, "Could not get name of the debugtarget.", e); } } else if (debugEvent.getSource() instanceof PooslThread) { PooslThread newThread = (PooslThread) debugEvent.getSource(); - thread = (isThreadID(newThread, secondID)) ? newThread : null; + result = (isThreadID(newThread, secondID)) ? newThread : null; } } - return thread; + return result; } } diff --git a/plugins/org.eclipse.poosl.rotalumisclient/src/org/eclipse/poosl/rotalumisclient/views/WindowCreater.java b/plugins/org.eclipse.poosl.rotalumisclient/src/org/eclipse/poosl/rotalumisclient/views/WindowCreater.java index d3c9b6fc..d7fd8040 100644 --- a/plugins/org.eclipse.poosl.rotalumisclient/src/org/eclipse/poosl/rotalumisclient/views/WindowCreater.java +++ b/plugins/org.eclipse.poosl.rotalumisclient/src/org/eclipse/poosl/rotalumisclient/views/WindowCreater.java @@ -39,11 +39,15 @@ /** * Helper class to create new seperate windows.
- * {@link WindowCreater#getWindowForError(IWorkbenchPartSite, PooslDebugTarget)} creates if need a new window containing - * {@link StackTraceView} and {@link StackTraceVariableView} containing stacktrace information when an error occurs. + * {@link WindowCreater#getWindowForError(IWorkbenchPartSite, PooslDebugTarget)} + * creates if need a new window containing + * {@link StackTraceView} and {@link StackTraceVariableView} containing + * stacktrace information when an error occurs. *
- * {@link WindowCreater#getWindowForThread(IWorkbenchPartSite, PooslThread)} creates if needed a new window containing - * {@link PooslPETView} and {@link PooslVariablesView} to show information on a specific thread determined by the views + * {@link WindowCreater#getWindowForThread(IWorkbenchPartSite, PooslThread)} + * creates if needed a new window containing + * {@link PooslPETView} and {@link PooslVariablesView} to show information on a + * specific thread determined by the views * second ID. * * @author Koen Staal @@ -57,44 +61,54 @@ private WindowCreater() { } /** - * Creates or finds the thread window that contains the seperate PETView and VariableView for the given thread. The - * created views get a secondid, see {@link ViewHelper#getSecondId(PooslThread)}. It creates a new window if both + * Creates or finds the thread window that contains the seperate PETView and + * VariableView for the given thread. The + * created views get a secondid, see + * {@link ViewHelper#getSecondId(PooslThread)}. It creates a new window if + * both * views are not in the same window. * * @param site - * {@link IWorkbenchPartSite} used as context to search for the views and creating the window. + * {@link IWorkbenchPartSite} used as context to search for the views + * and creating the window. * @param thread - * The {@link PooslThread} that should be shown in the window + * The {@link PooslThread} that should be shown in the window * @return A {@link MWindow} with a PET view and Variable view of the thread * @throws DebugException * @throws PartInitException */ - public static MWindow getWindowForThread(IWorkbenchPartSite site, PooslThread thread) throws DebugException, PartInitException { + public static MWindow getWindowForThread(IWorkbenchPartSite site, PooslThread thread) + throws DebugException, PartInitException { MWindow window = null; IViewPart petView = null; IViewPart varView = null; String secondID = ViewHelper.getSecondId(thread); - IViewReference petReference = site.getPage().findViewReference(PooslConstants.ID_POOSL_PETVIEW, secondID); + IViewReference petReference = site.getPage() + .findViewReference(PooslConstants.ID_POOSL_PETVIEW, secondID); if (petReference != null) { petView = petReference.getView(true); } - IViewReference varReference = site.getPage().findViewReference(PooslConstants.ID_POOSL_VARIABLESVIEW, secondID); + IViewReference varReference = site.getPage() + .findViewReference(PooslConstants.ID_POOSL_VARIABLESVIEW, secondID); if (varReference != null) { varView = varReference.getView(true); } if (petView == null) { - petView = site.getPage().showView(PooslConstants.ID_POOSL_PETVIEW, secondID, IWorkbenchPage.VIEW_VISIBLE); + petView = site.getPage().showView(PooslConstants.ID_POOSL_PETVIEW, secondID, + IWorkbenchPage.VIEW_VISIBLE); } if (varView == null) { - varView = site.getPage().showView(PooslConstants.ID_POOSL_VARIABLESVIEW, secondID, IWorkbenchPage.VIEW_VISIBLE); + varView = site.getPage().showView(PooslConstants.ID_POOSL_VARIABLESVIEW, secondID, + IWorkbenchPage.VIEW_VISIBLE); } EModelService service = site.getService(EModelService.class); window = findWindow(petView, varView); if (window == null) { - window = WindowCreater.createCombinedWindow(service, petView, varView, new WindowShape(450, 600, false)); + window = WindowCreater.createCombinedWindow(service, petView, varView, + new WindowShape(450, 600, false)); window.setLabel(thread.getDebugTarget().getName() + " " + thread.getName()); //$NON-NLS-1$ } else { service.bringToTop(window); @@ -103,31 +117,42 @@ public static MWindow getWindowForThread(IWorkbenchPartSite site, PooslThread th } /** - * If either the {@link StackTraceView} or the {@link StackTraceVariableView} is not shown a new window is created - * with them in it. If they are already shown not window is created and null is returned. (The views dont have to be + * If either the {@link StackTraceView} or the + * {@link StackTraceVariableView} is not shown a new window is created + * with them in it. If they are already shown not window is created and null + * is returned. (The views dont have to be * in the same Window.) * * @param site - * {@link IWorkbenchPartSite} used as context to search for the views and creating the window. + * {@link IWorkbenchPartSite} used as context to search for the views + * and creating the window. * @param target - * {@link PooslDebugTarget} is given to the {@link StackTraceView} after creation + * {@link PooslDebugTarget} is given to the {@link StackTraceView} after + * creation * @return {@link MWindow} if one is created otherwise it returns null * @throws DebugException * @throws PartInitException */ - public static MWindow getWindowForError(IWorkbenchPartSite site, PooslDebugTarget target) throws PartInitException { - IViewReference traceReference = site.getPage().findViewReference(PooslConstants.ID_POOSL_STACKTRACEVIEW); - IViewReference frameReference = site.getPage().findViewReference(PooslConstants.ID_POOSL_STACKTRACEVARIABLEVIEW); + public static MWindow getWindowForError(IWorkbenchPartSite site, PooslDebugTarget target) + throws PartInitException { + IViewReference traceReference = site.getPage() + .findViewReference(PooslConstants.ID_POOSL_STACKTRACEVIEW); + IViewReference frameReference = site.getPage() + .findViewReference(PooslConstants.ID_POOSL_STACKTRACEVARIABLEVIEW); if (traceReference != null && frameReference != null) { IViewPart traceView = traceReference.getView(true); IViewPart frameView = frameReference.getView(true); - frameView.getViewSite().getPage().showView(PooslConstants.ID_POOSL_STACKTRACEVARIABLEVIEW, null, IWorkbenchPage.VIEW_ACTIVATE); - traceView.getViewSite().getPage().showView(PooslConstants.ID_POOSL_STACKTRACEVIEW, null, IWorkbenchPage.VIEW_ACTIVATE); + frameView.getViewSite().getPage().showView( + PooslConstants.ID_POOSL_STACKTRACEVARIABLEVIEW, null, + IWorkbenchPage.VIEW_ACTIVATE); + traceView.getViewSite().getPage().showView(PooslConstants.ID_POOSL_STACKTRACEVIEW, null, + IWorkbenchPage.VIEW_ACTIVATE); return null; } else { IViewPart traceView = site.getPage().showView(PooslConstants.ID_POOSL_STACKTRACEVIEW); - IViewPart frameView = site.getPage().showView(PooslConstants.ID_POOSL_STACKTRACEVARIABLEVIEW); + IViewPart frameView = site.getPage() + .showView(PooslConstants.ID_POOSL_STACKTRACEVARIABLEVIEW); if (traceView instanceof StackTraceView) { ((StackTraceView) traceView).setDebugContext(target); @@ -136,7 +161,8 @@ public static MWindow getWindowForError(IWorkbenchPartSite site, PooslDebugTarge EModelService service = site.getService(EModelService.class); MWindow window = findWindow(traceView, frameView); if (window == null) { - window = createCombinedWindow(service, traceView, frameView, new WindowShape(900, 600, true)); + window = createCombinedWindow(service, traceView, frameView, + new WindowShape(900, 600, true)); window.setLabel("StackTrace"); } else { service.bringToTop(window); @@ -150,7 +176,8 @@ public static MWindow getWindowForError(IWorkbenchPartSite site, PooslDebugTarge * * @param petView * @param varView - * @return null if the views are not in their own window otherwise return the window + * @return null if the views are not in their own window otherwise return + * the window */ private static MTrimmedWindow findWindow(IViewPart petView, IViewPart varView) { MUIElement petElement = petView.getSite().getService(MPart.class); @@ -163,12 +190,14 @@ private static MTrimmedWindow findWindow(IViewPart petView, IViewPart varView) { varElement = varElement.getCurSharedRef(); } - if (petElement.getParent() != null && petElement.getParent().getParent() != null && varElement.getParent() != null && varElement.getParent().getParent() != null) { + if (petElement.getParent() != null && petElement.getParent().getParent() != null + && varElement.getParent() != null && varElement.getParent().getParent() != null) { MElementContainer petContainer = petElement.getParent().getParent(); MElementContainer varContainer = varElement.getParent().getParent(); if ((petContainer == varContainer) && (petContainer.getParent() != null)) { MUIElement parentElement = petContainer.getParent(); - if (parentElement instanceof MTrimmedWindow && parentElement.getElementId() != null && parentElement.getElementId().equals(POOSL_THREAD_WINDOW)) { + if (parentElement instanceof MTrimmedWindow && parentElement.getElementId() != null + && parentElement.getElementId().equals(POOSL_THREAD_WINDOW)) { return (MTrimmedWindow) parentElement; } @@ -183,20 +212,24 @@ private static MTrimmedWindow findWindow(IViewPart petView, IViewPart varView) { * * @param service * @param firstView + * of site * @param secondView + * of site * @param shape - * @return + * @return created window * @throws PartInitException * @see {@link WindowShape} */ - private static MWindow createCombinedWindow(EModelService service, IViewPart firstView, IViewPart secondView, WindowShape shape) { + private static MWindow createCombinedWindow( + EModelService service, IViewPart firstView, IViewPart secondView, WindowShape shape) { MPart topPart = firstView.getSite().getService(MPart.class); MPart botPart = secondView.getSite().getService(MPart.class); MWindow window = service.getTopLevelWindowFor(topPart); MPerspective thePersp = service.getPerspectiveFor(topPart); - MWindowElement container = wrapElementsInContainer(service, topPart, botPart, shape.isHorizontal()); + MWindowElement container = wrapElementsInContainer(service, topPart, botPart, + shape.isHorizontal()); MTrimmedWindow newWindow = createNewWindow(service, shape); newWindow.setElementId(POOSL_THREAD_WINDOW); newWindow.getChildren().add(container); @@ -213,13 +246,20 @@ private static MWindow createCombinedWindow(EModelService service, IViewPart fir * Puts both elements in a container. Vital for arranging them in a window. * * @param service - * @param firstElement - * @param secondElement + * @param first + * top + * @param second + * bottom * @param horizontal - * The direction the views will be placed compared to each other + * The direction the views will be placed compared to each other * @return {@link MPartSashContainer} as {@link MWindowElement} */ - private static MWindowElement wrapElementsInContainer(EModelService service, MPartSashContainerElement firstElement, MPartSashContainerElement secondElement, boolean horizontal) { + private static MWindowElement wrapElementsInContainer( + EModelService service, MPartSashContainerElement first, + MPartSashContainerElement second, boolean horizontal) { + MPartSashContainerElement firstElement = first; + MPartSashContainerElement secondElement = second; + if (firstElement.getCurSharedRef() != null) { firstElement = firstElement.getCurSharedRef(); } @@ -246,11 +286,13 @@ private static MWindowElement wrapElementsInContainer(EModelService service, MPa } /** - * Create new Window based on the shape + * Create new Window based on the shape. * * @param service + * to create ui model * @param shape - * @return + * of window + * @return created window */ private static MTrimmedWindow createNewWindow(EModelService service, WindowShape shape) { MTrimmedWindow newWindow = service.createModelElement(MTrimmedWindow.class); @@ -261,7 +303,8 @@ private static MTrimmedWindow createNewWindow(EModelService service, WindowShape return newWindow; } - private static MPartStack wrapElementForWindow(EModelService service, MPartSashContainerElement element) { + private static MPartStack wrapElementForWindow( + EModelService service, MPartSashContainerElement element) { if (element instanceof MPlaceholder) { MUIElement ref = ((MPlaceholder) element).getRef(); if (ref instanceof MPart) { @@ -295,7 +338,6 @@ private static class WindowShape { private final boolean horizontal; WindowShape(int width, int height, boolean horizontal) { - super(); this.x = 100; this.y = 100; this.width = width; @@ -328,12 +370,14 @@ public boolean isHorizontal() { * Closes all thread windows within the {@link IWorkbenchPage}. * * @param page - * {@link IWorkbenchPage} In this page it searches for views having a secondary id starting with - * {@link PooslConstants#THREAD_VIEW_ID} and hides them. + * {@link IWorkbenchPage} In this page it searches for views having a + * secondary id starting with + * {@link PooslConstants#THREAD_VIEW_ID} and hides them. */ public static void closeAllThreadWindows(IWorkbenchPage page) { for (IViewReference iViewReference : page.getViewReferences()) { - if (iViewReference.getSecondaryId() != null && iViewReference.getSecondaryId().startsWith(PooslConstants.THREAD_VIEW_ID)) { + if (iViewReference.getSecondaryId() != null + && iViewReference.getSecondaryId().startsWith(PooslConstants.THREAD_VIEW_ID)) { // A view can be shown in multiple pages, it is disposed when its hidden in all // of them page.hideView(iViewReference); diff --git a/plugins/org.eclipse.poosl.sirius/src/org/eclipse/poosl/sirius/debug/GraphicalDebugListener.java b/plugins/org.eclipse.poosl.sirius/src/org/eclipse/poosl/sirius/debug/GraphicalDebugListener.java index 33bcb370..a6c9d0d3 100644 --- a/plugins/org.eclipse.poosl.sirius/src/org/eclipse/poosl/sirius/debug/GraphicalDebugListener.java +++ b/plugins/org.eclipse.poosl.sirius/src/org/eclipse/poosl/sirius/debug/GraphicalDebugListener.java @@ -73,7 +73,8 @@ public void launchStart(ExternLaunchStartMessage startMessage) { files.addAll(startMessage.getFiles()); files.addAll(getRelativeUris(startMessage.getRelativeModelPath(), files, projectName)); - Activator.MESSAGEUPDATER.launchStarted(startMessage.getLaunchID(), startMessage.getInstancePortMap(), files); + Activator.MESSAGEUPDATER.launchStarted(startMessage.getLaunchID(), + startMessage.getInstancePortMap(), files); } @Override @@ -82,13 +83,16 @@ public void lastMessageChanged(ExternDebugMessage lastMessage) { } @Override - public void debugSelectionChanged(final ExternDebugItem selectedItem, ExternDebugMessage message) { - final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(selectedItem.getProjectName()); + public void debugSelectionChanged( + final ExternDebugItem selectedItem, ExternDebugMessage message) { + final IProject project = ResourcesPlugin.getWorkspace().getRoot() + .getProject(selectedItem.getProjectName()); final EObject diagramTarget = getDiagramTarget(selectedItem); if (diagramTarget != null) { GraphicalEditorHelper.openCommunicationDiagram(selectedItem, project, diagramTarget); } else { - LOGGER.log(Level.SEVERE, "Could not find ecore model of the diagram target " + selectedItem.getDiagram()); + LOGGER.log(Level.SEVERE, "Could not find ecore model of the diagram target " + + selectedItem.getDiagram()); } } @@ -98,13 +102,15 @@ public void launchStopped(final String launchID) { ArrayList idAsArray = new ArrayList<>(Arrays.asList(launchID)); for (final Session session : SessionManager.INSTANCE.getSessions()) { UpdateHelper.addRepresentations(idAsArray, session2Descriptors, session); - PooslPermissionAuthority authority = GraphicalEditorHelper.getPermissionAuthority(session); + PooslPermissionAuthority authority = GraphicalEditorHelper + .getPermissionAuthority(session); if (authority != null) { authority.deActivate(launchID); } } Activator.MESSAGEUPDATER.launchStopped(launchID); - PooslDiagramDeleteHelper.closeAndDeleteDiagrams(UpdateHelper.getPooslShell(), session2Descriptors); + PooslDiagramDeleteHelper.closeAndDeleteDiagrams(UpdateHelper.getPooslShell(), + session2Descriptors); } private EObject getDiagramTarget(ExternDebugItem selectedItem) { @@ -121,17 +127,19 @@ private EObject getDiagramTarget(ExternDebugItem selectedItem) { } private ClusterClass getClusterClass(String[] path, ClusterClass cluster) { + ClusterClass result = cluster; for (int i = 2; i < path.length; i++) { - cluster = getInstanceClass(cluster, path[i]); + result = getInstanceClass(result, path[i]); } - return cluster; + return result; } private ClusterClass getInstanceClass(ClusterClass cluster, String instanceName) { if (cluster != null && instanceName != null) { for (Instance instance : cluster.getInstances()) { if (instance.getName().equals(instanceName)) { - IEObjectDescription descr = PooslReferenceHelper.getInstantiableClassDescription(instance); + IEObjectDescription descr = PooslReferenceHelper + .getInstantiableClassDescription(instance); if (descr.getEClass() == Literals.CLUSTER_CLASS) { EObject obj = descr.getEObjectOrProxy(); if (obj.eIsProxy()) @@ -144,14 +152,17 @@ private ClusterClass getInstanceClass(ClusterClass cluster, String instanceName) return null; } - private List getRelativeUris(String relativeModelPath, List files, String projectName) { + private List getRelativeUris( + String relativeModelPath, List files, String projectName) { String absoluteMain = getMainFile(relativeModelPath, files); List relatives = new ArrayList<>(); if (absoluteMain != null) { - String base = absoluteMain.substring(0, absoluteMain.length() - relativeModelPath.substring(projectName.length() + 1).length()); + String base = absoluteMain.substring(0, absoluteMain.length() + - relativeModelPath.substring(projectName.length() + 1).length()); for (URI absolute : files) { if (absolute.isFile() && absolute.toFileString().startsWith(base)) { - relatives.add(URI.createPlatformResourceURI(absolute.toFileString().replace(base, "\\" + projectName), true)); //$NON-NLS-1$ + relatives.add(URI.createPlatformResourceURI( + absolute.toFileString().replace(base, "\\" + projectName), true)); //$NON-NLS-1$ } } } @@ -159,11 +170,14 @@ private List getRelativeUris(String relativeModelPath, List files, Str } /** - * find main file (used to start the debug session), IDE no longer controls the location in the list + * Finds main file (used to start the debug session), IDE no longer controls + * the location in the list. * * @param relativeModelPath + * from project * @param files - * @return + * loaded for debug + * @return the main file path of null */ private String getMainFile(String relativeModelPath, List files) { // first or last are most likely to be main file. @@ -187,19 +201,23 @@ private String getMainFile(String relativeModelPath, List files) { } /** - * Get Session without having to provide the monitor and still use the Progress Service from non gui context. + * Get Session without having to provide the monitor and still use the + * Progress Service from non gui context. * * @param activeProject * @param editor * @param create * @return session or null */ - public static Session getSession(final IProject activeProject, final IEditorPart editor, final boolean create) { + public static Session getSession( + final IProject activeProject, final IEditorPart editor, final boolean create) { final Set sessions = new HashSet<>(); IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - sessions.add(GraphicalEditorHelper.getSession(activeProject, editor, create, false, monitor)); + public void run(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException { + sessions.add(GraphicalEditorHelper.getSession(activeProject, editor, create, false, + monitor)); } }; diff --git a/plugins/org.eclipse.poosl.sirius/src/org/eclipse/poosl/sirius/permissions/PooslPermissionAuthority.java b/plugins/org.eclipse.poosl.sirius/src/org/eclipse/poosl/sirius/permissions/PooslPermissionAuthority.java index 3dc6e96a..525212b2 100644 --- a/plugins/org.eclipse.poosl.sirius/src/org/eclipse/poosl/sirius/permissions/PooslPermissionAuthority.java +++ b/plugins/org.eclipse.poosl.sirius/src/org/eclipse/poosl/sirius/permissions/PooslPermissionAuthority.java @@ -50,7 +50,8 @@ public class PooslPermissionAuthority implements IPermissionAuthority { private List listeners = new CopyOnWriteArrayList<>(); /** the locked objects. */ - private ConcurrentMap lockedObjects = new MapMaker().concurrencyLevel(4).weakKeys().makeMap(); + private ConcurrentMap lockedObjects = new MapMaker().concurrencyLevel(4) + .weakKeys().makeMap(); public PooslPermissionAuthority() { } @@ -63,7 +64,8 @@ private List getLockedUris(String launchID) { return Activator.MESSAGEUPDATER.getLockedFiles().get(launchID); } - private boolean isReadOnly(EObject diagramObj) { + private boolean isReadOnly(EObject it) { + EObject diagramObj = it; if (diagramObj instanceof DiagramImpl) { DiagramImpl dd = (DiagramImpl) diagramObj; diagramObj = dd.getElement(); @@ -71,8 +73,9 @@ private boolean isReadOnly(EObject diagramObj) { if (diagramObj instanceof DSemanticDecorator) { diagramObj = ((DSemanticDecorator) diagramObj).getTarget(); } - if (diagramObj == null) + if (diagramObj == null) { return false; + } URI uri = null; if (diagramObj.eResource() != null) { @@ -117,7 +120,7 @@ private void notify(final boolean approval, final EObject obj) { * Check approval for editing this object. * * @param eObject - * the object + * the object * @return trueif approval, false otherwise */ private boolean checkApproval(final EObject eObject) { @@ -191,7 +194,7 @@ public LockStatus getLockStatus(EObject element) { * Check if an object is locked or not. * * @param eObject - * the object to check + * the object to check * @return true if is locked, false otherwise */ private boolean isLocked(final EObject eObject) { @@ -202,7 +205,7 @@ private boolean isLocked(final EObject eObject) { * Store as locked instance and notify. * * @param eObject - * the locked instance + * the locked instance */ private void storeAsLockedAndNotify(final EObject eObject) { lockedObjects.put(eObject, true); @@ -215,7 +218,7 @@ private void storeAsLockedAndNotify(final EObject eObject) { * Release and notify. * * @param eObject - * the locked instance + * the locked instance */ private void releaseFromLockedAndNotify(final EObject eObject) { lockedObjects.remove(eObject); @@ -284,8 +287,11 @@ public void createdRepresentation(URI uri) { creatingURIs.remove(uri); } + @Override public List getLockedObjects() { - // TODO Auto-generated method stub + // According to Sirius, every locked EObject should be returned. + // As locked objects are only the representation at creation time, + // result match empty list most of the time. return new ArrayList<>(); } } diff --git a/plugins/org.eclipse.poosl.xtext/src/org/eclipse/poosl/xtext/formatting2/PooslFormatter.java b/plugins/org.eclipse.poosl.xtext/src/org/eclipse/poosl/xtext/formatting2/PooslFormatter.java index 7231404d..8ab52624 100644 --- a/plugins/org.eclipse.poosl.xtext/src/org/eclipse/poosl/xtext/formatting2/PooslFormatter.java +++ b/plugins/org.eclipse.poosl.xtext/src/org/eclipse/poosl/xtext/formatting2/PooslFormatter.java @@ -135,64 +135,29 @@ public class PooslFormatter extends AbstractFormatter2 { private static final String KEYWORD_VARIABLES = "variables"; //$NON-NLS-1$ - private static final Procedure1 NO_SPACE = new Procedure1() { - @Override - public void apply(final IHiddenRegionFormatter it) { - it.noSpace(); - } - }; + private static final Procedure1 NO_SPACE = it -> it.noSpace(); - private static final Procedure1 ONE_SPACE = new Procedure1() { - @Override - public void apply(final IHiddenRegionFormatter it) { - it.oneSpace(); - it.autowrap(); - } + private static final Procedure1 ONE_SPACE = it -> { + it.oneSpace(); + it.autowrap(); }; - private static final Procedure1 ONE_SPACE_NO_WRAP = new Procedure1() { - @Override - public void apply(final IHiddenRegionFormatter it) { - it.oneSpace(); - } - }; + private static final Procedure1 ONE_SPACE_NO_WRAP = it -> it.oneSpace(); - private static final Procedure1 NEW_LINE = new Procedure1() { - @Override - public void apply(final IHiddenRegionFormatter it) { - it.newLine(); - } - }; + private static final Procedure1 NEW_LINE = it -> it.newLine(); - private static final Procedure1 EMPTY_LINE = new Procedure1() { - @Override - public void apply(final IHiddenRegionFormatter it) { - it.setNewLines(2); - } - }; + private static final Procedure1 EMPTY_LINE = it -> it.setNewLines(2); - private static final Procedure1 EMPTY_LINES = new Procedure1() { - @Override - public void apply(final IHiddenRegionFormatter it) { - it.setNewLines(3); - } - }; + private static final Procedure1 EMPTY_LINES = it -> it.setNewLines(3); - private static final Procedure1 INDENT = new Procedure1() { - @Override - public void apply(final IHiddenRegionFormatter it) { - it.indent(); - } - }; + private static final Procedure1 INDENT = it -> it.indent(); - private static final Procedure1 DOUBLE_INDENT = new Procedure1() { - @Override - public void apply(final IHiddenRegionFormatter it) { - it.indent(); - it.indent(); - } + private static final Procedure1 DOUBLE_INDENT = it -> { + it.indent(); + it.indent(); }; + /** Grammar. */ @Inject @Extension protected PooslGrammarAccess pooslGrammar; @@ -211,7 +176,8 @@ public ITextReplacer createCommentReplacer(IComment comment) { } @Override - public ITextReplacer createHiddenRegionReplacer(IHiddenRegion region, IHiddenRegionFormatting formatting) { + public ITextReplacer createHiddenRegionReplacer( + IHiddenRegion region, IHiddenRegionFormatting formatting) { return new PooslHiddenRegionReplacer(region, formatting); } @@ -248,7 +214,8 @@ private void format(Poosl poosl, IFormattableDocument document) { } private void format(Import imports, IFormattableDocument document) { - ISemanticRegion previousSemantic = textRegionExtensions.regionForEObject(imports).getPreviousSemanticRegion(); + ISemanticRegion previousSemantic = textRegionExtensions.regionForEObject(imports) + .getPreviousSemanticRegion(); if (previousSemantic != null) { document.prepend(imports, NEW_LINE); } @@ -261,7 +228,8 @@ private void format(ClusterClass cluster, IFormattableDocument document) { format(cluster.getAnnotations(), document); ClusterClassElements grammar = pooslGrammar.getClusterClassAccess(); - Procedure1 oneSpaceWrap = createOneSpaceWrapUpTo(regionFinder.keyword(KEYWORD_PORTS), INDENT); + Procedure1 oneSpaceWrap = createOneSpaceWrapUpTo( + regionFinder.keyword(KEYWORD_PORTS), INDENT); document.append(regionFinder.keyword(KEYWORD_CLUSTER), oneSpaceWrap); document.append(regionFinder.keyword(KEYWORD_CLASS), oneSpaceWrap); @@ -274,9 +242,11 @@ private void format(ClusterClass cluster, IFormattableDocument document) { commaSpacing(regionFinder, grammar.getCommaKeyword_6_1_0(), document); // ports commaSpacing(regionFinder, grammar.getCommaKeyword_6_2(), document); - List> brackets = regionFinder.keywordPairs(PAR_OPEN, PAR_CLOSE); + List> brackets = regionFinder.keywordPairs(PAR_OPEN, + PAR_CLOSE); if (!brackets.isEmpty()) { - formatBracketDeclarations(cluster.getParameters(), brackets.get(0), oneSpaceWrap, document); + formatBracketDeclarations(cluster.getParameters(), brackets.get(0), oneSpaceWrap, + document); } indentList(cluster.getPorts(), document); @@ -300,7 +270,8 @@ private void format(DataClass data, IFormattableDocument document) { topElementEmptyLine(data, document); ISemanticRegionsFinder regionFinder = textRegionExtensions.regionFor(data); format(data.getAnnotations(), document); - Procedure1 oneSpaceWrap = createOneSpaceWrapUpTo(regionFinder.keyword(KEYWORD_VARIABLES), INDENT); + Procedure1 oneSpaceWrap = createOneSpaceWrapUpTo( + regionFinder.keyword(KEYWORD_VARIABLES), INDENT); document.append(regionFinder.keyword(KEYWORD_DATA), oneSpaceWrap); document.append(regionFinder.keyword(KEYWORD_CLASS), oneSpaceWrap); @@ -325,11 +296,13 @@ private void format(DataClass data, IFormattableDocument document) { format(dataMethodsNamed, document, first == dataMethodsNamed); } - for (DataMethodUnaryOperator dataMethodsUnaryOperator : data.getDataMethodsUnaryOperator()) { + for (DataMethodUnaryOperator dataMethodsUnaryOperator : data + .getDataMethodsUnaryOperator()) { format(dataMethodsUnaryOperator, document, first == dataMethodsUnaryOperator); } - for (DataMethodBinaryOperator dataMethodsBinaryOperator : data.getDataMethodsBinaryOperator()) { + for (DataMethodBinaryOperator dataMethodsBinaryOperator : data + .getDataMethodsBinaryOperator()) { format(dataMethodsBinaryOperator, document, first == dataMethodsBinaryOperator); } } @@ -339,15 +312,18 @@ private void format(DataMethod dMethod, IFormattableDocument document, boolean f ISemanticRegionsFinder mRegionFinder = textRegionExtensions.regionFor(dMethod); format(dMethod.getAnnotations(), document); - Procedure1 oneSpaceWrap = (dMethod.getBody() == null) ? createOneSpaceWrapDouble(dMethod) : createOneSpaceUpTo(dMethod.getBody()); + Procedure1 oneSpaceWrap = (dMethod.getBody() == null) + ? createOneSpaceWrapDouble(dMethod) : createOneSpaceUpTo(dMethod.getBody()); bracketPairSpacing(mRegionFinder, document); commaSpacing(mRegionFinder, oneSpaceWrap, document); colonSpacing(mRegionFinder, document); - List> keywordPairs = mRegionFinder.keywordPairs(PAR_OPEN, PAR_CLOSE); + List> keywordPairs = mRegionFinder + .keywordPairs(PAR_OPEN, PAR_CLOSE); if (!keywordPairs.isEmpty()) { - formatBracketDeclarations(dMethod.getParameters(), keywordPairs.get(0), oneSpaceWrap, document); + formatBracketDeclarations(dMethod.getParameters(), keywordPairs.get(0), oneSpaceWrap, + document); } formatPipeDeclarations(dMethod.getLocalVariables(), mRegionFinder, oneSpaceWrap, document); @@ -362,7 +338,8 @@ private void format(ProcessClass process, IFormattableDocument document) { format(process.getAnnotations(), document); ProcessClassElements grammar = pooslGrammar.getProcessClassAccess(); - Procedure1 oneSpaceWrap = createOneSpaceWrapUpTo(regionFinder.keyword(KEYWORD_PORTS), INDENT); + Procedure1 oneSpaceWrap = createOneSpaceWrapUpTo( + regionFinder.keyword(KEYWORD_PORTS), INDENT); document.append(regionFinder.keyword("process"), oneSpaceWrap); //$NON-NLS-1$ document.append(regionFinder.keyword(KEYWORD_CLASS), oneSpaceWrap); @@ -377,12 +354,15 @@ private void format(ProcessClass process, IFormattableDocument document) { commaSpacing(regionFinder, grammar.getCommaKeyword_11_2(), document); formatExtend(regionFinder, oneSpaceWrap, document); - keywordsOnNewLine(process, document, KEYWORD_PORTS, "messages", KEYWORD_VARIABLES, "init", KEYWORD_METHODS); //$NON-NLS-1$ //$NON-NLS-2$ + keywordsOnNewLine(process, document, KEYWORD_PORTS, "messages", KEYWORD_VARIABLES, "init", //$NON-NLS-1$//$NON-NLS-2$ + KEYWORD_METHODS); - List> brackets = regionFinder.keywordPairs(PAR_OPEN, PAR_CLOSE); + List> brackets = regionFinder.keywordPairs(PAR_OPEN, + PAR_CLOSE); if (!brackets.isEmpty()) { document.prepend(brackets.get(0).getKey(), NO_SPACE); - formatBracketDeclarations(process.getParameters(), brackets.get(0), oneSpaceWrap, document); + formatBracketDeclarations(process.getParameters(), brackets.get(0), oneSpaceWrap, + document); } indentList(process.getPorts(), document); @@ -432,24 +412,31 @@ private void format(ProcessMethod method, IFormattableDocument document, boolean document.append(mRegionFinder.feature(Literals.PROCESS_METHOD__NAME), NO_SPACE); bracketPairSpacing(mRegionFinder, document); - Procedure1 oneSpaceWrapMethod = (method.getBody() == null) ? createOneSpaceWrapDouble(method) : createOneSpaceUpTo(method.getBody()); + Procedure1 oneSpaceWrapMethod = (method.getBody() == null) + ? createOneSpaceWrapDouble(method) : createOneSpaceUpTo(method.getBody()); commaSpacing(mRegionFinder, oneSpaceWrapMethod, document); - List> mBrackets = mRegionFinder.keywordPairs(PAR_OPEN, PAR_CLOSE); + List> mBrackets = mRegionFinder + .keywordPairs(PAR_OPEN, PAR_CLOSE); if (mBrackets.size() == 2) { document.append(mBrackets.get(0).getValue(), NO_SPACE); - formatBracketDeclarations(method.getInputParameters(), mBrackets.get(0), oneSpaceWrapMethod, document); - formatBracketDeclarations(method.getOutputParameters(), mBrackets.get(1), oneSpaceWrapMethod, document); + formatBracketDeclarations(method.getInputParameters(), mBrackets.get(0), + oneSpaceWrapMethod, document); + formatBracketDeclarations(method.getOutputParameters(), mBrackets.get(1), + oneSpaceWrapMethod, document); } - formatPipeDeclarations(method.getLocalVariables(), mRegionFinder, oneSpaceWrapMethod, document); + formatPipeDeclarations(method.getLocalVariables(), mRegionFinder, oneSpaceWrapMethod, + document); document.prepend(method.getBody(), NEW_LINE); indent(method.getBody(), document, false); format(method.getBody(), document, null, false); } - private void formatExtend(ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrap, IFormattableDocument document) { + private void formatExtend( + ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrap, + IFormattableDocument document) { ISemanticRegion kwExtend = regionFinder.keyword("extends"); //$NON-NLS-1$ if (kwExtend != null) { document.prepend(kwExtend, oneSpaceWrap); @@ -474,7 +461,8 @@ private void format(Instance instance, IFormattableDocument document) { commaSpacing(regionFinder, oneSpaceWrap, document); for (InstanceParameter instanceParameter : instance.getInstanceParameters()) { - document.append(textRegionExtensions.regionFor(instanceParameter).feature(Literals.INSTANCE_PARAMETER__PARAMETER), oneSpaceWrap); + document.append(textRegionExtensions.regionFor(instanceParameter) + .feature(Literals.INSTANCE_PARAMETER__PARAMETER), oneSpaceWrap); document.prepend(instanceParameter.getExpression(), oneSpaceWrap); format(instanceParameter.getExpression(), document, oneSpaceWrap, true); } @@ -497,7 +485,7 @@ private void format(Channel channel, IFormattableDocument document) { curlyBracketPairSpacing(regionFinder, document); Procedure1 oneSpaceWrap = createOneSpaceWrap(channel); - // TODO commaspacing needs to use oneSpaceWrap, atm causes an extra indent, + // XXX commaspacing needs to use oneSpaceWrap, atm causes an extra indent, // fixed in xtext 2.13 // https://esi-redmine.tno.nl/issues/2605 commaSpacing(regionFinder, oneSpaceWrap, document); @@ -507,20 +495,26 @@ private void format(Channel channel, IFormattableDocument document) { } } - private void format(Declaration declaration, Procedure1 oneSpaceWrapper, IFormattableDocument document) { + private void format( + Declaration declaration, Procedure1 oneSpaceWrapper, + IFormattableDocument document) { ISemanticRegionsFinder regionFinder = textRegionExtensions.regionFor(declaration); colonSpacing(regionFinder, document); commaSpacing(regionFinder, oneSpaceWrapper, document); } - private void formatNewLine(Declaration declaration, Procedure1 oneSpaceWrapper, IFormattableDocument document) { + private void formatNewLine( + Declaration declaration, Procedure1 oneSpaceWrapper, + IFormattableDocument document) { ISemanticRegionsFinder regionFinder = textRegionExtensions.regionFor(declaration); document.prepend(declaration, NEW_LINE); colonSpacing(regionFinder, document); commaSpacing(regionFinder, oneSpaceWrapper, document); } - private void format(Expression expression, IFormattableDocument document, Procedure1 oneSpaceWrapper, boolean singleLine) { + private void format( + Expression expression, IFormattableDocument document, + Procedure1 wrapper, boolean singleLine) { ISemanticRegionsFinder regionFinder = textRegionExtensions.regionFor(expression); if (expression instanceof ExpressionSequence) { EList expressions = ((ExpressionSequence) expression).getExpressions(); @@ -529,41 +523,53 @@ private void format(Expression expression, IFormattableDocument document, Proced } semiColonSpacing(regionFinder, document, singleLine); for (Expression expr : expressions) { - format(expr, document, oneSpaceWrapper, singleLine); + format(expr, document, wrapper, singleLine); } } else { - oneSpaceWrapper = (oneSpaceWrapper == null) ? createOneSpaceWrap(expression) : oneSpaceWrapper; + Procedure1 oneSpaceWrapper = (wrapper == null) + ? createOneSpaceWrap(expression) : wrapper; if (expression instanceof AssignmentExpression) { document.surround(regionFinder.keyword(":="), oneSpaceWrapper); //$NON-NLS-1$ - format(((AssignmentExpression) expression).getExpression(), document, oneSpaceWrapper, singleLine); + format(((AssignmentExpression) expression).getExpression(), document, + oneSpaceWrapper, singleLine); } else if (expression instanceof ReturnExpression) { document.append(regionFinder.keyword("return"), oneSpaceWrapper); //$NON-NLS-1$ - format(((ReturnExpression) expression).getExpression(), document, oneSpaceWrapper, singleLine); + format(((ReturnExpression) expression).getExpression(), document, oneSpaceWrapper, + singleLine); } else if (expression instanceof BinaryOperatorExpression) { - format((BinaryOperatorExpression) expression, document, oneSpaceWrapper, singleLine); + format((BinaryOperatorExpression) expression, document, oneSpaceWrapper, + singleLine); } else if (expression instanceof DataMethodCallExpression) { - format((DataMethodCallExpression) expression, document, regionFinder, oneSpaceWrapper, singleLine); + format((DataMethodCallExpression) expression, document, regionFinder, + oneSpaceWrapper, singleLine); } else if (expression instanceof UnaryOperatorExpression) { format((UnaryOperatorExpression) expression, document, oneSpaceWrapper, singleLine); } else if (expression instanceof IfExpression) { - format((IfExpression) expression, document, regionFinder, oneSpaceWrapper, singleLine); + format((IfExpression) expression, document, regionFinder, oneSpaceWrapper, + singleLine); } else if (expression instanceof WhileExpression) { - format((WhileExpression) expression, document, regionFinder, oneSpaceWrapper, singleLine); + format((WhileExpression) expression, document, regionFinder, oneSpaceWrapper, + singleLine); } else if (expression instanceof SwitchExpression) { - format((SwitchExpression) expression, document, regionFinder, oneSpaceWrapper, singleLine); + format((SwitchExpression) expression, document, regionFinder, oneSpaceWrapper, + singleLine); } else if (expression instanceof NewExpression) { format((NewExpression) expression, document, oneSpaceWrapper, regionFinder); } } } - private void format(IfExpression expression, IFormattableDocument document, ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, boolean singleLine) { + private void format( + IfExpression expression, IFormattableDocument document, + ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, + boolean singleLine) { document.append(regionFinder.keyword(KEYWORD_IF), ONE_SPACE_NO_WRAP); ISemanticRegion kwThen = regionFinder.keyword(KEYWORD_THEN); Procedure1 oneSpaceCondition = getOneSpaceWrapIncluding(kwThen); - Procedure1 lineFormat = getLineFormatting(singleLine, oneSpaceWrapper); + Procedure1 lineFormat = getLineFormatting(singleLine, + oneSpaceWrapper); document.prepend(kwThen, oneSpaceCondition); document.append(kwThen, lineFormat); @@ -591,13 +597,19 @@ private void format(IfExpression expression, IFormattableDocument document, ISem format(expression.getElseClause(), document, null, singleLine); } - private void format(SwitchExpression expression, IFormattableDocument document, ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, boolean singleLine) { + private void format( + SwitchExpression expression, IFormattableDocument document, + ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, + boolean singleLine) { document.append(regionFinder.keyword(KEYWORD_SWITCH), oneSpaceWrapper); - List> keywordPairs = regionFinder.keywordPairs(KEYWORD_DO, KEYWORD_OD); + List> keywordPairs = regionFinder + .keywordPairs(KEYWORD_DO, KEYWORD_OD); - Procedure1 oneSpaceWrapperCondition = getOneSpaceWrapIncluding(keywordPairs.isEmpty() ? null : keywordPairs.get(0).getKey()); + Procedure1 oneSpaceWrapperCondition = getOneSpaceWrapIncluding( + keywordPairs.isEmpty() ? null : keywordPairs.get(0).getKey()); - Procedure1 lineFormat = getLineFormatting(singleLine, oneSpaceWrapper); + Procedure1 lineFormat = getLineFormatting(singleLine, + oneSpaceWrapper); for (Pair pair : keywordPairs) { document.prepend(pair.getKey(), oneSpaceWrapperCondition); document.prepend(pair.getValue(), lineFormat); @@ -606,12 +618,14 @@ private void format(SwitchExpression expression, IFormattableDocument document, format(expression.getExpression(), document, oneSpaceWrapperCondition, singleLine); for (SwitchExpressionCase switchExpressionCase : expression.getCases()) { - ISemanticRegionsFinder cRegionFinder = textRegionExtensions.regionFor(switchExpressionCase); + ISemanticRegionsFinder cRegionFinder = textRegionExtensions + .regionFor(switchExpressionCase); ISemanticRegion kwCase = cRegionFinder.keyword("case"); //$NON-NLS-1$ document.prepend(kwCase, lineFormat); ISemanticRegion kwThen = cRegionFinder.keyword(KEYWORD_THEN); - Procedure1 oneSpaceCaseCondition = getOneSpaceWrapIncluding(kwThen); + Procedure1 oneSpaceCaseCondition = getOneSpaceWrapIncluding( + kwThen); document.append(kwCase, oneSpaceCaseCondition); document.prepend(kwThen, oneSpaceCaseCondition); @@ -630,21 +644,27 @@ private void format(SwitchExpression expression, IFormattableDocument document, format(expression.getDefaultBody(), document, null, singleLine); } - private void format(WhileExpression expression, IFormattableDocument document, ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, boolean singleLine) { + private void format( + WhileExpression expression, IFormattableDocument document, + ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, + boolean singleLine) { document.append(regionFinder.keyword("while"), oneSpaceWrapper); //$NON-NLS-1$ ISemanticRegion kwDo = regionFinder.keyword(KEYWORD_DO); Procedure1 oneSpaceWrapperCond = getOneSpaceWrapIncluding(kwDo); document.prepend(kwDo, oneSpaceWrapperCond); document.append(kwDo, getLineFormatting(singleLine, oneSpaceWrapper)); - document.prepend(regionFinder.keyword(KEYWORD_OD), getLineFormatting(singleLine, oneSpaceWrapper)); + document.prepend(regionFinder.keyword(KEYWORD_OD), + getLineFormatting(singleLine, oneSpaceWrapper)); format(expression.getCondition(), document, oneSpaceWrapperCond, singleLine); indent(expression.getBody(), document, singleLine); format(expression.getBody(), document, null, singleLine); } - private void format(DataMethodCallExpression expression, IFormattableDocument document, ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, + private void format( + DataMethodCallExpression expression, IFormattableDocument document, + ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, boolean singleLine) { methodCallBracketSpacing(regionFinder, document); commaSpacing(regionFinder, oneSpaceWrapper, document); @@ -660,7 +680,9 @@ private void format(DataMethodCallExpression expression, IFormattableDocument do format(expression.getTarget(), document, null, singleLine); } - private void format(BinaryOperatorExpression expression, IFormattableDocument document, Procedure1 oneSpaceWrapper, boolean singleLine) { + private void format( + BinaryOperatorExpression expression, IFormattableDocument document, + Procedure1 oneSpaceWrapper, boolean singleLine) { Expression left = expression.getLeftOperand(); Expression right = expression.getRightOperand(); @@ -670,13 +692,18 @@ private void format(BinaryOperatorExpression expression, IFormattableDocument do format(right, document, oneSpaceWrapper, singleLine); } - private void format(UnaryOperatorExpression expression, IFormattableDocument document, Procedure1 oneSpaceWrapper, boolean singleLine) { + private void format( + UnaryOperatorExpression expression, IFormattableDocument document, + Procedure1 oneSpaceWrapper, boolean singleLine) { Expression oper = expression.getOperand(); document.prepend(oper, NO_SPACE); format(oper, document, oneSpaceWrapper, singleLine); } - private void format(NewExpression expression, IFormattableDocument document, Procedure1 oneSpaceWrapper, ISemanticRegionsFinder regionFinder) { + private void format( + NewExpression expression, IFormattableDocument document, + Procedure1 oneSpaceWrapper, + ISemanticRegionsFinder regionFinder) { ISemanticRegion kwNew = regionFinder.keyword("new"); //$NON-NLS-1$ if (kwNew.immediatelyFollowing().keyword(PAR_OPEN) != null) { document.append(kwNew, NO_SPACE); @@ -685,72 +712,107 @@ private void format(NewExpression expression, IFormattableDocument document, Pro } } - private void format(Statement statement, IFormattableDocument document, Procedure1 oneSpaceWrapper, boolean singleLine) { + private void format( + Statement statement, IFormattableDocument document, + Procedure1 wrapper, boolean singleLine) { ISemanticRegionsFinder regionFinder = textRegionExtensions.regionFor(statement); if (statement instanceof StatementSequence) { - EList statements = ((StatementSequence) statement).getStatements(); - if (statement instanceof StatementSequenceRoundBracket) { - formatRoundBracketSequence(statements, document, regionFinder, singleLine); - } - - semiColonSpacing(regionFinder, document, singleLine); - for (Statement stat : statements) { - format(stat, document, oneSpaceWrapper, singleLine); - } + formatStatementSequence((StatementSequence) statement, document, wrapper, singleLine, + regionFinder); } else { - oneSpaceWrapper = (oneSpaceWrapper == null) ? createOneSpaceWrapDouble(statement) : oneSpaceWrapper; + Procedure1 oneSpaceWrapper = (wrapper == null) + ? createOneSpaceWrapDouble(statement) : wrapper; if (statement instanceof AbortStatement) { - format((AbortStatement) statement, document, regionFinder, oneSpaceWrapper, singleLine); + format((AbortStatement) statement, document, regionFinder, oneSpaceWrapper, + singleLine); } else if (statement instanceof DelayStatement) { ISemanticRegion kwDelay = regionFinder.keyword("delay"); //$NON-NLS-1$ document.append(kwDelay, oneSpaceWrapper); - format(((DelayStatement) statement).getExpression(), document, oneSpaceWrapper, singleLine); + format(((DelayStatement) statement).getExpression(), document, oneSpaceWrapper, + singleLine); } else if (statement instanceof GuardedStatement) { squareBracketSpacing(regionFinder, oneSpaceWrapper, document); - format(((GuardedStatement) statement).getGuard(), document, oneSpaceWrapper, singleLine); - format(((GuardedStatement) statement).getStatement(), document, oneSpaceWrapper, singleLine); + format(((GuardedStatement) statement).getGuard(), document, oneSpaceWrapper, + singleLine); + format(((GuardedStatement) statement).getStatement(), document, oneSpaceWrapper, + singleLine); } else if (statement instanceof InterruptStatement) { - format((InterruptStatement) statement, document, regionFinder, oneSpaceWrapper, singleLine); + format((InterruptStatement) statement, document, regionFinder, oneSpaceWrapper, + singleLine); } else if (statement instanceof ParStatement) { - format((ParStatement) statement, document, regionFinder, oneSpaceWrapper, singleLine); + format((ParStatement) statement, document, regionFinder, oneSpaceWrapper, + singleLine); } else if (statement instanceof ProcessMethodCall) { - format((ProcessMethodCall) statement, document, regionFinder, oneSpaceWrapper, singleLine); + format((ProcessMethodCall) statement, document, regionFinder, oneSpaceWrapper, + singleLine); } else if (statement instanceof SelStatement) { - format((SelStatement) statement, document, regionFinder, oneSpaceWrapper, singleLine); + format((SelStatement) statement, document, regionFinder, oneSpaceWrapper, + singleLine); } else if (statement instanceof SendStatement) { - format((SendStatement) statement, document, regionFinder, oneSpaceWrapper, singleLine); + format((SendStatement) statement, document, regionFinder, oneSpaceWrapper, + singleLine); } else if (statement instanceof ReceiveStatement) { - format((ReceiveStatement) statement, document, regionFinder, oneSpaceWrapper, singleLine); + format((ReceiveStatement) statement, document, regionFinder, oneSpaceWrapper, + singleLine); } else if (statement instanceof IfStatement) { - format((IfStatement) statement, document, regionFinder, oneSpaceWrapper, singleLine); + format((IfStatement) statement, document, regionFinder, oneSpaceWrapper, + singleLine); } else if (statement instanceof WhileStatement) { - format((WhileStatement) statement, document, regionFinder, oneSpaceWrapper, singleLine); + format((WhileStatement) statement, document, regionFinder, oneSpaceWrapper, + singleLine); } else if (statement instanceof SwitchStatement) { - format((SwitchStatement) statement, document, regionFinder, oneSpaceWrapper, singleLine); + format((SwitchStatement) statement, document, regionFinder, oneSpaceWrapper, + singleLine); } else if (statement instanceof ExpressionStatement) { - formatCurlyBracketsMultiOrSingle(((ExpressionStatement) statement).getExpression(), document, regionFinder, singleLine, oneSpaceWrapper, false); + formatCurlyBracketsMultiOrSingle(((ExpressionStatement) statement).getExpression(), + document, regionFinder, singleLine, oneSpaceWrapper, false); } } } - private void format(WhileStatement statement, IFormattableDocument document, ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, boolean singleLine) { + private void formatStatementSequence( + StatementSequence statement, IFormattableDocument document, + Procedure1 wrapper, boolean singleLine, + ISemanticRegionsFinder regionFinder) { + EList statements = statement.getStatements(); + if (statement instanceof StatementSequenceRoundBracket) { + formatRoundBracketSequence(statements, document, regionFinder, singleLine); + } + + semiColonSpacing(regionFinder, document, singleLine); + for (Statement stat : statements) { + format(stat, document, wrapper, singleLine); + } + } + + private void format( + WhileStatement statement, IFormattableDocument document, + ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, + boolean singleLine) { ISemanticRegion kwDo = regionFinder.keyword(KEYWORD_DO); - Procedure1 oneSpaceWrapperCondition = getOneSpaceWrapIncluding(kwDo); + Procedure1 oneSpaceWrapperCondition = getOneSpaceWrapIncluding( + kwDo); document.prepend(kwDo, oneSpaceWrapperCondition); document.append(kwDo, getLineFormatting(singleLine, oneSpaceWrapper)); - document.prepend(regionFinder.keyword(KEYWORD_OD), getLineFormatting(singleLine, oneSpaceWrapper)); + document.prepend(regionFinder.keyword(KEYWORD_OD), + getLineFormatting(singleLine, oneSpaceWrapper)); format(statement.getCondition(), document, oneSpaceWrapperCondition, singleLine); indent(statement.getBody(), document, singleLine); format(statement.getBody(), document, null, singleLine); } - private void format(IfStatement statement, IFormattableDocument document, ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, boolean singleLine) { + private void format( + IfStatement statement, IFormattableDocument document, + ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, + boolean singleLine) { ISemanticRegion kwThen = regionFinder.keyword(KEYWORD_THEN); - Procedure1 oneSpaceWrapperCondition = getOneSpaceWrapIncluding(kwThen); + Procedure1 oneSpaceWrapperCondition = getOneSpaceWrapIncluding( + kwThen); - Procedure1 lineFormat = getLineFormatting(singleLine, oneSpaceWrapper); + Procedure1 lineFormat = getLineFormatting(singleLine, + oneSpaceWrapper); document.prepend(kwThen, oneSpaceWrapperCondition); document.append(kwThen, lineFormat); ISemanticRegion kwElse = regionFinder.keyword(KEYWORD_ELSE); @@ -777,13 +839,19 @@ private void format(IfStatement statement, IFormattableDocument document, ISeman format(statement.getThenClause(), document, null, singleLine); } - private void format(SwitchStatement statement, IFormattableDocument document, ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, boolean singleLine) { + private void format( + SwitchStatement statement, IFormattableDocument document, + ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, + boolean singleLine) { document.append(regionFinder.keyword(KEYWORD_SWITCH), oneSpaceWrapper); - List> keywordPairs = regionFinder.keywordPairs(KEYWORD_DO, KEYWORD_OD); + List> keywordPairs = regionFinder + .keywordPairs(KEYWORD_DO, KEYWORD_OD); - Procedure1 oneSpaceWrapCondition = getOneSpaceWrapIncluding(keywordPairs.isEmpty() ? null : keywordPairs.get(0).getKey()); + Procedure1 oneSpaceWrapCondition = getOneSpaceWrapIncluding( + keywordPairs.isEmpty() ? null : keywordPairs.get(0).getKey()); - Procedure1 lineFormat = getLineFormatting(singleLine, oneSpaceWrapper); + Procedure1 lineFormat = getLineFormatting(singleLine, + oneSpaceWrapper); for (Pair pair : keywordPairs) { document.prepend(pair.getKey(), oneSpaceWrapCondition); document.prepend(pair.getValue(), lineFormat); @@ -792,12 +860,14 @@ private void format(SwitchStatement statement, IFormattableDocument document, IS format(statement.getExpression(), document, oneSpaceWrapCondition, singleLine); for (SwitchStatementCase switchExpressionCase : statement.getCases()) { - ISemanticRegionsFinder cRegionFinder = textRegionExtensions.regionFor(switchExpressionCase); + ISemanticRegionsFinder cRegionFinder = textRegionExtensions + .regionFor(switchExpressionCase); ISemanticRegion kwCase = cRegionFinder.keyword("case"); //$NON-NLS-1$ document.prepend(kwCase, lineFormat); ISemanticRegion kwThen = cRegionFinder.keyword(KEYWORD_THEN); - Procedure1 oneSpaceCaseCondition = getOneSpaceWrapIncluding(kwThen); + Procedure1 oneSpaceCaseCondition = getOneSpaceWrapIncluding( + kwThen); document.append(kwCase, oneSpaceCaseCondition); document.prepend(kwThen, oneSpaceCaseCondition); @@ -815,8 +885,12 @@ private void format(SwitchStatement statement, IFormattableDocument document, IS format(statement.getDefaultBody(), document, null, singleLine); } - private void format(ParStatement statement, IFormattableDocument document, ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, boolean singleLine) { - Procedure1 lineFormat = getLineFormatting(singleLine, oneSpaceWrapper); + private void format( + ParStatement statement, IFormattableDocument document, + ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, + boolean singleLine) { + Procedure1 lineFormat = getLineFormatting(singleLine, + oneSpaceWrapper); document.append(regionFinder.keyword("par"), lineFormat); //$NON-NLS-1$ for (ISemanticRegion iSemanticRegion : regionFinder.keywords("and")) { //$NON-NLS-1$ document.prepend(iSemanticRegion, lineFormat); @@ -830,9 +904,13 @@ private void format(ParStatement statement, IFormattableDocument document, ISema } } - private void format(SelStatement statement, IFormattableDocument document, ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, boolean singleLine) { + private void format( + SelStatement statement, IFormattableDocument document, + ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, + boolean singleLine) { document.append(regionFinder.keyword("sel"), NEW_LINE); //$NON-NLS-1$ - Procedure1 lineFormat = getLineFormatting(singleLine, oneSpaceWrapper); + Procedure1 lineFormat = getLineFormatting(singleLine, + oneSpaceWrapper); for (ISemanticRegion iSemanticRegion : regionFinder.keywords("or")) { //$NON-NLS-1$ document.prepend(iSemanticRegion, lineFormat); document.append(iSemanticRegion, lineFormat); @@ -845,17 +923,29 @@ private void format(SelStatement statement, IFormattableDocument document, ISema } } - private void format(AbortStatement statement, IFormattableDocument document, ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, boolean singleLine) { - document.append(regionFinder.keyword("abort"), getLineFormatting(singleLine, oneSpaceWrapper)); //$NON-NLS-1$ - formatStatementWith(statement.getNormalClause(), statement.getAbortingClause(), document, regionFinder, oneSpaceWrapper, singleLine); + private void format( + AbortStatement statement, IFormattableDocument document, + ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, + boolean singleLine) { + document.append(regionFinder.keyword("abort"), //$NON-NLS-1$ + getLineFormatting(singleLine, oneSpaceWrapper)); + formatStatementWith(statement.getNormalClause(), statement.getAbortingClause(), document, + regionFinder, oneSpaceWrapper, singleLine); } - private void format(InterruptStatement statement, IFormattableDocument document, ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, boolean singleLine) { - document.append(regionFinder.keyword("interrupt"), getLineFormatting(singleLine, oneSpaceWrapper)); //$NON-NLS-1$ - formatStatementWith(statement.getNormalClause(), statement.getInterruptingClause(), document, regionFinder, oneSpaceWrapper, singleLine); + private void format( + InterruptStatement statement, IFormattableDocument document, + ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, + boolean singleLine) { + document.append(regionFinder.keyword("interrupt"), //$NON-NLS-1$ + getLineFormatting(singleLine, oneSpaceWrapper)); + formatStatementWith(statement.getNormalClause(), statement.getInterruptingClause(), + document, regionFinder, oneSpaceWrapper, singleLine); } - private void formatStatementWith(Statement normal, Statement with, IFormattableDocument document, ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, + private void formatStatementWith( + Statement normal, Statement with, IFormattableDocument document, + ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, boolean singleLine) { ISemanticRegion kwWith = regionFinder.keyword("with"); //$NON-NLS-1$ document.prepend(kwWith, getLineFormatting(singleLine, oneSpaceWrapper)); @@ -866,27 +956,37 @@ private void formatStatementWith(Statement normal, Statement with, IFormattableD format(with, document, null, singleLine); } - private void format(SendStatement statement, IFormattableDocument document, ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, boolean singleLine) { + private void format( + SendStatement statement, IFormattableDocument document, + ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, + boolean singleLine) { document.append(regionFinder.feature(Literals.SEND_STATEMENT__NAME), NO_SPACE); bracketPairSpacing(regionFinder, document); commaSpacing(regionFinder, oneSpaceWrapper, document); exclamationSpacing(regionFinder, document); - formatCurlyBracketsMultiOrSingle(statement.getPostCommunicationExpression(), document, regionFinder, singleLine, oneSpaceWrapper, true); + formatCurlyBracketsMultiOrSingle(statement.getPostCommunicationExpression(), document, + regionFinder, singleLine, oneSpaceWrapper, true); for (Expression expression : statement.getArguments()) { format(expression, document, null, true); } } - private void format(ReceiveStatement statement, IFormattableDocument document, ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, boolean singleLine) { + private void format( + ReceiveStatement statement, IFormattableDocument document, + ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, + boolean singleLine) { bracketPairSpacing(regionFinder, document); commaSpacing(regionFinder, oneSpaceWrapper, document); questionMarkSpacing(regionFinder, document); - formatCurlyBracketsMultiOrSingle(statement.getPostCommunicationExpression(), document, regionFinder, singleLine, oneSpaceWrapper, true); + formatCurlyBracketsMultiOrSingle(statement.getPostCommunicationExpression(), document, + regionFinder, singleLine, oneSpaceWrapper, true); format(statement.getReceptionCondition(), document, null, true); } - private void format(ProcessMethodCall processMethodCall, IFormattableDocument document, ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, + private void format( + ProcessMethodCall processMethodCall, IFormattableDocument document, + ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, boolean singleLine) { methodCallBracketSpacing(regionFinder, document); for (Expression expression : processMethodCall.getInputArguments()) { @@ -899,7 +999,8 @@ private void format(EList annotations, IFormattableDocument document document.append(annotation, NEW_LINE); ISemanticRegionsFinder regionFinder = textRegionExtensions.regionFor(annotation); - ISemanticRegion annotationName = regionFinder.assignment(pooslGrammar.getAnnotationAccess().getNameAssignment_1()); + ISemanticRegion annotationName = regionFinder + .assignment(pooslGrammar.getAnnotationAccess().getNameAssignment_1()); document.surround(annotationName, NO_SPACE); formatRoundBracketSequence(annotation.getArguments(), document, regionFinder, true); @@ -907,22 +1008,27 @@ private void format(EList annotations, IFormattableDocument document } } - private void formatRoundBracketSequence(EList list, IFormattableDocument document, ISemanticRegionsFinder regionFinder, Boolean singleLine) { - List> brackets = regionFinder.keywordPairs(PAR_OPEN, PAR_CLOSE); - singleLine |= list.size() < 2; - formatBracketsSingleOrMulti(singleLine, document, brackets); + private void formatRoundBracketSequence( + EList list, IFormattableDocument document, + ISemanticRegionsFinder regionFinder, boolean singleLine) { + List> brackets = regionFinder.keywordPairs(PAR_OPEN, + PAR_CLOSE); + formatBracketsSingleOrMulti(singleLine || list.size() < 2, document, brackets); } - private void formatCurlyBracketsMultiOrSingle(Expression expression, IFormattableDocument document, ISemanticRegionsFinder regionFinder, boolean singleLine, + private void formatCurlyBracketsMultiOrSingle( + Expression expression, IFormattableDocument document, + ISemanticRegionsFinder regionFinder, boolean singleLine, Procedure1 oneSpaceWrapper, boolean prependSpace) { if (expression != null) { - List> brackets = regionFinder.keywordPairs("{", "}"); //$NON-NLS-1$ //$NON-NLS-2$ + List> brackets = regionFinder.keywordPairs("{", //$NON-NLS-1$ + "}"); //$NON-NLS-1$ if (prependSpace && !brackets.isEmpty()) { document.prepend(brackets.get(0).getKey(), oneSpaceWrapper); } - singleLine |= !isMultiLine(expression); - formatBracketsSingleOrMulti(singleLine, document, brackets); - format(expression, document, null, singleLine); + boolean single = singleLine || !isMultiLine(expression); + formatBracketsSingleOrMulti(single, document, brackets); + format(expression, document, null, single); } } @@ -942,11 +1048,22 @@ private boolean isMultiLine(Expression expression) { } private boolean allowOnSingleLine(Expression expression) { - return expression instanceof BooleanConstant || expression instanceof EnvironmentConstant || expression instanceof FloatConstant || expression instanceof IntegerConstant - || expression instanceof NilConstant || expression instanceof RealConstant || expression instanceof StringConstant; - } - - private void formatBracketsSingleOrMulti(boolean singleLine, IFormattableDocument document, List> brackets) { + // CHECKSTYLE.OFF: BooleanExpressionComplexity + // @formatter:off + return expression instanceof BooleanConstant + || expression instanceof EnvironmentConstant + || expression instanceof FloatConstant + || expression instanceof IntegerConstant + || expression instanceof NilConstant + || expression instanceof RealConstant + || expression instanceof StringConstant; + // @formatter:on + // CHECKSTYLE.ON + } + + private void formatBracketsSingleOrMulti( + boolean singleLine, IFormattableDocument document, + List> brackets) { if (!brackets.isEmpty()) { Pair pair = brackets.get(0); if (singleLine) { @@ -963,10 +1080,12 @@ private void formatBracketsSingleOrMulti(boolean singleLine, IFormattableDocumen // --- Text region helper functions ------- private void topElementEmptyLine(EObject object, IFormattableDocument document) { - ISemanticRegion previousSemantic = textRegionExtensions.regionForEObject(object).getPreviousSemanticRegion(); + ISemanticRegion previousSemantic = textRegionExtensions.regionForEObject(object) + .getPreviousSemanticRegion(); if (previousSemantic != null) { EObject element = previousSemantic.getSemanticElement(); - if (element instanceof ProcessClass || element instanceof ClusterClass || element instanceof DataClass) { + if (element instanceof ProcessClass || element instanceof ClusterClass + || element instanceof DataClass) { // previous object is a keyword, add extra emptyLine document.prepend(object, EMPTY_LINES); } else { @@ -987,16 +1106,21 @@ private void indentList(EList objects, IFormattableDocument d } /** - * Indenting multiple lists containing EObjects that syntactically can be in between each other and behave as one - * list. Finds which EObject in the lists is actually the first or last based on its offset in the document and - * indents based on that info. It doesn't have to iterate through the lists it only needs the first and last of the - * list as they are also the first and last in the document. (Example: send and receive messages) + * Indenting multiple lists containing EObjects that syntactically can be in + * between each other and behave as one + * list. Finds which EObject in the lists is actually the first or last + * based on its offset in the document and + * indents based on that info. It doesn't have to iterate through the lists + * it only needs the first and last of the + * list as they are also the first and last in the document. (Example: send + * and receive messages) * * @param document * @param lists * @return can return null if the lists */ - private EObject indentLists(IFormattableDocument document, List> lists) { + private EObject indentLists( + IFormattableDocument document, List> lists) { EObject first = null; EObject last = null; int firstOffset = -1; @@ -1065,10 +1189,13 @@ private void keywordsOnNewLine(EObject obj, IFormattableDocument document, Strin } } - private void formatPipeDeclarations(EList declarations, ISemanticRegionsFinder mRegionFinder, Procedure1 oneSpaceWrap, IFormattableDocument document) { + private void formatPipeDeclarations( + EList declarations, ISemanticRegionsFinder mRegionFinder, + Procedure1 oneSpaceWrap, IFormattableDocument document) { List pipes = mRegionFinder.keywords("|"); //$NON-NLS-1$ if (pipes.size() == 2) { - if (formatMutlilineDeclarations(pipes.get(0), pipes.get(1), declarations, oneSpaceWrap, document)) { + if (formatMutlilineDeclarations(pipes.get(0), pipes.get(1), declarations, oneSpaceWrap, + document)) { document.prepend(pipes.get(0), oneSpaceWrap); document.prepend(pipes.get(1), ONE_SPACE_NO_WRAP); } else { @@ -1079,9 +1206,11 @@ private void formatPipeDeclarations(EList declarations, ISemanticRe } } - private void formatBracketDeclarations(EList declarations, Pair pair, Procedure1 oneSpaceWrap, - IFormattableDocument document) { - if (formatMutlilineDeclarations(pair.getKey(), pair.getValue(), declarations, oneSpaceWrap, document)) { + private void formatBracketDeclarations( + EList declarations, Pair pair, + Procedure1 oneSpaceWrap, IFormattableDocument document) { + if (formatMutlilineDeclarations(pair.getKey(), pair.getValue(), declarations, oneSpaceWrap, + document)) { document.prepend(pair.getValue(), NO_SPACE); } else { document.append(pair.getKey(), NO_SPACE); @@ -1099,8 +1228,9 @@ private void formatBracketDeclarations(EList declarations, Pair declarations, Procedure1 oneSpaceWrap, - IFormattableDocument document) { + private boolean formatMutlilineDeclarations( + ISemanticRegion fromRegion, ISemanticRegion toRegion, EList declarations, + Procedure1 oneSpaceWrap, IFormattableDocument document) { if (!declarations.isEmpty()) { IEObjectRegion firstLocal = textRegionExtensions.regionForEObject(declarations.get(0)); IHiddenRegion s = firstLocal.getPreviousHiddenRegion(); @@ -1124,27 +1254,32 @@ private boolean formatMutlilineDeclarations(ISemanticRegion fromRegion, ISemanti return false; } - private Procedure1 getLineFormatting(boolean singleLine, Procedure1 oneSpaceWrap) { + private Procedure1 getLineFormatting( + boolean singleLine, Procedure1 oneSpaceWrap) { return singleLine ? oneSpaceWrap : NEW_LINE; } // --- Static helper functions ------- - private static void questionMarkSpacing(ISemanticRegionsFinder regionFinder, IFormattableDocument document) { + private static void questionMarkSpacing( + ISemanticRegionsFinder regionFinder, IFormattableDocument document) { for (ISemanticRegion iSemanticRegion : regionFinder.keywords("?")) { //$NON-NLS-1$ document.surround(iSemanticRegion, NO_SPACE); } } - private static void bracketPairSpacing(ISemanticRegionsFinder regionFinder, IFormattableDocument document) { - for (Pair pair : regionFinder.keywordPairs(PAR_OPEN, PAR_CLOSE)) { + private static void bracketPairSpacing( + ISemanticRegionsFinder regionFinder, IFormattableDocument document) { + for (Pair pair : regionFinder.keywordPairs(PAR_OPEN, + PAR_CLOSE)) { document.prepend(pair.getKey(), NO_SPACE); document.append(pair.getKey(), NO_SPACE); document.prepend(pair.getValue(), NO_SPACE); } } - private static void curlyBracketPairSpacing(ISemanticRegionsFinder regionFinder, IFormattableDocument document) { + private static void curlyBracketPairSpacing( + ISemanticRegionsFinder regionFinder, IFormattableDocument document) { for (Pair pair : regionFinder.keywordPairs("{", "}")) { //$NON-NLS-1$ //$NON-NLS-2$ document.prepend(pair.getKey(), NO_SPACE); document.append(pair.getKey(), ONE_SPACE_NO_WRAP); @@ -1153,40 +1288,53 @@ private static void curlyBracketPairSpacing(ISemanticRegionsFinder regionFinder, } } - private static void squareBracketSpacing(ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrap, IFormattableDocument document) { + private static void squareBracketSpacing( + ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrap, + IFormattableDocument document) { for (Pair pair : regionFinder.keywordPairs("[", "]")) { //$NON-NLS-1$ //$NON-NLS-2$ document.append(pair.getValue(), oneSpaceWrap); } } - private static void methodCallBracketSpacing(ISemanticRegionsFinder regionFinder, IFormattableDocument document) { - for (Pair pair : regionFinder.keywordPairs(PAR_OPEN, PAR_CLOSE)) { + private static void methodCallBracketSpacing( + ISemanticRegionsFinder regionFinder, IFormattableDocument document) { + for (Pair pair : regionFinder.keywordPairs(PAR_OPEN, + PAR_CLOSE)) { document.surround(pair.getKey(), NO_SPACE); document.prepend(pair.getValue(), NO_SPACE); } } - private static void commaSpacing(ISemanticRegionsFinder regionFinder, Procedure1 oneSpaceWrapper, IFormattableDocument document) { + private static void commaSpacing( + ISemanticRegionsFinder regionFinder, + Procedure1 oneSpaceWrapper, + IFormattableDocument document) { for (ISemanticRegion iSemanticRegion : regionFinder.keywords(",")) { //$NON-NLS-1$ document.prepend(iSemanticRegion, NO_SPACE); document.append(iSemanticRegion, oneSpaceWrapper); } } - private static void commaSpacing(ISemanticRegionsFinder regionFinder, Keyword comma, Procedure1 oneSpaceWrapper, IFormattableDocument document) { + private static void commaSpacing( + ISemanticRegionsFinder regionFinder, Keyword comma, + Procedure1 oneSpaceWrapper, + IFormattableDocument document) { for (ISemanticRegion iSemanticRegion : regionFinder.keywords(comma)) { document.prepend(iSemanticRegion, NO_SPACE); document.append(iSemanticRegion, oneSpaceWrapper); } } - private static void commaSpacing(ISemanticRegionsFinder regionFinder, Keyword comma, IFormattableDocument document) { + private static void commaSpacing( + ISemanticRegionsFinder regionFinder, Keyword comma, IFormattableDocument document) { for (ISemanticRegion iSemanticRegion : regionFinder.keywords(comma)) { document.prepend(iSemanticRegion, NO_SPACE); } } - private static void semiColonSpacing(ISemanticRegionsFinder regionFinder, IFormattableDocument document, boolean singleLine) { + private static void semiColonSpacing( + ISemanticRegionsFinder regionFinder, IFormattableDocument document, + boolean singleLine) { for (ISemanticRegion iSemanticRegion : regionFinder.keywords(";")) { //$NON-NLS-1$ document.prepend(iSemanticRegion, NO_SPACE); if (singleLine) { @@ -1197,41 +1345,51 @@ private static void semiColonSpacing(ISemanticRegionsFinder regionFinder, IForma } } - private static void periodSpacing(ISemanticRegionsFinder regionFinder, IFormattableDocument document) { + private static void periodSpacing( + ISemanticRegionsFinder regionFinder, IFormattableDocument document) { for (ISemanticRegion iSemanticRegion : regionFinder.keywords(".")) { //$NON-NLS-1$ document.surround(iSemanticRegion, NO_SPACE); } } - private static void exclamationSpacing(ISemanticRegionsFinder regionFinder, IFormattableDocument document) { + private static void exclamationSpacing( + ISemanticRegionsFinder regionFinder, IFormattableDocument document) { for (ISemanticRegion iSemanticRegion : regionFinder.keywords("!")) { //$NON-NLS-1$ document.surround(iSemanticRegion, NO_SPACE); } } - private static void colonSpacing(ISemanticRegionsFinder regionFinder, IFormattableDocument document) { + private static void colonSpacing( + ISemanticRegionsFinder regionFinder, IFormattableDocument document) { for (ISemanticRegion iSemanticRegion : regionFinder.keywords(":")) { //$NON-NLS-1$ document.surround(iSemanticRegion, ONE_SPACE_NO_WRAP); } } private Procedure1 createOneSpaceWrap(EObject semanticElement) { - return (semanticElement == null) ? ONE_SPACE : getOneSpaceWrapper(textRegionExtensions.nextHiddenRegion(semanticElement), INDENT); + return (semanticElement == null) + ? ONE_SPACE + : getOneSpaceWrapper(textRegionExtensions.nextHiddenRegion(semanticElement), INDENT); } private Procedure1 createOneSpaceUpTo(EObject semanticElement) { - return (semanticElement == null) ? ONE_SPACE : getOneSpaceWrapper(textRegionExtensions.previousHiddenRegion(semanticElement), DOUBLE_INDENT); + return (semanticElement == null) + ? ONE_SPACE : getOneSpaceWrapper( + textRegionExtensions.previousHiddenRegion(semanticElement), DOUBLE_INDENT); } private Procedure1 createOneSpaceWrapDouble(EObject semanticElement) { - return (semanticElement == null) ? ONE_SPACE : getOneSpaceWrapper(textRegionExtensions.nextHiddenRegion(semanticElement), DOUBLE_INDENT); + return (semanticElement == null) + ? ONE_SPACE : getOneSpaceWrapper(textRegionExtensions.nextHiddenRegion(semanticElement), + DOUBLE_INDENT); } private Procedure1 getOneSpaceWrapIncluding(ISemanticRegion region) { return getOneSpaceWrapIncluding(region, DOUBLE_INDENT); } - private Procedure1 getOneSpaceWrapIncluding(ISemanticRegion region, Procedure1 proc) { + private Procedure1 getOneSpaceWrapIncluding( + ISemanticRegion region, Procedure1 proc) { if (region != null) { ISemanticRegion nextSem = region.getNextSemanticRegion(); if (nextSem != null) { @@ -1241,14 +1399,16 @@ private Procedure1 getOneSpaceWrapIncluding(ISemanticReg return ONE_SPACE; } - private Procedure1 createOneSpaceWrapUpTo(ISemanticRegion region, Procedure1 proc) { + private Procedure1 createOneSpaceWrapUpTo( + ISemanticRegion region, Procedure1 proc) { if (region != null) { return getOneSpaceWrapper(region.getPreviousHiddenRegion(), proc); } return ONE_SPACE; } - private Procedure1 getOneSpaceWrapper(final IHiddenRegion last, Procedure1 proc) { + private Procedure1 getOneSpaceWrapper( + final IHiddenRegion last, Procedure1 proc) { final PooslAutoWrapper wrapper = new PooslAutoWrapper(last, proc); return new Procedure1() { @Override