Developer Tools - UA-ScriptEase/scriptease GitHub Wiki

#Eclipse

##Helpful Hotkeys You'll wind up using some of these all the time. You'll even try to use them in other software, and feel confused and bewildered when it does something else. Don't worry. That's natural.

Hotkey Description
Ctrl + space Autocomplete methods, variable names, etc. If you Ctrl+Space in a blank area inside of a class but not in any method, you can insert methods to override, which is very useful. Learn to use this a lot!
Ctrl + 1 Autocorrect. Shows you options to correct the warned about code that you are currently at.
Ctrl + Shift + F Auto-formatting (indentation, whitespace, max line length) of selected text or all text if no selection.
Alt + (Left/Right) Move backwards or forwards between last important locations
Ctrl + Shift + O Clean up import list
Ctrl + K Find other instances of selected text in file
Ctrl + H Inter-File search
Ctrl + Shift + T Open specific class definition
Ctrl + click Go to declaration
Ctrl + D Delete current/selected line
Ctrl + / or Ctrl + Shift + C Toggle comments on all selected lines or line that the text caret is on if no selection.
Ctrl + Shift + R Open Resource by file name. Useful for opening apidictionary, languagedictionary, and other xml files.
Alt + Shift + R Rename a method/variable/constructor/etc, and all references to it. Can be used anywhere the name appears. Press Enter when done.
Ctrl + Alt + H Open the Call Hierarchy of the method/class.
Ctrl + Shift + G Find all references to the method/variable/constructor/etc.
Ctrl + O Opens a pop up displaying all methods in the class, allowing you to quickly move to another method. Using this, you can get rid of the outline view on the right of the screen to give you more screen real estate. Pressing it again shows the inherited methods, too.
Ctrl + G Searches for all declarations. So if you have someMethod() in Class A, and someMethod() in Class A extends B, pressing Ctrl+G over one method would find both of them.

##Other Helpful Shortcuts

  • Typing "sysout" or "syserr" and pressing enter writes the appropriate System.out/err.println() for you. You can just type "sys" then hit Ctrl+Space to autocomplete, and see a few more options.
  • Use the Javadoc view (Window -> Show view -> Javadoc) to read javadoc easier. It gets formatted properly in that window, as it would on the web.
  • Drag a file's tab around the screen. You'll see various options for changing the layout, including the ability to look at two files simultaneously.
  • Right click an open file's tab and click on "New Editor" to open a second editor for the file. This is especially useful when you are editing large classes.
  • Project giving you strange errors? Imports not working properly? Try cleaning it by going to Project -> Clean.
  • If, for some reason, you need to insert or delete the same text on many consecutive lines at once, toggle Block Selection Mode with Alt+Shift+A to select many lines at a time.
  • When you are inter-file searching, make sure you are in "File Search" instead of "Java Search". There is an 87.3% higher chance of finding what you were looking for.

##Debugging The best and easiest way to begin debugging is by using Eclipse's built in debugging tool. Instead of running your program by pressing "Run", click on the "Debug" button, which looks like a bug. Your program will run exactly like usual. However, by double clicking line numbers in your code, you can insert breakpoints. Note that only lines that actually do something will work.

Breakpoints cause your program to pause when they are reached. Eclipse should prompt you to switch to the Debug perspective when this happens. If not, switch to it by going to Window -> Open Perspective -> Debug. A few controls will be visible near the top of the screen. From here, you can resume your program, stop it, or step through it. Stepping is the important part.

The first arrow, Step Into, steps you through each method, going into each method that is called. This includes all Java files, so if you are using the JRE instead of the JDK, you won't be able to see what is happening. Step Into is useful if you want to start at the top of a call heirarchy and find out where the program breaks or does something unexpected. The hotkey for Step Into is F5.

The second arrow, Step Over, steps over the method call and goes to the next line. This is useful for lines where you are sure there is no problem. For example, you most likely don't want to go into every "new ArrayList()" to see if the ArrayList is being correctly created. The hotkey for Step Through is F6.

Now, sometimes you accidentally step into a gigantic method, then find yourself stepping over each method in there until you get out of it. But there's an easier way: Step Return. The third arrow gets you back to the original method after stepping into another method.

As you are stepping through, you can use the top right frame to see currently active Variables and their values.

If you want to see what a method will evaluate to, highlight it in your code and press "CTRL+SHIFT+I" to "Investigate" it.

These tools are what you will use most often, but there are more. Go to the Eclipse Website to learn more about all of the functionality of the debug tool.

###Debugging Translators If you are working with translators and compiling them with ANT outside of Eclipse, you might not be able to debug them. This is because they need to be compiled with debug mode set to true to give the compiler more information.

For the Neverwinter Nights translator, the translator is compiled by adding the flag "-Ddebug.mode=true" to the command. So it would read something like "ant install -Ddebug.mode=true". You can then hit Debug on ScriptEase in Eclipse like usual, and it will respect the breakpoints you add to the translator files.

###Finding Memory Leaks There have been issues with memory leaks. These usually stem from our various observers not getting garbage collected. Our classes that handle observers, ObserverManagers, hold observers in a map to Weakly Referenced objects. This means that the map will automatically remove elements whose keys are no longer referenced anywhere else in the program.

Another useful tool for real time statistics is JVM Monitor. Search for it on the marketplace.

By using the Memory Analyzer Tool in Eclipse, you can find out which objects are taking up a lot of memory. The creation of the highest object might not be the reason for the memory leak; maybe something else is creating them, and that isn't getting garbage collected because it calls a specific function in another class. But it does help you get an idea of where to begin looking.

There is a great tutorial on how to set up a Leak Suspects Report at Vogella.com.

After you have generated the report, a pie chart will display. Click on "System Overview" at the top, then click on "Top Consumers" to see a more detailed pie chart.

Building Woes

Sometimes you will have to start Eclipse anew. Your project may no longer build or compile correctly. AJDT may produce obscure errors like "NullPointerException. Compile Error : null" that turn up nothing useful on Google.

To fix this, follow the following instructions until the projects compile successfully:

  1. Clean your project (Build -> Clean -> Clean All Projects)
  2. Remove your projects and readd them. Remember to clean again.
  3. If all else fails, start a new workspace and add your projects to it.

##Specific Problem Resolutions ###Corrupted Header in Jar So you're compiling as usual, ANT doesn't complain, and everything is wonderful. But then you try to compile the translator, and things get weird. It begins to complain about corrupted Jar file. You attempt to discover the problem by opening the Jar itself, but that just pops up an error dialog with "Corrupted Header!" Now what? Why would this happen?

It happens because your manifest file in the Jar has a broken header. This happens sometimes when you commit. So just git commit again, and then try compiling. Your Jars should be working again.

###llegalArgumentException: "Comparison Method Violates Its General Contract"

No one expects the Java Timquisition!

The cause of this is that Java 1.7 switched out MergeSort for TimSort. This makes Collections.sort more efficient, but, as far as I understand it, also throws an exception when two equal objects do not return 0. And of course, the printed stack trace only has references to JDK classes, so good luck finding out where it happened.

I attempted to fix the methods where comparisons fail, but it still occurred. It seems to happen on "swingComponent.remove();" and "removeAll()" methods, even though we didn't make up our own.

So, in the meantime, ScriptEase will only be expected to work on Java 1.6. Maybe Java 1.7.* will provide a fix, or Java 1.8. We will have to try as they come out.

If you happen to fix it, edit the ticket and let me know so I can give you a medal. -aschenk

#Ant

What is this, a programming language for ANTs!?

Ant is an automatic build process scripting tool. Comes native to the linux machines, so no need to install there. The user manual is located at http://ant.apache.org/manual/index.html and the List of Tasks is quite handy.

ScriptEase is built from an ANT file to do releases. There is a build.xml file located in the ScriptEase root directory and in each of the translators' root directories. Call ant -p in the same directory as the build file to get ANT to print out the documentation stored in the build.xml.

##Building ScriptEase II Before we build any translators, we need to build ScriptEase II with ant. Navigate to the ScriptEase directory and type in the command ant zip

This will install ScriptEase II. We usually don't have to zip it again unless we change one of the classes that the translators extend.

##Installing Translators To install translators, we navigate to the translator directory (usually in scriptease2/translators_src/translatorname), and use the command ant install -Ddebug.mode=true

The flag at the end lets us debug the translator with Eclipse. We need to reinstall the translator this way any time we make a change to it that we want to run.

##ANT with Java 1.7 I have not been able to figure out how to get Java 1.7 to work with ANT. We can compile fine in Eclipse, but ant will fail because the CS servers only have up to Java 1.6. So for now, just use Java 1.6u35 to program ScriptEase 2. Once the CS Department moves to 1.7 we can use it.

There aren't any critical features we need in 1.7, and it actually introduces a bug (the dreaded TimSort. See Java Debugging). -aschenk

⚠️ **GitHub.com Fallback** ⚠️