本文整理汇总了Java中com.intellij.codeInsight.template.Macro类的典型用法代码示例。如果您正苦于以下问题:Java Macro类的具体用法?Java Macro怎么用?Java Macro使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Macro类属于com.intellij.codeInsight.template包,在下文中一共展示了Macro类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createMacro
import com.intellij.codeInsight.template.Macro; //导入依赖的package包/类
public static Macro createMacro(@NonNls String name) {
if(myMacroTable == null) {
init();
}
return myMacroTable.get(name);
}
示例2: getMacros
import com.intellij.codeInsight.template.Macro; //导入依赖的package包/类
public static Macro[] getMacros() {
if(myMacroTable == null) {
init();
}
final Collection<Macro> values = myMacroTable.values();
return values.toArray(new Macro[values.size()]);
}
示例3: init
import com.intellij.codeInsight.template.Macro; //导入依赖的package包/类
private static void init() {
myMacroTable = new HashMap<String, Macro>();
for(Macro macro: Extensions.getExtensions(Macro.EP_NAME)) {
myMacroTable.put(macro.getName(), macro);
}
}
示例4: parseMacro
import com.intellij.codeInsight.template.Macro; //导入依赖的package包/类
@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("");
}
Macro macro = MacroFactory.createMacro(token);
if (macro == null) {
return parseVariable(lexer, expression);
}
advance(lexer);
MacroCallNode macroCallNode = new MacroCallNode(macro);
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;
}
示例5: parseMacro
import com.intellij.codeInsight.template.Macro; //导入依赖的package包/类
@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(token.substring(1, token.length() - 1).replaceAll("\\\\n", "\n").
replaceAll("\\\\r", "\r").replaceAll("\\\\t", "\t").replaceAll("\\\\f", "\f").replaceAll("\\\\(.)", "$1"));
}
if (tokenType != MacroTokenType.IDENTIFIER) {
System.out.println("Bad macro syntax: Not identifier: " + token);
advance(lexer);
return new ConstantNode("");
}
Macro macro = MacroFactory.createMacro(token);
if (macro == null) {
return parseVariable(lexer, expression);
}
advance(lexer);
MacroCallNode macroCallNode = new MacroCallNode(macro);
if (lexer.getTokenType() == null) {
return macroCallNode;
}
if (lexer.getTokenType() != MacroTokenType.LPAREN) {
return macroCallNode;
}
advance(lexer);
parseParameters(macroCallNode, lexer, expression);
if (lexer.getTokenType() != MacroTokenType.RPAREN) {
System.out.println("Bad macro syntax: ) expected: " + expression);
}
advance(lexer);
return macroCallNode;
}
示例6: init
import com.intellij.codeInsight.template.Macro; //导入依赖的package包/类
private static MultiMap<String, Macro> init() {
MultiMap<String, Macro> result = MultiMap.create();
for(Macro macro: Extensions.getExtensions(Macro.EP_NAME)) {
result.putValue(macro.getName(), macro);
}
return result;
}
示例7: parseMacro
import com.intellij.codeInsight.template.Macro; //导入依赖的package包/类
@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;
}
示例8: register
import com.intellij.codeInsight.template.Macro; //导入依赖的package包/类
/**
* @deprecated use com.intellij.liveTemplateMacro extension point instead
*/
public static void register(Macro macro) {
if (myMacroTable == null) init();
myMacroTable.put(macro.getName(), macro);
}
示例9: getMacro
import com.intellij.codeInsight.template.Macro; //导入依赖的package包/类
public Macro getMacro() {
return myMacro;
}
示例10: MacroCallNode
import com.intellij.codeInsight.template.Macro; //导入依赖的package包/类
public MacroCallNode(@NotNull Macro macro) {
myMacro = macro;
}
示例11: createVariablesTable
import com.intellij.codeInsight.template.Macro; //导入依赖的package包/类
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);
}
ComboBox comboField = new ComboBox();
Macro[] macros = MacroFactory.getMacros();
Arrays.sort(macros, new Comparator<Macro> () {
@Override
public int compare(@NotNull Macro m1, @NotNull Macro m2) {
return m1.getPresentableName().compareTo(m2.getPresentableName());
}
});
eachMacro:
for (Macro macro : macros) {
for (TemplateContextType contextType : myContextTypes) {
if (macro.isAcceptableInContext(contextType)) {
comboField.addItem(macro.getPresentableName());
continue eachMacro;
}
}
}
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();
}
示例12: createVariablesTable
import com.intellij.codeInsight.template.Macro; //导入依赖的package包/类
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);
}
JComboBox comboField = new JComboBox();
Macro[] macros = MacroFactory.getMacros();
Arrays.sort(macros, new Comparator<Macro> () {
@Override
public int compare(Macro m1, Macro m2) {
return m1.getPresentableName().compareTo(m2.getPresentableName());
}
});
eachMacro:
for (Macro macro : macros) {
for (TemplateContextType contextType : myContextTypes) {
if (macro.isAcceptableInContext(contextType)) {
comboField.addItem(macro.getPresentableName());
continue eachMacro;
}
}
}
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();
}
示例13: createMacro
import com.intellij.codeInsight.template.Macro; //导入依赖的package包/类
public static Macro createMacro(@NonNls String name) {
return ContainerUtil.getFirstItem(myMacroTable.get(name));
}
示例14: getMacros
import com.intellij.codeInsight.template.Macro; //导入依赖的package包/类
public static List<Macro> getMacros(@NonNls String name) {
return (List<Macro>)myMacroTable.get(name);
}
示例15: MacroCallNode
import com.intellij.codeInsight.template.Macro; //导入依赖的package包/类
public MacroCallNode(@Nonnull Macro macro) {
myMacro = macro;
}