While debugging in eclipse, eclipse hides some variables - java

I am debugging my program in eclipse and facing some strange problem. I have a list fileList1, which is a list of objects files, which has 2 properties:
fileName
versionList
Please have a look on this picture, you will understand my problem.
While debugging, I noticed that when I add object files in fileList1 using a for loop, it works fine and the object files is added. But when I extract the FileList1, it doesn't shows all nodes information, for example, here you can see:
When I extracted FileList1[0], only filename is shown. The next filed, which should show versionList is blank.
Again, When I extracted FileList1[2],nothing is shown, neither filename or versionList.
If I mistakenly doesn't add anything in a particular file, then atleast the variable name , like fileName and versionList should be shown with null properties. But its not the case here. Also, sometimes, the fileName variable in debugger variables view shown one value and if I click on it to extract, it shows another value.
I think the problem is with debugger. Its not updating properly. My output is also coming weird. It seems new entries are replacing old entries, although I did not used any replace function for list, just used fileList1.add(file). I am not understanding, whats the problem here.
I already checked internet and stackoverflow for a solution. But did not found similar topic. Your help will be highly appreciated.

Related

Find the just written code in a java file with Eclipse (i.e. highlight the new part of code)

Context
I am modifying a big project in Java. In a file, I make some modification to the code (maybe inadvertently). The file is marked with a little * close to the name (that means it is still not saved).
Question
How to find where the new characters were just written?
I know I can use ctrl+z to undo the changes and, thus, find the place where the changes were made. What I am looking for is a way of highlighting the new part in the existing code.
Eclipse already shows this information by default. Every unsaved change is marked on the left line number ruler.
Deleted lines are marked with an horizontal line "-".
Added/changed lines are marked with a different color of the line number.

How to retrieve the string id you defined (not integer id) in AndroidStudio, and Object Tags

I'm new to Android development and I'm trying to make a calculator app in AndroidStudio. Originally, I used Buttons, and to retrieve the number of a button pressed, the function btn.getText() worked perfectly. I've since replaced the Buttons with ImageButtons, with the number now represented in the image.
My plan was to give all ImageButtons ids in the vein of 'btn0', 'btn1', and so on, then do something like
Character number = imgbtn.getId().charAt(imgbtn.length()-1);. This, however, fails miserably, as the id is apparently an automatically assigned int, and not the id I set.
Is there a way to access the string id property that I defined?
Alternatively, I saw mention of a getTag() function in my prior googling for solutions that looks like it might be useful in this situation, but I can't find an ImageButton tag property where I can set it.
Solved my specific issue: I just discovered that I can set the tag in the Text view, by adding android:tag="x" to the relevant ImageButtons (or that I could call imgbtn.setTag() to the same effect). I'm going to submit this anyway, in case someone has a similar issue in the future.
Lingering Questions
My question about accessing one's defined string id still stands. Is there a way to do that, in case I'd ever like to?
Also, what's an Object Tag, such as it would be used in imgbtn.setTag(<Object tag>)? I can't find any documentation.
At compile time, all resources are compiled in to a class called R.Java. When you say findViewById(R.id.xxx) what you are actually doing is pointing to a static reference of a final integer called "xxx" that has been hardcoded into this Java file. If you'd like to view this, navigate to the build directory after you've built your project and go to generated, source, debug (or release) then through your project until you see R.java
In other words, the String of the id is not present at runtime.

Java find where a class is used in the code - programmatically

I have a List of classes which I can iterate through. Using Java is there a way of finding out where these classes are used so that I can write it out to a report?
I know that I can find out using 'References' in Eclipse but there are too many to be able to do this manually. So I need to be able to do this programmatically. Can anyone give me any pointers please?
Edit:
This is static analysis and part of creating a bigger traceability report for non-technical people. I have comprehensive Javadocs but they are not 'friendly' and also work in the opposite direction to how I need the report. Javadocs start from package and work downwards, whereas I need to start a variable level and work upwards. If that makes any sense.
You could try to add a stacktrace dump somewhere in the class that isolates the specific case you are looking for.
public void someMethodInMyClass()
{
if (conditions_are_met_to_identify)
{
Thread.dumpStack();
}
// ... original code here
}
You may have to scan all the sources, and check the import statements. (Taking care of the * imports.. having to setup your scanner for both the fully Qualified class name and its packagename.*)
EDIT: It would be great to use the eclipse search engine for this. Perhaps here is the answer
Still another approach (probably not complete):
Search Google for 'java recursively list directories and files' and get source code that will recursively list all the *.java file path/names in a project.
For each file in the list:
1: See if the file path/name is in the list of fully qualified file names you are interested in. If so, record is path/name as a match.
2: Regardless if its a match or not, open the file and copy its content to a List collection. Iterate through the content list and see if the class name is present. If found, determine its path by seeing if its in the same package as the current file you are examining. If so, you have a match. If not, you need to extract the paths from the *.import statements, add it to the class name, and see if it exists in your recursive list of file path/names. If still not found, add it to a 'not found' list (including what line number it was found on) so you can manually see why it was not identified.
3: Add all matches to a 'found match' list. Examine the list to ensure it looks correct.
Not sure what you are trying to do, but in case you want to analyse code during runtime, I would use an out-of-the box profiler that shows you what is loaded and what allocated.
#Open source profilers: Open Source Java Profilers
On the other hand, if you want to do this yourself (During runtime) you can write your own custom profiler:
How to write a profiler?
You might also find this one useful (Although not exactly what you want):
How can I list all classes loaded in a specific class loader
http://docs.oracle.com/javase/7/docs/api/java/lang/instrument/Instrumentation.html
If what you are looking is just to examine your code base, there are really good tools out there as well.
#see http://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis

create a directory like windows explorer and store information a text file

guys i have got a problem in which i have to create a directory which keeps a text file which keeps the information about all the files. Like file created, last modified , type etc.. its not a big deal till i have to maintain this record of the static files(already present in the directory). But what happens when some new files are added, how do i check that the last modified thing. For the static files, initially i have set the class variable as zero and later the variable is compared with the last modified value. My question is what happens when a new file is added ? A new object is created every time a new file is added ?
I tried that way but its turning out to be highly tedious? Am i moving in the right direction? It has to be done in java. In a real fix. Kindly help guys. I hope am clear with my doubt.
Thanks in advance!

How can I set the default Scope in IntelliJ 12 for Find Usages?

I've returned to IntelliJ after a long hiatus for Android development so I'm getting used to it again. The problem I have is that for example when you want to see where is a class being used, you'd position the caret in the class declaration and issue cmdaltF7 (on Mac OS X) to Find Usages, which is returning stuff from mapping.txt and seeds.txt as well as the .java results, and even tho I can set up the defaults by doing shiftcmdaltF7 and un-tick the: search for text occurrences and even change the scope from Project Files to a custom scope (for example), these options are not saved when I invoke Find Usages again.
Does anybody know of a way to personalize the Find Usages so it's more close to what Eclipse would do? (I.e., find the real usages instead of a text search for occurrences).
Reporting back from the future: the behaviour described in the question has now been implemented (Intellij issue mentioned in the comments).
To configure cmdaltF7 to run in a default scope, start by running it against some Symbol
Clicking on the wrench icon, one can select one of the pre-defined scopes, or create a new one (using the ... button).
The + creates a new scope. Find the folder in which to look, and click Include recursively. And voila!
Any consequent searches will use that scope until it is changed.
Instead of cmdaltF7, use the shortcut altF7. This will open a pop-up for you to make a selection about Scope, Test occurrences, and types of usage. You will have to make this selection one time. The next time you press altF7 then your choices are remembered.
The result is that altF7 followed by enter gives you what you need.

Categories

Resources