Hi there,
I can not find some advanced documentation on the Snippets only the basic one from the docs.
I have written a snippet which is good for Java development for classes.
I would like to make it even “smarter”
What I would like to do is that when you put the private data fields I could put flexible numbers of fields.
Example:
private String make, model, color
$1 $2 $3 $4
I would be able to put only make OR make and model OR make, model, color
and could read somehow how many parameters give there.
After I could make the setters/getters and other functions automatically depending on how many fields I declared before.
How to do this or other more flexible technics?
Thx
Krisztian
<snippet>
<content><![CDATA[
/*
* $TM_FILENAME
* name: Krisztian
* This program is implementing the $1 class.
**/
public class ${1:${TM_FILENAME/(.+)\..+|.*/$1/:name}} ${2:extends ${3:Parent_class_name}}
{
private ${4:type} ${5:field_name};
${6:private ${7:type} ${8:field_name}};
${9:private ${10:type} ${11:field_name}};
$1() {
this("");
}
$1($4 $5, $7 $8, $10 $11) {
set${5/^(\w)/(?1\u$1:)/}($5);
set${8/^(\w)/(?1\u$1:)/}($8);
set${11/^(\w)/(?1\u$1:)/}($11);
}
// setters / modifiers
public void set${5/^(\w)/(?1\u$1:)/}($4 $5) {
this.$5 = $5;
}
public void set${8/^(\w)/(?1\u$1:)/}($7 $8) {
this.$8 = $8;
}
public void set${11/^(\w)/(?1\u$1:)/}($10 $11) {
this.$11 = $11;
}
// getters / accessors
public $4 get${5/^(\w)/(?1\u$1:)/}() {
return $5;
}
public $7 get${8/^(\w)/(?1\u$1:)/}() {
return $8;
}
public $10 get${11/^(\w)/(?1\u$1:)/}() {
return $11;
}
// copy constructor
public $1($1 other$1) {
this.$5 = other$1.$5;
this.$8 = other$1.$8;
this.$11 = other$1.$11;
}
// copy method
public $1 copy() {
return new $1(this);
}
// equals method
public boolean equals($1 other$1) {
return this.$5.equals(other$1.$5) &&
this.$8.equals(other$1.$8) &&
this.$11.equals(other$1.$11);
}
// to String method
public String toString() {
return "$5: " + $5 +
"\n$8: " + $8 +
"\n$11: " + $11;
}
}
//******* UML *************
$1
-----------------------
- $5 : $4
- $8 : $7
- $11 : $10
-----------------------
+ $1() :
+ $1($5 : $4, $8 : $7, $11 : $10) :
// setters / mutators
+ set${5/^(\w)/(?1\u$1:)/}($5 : $4) : void
+ set${8/^(\w)/(?1\u$1:)/}($8 : $7) : void
+ set${11/^(\w)/(?1\u$1:)/}($11 : $10) : void
// getters / accessors
+ get${5/^(\w)/(?1\u$1:)/}() : $4
+ get${8/^(\w)/(?1\u$1:)/}() : $7
+ get${11/^(\w)/(?1\u$1:)/}() : $10
// copy constructor
+ $1($1 other$1) :
// copy method
+ copy() : $1
// equals method
+ equals(other$1 : $1) : boolean
// to String method
+ toString() : String
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>class</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.java</scope>
</snippet>