From 9e510080d6e8155f27ec15ecad4fcdcb5ff78c0d Mon Sep 17 00:00:00 2001 From: earplov Date: Tue, 24 May 2016 14:52:30 +0200 Subject: [PATCH] Bug 494410 - bugfix: Cfg Editor groups section Signed-off-by: earplov --- .../parsers/cfg/ConfigTreeNodeUtilities.java | 36 ++++++++++----- .../pages/compgroupmc/GroupsSubPage.java | 45 +++++-------------- 2 files changed, 36 insertions(+), 45 deletions(-) diff --git a/org.eclipse.titan.common/src/org/eclipse/titan/common/parsers/cfg/ConfigTreeNodeUtilities.java b/org.eclipse.titan.common/src/org/eclipse/titan/common/parsers/cfg/ConfigTreeNodeUtilities.java index b4d203ede..167b7b1af 100644 --- a/org.eclipse.titan.common/src/org/eclipse/titan/common/parsers/cfg/ConfigTreeNodeUtilities.java +++ b/org.eclipse.titan.common/src/org/eclipse/titan/common/parsers/cfg/ConfigTreeNodeUtilities.java @@ -347,13 +347,28 @@ public final class ConfigTreeNodeUtilities { ErrorReporter.INTERNAL_ERROR("ConfigTreeNodeUtilities.removeChild( ParseTree, ParseTree ): only ParserRuleContext can have children"); } } - + /** - * Removes child and a separator ("|") before or after the child (if any) from parent's list + * Removes child and a separator before or after the child (if any) from parent's list. + * Default case * @param aParent parent node to remove the child from * @param aChild child element to remove */ public static void removeChildWithSeparator( final ParseTree aParent, final ParseTree aChild ) { + removeChildWithSeparator( aParent, aChild, "|", 0 ); + } + /** + * Removes child and a separator before or after the child (if any) from parent's list + * @param aParent parent node to remove the child from + * @param aChild child element to remove + * @param aSeparator separator string + * @param aStartIndex the start index where the items start + * aStartIndex > 0 if rule contains some other parse tree nodes than normal list items + */ + public static void removeChildWithSeparator( final ParseTree aParent, + final ParseTree aChild, + final String aSeparator, + final int aStartIndex ) { if ( aParent == null ) { ErrorReporter.INTERNAL_ERROR("ConfigTreeNodeUtilities.removeChildWithSeparator( ParseTree, ParseTree ): aParent == null"); return; @@ -367,22 +382,21 @@ public final class ConfigTreeNodeUtilities { final String childText = aChild.getText(); //NOTE: do NOT start from back, because it deletes by text // and the 1st occurrence must be deleted - for ( int i = 0; i < size; i++ ) { + for ( int i = aStartIndex; i < size; i++ ) { if ( childText.equals( list.get( i ).getText() ) ) { list.remove( i ); - final String separator = "|"; - if ( i > 0 ) { + if ( i > aStartIndex ) { final ParseTree previous = list.get( i - 1 ); - if ( separator.equals( previous.getText() ) ) { + if ( aSeparator.equals( previous.getText() ) ) { list.remove( i - 1 ); } - } else if( size > 1 ) { - // i == 0, but let's check also, if this is not the last item, + } else if( size > aStartIndex + 1 ) { + // i == aStartIndex, but let's check also, if this is not the last item, // because in that case there is no more separator, there is nothing to remove // NOTE: remember, that list size just decreased by 1 now - final ParseTree next = list.get( 0 ); - if ( separator.equals( next.getText() ) ) { - list.remove( 0 ); + final ParseTree next = list.get( aStartIndex ); + if ( aSeparator.equals( next.getText() ) ) { + list.remove( aStartIndex ); } } break; diff --git a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/editors/configeditor/pages/compgroupmc/GroupsSubPage.java b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/editors/configeditor/pages/compgroupmc/GroupsSubPage.java index 84d22797f..ea5b7650a 100644 --- a/org.eclipse.titan.designer/src/org/eclipse/titan/designer/editors/configeditor/pages/compgroupmc/GroupsSubPage.java +++ b/org.eclipse.titan.designer/src/org/eclipse/titan/designer/editors/configeditor/pages/compgroupmc/GroupsSubPage.java @@ -509,41 +509,18 @@ public final class GroupsSubPage { if (item != null) { final List groupItems = selectedGroup.getGroupItems(); final int size = groupItems.size(); - final int index = groupItems.indexOf(item); - - if (index == 0) { - if ( size == 1 ) { - // if it is the only one - // DO NOTHING - // Each group must have at least one item. - return; - } - - final ParseTree selected = item.getItem(); - final String selectedText = selected.getText(); - final ParseTree parent = selectedGroup.getRoot(); - if ( parent instanceof ParserRuleContext ) { - ParserRuleContext parentRule = (ParserRuleContext)parent; - if ( parentRule.children != null ) { - final List childrenList = parentRule.children; - for ( int i = 0; i < childrenList.size(); i++ ) { - // delete by text - final String text = childrenList.get(i).getText(); - if ( selectedText.equals( text ) ) { - childrenList.remove(i); - //also remove the previos " " or ", " - if (i > 0) { - childrenList.remove( i - 1 ); - } - break; - } - } - } - } - groupItems.remove(index); - + if ( size == 1 ) { + // if it is the only one + // DO NOTHING + // Each group must have at least one item. + return; } - + + final ParseTree selected = item.getItem(); + final ParseTree parent = selectedGroup.getRoot(); + // items are separated by "," + // first 2 items of the rule are: group name, ":=", they are not items + ConfigTreeNodeUtilities.removeChildWithSeparator( parent, selected, ",", 2 ); selectedGroup.getGroupItems().remove(item); } } -- GitLab