當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。