Skip to content

Commit c6761fe

Browse files
committed
Layered: Fixed NPE in polyline and spline edge routers. #587
Signed-off-by: le-cds <zephanya@web.de> (cherry picked from commit 8d8470a)
1 parent ef05733 commit c6761fe

File tree

3 files changed

+86
-28
lines changed

3 files changed

+86
-28
lines changed

plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/PolylineEdgeRouter.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2010, 2015 Kiel University and others.
2+
* Copyright (c) 2010, 2020 Kiel University and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -76,9 +76,11 @@ public boolean apply(final LNode node) {
7676
* - LABEL_DUMMY_INSERTER
7777
*
7878
* Before phase 3:
79+
* - Always:
80+
* - INVERTED_PORT_PROCESSOR
81+
*
7982
* - For non-free ports:
8083
* - NORTH_SOUTH_PORT_PREPROCESSOR
81-
* - INVERTED_PORT_PROCESSOR
8284
*
8385
* - For edge labels:
8486
* - LABEL_SIDE_SELECTOR
@@ -107,8 +109,8 @@ public boolean apply(final LNode node) {
107109
* - END_LABEL_POSTPROCESSOR
108110
*/
109111

110-
/** additional processor dependencies for graphs with possible inverted ports. */
111-
private static final LayoutProcessorConfiguration<LayeredPhases, LGraph> INVERTED_PORT_PROCESSING_ADDITIONS =
112+
/** baseline config. */
113+
private static final LayoutProcessorConfiguration<LayeredPhases, LGraph> BASELINE_PROCESSOR_CONFIGURATION =
112114
LayoutProcessorConfiguration.<LayeredPhases, LGraph>create()
113115
.addBefore(LayeredPhases.P3_NODE_ORDERING, IntermediateProcessorStrategy.INVERTED_PORT_PROCESSOR);
114116

@@ -149,18 +151,13 @@ public LayoutProcessorConfiguration<LayeredPhases, LGraph> getLayoutProcessorCon
149151

150152
// Basic configuration
151153
LayoutProcessorConfiguration<LayeredPhases, LGraph> configuration =
152-
LayoutProcessorConfiguration.<LayeredPhases, LGraph>create();
154+
LayoutProcessorConfiguration.createFrom(BASELINE_PROCESSOR_CONFIGURATION);
153155

154156
// Additional dependencies
155-
if (graphProperties.contains(GraphProperties.NON_FREE_PORTS)
156-
|| graph.getProperty(LayeredOptions.FEEDBACK_EDGES)) {
157-
158-
configuration.addAll(INVERTED_PORT_PROCESSING_ADDITIONS);
159-
160-
if (graphProperties.contains(GraphProperties.NORTH_SOUTH_PORTS)) {
161-
configuration.addAll(NORTH_SOUTH_PORT_PROCESSING_ADDITIONS);
162-
}
157+
if (graphProperties.contains(GraphProperties.NORTH_SOUTH_PORTS)) {
158+
configuration.addAll(NORTH_SOUTH_PORT_PROCESSING_ADDITIONS);
163159
}
160+
164161
if (graphProperties.contains(GraphProperties.SELF_LOOPS)) {
165162
configuration.addAll(SELF_LOOP_PROCESSING_ADDITIONS);
166163
}

plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/p5edges/splines/SplineEdgeRouter.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2010, 2018 Kiel University and others.
2+
* Copyright (c) 2010, 2020 Kiel University and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -84,7 +84,8 @@ public final class SplineEdgeRouter implements ILayoutPhase<LayeredPhases, LGrap
8484
private static final LayoutProcessorConfiguration<LayeredPhases, LGraph> BASELINE_PROCESSING_ADDITIONS =
8585
LayoutProcessorConfiguration.<LayeredPhases, LGraph>create()
8686
.addAfter(LayeredPhases.P5_EDGE_ROUTING,
87-
IntermediateProcessorStrategy.FINAL_SPLINE_BENDPOINTS_CALCULATOR);
87+
IntermediateProcessorStrategy.FINAL_SPLINE_BENDPOINTS_CALCULATOR)
88+
.addBefore(LayeredPhases.P3_NODE_ORDERING, IntermediateProcessorStrategy.INVERTED_PORT_PROCESSOR);
8889

8990
/** additional processor dependencies for graphs with self-loops. */
9091
private static final LayoutProcessorConfiguration<LayeredPhases, LGraph> SELF_LOOP_PROCESSING_ADDITIONS =
@@ -103,11 +104,6 @@ public final class SplineEdgeRouter implements ILayoutPhase<LayeredPhases, LGrap
103104
.addBefore(LayeredPhases.P4_NODE_PLACEMENT, IntermediateProcessorStrategy.LABEL_SIDE_SELECTOR)
104105
.addAfter(LayeredPhases.P5_EDGE_ROUTING, IntermediateProcessorStrategy.LABEL_DUMMY_REMOVER);
105106

106-
/** additional processor dependencies for graphs with possible inverted ports. */
107-
private static final LayoutProcessorConfiguration<LayeredPhases, LGraph> INVERTED_PORT_PROCESSING_ADDITIONS =
108-
LayoutProcessorConfiguration.<LayeredPhases, LGraph>create()
109-
.addBefore(LayeredPhases.P3_NODE_ORDERING, IntermediateProcessorStrategy.INVERTED_PORT_PROCESSOR);
110-
111107
/** additional processor dependencies for graphs with northern / southern non-free ports. */
112108
private static final LayoutProcessorConfiguration<LayeredPhases, LGraph> NORTH_SOUTH_PORT_PROCESSING_ADDITIONS =
113109
LayoutProcessorConfiguration.<LayeredPhases, LGraph>create()
@@ -140,14 +136,8 @@ public LayoutProcessorConfiguration<LayeredPhases, LGraph> getLayoutProcessorCon
140136
configuration.addAll(CENTER_EDGE_LABEL_PROCESSING_ADDITIONS);
141137
}
142138

143-
if (graphProperties.contains(GraphProperties.NON_FREE_PORTS)
144-
|| graph.getProperty(LayeredOptions.FEEDBACK_EDGES)) {
145-
146-
configuration.addAll(INVERTED_PORT_PROCESSING_ADDITIONS);
147-
148-
if (graphProperties.contains(GraphProperties.NORTH_SOUTH_PORTS)) {
149-
configuration.addAll(NORTH_SOUTH_PORT_PROCESSING_ADDITIONS);
150-
}
139+
if (graphProperties.contains(GraphProperties.NORTH_SOUTH_PORTS)) {
140+
configuration.addAll(NORTH_SOUTH_PORT_PROCESSING_ADDITIONS);
151141
}
152142

153143
if (graphProperties.contains(GraphProperties.END_LABELS)) {
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2020 Kiel University and others.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*******************************************************************************/
10+
package org.eclipse.elk.alg.layered.issues;
11+
12+
import java.util.List;
13+
14+
import org.eclipse.elk.alg.layered.options.LayeredOptions;
15+
import org.eclipse.elk.alg.test.framework.LayoutTestRunner;
16+
import org.eclipse.elk.alg.test.framework.annotations.Configurator;
17+
import org.eclipse.elk.alg.test.framework.annotations.DefaultConfiguration;
18+
import org.eclipse.elk.alg.test.framework.annotations.GraphResourceProvider;
19+
import org.eclipse.elk.alg.test.framework.io.AbstractResourcePath;
20+
import org.eclipse.elk.alg.test.framework.io.FileNameFilter;
21+
import org.eclipse.elk.alg.test.framework.io.ModelResourcePath;
22+
import org.eclipse.elk.core.options.EdgeRouting;
23+
import org.eclipse.elk.graph.ElkNode;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
27+
import com.google.common.collect.Lists;
28+
29+
/**
30+
* Test for issue 587.
31+
*/
32+
@RunWith(LayoutTestRunner.class)
33+
@DefaultConfiguration()
34+
public class Issue587Test {
35+
36+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
37+
// Sources
38+
39+
@GraphResourceProvider
40+
public List<AbstractResourcePath> testGraphs() {
41+
return Lists.newArrayList(
42+
new ModelResourcePath("tickets/layered/**").withFilter(new FileNameFilter("587.+\\.elkt")));
43+
}
44+
45+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
46+
// Configurations
47+
48+
@Configurator
49+
public void configureOrthogonalEdgeRouting(final ElkNode graph) {
50+
graph.setProperty(LayeredOptions.EDGE_ROUTING, EdgeRouting.ORTHOGONAL);
51+
}
52+
53+
@Configurator
54+
public void configurePolylineEdgeRouting(final ElkNode graph) {
55+
graph.setProperty(LayeredOptions.EDGE_ROUTING, EdgeRouting.POLYLINE);
56+
}
57+
58+
@Configurator
59+
public void configureSplineEdgeRouting(final ElkNode graph) {
60+
graph.setProperty(LayeredOptions.EDGE_ROUTING, EdgeRouting.SPLINES);
61+
}
62+
63+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
64+
// Tests
65+
66+
@Test
67+
public void testNoException(final ElkNode graph) {
68+
// The bug caused an exception; nothing particular to test here
69+
}
70+
71+
}

0 commit comments

Comments
 (0)