-
Notifications
You must be signed in to change notification settings - Fork 56
Leonidas Tipper Template
Michal Cohen edited this page Oct 1, 2018
·
3 revisions
From issue #1385 (better as wiki)
Since I probably can't push this template to git, here is the template I've defined to create new leonidas tippers. Right click any file in the explorer -> new -> edit file templates -> files -> big green plus Give your template a name and paste this code:
package il.org.spartan.Leonidas.plugin.tippers.leonidas;
import java.util.HashMap;
import java.util.Map;
import il.org.spartan.Leonidas.auxilary_layer.ExampleMapFactory;
import static il.org.spartan.Leonidas.plugin.leonidas.BasicBlocks.GenericPsiElementStub.*;
import static il.org.spartan.Leonidas.plugin.leonidas.The.element;
/**
* <Tipper description>
*
* @author ${USER}
* @since ${DAY}-${MONTH}-${YEAR}
*/
public class ${NAME} implements LeonidasTipperDefinition {
/**
* Write here additional constraints on the matcher tree.
* The structural constraint are of the form:
* element(<id>).{is/isNot}(() - > <template>)[.ofType(Psi class)];
* There are non structural that you can apply, for example
* element(<id>).asMethod.startsWith("set);
*/
@Override
public void constraints() {
}
@Override
public void matcher() {
new Template(() -> {
/** start */
//<template>
/** end */
});
}
@Override
public void replacer() {
new Template(() -> {
/** start */
//<template>
/** end */
});
}
/**
* Defines code examples and results after applying the tipper.
* This is used to test the tipper.
* example:
* examples.put("!(!(x > 4))", "x > 4");
*/
@Override
public Map<String, String> getExamples() {
return new ExampleMapFactory()
.put(<before>,<after>)
.put(<before>,<after>)
// add more
.map();
}
}