Search in sources :

Example 1 with TextResult

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

the class ParameterNameExpression method calculateResult.

@Override
public Result calculateResult(ExpressionContext context) {
    PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getEditor().getDocument());
    SuggestedNameInfo info = getNameInfo(context);
    if (info == null)
        return new TextResult("p");
    String[] names = info.names;
    if (names.length > 0) {
        return new TextResult(names[0]);
    }
    return null;
}
Also used : TextResult(com.intellij.codeInsight.template.TextResult) SuggestedNameInfo(com.intellij.psi.codeStyle.SuggestedNameInfo)

Example 2 with TextResult

use of com.intellij.codeInsight.template.TextResult in project intellij-plugins by JetBrains.

the class DartClassNameMethodNameMacro method calculateResult.

@Override
public Result calculateResult(@NotNull Expression[] params, final ExpressionContext context) {
    final Result classNameResult = (new DartClassNameMacro()).calculateResult(params, context);
    final Result methodNameResult = (new DartMethodNameMacro()).calculateResult(params, context);
    if (classNameResult != null && methodNameResult != null) {
        return new TextResult(classNameResult.toString() + "." + methodNameResult.toString());
    } else if (classNameResult == null && methodNameResult != null) {
        return new TextResult(methodNameResult.toString());
    } else if (classNameResult != null) {
        return new TextResult(classNameResult.toString());
    } else {
        return null;
    }
}
Also used : TextResult(com.intellij.codeInsight.template.TextResult) Result(com.intellij.codeInsight.template.Result) TextResult(com.intellij.codeInsight.template.TextResult)

Example 3 with TextResult

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

the class AbstractInplaceIntroducer method startInplaceIntroduceTemplate.

/**
   * Begins the in-place refactoring operation.
   *
   * @return true if the in-place refactoring was successfully started, false if it failed to start and a dialog should be shown instead.
   */
public boolean startInplaceIntroduceTemplate() {
    final boolean replaceAllOccurrences = isReplaceAllOccurrences();
    final Ref<Boolean> result = new Ref<>();
    CommandProcessor.getInstance().executeCommand(myProject, () -> {
        final String[] names = suggestNames(replaceAllOccurrences, getLocalVariable());
        final V variable = createFieldToStartTemplateOn(replaceAllOccurrences, names);
        boolean started = false;
        if (variable != null) {
            int caretOffset = getCaretOffset();
            myEditor.getCaretModel().moveToOffset(caretOffset);
            myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
            final LinkedHashSet<String> nameSuggestions = new LinkedHashSet<>();
            nameSuggestions.add(variable.getName());
            nameSuggestions.addAll(Arrays.asList(names));
            initOccurrencesMarkers();
            setElementToRename(variable);
            updateTitle(getVariable());
            started = super.performInplaceRefactoring(nameSuggestions);
            if (started) {
                onRenameTemplateStarted();
                myDocumentAdapter = new DocumentAdapter() {

                    @Override
                    public void documentChanged(DocumentEvent e) {
                        if (myPreview == null)
                            return;
                        final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor);
                        if (templateState != null) {
                            final TextResult value = templateState.getVariableValue(InplaceRefactoring.PRIMARY_VARIABLE_NAME);
                            if (value != null) {
                                updateTitle(getVariable(), value.getText());
                            }
                        }
                    }
                };
                myEditor.getDocument().addDocumentListener(myDocumentAdapter);
                updateTitle(getVariable());
                if (TemplateManagerImpl.getTemplateState(myEditor) != null) {
                    myEditor.putUserData(ACTIVE_INTRODUCE, this);
                }
            }
        }
        result.set(started);
        if (!started) {
            finish(true);
        }
    }, getCommandName(), getCommandName());
    return result.get();
}
Also used : TextResult(com.intellij.codeInsight.template.TextResult) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) TemplateState(com.intellij.codeInsight.template.impl.TemplateState) Ref(com.intellij.openapi.util.Ref)

Example 4 with TextResult

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

the class MyLookupExpression method calculateResult.

@Override
public Result calculateResult(ExpressionContext context) {
    TemplateState templateState = TemplateManagerImpl.getTemplateState(context.getEditor());
    final TextResult insertedValue = templateState != null ? templateState.getVariableValue(InplaceRefactoring.PRIMARY_VARIABLE_NAME) : null;
    if (insertedValue != null) {
        if (!insertedValue.getText().isEmpty())
            return insertedValue;
    }
    return new TextResult(myName);
}
Also used : TextResult(com.intellij.codeInsight.template.TextResult) TemplateState(com.intellij.codeInsight.template.impl.TemplateState)

Aggregations

TextResult (com.intellij.codeInsight.template.TextResult)4 TemplateState (com.intellij.codeInsight.template.impl.TemplateState)2 Result (com.intellij.codeInsight.template.Result)1 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)1 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1 Ref (com.intellij.openapi.util.Ref)1 SuggestedNameInfo (com.intellij.psi.codeStyle.SuggestedNameInfo)1