Eclipse: Create placeholder function from unrecognized function name? - eclipse

Perhaps I'm using the wrong search terms, or maybe eclipse just doesn't support this, but when I type a function call to a function that I haven't written yet, is there a way to have eclipse automatically create an empty placeholder function with the same name?
I'm using FDT to do ActionScript3 coding, if that makes any difference.
For example, if I type this:
var x = func(5.2);
but I haven't written the func function yet, eclipse will underline func to alert me that it can find a reference to that function. This is presenting me with a problem, but not a solution. Is there a keyboard shortcut to have eclipse automatically go to this:
var x = func(5.2);
private function func():void {
// add your code here...
}

Use Ctrl-1 (Windows) or Cmd-1 (MacOS).

Related

In Katalon Studio, How to retrieve the values using the javascript executor. document.getElementsByTagName('input')[29].value

enter image description here
I tried below code but not works.
a = WebUI.executeJavaScript('document.getElementsByTagName("input")[29].value', null)
Thread.sleep(5000)
System.out.println(a)
There is so much wrong with this question that I don't even know where to begin...
What are you trying to accomplish by using JavaScript (this is a testing code smell, for 99% of testing cases) to fetch a value ?
Why not do the following:
create a TestObject, preferably in the Object Repository, that points to the object in question.
give that Test Object the locator. This is, by default, some xpath.
In your case, give it xpath
(//input)[29]
. However, I advise you come up with a more meaningful selector for it (for example, select it by some class, data-* attribute, name) that is easier to maintain
use the built-in Keyword for getting attribute, like this:
WebUI.getAttribute(findTestObject('[whateverYourTestObjectNameIs]'), 'value')
this is just good code design, but write this to some Custom Keyword for this util:
// import statements here. Ctrl + Shift + O on your keyboard to bring those in
public final class GeneralWebUIUtils {
public static final String Value = "value";
public static final String GetValue(TestObject to) {
return WebUI.getAttribute(to, this.Value);
}
}
Also, why are you pausing runtime by some hard-coded time amount? That is a testing code smell. Stop it!
What exactly are you waiting on? Use the WebUI keywords for this thing you are waiting on, and if none of those suffice, hmu and I may have the wait method you're looking for ....
Oh, and looking at that image you linked, it looks like you solved your own question.

eclipse autocomplete fails in PHP when using parentheses

I'm using eclipse Juno with PDT. Autocomplete works fine except in a specific situation.
If I do this it works fine
class Example {
public function doit() {
$v = new Example();
}
}
I can control-click the Example() object fine and also I see the doit() method when autocompleting $v->.
Now see this example
class Example2 {
public function doit() {
$v = (new Example2());
}
}
Now the autocompleter is broken, I cannot control-click anything but also the outline view is now empty. Eclipse cannot see any methods or anything. There is nothing in the eclipse logs.
Of course this is a stupid example but I've seen this construction happening in statements with the ternary operator in external frameworks. This is pretty annoying because the objects from such classes cannot be used anymore with the autocompleter.
This call relates to Eclipse PHP autocomplete acting funny, some files complete some don't btw where I also replied with the actual issue. Please don't shoot me for re-posting.

Why is # referring to Window object in Coffeescript?

Having a bit of hardtime understanding coffeescript. Why is this the window object in the set_position function?
window.App = {}
$ ->
driver = new Driver if ($('#drivers_become').length >= 1)
window.App.driver = driver
class Driver
constructor: ->
#get_position()
get_position: ->
if navigator.geolocation
navigator.geolocation.getCurrentPosition(#set_position)
set_position: (pos) ->
# this refers to window object in this case. why?
#latitude = pos.coords.latitude
#longitude = pos.coords.longitude
get_latitude: ->
#latitude
get_longitude: ->
#longitude
get_latitude and get_longitude return undefined in this case.
If you are using aDriverInstance.set_position as an event handler function, the browser will invoke it as a regular function not a method. To fix that, use a "fat arrow" when defining it: set_position: (pos) =>. But more broadly it is a question of invoking via dot notation and invoking via direct reference:
aDriverInstance.set_position(pos) will have this set to aDriverInstance and all is well
set_position_reference = aDriverInstance.set_position;set_position_reference(pos) will have this set to the window object.
This is a classic binding issue, and applies as much to Javascript as Coffeescript.
You are passing a Driver method, set_position to a Windows function,
navigator.geolocation.getCurrentPosition(#set_position)
That function evaluates set_position in the global, windows, context. In effect it ends up setting global latitude and longitude variables, not the attributes of the Driver instance. In your console see if those variables are defined.
What you want to do is define set_position so #is bound to the Driver instance. To do that, use the fat arrow, =>. http://coffeescript.org/#fat-arrow
set_position: (pos) =>
# this refers to window object in this case. why?
#latitude = pos.coords.latitude
#longitude = pos.coords.longitude
If you use this, and look at the compiled Coffee, you will see a line that does:
this.set_position = __bind(this.set_position, this);
Packages like jquery and underscore also have a bind function, as do recent browsers.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
get_position: ->
if navigator.geolocation
navigator.geolocation.getCurrentPosition(#set_position.bind(this))
Uses the browser's bind

Coffeescript - call function by variable

I want to manage part of my layout with coffeescript. I have a left/right panel and I want to be able to switch between them. I have created something like this:
window.switchPanel = (panel = 'left', action = 'toggle') ->
open = (panel) ->
...
close = (panel) ->
...
toggle = (panel) ->
...
My question is, how do I structure this so that I can call open/close/toggle by the action variable and can I use something so that I don't have to pass in the panel to every child function? Perhaps #panel?
I think you just want to throw your functions into an object so that you can access them by name:
window.switchPanel = (panel = 'left', action = 'toggle') ->
funcs =
open: (panel) ->
...
close: (panel) ->
...
toggle: (panel) ->
...
Then you can simply funcs[action](panel) inside switchPanel. If you don't want pass panel into the functions then you don't have to, they'll have access to panel simply by being defined within switchPanel:
window.switchPanel = (panel = 'left', action = 'toggle') ->
funcs =
open: ->
...
close: ->
...
toggle: ->
...
Then you'd just funcs[action]() and they could do what they like with panel.
Demo: http://jsfiddle.net/ambiguous/UV42x/
Some reading on JavaScript closures would clarify what's going on in the second version.
You might want to include an if(action !of funcs) check to make sure you don't try to use a bad action. Or, as Aaron Dufour notes in the comments, you could funcs[action]?() if you only need to check that action is valid once.
Few things:
1) I think you're creating obvuscated architecture by selectively calling methods within the object based on an input to the object. It begs the question "Why even create the methods? Why not just use a big IF ELSE IF type structure?" But others would disagree with me.
2) This is one of the confusing circumstances of CoffeeScript. You're dealing with something that would normally be clear if wrapped in explicit braces. I don't like javascript's crazy use of anonymous function wrappers everywhere, but I do believe in bracketed code. I defer to point 1. I think you're just making things more complicated by doing it this way.
3) Have you studied how coffeescript transforms the 'this' keyword? I'm pretty certain CoffeeScript does some kind of smart transformation on 'this' that deviates from standard javascript, which will mean nobody can answer this question for you except Coffee users. It won't be the same as javascript. Its relevant because in order to access 'panel' in the methods without passing it explicitly, you would need to use 'this.panel' or some other dereferencing mechanism to access the panel member from within one of the methods. I can't tell you how, but this information my help steer you in the right direction. The issue at hand is clearly a question of how to reference object members.

Can Eclipse generate method-chaining setters

I'd like to generate method-chaining setters (setters that return the object being set), like so:
public MyObject setField (Object value) {
this.field = value;
return this;
}
This makes it easier to do one-liner instantiations, which I find easier to read:
myMethod (new MyObject ().setField (someValue).setOtherField (someOtherValue));
Can Eclipse's templates be modified to do this? I've changed the content to include return this; but the signature is not changed.
I confirm eclipse (up to 3.5RC1) does not support "method chaining" setter generation.
It only allows for comment and body customization, not API modification of a setter (meaning a generated setter still return 'void').
May be the plugin Builder Pattern can help here... (not tested though)
Classic way (not "goof" since it will always generate a "void" as return type for setter):
(source: eclipse.org)
Vs. new way (Builder Pattern, potentially used as an Eclipse plugin)
alt text http://www.javadesign.info/media/blogs/JDesign/DesignConcepts/DesignPatterns/GOF/Creational-BuilderPatternStructure.jpeg
Don't use eclipse myself, but you'll have to change one of the standard templates if you can't find a feature.
It's called method chaining by the way (which might help with a Google search or two).