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


Java ExpressionContext.getProject方法代码示例

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


在下文中一共展示了ExpressionContext.getProject方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例6: calculateResult

import com.intellij.codeInsight.template.ExpressionContext; //导入方法依赖的package包/类
@Override
public Result calculateResult(@NotNull Expression[] params, ExpressionContext context) {
    final Project project = context.getProject();
    if (context.getEditor() == null) {
        return new TextResult("");
    }
    final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
    if (file == null) {
        return new TextResult("");
    }
    return new TextResult(CloudSlangFileUtils.getNameWithoutExtension(file.getName()));
}
 
开发者ID:CloudSlang,项目名称:cs-intellij-plugin,代码行数:13,代码来源:CloudSlangExecutableNameMacro.java

示例7: resultToPsiExpression

import com.intellij.codeInsight.template.ExpressionContext; //导入方法依赖的package包/类
@Nullable public static PsiExpression resultToPsiExpression(Result result, ExpressionContext context){
  if (result instanceof PsiElementResult){
    PsiElement element = ((PsiElementResult)result).getElement();
    if (element instanceof PsiExpression){
      return (PsiExpression)element;
    }
  }
  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 resolve algorithm
  PsiElement place = file != null ? file.findElementAt(context.getStartOffset()) : null;
  if (place != null) {
    PsiElement parent = place.getParent();
    if (parent != null) {
      PsiElement parentOfParent = parent.getParent();
      if (parentOfParent instanceof PsiDeclarationStatement) {
        place = file.findElementAt(parentOfParent.getTextOffset() -1);
      }
    }
  }
  PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
  try{
    return factory.createExpressionFromText(text, place);
  }
  catch(IncorrectOperationException e){
    return null;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:MacroUtil.java

示例8: calculateResult

import com.intellij.codeInsight.template.ExpressionContext; //导入方法依赖的package包/类
@Nullable
@Override
@RequiredDispatchThread
public Result calculateResult(@NotNull Expression[] params, ExpressionContext context)
{
	final Project project = context.getProject();
	final int offset = context.getStartOffset();

	PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
	PsiElement place = file.findElementAt(offset);

	List<DotNetVariable> dotNetVariables = CSharpLiveTemplateMacroUtil.resolveAllVariables(place);

	DotNetVariable variable = CSharpLineMarkerUtil.getNameIdentifierAs(place, DotNetVariable.class);

	ChooseLetterLoop:
	for(char letter = 'i'; letter <= 'z'; letter++)
	{
		for(DotNetVariable dotNetVariable : dotNetVariables)
		{
			// skip self
			if(dotNetVariable == variable)
			{
				continue;
			}

			String name = dotNetVariable.getName();
			if(name != null && name.length() == 1 && name.charAt(0) == letter)
			{
				continue ChooseLetterLoop;
			}
		}
		return new TextResult(String.valueOf(letter));
	}
	return null;
}
 
开发者ID:consulo,项目名称:consulo-csharp,代码行数:37,代码来源:SuggestIndexVariableNameMacro.java

示例9: getCaretElement

import com.intellij.codeInsight.template.ExpressionContext; //导入方法依赖的package包/类
public static PsiElement getCaretElement(ExpressionContext context)
{
	Project project = context.getProject();

	PsiDocumentManager.getInstance(project).commitAllDocuments();

	Editor editor = context.getEditor();
	if(editor == null)
	{
		return null;
	}
	PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
	return file == null ? null : file.findElementAt(editor.getCaretModel().getOffset());
}
 
开发者ID:consulo,项目名称:consulo-csharp,代码行数:15,代码来源:ReturnStatementExpression.java

示例10: findElementAtCaret

import com.intellij.codeInsight.template.ExpressionContext; //导入方法依赖的package包/类
public static PsiElement findElementAtCaret(final ExpressionContext context)
{
	Project project = context.getProject();
	int templateStartOffset = context.getTemplateStartOffset();
	int offset = templateStartOffset > 0 ? context.getTemplateStartOffset() - 1 : context.getTemplateStartOffset();

	PsiDocumentManager.getInstance(project).commitAllDocuments();

	PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
	return file.findElementAt(offset);
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:12,代码来源:JSClassNameMacro.java

示例11: resultToPsiType

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

示例12: resultToPsiExpression

import com.intellij.codeInsight.template.ExpressionContext; //导入方法依赖的package包/类
@Nullable
@RequiredReadAction
public static PsiExpression resultToPsiExpression(Result result, ExpressionContext context)
{
	if(result instanceof PsiElementResult)
	{
		PsiElement element = ((PsiElementResult) result).getElement();
		if(element instanceof PsiExpression)
		{
			return (PsiExpression) element;
		}
	}
	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 resolve algorithm
	PsiElement place = file != null ? file.findElementAt(context.getStartOffset()) : null;
	if(place != null)
	{
		PsiElement parent = place.getParent();
		if(parent != null)
		{
			PsiElement parentOfParent = parent.getParent();
			if(parentOfParent instanceof PsiDeclarationStatement)
			{
				place = file.findElementAt(parentOfParent.getTextOffset() - 1);
			}
		}
	}
	PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
	try
	{
		return factory.createExpressionFromText(text, place);
	}
	catch(IncorrectOperationException e)
	{
		return null;
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:45,代码来源:MacroUtil.java


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