use of com.intellij.codeInsight.template.impl.ConstantNode in project intellij-community by JetBrains.
the class TemplateBuilderImpl method replaceRange.
@Override
public void replaceRange(TextRange rangeWithinElement, String replacementText) {
final RangeMarker key = myDocument.createRangeMarker(rangeWithinElement.shiftRight(myContainerElement.getStartOffset()));
ConstantNode value = new ConstantNode(replacementText);
replaceElement(key, value);
}
use of com.intellij.codeInsight.template.impl.ConstantNode in project intellij-community by JetBrains.
the class JavaMethodCallElement method createArgTemplate.
@NotNull
private static Template createArgTemplate(PsiMethod method, int caretOffset, PsiExpressionList argList, TextRange argRange) {
Template template = TemplateManager.getInstance(method.getProject()).createTemplate("", "");
PsiParameter[] parameters = method.getParameterList().getParameters();
for (int i = 0; i < parameters.length; i++) {
if (i > 0) {
template.addTextSegment(", ");
}
String name = StringUtil.notNullize(parameters[i].getName());
Expression expression = Registry.is("java.completion.argument.live.template.completion") ? new AutoPopupCompletion() : new ConstantNode(name);
template.addVariable(name, expression, new ConstantNode(name), true);
}
boolean finishInsideParens = method.isVarArgs();
if (finishInsideParens) {
template.addEndVariable();
}
template.addTextSegment(argList.getText().substring(caretOffset - argRange.getStartOffset(), argList.getTextLength()));
if (!finishInsideParens) {
template.addEndVariable();
}
return template;
}
use of com.intellij.codeInsight.template.impl.ConstantNode in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoIntroduceFunctionFix method setupFunctionParameters.
private static void setupFunctionParameters(@NotNull Template template, @NotNull List<GoExpression> args, PsiFile file) {
Map<String, GoImportSpec> importMap = ((GoFile) file).getImportedPackagesMap();
template.addTextSegment("(");
for (int i = 0; i < args.size(); i++) {
GoExpression e = args.get(i);
template.addVariable(GoRefactoringUtil.createParameterNameSuggestedExpression(e), true);
template.addTextSegment(" ");
String type = convertType(file, e.getGoType(null), importMap);
template.addVariable(new ConstantNode(type), true);
if (i != args.size() - 1)
template.addTextSegment(", ");
}
template.addTextSegment(")");
}
use of com.intellij.codeInsight.template.impl.ConstantNode in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoIntroduceFunctionFix method setupFunctionResult.
private static void setupFunctionResult(@NotNull Template template, @Nullable GoType type) {
if (type instanceof GoTypeList) {
template.addTextSegment(" (");
List<GoType> list = ((GoTypeList) type).getTypeList();
for (int i = 0; i < list.size(); i++) {
template.addVariable(new ConstantNode(list.get(i).getText()), true);
if (i < list.size() - 1)
template.addTextSegment(", ");
}
template.addTextSegment(")");
return;
}
if (type != null) {
template.addTextSegment(" ");
template.addVariable(new ConstantNode(type.getText()), true);
}
}
use of com.intellij.codeInsight.template.impl.ConstantNode in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoCreateWrapperTypeQuickFix method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable("is null when called from inspection") Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
if (editor == null) {
LOG.error("Cannot run quick fix without editor: " + getClass().getSimpleName(), AttachmentFactory.createAttachment(file.getVirtualFile()));
return;
}
if (!(startElement instanceof GoType))
return;
GoType type = (GoType) startElement;
PsiElement anchor = PsiTreeUtil.findPrevParent(file, type);
String name = "TypeName";
GoTypeDeclaration decl = (GoTypeDeclaration) file.addBefore(GoElementFactory.createTypeDeclaration(project, name, type), anchor);
if (decl == null)
return;
decl = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(decl);
if (decl == null)
return;
GoTypeSpec spec = ContainerUtil.getFirstItem(decl.getTypeSpecList());
if (spec == null)
return;
TemplateBuilderImpl builder = new TemplateBuilderImpl(file);
builder.replaceElement(type, OTHER_NAME, INPUT_NAME, false);
builder.replaceElement(spec.getIdentifier(), INPUT_NAME, new ConstantNode(name), true);
editor.getCaretModel().moveToOffset(file.getTextRange().getStartOffset());
Template template = builder.buildInlineTemplate();
editor.getCaretModel().moveToOffset(file.getTextRange().getStartOffset());
TemplateManager.getInstance(project).startTemplate(editor, template);
}
Aggregations