Related IFunction Cast Problem [message #258337] |
Thu, 12 June 2008 16:24 |
Eclipse User |
|
|
|
Originally posted by: gang.xu.delphi.com
Related to my other issue, an attempt to cast the first element in a
TreeSelection as an IFunction in a pop-up menu class causes the action not
to be recognizable-"The chosen operation is not currently available" pops
up as a message rather than my original action.
I have commented where the problem is. If the try-catch block is commented
out, the action is executed just fine. When it isn't a break point never
even gets hit-it's as if the class isn't even reached!
The menu and action are still listed on right-clicking because that is
specified separately in the plug-in. I also imported the correct IFunction
reference (cdt model used, not the ast one), I'm just confused as to why
1. I cannot cast as IFunction when debugging with the try-catch block
commented out shows that the TreeSelection indeed that the firstElement is
a Function.
2. Trying to access contents of such a function causes the class not even
to be read!
3. Debugging with the try-catch block commented out caused the '*' problem
discussed below.
Your help is much appreciated!
Here is my code. fnName and fnBody are String instance variables. The
first '*' represents where I put the breakpoint, the second is where I
cannot step further-F5 and F6 both freeze up inside underlying classes
rather than returning and simply skipping over the if.
public void selectionChanged(IAction action, ISelection selection) {
TreeSelection testcase;
IFunction function;
String temp = selection.toString();
'*' fnName = temp.substring(1, temp.length()-1);
if (selection instanceof TreeSelection) {
testcase = (TreeSelection) selection;
//not getting casted as IFunction!
'*' if (testcase.getFirstElement() instanceof IFunction) {
function = (IFunction)testcase.getFirstElement();
try {
//problem is right here!
fnBody = function.getSource();
} catch (CModelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.07890 seconds