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;
}
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;
}
}
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();
}
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);
}
Aggregations