本文整理汇总了Java中com.intellij.codeInsight.template.impl.VariableNode类的典型用法代码示例。如果您正苦于以下问题:Java VariableNode类的具体用法?Java VariableNode怎么用?Java VariableNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VariableNode类属于com.intellij.codeInsight.template.impl包,在下文中一共展示了VariableNode类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setVariables
import com.intellij.codeInsight.template.impl.VariableNode; //导入依赖的package包/类
@Override
public void setVariables(@NotNull Template template, @NotNull PsiElement element) {
MacroCallNode type = new MacroCallNode(new IterableComponentTypeMacro());
MacroCallNode name = new MacroCallNode(new SuggestVariableNameMacro());
type.addParameter(new VariableNode("expr", null));
template.addVariable("type", type, type, false);
template.addVariable("name", name, name, true);
}
示例2: createElement
import com.intellij.codeInsight.template.impl.VariableNode; //导入依赖的package包/类
@Override
protected DomElement createElement(final WebApp context,
final Editor editor,
PsiFile file,
final Project project,
final PsiClass selectedClass) {
new WriteCommandAction.Simple(project, "Create Filter", file) {
@Override
protected void run() throws Throwable {
Filter filter = (Filter)createElement(context);
filter.getFilterClass().setValue(selectedClass);
FilterMapping mapping = context.addFilterMapping();
TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(context.getXmlElement());
VariableNode nameNode = new VariableNode("NAME", new MacroCallNode(new CompleteMacro()));
replaceElementValue(builder, filter.getFilterName(), nameNode);
replaceElementValue(builder, mapping.getFilterName(), nameNode);
GenericDomValue<String> value = mapping.addUrlPattern();
XmlTag tag = value.ensureTagExists();
PsiElement child = tag.getLastChild();
while (child != null && child != tag.getFirstChild()) {
PsiElement prevSibling = child.getPrevSibling();
child.delete();
child = prevSibling;
}
builder.replaceElement(tag, TextRange.from(1, 0), new MacroCallNode(new CompleteSmartMacro()));
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
builder.run();
}
}.execute();
return null;
}
示例3: createElement
import com.intellij.codeInsight.template.impl.VariableNode; //导入依赖的package包/类
@Override
protected DomElement createElement(final WebApp context,
final Editor editor,
PsiFile file,
final Project project,
final PsiClass selectedClass) {
new WriteCommandAction.Simple(project, "Create servlet", file) {
@Override
protected void run() throws Throwable {
Servlet servlet = (Servlet)createElement(context);
servlet.getServletClass().setValue(selectedClass);
ServletMapping mapping = context.addServletMapping();
TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(context.getXmlElement());
VariableNode nameNode = new VariableNode("NAME", new MacroCallNode(new CompleteMacro()));
replaceElementValue(builder, servlet.getServletName(), nameNode);
replaceElementValue(builder, mapping.getServletName(), nameNode);
replaceElementValue(builder, mapping.addUrlPattern(), new EmptyNode());
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
builder.run();
}
}.execute();
return null;
}
示例4: expand
import com.intellij.codeInsight.template.impl.VariableNode; //导入依赖的package包/类
@Override
public void expand(@NotNull PsiElement context, @NotNull Editor editor) {
PsiExpression expr = JavaPostfixTemplatesUtils.getTopmostExpression(context);
if (expr == null) return;
Project project = context.getProject();
Document document = editor.getDocument();
document.deleteString(expr.getTextRange().getStartOffset(), expr.getTextRange().getEndOffset());
TemplateManager manager = TemplateManager.getInstance(project);
Template template = manager.createTemplate("", "");
template.setToReformat(true);
template.addTextSegment("for (");
MacroCallNode type = new MacroCallNode(new IterableComponentTypeMacro());
String variable = "variable";
type.addParameter(new VariableNode(variable, null));
MacroCallNode name = new MacroCallNode(new SuggestVariableNameMacro());
template.addVariable("type", type, type, false);
template.addTextSegment(" ");
template.addVariable("name", name, name, true);
template.addTextSegment(" : ");
template.addVariable(variable, new TextExpression(expr.getText()), false);
template.addTextSegment(") {\n");
template.addEndVariable();
template.addTextSegment("\n}");
manager.startTemplate(editor, template);
}