home | contact us
» Posts tagged "netbeans"

Items Tagged: netbeans


All developers love code completion, but sometimes the minimalist info that can come up in PHPStorm can be not quite enough.

Netbeans gave an excerpt that gave plenty of information from the docblock, and PHPStorm can do too, it just defaults to off.

The setting is under Editor-Code Completion and is “Show full signatures”. The good news is it is an “IDE Setting” so it persists for all projects, the bad news is that that means the setting will be forgotten about before you next reinstall and want it again.


 

Followers of this blog will remember the Replicate Netbeans “Select in project” in phpstorm post which gave a handy key combo to select the current file in the project window.

It has been brought to our attention that there’s also a button to do this with the mouse in one click!  At the top of the Project window, there’s a cross-hair/target icon labelled a rather cryptic “Scroll from Source”.  Click that and it does what netbeans users will be looking for as “Select in Projects”

So there you have it, “Scroll from Source”, is the magic words that you want.


 

At Edmonds Commerce we were staunch Netbeans users for years but we always struggled with large scale projects (Magento I’m looking at you) meaning that Netbeans would sometimes really crawl as it tried to reindex thousands of PHP files.

After a recent upgrade of our Linux desktop environment to the Mate edition of Linux Mint 13, Netbeans seemed to perform even worse and had a few bugs as well. At the same time we had been evaluating other IDE options including Eclipse and Zend Studio (which we all have free licences for thanks to being Zend Certified Developers).

In the end though, the one we tried that really impressed was PHPStorm. It isn’t free open source but it isn’t too expensive, especially considering it is perhaps the single most important and highly used tool of a professional PHP developer.

Now a new version has come out. Downloading and upgrading took all of 5 minutes and we are now going to enjoy better performance and some nice new features. I have yet to really test out the new version so I can’t really report on them but they look good. You can read about all the new features in version 5 here.


 

Netbeans has a handy feature when you right-click a file in the editor window to take you to the file in the project (file manager tab) view.

To get phpstorm to do this is not as simple but is handily mappable to a shortcut key.

To enable this, go to Settings-Keymap-Main menu-Navigate-Select in… and choose a key. I set it to Alt+P, so now I press Alt+P then press enter to go to the current file in the project view.


 

If you have issues with netbeans and xdebug not connecting on recent distros, you might find that netbeans is listening on tcp6 and xdebug connecting on plain tcp.

To check if this is the case, run the following command whilst netbeans is “waiting for connection” (change 9000 if you’ve set a different port) :-

netstat -aln | grep 9000

if you get a line similar to the following (specifically tcp6 and not just tcp), it may well be that xdebug can’t connect over ipv6 :-
tcp6 0 0 :::9000 :::* LISTEN

One solution is to disable ipv6, which can be done by creating the file /etc/sysctl.d/10-disable-ipv6.conf with the following contents :-
net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6=1

then run (as root or sudo)
sysctl -p /etc/sysctl.d/10-disable-ipv6.conf
and restart netbeans. Suddenly, netbeans will listen on tcp (ipv4) and xdebug will connect.


 

If you are using a Java application on your nice new Linux Mint desktop and are wondering why its so damn ugly, this might be your solution.

It looks like there is an issue with Java detecting your standard system style, fonts etc so it reverts to something pretty hideous.

One easy solution to at least get it looking alright (and also fixing a bug with menus and maximisation) is to set your netbeans conf to the following.

Simply go to your netbeans folder and look for an etc folder.

Inside there is a file called netbeans.conf

Back that up (rename to netbeans.conf.backup) and create a new file called netbeans.conf

Then paste this in:


# ${HOME} will be replaced by JVM user.home system property
netbeans_default_userdir="${HOME}/.netbeans/7.1.2"

# Options used by NetBeans launcher by default, can be overridden by explicit
# command line switches:
netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.zip.disableMemoryMapping=true"

#trying to fix teh UGLY
netbeans_default_options="${netbeans_default_options} --laf Nimbus -J-Dswing.aatext=true -J-Dawt.useSystemAAFontSettings=lcd"

# Note that default -Xmx and -XX:MaxPermSize are selected for you automatically.
# You can find these values in var/log/messages.log file in your userdir.
# The automatically selected value can be overridden by specifying -J-Xmx or
# -J-XX:MaxPermSize= here or on the command line.

# If you specify the heap size (-Xmx) explicitly, you may also want to enable
# Concurrent Mark & Sweep garbage collector. In such case add the following
# options to the netbeans_default_options:
# -J-XX:+UseConcMarkSweepGC -J-XX:+CMSClassUnloadingEnabled -J-XX:+CMSPermGenSweepingEnabled
# (see http://wiki.netbeans.org/FaqGCPauses)

# Default location of JDK, can be overridden by using --jdkhome <dir>:
netbeans_jdkhome="/opt/java/64/jre1.7.0_04"

# Additional module clusters, using ${path.separator} (';' on Windows or ':' on Unix):
#netbeans_extraclusters="/absolute/path/to/cluster1:/absolute/path/to/cluster2"

# If you have some problems with detect of proxy settings, you may want to enable
# detect the proxy settings provided by JDK5 or higher.
# In such case add -J-Djava.net.useSystemProxies=true to the netbeans_default_options.

 

So, this is documented in the manual, but isn’t obvious in any menu :-

To uppercase a selection, press Control+U then U.
To lowercase a selection, press Control+U then L.
and to reverse case in the selection (for when you have typed a whole line of code without checking your caps lock!), press Control+U then S.

Really useful but not well known.


 

As we have been working with the various versions of Magento its nice to see more and more use of DocBlock notation to help IDEs auto suggest and auto complete methods etc when working with objects.

However the style is inconsistent and with a few subtle tweaks would be much, much better.

Template Files, What is $this?

First one is the @see syntax often used in .phtml files to describe which block object is in play as $this. Whilst that is useful to read, it is totally useless to the IDE.

For example have a look at
app/design/frontend/base/default/template/catalog/product/view.phtml

/**
 * Product view template
 *
 * @see Mage_Catalog_Block_Product_View
 * @see Mage_Review_Block_Product_View
 */

All we need to do is add this underneath

/*
 * @var $this Mage_Catalog_Block_Product_View
 */

And now when working with in the .phtml file, $this will auto complete for you.

Eagle eyed readers may think that as $this could be either this is perhaps a bad idea, however the Review one actually extends the Catalog one overriding some functionality, it is basically the same.

$Model = Mage::getModel() why always the Abstract?

Another one that I have just finally figured out is the correct way to get Netbeans to recognise exactly what class an object is when called with Mage::getModel() or Mage::getSingleton().

You might have auto complete suggesting that this is an instance of Mage_Core_Model_Abstract.

Whilst effectively true, this is unlikely to be useful for you in your context, you need to know exactly what Model class it is.

The reason that Netbeans thinks its Mage_Core_Model_Abstract is because the docblock in
app/Mage.php
describes this as the return value of this method.

    /**
     * Retrieve model object
     *
     * @link    Mage_Core_Model_Config::getModelInstance
     * @param   string $modelClass
     * @param   array $arguments
     * @return  Mage_Core_Model_Abstract
     */
    public static function getModel($modelClass = '', $arguments = array())
    {
        return self::getConfig()->getModelInstance($modelClass, $arguments);
    }

I often see blocks of code where the author is attempting to get auto complete working properly by using this syntax

see
app/code/core/Mage/Customer/controllers/AccountController.php
createPostAction()

/* @var $customerForm Mage_Customer_Model_Form */
$customerForm = Mage::getModel('customer/form');

This is generally the right way to do it, however I think the docblock specifying the return value on Mage:getModel clobbers it.

The simple solution is to move the docblock from above the Mage::getModel call to below it.

$customerForm = Mage::getModel('customer/form');
/* @var $customerForm Mage_Customer_Model_Form */

And it works!


 

If you have a dual monitor setup you might decide to undock some of your Netbeans windows, for example for running XDebug sessions or PHPUnit testing.

However you will find that by default, Netbeans sets the transparency of these windows to unreadable levels when they are not active.

This really defeats the object and is quite irritating.

I spent a long time under the false impression that this was some errant compiz setting and trying to figure it out that way.

Turns out that this is a Netbeans “feature” and you can disable it with a single untick of a box.

Tools-Options-Miscellaneous-Appearance

untick the “Transparent floating windows” box

Enjoy lots of usable desk space in Netbeans!


 

If you use Netbeans then you have no doubt seen the red wavy underline that pops under lines that have errors.

Unfortunatley if your errors relate to punctuation, eg concatenation full stops, then the red wavy line can actually obscure these making finding and fixing the error tricky.

An nice alternative is to set Netbeans to use a red strikethrough instead of the wavy line. This is just as visilble but does not obscure punctuation in any way making finding and fixing the error a lot easier.

To change this simply go to Tools-Options-Fonts & Colors

Then Set Language to All Languages

Then select Error in the category drop down

Simply change the Effects: drop down from Wave Underlined line to Strike Through


 
rss icon