Skip to content
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

Netbeans code templates - string functions #4621

Open
zeleznypa opened this issue Sep 11, 2022 · 2 comments
Open

Netbeans code templates - string functions #4621

zeleznypa opened this issue Sep 11, 2022 · 2 comments
Labels
Editor Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) kind:feature A feature request pending-response Awaiting further information to be supplied

Comments

@zeleznypa
Copy link

zeleznypa commented Sep 11, 2022

Description

Netbeans contains great tool „code templates“ that allows me to simplify my work.

For many years I missed last functionality for the perfection, which is some additional string function.

Use case/motivation

For example, I have at this time the following code template:

    /**
     * ${PARAMETER newVarName default="Parameter"} getter
     *
     * @return ${TYPE newVarName default="Parameter"}
     */
    protected function get${PARAMETER editable=false}(): ${TYPE editable=false}
    {
        return $this->${PROPERTY newVarName default="parameter"};
    }

    /**
     * ${PARAMETER editable=false} setter
     *
     * @param ${TYPE editable=false} $$${PROPERTY editable=false}
     * @return static Provides fluent interface
     */
    protected function set${PARAMETER editable=false}(${TYPE editable=false} $$${PROPERTY editable=false})
    {
        $this->${PROPERTY editable=false} = $$${PROPERTY editable=false};
        return $this;
    }

That allows me to quickly generate the code of generic getter & setter and simply replace the name ${PARAMETER} with the real one. After that I have to replace the name ${PROPERTY} which should be the same like ${PARAMETER} but with the first letter lowercase.

Will it be possible please to add functionalities like:

  • lower case all
  • lower case first letter
  • upper case all
  • upper case first letter
  • replace something with something
  • replace something with something by regexp?

Related issues

No response

Are you willing to submit a pull request?

I want to, but I'm not a Java developer

Code of Conduct

Yes

@zeleznypa zeleznypa added kind:feature A feature request needs:triage Requires attention from one of the committers labels Sep 11, 2022
@mbien mbien added pending-response Awaiting further information to be supplied Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) Editor and removed needs:triage Requires attention from one of the committers labels May 25, 2024
@mbien
Copy link
Member

mbien commented May 25, 2024

the templates should be https://freemarker.apache.org/ templates.

I haven't tried it but it should already work, no?

e.g: https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_c_lower_case

@zeleznypa
Copy link
Author

@mbien It will be nice but I don't know how to use them :(

I have tried the following codes:

${PARAMETER newVarName default="Parameter"}
${PARAMETER editable=false?uncap_first}
${PARAMETER newVarName default="Parameter"}
${${PARAMETER editable=false}?uncap_first}

And then use them in the code, but it will lead in exception:

java.lang.NullPointerException: Cannot invoke "String.hashCode()" because "<local4>" is null
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.visit(SemiAttribute.java:534)
	at org.netbeans.modules.php.editor.parser.astnodes.StaticConstantAccess.accept(StaticConstantAccess.java:90)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:143)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.scan(SemiAttribute.java:128)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:150)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.visit(SemiAttribute.java:397)
	at org.netbeans.modules.php.editor.parser.astnodes.FunctionInvocation.accept(FunctionInvocation.java:70)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:143)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.scan(SemiAttribute.java:128)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.visit(DefaultVisitor.java:492)
	at org.netbeans.modules.php.editor.parser.astnodes.MethodInvocation.accept(MethodInvocation.java:57)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:143)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.scan(SemiAttribute.java:128)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.visit(DefaultVisitor.java:491)
	at org.netbeans.modules.php.editor.parser.astnodes.MethodInvocation.accept(MethodInvocation.java:57)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:143)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.scan(SemiAttribute.java:128)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.visit(DefaultVisitor.java:341)
	at org.netbeans.modules.php.editor.parser.astnodes.ExpressionStatement.accept(ExpressionStatement.java:51)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:143)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.scan(SemiAttribute.java:128)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:150)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.visit(DefaultVisitor.java:212)
	at org.netbeans.modules.php.editor.parser.astnodes.Block.accept(Block.java:70)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:143)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.scan(SemiAttribute.java:128)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.visit(DefaultVisitor.java:423)
	at org.netbeans.modules.php.editor.parser.astnodes.IfStatement.accept(IfStatement.java:85)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:143)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.scan(SemiAttribute.java:128)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.visit(DefaultVisitor.java:424)
	at org.netbeans.modules.php.editor.parser.astnodes.IfStatement.accept(IfStatement.java:85)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:143)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.scan(SemiAttribute.java:128)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:150)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.visit(DefaultVisitor.java:212)
	at org.netbeans.modules.php.editor.parser.astnodes.Block.accept(Block.java:70)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:143)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.scan(SemiAttribute.java:128)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.visit(DefaultVisitor.java:372)
	at org.netbeans.modules.php.editor.parser.astnodes.ForEachStatement.accept(ForEachStatement.java:96)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:143)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.scan(SemiAttribute.java:128)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:150)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.visit(DefaultVisitor.java:212)
	at org.netbeans.modules.php.editor.parser.astnodes.Block.accept(Block.java:70)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:143)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.scan(SemiAttribute.java:128)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.visit(DefaultVisitor.java:397)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.visit(SemiAttribute.java:205)
	at org.netbeans.modules.php.editor.parser.astnodes.FunctionDeclaration.accept(FunctionDeclaration.java:144)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:143)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.scan(SemiAttribute.java:128)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.visit(DefaultVisitor.java:486)
	at org.netbeans.modules.php.editor.parser.astnodes.MethodDeclaration.accept(MethodDeclaration.java:73)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:143)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.scan(SemiAttribute.java:128)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:150)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.visit(DefaultVisitor.java:212)
	at org.netbeans.modules.php.editor.parser.astnodes.Block.accept(Block.java:70)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:143)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.scan(SemiAttribute.java:128)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.visit(DefaultVisitor.java:253)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.visit(SemiAttribute.java:453)
	at org.netbeans.modules.php.editor.parser.astnodes.ClassDeclaration.accept(ClassDeclaration.java:140)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:143)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.scan(SemiAttribute.java:128)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:150)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.visit(DefaultVisitor.java:212)
	at org.netbeans.modules.php.editor.parser.astnodes.Block.accept(Block.java:70)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:143)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.scan(SemiAttribute.java:128)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.visit(DefaultVisitor.java:687)
	at org.netbeans.modules.php.editor.parser.astnodes.NamespaceDeclaration.accept(NamespaceDeclaration.java:88)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:143)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.scan(SemiAttribute.java:128)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:150)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.visit(DefaultVisitor.java:518)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.visit(SemiAttribute.java:140)
	at org.netbeans.modules.php.editor.parser.astnodes.Program.accept(Program.java:67)
	at org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor.scan(DefaultVisitor.java:143)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.scan(SemiAttribute.java:128)
	at org.netbeans.modules.php.editor.codegen.SemiAttribute.semiAttribute(SemiAttribute.java:826)
	at org.netbeans.modules.php.editor.codegen.ASTNodeUtilities.getVariablesInScope(ASTNodeUtilities.java:49)
	at org.netbeans.modules.php.editor.codegen.PHPCodeTemplateProcessor.newVarName(PHPCodeTemplateProcessor.java:254)
	at org.netbeans.modules.php.editor.codegen.PHPCodeTemplateProcessor.getProposedValue(PHPCodeTemplateProcessor.java:163)
	at org.netbeans.modules.php.editor.codegen.PHPCodeTemplateProcessor.updateDefaultValues(PHPCodeTemplateProcessor.java:85)
	at org.netbeans.lib.editor.codetemplates.CodeTemplateInsertHandler.processTemplate(CodeTemplateInsertHandler.java:226)
	at org.netbeans.lib.editor.codetemplates.CodeTemplateManagerOperation.insert(CodeTemplateManagerOperation.java:273)
	at org.netbeans.lib.editor.codetemplates.api.CodeTemplate.insert(CodeTemplate.java:82)
	at org.netbeans.lib.editor.codetemplates.AbbrevDetection.expand(AbbrevDetection.java:517)
	at org.netbeans.lib.editor.codetemplates.AbbrevDetection.expand(AbbrevDetection.java:411)
	at org.netbeans.lib.editor.codetemplates.AbbrevDetection.checkExpansionKeystroke(AbbrevDetection.java:315)
	at org.netbeans.lib.editor.codetemplates.AbbrevDetection.keyPressed(AbbrevDetection.java:267)
	at java.desktop/java.awt.AWTEventMulticaster.keyPressed(AWTEventMulticaster.java:258)
	at java.desktop/java.awt.AWTEventMulticaster.keyPressed(AWTEventMulticaster.java:257)
	at java.desktop/java.awt.AWTEventMulticaster.keyPressed(AWTEventMulticaster.java:257)
	at java.desktop/java.awt.Component.processKeyEvent(Component.java:6579)
	at java.desktop/javax.swing.JComponent.processKeyEvent(JComponent.java:2905)
	at java.desktop/java.awt.Component.processEvent(Component.java:6398)
	at java.desktop/java.awt.Container.processEvent(Container.java:2266)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4996)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4828)
	at java.desktop/java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1942)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:883)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1146)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:1020)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:848)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4877)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2780)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4828)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:775)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:98)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:747)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:744)
	at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:136)
[catch] at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Editor Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) kind:feature A feature request pending-response Awaiting further information to be supplied
Projects
None yet
Development

No branches or pull requests

2 participants