private final void addToLists( DefinedParamType type, Map<Type, List<DefinedParamType>> assignmentMap, List<DefinedParamType> assignmentList) { assignmentMap.putIfAbsent(type.getType(), new ArrayList<>()); // Will return null if new assignmentMap.get(type.getType()).add(type); if (!assignmentList.contains(type)) { assignmentList.add(type); } }
private BlockStmt getInputOrOutputSocketBody( List<DefinedParamType> paramTypes, ClassOrInterfaceType socketType, String inputOrOutputPostfix) { List<Expression> passedExpressions = new ArrayList<>(); for (DefinedParamType inputParam : paramTypes) { if (inputParam.isIgnored()) continue; passedExpressions.add(getSocketListParam(inputParam, socketType, inputOrOutputPostfix)); } BlockStmt returnStatement = new BlockStmt( Arrays.asList( new ReturnStmt( new ArrayCreationExpr( socketType, 1, new ArrayInitializerExpr(passedExpressions))))); return returnStatement; }
public List<SocketHintDeclaration> getAllSocketHints() { List<SocketHintDeclaration> socketHintDeclarations = new ArrayList<>(); for (Type type : inputHintsMap.keySet()) { socketHintDeclarations.add( new SocketHintDeclaration( collector, type, inputHintsMap.get(type), DefinedParamType.DefinedParamDirection.INPUT)); } for (Type type : outputHintsMap.keySet()) { socketHintDeclarations.add( new SocketHintDeclaration( collector, type, outputHintsMap.get(type), DefinedParamType.DefinedParamDirection.OUTPUT)); } return socketHintDeclarations; }
public List<Expression> getSocketAssignments(String inputParamId, String outputParamId) { List<Expression> assignments = new ArrayList<>(); int inputIndex = 0; int outputIndex = 0; for (DefinedParamType paramType : paramTypes) { // We still need to increment the values if the param is ignored if (paramType.isIgnored()) continue; int index; String paramId; if (inputParamTypes.contains(paramType) && outputParamTypes.contains(paramType)) { if (paramType.getType().toStringWithoutComments().contains("Mat")) { assignments.add( generateCopyExpression( paramType, inputParamId, inputParamTypes.indexOf(paramType), outputParamId, outputParamTypes.indexOf(paramType))); } else { throw new IllegalStateException( "Can not generate Input/Output Socket for type: " + paramType.getType().toString()); } // We have used the input socket inputIndex++; } // Generate the output socket event if this is an input/output socket if (outputParamTypes.contains(paramType)) { paramId = outputParamId; index = outputIndex; outputIndex++; } else if (inputParamTypes.contains(paramType)) { paramId = inputParamId; index = inputIndex; inputIndex++; } else { assert false : "The paramType was not in either the input or output list"; return null; } final MethodCallExpr getValueExpression = getValueExpression(paramId, index); final Expression assignExpression; if (paramType.getType() instanceof PrimitiveType && (!((PrimitiveType) paramType.getType()) .getType() .equals(PrimitiveType.Primitive.Boolean))) { final String numberConversionFunction; switch (((PrimitiveType) paramType.getType()).getType()) { case Int: numberConversionFunction = "intValue"; break; case Short: case Char: numberConversionFunction = "shortValue"; break; case Float: numberConversionFunction = "floatValue"; break; case Double: numberConversionFunction = "doubleValue"; break; case Byte: numberConversionFunction = "byteValue"; break; case Long: numberConversionFunction = "longValue"; break; default: throw new IllegalStateException( "Conversion for type " + paramType.getType() + " is not defined"); } assignExpression = new MethodCallExpr( new EnclosedExpr( new CastExpr(ASTHelper.createReferenceType("Number", 0), getValueExpression)), numberConversionFunction); } else { assignExpression = new CastExpr(paramType.getTypeBoxedIfPossible(), getValueExpression); } assignments.add( new VariableDeclarationExpr( ModifierSet.FINAL, paramType.getType(), Collections.singletonList( new VariableDeclarator( new VariableDeclaratorId(paramType.getName()), assignExpression)))); } return assignments; }