本文整理汇总了Java中com.intellij.codeInsight.template.Template.addTextSegment方法的典型用法代码示例。如果您正苦于以下问题:Java Template.addTextSegment方法的具体用法?Java Template.addTextSegment怎么用?Java Template.addTextSegment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.codeInsight.template.Template
的用法示例。
在下文中一共展示了Template.addTextSegment方法的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: buildTemplate
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
@RequiredReadAction
@Override
public void buildTemplate(@NotNull CreateUnresolvedElementFixContext context, CSharpContextUtil.ContextType contextType, @NotNull PsiFile file, @NotNull Template template)
{
template.addTextSegment(CreateUnresolvedMethodFix.calcModifier(context).getPresentableText());
template.addTextSegment(" ");
if(contextType == CSharpContextUtil.ContextType.STATIC)
{
template.addTextSegment("static ");
}
template.addVariable(new TypeRefExpression(myLikeMethod.getReturnTypeRef(), file), true);
template.addTextSegment(" ");
template.addTextSegment(myReferenceName);
buildParameterList(context, file, template);
template.addTextSegment("{\n");
template.addVariable("$RETURN_STATEMENT$", new ReturnStatementExpression(), false);
template.addEndVariable();
template.addTextSegment("}");
}
示例3: buildParameterList
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
protected void buildParameterList(@NotNull CreateUnresolvedElementFixContext context, @NotNull PsiFile file, @NotNull Template template)
{
template.addTextSegment("(");
CSharpSimpleParameterInfo[] parameterInfos = myLikeMethod.getParameterInfos();
for(int i = 0; i < parameterInfos.length; i++)
{
if(i != 0)
{
template.addTextSegment(", ");
}
CSharpSimpleParameterInfo parameterInfo = parameterInfos[i];
template.addVariable(new ConstantNode(CSharpTypeRefPresentationUtil.buildShortText(parameterInfo.getTypeRef(), context.getExpression())), true);
template.addTextSegment(" ");
template.addVariable(new ConstantNode(parameterInfo.getNotNullName()), true);
}
template.addTextSegment(")");
}
示例4: addAccessModifier
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
protected static JSExpression addAccessModifier(final Template template, final JSReferenceExpression referenceExpression, final boolean ecma, boolean staticContext)
{
final JSExpression qualifier = referenceExpression.getQualifier();
if(ecma)
{
if((qualifier == null || qualifier instanceof JSThisExpression))
{
template.addTextSegment("private ");
}
if(staticContext)
{
template.addTextSegment("static ");
}
}
return qualifier;
}
示例5: buildParamArray
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
private Template buildParamArray(Template template, String[] conditionParams, ArrayCreationExpression array, int conditionParameterIndex) {
if (methodReference.getParameterList() != null
&& (methodReference.getParameterList().getParameters()[conditionParameterIndex].getNextSibling() == null ||
! methodReference.getParameterList().getParameters()[conditionParameterIndex].getNextSibling().getText().equals(",")))
template.addTextSegment(", ");
template.addTextSegment("[");
String separator = " ";
if (conditionParams.length > 1)
separator = "\n";
Boolean addComma = false;
for (String variable : conditionParams) {
if (addComma) {
template.addTextSegment(",");
}
template.addTextSegment(separator);
String templateVariable = "$" + variable.toUpperCase() + "$";
// template.addVariable(templateVariable, "", "'variable'", true);
String value = getArrayValueByHash(variable, array);
//if (value != null)
// template.addVariable("test", value, true);
String valueStr = value == null ? "''" : value;
template.addTextSegment("'" + variable + "' => " + valueStr);
// template.addVariableSegment(templateVariable);
addComma = true;
}
template.addTextSegment(separator + "]");
return template;
}
示例6: 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);
}
示例7: 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);
}
示例8: 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);
}
示例9: testLiveTemplate
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
public void testLiveTemplate() throws Throwable {
final Template template = TemplateManager.getInstance(getProject()).createTemplate("foo", "zzz");
template.addTextSegment("FooFactory.createFoo()");
final SmartCompletionContextType completionContextType =
ContainerUtil.findInstance(TemplateContextType.EP_NAME.getExtensions(), SmartCompletionContextType.class);
((TemplateImpl)template).getTemplateContext().setEnabled(completionContextType, true);
CodeInsightTestUtil.addTemplate(template, myTestRootDisposable);
doTest();
}
示例10: completeAttribute
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
private static void completeAttribute(Template template) {
template.addTextSegment(" ");
template.addVariable(new MacroCallNode(new CompleteMacro()), true);
template.addTextSegment("=\"");
template.addEndVariable();
template.addTextSegment("\"");
}
示例11: 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();
}
示例12: completeTagTail
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
private static void completeTagTail(Template template, XmlElementDescriptor descriptor, PsiFile file, XmlTag context, boolean firstLevel) {
boolean completeIt = !firstLevel || descriptor.getAttributesDescriptors(null).length == 0;
switch (descriptor.getContentType()) {
case XmlElementDescriptor.CONTENT_TYPE_UNKNOWN:
return;
case XmlElementDescriptor.CONTENT_TYPE_EMPTY:
if (completeIt) {
template.addTextSegment("/>");
}
break;
case XmlElementDescriptor.CONTENT_TYPE_MIXED:
if (completeIt) {
template.addTextSegment(">");
if (firstLevel) {
template.addEndVariable();
}
else {
template.addVariable(new MacroCallNode(new CompleteMacro()), true);
}
addTagEnd(template, descriptor, context);
}
break;
default:
if (!addRequiredSubTags(template, descriptor, file, context)) {
if (completeIt) {
template.addTextSegment(">");
template.addEndVariable();
addTagEnd(template, descriptor, context);
}
}
break;
}
}
示例13: 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);
}
示例14: testLiveTemplate
import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
public void testLiveTemplate() throws Throwable {
final Template template = TemplateManager.getInstance(getProject()).createTemplate("foo", "zzz");
template.addTextSegment("FooFactory.createFoo()");
final SmartCompletionContextType completionContextType =
ContainerUtil.findInstance(TemplateContextType.EP_NAME.getExtensions(), SmartCompletionContextType.class);
((TemplateImpl)template).getTemplateContext().setEnabled(completionContextType, true);
TemplateSettings.getInstance().addTemplate(template);
try {
doTest();
}
finally {
TemplateSettings.getInstance().removeTemplate(template);
}
}
示例15: 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);
}