本文整理汇总了Java中com.intellij.codeInsight.template.impl.ConstantNode类的典型用法代码示例。如果您正苦于以下问题:Java ConstantNode类的具体用法?Java ConstantNode怎么用?Java ConstantNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConstantNode类属于com.intellij.codeInsight.template.impl包,在下文中一共展示了ConstantNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertMethod
import com.intellij.codeInsight.template.impl.ConstantNode; //导入依赖的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: addExprVariable
import com.intellij.codeInsight.template.impl.ConstantNode; //导入依赖的package包/类
@Override
protected void addExprVariable(@NotNull PsiElement expr, Template template) {
ToStringIfNeedMacro toStringIfNeedMacro = new ToStringIfNeedMacro();
MacroCallNode macroCallNode = new MacroCallNode(toStringIfNeedMacro);
macroCallNode.addParameter(new ConstantNode(expr.getText()));
MacroCallNode node = new MacroCallNode(new VariableOfTypeMacro());
node.addParameter(new ConstantNode(VIEW.toString()));
template.addVariable("view", node, new EmptyNode(), false);
template.addVariable("expr", macroCallNode, false);
if (mWithAction) {
template.addVariable("actionText", new EmptyNode(), false);
template.addVariable("action", new EmptyNode(), false);
}
}
示例3: buildParameterList
import com.intellij.codeInsight.template.impl.ConstantNode; //导入依赖的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: replaceRange
import com.intellij.codeInsight.template.impl.ConstantNode; //导入依赖的package包/类
@Override
public void replaceRange(TextRange rangeWithinElement, String replacementText) {
final RangeMarker key = myDocument.createRangeMarker(rangeWithinElement.shiftRight(myContainerElement.getStartOffset()));
ConstantNode value = new ConstantNode(replacementText);
replaceElement(key, value);
}
示例5: addExprVariable
import com.intellij.codeInsight.template.impl.ConstantNode; //导入依赖的package包/类
@Override
protected void addExprVariable(@NotNull PsiElement expr, Template template) {
final ToStringIfNeedMacro toStringIfNeedMacro = new ToStringIfNeedMacro();
MacroCallNode macroCallNode = new MacroCallNode(toStringIfNeedMacro);
macroCallNode.addParameter(new ConstantNode(expr.getText()));
template.addVariable("expr", macroCallNode, false);
}
示例6: setVariables
import com.intellij.codeInsight.template.impl.ConstantNode; //导入依赖的package包/类
@Override
protected void setVariables(@NotNull Template template, @NotNull PsiElement element) {
MacroCallNode node = new MacroCallNode(new VariableOfTypeMacro());
node.addParameter(new ConstantNode(CONTEXT.toString()));
template.addVariable("context", node, new ConstantNode(""), false);
}
示例7: addExprVariable
import com.intellij.codeInsight.template.impl.ConstantNode; //导入依赖的package包/类
@Override
protected void addExprVariable(@NotNull PsiElement expr, Template template) {
final FindViewByIdMacro toStringIfNeedMacro = new FindViewByIdMacro();
MacroCallNode macroCallNode = new MacroCallNode(toStringIfNeedMacro);
macroCallNode.addParameter(new ConstantNode(expr.getText()));
template.addVariable("expr", macroCallNode, false);
}
示例8: createArgTemplate
import com.intellij.codeInsight.template.impl.ConstantNode; //导入依赖的package包/类
@NotNull
private static Template createArgTemplate(PsiMethod method, int caretOffset, PsiExpressionList argList, TextRange argRange)
{
Template template = TemplateManager.getInstance(method.getProject()).createTemplate("", "");
PsiParameter[] parameters = method.getParameterList().getParameters();
for(int i = 0; i < parameters.length; i++)
{
if(i > 0)
{
template.addTextSegment(", ");
}
String name = StringUtil.notNullize(parameters[i].getName());
Expression expression = JAVA_COMPLETION_ARGUMENT_LIVE_TEMPLATE_COMPLETION ? new AutoPopupCompletion() : new ConstantNode(name);
template.addVariable(name, expression, new ConstantNode(name), true);
}
boolean finishInsideParens = method.isVarArgs();
if(finishInsideParens)
{
template.addEndVariable();
}
template.addTextSegment(argList.getText().substring(caretOffset - argRange.getStartOffset(), argList.getTextLength()));
if(!finishInsideParens)
{
template.addEndVariable();
}
return template;
}
示例9: createTestMethodTemplate
import com.intellij.codeInsight.template.impl.ConstantNode; //导入依赖的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;
}
示例10: replaceElement
import com.intellij.codeInsight.template.impl.ConstantNode; //导入依赖的package包/类
@Override
public void replaceElement(@NotNull PsiElement element, String replacementText) {
replaceElement(element, new ConstantNode(replacementText));
}
示例11: getVariableByFQDN
import com.intellij.codeInsight.template.impl.ConstantNode; //导入依赖的package包/类
private Result getVariableByFQDN(ExpressionContext context, String fqn) {
MacroCallNode callNode = new MacroCallNode(new VariableOfTypeMacro());
callNode.addParameter(new ConstantNode(fqn));
return callNode.calculateResult(context);
}
示例12: setVariables
import com.intellij.codeInsight.template.impl.ConstantNode; //导入依赖的package包/类
@Override
protected void setVariables(@NotNull Template template, @NotNull PsiElement element) {
MacroCallNode node = new MacroCallNode(new TagMacro());
template.addVariable("TAG", node, new ConstantNode(""), false);
}
示例13: createTestMethodTemplate
import com.intellij.codeInsight.template.impl.ConstantNode; //导入依赖的package包/类
private static Template createTestMethodTemplate(MethodKind methodKind,
TestFramework descriptor,
PsiClass targetClass,
@Nullable String name,
boolean automatic) {
FileTemplateDescriptor templateDesc = methodKind.getFileTemplateDescriptor(descriptor);
String templateName = templateDesc.getFileName();
FileTemplate fileTemplate = FileTemplateManager.getInstance().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();
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;
}
示例14: replaceElement
import com.intellij.codeInsight.template.impl.ConstantNode; //导入依赖的package包/类
@Override
public void replaceElement(@Nonnull PsiElement element, String replacementText) {
replaceElement(element, new ConstantNode(replacementText));
}
示例15: createTestMethodTemplate
import com.intellij.codeInsight.template.impl.ConstantNode; //导入依赖的package包/类
private static Template createTestMethodTemplate(MethodKind methodKind,
TestFramework descriptor,
PsiClass targetClass,
@Nullable String name,
boolean automatic) {
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();
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;
}