Package org.openquark.cal.valuenode

Examples of org.openquark.cal.valuenode.AbstractRecordValueNode


    private Map<ValueNode, TypeExpr> getValueNodeToUnconstrainedTypeMap() {
       
        //Map to hold the result of this function ValueNode->TypeExpr
        final Map<ValueNode, TypeExpr> resultMap = new HashMap<ValueNode, TypeExpr>();
       
        final AbstractRecordValueNode currentValueNode = (AbstractRecordValueNode)getValueNode();
        final List<FieldName> hasFieldNames = ((RecordType)currentValueNode.getTypeExpr()).getHasFieldNames();
        final int numFields = currentValueNode.getTypeExpr().rootRecordType().getNHasFields();

      
        // get the context least constrained type
        final TypeExpr contextLeastConstrainedType = getContext().getLeastConstrainedTypeExpr();
       
        //build one that includes all of the new fields as well.
        final Map<FieldName, TypeExpr> contextFieldsMap; //map of all the fields in the context RecordFieldName -> TypeExpr
        if (contextLeastConstrainedType instanceof RecordType) {
            contextFieldsMap = ((RecordType) contextLeastConstrainedType).getHasFieldsMap();
        } else {
            contextFieldsMap = new HashMap<FieldName, TypeExpr>();
        }

        final Map<FieldName, TypeExpr> allFieldsMap = new HashMap<FieldName, TypeExpr>(); //map containing all the context fields and fields added with the value editor, RecordFieldName -> TypeExpr

        for (int i = 0; i < numFields; i++) {
            final FieldName fieldName = hasFieldNames.get(i);
            if (contextFieldsMap.containsKey(fieldName)) {
                allFieldsMap.put(fieldName, contextFieldsMap.get(fieldName));
            } else {
                allFieldsMap.put(fieldName, TypeExpr.makeParametricType());
            }
        }
        final RecordType leastConstrainedRecordType = TypeExpr.makePolymorphicRecordType(allFieldsMap);

       
        // add the record node itself to the result map
        resultMap.put(currentValueNode, leastConstrainedRecordType);

        // add all the record field nodes to the result map
        for (int j = 0; j < numFields; j++) {
            ValueNode currentFieldNode = currentValueNode.getValueAt(j);
            FieldName fieldName = hasFieldNames.get(j);
           
            TypeExpr leastConstrainedRecordElementType = leastConstrainedRecordType.getHasFieldType(fieldName);
                           
            resultMap.put(currentFieldNode, leastConstrainedRecordElementType);
View Full Code Here


    public void commitChildChanges(ValueNode oldChild, ValueNode newChild) {
               
        // Get the copy of the current value node, type switched if necessary.
       
        ValueNode oldValueNode = getValueNode();
        AbstractRecordValueNode newValueNode;
        if (!oldChild.getTypeExpr().sameType(newChild.getTypeExpr())) {
           
            // A child is switching type. So calculate new types/values of all our field nodes
           
            Map<ValueNode, TypeExpr> valueNodeToUnconstrainedTypeMap = getValueNodeToUnconstrainedTypeMap();
            Map<ValueNode, ValueNode> commitValueMap = valueEditorManager.getValueNodeCommitHelper().getCommitValues(oldChild, newChild, valueNodeToUnconstrainedTypeMap);
           
            newValueNode = (AbstractRecordValueNode)commitValueMap.get(oldValueNode);

        } else {
            newValueNode = (AbstractRecordValueNode)oldValueNode.copyValueNode();
        }       
       
        // Update the values of the children to match the updated value
       
        List<ValueNode> currentChildrenList = UnsafeCast.<List<ValueNode>>unsafeCast(oldValueNode.getValue());          // unsafe.
        for (int i = 0, listSize = newValueNode.getTypeExpr().rootRecordType().getNHasFields(); i < listSize; i++) {
            if (currentChildrenList.get(i) == oldChild) {
                TypeExpr childType = newValueNode.getValueAt(i).getTypeExpr();
                newValueNode.setValueNodeAt(i, newChild.copyValueNode(childType));
                break;
            }
        }

        // Set the value node
View Full Code Here

                   
                    // Iterate through the list of record nodes and change their type expressions
                   
                    for (int i = 0; i < listSize; i++) {
                       
                        AbstractRecordValueNode recordValueNode = (AbstractRecordValueNode)((ListValueNode)getValueNode()).getValueAt(i);
                        recordValueNode = recordValueNode.renameField(oldName, newName, valueEditorManager.getValueNodeBuilderHelper(), valueEditorManager.getValueNodeTransformer());
                        ((ListValueNode)getValueNode()).setValueNodeAt(i, recordValueNode);
                    }
                   
                }
               
View Full Code Here

                }
            }

        } else {
            // isListRecord == true, ie. must be a list of records (or tuples).
            AbstractRecordValueNode firstChild = (AbstractRecordValueNode)oldChildrenList.get(0);
           
            // To find the child that changed, for each value in the list, have to iterate through the tuple/record.
            int listSize = newValueNode.getNElements();
           
            int childrenSize = firstChild.getNFieldNames();

            // TODO: Note that new record value nodes may have more/less fields than the old nodes,
            // because of type switch
           
          listItem:
            for (int i = 0; i < listSize; i++) {
                AbstractRecordValueNode currentValue = (AbstractRecordValueNode)oldChildrenList.get(i);

                for (int j = 0; j < childrenSize; j++) {
                    if (currentValue.getValueAt(j) == oldChild) {
                        AbstractRecordValueNode newListItemValue = (AbstractRecordValueNode)newChildrenList.get(i);
                        newListItemValue.setValueNodeAt(j, newChild.copyValueNode());
                        break listItem;
                    }
                }
            }
        }
View Full Code Here

TOP

Related Classes of org.openquark.cal.valuenode.AbstractRecordValueNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.