You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2020/03/16 06:55:27 UTC
[GitHub] [netbeans] Akshay-Gupta-Oracle opened a new pull request #2020:
[NETBEANS-3986] Creating New Class On Pasting Class Text
Akshay-Gupta-Oracle opened a new pull request #2020: [NETBEANS-3986] Creating New Class On Pasting Class Text
URL: https://github.com/apache/netbeans/pull/2020
This PR supports copying raw java text from anywhere(inside or outside of Netbeans) and pasting directly to a package to create a new class automatically. Copied text should have a valid syntax and should start with a **public class** followed by class name.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lahodaj commented on a change in pull request #2020:
[NETBEANS-3986] Creating New Class On Pasting Class Text
Posted by GitBox <gi...@apache.org>.
lahodaj commented on a change in pull request #2020: [NETBEANS-3986] Creating New Class On Pasting Class Text
URL: https://github.com/apache/netbeans/pull/2020#discussion_r393000358
##########
File path: java/java.project.ui/src/org/netbeans/spi/java/project/support/ui/CreateClassAndCopy.java
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.
+ */
+package org.netbeans.spi.java.project.support.ui;
+
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.lang.model.SourceVersion;
+import javax.swing.JOptionPane;
+import org.openide.actions.PasteAction;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionRegistration;
+import org.openide.explorer.ExplorerManager;
+import org.openide.filesystems.FileObject;
+import org.openide.loaders.DataFolder;
+import org.openide.nodes.Node;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+
+@ActionID(
+ category = "Build",
+ id = "org.netbeans.spi.java.project.support.ui.CreateClassAndCopy"
+)
+@ActionRegistration(
+ displayName = "#CTL_CreateClassAndCopy"
+)
+@ActionReference(path = "Loaders/folder/any/Actions", position = 750)
+@Messages("CTL_CreateClassAndCopy=PasteClass")
+public final class CreateClassAndCopy implements ActionListener {
+
+ private final DataFolder context;
+
+ public CreateClassAndCopy(DataFolder context) {
+ this.context = context;
+ }
+
+ static ExplorerManager findExplorerManager() {
Review comment:
I am unclear why finding ExplorerManager is needed - isn't "context" enough? I.e. shouldn't be paste simply happen "under" the given DataFolder?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] ebarboni commented on issue #2020: [NETBEANS-3986]
Creating New Class On Pasting Class Text
Posted by GitBox <gi...@apache.org>.
ebarboni commented on issue #2020: [NETBEANS-3986] Creating New Class On Pasting Class Text
URL: https://github.com/apache/netbeans/pull/2020#issuecomment-599551082
my bad did a merge a few hour later. I did a revert. I think this PR has to be recreated.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lahodaj commented on a change in pull request #2020:
[NETBEANS-3986] Creating New Class On Pasting Class Text
Posted by GitBox <gi...@apache.org>.
lahodaj commented on a change in pull request #2020: [NETBEANS-3986] Creating New Class On Pasting Class Text
URL: https://github.com/apache/netbeans/pull/2020#discussion_r393007526
##########
File path: java/java.project.ui/src/org/netbeans/spi/java/project/support/ui/CreateClassAndCopy.java
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.
+ */
+package org.netbeans.spi.java.project.support.ui;
+
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.lang.model.SourceVersion;
+import javax.swing.JOptionPane;
+import org.openide.actions.PasteAction;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionRegistration;
+import org.openide.explorer.ExplorerManager;
+import org.openide.filesystems.FileObject;
+import org.openide.loaders.DataFolder;
+import org.openide.nodes.Node;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+
+@ActionID(
+ category = "Build",
+ id = "org.netbeans.spi.java.project.support.ui.CreateClassAndCopy"
+)
+@ActionRegistration(
+ displayName = "#CTL_CreateClassAndCopy"
+)
+@ActionReference(path = "Loaders/folder/any/Actions", position = 750)
+@Messages("CTL_CreateClassAndCopy=PasteClass")
+public final class CreateClassAndCopy implements ActionListener {
+
+ private final DataFolder context;
+
+ public CreateClassAndCopy(DataFolder context) {
+ this.context = context;
+ }
+
+ static ExplorerManager findExplorerManager() {
+ Throwable t = null;
+
+ try {
+ Class c = Class.forName("org.openide.windows.TopComponent"); // NOI18N
+
+ // use reflection now
+ Method m = c.getMethod("getRegistry"); // NOI18N
+ Object o = m.invoke(null);
+
+ c = Class.forName("org.openide.windows.TopComponent$Registry"); // NOI18N
+
+ // use reflection now
+ m = c.getMethod("getActivated"); // NOI18N
+ o = m.invoke(o);
+
+ if (o instanceof ExplorerManager.Provider) {
+ return ((ExplorerManager.Provider) o).getExplorerManager();
+ }
+ } // exceptions from forName:
+ catch (ClassNotFoundException x) {
+ } catch (ExceptionInInitializerError x) {
+ } catch (LinkageError x) {
+ } // exceptions from getMethod:
+ catch (SecurityException x) {
+ t = x;
+ } catch (NoSuchMethodException x) {
+ t = x;
+ } // exceptions from invoke
+ catch (IllegalAccessException x) {
+ t = x;
+ } catch (IllegalArgumentException x) {
+ t = x;
+ } catch (InvocationTargetException x) {
+ t = x;
+ }
+
+ if (t != null) {
+ Logger.getLogger(PasteAction.class.getName()).log(Level.WARNING, null, t);
+ }
+
+ return null;
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent ev) {
+ try {
+ Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
+ if(!c.isDataFlavorAvailable(DataFlavor.stringFlavor))return;
+ boolean containsClass = false;
+ String data = (String) c.getData(DataFlavor.stringFlavor);
+ String className = "";
Review comment:
I wonder if it wouldn't be easier to let some (Java) parser parse the class, and analyze the output. Something as simple as:
((JavacTask) javax.tools.ToolProvider.getSystemJavaCompiler().getTask(...)).parse()
might give much better outcomes, and is unlikely to be problematic w.r.t. performance (parse is typically very fast). The only parameter that really needs to be filled in for getTask is the last one, and it may be a singleton list with a very simple JavaFileObject, like this one:
https://github.com/apache/netbeans/blob/5f675e88a3ae3fee652332f9faf2f1985508c272/java/lib.nbjavac/test/unit/src/org/netbeans/lib/nbjavac/services/NBClassWriterTest.java#L61
(Passing the "out" Writer and passing the output to "/dev/null" is probably a good idea, as well, but not needed for the functionality to work.)
As far as I can tell, the code here won't work if:
-there are any imports
-or annotations
-or the class is non-public
-or if the thing that is being pasted is an interface, enum, annotation type (or record)
-or if there's any other modifier for the class (not a big factor right now, as probably only "strictfp" could be here).
This feels unnecessarily limited.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lahodaj commented on a change in pull request #2020:
[NETBEANS-3986] Creating New Class On Pasting Class Text
Posted by GitBox <gi...@apache.org>.
lahodaj commented on a change in pull request #2020: [NETBEANS-3986] Creating New Class On Pasting Class Text
URL: https://github.com/apache/netbeans/pull/2020#discussion_r393009647
##########
File path: java/java.project.ui/src/org/netbeans/spi/java/project/support/ui/CreateClassAndCopy.java
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.
+ */
+package org.netbeans.spi.java.project.support.ui;
+
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.lang.model.SourceVersion;
+import javax.swing.JOptionPane;
+import org.openide.actions.PasteAction;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionRegistration;
+import org.openide.explorer.ExplorerManager;
+import org.openide.filesystems.FileObject;
+import org.openide.loaders.DataFolder;
+import org.openide.nodes.Node;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+
+@ActionID(
+ category = "Build",
+ id = "org.netbeans.spi.java.project.support.ui.CreateClassAndCopy"
+)
+@ActionRegistration(
+ displayName = "#CTL_CreateClassAndCopy"
+)
+@ActionReference(path = "Loaders/folder/any/Actions", position = 750)
+@Messages("CTL_CreateClassAndCopy=PasteClass")
+public final class CreateClassAndCopy implements ActionListener {
+
+ private final DataFolder context;
+
+ public CreateClassAndCopy(DataFolder context) {
+ this.context = context;
+ }
+
+ static ExplorerManager findExplorerManager() {
+ Throwable t = null;
+
+ try {
+ Class c = Class.forName("org.openide.windows.TopComponent"); // NOI18N
+
+ // use reflection now
+ Method m = c.getMethod("getRegistry"); // NOI18N
+ Object o = m.invoke(null);
+
+ c = Class.forName("org.openide.windows.TopComponent$Registry"); // NOI18N
+
+ // use reflection now
+ m = c.getMethod("getActivated"); // NOI18N
+ o = m.invoke(o);
+
+ if (o instanceof ExplorerManager.Provider) {
+ return ((ExplorerManager.Provider) o).getExplorerManager();
+ }
+ } // exceptions from forName:
+ catch (ClassNotFoundException x) {
+ } catch (ExceptionInInitializerError x) {
+ } catch (LinkageError x) {
+ } // exceptions from getMethod:
+ catch (SecurityException x) {
+ t = x;
+ } catch (NoSuchMethodException x) {
+ t = x;
+ } // exceptions from invoke
+ catch (IllegalAccessException x) {
+ t = x;
+ } catch (IllegalArgumentException x) {
+ t = x;
+ } catch (InvocationTargetException x) {
+ t = x;
+ }
+
+ if (t != null) {
+ Logger.getLogger(PasteAction.class.getName()).log(Level.WARNING, null, t);
+ }
+
+ return null;
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent ev) {
+ try {
+ Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
+ if(!c.isDataFlavorAvailable(DataFlavor.stringFlavor))return;
+ boolean containsClass = false;
+ String data = (String) c.getData(DataFlavor.stringFlavor);
+ String className = "";
+ String uncommented = data.replaceAll("(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/)|(?://.*)","");// NOI18N
+ uncommented = uncommented.trim();
+ StringTokenizer st = new StringTokenizer(uncommented, " ");// NOI18N
+ if (st.hasMoreTokens() && st.nextToken().equals("public") && st.hasMoreTokens() && st.nextToken().equals("class") && st.hasMoreTokens()) {// NOI18N
+ String cname = st.nextToken().trim();
+ if (cname.charAt(cname.length() - 1) == '{') {
+ cname = cname.substring(0, cname.length() - 1);
+ }
+ if (SourceVersion.isIdentifier(cname)) {
+ containsClass = true;
+ className = cname;
+ }
+ }
+ if (!containsClass) {
+ JOptionPane.showMessageDialog(null, "Code not valid to create class");
+ return;
+ }
+ Set<FileObject> files = this.context.files();
+ if (files.size() != 1) {
+ return;
+ }
+ String path = files.iterator().next().getPath();
+ String packageName = "";
+ File f = new File(path + "\\" + className + ".java");// NOI18N
Review comment:
Using:
File f = new File(path + "\\" + className + ".java");// NOI18N
will clearly not work on Linux, and probably not on Mac - the file separator for these is '/'. I would suggest to simply using FileObject all the way, unless there is a really compelling reason to not to.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lahodaj commented on a change in pull request #2020:
[NETBEANS-3986] Creating New Class On Pasting Class Text
Posted by GitBox <gi...@apache.org>.
lahodaj commented on a change in pull request #2020: [NETBEANS-3986] Creating New Class On Pasting Class Text
URL: https://github.com/apache/netbeans/pull/2020#discussion_r393010876
##########
File path: java/java.project.ui/src/org/netbeans/spi/java/project/support/ui/CreateClassAndCopy.java
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.
+ */
+package org.netbeans.spi.java.project.support.ui;
+
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.lang.model.SourceVersion;
+import javax.swing.JOptionPane;
+import org.openide.actions.PasteAction;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionRegistration;
+import org.openide.explorer.ExplorerManager;
+import org.openide.filesystems.FileObject;
+import org.openide.loaders.DataFolder;
+import org.openide.nodes.Node;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+
+@ActionID(
+ category = "Build",
+ id = "org.netbeans.spi.java.project.support.ui.CreateClassAndCopy"
+)
+@ActionRegistration(
+ displayName = "#CTL_CreateClassAndCopy"
+)
+@ActionReference(path = "Loaders/folder/any/Actions", position = 750)
+@Messages("CTL_CreateClassAndCopy=PasteClass")
+public final class CreateClassAndCopy implements ActionListener {
+
+ private final DataFolder context;
+
+ public CreateClassAndCopy(DataFolder context) {
+ this.context = context;
+ }
+
+ static ExplorerManager findExplorerManager() {
+ Throwable t = null;
+
+ try {
+ Class c = Class.forName("org.openide.windows.TopComponent"); // NOI18N
+
+ // use reflection now
+ Method m = c.getMethod("getRegistry"); // NOI18N
+ Object o = m.invoke(null);
+
+ c = Class.forName("org.openide.windows.TopComponent$Registry"); // NOI18N
+
+ // use reflection now
+ m = c.getMethod("getActivated"); // NOI18N
+ o = m.invoke(o);
+
+ if (o instanceof ExplorerManager.Provider) {
+ return ((ExplorerManager.Provider) o).getExplorerManager();
+ }
+ } // exceptions from forName:
+ catch (ClassNotFoundException x) {
+ } catch (ExceptionInInitializerError x) {
+ } catch (LinkageError x) {
+ } // exceptions from getMethod:
+ catch (SecurityException x) {
+ t = x;
+ } catch (NoSuchMethodException x) {
+ t = x;
+ } // exceptions from invoke
+ catch (IllegalAccessException x) {
+ t = x;
+ } catch (IllegalArgumentException x) {
+ t = x;
+ } catch (InvocationTargetException x) {
+ t = x;
+ }
+
+ if (t != null) {
+ Logger.getLogger(PasteAction.class.getName()).log(Level.WARNING, null, t);
+ }
+
+ return null;
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent ev) {
+ try {
+ Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
+ if(!c.isDataFlavorAvailable(DataFlavor.stringFlavor))return;
+ boolean containsClass = false;
+ String data = (String) c.getData(DataFlavor.stringFlavor);
+ String className = "";
+ String uncommented = data.replaceAll("(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/)|(?://.*)","");// NOI18N
+ uncommented = uncommented.trim();
+ StringTokenizer st = new StringTokenizer(uncommented, " ");// NOI18N
+ if (st.hasMoreTokens() && st.nextToken().equals("public") && st.hasMoreTokens() && st.nextToken().equals("class") && st.hasMoreTokens()) {// NOI18N
+ String cname = st.nextToken().trim();
+ if (cname.charAt(cname.length() - 1) == '{') {
+ cname = cname.substring(0, cname.length() - 1);
+ }
+ if (SourceVersion.isIdentifier(cname)) {
+ containsClass = true;
+ className = cname;
+ }
+ }
+ if (!containsClass) {
+ JOptionPane.showMessageDialog(null, "Code not valid to create class");
+ return;
+ }
+ Set<FileObject> files = this.context.files();
+ if (files.size() != 1) {
+ return;
+ }
+ String path = files.iterator().next().getPath();
+ String packageName = "";
+ File f = new File(path + "\\" + className + ".java");// NOI18N
+ if (f.exists()) {
+ JOptionPane.showMessageDialog(null, "Can not create class already present");
+ return;
+ }
+ if (!f.createNewFile()) {
+ JOptionPane.showMessageDialog(null, "Can not create file");
+ return;
+ }
+ ExplorerManager explorerManager = findExplorerManager();
+ if (explorerManager.getSelectedNodes().length != 1) {
+ return;
+ }
+ Node selectedNode = explorerManager.getSelectedNodes()[0];
+ while (!selectedNode.getName().equals("${src.dir}")) {// NOI18N
Review comment:
This feels really weird - I don't think anyone ever said anything about the names of the Nodes. Suggest to use ClassPath.getClassPath(SOURCE, target).getResourceName(target) (handling failures along the way).
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lahodaj commented on a change in pull request #2020:
[NETBEANS-3986] Creating New Class On Pasting Class Text
Posted by GitBox <gi...@apache.org>.
lahodaj commented on a change in pull request #2020: [NETBEANS-3986] Creating New Class On Pasting Class Text
URL: https://github.com/apache/netbeans/pull/2020#discussion_r392999295
##########
File path: java/java.project.ui/src/org/netbeans/spi/java/project/support/ui/CreateClassAndCopy.java
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.
+ */
+package org.netbeans.spi.java.project.support.ui;
+
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.lang.model.SourceVersion;
+import javax.swing.JOptionPane;
+import org.openide.actions.PasteAction;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionRegistration;
+import org.openide.explorer.ExplorerManager;
+import org.openide.filesystems.FileObject;
+import org.openide.loaders.DataFolder;
+import org.openide.nodes.Node;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+
+@ActionID(
+ category = "Build",
+ id = "org.netbeans.spi.java.project.support.ui.CreateClassAndCopy"
+)
+@ActionRegistration(
+ displayName = "#CTL_CreateClassAndCopy"
+)
+@ActionReference(path = "Loaders/folder/any/Actions", position = 750)
Review comment:
This will show this action on all folder nodes? People working on non-Java projects may complain about that. Have you considered merging this with the ordinary Paste action? (Might only be feasible with the standard java/java.project.ui/src/org/netbeans/spi/java/project/support/ui/PackageView.java#createPackageView, but that might be OK.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] ebarboni merged pull request #2020: [NETBEANS-3986]
Creating New Class On Pasting Class Text
Posted by GitBox <gi...@apache.org>.
ebarboni merged pull request #2020: [NETBEANS-3986] Creating New Class On Pasting Class Text
URL: https://github.com/apache/netbeans/pull/2020
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists