use of com.intellij.codeInsight.template.Macro in project intellij-community by JetBrains.
the class EditVariableDialog method createVariablesTable.
private JComponent createVariablesTable() {
final String[] names = { CodeInsightBundle.message("templates.dialog.edit.variables.table.column.name"), CodeInsightBundle.message("templates.dialog.edit.variables.table.column.expression"), CodeInsightBundle.message("templates.dialog.edit.variables.table.column.default.value"), CodeInsightBundle.message("templates.dialog.edit.variables.table.column.skip.if.defined") };
// Create a model of the data.
TableModel dataModel = new VariablesModel(names);
// Create the table
myTable = new JBTable(dataModel);
myTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
myTable.setPreferredScrollableViewportSize(new Dimension(500, myTable.getRowHeight() * 8));
myTable.getColumn(names[0]).setPreferredWidth(120);
myTable.getColumn(names[1]).setPreferredWidth(200);
myTable.getColumn(names[2]).setPreferredWidth(200);
myTable.getColumn(names[3]).setPreferredWidth(100);
if (myVariables.size() > 0) {
myTable.getSelectionModel().setSelectionInterval(0, 0);
}
Predicate<Macro> isAcceptableInContext = macro -> myContextTypes.stream().anyMatch(macro::isAcceptableInContext);
Stream<String> availableMacroNames = Arrays.stream(MacroFactory.getMacros()).filter(isAcceptableInContext).map(Macro::getPresentableName).sorted();
Set<String> uniqueNames = availableMacroNames.collect(Collectors.toCollection(LinkedHashSet::new));
ComboBox comboField = new ComboBox();
uniqueNames.forEach(comboField::addItem);
comboField.setEditable(true);
DefaultCellEditor cellEditor = new DefaultCellEditor(comboField);
cellEditor.setClickCountToStart(1);
myTable.getColumn(names[1]).setCellEditor(cellEditor);
myTable.setRowHeight(comboField.getPreferredSize().height);
JTextField textField = new JTextField();
/*textField.addMouseListener(
new PopupHandler(){
public void invokePopup(Component comp,int x,int y){
showCellPopup((JTextField)comp,x,y);
}
}
);*/
cellEditor = new DefaultCellEditor(textField);
cellEditor.setClickCountToStart(1);
myTable.setDefaultEditor(String.class, cellEditor);
final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myTable).disableAddAction().disableRemoveAction();
return decorator.createPanel();
}
use of com.intellij.codeInsight.template.Macro in project intellij-community by JetBrains.
the class MacroParser method parseMacro.
//-----------------------------------------------------------------------------------
@SuppressWarnings({ "HardCodedStringLiteral" })
private static Expression parseMacro(Lexer lexer, String expression) {
IElementType tokenType = lexer.getTokenType();
String token = getString(lexer, expression);
if (tokenType == MacroTokenType.STRING_LITERAL) {
advance(lexer);
return new ConstantNode(parseStringLiteral(token));
}
if (tokenType != MacroTokenType.IDENTIFIER) {
LOG.info("Bad macro syntax: Not identifier: " + token);
advance(lexer);
return new ConstantNode("");
}
List<Macro> macros = MacroFactory.getMacros(token);
if (macros.isEmpty()) {
return parseVariable(lexer, expression);
}
advance(lexer);
MacroCallNode macroCallNode = new MacroCallNode(macros.get(0));
if (lexer.getTokenType() == null) {
return macroCallNode;
}
if (lexer.getTokenType() != MacroTokenType.LPAREN) {
return macroCallNode;
}
advance(lexer);
parseParameters(macroCallNode, lexer, expression);
if (lexer.getTokenType() != MacroTokenType.RPAREN) {
LOG.info("Bad macro syntax: ) expected: " + expression);
}
advance(lexer);
return macroCallNode;
}
Aggregations