-
Notifications
You must be signed in to change notification settings - Fork 8
Remove duplicate comment from methods #55
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,8 @@ import * as commonStorage from '../storage/common_storage'; | |
export class ExtendedPythonGenerator extends PythonGenerator { | ||
private currentModule: commonStorage.Module | null = null; | ||
private mapWorkspaceIdToExportedBlocks: { [key: string]: Block[] } = Object.create(null); | ||
protected methods_: {[key: string]: string} = Object.create(null); | ||
lizlooney marked this conversation as resolved.
Show resolved
Hide resolved
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. Why protected instead of private? 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. I almost always go for protected instead of private so it can be subclassed later. 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. I'm the opposite. I go for the most restrictive visibility first and then make it more visible only if necessary. 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. While I agree fully about not making things public by default (as the style guide says), protected seems to be better than private. Imagine the mess we would be in if Blockly had made everything private instead of protected. (I'll admit that this tendency of mine is because I am almost always creating libraries or systems instead of applications.) 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. That makes sense for libraries where you (as author of the library) want to allow a class to be subclassed. In this case, it is not a library and within this application, we don't currently want to subclass ExtendedPythonGenerator. I'm going to approve (and merge) this PR so we can keep making progress. |
||
|
||
|
||
constructor() { | ||
super('Python'); | ||
|
@@ -158,6 +160,9 @@ export class ExtendedPythonGenerator extends PythonGenerator { | |
addImport(importModule: string): void { | ||
this.definitions_['import_' + importModule] = 'import ' + importModule; | ||
} | ||
addMethod(methodName: string, code : string): void { | ||
this.methods_[methodName] = code; | ||
} | ||
|
||
classParentFromModuleType(moduleType : string) : string{ | ||
if(moduleType == commonStorage.MODULE_TYPE_PROJECT){ | ||
|
@@ -186,31 +191,32 @@ export class ExtendedPythonGenerator extends PythonGenerator { | |
// Convert the definitions dictionary into a list. | ||
const imports = []; | ||
const definitions = []; | ||
|
||
for (let name in this.definitions_) { | ||
const def = this.definitions_[name]; | ||
if (def.match(/^(from\s+\S+\s+)?import\s+\S+/)) { | ||
imports.push(def); | ||
} else { | ||
} else{ | ||
definitions.push(def); | ||
} | ||
} | ||
// Call Blockly.CodeGenerator's finish. This is required to be done this way | ||
// because we derive from PythonGenerator which dervies from CodeGenerator | ||
// This section except for the class_def part is all copied from Blockly's | ||
// PythonGenerator. It can't be derived because it needs the class insertion | ||
// in the middle. | ||
code = Blockly.CodeGenerator.prototype.finish(code); | ||
const methods = []; | ||
for (let name in this.methods_){ | ||
methods.push(this.methods_[name]) | ||
} | ||
|
||
this.definitions_ = Object.create(null); | ||
this.functionNames_ = Object.create(null); | ||
this.methods_ = Object.create(null); | ||
|
||
this.isInitialized = false; | ||
|
||
let class_def = "class " + className + "(" + classParent + "):\n"; | ||
if (!code) { | ||
code = "pass"; | ||
} | ||
|
||
this.nameDB_!.reset(); | ||
const allDefs = imports.join('\n') + '\n\n' + definitions.join('\n\n'); | ||
return allDefs.replace(/\n\n+/g, '\n\n').replace(/\n*$/, '\n\n\n') + class_def + | ||
this.prefixLines(code, this.INDENT); | ||
this.prefixLines(methods.join('\n\n'), this.INDENT); | ||
} | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.