本文整理汇总了Java中com.intellij.codeInsight.template.Template.setToReformat方法的典型用法代码示例。如果您正苦于以下问题:Java Template.setToReformat方法的具体用法?Java Template.setToReformat怎么用?Java Template.setToReformat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.codeInsight.template.Template
的用法示例。
在下文中一共展示了Template.setToReformat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertMethod
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
@Override
protected void insertMethod(@NotNull Project project, @NotNull Editor editor) {
Template template = TemplateManager.getInstance(project).createTemplate("", "");
template.addTextSegment("public function test");
Expression nameExpr = new ConstantNode("");
template.addVariable("name", nameExpr, nameExpr, true);
template.addTextSegment("()");
PhpLanguageLevel languageLevel = PhpProjectConfigurationFacade.getInstance(project).getLanguageLevel();
if (languageLevel.hasFeature(PhpLanguageFeature.RETURN_VOID)) {
template.addTextSegment(": void");
}
template.addTextSegment("\n{\n");
template.addEndVariable();
template.addTextSegment("\n}");
template.setToIndent(true);
template.setToReformat(true);
template.setToShortenLongNames(true);
TemplateManager.getInstance(project).startTemplate(editor, template, null);
}
示例2: applyFix
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor)
{
final PsiElement element = descriptor.getPsiElement();
final Editor editor = BaseCreateFix.getEditor(project, element.getContainingFile());
if(editor == null)
{
return;
}
final String shortenedType = JSResolveUtil.getShortenedType(this.type, element);
final TemplateManager templateManager = TemplateManager.getInstance(project);
Template template = templateManager.createTemplate("", "", shortenedType + "($SELECTION$)");
template.setToReformat(true);
final int offset = element.getTextOffset();
editor.getSelectionModel().setSelection(offset, offset + element.getTextLength());
editor.getCaretModel().moveToOffset(offset);
templateManager.startTemplate(editor, element.getText(), template);
}
示例3: applyFix
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) {
Method method = (Method)methodReference.resolve();
if (method != null) {
Parameter[] parameters = method.getParameters();
int paramParameterIndex = ClassUtils.getParamIndex(method, "params");
int conditionParameterIndex = ClassUtils.getParamIndex(method, new String[]{ "condition", "expression", "sql"});
if (paramParameterIndex > -1
&& conditionParameterIndex > -1
&& conditionParameterIndex == paramParameterIndex - 1
&& methodReference.getParameters().length > conditionParameterIndex) {
String condition = methodReference.getParameters()[conditionParameterIndex].getText();
String[] conditionParams = DatabaseUtils.extractParamsFromCondition(condition);
ArrayCreationExpression array = null;
if (methodReference.getParameters().length > paramParameterIndex) {
PsiElement paramParameter = methodReference.getParameters()[paramParameterIndex];
if (paramParameter instanceof ArrayCreationExpression)
array = (ArrayCreationExpression)paramParameter;
paramParameter.delete();
}
TemplateManager templateManager = TemplateManager.getInstance(project);
Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
if (editor == null || methodReference.getParameterList() == null) return;
editor.getCaretModel().moveToOffset(methodReference.getParameterList().getLastChild().getTextRange().getEndOffset());
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
Template template = templateManager.createTemplate("", "");
template.setToReformat(true);
buildParamArray(template, conditionParams, array, conditionParameterIndex);
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
templateManager.startTemplate(editor, template);
}
}
}
示例4: applyFix
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) {
List<PhpDocPropertyTag> propertyTags = this.comment.getPropertyTags();
Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
if (editor == null)
return;
Document document = editor.getDocument();
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document);
TemplateManager templateManager = TemplateManager.getInstance(project);
Template template = templateManager.createTemplate("", "");
template.setToReformat(true);
for (VirtualProperty missingProperty: this.missingProperties)
{
String propertyText = "* @property "+ (missingProperty.getType() != null ? missingProperty.getType() : "") + " $" +missingProperty.getName();
if ( missingProperty.getComment() != null) {
propertyText += " " + missingProperty.getComment();
}
template.addTextSegment("\n" + propertyText);
}
template.addTextSegment("\n");
int offset = comment.getLastChild().getTextOffset();
if (propertyTags.size() > 0) {
PhpDocPropertyTag phpDocPropertyTag = propertyTags.get(comment.getPropertyTags().size() - 1);
offset = phpDocPropertyTag.getTextOffset() + phpDocPropertyTag.getTextLength();
}
editor.getCaretModel().moveToOffset(offset);
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document);
templateManager.startTemplate(editor, template);
}
示例5: insertMethod
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
@Override
protected void insertMethod(@NotNull Project project, @NotNull Editor editor) {
Template template = TemplateManager.getInstance(project).createTemplate("", "");
template.addTextSegment("protected function setUp()\n{\n");
template.addTextSegment("parent::setUp();\n");
template.addEndVariable();
template.addTextSegment("\n}");
template.setToIndent(true);
template.setToReformat(true);
template.setToShortenLongNames(true);
TemplateManager.getInstance(project).startTemplate(editor, template, null);
}
示例6: insertMethod
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
@Override
protected void insertMethod(@NotNull Project project, @NotNull Editor editor) {
Template template = TemplateManager.getInstance(project).createTemplate("", "");
template.addTextSegment("protected function tearDown()\n{\n");
template.addTextSegment("parent::tearDown();\n");
template.addEndVariable();
template.addTextSegment("\n}");
template.setToIndent(true);
template.setToReformat(true);
template.setToShortenLongNames(true);
TemplateManager.getInstance(project).startTemplate(editor, template, null);
}
示例7: addRequiredSubTags
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
private static boolean addRequiredSubTags(Template template, XmlElementDescriptor descriptor, PsiFile file, XmlTag context) {
if (!WebEditorOptions.getInstance().isAutomaticallyInsertRequiredSubTags()) return false;
List<XmlElementDescriptor> requiredSubTags = GenerateXmlTagAction.getRequiredSubTags(descriptor);
if (!requiredSubTags.isEmpty()) {
template.addTextSegment(">");
template.setToReformat(true);
}
for (XmlElementDescriptor subTag : requiredSubTags) {
if (subTag == null) { // placeholder for smart completion
template.addTextSegment("<");
template.addVariable(new MacroCallNode(new CompleteSmartMacro()), true);
continue;
}
String qname = subTag.getName();
if (subTag instanceof XmlElementDescriptorImpl) {
String prefixByNamespace = context.getPrefixByNamespace(((XmlElementDescriptorImpl)subTag).getNamespace());
if (StringUtil.isNotEmpty(prefixByNamespace)) {
qname = prefixByNamespace + ":" + subTag.getName();
}
}
template.addTextSegment("<" + qname);
addRequiredAttributes(subTag, null, template, file);
completeTagTail(template, subTag, file, context, false);
}
if (!requiredSubTags.isEmpty()) {
addTagEnd(template, descriptor, context);
}
return !requiredSubTags.isEmpty();
}
示例8: addTextTo
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
protected void addTextTo(Template template, XmlTag rootTag) {
String schemaPrefix = rootTag.getPrefixByNamespace(XmlUtil.XML_SCHEMA_URI);
if (!schemaPrefix.isEmpty()) schemaPrefix += ":";
template.addTextSegment(
"<" + schemaPrefix + myDeclarationTagName + " name=\"" + XmlUtil.findLocalNameByQualifiedName(myRef.getCanonicalText()) + "\">"
);
template.addEndVariable();
template.addTextSegment(
"</" + schemaPrefix + myDeclarationTagName + ">\n"
);
template.setToReformat(true);
}
示例9: addTextTo
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
protected void addTextTo(Template template, XmlTag rootTag) {
String schemaPrefix = rootTag.getPrefixByNamespace(XmlUtil.XML_SCHEMA_URI);
if (schemaPrefix.length() > 0) schemaPrefix += ":";
template.addTextSegment(
"<" + schemaPrefix + myDeclarationTagName + " name=\"" + XmlUtil.findLocalNameByQualifiedName(myRef.getCanonicalText()) + "\">"
);
template.addEndVariable();
template.addTextSegment(
"</" + schemaPrefix + myDeclarationTagName + ">\n"
);
template.setToReformat(true);
}
示例10: addRequiredSubTags
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
private static boolean addRequiredSubTags(Template template, XmlElementDescriptor descriptor, PsiFile file, XmlTag context)
{
if(!XmlEditorOptions.getInstance().isAutomaticallyInsertRequiredSubTags())
{
return false;
}
List<XmlElementDescriptor> requiredSubTags = GenerateXmlTagAction.getRequiredSubTags(descriptor);
if(!requiredSubTags.isEmpty())
{
template.addTextSegment(">");
template.setToReformat(true);
}
for(XmlElementDescriptor subTag : requiredSubTags)
{
if(subTag == null)
{ // placeholder for smart completion
template.addTextSegment("<");
template.addVariable(new MacroCallNode(new CompleteSmartMacro()), true);
continue;
}
String qname = subTag.getName();
if(subTag instanceof XmlElementDescriptorImpl)
{
String prefixByNamespace = context.getPrefixByNamespace(((XmlElementDescriptorImpl) subTag).getNamespace());
if(StringUtil.isNotEmpty(prefixByNamespace))
{
qname = prefixByNamespace + ":" + subTag.getName();
}
}
template.addTextSegment("<" + qname);
addRequiredAttributes(subTag, null, template, file);
completeTagTail(template, subTag, file, context, false);
}
if(!requiredSubTags.isEmpty())
{
addTagEnd(template, descriptor, context);
}
return !requiredSubTags.isEmpty();
}
示例11: addTextTo
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
protected void addTextTo(Template template, XmlTag rootTag) {
String schemaPrefix = rootTag.getPrefixByNamespace(XmlUtil.XML_SCHEMA_URI);
if (!schemaPrefix.isEmpty()) schemaPrefix += ":";
template.addTextSegment(
"<" + schemaPrefix + myDeclarationTagName + " name=\"" + XmlUtil.findLocalNameByQualifiedName(myRef.getCanonicalText()) + "\">"
);
template.addEndVariable();
template.addTextSegment(
"</" + schemaPrefix + myDeclarationTagName + ">\n"
);
template.setToReformat(true);
}
示例12: expand
import com.intellij.codeInsight.template.Template; //导入方法依赖的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);
}
示例13: expand
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
@Override
public void expand(@NotNull PsiElement context, @NotNull Editor editor) {
PsiExpression expr = JavaPostfixTemplatesUtils.getTopmostExpression(context);
if (expr == null) {
PostfixTemplatesUtils.showErrorHint(context.getProject(), editor);
return;
}
Pair<String, String> bounds = calculateBounds(expr);
if (bounds == null) {
PostfixTemplatesUtils.showErrorHint(context.getProject(), editor);
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 (" + suggestIndexType(expr) + " ");
MacroCallNode index = new MacroCallNode(new SuggestVariableNameMacro());
String indexVariable = "index";
template.addVariable(indexVariable, index, index, true);
template.addTextSegment(" = " + bounds.first + "; ");
template.addVariableSegment(indexVariable);
template.addTextSegment(getComparativeSign(expr));
template.addTextSegment(bounds.second);
template.addTextSegment("; ");
template.addVariableSegment(indexVariable);
template.addTextSegment(getOperator());
template.addTextSegment(") {\n");
template.addEndVariable();
template.addTextSegment("\n}");
manager.startTemplate(editor, template);
}
示例14: createTestMethodTemplate
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
public static Template createTestMethodTemplate(MethodKind methodKind,
TestFramework descriptor,
PsiClass targetClass,
@Nullable String name,
boolean automatic,
Set<String> existingNames) {
FileTemplateDescriptor templateDesc = methodKind.getFileTemplateDescriptor(descriptor);
String templateName = templateDesc.getFileName();
FileTemplate fileTemplate = FileTemplateManager.getInstance(targetClass.getProject()).getCodeTemplate(templateName);
Template template = TemplateManager.getInstance(targetClass.getProject()).createTemplate("", "");
String templateText;
try {
templateText = fileTemplate.getText(new Properties());
}
catch (IOException e) {
LOG.warn(e);
templateText = fileTemplate.getText();
}
if (name == null) name = methodKind.getDefaultName();
if (existingNames != null && !existingNames.add(name)) {
int idx = 1;
while (existingNames.contains(name)) {
final String newName = name + (idx++);
if (existingNames.add(newName)) {
name = newName;
break;
}
}
}
templateText = StringUtil.replace(templateText, "${BODY}", "");
int from = 0;
while (true) {
int index = templateText.indexOf("${NAME}", from);
if (index == -1) break;
template.addTextSegment(templateText.substring(from, index));
if (index > 0 && !Character.isWhitespace(templateText.charAt(index - 1))) {
name = StringUtil.capitalize(name);
}
else {
name = StringUtil.decapitalize(name);
}
if (from == 0) {
Expression nameExpr = new ConstantNode(name);
template.addVariable("name", nameExpr, nameExpr, !automatic);
}
else {
template.addVariableSegment("name");
}
from = index + "${NAME}".length();
}
template.addTextSegment(templateText.substring(from, templateText.length()));
template.setToIndent(true);
template.setToReformat(true);
template.setToShortenLongNames(true);
return template;
}
示例15: createTemplate
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
public Template createTemplate(TemplateManager manager, String templateString) {
Template template = manager.createTemplate("", "", templateString);
template.setToReformat(shouldReformat());
return template;
}