33import de .vill .exception .ParseError ;
44import de .vill .model .*;
55import de .vill .model .constraint .Constraint ;
6+ import de .vill .model .constraint .ExpressionConstraint ;
67import de .vill .model .constraint .LiteralConstraint ;
8+ import de .vill .model .expression .AggregateFunctionExpression ;
9+ import de .vill .model .expression .Expression ;
710
811import java .util .List ;
912import java .util .Map ;
@@ -102,7 +105,7 @@ public void addAttribute(Feature feature, Attribute<?> attribute) {
102105 */
103106 public boolean renameFeature (String oldName , String newName ) {
104107 Map <String , Feature > featureMap = fmInConstruction .getFeatureMap ();
105- if (featureMap .containsKey (oldName )) {
108+ if (! featureMap .containsKey (oldName )) {
106109 return false ;
107110 }
108111 Feature featureToUpdate = featureMap .get (oldName );
@@ -116,6 +119,49 @@ public boolean renameFeature(String oldName, String newName) {
116119 return true ;
117120 }
118121
122+ public void renameAttribute (Attribute <?> attribute , String newName ) {
123+ String oldName = attribute .getName ();
124+ attribute .setName (newName );
125+ attribute .getFeature ().getAttributes ().remove (oldName );
126+ attribute .getFeature ().getAttributes ().put (newName , attribute );
127+ }
128+
129+ public void renameAttributeGlobally (String oldName , String newName ) {
130+ for (Feature feature : fmInConstruction .getFeatureMap ().values ()) {
131+ if (feature .getAttributes ().containsKey (oldName )) {
132+ Attribute <?> attribute = feature .getAttributes ().get (oldName );
133+ renameAttribute (attribute , newName );
134+ }
135+ }
136+ for (Constraint constraint : fmInConstruction .getConstraints ()) {
137+ crawlConstraintsToRenameGlobalAttribute (constraint , oldName , newName );
138+ }
139+ }
140+ private void crawlConstraintsToRenameGlobalAttribute (Constraint constraint , String attributeName , String replace ) {
141+ if (constraint instanceof ExpressionConstraint ) {
142+ for (Expression exp : ((ExpressionConstraint ) constraint ).getExpressionSubParts ()) {
143+ crawlExpressionsToRenameGlobalAttribute (exp , attributeName , replace );
144+ }
145+ } else {
146+ for (Constraint child : constraint .getConstraintSubParts ()) {
147+ crawlConstraintsToRenameGlobalAttribute (child , attributeName , replace );
148+ }
149+ }
150+ }
151+
152+ private void crawlExpressionsToRenameGlobalAttribute (Expression expression , String attributeName , String replace ) {
153+ if (expression instanceof AggregateFunctionExpression ) {
154+ AggregateFunctionExpression aggregateFunctionExpression = (AggregateFunctionExpression ) expression ;
155+ if (aggregateFunctionExpression .getAttribute ().getIdentifier ().equals (attributeName )) {
156+ aggregateFunctionExpression .getAttribute ().renameGlobalAttribute (replace );
157+ };
158+ } else {
159+ for (Expression exp : expression .getExpressionSubParts ()) {
160+ crawlExpressionsToRenameGlobalAttribute (exp , attributeName , replace );
161+ }
162+ }
163+ }
164+
119165 public void addConstraint (Constraint constraint ) {
120166 fmInConstruction .getOwnConstraints ().add (0 ,constraint );
121167 }
0 commit comments