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

Java ExpressionContext类代码示例

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

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



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

示例1: calculateResult

import com.intellij.codeInsight.template.ExpressionContext; //导入依赖的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: resultToPsiType

import com.intellij.codeInsight.template.ExpressionContext; //导入依赖的package包/类
@Nullable public static PsiType resultToPsiType(Result result, ExpressionContext context){
  if (result instanceof PsiTypeResult) {
    return ((PsiTypeResult) result).getType();
  }
  Project project = context.getProject();
  String text = result.toString();
  if (text == null) return null;
  PsiManager manager = PsiManager.getInstance(project);
  PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
  //-1: Hack to deal with stupid resolve
  PsiElement place = file != null ? file.findElementAt(context.getStartOffset()) : null;
  PsiDeclarationStatement decl = file != null ? PsiTreeUtil.getParentOfType(place, PsiDeclarationStatement.class) : null;
  if (decl != null) {
    place = file.findElementAt(decl.getTextOffset() -1);
  }
  PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
  try{
    return factory.createTypeFromText(text, place);
  }
  catch(IncorrectOperationException e){
    return null;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:MacroUtil.java


示例3: getVariables

import com.intellij.codeInsight.template.ExpressionContext; //导入依赖的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: calculateResult

import com.intellij.codeInsight.template.ExpressionContext; //导入依赖的package包/类
@Override
public Result calculateResult(ExpressionContext context) {
  final Project project = context.getProject();
  PsiDocumentManager.getInstance(project).commitAllDocuments();
  if (myItems.isEmpty()) return null;

  final PsiType type = myItems.iterator().next().getType();
  return type == null? null : new PsiTypeResult(type, project) {
    @Override
    public void handleRecalc(PsiFile psiFile, Document document, int segmentStart, int segmentEnd) {
      if (myItems.size() <= 1) {
        super.handleRecalc(psiFile, document, segmentStart, segmentEnd);
      } else {
        JavaTemplateUtil.updateTypeBindings(getType(), psiFile, document, segmentStart, segmentEnd, true);
      }
    }

    @Override
    public String toString() {
      return myItems.size() == 1 ? super.toString() : type.getPresentableText();
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:TypeExpression.java


示例5: formatUserDefined

import com.intellij.codeInsight.template.ExpressionContext; //导入依赖的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


示例6: calculateResult

import com.intellij.codeInsight.template.ExpressionContext; //导入依赖的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


示例7: calculateResult

import com.intellij.codeInsight.template.ExpressionContext; //导入依赖的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.ExpressionContext; //导入依赖的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.ExpressionContext; //导入依赖的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.ExpressionContext; //导入依赖的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.ExpressionContext; //导入依赖的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.ExpressionContext; //导入依赖的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.ExpressionContext; //导入依赖的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.ExpressionContext; //导入依赖的package包/类
@Nullable
@Override
public Result calculateResult(ExpressionContext context)
{
	PsiElement caretElement = getCaretElement(context);
	if(caretElement == null)
	{
		return new TextResult("");
	}

	CSharpSimpleLikeMethodAsElement element = PsiTreeUtil.getParentOfType(caretElement, CSharpSimpleLikeMethodAsElement.class);
	if(element == null)
	{
		return new TextResult("");
	}

	String defaultValueForType = MethodGenerateUtil.getDefaultValueForType(element.getReturnTypeRef(), element);
	if(defaultValueForType != null)
	{
		return new TextResult("return " + defaultValueForType + ";");
	}
	return new TextResult("");
}
 
开发者ID:consulo,项目名称:consulo-csharp,代码行数:24,代码来源:ReturnStatementExpression.java


示例15: calculateResult

import com.intellij.codeInsight.template.ExpressionContext; //导入依赖的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


示例16: calculateResult

import com.intellij.codeInsight.template.ExpressionContext; //导入依赖的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


示例17: calculateResult

import com.intellij.codeInsight.template.ExpressionContext; //导入依赖的package包/类
@Override
public Result calculateResult(@NotNull Expression[] params, ExpressionContext context)
{
	final PsiElement elementAtCaret = JSClassNameMacro.findElementAtCaret(context);
	if(elementAtCaret != null)
	{
		JSFunction function = PsiTreeUtil.getParentOfType(elementAtCaret, JSFunction.class);
		if(function instanceof JSFunctionExpression)
		{
			function = ((JSFunctionExpression) function).getFunction();
		}

		if(function != null)
		{
			final String name = function.getName();
			if(name != null)
			{
				return new TextResult(name);
			}
		}
	}
	return null;
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:24,代码来源:JSMethodNameMacro.java


示例18: calculateResult

import com.intellij.codeInsight.template.ExpressionContext; //导入依赖的package包/类
@Override
public Result calculateResult(@NotNull final Expression[] params, final ExpressionContext context)
{
	final PsiElement elementAtCaret = findElementAtCaret(context);
	final JSResolveUtil.ContextResolver resolver = new JSResolveUtil.ContextResolver(elementAtCaret);

	String text = resolver.getQualifierAsString();
	if(text == null)
	{
		final JSFunction previousFunction = PsiTreeUtil.getPrevSiblingOfType(elementAtCaret, JSFunction.class);

		if(previousFunction != null)
		{
			text = previousFunction.getName();
		}
	}

	if(text != null)
	{
		return new TextResult(text);
	}

	return null;
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:25,代码来源:JSClassNameMacro.java


示例19: calculateLookupItems

import com.intellij.codeInsight.template.ExpressionContext; //导入依赖的package包/类
@Override
public LookupElement[] calculateLookupItems(ExpressionContext context) {
  Set<LookupElement> set = new LinkedHashSet<LookupElement>();
  set.add(JavaLookupElementBuilder.forField(myField).withTypeText(myField.getType().getPresentableText()));
  PsiField[] fields = myClass.getFields();
  for (PsiField otherField : fields) {
    if (!myDefaultFieldName.equals(otherField.getName())) {
      PsiType otherType = otherField.getType();
      for (PsiType type : myExpectedTypes) {
        if (type.equals(otherType)) {
          set.add(JavaLookupElementBuilder.forField(otherField).withTypeText(otherType.getPresentableText()));
        }
      }
    }
  }

  if (set.size() < 2) return null;
  return set.toArray(new LookupElement[set.size()]);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:20,代码来源:CreatePropertyFromUsageFix.java


示例20: calculateResult

import com.intellij.codeInsight.template.ExpressionContext; //导入依赖的package包/类
@Override
public Result calculateResult(ExpressionContext context) {
  final Project project = context.getProject();
  PsiDocumentManager.getInstance(project).commitAllDocuments();
  if (myItems.isEmpty()) return null;

  final PsiType type = myItems.iterator().next().getType();
  return type == null? null : new PsiTypeResult(type, project) {
    @Override
    public void handleRecalc(PsiFile psiFile, Document document, int segmentStart, int segmentEnd) {
      if (myItems.size() <= 1) {
        super.handleRecalc(psiFile, document, segmentStart, segmentEnd);
      } else {
        JavaTemplateUtil.updateTypeBindings(getType(), psiFile, document, segmentStart, segmentEnd, true);
      }
    }

    @Override
    public String toString() {
      return myItems.size() == 1 ? type.getCanonicalText() : super.toString();
    }
  };
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:24,代码来源:TypeExpression.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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