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


Java PsiMatchers类代码示例

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


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

示例1: invoke

import com.intellij.psi.util.PsiMatchers; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) {
  if (!FileModificationService.getInstance().prepareFileForWrite(myConstructor.getContainingFile())) return;
  try {
    PsiStatement superCall =
      JavaPsiFacade.getInstance(myConstructor.getProject()).getElementFactory().createStatementFromText("super();",null);

    PsiCodeBlock body = myConstructor.getBody();
    PsiJavaToken lBrace = body.getLBrace();
    body.addAfter(superCall, lBrace);
    lBrace = (PsiJavaToken) new PsiMatcherImpl(body)
              .firstChild(PsiMatchers.hasClass(PsiExpressionStatement.class))
              .firstChild(PsiMatchers.hasClass(PsiMethodCallExpression.class))
              .firstChild(PsiMatchers.hasClass(PsiExpressionList.class))
              .firstChild(PsiMatchers.hasClass(PsiJavaToken.class))
              .dot(PsiMatchers.hasText("("))
              .getElement();
    editor.getCaretModel().moveToOffset(lBrace.getTextOffset()+1);
    UndoUtil.markPsiFileForUndo(file);
  }
  catch (IncorrectOperationException e) {
    LOG.error(e);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:InsertSuperFix.java

示例2: isParameterUsedRecursively

import com.intellij.psi.util.PsiMatchers; //导入依赖的package包/类
private static boolean isParameterUsedRecursively(@NotNull PsiElement element, @NotNull Collection<PsiReference> array) {
  if (!(element instanceof PsiParameter)) return false;
  PsiParameter parameter = (PsiParameter)element;
  PsiElement scope = parameter.getDeclarationScope();
  if (!(scope instanceof PsiMethod)) return false;
  PsiMethod method = (PsiMethod)scope;
  int paramIndex = ArrayUtilRt.find(method.getParameterList().getParameters(), parameter);

  for (PsiReference reference : array) {
    if (!(reference instanceof PsiElement)) return false;
    PsiElement argument = (PsiElement)reference;

    PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)new PsiMatcherImpl(argument)
      .dot(PsiMatchers.hasClass(PsiReferenceExpression.class))
      .parent(PsiMatchers.hasClass(PsiExpressionList.class))
      .parent(PsiMatchers.hasClass(PsiMethodCallExpression.class))
      .getElement();
    if (methodCallExpression == null) return false;
    PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
    if (method != methodExpression.resolve()) return false;
    PsiExpressionList argumentList = methodCallExpression.getArgumentList();
    PsiExpression[] arguments = argumentList.getExpressions();
    int argumentIndex = ArrayUtilRt.find(arguments, argument);
    if (paramIndex != argumentIndex) return false;
  }

  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:RefCountHolder.java

示例3: isParameterUsedRecursively

import com.intellij.psi.util.PsiMatchers; //导入依赖的package包/类
private static boolean isParameterUsedRecursively(@NotNull PsiElement element, @NotNull List<PsiReference> array) {
  if (!(element instanceof PsiParameter)) return false;
  PsiParameter parameter = (PsiParameter)element;
  PsiElement scope = parameter.getDeclarationScope();
  if (!(scope instanceof PsiMethod)) return false;
  PsiMethod method = (PsiMethod)scope;
  int paramIndex = ArrayUtilRt.find(method.getParameterList().getParameters(), parameter);

  for (PsiReference reference : array) {
    if (!(reference instanceof PsiElement)) return false;
    PsiElement argument = (PsiElement)reference;

    PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)new PsiMatcherImpl(argument)
      .dot(PsiMatchers.hasClass(PsiReferenceExpression.class))
      .parent(PsiMatchers.hasClass(PsiExpressionList.class))
      .parent(PsiMatchers.hasClass(PsiMethodCallExpression.class))
      .getElement();
    if (methodCallExpression == null) return false;
    PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
    if (method != methodExpression.resolve()) return false;
    PsiExpressionList argumentList = methodCallExpression.getArgumentList();
    PsiExpression[] arguments = argumentList.getExpressions();
    int argumentIndex = ArrayUtilRt.find(arguments, argument);
    if (paramIndex != argumentIndex) return false;
  }

  return true;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:29,代码来源:RefCountHolder.java

示例4: getEnclosingStaticClass

import com.intellij.psi.util.PsiMatchers; //导入依赖的package包/类
private static PsiElement getEnclosingStaticClass(@NotNull PsiKeyword keyword, @NotNull Class<?> parentClass)
{
	return new PsiMatcherImpl(keyword).dot(PsiMatchers.hasText(PsiModifier.STATIC)).parent(PsiMatchers.hasClass
			(PsiModifierList.class)).parent(PsiMatchers.hasClass(parentClass)).parent(PsiMatchers.hasClass
			(PsiClass.class)).dot(JavaMatchers.hasModifier(PsiModifier.STATIC, false)).parent(PsiMatchers.hasClass
			(PsiClass.class, PsiDeclarationStatement.class, PsiNewExpression.class,
					PsiEnumConstant.class)).getElement();
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:9,代码来源:HighlightClassUtil.java

示例5: visitConstructorChain

import com.intellij.psi.util.PsiMatchers; //导入依赖的package包/类
static void visitConstructorChain(PsiMethod constructor, ConstructorVisitorInfo info) {
  while (true) {
    if (constructor == null) return;
    final PsiCodeBlock body = constructor.getBody();
    if (body == null) return;
    final PsiStatement[] statements = body.getStatements();
    if (statements.length == 0) return;
    final PsiStatement statement = statements[0];
    final PsiElement element = new PsiMatcherImpl(statement)
      .dot(PsiMatchers.hasClass(PsiExpressionStatement.class))
      .firstChild(PsiMatchers.hasClass(PsiMethodCallExpression.class))
      .firstChild(PsiMatchers.hasClass(PsiReferenceExpression.class))
      .firstChild(PsiMatchers.hasClass(PsiKeyword.class))
      .dot(PsiMatchers.hasText(PsiKeyword.THIS))
      .parent(null)
      .parent(null)
      .getElement();
    if (element == null) return;
    PsiMethodCallExpression methodCall = (PsiMethodCallExpression)element;
    PsiMethod method = methodCall.resolveMethod();
    if (method == null) return;
    if (info.visitedConstructors != null && info.visitedConstructors.contains(method)) {
      info.recursivelyCalledConstructor = method;
      return;
    }
    if (info.visitedConstructors == null) info.visitedConstructors = new ArrayList<PsiMethod>(5);
    info.visitedConstructors.add(method);
    constructor = method;
  }
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:31,代码来源:JavaHighlightUtil.java

示例6: invoke

import com.intellij.psi.util.PsiMatchers; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file)
{
	PsiStatement superCall = JavaPsiFacade.getInstance(myConstructor.getProject()).getElementFactory().createStatementFromText(myCall, null);

	PsiCodeBlock body = myConstructor.getBody();
	PsiJavaToken lBrace = body.getLBrace();
	body.addAfter(superCall, lBrace);
	lBrace = (PsiJavaToken) new PsiMatcherImpl(body).firstChild(PsiMatchers.hasClass(PsiExpressionStatement.class)).firstChild(PsiMatchers.hasClass(PsiMethodCallExpression.class)).firstChild
			(PsiMatchers.hasClass(PsiExpressionList.class)).firstChild(PsiMatchers.hasClass(PsiJavaToken.class)).dot(PsiMatchers.hasText("(")).getElement();
	editor.getCaretModel().moveToOffset(lBrace.getTextOffset() + 1);
	UndoUtil.markPsiFileForUndo(file);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:14,代码来源:InsertConstructorCallFix.java

示例7: checkStaticClassDeclarationInInnerClass

import com.intellij.psi.util.PsiMatchers; //导入依赖的package包/类
@Nullable
private static HighlightInfo checkStaticClassDeclarationInInnerClass(PsiKeyword keyword)
{
	// keyword points to 'class' or 'interface' or 'enum'
	if(new PsiMatcherImpl(keyword).parent(PsiMatchers.hasClass(PsiClass.class)).dot(JavaMatchers.hasModifier
			(PsiModifier.STATIC, true)).parent(PsiMatchers.hasClass(PsiClass.class)).dot(JavaMatchers.hasModifier
			(PsiModifier.STATIC, false)).parent(PsiMatchers.hasClass(PsiClass.class,
			PsiDeclarationStatement.class, PsiNewExpression.class, PsiEnumConstant.class)).getElement() == null)
	{
		return null;
	}

	PsiClass aClass = (PsiClass) keyword.getParent();
	if(PsiUtilCore.hasErrorElementChild(aClass))
	{
		return null;
	}

	// highlight 'static' keyword if any, or class or interface if not
	PsiElement context = null;
	PsiModifierList modifierList = aClass.getModifierList();
	if(modifierList != null)
	{
		for(PsiElement element : modifierList.getChildren())
		{
			if(Comparing.equal(element.getText(), PsiModifier.STATIC))
			{
				context = element;
				break;
			}
		}
	}
	TextRange range = context != null ? context.getTextRange() : HighlightNamesUtil.getClassDeclarationTextRange
			(aClass);
	String message = JavaErrorMessages.message("static.declaration.in.inner.class");
	HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(range)
			.descriptionAndTooltip(message).create();
	if(context != keyword)
	{
		QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createModifierListFix(aClass,
				PsiModifier.STATIC, false, false));
	}
	PsiClass containingClass = aClass.getContainingClass();
	if(containingClass != null)
	{
		QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createModifierListFix(containingClass,
				PsiModifier.STATIC, true, false));
	}
	return info;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:51,代码来源:HighlightClassUtil.java

示例8: isParameterUsedRecursively

import com.intellij.psi.util.PsiMatchers; //导入依赖的package包/类
private static boolean isParameterUsedRecursively(@NotNull PsiElement element, @NotNull Collection<PsiReference> array)
{
	if(!(element instanceof PsiParameter))
	{
		return false;
	}
	PsiParameter parameter = (PsiParameter) element;
	PsiElement scope = parameter.getDeclarationScope();
	if(!(scope instanceof PsiMethod))
	{
		return false;
	}
	PsiMethod method = (PsiMethod) scope;
	int paramIndex = ArrayUtilRt.find(method.getParameterList().getParameters(), parameter);

	for(PsiReference reference : array)
	{
		if(!(reference instanceof PsiElement))
		{
			return false;
		}
		PsiElement argument = (PsiElement) reference;

		PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) new PsiMatcherImpl(argument).dot(PsiMatchers.hasClass(PsiReferenceExpression.class)).parent(PsiMatchers.hasClass
				(PsiExpressionList.class)).parent(PsiMatchers.hasClass(PsiMethodCallExpression.class)).getElement();
		if(methodCallExpression == null)
		{
			return false;
		}
		PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
		if(method != methodExpression.resolve())
		{
			return false;
		}
		PsiExpressionList argumentList = methodCallExpression.getArgumentList();
		PsiExpression[] arguments = argumentList.getExpressions();
		int argumentIndex = ArrayUtilRt.find(arguments, argument);
		if(paramIndex != argumentIndex)
		{
			return false;
		}
	}

	return true;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:46,代码来源:RefCountHolder.java


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