本文整理汇总了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;
}
}
示例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();
}
};
}
示例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();
}
};
}
示例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;
}
}