Search in sources :

Example 6 with Expression

use of com.intellij.codeInsight.template.Expression in project intellij-community by JetBrains.

the class HighlightUtil method showRenameTemplate.

public static void showRenameTemplate(PsiElement context, PsiNameIdentifierOwner element) {
    context = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(context);
    final Query<PsiReference> query = ReferencesSearch.search(element, element.getUseScope());
    final Collection<PsiReference> references = query.findAll();
    final Project project = context.getProject();
    final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
    final Editor editor = fileEditorManager.getSelectedTextEditor();
    if (editor == null) {
        return;
    }
    final TemplateBuilderImpl builder = new TemplateBuilderImpl(context);
    final Expression macroCallNode = new MacroCallNode(new SuggestVariableNameMacro());
    final PsiElement identifier = element.getNameIdentifier();
    builder.replaceElement(identifier, "PATTERN", macroCallNode, true);
    for (PsiReference reference : references) {
        builder.replaceElement(reference, "PATTERN", "PATTERN", false);
    }
    final Template template = builder.buildInlineTemplate();
    final TextRange textRange = context.getTextRange();
    final int startOffset = textRange.getStartOffset();
    editor.getCaretModel().moveToOffset(startOffset);
    final TemplateManager templateManager = TemplateManager.getInstance(project);
    templateManager.startTemplate(editor, template);
}
Also used : PsiReference(com.intellij.psi.PsiReference) TextRange(com.intellij.openapi.util.TextRange) Template(com.intellij.codeInsight.template.Template) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) TemplateBuilderImpl(com.intellij.codeInsight.template.TemplateBuilderImpl) Expression(com.intellij.codeInsight.template.Expression) TemplateManager(com.intellij.codeInsight.template.TemplateManager) SuggestVariableNameMacro(com.intellij.codeInsight.template.macro.SuggestVariableNameMacro) MacroCallNode(com.intellij.codeInsight.template.impl.MacroCallNode) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement)

Example 7 with Expression

use of com.intellij.codeInsight.template.Expression in project kotlin by JetBrains.

the class KotlinInplaceVariableIntroducer method addTypeReferenceVariable.

protected void addTypeReferenceVariable(TemplateBuilderImpl builder) {
    KtTypeReference typeReference = myDeclaration.getTypeReference();
    Expression expression = SpecifyTypeExplicitlyIntention.Companion.createTypeExpressionForTemplate(myExprType, myDeclaration);
    if (typeReference != null && expression != null) {
        builder.replaceElement(typeReference, TYPE_REFERENCE_VARIABLE_NAME, expression, false);
    }
}
Also used : Expression(com.intellij.codeInsight.template.Expression)

Aggregations

Expression (com.intellij.codeInsight.template.Expression)7 Template (com.intellij.codeInsight.template.Template)3 TemplateBuilderImpl (com.intellij.codeInsight.template.TemplateBuilderImpl)2 TemplateManager (com.intellij.codeInsight.template.TemplateManager)2 MacroCallNode (com.intellij.codeInsight.template.impl.MacroCallNode)2 SuggestVariableNameMacro (com.intellij.codeInsight.template.macro.SuggestVariableNameMacro)2 Editor (com.intellij.openapi.editor.Editor)2 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)2 Project (com.intellij.openapi.project.Project)2 TextRange (com.intellij.openapi.util.TextRange)2 PsiElement (com.intellij.psi.PsiElement)2 PsiReference (com.intellij.psi.PsiReference)2 ConstantNode (com.intellij.codeInsight.template.impl.ConstantNode)1 FileTemplate (com.intellij.ide.fileTemplates.FileTemplate)1 FileTemplateDescriptor (com.intellij.ide.fileTemplates.FileTemplateDescriptor)1 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)1 IOException (java.io.IOException)1