You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by lk...@apache.org on 2020/06/18 23:05:30 UTC

[netbeans] branch master updated: [NETBEANS-4431]: Added option to create new file in Java project as record type

This is an automated email from the ASF dual-hosted git repository.

lkishalmi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 081d26f  [NETBEANS-4431]: Added option to create new file in Java project as record type
081d26f is described below

commit 081d26f13f2d0fa3ba1d89d8767ce2067d8f6cec
Author: Arunava Sinha <ar...@oracle.com>
AuthorDate: Fri Jun 12 15:32:16 2020 +0530

    [NETBEANS-4431]: Added option to create new file in Java project as record type
---
 .../java/project/ui/NewJavaFileWizardIterator.java |  7 +++--
 .../modules/java/project/ui/resources/Record.html  | 30 ++++++++++++++++++++++
 .../java/project/ui/resources/Record.java.template | 16 ++++++++++++
 .../NewFileWizardTest/testCreateRecord.pass        | 14 ++++++++++
 .../org/netbeans/test/java/gui/GuiUtilities.java   |  4 +--
 .../test/java/gui/wizards/NewFileWizardTest.java   |  6 +++++
 6 files changed, 73 insertions(+), 4 deletions(-)

diff --git a/java/java.project.ui/src/org/netbeans/modules/java/project/ui/NewJavaFileWizardIterator.java b/java/java.project.ui/src/org/netbeans/modules/java/project/ui/NewJavaFileWizardIterator.java
index edcc561..814ac13 100644
--- a/java/java.project.ui/src/org/netbeans/modules/java/project/ui/NewJavaFileWizardIterator.java
+++ b/java/java.project.ui/src/org/netbeans/modules/java/project/ui/NewJavaFileWizardIterator.java
@@ -77,7 +77,8 @@ import org.openide.util.NbBundle;
     @TemplateRegistration(folder = NewJavaFileWizardIterator.FOLDER, position = 800, content = "resources/Applet.java.template", scriptEngine = "freemarker", displayName = "#Applet.java", iconBase = JavaTemplates.JAVA_ICON, description = "resources/Applet.html", category = "java-classes"),
     @TemplateRegistration(folder = NewJavaFileWizardIterator.FOLDER, position = 900, content = "resources/Main.java.template", scriptEngine = "freemarker", displayName = "#Main.java", iconBase = "org/netbeans/modules/java/project/ui/resources/main-class.png", description = "resources/Main.html", category = "java-main-class"),
     @TemplateRegistration(folder = NewJavaFileWizardIterator.FOLDER, position = 950, content = "resources/Singleton.java.template", scriptEngine = "freemarker", displayName = "#Singleton.java", iconBase = JavaTemplates.JAVA_ICON, description = "resources/Singleton.html", category = "java-classes"),
-    @TemplateRegistration(folder = NewJavaFileWizardIterator.FOLDER, position = 1000, content = "resources/Empty.java.template", scriptEngine = "freemarker", displayName = "#Empty.java", iconBase = JavaTemplates.JAVA_ICON, description = "resources/Empty.html", category = {"java-classes", "java-classes-basic"})
+    @TemplateRegistration(folder = NewJavaFileWizardIterator.FOLDER, position = 1000, content = "resources/Empty.java.template", scriptEngine = "freemarker", displayName = "#Empty.java", iconBase = JavaTemplates.JAVA_ICON, description = "resources/Empty.html", category = {"java-classes", "java-classes-basic"}),
+    @TemplateRegistration(folder = NewJavaFileWizardIterator.FOLDER, position = 1150, content = "resources/Record.java.template", scriptEngine = "freemarker", displayName = "#Record.java", iconBase = JavaTemplates.JAVA_ICON, description = "resources/Record.html", category = {"java-classes", NewJavaFileWizardIterator.JDK_14}),
 })
 @Messages({
     "Class.java=Java Class",
@@ -89,7 +90,8 @@ import org.openide.util.NbBundle;
     "Applet.java=Applet",
     "Main.java=Java Main Class",
     "Singleton.java=Java Singleton Class",
-    "Empty.java=Empty Java File"
+    "Empty.java=Empty Java File",
+    "Record.java=Java Record"
 })
 public class NewJavaFileWizardIterator implements WizardDescriptor.AsynchronousInstantiatingIterator<WizardDescriptor> {
 
@@ -99,6 +101,7 @@ public class NewJavaFileWizardIterator implements WizardDescriptor.AsynchronousI
 
     static final String JDK_5 = "jdk5";
     static final String JDK_9 = "jdk9";
+    static final String JDK_14 = "jdk14";
     
     private static final long serialVersionUID = 1L;
 
diff --git a/java/java.project.ui/src/org/netbeans/modules/java/project/ui/resources/Record.html b/java/java.project.ui/src/org/netbeans/modules/java/project/ui/resources/Record.html
new file mode 100644
index 0000000..a00d43e
--- /dev/null
+++ b/java/java.project.ui/src/org/netbeans/modules/java/project/ui/resources/Record.html
@@ -0,0 +1,30 @@
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+-->
+
+<html>
+<head>
+	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+</head>
+<BODY>
+Creates a new Java record file. To be able to use record files, your project must use
+JDK 14.0 or compatible.
+
+</BODY></HTML>
diff --git a/java/java.project.ui/src/org/netbeans/modules/java/project/ui/resources/Record.java.template b/java/java.project.ui/src/org/netbeans/modules/java/project/ui/resources/Record.java.template
new file mode 100644
index 0000000..7d68960
--- /dev/null
+++ b/java/java.project.ui/src/org/netbeans/modules/java/project/ui/resources/Record.java.template
@@ -0,0 +1,16 @@
+<#assign licenseFirst = "/*">
+<#assign licensePrefix = " * ">
+<#assign licenseLast = " */">
+<#include "${project.licensePath}">
+
+<#if package?? && package != "">
+package ${package};
+
+</#if>
+/**
+ *
+ * @author ${user}
+ */
+public record ${name}() {
+
+}
diff --git a/java/java.source/test/qa-functional/data/goldenfiles/org/netbeans/test/java/gui/wizards/NewFileWizardTest/testCreateRecord.pass b/java/java.source/test/qa-functional/data/goldenfiles/org/netbeans/test/java/gui/wizards/NewFileWizardTest/testCreateRecord.pass
new file mode 100644
index 0000000..a8eb9dd
--- /dev/null
+++ b/java/java.source/test/qa-functional/data/goldenfiles/org/netbeans/test/java/gui/wizards/NewFileWizardTest/testCreateRecord.pass
@@ -0,0 +1,14 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package test;
+
+/**
+ *
+ * @author jp159440
+ */
+public record MyRecord() {
+
+}
diff --git a/java/java.source/test/qa-functional/src/org/netbeans/test/java/gui/GuiUtilities.java b/java/java.source/test/qa-functional/src/org/netbeans/test/java/gui/GuiUtilities.java
index d1fef05..20450ee 100644
--- a/java/java.source/test/qa-functional/src/org/netbeans/test/java/gui/GuiUtilities.java
+++ b/java/java.source/test/qa-functional/src/org/netbeans/test/java/gui/GuiUtilities.java
@@ -92,7 +92,7 @@ public class GuiUtilities {
             for (int j=0; j<jto.getChildCount(jto.getRoot()); j++) {
                 if (jto.getChild(jto.getRoot(), j).toString() == Bundle.getString(
                         "org.netbeans.modules.java.j2seproject.ui.wizards.Bundle",
-                        "Templates/Project/Standard")) {
+                        "Templates/Project/AntJava")) {
                     exitLoop = true;
                     System.out.println("General found");
                     break;
@@ -103,7 +103,7 @@ public class GuiUtilities {
         
         new Node(jto, Bundle.getString(
                 "org.netbeans.modules.java.j2seproject.ui.wizards.Bundle",
-                "Templates/Project/Standard")).select();
+                "Templates/Project/AntJava")).select();
         // java project
         opc.selectProject(Bundle.getString(
                 "org.netbeans.modules.java.j2seproject.ui.wizards.Bundle",
diff --git a/java/java.source/test/qa-functional/src/org/netbeans/test/java/gui/wizards/NewFileWizardTest.java b/java/java.source/test/qa-functional/src/org/netbeans/test/java/gui/wizards/NewFileWizardTest.java
index b692b9b..5768c38 100644
--- a/java/java.source/test/qa-functional/src/org/netbeans/test/java/gui/wizards/NewFileWizardTest.java
+++ b/java/java.source/test/qa-functional/src/org/netbeans/test/java/gui/wizards/NewFileWizardTest.java
@@ -291,6 +291,12 @@ public class NewFileWizardTest extends JavaTestCase {
                 Common.unify(expected),true);
     }
     
+    public void testCreateRecord() {
+        String expected = getContentOfGoldenFile();
+        createAndVerify("MyRecord", "Java Record",
+                Common.unify(expected), true);
+    }
+    
     public void testCreateException() {
         String expected = getContentOfGoldenFile();
         createAndVerify("MyExp" ,"Java Exception",


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists