-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid namespace collisions when collapsing graph to custom node #9330
Merged
mjkkirschner
merged 9 commits into
DynamoDS:master
from
mjkkirschner:elementResolverNull
Jan 2, 2019
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
39236d2
this works - but I am hesitant to modify this replacer.
mjkkirschner 7f08259
add a new visitor method for typedIdentifierNode
mjkkirschner e8324b7
Merge remote-tracking branch 'upstream/master' into elementResolverNull
mjkkirschner dfa9934
move shortQualifiedNameReplacer
mjkkirschner a59685b
add more tests
mjkkirschner eb00720
revert public API break, keep rewriter in dynamoCore but in new file
mjkkirschner 466f588
Merge remote-tracking branch 'upstream/master' into elementResolverNull
mjkkirschner c1a123a
remove extra usings added previously.
mjkkirschner 7372431
remove debugging code
mjkkirschner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Xml; | ||
using Dynamo.Engine; | ||
using Dynamo.Engine.NodeToCode; | ||
using Dynamo.Graph; | ||
using Dynamo.Graph.Annotations; | ||
using Dynamo.Graph.Connectors; | ||
|
@@ -22,6 +17,13 @@ | |
using Dynamo.Properties; | ||
using Dynamo.Selection; | ||
using Dynamo.Utilities; | ||
using ProtoCore.AST.AssociativeAST; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Xml; | ||
using Symbol = Dynamo.Graph.Nodes.CustomNodes.Symbol; | ||
|
||
namespace Dynamo.Core | ||
|
@@ -674,7 +676,8 @@ private bool InitializeCustomNode( | |
nodeGraph.ElementResolver, | ||
workspaceInfo); | ||
} | ||
else { | ||
else | ||
{ | ||
Exception ex; | ||
if (DynamoUtilities.PathHelper.isValidJson(workspaceInfo.FileName, out jsonDoc, out ex)) | ||
{ | ||
|
@@ -1031,6 +1034,7 @@ internal CustomNodeWorkspaceModel Collapse( | |
|
||
var inConnectors = new List<Tuple<NodeModel, int>>(); | ||
var uniqueInputSenders = new Dictionary<Tuple<NodeModel, int>, Symbol>(); | ||
var classTable = this.libraryServices.LibraryManagementCore.ClassTable; | ||
|
||
//Step 3: insert variables (reference step 1) | ||
foreach (var input in Enumerable.Range(0, inputs.Count).Zip(inputs, Tuple.Create)) | ||
|
@@ -1077,10 +1081,17 @@ internal CustomNodeWorkspaceModel Collapse( | |
var funcDesc = dsFunc.Controller.Definition; | ||
parameters = funcDesc.Parameters.ToList(); | ||
|
||
// if the node is an instance member the function won't contain a | ||
// parameter for this type so we need to generate a new typedParameter. | ||
if (funcDesc.Type == Engine.FunctionType.InstanceMethod || | ||
funcDesc.Type == Engine.FunctionType.InstanceProperty) | ||
{ | ||
var dummyType = new ProtoCore.Type() { Name = funcDesc.ClassName }; | ||
var dummyType = new ProtoCore.Type | ||
{ | ||
Name = funcDesc.ClassName, | ||
UID = classTable.IndexOf(funcDesc.ClassName) | ||
}; | ||
|
||
var instanceParam = new TypedParameter(funcDesc.ClassName, dummyType); | ||
parameters.Insert(0, instanceParam); | ||
} | ||
|
@@ -1090,10 +1101,35 @@ internal CustomNodeWorkspaceModel Collapse( | |
// input_var_name : type | ||
if (parameters != null && parameters.Count() > inputReceiverData) | ||
{ | ||
var typeName = parameters[inputReceiverData].DisplayTypeName; | ||
if (!string.IsNullOrEmpty(typeName)) | ||
var port = inputReceiverNode.InPorts[inputReceiverData]; | ||
var typedParameter = parameters[inputReceiverData]; | ||
// initially set the type name to the full type name | ||
// then try to shorten it. | ||
if (!string.IsNullOrEmpty(typedParameter.Type.Name)) | ||
{ | ||
node.InputSymbol += " : " + typeName; | ||
try | ||
{ | ||
|
||
var typedNode = new TypedIdentifierNode | ||
{ | ||
Name = port.Name, | ||
Value = port.Name, | ||
datatype = typedParameter.Type, | ||
TypeAlias = typedParameter.Type.Name | ||
}; | ||
|
||
NodeToCodeCompiler.ReplaceWithShortestQualifiedName( | ||
classTable, | ||
new List<AssociativeNode> { typedNode }, | ||
currentWorkspace.ElementResolver); | ||
|
||
node.InputSymbol = $"{typedNode.Value} :{typedNode.TypeAlias}"; | ||
} | ||
catch(Exception e) | ||
{ | ||
node.InputSymbol += ":" + typedParameter.Type.Name; | ||
this.AsLogger().LogError($"{e.Message}: could not generate a short type name for {typedParameter.Type.Name}"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, thats what it does. |
||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the nodeGraph is instantiated from an xml file? Is that why it doesn't get the correct element resolver as we are now using JSON?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here is where we use the deserialized element resolver when loading a JSON graph and pass it to the home workspace or customNode workspace that was just deserialized.
Dynamo/src/DynamoCore/Graph/Workspaces/SerializationConverters.cs
Line 532 in ec10f93