Class PdeParseTreeListener
- All Implemented Interfaces:
org.antlr.v4.runtime.tree.ParseTreeListener,ProcessingListener
ANTLR tree traversal listener that preforms code rewrites as part of sketch preprocessing, turning sketch source into compilable Java code. Note that this emits both the Java source when using javac directly as part of {JavaBuild} as well as {TextTransform.Edit}s when using the JDT via the {PreprocessingService}.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceListener for issues encountered while processing a valid pde parse tree.static classDecorator around a {TokenStreamRewriter}. -
Constructor Summary
ConstructorsConstructorDescriptionPdeParseTreeListener(org.antlr.v4.runtime.TokenStream tokens, String newSketchName, int newTabSize, Optional<String> newDestinationPackageName) Create a new listener. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancalledFromGlobalOrSetup(org.antlr.v4.runtime.ParserRuleContext callContext) protected static TextTransform.EditcreateDelete(org.antlr.v4.runtime.Token start, org.antlr.v4.runtime.Token stop, org.antlr.v4.runtime.TokenStreamRewriter rewriter) Delete tokens between a start end end token inclusive.protected static TextTransform.EditcreateDelete(org.antlr.v4.runtime.Token start, org.antlr.v4.runtime.TokenStreamRewriter rewriter) Delete a single token.protected static TextTransform.EditcreateInsertAfter(org.antlr.v4.runtime.Token start, String text, org.antlr.v4.runtime.TokenStreamRewriter rewriter) Insert text after a token.protected static TextTransform.EditcreateInsertBefore(int before, int beforeOffset, String text, org.antlr.v4.runtime.TokenStreamRewriter rewriter) Insert text before a position in code.protected static TextTransform.EditcreateInsertBefore(org.antlr.v4.runtime.Token before, String text, org.antlr.v4.runtime.TokenStreamRewriter rewriter) Insert text before a token.protected voiddelete(org.antlr.v4.runtime.Token location) Delete a single token.protected voiddelete(org.antlr.v4.runtime.Token start, org.antlr.v4.runtime.Token stop) Delete from a token to a token inclusive.voidDetect if the user is programming with "mixed" modes.voidEndpoint for ANTLR to call after parsing a "active" processing sketch.voidEndpoint for ANTLR to call after parsing a color primitive token.voidEndpoint for ANTLR to call after parsing a decimal point literal.voidEndpoint for ANTLR to call after parsing a primitive type name.voidEndpoint for ANTLR to call after parsing a hex color literal.voidEndpoint for ANTLR to call when finished parsing an import declaration.voidEndpoint for ANTLR to call when finished parsing a method invocatino.voidEndpoint for ANTLR to call after parsing a method declaration.voidEndpoint for ANTLR to call after parsing a String literal.voidEndpoint for ANTLR to call when having finished parsing a processing sketch.voidEndpoint for ANTLR to call after parsing a static processing sketch.booleanDetermine if the user provided their own "main" method.Get the sketch code transformed to grammatical Java.Get the result of the last preprocessing.getResult(List<PdePreprocessIssue> issues) Get the result of the last preprocessing with optional error.org.antlr.v4.runtime.TokenStreamRewriterGet the rewriter used by this listener.protected voidhandleNoSmoothCall(org.antlr.v4.runtime.ParserRuleContext ctx) protected voidhandlePixelDensityCall(org.antlr.v4.runtime.ParserRuleContext ctx) protected voidhandleSizeCall(org.antlr.v4.runtime.ParserRuleContext ctx) Manage parsing out a size or fullscreen call.protected voidhandleSmoothCall(org.antlr.v4.runtime.ParserRuleContext ctx) protected static TextTransform.EditinsertAfter(int start, String text, org.antlr.v4.runtime.TokenStreamRewriter rewriter) Insert text after a token.protected voidinsertAfter(org.antlr.v4.runtime.Token location, String text) Insert text after a location in code.protected voidinsertBefore(int locationToken, int locationOffset, String text) Insert text before a location in code.protected voidinsertBefore(org.antlr.v4.runtime.Token location, String text) Insert text before a token.protected booleanCheck if this contains an annation.protected booleanisMethodSetup(org.antlr.v4.runtime.ParserRuleContext declaration) Determine if a method declaration is for setup.protected RewriteResultprepareFooter(org.antlr.v4.runtime.TokenStreamRewriter footerWriter, int insertPoint) Prepare the footer for a sketch (finishes the constructs introduced in header like class def).protected RewriteResultprepareHeader(org.antlr.v4.runtime.TokenStreamRewriter headerWriter) Prepare preface code to wrap sketch code so that it is contained within a proper Java definition.voidsetCodeFolderImportInfo(List<ImportStatement> codeFolderImports) Indicate imports for code folders given full import statement information.voidsetCodeFolderImports(List<String> codeFolderImports) Indicate imports for code folders given those imports' fully qualified names.voidsetCoreImportInfo(List<ImportStatement> coreImports) voidsetCoreImports(String[] coreImports) Indicate list of imports required for all sketches to be inserted in preprocessing given those imports' fully qualified names.voidsetCoreImports(List<String> coreImports) Indicate list of imports required for all sketches to be inserted in preprocessing given those imports' fully qualified names.voidsetDefaultImportInfo(List<ImportStatement> defaultImports) voidsetDefaultImports(String[] defaultImports) Indicate list of default convenience imports.voidsetDefaultImports(List<String> defaultImports) Indicate list of default convenience imports.voidsetTesting(boolean isTesting) Indicate if running in unit tests.voidIndicate which listener should be informed of parse tree processing issues.protected voidwriteClassFooter(PdeParseTreeListener.PrintWriterWithEditGen footerWriter, RewriteResultBuilder resultBuilder) Write the end of the class body for the footer.protected voidwriteClassHeader(PdeParseTreeListener.PrintWriterWithEditGen headerWriter, RewriteResultBuilder resultBuilder) Write the prefix which defines the enclosing class for the sketch.protected voidwriteExtraFieldsAndMethods(PdeParseTreeListener.PrintWriterWithEditGen classBodyWriter, RewriteResultBuilder resultBuilder) Write code supporting special functions like size.protected voidwriteFooterContents(PdeParseTreeListener.PrintWriterWithEditGen decoratedWriter, RewriteResultBuilder resultBuilder) Write the contents of the footer using a prebuilt print writer.protected voidwriteHeaderContents(PdeParseTreeListener.PrintWriterWithEditGen decoratedWriter, RewriteResultBuilder resultBuilder) Write the contents of the header using a prebuilt print writer.protected voidwriteImportList(PdeParseTreeListener.PrintWriterWithEditGen headerWriter, List<ImportStatement> imports, RewriteResultBuilder resultBuilder) Write a list of imports.protected voidwriteImportList(PdeParseTreeListener.PrintWriterWithEditGen headerWriter, ImportStatement[] imports, RewriteResultBuilder resultBuilder) Write a list of imports.protected voidwriteImports(PdeParseTreeListener.PrintWriterWithEditGen headerWriter, RewriteResultBuilder resultBuilder) Add imports as part of conversion from processing sketch to Java code.protected voidwriteMain(PdeParseTreeListener.PrintWriterWithEditGen footerWriter, RewriteResultBuilder resultBuilder) Write the main method.protected voidwritePreprocessorComment(PdeParseTreeListener.PrintWriterWithEditGen headerWriter, RewriteResultBuilder resultBuilder) Comment out sketch code before it is moved elsewhere in resulting Java.protected voidwriteStaticSketchFooter(PdeParseTreeListener.PrintWriterWithEditGen footerWriter, RewriteResultBuilder resultBuilder) Write the bottom of the sketch code for static mode.protected voidwriteStaticSketchHeader(PdeParseTreeListener.PrintWriterWithEditGen headerWriter, RewriteResultBuilder resultBuilder) Write the header for a static sketch (no methods).Methods inherited from class processing.mode.java.preproc.ProcessingBaseListener
enterActiveProcessingSketch, enterAltAnnotationQualifiedName, enterAnnotation, enterAnnotationConstantRest, enterAnnotationMethodOrConstantRest, enterAnnotationMethodRest, enterAnnotationTypeBody, enterAnnotationTypeDeclaration, enterAnnotationTypeElementDeclaration, enterAnnotationTypeElementRest, enterArguments, enterArrayCreatorRest, enterArrayInitializer, enterBaseStringLiteral, enterBinaryOperatorExpression, enterBlock, enterBlockStatement, enterCastExpression, enterCatchClause, enterCatchType, enterClassBody, enterClassBodyDeclaration, enterClassCreatorRest, enterClassDeclaration, enterClassOrInterfaceModifier, enterClassOrInterfaceType, enterClassType, enterColorPrimitiveType, enterCompactConstructorDeclaration, enterCompilationUnit, enterConstantDeclarator, enterConstDeclaration, enterConstructorDeclaration, enterCreatedName, enterCreator, enterDefaultValue, enterElementValue, enterElementValueArrayInitializer, enterElementValuePair, enterElementValuePairs, enterEnhancedForControl, enterEnumBodyDeclarations, enterEnumConstant, enterEnumConstants, enterEnumDeclaration, enterEveryRule, enterExplicitGenericInvocation, enterExplicitGenericInvocationSuffix, enterExpressionLambda, enterExpressionList, enterExpressionSwitch, enterFieldDeclaration, enterFinallyBlock, enterFloatLiteral, enterForControl, enterForInit, enterFormalParameter, enterFormalParameterList, enterFormalParameters, enterFunctionWithPrimitiveTypeName, enterGenericConstructorDeclaration, enterGenericInterfaceMethodDeclaration, enterGenericMethodDeclaration, enterGuardedPattern, enterHexColorLiteral, enterIdentifier, enterImportDeclaration, enterInnerCreator, enterInstanceOfOperatorExpression, enterIntegerLiteral, enterInterfaceBody, enterInterfaceBodyDeclaration, enterInterfaceCommonBodyDeclaration, enterInterfaceDeclaration, enterInterfaceMemberDeclaration, enterInterfaceMethodDeclaration, enterInterfaceMethodModifier, enterJavaProcessingSketch, enterLambdaBody, enterLambdaExpression, enterLambdaLVTIList, enterLambdaLVTIParameter, enterLambdaParameters, enterLastFormalParameter, enterLiteral, enterLocalTypeDeclaration, enterLocalVariableDeclaration, enterMemberDeclaration, enterMemberReferenceExpression, enterMethodBody, enterMethodCall, enterMethodCallExpression, enterMethodDeclaration, enterMethodReferenceExpression, enterModifier, enterModuleBody, enterModuleDeclaration, enterModuleDirective, enterMultilineStringLiteral, enterNonWildcardTypeArguments, enterNonWildcardTypeArgumentsOrDiamond, enterObjectCreationExpression, enterPackageDeclaration, enterParExpression, enterPattern, enterPostIncrementDecrementOperatorExpression, enterPrimary, enterPrimaryExpression, enterPrimitiveType, enterProcessingSketch, enterQualifiedName, enterQualifiedNameList, enterReceiverParameter, enterRecordBody, enterRecordComponent, enterRecordComponentList, enterRecordDeclaration, enterRecordHeader, enterRequiresModifier, enterResource, enterResources, enterResourceSpecification, enterSquareBracketExpression, enterStatement, enterStaticProcessingSketch, enterStringLiteral, enterSuperSuffix, enterSwitchBlockStatementGroup, enterSwitchExpression, enterSwitchLabel, enterSwitchLabeledRule, enterSwitchRuleOutcome, enterTernaryExpression, enterTypeArgument, enterTypeArguments, enterTypeArgumentsOrDiamond, enterTypeBound, enterTypeDeclaration, enterTypeIdentifier, enterTypeList, enterTypeParameter, enterTypeParameters, enterTypeType, enterTypeTypeOrVoid, enterUnaryOperatorExpression, enterVariableDeclarator, enterVariableDeclaratorId, enterVariableDeclarators, enterVariableInitializer, enterVariableModifier, enterWarnTypeAsVariableName, exitAltAnnotationQualifiedName, exitAnnotation, exitAnnotationConstantRest, exitAnnotationMethodOrConstantRest, exitAnnotationMethodRest, exitAnnotationTypeBody, exitAnnotationTypeDeclaration, exitAnnotationTypeElementDeclaration, exitAnnotationTypeElementRest, exitArguments, exitArrayCreatorRest, exitArrayInitializer, exitBaseStringLiteral, exitBinaryOperatorExpression, exitBlock, exitBlockStatement, exitCastExpression, exitCatchClause, exitCatchType, exitClassBody, exitClassBodyDeclaration, exitClassCreatorRest, exitClassDeclaration, exitClassOrInterfaceModifier, exitClassOrInterfaceType, exitClassType, exitCompactConstructorDeclaration, exitCompilationUnit, exitConstantDeclarator, exitConstDeclaration, exitConstructorDeclaration, exitCreatedName, exitCreator, exitDefaultValue, exitElementValue, exitElementValueArrayInitializer, exitElementValuePair, exitElementValuePairs, exitEnhancedForControl, exitEnumBodyDeclarations, exitEnumConstant, exitEnumConstants, exitEnumDeclaration, exitEveryRule, exitExplicitGenericInvocation, exitExplicitGenericInvocationSuffix, exitExpressionLambda, exitExpressionList, exitExpressionSwitch, exitFieldDeclaration, exitFinallyBlock, exitForControl, exitForInit, exitFormalParameter, exitFormalParameterList, exitFormalParameters, exitGenericConstructorDeclaration, exitGenericInterfaceMethodDeclaration, exitGenericMethodDeclaration, exitGuardedPattern, exitIdentifier, exitInnerCreator, exitInstanceOfOperatorExpression, exitIntegerLiteral, exitInterfaceBody, exitInterfaceBodyDeclaration, exitInterfaceCommonBodyDeclaration, exitInterfaceDeclaration, exitInterfaceMemberDeclaration, exitInterfaceMethodDeclaration, exitInterfaceMethodModifier, exitJavaProcessingSketch, exitLambdaBody, exitLambdaExpression, exitLambdaLVTIList, exitLambdaLVTIParameter, exitLambdaParameters, exitLastFormalParameter, exitLiteral, exitLocalTypeDeclaration, exitLocalVariableDeclaration, exitMemberDeclaration, exitMemberReferenceExpression, exitMethodBody, exitMethodCallExpression, exitMethodReferenceExpression, exitModifier, exitModuleBody, exitModuleDeclaration, exitModuleDirective, exitNonWildcardTypeArguments, exitNonWildcardTypeArgumentsOrDiamond, exitObjectCreationExpression, exitPackageDeclaration, exitParExpression, exitPattern, exitPostIncrementDecrementOperatorExpression, exitPrimary, exitPrimaryExpression, exitPrimitiveType, exitQualifiedName, exitQualifiedNameList, exitReceiverParameter, exitRecordBody, exitRecordComponent, exitRecordComponentList, exitRecordDeclaration, exitRecordHeader, exitRequiresModifier, exitResource, exitResources, exitResourceSpecification, exitSquareBracketExpression, exitStatement, exitStringLiteral, exitSuperSuffix, exitSwitchBlockStatementGroup, exitSwitchExpression, exitSwitchLabel, exitSwitchLabeledRule, exitSwitchRuleOutcome, exitTernaryExpression, exitTypeArgument, exitTypeArguments, exitTypeArgumentsOrDiamond, exitTypeBound, exitTypeDeclaration, exitTypeIdentifier, exitTypeList, exitTypeParameter, exitTypeParameters, exitTypeType, exitTypeTypeOrVoid, exitUnaryOperatorExpression, exitVariableDeclarator, exitVariableDeclaratorId, exitVariableDeclarators, exitVariableInitializer, exitVariableModifier, exitWarnMixedModes, exitWarnTypeAsVariableName, visitErrorNode, visitTerminal
-
Constructor Details
-
PdeParseTreeListener
public PdeParseTreeListener(org.antlr.v4.runtime.TokenStream tokens, String newSketchName, int newTabSize, Optional<String> newDestinationPackageName) Create a new listener.- Parameters:
tokens- The tokens over which to rewrite.newSketchName- The name of the sketch being traversed.newTabSize- Size of tab / indent.newDestinationPackageName- The package to which generated code should be assigned (the package to which the sketch code java file should be assigned).
-
-
Method Details
-
setCodeFolderImports
Indicate imports for code folders given those imports' fully qualified names.- Parameters:
codeFolderImports- List of imports for sources sitting in the sketch code folder. Note that these will be interpreted as non-static imports.
-
setCodeFolderImportInfo
Indicate imports for code folders given full import statement information. names.- Parameters:
codeFolderImports- List of import statement info for sources sitting in the sketch code folder.
-
setCoreImports
Indicate list of imports required for all sketches to be inserted in preprocessing given those imports' fully qualified names.- Parameters:
coreImports- The list of imports required for all sketches. Note that these will be interpreted as non-static imports.
-
setCoreImports
Indicate list of imports required for all sketches to be inserted in preprocessing given those imports' fully qualified names.- Parameters:
coreImports- The list of imports required for all sketches. Note that these will be interpreted as non-static imports.
-
setCoreImportInfo
-
setDefaultImports
Indicate list of default convenience imports.Indicate list of imports that are not required for sketch operation but included for the user's convenience regardless.
- Parameters:
defaultImports- The list of imports to include for user convenience.
-
setDefaultImports
Indicate list of default convenience imports.Indicate list of imports that are not required for sketch operation but included for the user's convenience regardless given those imports' fully qualified names.
- Parameters:
defaultImports- The list of imports to include for user convenience. Note that these will be interpreted as non-static imports.
-
setDefaultImportInfo
-
setTesting
public void setTesting(boolean isTesting) Indicate if running in unit tests.- Parameters:
isTesting- True if running as part of tests and false otherwise.
-
setTreeErrorListener
Indicate which listener should be informed of parse tree processing issues.- Parameters:
newListener- listener to be informed when an issue is encoutnered in processing the parse tree.
-
foundMain
public boolean foundMain()Determine if the user provided their own "main" method.- Returns:
- True if the sketch code provides a main method. False otherwise.
-
getOutputProgram
Get the sketch code transformed to grammatical Java.- Returns:
- Complete sketch code as Java.
-
getRewriter
public org.antlr.v4.runtime.TokenStreamRewriter getRewriter()Get the rewriter used by this listener.- Returns:
- Listener's rewriter.
-
getResult
Get the result of the last preprocessing.- Returns:
- The result of the last preprocessing.
-
getResult
Get the result of the last preprocessing with optional error.- Parameters:
issues- The errors (if any) encountered.- Returns:
- The result of the last preprocessing.
-
exitProcessingSketch
Endpoint for ANTLR to call when having finished parsing a processing sketch.- Specified by:
exitProcessingSketchin interfaceProcessingListener- Overrides:
exitProcessingSketchin classProcessingBaseListener- Parameters:
ctx- The context from ANTLR for the processing sketch.
-
enterWarnMixedModes
Detect if the user is programming with "mixed" modes.Detect if the user is programming with "mixed" modes where they are combining active and static mode features. This may be, for example, a method call followed by method definition.
- Specified by:
enterWarnMixedModesin interfaceProcessingListener- Overrides:
enterWarnMixedModesin classProcessingBaseListener- Parameters:
ctx- The context from ANTLR for the mixed modes sketch.
-
exitMethodCall
Endpoint for ANTLR to call when finished parsing a method invocatino.- Specified by:
exitMethodCallin interfaceProcessingListener- Overrides:
exitMethodCallin classProcessingBaseListener- Parameters:
ctx- The ANTLR context for the method call.
-
exitImportDeclaration
Endpoint for ANTLR to call when finished parsing an import declaration.Endpoint for ANTLR to call when finished parsing an import declaration, remvoing those declarations from sketch body so that they can be included in the header.
- Specified by:
exitImportDeclarationin interfaceProcessingListener- Overrides:
exitImportDeclarationin classProcessingBaseListener- Parameters:
ctx- ANTLR context for the import declaration.
-
exitFloatLiteral
Endpoint for ANTLR to call after parsing a decimal point literal.Endpoint for ANTLR to call when finished parsing a floating point literal, adding an 'f' at the end to force it float instead of double for API compatability.
- Specified by:
exitFloatLiteralin interfaceProcessingListener- Overrides:
exitFloatLiteralin classProcessingBaseListener- Parameters:
ctx- ANTLR context for the literal.
-
exitMultilineStringLiteral
Endpoint for ANTLR to call after parsing a String literal.Endpoint for ANTLR to call when finished parsing a string literal, simulating multiline strings if configured to do so.
- Specified by:
exitMultilineStringLiteralin interfaceProcessingListener- Overrides:
exitMultilineStringLiteralin classProcessingBaseListener- Parameters:
ctx- ANTLR context for the literal.
-
exitStaticProcessingSketch
Endpoint for ANTLR to call after parsing a static processing sketch.Endpoint for ANTLR to call after parsing a static processing sketch, informing this parser that it is operating on a static sketch (no method or class declarations) so that it writes the correct header / footer.
- Specified by:
exitStaticProcessingSketchin interfaceProcessingListener- Overrides:
exitStaticProcessingSketchin classProcessingBaseListener- Parameters:
ctx- ANTLR context for the sketch.
-
exitActiveProcessingSketch
Endpoint for ANTLR to call after parsing a "active" processing sketch.Endpoint for ANTLR to call after parsing a "active" processing sketch, informing this parser that it is operating on an active sketch so that it writes the correct header / footer.
- Specified by:
exitActiveProcessingSketchin interfaceProcessingListener- Overrides:
exitActiveProcessingSketchin classProcessingBaseListener- Parameters:
ctx- ANTLR context for the sketch.
-
exitMethodDeclaration
Endpoint for ANTLR to call after parsing a method declaration.Endpoint for ANTLR to call after parsing a method declaration, making any method "public" that has:
- no other access modifier
- return type "void"
- is either in the context of the sketch class
- is in the context of a class definition that extends PApplet
- Specified by:
exitMethodDeclarationin interfaceProcessingListener- Overrides:
exitMethodDeclarationin classProcessingBaseListener- Parameters:
ctx- ANTLR context for the method declaration
-
exitFunctionWithPrimitiveTypeName
public void exitFunctionWithPrimitiveTypeName(ProcessingParser.FunctionWithPrimitiveTypeNameContext ctx) Endpoint for ANTLR to call after parsing a primitive type name.Endpoint for ANTLR to call after parsing a primitive type name, possibly converting that type to a parse function as part of the Processing API.
- Specified by:
exitFunctionWithPrimitiveTypeNamein interfaceProcessingListener- Overrides:
exitFunctionWithPrimitiveTypeNamein classProcessingBaseListener- Parameters:
ctx- ANTLR context for the primitive name token.
-
exitColorPrimitiveType
Endpoint for ANTLR to call after parsing a color primitive token.Endpoint for ANTLR to call after parsing a color primitive token, fixing "color type" to be "int" as part of the processing API.
- Specified by:
exitColorPrimitiveTypein interfaceProcessingListener- Overrides:
exitColorPrimitiveTypein classProcessingBaseListener- Parameters:
ctx- ANTLR context for the type token.
-
exitHexColorLiteral
Endpoint for ANTLR to call after parsing a hex color literal.- Specified by:
exitHexColorLiteralin interfaceProcessingListener- Overrides:
exitHexColorLiteralin classProcessingBaseListener- Parameters:
ctx- ANTLR context for the literal.
-
handleSizeCall
protected void handleSizeCall(org.antlr.v4.runtime.ParserRuleContext ctx) Manage parsing out a size or fullscreen call.The size call will need to be rewritten if it is in global or setup, having it hoisted up to settings body.
- Parameters:
ctx- The context of the call.
-
handlePixelDensityCall
protected void handlePixelDensityCall(org.antlr.v4.runtime.ParserRuleContext ctx) -
handleNoSmoothCall
protected void handleNoSmoothCall(org.antlr.v4.runtime.ParserRuleContext ctx) -
handleSmoothCall
protected void handleSmoothCall(org.antlr.v4.runtime.ParserRuleContext ctx) -
calledFromGlobalOrSetup
protected boolean calledFromGlobalOrSetup(org.antlr.v4.runtime.ParserRuleContext callContext) -
isMethodSetup
protected boolean isMethodSetup(org.antlr.v4.runtime.ParserRuleContext declaration) Determine if a method declaration is for setup.- Parameters:
declaration- The method declaration to parse.- Returns:
- True if setup and false otherwise.
-
isAnnotation
Check if this contains an annation.- Parameters:
context- The modifier context to check.- Returns:
- True if annotation. False otherwise
-
insertBefore
Insert text before a token.- Parameters:
location- The token before which code should be added.text- The text to add.
-
insertBefore
Insert text before a location in code.- Parameters:
locationToken- Character offset from start.locationOffset-text- Text to add.
-
insertAfter
Insert text after a location in code.- Parameters:
location- The token after which to insert code.text- The text to insert.
-
delete
protected void delete(org.antlr.v4.runtime.Token start, org.antlr.v4.runtime.Token stop) Delete from a token to a token inclusive.- Parameters:
start- First token to delete.stop- Last token to delete.
-
delete
protected void delete(org.antlr.v4.runtime.Token location) Delete a single token.- Parameters:
location- Token to delete.
-
prepareHeader
Prepare preface code to wrap sketch code so that it is contained within a proper Java definition.- Parameters:
headerWriter- The writer into which the header should be written.- Returns:
- Information about the completed rewrite.
-
writeHeaderContents
protected void writeHeaderContents(PdeParseTreeListener.PrintWriterWithEditGen decoratedWriter, RewriteResultBuilder resultBuilder) Write the contents of the header using a prebuilt print writer.- Parameters:
decoratedWriter- he writer though which the comment should be introduced.resultBuilder- Builder for reporting out results to the caller.
-
writePreprocessorComment
protected void writePreprocessorComment(PdeParseTreeListener.PrintWriterWithEditGen headerWriter, RewriteResultBuilder resultBuilder) Comment out sketch code before it is moved elsewhere in resulting Java.- Parameters:
headerWriter- The writer though which the comment should be introduced.resultBuilder- Builder for reporting out results to the caller.
-
writeImports
protected void writeImports(PdeParseTreeListener.PrintWriterWithEditGen headerWriter, RewriteResultBuilder resultBuilder) Add imports as part of conversion from processing sketch to Java code.- Parameters:
headerWriter- The writer though which the imports should be introduced.resultBuilder- Builder for reporting out results to the caller.
-
writeImportList
protected void writeImportList(PdeParseTreeListener.PrintWriterWithEditGen headerWriter, List<ImportStatement> imports, RewriteResultBuilder resultBuilder) Write a list of imports.- Parameters:
headerWriter- The writer though which the imports should be introduced.imports- Collection of imports to introduce.resultBuilder- Builder for reporting out results to the caller.
-
writeImportList
protected void writeImportList(PdeParseTreeListener.PrintWriterWithEditGen headerWriter, ImportStatement[] imports, RewriteResultBuilder resultBuilder) Write a list of imports.- Parameters:
headerWriter- The writer though which the imports should be introduced.imports- Collection of imports to introduce.resultBuilder- Builder for reporting out results to the caller.
-
writeClassHeader
protected void writeClassHeader(PdeParseTreeListener.PrintWriterWithEditGen headerWriter, RewriteResultBuilder resultBuilder) Write the prefix which defines the enclosing class for the sketch.- Parameters:
headerWriter- The writer through which the header should be introduced.resultBuilder- Builder for reporting out results to the caller.
-
writeStaticSketchHeader
protected void writeStaticSketchHeader(PdeParseTreeListener.PrintWriterWithEditGen headerWriter, RewriteResultBuilder resultBuilder) Write the header for a static sketch (no methods).- Parameters:
headerWriter- The writer through which the header should be introduced.resultBuilder- Builder for reporting out results to the caller.
-
writeExtraFieldsAndMethods
protected void writeExtraFieldsAndMethods(PdeParseTreeListener.PrintWriterWithEditGen classBodyWriter, RewriteResultBuilder resultBuilder) Write code supporting special functions like size.- Parameters:
classBodyWriter- The writer into which the code should be written. Should be for class body.resultBuilder- Builder for reporting out results to the caller.
-
writeMain
protected void writeMain(PdeParseTreeListener.PrintWriterWithEditGen footerWriter, RewriteResultBuilder resultBuilder) Write the main method.- Parameters:
footerWriter- The writer into which the footer should be written.resultBuilder- Builder for reporting out results to the caller.
-
createDelete
protected static TextTransform.Edit createDelete(org.antlr.v4.runtime.Token start, org.antlr.v4.runtime.Token stop, org.antlr.v4.runtime.TokenStreamRewriter rewriter) Delete tokens between a start end end token inclusive.- Parameters:
start- The token to be deleted.stop- The final token to be deleted.rewriter- The rewriter with which to make the edit.- Returns:
- The {TextTransform.Edit} corresponding to this change.
-
createInsertAfter
protected static TextTransform.Edit createInsertAfter(org.antlr.v4.runtime.Token start, String text, org.antlr.v4.runtime.TokenStreamRewriter rewriter) Insert text after a token.- Parameters:
start- The token after which the text should be inserted.text- The text to insert.rewriter- The rewriter with which to make the edit.- Returns:
- The {TextTransform.Edit} corresponding to this change.
-
createInsertBefore
protected static TextTransform.Edit createInsertBefore(org.antlr.v4.runtime.Token before, String text, org.antlr.v4.runtime.TokenStreamRewriter rewriter) Insert text before a token.- Parameters:
before- Token before which the text should be inserted.text- The text to insert.rewriter- The rewriter with which to make the edit.- Returns:
- The {TextTransform.Edit} corresponding to this change.
-
createInsertBefore
protected static TextTransform.Edit createInsertBefore(int before, int beforeOffset, String text, org.antlr.v4.runtime.TokenStreamRewriter rewriter) Insert text before a position in code.- Parameters:
before- The location before which to insert the text in tokens.beforeOffset- THe location before which to insert the text in chars.text- The text to insert.rewriter- The rewriter with which to make the edit.- Returns:
- The {TextTransform.Edit} corresponding to this change.
-
insertAfter
protected static TextTransform.Edit insertAfter(int start, String text, org.antlr.v4.runtime.TokenStreamRewriter rewriter) Insert text after a token.- Parameters:
start- The position after which the text should be inserted.text- The text to insert.rewriter- The rewriter with which to make the edit.- Returns:
- The {TextTransform.Edit} corresponding to this change.
-
createDelete
protected static TextTransform.Edit createDelete(org.antlr.v4.runtime.Token start, org.antlr.v4.runtime.TokenStreamRewriter rewriter) Delete a single token.- Parameters:
start- The token to be deleted.rewriter- The rewriter with which to make the edit.- Returns:
- The {TextTransform.Edit} corresponding to this change.
-