当前位置: 首页>>代码示例>>Java>>正文


Java Expression类代码示例

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


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

示例1: calculateResult

import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Override
public Result calculateResult(@NotNull Expression[] params, ExpressionContext context) {
    Project project = context.getProject();
    if (context.getEditor() == null) {
        return new TextResult(DEFAULT_NAMESPACE_TO_USE);
    }

    PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
    if ((file == null) || (file.getVirtualFile() == null)) {
        return new TextResult(DEFAULT_NAMESPACE_TO_USE);
    }
    VirtualFile virtualFile = file.getVirtualFile();
    String editorFilePath = virtualFile.getPath();
    String projectPath = project.getBasePath();

    return new TextResult(fixNamespace(projectPath, editorFilePath));
}
 
开发者ID:CloudSlang,项目名称:cs-intellij-plugin,代码行数:18,代码来源:CurrentNamespaceMacro.java

示例2: insertMethod

import com.intellij.codeInsight.template.Expression; //导入依赖的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);
}
 
开发者ID:jiripudil,项目名称:intellij-nette-tester,代码行数:23,代码来源:TesterGenerateTestMethodAction.java

示例3: getVariables

import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Override
protected PsiElement[] getVariables(Expression[] params, final ExpressionContext context) {
  if (params.length != 0) return null;

  Project project = context.getProject();
  final int offset = context.getStartOffset();
  final ArrayList<PsiVariable> array = new ArrayList<PsiVariable>();
  PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
  PsiElement place = file.findElementAt(offset);
  PsiVariable[] variables = MacroUtil.getVariablesVisibleAt(place, "");
  for (PsiVariable variable : variables) {
    PsiType type = VariableTypeCalculator.getVarTypeAt(variable, place);
    if (type instanceof PsiArrayType) {
      array.add(variable);
    }
  }
  return array.toArray(new PsiVariable[array.size()]);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ArrayVariableMacro.java

示例4: formatUserDefined

import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
static String formatUserDefined(Expression[] params, ExpressionContext context, boolean date) {
  long time = Clock.getTime();
  if (params.length == 1) {
    Result format = params[0].calculateResult(context);
    if (format != null) {
      String pattern = format.toString();
      try {
        return new SimpleDateFormat(pattern).format(new Date(time));
      }
      catch (Exception e) {
        return "Problem when formatting date/time for pattern \"" + pattern + "\": " + e.getMessage();
      }
    }
  }
  return date ? DateFormatUtil.formatDate(time) : DateFormatUtil.formatTime(time);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:CurrentDateMacro.java

示例5: calculateResult

import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Nullable
@Override
protected Result calculateResult(@NotNull Expression[] params, ExpressionContext context, boolean quick) {
  final String text = getTextResult(params, context, true);
  if (text != null) {

    final List<String> strings = StringUtil.split(text, "_");
    if (strings.size() > 0) {
      final StringBuilder buf = new StringBuilder();
      buf.append(strings.get(0).toLowerCase());
      for (int i = 1; i < strings.size(); i++) {
        buf.append(StringUtil.capitalize(strings.get(i).toLowerCase()));
      }
      return new TextResult(buf.toString());
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ReplaceUnderscoresToCamelCaseMacro.java

示例6: parseVariable

import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
private static Expression parseVariable(Lexer lexer, String expression) {
  String variableName = getString(lexer, expression);
  advance(lexer);

  if (lexer.getTokenType() == null) {
    if (TemplateImpl.END.equals(variableName)) {
      return new EmptyNode();
    }

    return new VariableNode(variableName, null);
  }

  if (lexer.getTokenType() != MacroTokenType.EQ) {
    return new VariableNode(variableName, null);
  }

  advance(lexer);
  Expression node = parseMacro(lexer, expression);
  return new VariableNode(variableName, node);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:MacroParser.java

示例7: calculateResult

import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Nullable
@Override
protected Result calculateResult(@NotNull Expression[] params, ExpressionContext context, boolean quick) {
  final String text = getTextResult(params, context, true);
  if (text != null) {
    final List<String> strings = StringUtil.split(text, "_");
    if (strings.size() > 0) {
      final StringBuilder buf = new StringBuilder();
      buf.append(strings.get(0).toLowerCase());
      for (int i = 1; i < strings.size(); i++) {
        buf.append(StringUtil.capitalize(strings.get(i).toLowerCase()));
      }
      return new TextResult(buf.toString());
    }
  }
  return null;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:18,代码来源:ReplaceUnderscoresToCamelCaseMacro.java

示例8: calculateResult

import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Override
protected Result calculateResult(@NotNull Expression[] params, ExpressionContext context, boolean quick) {
  String text = getTextResult(params, context, true);
  if (text != null && text.length() > 0) {
    final String[] words = NameUtil.nameToWords(text);
    boolean insertUnderscore = false;
    final StringBuffer buf = new StringBuffer();
    for (String word : words) {
      if (insertUnderscore) {
        buf.append("_");
      } else {
        insertUnderscore = true;
      }
      buf.append(StringUtil.toUpperCase(word));
    }
    return new TextResult(buf.toString());
  }
  return null;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:20,代码来源:CapitalizeAndUnderscoreMacro.java

示例9: calculateResult

import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Override
public Result calculateResult(@NotNull Expression[] params, ExpressionContext context)
{
	final PsiElement[] vars = getVariables(params, context);
	if(vars == null || vars.length == 0)
	{
		return null;
	}
	return new PsiElementResult(vars[0])
	{
		@Override
		public String toString()
		{
			PsiElement element = getElement();
			if(element instanceof DotNetVariable)
			{
				return ((DotNetVariable) element).getName();
			}
			return super.toString();
		}
	};
}
 
开发者ID:consulo,项目名称:consulo-csharp,代码行数:23,代码来源:VariableTypeMacroBase.java

示例10: getVariables

import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Nullable
@Override
protected PsiElement[] getVariables(Expression[] params, ExpressionContext context)
{
	final PsiElement psiElementAtStartOffset = context.getPsiElementAtStartOffset();
	if(psiElementAtStartOffset == null)
	{
		return PsiElement.EMPTY_ARRAY;
	}

	List<DotNetVariable> variables = CSharpLiveTemplateMacroUtil.resolveAllVariables(context.getPsiElementAtStartOffset());

	List<DotNetVariable> list = new SmartList<DotNetVariable>();
	for(DotNetVariable variable : variables)
	{
		DotNetTypeRef typeRefOfVariable = variable.toTypeRef(true);

		if(CSharpTypeDeclarationImplUtil.isInheritOrSelf(typeRefOfVariable, psiElementAtStartOffset, ourAcceptableTypes))
		{
			list.add(variable);
		}
	}
	return list.toArray(new PsiElement[list.size()]);
}
 
开发者ID:consulo,项目名称:consulo-csharp,代码行数:25,代码来源:ForeachVariableMacro.java

示例11: calculateLookupItems

import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Nullable
@Override
@RequiredReadAction
public LookupElement[] calculateLookupItems(@NotNull Expression[] params, ExpressionContext context)
{
	Result result = calculateResult(params, context);
	if(result == null)
	{
		return LookupElement.EMPTY_ARRAY;
	}
	List<LookupElement> list = new SmartList<LookupElement>();
	list.add(LookupElementBuilder.create(result.toString()));
	if(CSharpModuleUtil.findLanguageVersion(context.getPsiElementAtStartOffset()).isAtLeast(CSharpLanguageVersion._2_0))
	{
		list.add(LookupElementBuilder.create("var").bold());
	}
	return list.toArray(new LookupElement[list.size()]);
}
 
开发者ID:consulo,项目名称:consulo-csharp,代码行数:19,代码来源:ForeachComponentTypeMacro.java

示例12: getVariables

import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Nullable
@Override
protected PsiElement[] getVariables(Expression[] params, ExpressionContext context)
{
	final PsiElement psiElementAtStartOffset = context.getPsiElementAtStartOffset();
	if(psiElementAtStartOffset == null)
	{
		return PsiElement.EMPTY_ARRAY;
	}

	List<DotNetVariable> variables = CSharpLiveTemplateMacroUtil.resolveAllVariables(context.getPsiElementAtStartOffset());

	List<DotNetVariable> list = new SmartList<DotNetVariable>();
	for(DotNetVariable variable : variables)
	{
		DotNetTypeRef typeRefOfVariable = variable.toTypeRef(true);

		if(CSharpTypeDeclarationImplUtil.isInheritOrSelf(typeRefOfVariable, psiElementAtStartOffset, DotNetTypes2.System.Collections.Generic
				.IList$1))
		{
			list.add(variable);
		}
	}
	return list.toArray(new PsiElement[list.size()]);
}
 
开发者ID:consulo,项目名称:consulo-csharp,代码行数:26,代码来源:IListVariableMacro.java

示例13: getVariables

import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Nullable
@Override
protected PsiElement[] getVariables(Expression[] params, ExpressionContext context)
{
	final PsiElement psiElementAtStartOffset = context.getPsiElementAtStartOffset();
	if(psiElementAtStartOffset == null)
	{
		return PsiElement.EMPTY_ARRAY;
	}

	List<DotNetVariable> variables = CSharpLiveTemplateMacroUtil.resolveAllVariables(context.getPsiElementAtStartOffset());

	List<DotNetVariable> list = new SmartList<DotNetVariable>();
	for(DotNetVariable variable : variables)
	{
		DotNetTypeRef typeRefOfVariable = variable.toTypeRef(true);

		if(typeRefOfVariable instanceof CSharpArrayTypeRef && ((CSharpArrayTypeRef) typeRefOfVariable).getDimensions() == 0)
		{
			list.add(variable);
		}
	}
	return list.toArray(new PsiElement[list.size()]);
}
 
开发者ID:consulo,项目名称:consulo-csharp,代码行数:25,代码来源:ArrayVariableMacro.java

示例14: calculateResult

import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Nullable
@Override
protected Result calculateResult(@Nonnull Expression[] params, ExpressionContext context, boolean quick) {
  final String text = getTextResult(params, context, true);
  if (text != null) {
    final List<String> strings = StringUtil.split(text, "_");
    if (strings.size() > 0) {
      final StringBuilder buf = new StringBuilder();
      buf.append(strings.get(0).toLowerCase());
      for (int i = 1; i < strings.size(); i++) {
        buf.append(StringUtil.capitalize(strings.get(i).toLowerCase()));
      }
      return new TextResult(buf.toString());
    }
  }
  return null;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:18,代码来源:ReplaceUnderscoresToCamelCaseMacro.java

示例15: calculateResult

import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Override
protected Result calculateResult(@Nonnull Expression[] params, ExpressionContext context, boolean quick) {
  String text = getTextResult(params, context, true);
  if (text != null && text.length() > 0) {
    final String[] words = NameUtil.nameToWords(text);
    boolean insertUnderscore = false;
    final StringBuffer buf = new StringBuffer();
    for (String word : words) {
      if (insertUnderscore) {
        buf.append("_");
      } else {
        insertUnderscore = true;
      }
      buf.append(StringUtil.toUpperCase(word));
    }
    return new TextResult(buf.toString());
  }
  return null;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:20,代码来源:CapitalizeAndUnderscoreMacro.java


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