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


Java PsiTypeResult类代码示例

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


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

示例1: resultToPsiType

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

示例2: calculateResult

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

示例3: calculateResult

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

示例4: resultToPsiType

import com.intellij.codeInsight.template.PsiTypeResult; //导入依赖的package包/类
@Nullable
@RequiredReadAction
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:consulo,项目名称:consulo-java,代码行数:34,代码来源:MacroUtil.java


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