How to add "create on" comment in eclipse? - java

How to add "create on" comment in eclipse every time in create a new class file? I know the alt+shift+j option creates comments for adding name to the eclipse class file.

Window -> Preferences -> Java -> Code Style -> Code Templates
Expand Comments -> Types
Edit the template for comments created for new types. Use the ${date} token.

Related

How i can adding shortcut keys for java code in eclipse

I want to add a quick shortcut like (sout + Tab = System.out.println() ) in eclipse how I can do this?
There is already a shortcut for System.out.println().
just type sysout then press ctrl + space.
If you want to make a template for other code, for example System.out.print(), Go to Preferences > Java > Editor > Templates and create a new template. To use the newly created template, type the name of the template + ctrl + space.
Window>Preferences>Java>Editor>Templates>New
edit name and pattern
try it

unable to use sendKeys"sendKeys(CharSequence[]) in the type WebElement is not applicable for the arguments (String)"

I am trying to send "String" as argument in sendKeys method [type WebElement] but system is using it as char sequence, so I am not getting proper output.
public static void setGridDropDownValue(Selenium selenium, WebDriver webDriver, String strGridId, int nRowIndex, int nCellIndex, String strValue)
{
String strXPath = "//div[#id='"+strGridId+"']//table/tbody/tr[2]/td/div/div/table/tbody/tr["+(nRowIndex+2)+"]/td["+(nCellIndex+1)+"]/";
selenium.click(strXPath);
selenium.doubleClick(strXPath);
strXPath = "//select";
Select selStatus = new Select(webDriver.findElement(By.xpath(strXPath)));
List<WebElement> we = selStatus.getOptions();
for(int i = 0; i< we.size();i++)
{
WebElement wei = we.get(i);
System.out.println("Options : "+wei.getText().toString());
if(wei.getText().toString().equals(strValue))
{
wei.sendKeys(strValue);
break;
}
}
}
For example : My dropdown have 4 options(Partial,Done,Verified,Delete). If selected value is "Partial" and I am sending key "Done" then it is working fine, but if selected value is "Verified" and I am sending "Done" then system is selecting "Delete". I am not getting its working procedure but I think system is comparing characters. If selected value is "Verified" and I am sending "Partial" then system is selecting "Partial"(working proper).
F.Y.I. : My dropdown is invisible until user double click on that element.
Please let me know if there is any way to send "String" with sendKeys method. TIA
Follow the steps below if you are using eclipse:
Right click on your java project and select Build Path -> Click on Configure Build Path...
In project properties window: Click/select Java Compiler at the left panel
At the right panel: change the Compiler compliance level from 1.4 to 1.7 or higher
Lastly Click on Apply and OK
Set the JRE System Library again. If you use eclipse follow the steps below:
Go to project properties
Select Java Build Path at the left panel -> Select Libraries tab at the right
Click/select JRE System Library[] -> Click Edit button at the right side
Set your preferred JRE and click Finish button
Lastly click OK button from the project properties pop up window
Instead of editing you can also do by deleting and adding. The steps are:
Right-click on project » Properties » Java Build Path
Select Libraries tab
Find the JRE System Library and remove it
Click Add Library... button at right side » Add the JRE System Library
(Workspace default JRE)
You can use Select class
Select select = (Select) driver.findElement(By.xpath(strXPath));
select.selectByVisibleText(strValue);
If you are using eclipse, follow below steps:-
1.Right click your project-> Build Path->Configure Build Path
2.Select Java Compiler-> Change level to 1.7
3.Click Apply-> OK`
I think this should work. No compilation error.

Change Author template in Android Studio

I want to change the automatic author that appears when I create a file in AndroidStudio.
/**
* Created by a556520 on 16/01/14.
*/
public class POI {
The author takes 'a556520' but I want that appears my name, and not the number of employee. Is that possible?
I didn't find in the settings.
You can overwrite the ${USER} variable in the template file with the
#set( $VARIABLE = "value")
function. Go to Settings -> Editor -> File and Code Templates -> Includes -> File Header prepend the #set() function call, for example:
#set( $USER = "Your name" )
/**
* Created by ${USER} on ${DATE}.
*/
The above answers are correct. But you can go even further and define your own variables - such as User, Company, Email etc.:
#set ($USER = "Name name")
#set ($COMPANY = "company Ltd")
#set ($EMAIL = "example#gmail.com")
/**
* Created by ${USER} on ${DATE}.
* ${COMPANY}
* ${EMAIL}
*/
To edit your File Header template, do the following:
1)Open Android Studio Preferences dialog.
2)In the search box, write "File and Code Templates".
3)Select the left menu item "File and Code Templates".
4)From the middle tabular navigation section, select Includes.
5)Select File Header item that applies to the Java files.
6)You will find an editor section that allow you to edit it for the required pattern. Use the description section below to understand the different parameters that can be used.
/**
* Created by ${USER} on ${DAY},${MONTH_NAME_FULL},${YEAR}
*/
Note: For the name attribute, you can simply write it directly without using attributes. Also you can add your company name or project name in the same way also such as:
/**
* Created by Sami on ${DAY},${MONTH_NAME_FULL},${YEAR}
* ABCDFG company,
* Dubai, UAE.
*/
Press Ctrl+Alt+S then go to File and Code Templates. Here you can set up what you want. E.g. replace ${USER} to your name.
Actually the correct way to change the username is to change the name
of the current user logged in into Windows. (if you're using windows)
Android Studio uses the name saved in %USERNAME% variable.
This is the name you get if you type whoami into a command console
or batch file. And it is the name that is stored under C(orWhatEver):\User.
To change the name you can not just change the name of the profile
you are logged in.
You need to create a new user and give it the correct name.
This way, even if you reinstall AndroidStudio some day, you will end with
the correct ${USER} again.
The easier way surely is to just hard code your name into the template.
But that is just treating the symptoms and you should use the way to fix the root cause.
You can change template for file header by going to Preferences -> Editor -> File and Code Templates. Then change ${USER} in File Header under Includes tab. However this is hardcoding solution it would be better to change actual value of ${USER} variable.
Settings -> Editor -> File and Code Templates -> Includes -> File Header
/**
* #Author: yourname
* #Date: ${DATE}
*/
Open Android Studio Preferences dialog.
In the search box, write "File and Code Templates".
Select the left menu item "File and Code Templates".
From the middle tabular navigation section, select Includes.
Select File Header item that applies to the Java files.
You will find an editor section that allow you to edit it for the required pattern. Use the description section below to understand the different parameters that can be used.
Set the properties first.
#set ($USER = "Your name")
#set ($COMPANY = "Your company")
#set ($EMAIL = "Your email")
/**Created by ${USER} on ${DAY},${MONTH_NAME_FULL},${YEAR} ${COMPANY} ${EMAIL} **/

How do I prevent Eclipse from adding the 'final' keyword to a member variable declaration?

When I type this
private MyKlass myklass;
and hit 'save' in Eclipse, it becomes this:
private final MyKlass myklass;
How do I stop Eclipse from doing this?
You need to disable that option in your 'save actions'.
right click your project > properties, then go to java editor > save actions. go to 'configure', 'code style' tab, and you have it on the bottom ('private fields').
Window - Preferences - Java - Editor - Save Actions - Configure... - Code Style - Use modifier final when possible
The same option can be found in Java - Code Style - Clean up.
If you want to leave this feature enabled in general but turn it off for a specific field, I found a simple workaround. Just declare a protected method that assigns to this field.
protected void preventFinal() {
field = null;
}
You can go to Project --> Properties --> Java Editor --> Save actions , Uncheck "Enable project specific settings"
There is Section called Save Actions in Eclipse Window -> Preferences -> Java -> Editor. There You can Configure Aditional actions - > (tab) code style - > Variable declarations -> edit use of final keyword.
Initialize the field with null:
private File tempDir = null;

Intellij: Adding 'Interface' to my context menu in the Project Pane

Currently in IntelliJ, if I right-click a package in the Project pane, I can see things such as:
new > Java class
new > File
new > Package
I want to add some new menu items in the 'new' context menu such as Interface and Enum. Does anyone know how to do this?
I've been playing around in the Settings > Menus and Toolbars without any luck.
Edit: The funny thing is if I right click a package and choose New > Edit File Templates..., I can see the template for an Interface and in the description it actually says:
This is a built-in template used by IDEA each time you create a new Java interface, by selecting New | Interface from the popup menu in one of the project views.
Unless I need to look at a different pane other than Project, I can't seem to find any context menu that lets me choose New > Interface as suggested by the above description.
New | Java Class, Create New Class dialog appears, in this dialog you can choose Kind between one of the following:
Class
Interface
Enum
Annotation
(tested with IDEA 9.0.3)
If you want Interface directly in the New list, then you have to add new template in Settings | File Templates, name it something like Java Interface and copy the contents of the Interface template into this one.
Also you can create a shortcut to save some secs.
Alt+Ctr+S -> Keymap -> in search box type 'create new' and select Java class and then assign any shortcut like Ctrl+N.
It's under the New Java Class menu.
Yes its available in Class menu : New--> Java class --> Interface .
create a package and then select create new class from that select interface and give a name.
enter image description here
then; you need to import the references files.

Categories