Archive for the ‘intellij’ tag
After a recent IntelliJ upgrade I’ve been running into the following error when trying to attach the sources of any library being pulled in via Maven:
Unable to import maven project
And this is where you need to add it:
Cmd + , -> Build, Execution, Deployment -> Build Tools -> Maven -> Importing
Unfortunately it’s not quite working at the moment so I wanted to debug the code and see whether the input parameters were being correctly translated from the CSV file.
Each input is an array containing 784 values but by default IntelliJ restricts you to seeing 100 elements which wasn’t helpful in my case since the early values tend to all be 0 and it’s not until you get half way through that you see different values:
It’s actually relatively easy to see the other values by right clicking on the array in question and clicking ‘Adjust Range’:
Then I type in the end index of the array and we’re done!
Everyone now and then we end up having to write a bunch of mapping code and I quite like using IntelliJ’s ‘Replace’ option to do it but always end up spending about 5 minutes trying to remember how to do capture groups so I thought I’d write it down this time.
Given the following text in our file:
val mark = 0 val dave = 0 val john = 0 val alex = 0
Let’s say we wanted to prefix each of those names with ‘cool’ and had decided not to use Column mode for whatever reason.
One way of doing that is to capture the names and then replace each of them with ‘cool’ appended on the beginning:
A (very hacky) find regex could be this:
Where we capture all the letters in the variable name inside a group and then build our replacement string like so:
I always expect the capture group replacement syntax to be ‘\1’, ‘\2’ and so on but it actually uses a ‘$’ instead.
Hopefully now I shall remember!
We added them into ‘src/main/resources’ and set that as a source path in IntelliJ assuming that was all we needed to do.
Despite doing that our test kept failing because it couldn’t locate the files on the classpath.
Charles eventually came across the compiler resource patterns settings which are accessible from the Preferences > Compiler menu:
We had to add “*.xqy” to the end of the list of patterns to get our files picked up.
We came across another file extension that we needed to be on the classpath about 10 minutes later and obviously solved it much quicker that time!
One of my favourite features of IntelliJ is that it tracks the item that you currently have open on your Solution Explorer.
I thought this wasn’t possible in Visual Studio and had resigned myself to trying to remember which project each file was in. Luckily for me a colleague pointed out that it is in fact possible but is just turned off by default.
Tools > Options > Projects and Solutions > Check ‘Track Active Item in Solution Explorer’
Although modern day IDEs (Eclipse, IntelliJ, Resharper etc) undoubtedly provide a lot of benefits when writing code, I am starting to wonder if the ease at which they make things possible actually encourages bad habits.
Useful features such as creating and initialising member variables from the definition of a constructor are quickly nullified by the ease at which one is able to create getters/setters/properties for these same member variables. All hopes of encapsulation gone with a few clicks of the mouse.
The counter argument is that you need to work responsibly when given a powerful tool, but it just seems to me that it’s hard enough to write good OO code (too hard maybe?) – anything which makes it harder is not a good thing!
I am convinced that IDEs need to provide an Office paper clip style Martin Fowler which pops up whenever you do something questionable (such as creating getters for every field on a class) and asks whether you really want to do what you’re doing.
Or maybe there is too much cranking out of the code and not enough thinking about the design of what we’re coding that’s the real problem…