Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/blocks/mrc_component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { Order } from 'blockly/python';
import { MRC_STYLE_COMPONENTS } from '../themes/styles'
import { createFieldNonEditableText } from '../fields/FieldNonEditableText';
import { ExtendedPythonGenerator } from '../editor/extended_python_generator';
import { getAllowedTypesForSetCheck, getClassData, getSubclassNames } from './utils/python';
import { getAllowedTypesForSetCheck, getClassData, getModuleData, getSubclassNames } from './utils/python';
import * as ToolboxItems from '../toolbox/items';
import * as CommonStorage from '../storage/common_storage';
import { createPortShadow } from './mrc_port';
Expand Down Expand Up @@ -231,18 +231,18 @@ function createComponentBlock(
}

function getPortTypeForArgument(argName: string): string | null {
// TODO(lizlooney): Currently the JSON for component.PortType is ClassData
// instead of EnumData. When it is fixed to be EnumData, this code will need
// to be updated.

const argNameLower = argName.toLowerCase();
const classData = getClassData('component.PortType');
if (classData) {
for (const varData of classData.classVariables) {
if (argNameLower === varData.name.toLowerCase()) {
return varData.name;
const moduleData = getModuleData('component');
for (const enumData of moduleData.enums) {
if (enumData.enumClassName === 'component.PortType') {
for (const value of enumData.enumValues) {
if (argNameLower === value.toLowerCase()) {
return value;
}
}
break;
}
}

return null;
}
63 changes: 15 additions & 48 deletions src/blocks/utils/generated/external_samples_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -476,53 +476,6 @@
"moduleName": "component",
"staticMethods": []
},
{
"className": "component.PortType",
"classVariables": [
{
"name": "CAN_PORT",
"tooltip": "",
"type": "component.PortType",
"writable": false
},
{
"name": "I2C_PORT",
"tooltip": "",
"type": "component.PortType",
"writable": false
},
{
"name": "SERVO_PORT",
"tooltip": "",
"type": "component.PortType",
"writable": false
},
{
"name": "SMART_IO_PORT",
"tooltip": "",
"type": "component.PortType",
"writable": false
},
{
"name": "SMART_MOTOR_PORT",
"tooltip": "",
"type": "component.PortType",
"writable": false
},
{
"name": "USB_PORT",
"tooltip": "",
"type": "component.PortType",
"writable": false
}
],
"constructors": [],
"enums": [],
"instanceMethods": [],
"instanceVariables": [],
"moduleName": "component",
"staticMethods": []
},
{
"className": "rev_touch_sensor.RevTouchSensor",
"classVariables": [],
Expand Down Expand Up @@ -1846,7 +1799,21 @@
"moduleVariables": []
},
{
"enums": [],
"enums": [
{
"enumClassName": "component.PortType",
"enumValues": [
"CAN_PORT",
"I2C_PORT",
"SERVO_PORT",
"SMART_IO_PORT",
"SMART_MOTOR_PORT",
"USB_PORT"
],
"moduleName": "component",
"tooltip": null
}
],
"functions": [],
"moduleName": "component",
"moduleVariables": []
Expand Down
12 changes: 12 additions & 0 deletions src/blocks/utils/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ export function getClassData(className: string): ClassData | null {
return null;
}

// Returns the ModuleData for the given module name.
export function getModuleData(moduleName: string): ModuleData | null {
for (const pythonData of allPythonData) {
for (const moduleData of pythonData.modules) {
if (moduleData.moduleName === moduleName) {
return moduleData;
}
}
}
return null;
}

// If the given type is a type alias, returns the value of the type alias.
// For example, if type is 'wpimath.units.nanoseconds', this function will return 'float'
export function getAlias(type: string): string | null {
Expand Down