• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JavaPostfixTemplatesUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils的典型用法代码示例。如果您正苦于以下问题:Java JavaPostfixTemplatesUtils类的具体用法?Java JavaPostfixTemplatesUtils怎么用?Java JavaPostfixTemplatesUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JavaPostfixTemplatesUtils类属于com.intellij.codeInsight.template.postfix.util包,在下文中一共展示了JavaPostfixTemplatesUtils类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: isApplicable

import com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils; //导入依赖的package包/类
@Override
public boolean isApplicable(@NotNull PsiElement element, @NotNull Document copyDocument, int newOffset) {
  if (!PsiUtil.isLanguageLevel7OrHigher(element)) return false;

  PsiExpression initializer = JavaPostfixTemplatesUtils.getTopmostExpression(element);

  if (initializer == null) return false;

  final PsiType type = initializer.getType();
  if (!(type instanceof PsiClassType)) return false;
  final PsiClass aClass = ((PsiClassType)type).resolve();
  Project project = element.getProject();
  final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
  final PsiClass autoCloseable = facade.findClass(CommonClassNames.JAVA_LANG_AUTO_CLOSEABLE, ProjectScope.getLibrariesScope(project));
  if (!InheritanceUtil.isInheritorOrSelf(aClass, autoCloseable, true)) return false;

  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:TryWithResourcesPostfixTemplate.java


示例2: NewExpressionTemplate

import com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils; //导入依赖的package包/类
public NewExpressionTemplate() {
    super(
            "newInstanceReplacement",
            "new Type()",
            JavaPostfixTemplatesUtils.selectorTopmost()
    );
}
 
开发者ID:cesards,项目名称:HakunaMatataIntelliJPlugin,代码行数:8,代码来源:NewExpressionTemplate.java


示例3: EmptyStringTemplate

import com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils; //导入依赖的package包/类
public EmptyStringTemplate() {
    super(
            "emptyCheck",
            "TextUtils.isEmpty(expr)",
            JavaPostfixTemplatesUtils.selectorTopmost(JavaPostfixTemplatesUtils.IS_NOT_PRIMITIVE)
    );
}
 
开发者ID:cesards,项目名称:HakunaMatataIntelliJPlugin,代码行数:8,代码来源:EmptyStringTemplate.java


示例4: getStringTemplate

import com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils; //导入依赖的package包/类
@NotNull
@Override
public String getStringTemplate(@NotNull PsiExpression expr) {
  return JavaPostfixTemplatesUtils.isNumber(expr.getType())
         ? "for ($type$ $index$ = $bound$; $index$ > 0; $index$--) {\n$END$\n}"
         : "for ($type$ $index$ = $bound$ - 1; $index$ >= 0; $index$--) {\n$END$\n}";
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:ForDescendingPostfixTemplate.java


示例5: calculateBounds

import com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils; //导入依赖的package包/类
@Nullable
@Override
protected Pair<String, String> calculateBounds(@NotNull PsiExpression expression) {
  String bound = getExpressionBound(expression);
  if (bound == null) {
    return null;
  }
  return JavaPostfixTemplatesUtils.isNumber(expression.getType())
    ? Pair.create(bound, "0")
    : Pair.create(bound + " - 1", "0");
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:12,代码来源:ForDescendingPostfixTemplate.java


示例6: expand

import com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils; //导入依赖的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);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:32,代码来源:ForeachPostfixTemplate.java


示例7: isApplicable

import com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils; //导入依赖的package包/类
@Override
public boolean isApplicable(@NotNull PsiElement context, @NotNull Document copyDocument, int newOffset) {
  PsiExpression expr = JavaPostfixTemplatesUtils.getTopmostExpression(context);
  return expr != null && (JavaPostfixTemplatesUtils.isNumber(expr.getType()) ||
                          JavaPostfixTemplatesUtils.isArray(expr.getType()) ||
                          JavaPostfixTemplatesUtils.isIterable(expr.getType()));
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:8,代码来源:ForIndexedPostfixTemplate.java


示例8: expand

import com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils; //导入依赖的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);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:39,代码来源:ForIndexedPostfixTemplate.java


示例9: getExpressionBound

import com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils; //导入依赖的package包/类
@Nullable
protected static String getExpressionBound(@NotNull PsiExpression expr) {
  PsiType type = expr.getType();
  if (JavaPostfixTemplatesUtils.isNumber(type)) {
    return expr.getText();
  }
  else if (JavaPostfixTemplatesUtils.isArray(type)) {
    return expr.getText() + ".length";
  }
  else if (JavaPostfixTemplatesUtils.isIterable(type)) {
    return expr.getText() + ".size()";
  }
  return null;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:15,代码来源:ForIndexedPostfixTemplate.java


示例10: suggestIndexType

import com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils; //导入依赖的package包/类
@NotNull
private static String suggestIndexType(@NotNull PsiExpression expr) {
  PsiType type = expr.getType();
  if (JavaPostfixTemplatesUtils.isNumber(type)) {
    return type.getCanonicalText();
  }
  return "int";
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:9,代码来源:ForIndexedPostfixTemplate.java


示例11: maybeTopmostExpression

import com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils; //导入依赖的package包/类
@NotNull
private static List<PsiExpression> maybeTopmostExpression(@NotNull PsiElement context) {
  PsiExpression expression = JavaPostfixTemplatesUtils.getTopmostExpression(context);
  PsiType type = expression != null ? expression.getType() : null;
  if (type == null || PsiType.VOID.equals(type)) return ContainerUtil.emptyList();
  return ContainerUtil.createMaybeSingletonList(expression);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:8,代码来源:ExpressionPostfixTemplateWithChooser.java


示例12: AbstractRichStringBasedPostfixTemplate

import com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils; //导入依赖的package包/类
protected AbstractRichStringBasedPostfixTemplate(@NotNull String name,
                                                 @NotNull String example,
                                                 @NotNull Condition<PsiElement> typeChecker) {
    super(name, example, JavaPostfixTemplatesUtils.selectorAllExpressionsWithCurrentOffset(typeChecker));
}
 
开发者ID:cesards,项目名称:HakunaMatataIntelliJPlugin,代码行数:6,代码来源:AbstractRichStringBasedPostfixTemplate.java


示例13: DoReturnTemplate

import com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils; //导入依赖的package包/类
public DoReturnTemplate() {
    super("doReturn", "doReturn(ret).when(expr)",
            JavaPostfixTemplatesUtils.selectorAllExpressionsWithCurrentOffset(JavaPostfixTemplatesUtils.IS_NOT_PRIMITIVE));
}
 
开发者ID:krrrr38,项目名称:intellij-mockito-postfix-plugin,代码行数:5,代码来源:DoReturnTemplate.java


示例14: VerifyTemplate

import com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils; //导入依赖的package包/类
public VerifyTemplate() {
    super("verify", "verify(expr)",
            JavaPostfixTemplatesUtils.selectorAllExpressionsWithCurrentOffset(JavaPostfixTemplatesUtils.IS_NOT_PRIMITIVE));
}
 
开发者ID:krrrr38,项目名称:intellij-mockito-postfix-plugin,代码行数:5,代码来源:VerifyTemplate.java


示例15: DoThrowTemplate

import com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils; //导入依赖的package包/类
public DoThrowTemplate() {
    super("doThrow", "doThrow(ex).when(expr)",
            JavaPostfixTemplatesUtils.selectorAllExpressionsWithCurrentOffset(JavaPostfixTemplatesUtils.IS_NOT_PRIMITIVE));
}
 
开发者ID:krrrr38,项目名称:intellij-mockito-postfix-plugin,代码行数:5,代码来源:DoThrowTemplate.java


示例16: DoNothingTemplate

import com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils; //导入依赖的package包/类
public DoNothingTemplate() {
    super("doNothing", "doNothing().when(expr)",
            JavaPostfixTemplatesUtils.selectorAllExpressionsWithCurrentOffset(JavaPostfixTemplatesUtils.IS_NOT_PRIMITIVE));
}
 
开发者ID:krrrr38,项目名称:intellij-mockito-postfix-plugin,代码行数:5,代码来源:DoNothingTemplate.java


示例17: SpyTemplate

import com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils; //导入依赖的package包/类
public SpyTemplate() {
    super("spy", "spy(expr)",
            JavaPostfixTemplatesUtils.selectorAllExpressionsWithCurrentOffset(JavaPostfixTemplatesUtils.IS_NOT_PRIMITIVE));
}
 
开发者ID:krrrr38,项目名称:intellij-mockito-postfix-plugin,代码行数:5,代码来源:SpyTemplate.java


示例18: MockTemplate

import com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils; //导入依赖的package包/类
public MockTemplate() {
    super("mock", "mock(expr)",
            JavaPostfixTemplatesUtils.selectorAllExpressionsWithCurrentOffset(JavaPostfixTemplatesUtils.IS_NOT_PRIMITIVE));
}
 
开发者ID:krrrr38,项目名称:intellij-mockito-postfix-plugin,代码行数:5,代码来源:MockTemplate.java


示例19: WhenTemplate

import com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils; //导入依赖的package包/类
public WhenTemplate() {
    super("when", "when(expr)",
            JavaPostfixTemplatesUtils.selectorAllExpressionsWithCurrentOffset(JavaPostfixTemplatesUtils.IS_NOT_PRIMITIVE));
}
 
开发者ID:krrrr38,项目名称:intellij-mockito-postfix-plugin,代码行数:5,代码来源:WhenTemplate.java


示例20: isApplicable

import com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils; //导入依赖的package包/类
@Override
public boolean isApplicable(@NotNull PsiElement context, @NotNull Document copyDocument, int newOffset) {
  return JavaPostfixTemplatesUtils.isNotPrimitiveTypeExpression(JavaPostfixTemplatesUtils.getTopmostExpression(context));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:InstanceofExpressionPostfixTemplate.java



注:本文中的com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DistributedRowMatrix类代码示例发布时间:2022-05-23
下一篇:
Java EntityEgg类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap